Commit | Line | Data |
---|---|---|
43f66a6c | 1 | /****************************************************************************** |
bf79451e | 2 | |
171e7b2f | 3 | Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved. |
43f66a6c JK |
4 | |
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 | ||
bf79451e JG |
11 | 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 | |
43f66a6c | 13 | published by the Free Software Foundation. |
bf79451e JG |
14 | |
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 | |
43f66a6c | 18 | more details. |
bf79451e | 19 | |
43f66a6c | 20 | You should have received a copy of the GNU General Public License along with |
bf79451e | 21 | this program; if not, write to the Free Software Foundation, Inc., 59 |
43f66a6c | 22 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
bf79451e | 23 | |
43f66a6c JK |
24 | The full GNU General Public License is included in this distribution in the |
25 | file called LICENSE. | |
bf79451e | 26 | |
43f66a6c | 27 | Contact Information: |
c1eb2c82 | 28 | Intel Linux Wireless <ilw@linux.intel.com> |
43f66a6c JK |
29 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
30 | ||
31 | ******************************************************************************/ | |
32 | ||
d43c36dc | 33 | #include <linux/sched.h> |
5a0e3ad6 | 34 | #include <linux/slab.h> |
43f66a6c JK |
35 | #include "ipw2200.h" |
36 | ||
ae4af61f ZY |
37 | |
38 | #ifndef KBUILD_EXTMOD | |
39 | #define VK "k" | |
40 | #else | |
41 | #define VK | |
42 | #endif | |
43 | ||
44 | #ifdef CONFIG_IPW2200_DEBUG | |
45 | #define VD "d" | |
46 | #else | |
47 | #define VD | |
48 | #endif | |
49 | ||
50 | #ifdef CONFIG_IPW2200_MONITOR | |
51 | #define VM "m" | |
52 | #else | |
53 | #define VM | |
54 | #endif | |
55 | ||
56 | #ifdef CONFIG_IPW2200_PROMISCUOUS | |
57 | #define VP "p" | |
58 | #else | |
59 | #define VP | |
60 | #endif | |
61 | ||
459d4087 | 62 | #ifdef CONFIG_IPW2200_RADIOTAP |
ae4af61f ZY |
63 | #define VR "r" |
64 | #else | |
65 | #define VR | |
66 | #endif | |
67 | ||
68 | #ifdef CONFIG_IPW2200_QOS | |
69 | #define VQ "q" | |
70 | #else | |
71 | #define VQ | |
72 | #endif | |
73 | ||
ee2c4add | 74 | #define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ |
43f66a6c | 75 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" |
171e7b2f | 76 | #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation" |
43f66a6c JK |
77 | #define DRV_VERSION IPW2200_VERSION |
78 | ||
b095c381 JK |
79 | #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1) |
80 | ||
43f66a6c JK |
81 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
82 | MODULE_VERSION(DRV_VERSION); | |
83 | MODULE_AUTHOR(DRV_COPYRIGHT); | |
84 | MODULE_LICENSE("GPL"); | |
873395a9 BH |
85 | MODULE_FIRMWARE("ipw2200-ibss.fw"); |
86 | #ifdef CONFIG_IPW2200_MONITOR | |
87 | MODULE_FIRMWARE("ipw2200-sniffer.fw"); | |
88 | #endif | |
89 | MODULE_FIRMWARE("ipw2200-bss.fw"); | |
43f66a6c | 90 | |
f6c5cb7c | 91 | static int cmdlog = 0; |
43f66a6c | 92 | static int debug = 0; |
21f8a73f RC |
93 | static int default_channel = 0; |
94 | static int network_mode = 0; | |
43f66a6c JK |
95 | |
96 | static u32 ipw_debug_level; | |
5c7f9b73 | 97 | static int associate; |
43f66a6c | 98 | static int auto_create = 1; |
21f8a73f | 99 | static int led_support = 0; |
43f66a6c | 100 | static int disable = 0; |
810dabd4 | 101 | static int bt_coexist = 0; |
bde37d03 | 102 | static int hwcrypto = 0; |
4bfdb91d | 103 | static int roaming = 1; |
43f66a6c JK |
104 | static const char ipw_modes[] = { |
105 | 'a', 'b', 'g', '?' | |
106 | }; | |
d2b83e12 | 107 | static int antenna = CFG_SYS_ANTENNA_BOTH; |
43f66a6c | 108 | |
d685b8c2 ZY |
109 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
110 | static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */ | |
111 | #endif | |
112 | ||
a3caa99e JL |
113 | static struct ieee80211_rate ipw2200_rates[] = { |
114 | { .bitrate = 10 }, | |
115 | { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
116 | { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
117 | { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
118 | { .bitrate = 60 }, | |
119 | { .bitrate = 90 }, | |
120 | { .bitrate = 120 }, | |
121 | { .bitrate = 180 }, | |
122 | { .bitrate = 240 }, | |
123 | { .bitrate = 360 }, | |
124 | { .bitrate = 480 }, | |
125 | { .bitrate = 540 } | |
126 | }; | |
127 | ||
128 | #define ipw2200_a_rates (ipw2200_rates + 4) | |
129 | #define ipw2200_num_a_rates 8 | |
130 | #define ipw2200_bg_rates (ipw2200_rates + 0) | |
131 | #define ipw2200_num_bg_rates 12 | |
d685b8c2 | 132 | |
e43e3c1e | 133 | #ifdef CONFIG_IPW2200_QOS |
b095c381 JK |
134 | static int qos_enable = 0; |
135 | static int qos_burst_enable = 0; | |
136 | static int qos_no_ack_mask = 0; | |
137 | static int burst_duration_CCK = 0; | |
138 | static int burst_duration_OFDM = 0; | |
139 | ||
b0a4e7d8 | 140 | static struct libipw_qos_parameters def_qos_parameters_OFDM = { |
b095c381 JK |
141 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, |
142 | QOS_TX3_CW_MIN_OFDM}, | |
143 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, | |
144 | QOS_TX3_CW_MAX_OFDM}, | |
145 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, | |
146 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, | |
147 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, | |
148 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} | |
149 | }; | |
150 | ||
b0a4e7d8 | 151 | static struct libipw_qos_parameters def_qos_parameters_CCK = { |
b095c381 JK |
152 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, |
153 | QOS_TX3_CW_MIN_CCK}, | |
154 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, | |
155 | QOS_TX3_CW_MAX_CCK}, | |
156 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, | |
157 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, | |
158 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, | |
159 | QOS_TX3_TXOP_LIMIT_CCK} | |
160 | }; | |
161 | ||
b0a4e7d8 | 162 | static struct libipw_qos_parameters def_parameters_OFDM = { |
b095c381 JK |
163 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, |
164 | DEF_TX3_CW_MIN_OFDM}, | |
165 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, | |
166 | DEF_TX3_CW_MAX_OFDM}, | |
167 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, | |
168 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, | |
169 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, | |
170 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} | |
171 | }; | |
172 | ||
b0a4e7d8 | 173 | static struct libipw_qos_parameters def_parameters_CCK = { |
b095c381 JK |
174 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, |
175 | DEF_TX3_CW_MIN_CCK}, | |
176 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, | |
177 | DEF_TX3_CW_MAX_CCK}, | |
178 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, | |
179 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, | |
180 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, | |
181 | DEF_TX3_TXOP_LIMIT_CCK} | |
182 | }; | |
183 | ||
184 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; | |
185 | ||
186 | static int from_priority_to_tx_queue[] = { | |
187 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, | |
188 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 | |
189 | }; | |
190 | ||
191 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); | |
192 | ||
b0a4e7d8 | 193 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters |
b095c381 | 194 | *qos_param); |
b0a4e7d8 | 195 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element |
b095c381 | 196 | *qos_param); |
e43e3c1e | 197 | #endif /* CONFIG_IPW2200_QOS */ |
b095c381 | 198 | |
97a78ca9 | 199 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); |
b095c381 | 200 | static void ipw_remove_current_network(struct ipw_priv *priv); |
43f66a6c | 201 | static void ipw_rx(struct ipw_priv *priv); |
bf79451e | 202 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
43f66a6c JK |
203 | struct clx2_tx_queue *txq, int qindex); |
204 | static int ipw_queue_reset(struct ipw_priv *priv); | |
205 | ||
206 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, | |
207 | int len, int sync); | |
208 | ||
209 | static void ipw_tx_queue_free(struct ipw_priv *); | |
210 | ||
211 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); | |
212 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); | |
213 | static void ipw_rx_queue_replenish(void *); | |
43f66a6c | 214 | static int ipw_up(struct ipw_priv *); |
c4028958 | 215 | static void ipw_bg_up(struct work_struct *work); |
43f66a6c | 216 | static void ipw_down(struct ipw_priv *); |
c4028958 | 217 | static void ipw_bg_down(struct work_struct *work); |
43f66a6c | 218 | static int ipw_config(struct ipw_priv *); |
0edd5b44 JG |
219 | static int init_supported_rates(struct ipw_priv *priv, |
220 | struct ipw_supported_rates *prates); | |
b095c381 JK |
221 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); |
222 | static void ipw_send_wep_keys(struct ipw_priv *, int); | |
43f66a6c | 223 | |
f6c5cb7c JK |
224 | static int snprint_line(char *buf, size_t count, |
225 | const u8 * data, u32 len, u32 ofs) | |
43f66a6c JK |
226 | { |
227 | int out, i, j, l; | |
228 | char c; | |
bf79451e | 229 | |
43f66a6c JK |
230 | out = snprintf(buf, count, "%08X", ofs); |
231 | ||
232 | for (l = 0, i = 0; i < 2; i++) { | |
233 | out += snprintf(buf + out, count - out, " "); | |
bf79451e JG |
234 | for (j = 0; j < 8 && l < len; j++, l++) |
235 | out += snprintf(buf + out, count - out, "%02X ", | |
43f66a6c JK |
236 | data[(i * 8 + j)]); |
237 | for (; j < 8; j++) | |
238 | out += snprintf(buf + out, count - out, " "); | |
239 | } | |
bf79451e | 240 | |
43f66a6c JK |
241 | out += snprintf(buf + out, count - out, " "); |
242 | for (l = 0, i = 0; i < 2; i++) { | |
243 | out += snprintf(buf + out, count - out, " "); | |
244 | for (j = 0; j < 8 && l < len; j++, l++) { | |
245 | c = data[(i * 8 + j)]; | |
246 | if (!isascii(c) || !isprint(c)) | |
247 | c = '.'; | |
bf79451e | 248 | |
43f66a6c JK |
249 | out += snprintf(buf + out, count - out, "%c", c); |
250 | } | |
251 | ||
252 | for (; j < 8; j++) | |
253 | out += snprintf(buf + out, count - out, " "); | |
254 | } | |
bf79451e | 255 | |
f6c5cb7c | 256 | return out; |
43f66a6c JK |
257 | } |
258 | ||
0edd5b44 | 259 | static void printk_buf(int level, const u8 * data, u32 len) |
43f66a6c JK |
260 | { |
261 | char line[81]; | |
262 | u32 ofs = 0; | |
263 | if (!(ipw_debug_level & level)) | |
264 | return; | |
265 | ||
266 | while (len) { | |
f6c5cb7c JK |
267 | snprint_line(line, sizeof(line), &data[ofs], |
268 | min(len, 16U), ofs); | |
269 | printk(KERN_DEBUG "%s\n", line); | |
43f66a6c JK |
270 | ofs += 16; |
271 | len -= min(len, 16U); | |
272 | } | |
273 | } | |
274 | ||
f6c5cb7c JK |
275 | static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) |
276 | { | |
277 | size_t out = size; | |
278 | u32 ofs = 0; | |
279 | int total = 0; | |
280 | ||
281 | while (size && len) { | |
282 | out = snprint_line(output, size, &data[ofs], | |
283 | min_t(size_t, len, 16U), ofs); | |
284 | ||
285 | ofs += 16; | |
286 | output += out; | |
287 | size -= out; | |
288 | len -= min_t(size_t, len, 16U); | |
289 | total += out; | |
290 | } | |
291 | return total; | |
292 | } | |
293 | ||
c8fe6679 | 294 | /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
295 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); |
296 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) | |
297 | ||
c8fe6679 | 298 | /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
299 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); |
300 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) | |
301 | ||
c8fe6679 | 302 | /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
303 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); |
304 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) | |
305 | { | |
0edd5b44 JG |
306 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, |
307 | __LINE__, (u32) (b), (u32) (c)); | |
43f66a6c JK |
308 | _ipw_write_reg8(a, b, c); |
309 | } | |
310 | ||
c8fe6679 | 311 | /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
312 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); |
313 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) | |
314 | { | |
0edd5b44 JG |
315 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, |
316 | __LINE__, (u32) (b), (u32) (c)); | |
43f66a6c JK |
317 | _ipw_write_reg16(a, b, c); |
318 | } | |
319 | ||
c8fe6679 | 320 | /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
321 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); |
322 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) | |
323 | { | |
0edd5b44 JG |
324 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, |
325 | __LINE__, (u32) (b), (u32) (c)); | |
43f66a6c JK |
326 | _ipw_write_reg32(a, b, c); |
327 | } | |
328 | ||
c8fe6679 | 329 | /* 8-bit direct write (low 4K) */ |
1788bcd1 JS |
330 | static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs, |
331 | u8 val) | |
332 | { | |
333 | writeb(val, ipw->hw_base + ofs); | |
334 | } | |
c8fe6679 ZY |
335 | |
336 | /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ | |
fb55d887 | 337 | #define ipw_write8(ipw, ofs, val) do { \ |
1788bcd1 JS |
338 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \ |
339 | __LINE__, (u32)(ofs), (u32)(val)); \ | |
340 | _ipw_write8(ipw, ofs, val); \ | |
341 | } while (0) | |
43f66a6c | 342 | |
c8fe6679 | 343 | /* 16-bit direct write (low 4K) */ |
1788bcd1 JS |
344 | static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs, |
345 | u16 val) | |
346 | { | |
347 | writew(val, ipw->hw_base + ofs); | |
348 | } | |
c8fe6679 ZY |
349 | |
350 | /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ | |
1788bcd1 JS |
351 | #define ipw_write16(ipw, ofs, val) do { \ |
352 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \ | |
353 | __LINE__, (u32)(ofs), (u32)(val)); \ | |
354 | _ipw_write16(ipw, ofs, val); \ | |
355 | } while (0) | |
43f66a6c | 356 | |
c8fe6679 | 357 | /* 32-bit direct write (low 4K) */ |
1788bcd1 JS |
358 | static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs, |
359 | u32 val) | |
360 | { | |
361 | writel(val, ipw->hw_base + ofs); | |
362 | } | |
c8fe6679 ZY |
363 | |
364 | /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ | |
1788bcd1 JS |
365 | #define ipw_write32(ipw, ofs, val) do { \ |
366 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \ | |
367 | __LINE__, (u32)(ofs), (u32)(val)); \ | |
368 | _ipw_write32(ipw, ofs, val); \ | |
369 | } while (0) | |
43f66a6c | 370 | |
c8fe6679 | 371 | /* 8-bit direct read (low 4K) */ |
1788bcd1 | 372 | static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs) |
0edd5b44 | 373 | { |
1788bcd1 | 374 | return readb(ipw->hw_base + ofs); |
43f66a6c | 375 | } |
0edd5b44 | 376 | |
c8fe6679 | 377 | /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
1788bcd1 JS |
378 | #define ipw_read8(ipw, ofs) ({ \ |
379 | IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \ | |
380 | (u32)(ofs)); \ | |
381 | _ipw_read8(ipw, ofs); \ | |
382 | }) | |
43f66a6c | 383 | |
c8fe6679 | 384 | /* 16-bit direct read (low 4K) */ |
1788bcd1 | 385 | static inline u16 _ipw_read16(struct ipw_priv *ipw, unsigned long ofs) |
0edd5b44 | 386 | { |
1788bcd1 | 387 | return readw(ipw->hw_base + ofs); |
43f66a6c | 388 | } |
0edd5b44 | 389 | |
c8fe6679 | 390 | /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
1788bcd1 JS |
391 | #define ipw_read16(ipw, ofs) ({ \ |
392 | IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \ | |
393 | (u32)(ofs)); \ | |
394 | _ipw_read16(ipw, ofs); \ | |
395 | }) | |
43f66a6c | 396 | |
c8fe6679 | 397 | /* 32-bit direct read (low 4K) */ |
1788bcd1 | 398 | static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs) |
0edd5b44 | 399 | { |
1788bcd1 | 400 | return readl(ipw->hw_base + ofs); |
43f66a6c | 401 | } |
0edd5b44 | 402 | |
c8fe6679 | 403 | /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
1788bcd1 JS |
404 | #define ipw_read32(ipw, ofs) ({ \ |
405 | IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \ | |
406 | (u32)(ofs)); \ | |
407 | _ipw_read32(ipw, ofs); \ | |
408 | }) | |
43f66a6c JK |
409 | |
410 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); | |
c8fe6679 | 411 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
1788bcd1 JS |
412 | #define ipw_read_indirect(a, b, c, d) ({ \ |
413 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \ | |
414 | __LINE__, (u32)(b), (u32)(d)); \ | |
415 | _ipw_read_indirect(a, b, c, d); \ | |
416 | }) | |
43f66a6c | 417 | |
c8fe6679 | 418 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
0edd5b44 JG |
419 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, |
420 | int num); | |
1788bcd1 JS |
421 | #define ipw_write_indirect(a, b, c, d) do { \ |
422 | IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \ | |
423 | __LINE__, (u32)(b), (u32)(d)); \ | |
424 | _ipw_write_indirect(a, b, c, d); \ | |
425 | } while (0) | |
43f66a6c | 426 | |
c8fe6679 | 427 | /* 32-bit indirect write (above 4K) */ |
0edd5b44 | 428 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value) |
43f66a6c | 429 | { |
0edd5b44 | 430 | IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value); |
b095c381 JK |
431 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
432 | _ipw_write32(priv, IPW_INDIRECT_DATA, value); | |
43f66a6c JK |
433 | } |
434 | ||
c8fe6679 | 435 | /* 8-bit indirect write (above 4K) */ |
43f66a6c JK |
436 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) |
437 | { | |
2638bc39 | 438 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
c8fe6679 ZY |
439 | u32 dif_len = reg - aligned_addr; |
440 | ||
43f66a6c | 441 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
c8fe6679 ZY |
442 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
443 | _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value); | |
43f66a6c JK |
444 | } |
445 | ||
c8fe6679 | 446 | /* 16-bit indirect write (above 4K) */ |
0edd5b44 | 447 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value) |
43f66a6c | 448 | { |
2638bc39 | 449 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
c8fe6679 ZY |
450 | u32 dif_len = (reg - aligned_addr) & (~0x1ul); |
451 | ||
43f66a6c | 452 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
c8fe6679 ZY |
453 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
454 | _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); | |
43f66a6c JK |
455 | } |
456 | ||
c8fe6679 | 457 | /* 8-bit indirect read (above 4K) */ |
43f66a6c JK |
458 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) |
459 | { | |
460 | u32 word; | |
b095c381 | 461 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
43f66a6c | 462 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); |
b095c381 | 463 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); |
0edd5b44 | 464 | return (word >> ((reg & 0x3) * 8)) & 0xff; |
43f66a6c JK |
465 | } |
466 | ||
c8fe6679 | 467 | /* 32-bit indirect read (above 4K) */ |
43f66a6c JK |
468 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) |
469 | { | |
470 | u32 value; | |
471 | ||
472 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); | |
473 | ||
b095c381 JK |
474 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
475 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); | |
43f66a6c JK |
476 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); |
477 | return value; | |
478 | } | |
479 | ||
c8fe6679 ZY |
480 | /* General purpose, no alignment requirement, iterative (multi-byte) read, */ |
481 | /* for area above 1st 4K of SRAM/reg space */ | |
43f66a6c JK |
482 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
483 | int num) | |
484 | { | |
2638bc39 | 485 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
43f66a6c | 486 | u32 dif_len = addr - aligned_addr; |
43f66a6c | 487 | u32 i; |
bf79451e | 488 | |
43f66a6c JK |
489 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
490 | ||
ea2b26e0 JK |
491 | if (num <= 0) { |
492 | return; | |
493 | } | |
494 | ||
c8fe6679 | 495 | /* Read the first dword (or portion) byte by byte */ |
43f66a6c | 496 | if (unlikely(dif_len)) { |
b095c381 | 497 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
43f66a6c | 498 | /* Start reading at aligned_addr + dif_len */ |
ea2b26e0 | 499 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) |
b095c381 | 500 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); |
43f66a6c JK |
501 | aligned_addr += 4; |
502 | } | |
503 | ||
c8fe6679 | 504 | /* Read all of the middle dwords as dwords, with auto-increment */ |
b095c381 | 505 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
ea2b26e0 | 506 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
b095c381 | 507 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); |
bf79451e | 508 | |
c8fe6679 | 509 | /* Read the last dword (or portion) byte by byte */ |
ea2b26e0 | 510 | if (unlikely(num)) { |
b095c381 | 511 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
ea2b26e0 | 512 | for (i = 0; num > 0; i++, num--) |
b095c381 | 513 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); |
ea2b26e0 | 514 | } |
43f66a6c JK |
515 | } |
516 | ||
c8fe6679 ZY |
517 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
518 | /* for area above 1st 4K of SRAM/reg space */ | |
0edd5b44 | 519 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
43f66a6c JK |
520 | int num) |
521 | { | |
2638bc39 | 522 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
43f66a6c | 523 | u32 dif_len = addr - aligned_addr; |
43f66a6c | 524 | u32 i; |
bf79451e | 525 | |
43f66a6c | 526 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
bf79451e | 527 | |
ea2b26e0 JK |
528 | if (num <= 0) { |
529 | return; | |
530 | } | |
531 | ||
c8fe6679 | 532 | /* Write the first dword (or portion) byte by byte */ |
43f66a6c | 533 | if (unlikely(dif_len)) { |
b095c381 | 534 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
c8fe6679 | 535 | /* Start writing at aligned_addr + dif_len */ |
ea2b26e0 | 536 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) |
b095c381 | 537 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
43f66a6c JK |
538 | aligned_addr += 4; |
539 | } | |
bf79451e | 540 | |
c8fe6679 | 541 | /* Write all of the middle dwords as dwords, with auto-increment */ |
b095c381 | 542 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
ea2b26e0 | 543 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
b095c381 | 544 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); |
bf79451e | 545 | |
c8fe6679 | 546 | /* Write the last dword (or portion) byte by byte */ |
ea2b26e0 | 547 | if (unlikely(num)) { |
b095c381 | 548 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
ea2b26e0 | 549 | for (i = 0; num > 0; i++, num--, buf++) |
b095c381 | 550 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
ea2b26e0 | 551 | } |
43f66a6c JK |
552 | } |
553 | ||
c8fe6679 ZY |
554 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
555 | /* for 1st 4K of SRAM/regs space */ | |
bf79451e | 556 | static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf, |
43f66a6c JK |
557 | int num) |
558 | { | |
559 | memcpy_toio((priv->hw_base + addr), buf, num); | |
560 | } | |
561 | ||
c8fe6679 | 562 | /* Set bit(s) in low 4K of SRAM/regs */ |
43f66a6c JK |
563 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
564 | { | |
565 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); | |
566 | } | |
567 | ||
c8fe6679 | 568 | /* Clear bit(s) in low 4K of SRAM/regs */ |
43f66a6c JK |
569 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
570 | { | |
571 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); | |
572 | } | |
573 | ||
89c318ed | 574 | static inline void __ipw_enable_interrupts(struct ipw_priv *priv) |
43f66a6c JK |
575 | { |
576 | if (priv->status & STATUS_INT_ENABLED) | |
577 | return; | |
578 | priv->status |= STATUS_INT_ENABLED; | |
b095c381 | 579 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); |
43f66a6c JK |
580 | } |
581 | ||
89c318ed | 582 | static inline void __ipw_disable_interrupts(struct ipw_priv *priv) |
43f66a6c JK |
583 | { |
584 | if (!(priv->status & STATUS_INT_ENABLED)) | |
585 | return; | |
586 | priv->status &= ~STATUS_INT_ENABLED; | |
b095c381 | 587 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
43f66a6c JK |
588 | } |
589 | ||
89c318ed ZY |
590 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) |
591 | { | |
592 | unsigned long flags; | |
593 | ||
594 | spin_lock_irqsave(&priv->irq_lock, flags); | |
595 | __ipw_enable_interrupts(priv); | |
596 | spin_unlock_irqrestore(&priv->irq_lock, flags); | |
597 | } | |
598 | ||
599 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) | |
600 | { | |
601 | unsigned long flags; | |
602 | ||
603 | spin_lock_irqsave(&priv->irq_lock, flags); | |
604 | __ipw_disable_interrupts(priv); | |
605 | spin_unlock_irqrestore(&priv->irq_lock, flags); | |
606 | } | |
607 | ||
43f66a6c JK |
608 | static char *ipw_error_desc(u32 val) |
609 | { | |
610 | switch (val) { | |
bf79451e | 611 | case IPW_FW_ERROR_OK: |
43f66a6c | 612 | return "ERROR_OK"; |
bf79451e | 613 | case IPW_FW_ERROR_FAIL: |
43f66a6c | 614 | return "ERROR_FAIL"; |
bf79451e | 615 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
43f66a6c | 616 | return "MEMORY_UNDERFLOW"; |
bf79451e | 617 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
43f66a6c | 618 | return "MEMORY_OVERFLOW"; |
bf79451e | 619 | case IPW_FW_ERROR_BAD_PARAM: |
b095c381 | 620 | return "BAD_PARAM"; |
bf79451e | 621 | case IPW_FW_ERROR_BAD_CHECKSUM: |
b095c381 | 622 | return "BAD_CHECKSUM"; |
bf79451e | 623 | case IPW_FW_ERROR_NMI_INTERRUPT: |
b095c381 | 624 | return "NMI_INTERRUPT"; |
bf79451e | 625 | case IPW_FW_ERROR_BAD_DATABASE: |
b095c381 | 626 | return "BAD_DATABASE"; |
bf79451e | 627 | case IPW_FW_ERROR_ALLOC_FAIL: |
b095c381 | 628 | return "ALLOC_FAIL"; |
bf79451e | 629 | case IPW_FW_ERROR_DMA_UNDERRUN: |
b095c381 | 630 | return "DMA_UNDERRUN"; |
bf79451e | 631 | case IPW_FW_ERROR_DMA_STATUS: |
b095c381 JK |
632 | return "DMA_STATUS"; |
633 | case IPW_FW_ERROR_DINO_ERROR: | |
634 | return "DINO_ERROR"; | |
635 | case IPW_FW_ERROR_EEPROM_ERROR: | |
636 | return "EEPROM_ERROR"; | |
bf79451e | 637 | case IPW_FW_ERROR_SYSASSERT: |
b095c381 | 638 | return "SYSASSERT"; |
bf79451e | 639 | case IPW_FW_ERROR_FATAL_ERROR: |
b095c381 | 640 | return "FATAL_ERROR"; |
bf79451e | 641 | default: |
b095c381 | 642 | return "UNKNOWN_ERROR"; |
43f66a6c JK |
643 | } |
644 | } | |
645 | ||
b39860c6 JK |
646 | static void ipw_dump_error_log(struct ipw_priv *priv, |
647 | struct ipw_fw_error *error) | |
43f66a6c | 648 | { |
b39860c6 | 649 | u32 i; |
bf79451e | 650 | |
b39860c6 JK |
651 | if (!error) { |
652 | IPW_ERROR("Error allocating and capturing error log. " | |
653 | "Nothing to dump.\n"); | |
654 | return; | |
43f66a6c JK |
655 | } |
656 | ||
b39860c6 JK |
657 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
658 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", | |
659 | error->status, error->config); | |
43f66a6c | 660 | |
b39860c6 | 661 | for (i = 0; i < error->elem_len; i++) |
0edd5b44 | 662 | IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", |
b39860c6 JK |
663 | ipw_error_desc(error->elem[i].desc), |
664 | error->elem[i].time, | |
665 | error->elem[i].blink1, | |
666 | error->elem[i].blink2, | |
667 | error->elem[i].link1, | |
668 | error->elem[i].link2, error->elem[i].data); | |
669 | for (i = 0; i < error->log_len; i++) | |
670 | IPW_ERROR("%i\t0x%08x\t%i\n", | |
671 | error->log[i].time, | |
286568ab | 672 | error->log[i].data, error->log[i].event); |
43f66a6c JK |
673 | } |
674 | ||
c848d0af | 675 | static inline int ipw_is_init(struct ipw_priv *priv) |
43f66a6c | 676 | { |
c848d0af | 677 | return (priv->status & STATUS_INIT) ? 1 : 0; |
43f66a6c JK |
678 | } |
679 | ||
0edd5b44 | 680 | static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len) |
43f66a6c JK |
681 | { |
682 | u32 addr, field_info, field_len, field_count, total_len; | |
683 | ||
684 | IPW_DEBUG_ORD("ordinal = %i\n", ord); | |
685 | ||
686 | if (!priv || !val || !len) { | |
687 | IPW_DEBUG_ORD("Invalid argument\n"); | |
688 | return -EINVAL; | |
689 | } | |
bf79451e | 690 | |
43f66a6c JK |
691 | /* verify device ordinal tables have been initialized */ |
692 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { | |
693 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); | |
694 | return -EINVAL; | |
695 | } | |
696 | ||
697 | switch (IPW_ORD_TABLE_ID_MASK & ord) { | |
698 | case IPW_ORD_TABLE_0_MASK: | |
699 | /* | |
700 | * TABLE 0: Direct access to a table of 32 bit values | |
701 | * | |
bf79451e | 702 | * This is a very simple table with the data directly |
43f66a6c JK |
703 | * read from the table |
704 | */ | |
705 | ||
706 | /* remove the table id from the ordinal */ | |
707 | ord &= IPW_ORD_TABLE_VALUE_MASK; | |
708 | ||
709 | /* boundary check */ | |
710 | if (ord > priv->table0_len) { | |
711 | IPW_DEBUG_ORD("ordinal value (%i) longer then " | |
712 | "max (%i)\n", ord, priv->table0_len); | |
713 | return -EINVAL; | |
714 | } | |
715 | ||
716 | /* verify we have enough room to store the value */ | |
717 | if (*len < sizeof(u32)) { | |
718 | IPW_DEBUG_ORD("ordinal buffer length too small, " | |
aaa4d308 | 719 | "need %zd\n", sizeof(u32)); |
43f66a6c JK |
720 | return -EINVAL; |
721 | } | |
722 | ||
723 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", | |
0edd5b44 | 724 | ord, priv->table0_addr + (ord << 2)); |
43f66a6c JK |
725 | |
726 | *len = sizeof(u32); | |
727 | ord <<= 2; | |
0edd5b44 | 728 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
43f66a6c JK |
729 | break; |
730 | ||
731 | case IPW_ORD_TABLE_1_MASK: | |
732 | /* | |
733 | * TABLE 1: Indirect access to a table of 32 bit values | |
bf79451e JG |
734 | * |
735 | * This is a fairly large table of u32 values each | |
43f66a6c JK |
736 | * representing starting addr for the data (which is |
737 | * also a u32) | |
738 | */ | |
739 | ||
740 | /* remove the table id from the ordinal */ | |
741 | ord &= IPW_ORD_TABLE_VALUE_MASK; | |
bf79451e | 742 | |
43f66a6c JK |
743 | /* boundary check */ |
744 | if (ord > priv->table1_len) { | |
745 | IPW_DEBUG_ORD("ordinal value too long\n"); | |
746 | return -EINVAL; | |
747 | } | |
748 | ||
749 | /* verify we have enough room to store the value */ | |
750 | if (*len < sizeof(u32)) { | |
751 | IPW_DEBUG_ORD("ordinal buffer length too small, " | |
aaa4d308 | 752 | "need %zd\n", sizeof(u32)); |
43f66a6c JK |
753 | return -EINVAL; |
754 | } | |
755 | ||
0edd5b44 JG |
756 | *((u32 *) val) = |
757 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); | |
43f66a6c JK |
758 | *len = sizeof(u32); |
759 | break; | |
760 | ||
761 | case IPW_ORD_TABLE_2_MASK: | |
762 | /* | |
763 | * TABLE 2: Indirect access to a table of variable sized values | |
764 | * | |
765 | * This table consist of six values, each containing | |
766 | * - dword containing the starting offset of the data | |
767 | * - dword containing the lengh in the first 16bits | |
768 | * and the count in the second 16bits | |
769 | */ | |
770 | ||
771 | /* remove the table id from the ordinal */ | |
772 | ord &= IPW_ORD_TABLE_VALUE_MASK; | |
773 | ||
774 | /* boundary check */ | |
775 | if (ord > priv->table2_len) { | |
776 | IPW_DEBUG_ORD("ordinal value too long\n"); | |
777 | return -EINVAL; | |
778 | } | |
779 | ||
780 | /* get the address of statistic */ | |
781 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); | |
bf79451e JG |
782 | |
783 | /* get the second DW of statistics ; | |
43f66a6c | 784 | * two 16-bit words - first is length, second is count */ |
0edd5b44 JG |
785 | field_info = |
786 | ipw_read_reg32(priv, | |
787 | priv->table2_addr + (ord << 3) + | |
788 | sizeof(u32)); | |
bf79451e | 789 | |
43f66a6c | 790 | /* get each entry length */ |
0edd5b44 | 791 | field_len = *((u16 *) & field_info); |
bf79451e | 792 | |
43f66a6c | 793 | /* get number of entries */ |
0edd5b44 | 794 | field_count = *(((u16 *) & field_info) + 1); |
bf79451e | 795 | |
af901ca1 | 796 | /* abort if not enough memory */ |
43f66a6c JK |
797 | total_len = field_len * field_count; |
798 | if (total_len > *len) { | |
799 | *len = total_len; | |
800 | return -EINVAL; | |
801 | } | |
bf79451e | 802 | |
43f66a6c JK |
803 | *len = total_len; |
804 | if (!total_len) | |
805 | return 0; | |
806 | ||
807 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " | |
bf79451e | 808 | "field_info = 0x%08x\n", |
43f66a6c JK |
809 | addr, total_len, field_info); |
810 | ipw_read_indirect(priv, addr, val, total_len); | |
811 | break; | |
812 | ||
813 | default: | |
814 | IPW_DEBUG_ORD("Invalid ordinal!\n"); | |
815 | return -EINVAL; | |
816 | ||
817 | } | |
818 | ||
43f66a6c JK |
819 | return 0; |
820 | } | |
821 | ||
822 | static void ipw_init_ordinals(struct ipw_priv *priv) | |
823 | { | |
824 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; | |
bf79451e | 825 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
43f66a6c JK |
826 | |
827 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", | |
828 | priv->table0_addr, priv->table0_len); | |
829 | ||
830 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); | |
831 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); | |
832 | ||
833 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", | |
834 | priv->table1_addr, priv->table1_len); | |
835 | ||
836 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); | |
837 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); | |
0edd5b44 | 838 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
43f66a6c JK |
839 | |
840 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", | |
841 | priv->table2_addr, priv->table2_len); | |
842 | ||
843 | } | |
844 | ||
a73e22b2 | 845 | static u32 ipw_register_toggle(u32 reg) |
a613bffd | 846 | { |
b095c381 JK |
847 | reg &= ~IPW_START_STANDBY; |
848 | if (reg & IPW_GATE_ODMA) | |
849 | reg &= ~IPW_GATE_ODMA; | |
850 | if (reg & IPW_GATE_IDMA) | |
851 | reg &= ~IPW_GATE_IDMA; | |
852 | if (reg & IPW_GATE_ADMA) | |
853 | reg &= ~IPW_GATE_ADMA; | |
a613bffd JK |
854 | return reg; |
855 | } | |
856 | ||
857 | /* | |
858 | * LED behavior: | |
859 | * - On radio ON, turn on any LEDs that require to be on during start | |
860 | * - On initialization, start unassociated blink | |
861 | * - On association, disable unassociated blink | |
862 | * - On disassociation, start unassociated blink | |
863 | * - On radio OFF, turn off any LEDs started during radio on | |
864 | * | |
865 | */ | |
ede6111c ZY |
866 | #define LD_TIME_LINK_ON msecs_to_jiffies(300) |
867 | #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) | |
868 | #define LD_TIME_ACT_ON msecs_to_jiffies(250) | |
a613bffd | 869 | |
a73e22b2 | 870 | static void ipw_led_link_on(struct ipw_priv *priv) |
a613bffd JK |
871 | { |
872 | unsigned long flags; | |
873 | u32 led; | |
874 | ||
875 | /* If configured to not use LEDs, or nic_type is 1, | |
876 | * then we don't toggle a LINK led */ | |
877 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) | |
878 | return; | |
879 | ||
880 | spin_lock_irqsave(&priv->lock, flags); | |
881 | ||
882 | if (!(priv->status & STATUS_RF_KILL_MASK) && | |
883 | !(priv->status & STATUS_LED_LINK_ON)) { | |
884 | IPW_DEBUG_LED("Link LED On\n"); | |
b095c381 | 885 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
886 | led |= priv->led_association_on; |
887 | ||
888 | led = ipw_register_toggle(led); | |
889 | ||
890 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 891 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
892 | |
893 | priv->status |= STATUS_LED_LINK_ON; | |
894 | ||
895 | /* If we aren't associated, schedule turning the LED off */ | |
896 | if (!(priv->status & STATUS_ASSOCIATED)) | |
897 | queue_delayed_work(priv->workqueue, | |
898 | &priv->led_link_off, | |
899 | LD_TIME_LINK_ON); | |
900 | } | |
901 | ||
902 | spin_unlock_irqrestore(&priv->lock, flags); | |
903 | } | |
904 | ||
c4028958 | 905 | static void ipw_bg_led_link_on(struct work_struct *work) |
c848d0af | 906 | { |
c4028958 DH |
907 | struct ipw_priv *priv = |
908 | container_of(work, struct ipw_priv, led_link_on.work); | |
4644151b | 909 | mutex_lock(&priv->mutex); |
c4028958 | 910 | ipw_led_link_on(priv); |
4644151b | 911 | mutex_unlock(&priv->mutex); |
c848d0af JK |
912 | } |
913 | ||
a73e22b2 | 914 | static void ipw_led_link_off(struct ipw_priv *priv) |
a613bffd JK |
915 | { |
916 | unsigned long flags; | |
917 | u32 led; | |
918 | ||
919 | /* If configured not to use LEDs, or nic type is 1, | |
920 | * then we don't goggle the LINK led. */ | |
921 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) | |
922 | return; | |
923 | ||
924 | spin_lock_irqsave(&priv->lock, flags); | |
925 | ||
926 | if (priv->status & STATUS_LED_LINK_ON) { | |
b095c381 | 927 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
928 | led &= priv->led_association_off; |
929 | led = ipw_register_toggle(led); | |
930 | ||
931 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 932 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
933 | |
934 | IPW_DEBUG_LED("Link LED Off\n"); | |
935 | ||
936 | priv->status &= ~STATUS_LED_LINK_ON; | |
937 | ||
938 | /* If we aren't associated and the radio is on, schedule | |
939 | * turning the LED on (blink while unassociated) */ | |
940 | if (!(priv->status & STATUS_RF_KILL_MASK) && | |
941 | !(priv->status & STATUS_ASSOCIATED)) | |
942 | queue_delayed_work(priv->workqueue, &priv->led_link_on, | |
943 | LD_TIME_LINK_OFF); | |
944 | ||
945 | } | |
946 | ||
947 | spin_unlock_irqrestore(&priv->lock, flags); | |
948 | } | |
949 | ||
c4028958 | 950 | static void ipw_bg_led_link_off(struct work_struct *work) |
c848d0af | 951 | { |
c4028958 DH |
952 | struct ipw_priv *priv = |
953 | container_of(work, struct ipw_priv, led_link_off.work); | |
4644151b | 954 | mutex_lock(&priv->mutex); |
c4028958 | 955 | ipw_led_link_off(priv); |
4644151b | 956 | mutex_unlock(&priv->mutex); |
c848d0af JK |
957 | } |
958 | ||
858119e1 | 959 | static void __ipw_led_activity_on(struct ipw_priv *priv) |
a613bffd | 960 | { |
a613bffd JK |
961 | u32 led; |
962 | ||
963 | if (priv->config & CFG_NO_LED) | |
964 | return; | |
965 | ||
b095c381 | 966 | if (priv->status & STATUS_RF_KILL_MASK) |
a613bffd | 967 | return; |
a613bffd JK |
968 | |
969 | if (!(priv->status & STATUS_LED_ACT_ON)) { | |
b095c381 | 970 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
971 | led |= priv->led_activity_on; |
972 | ||
973 | led = ipw_register_toggle(led); | |
974 | ||
975 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 976 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
977 | |
978 | IPW_DEBUG_LED("Activity LED On\n"); | |
979 | ||
980 | priv->status |= STATUS_LED_ACT_ON; | |
981 | ||
c848d0af | 982 | cancel_delayed_work(&priv->led_act_off); |
a613bffd JK |
983 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
984 | LD_TIME_ACT_ON); | |
985 | } else { | |
986 | /* Reschedule LED off for full time period */ | |
987 | cancel_delayed_work(&priv->led_act_off); | |
988 | queue_delayed_work(priv->workqueue, &priv->led_act_off, | |
989 | LD_TIME_ACT_ON); | |
990 | } | |
b095c381 | 991 | } |
a613bffd | 992 | |
a73e22b2 | 993 | #if 0 |
b095c381 JK |
994 | void ipw_led_activity_on(struct ipw_priv *priv) |
995 | { | |
996 | unsigned long flags; | |
997 | spin_lock_irqsave(&priv->lock, flags); | |
998 | __ipw_led_activity_on(priv); | |
a613bffd JK |
999 | spin_unlock_irqrestore(&priv->lock, flags); |
1000 | } | |
a73e22b2 | 1001 | #endif /* 0 */ |
a613bffd | 1002 | |
a73e22b2 | 1003 | static void ipw_led_activity_off(struct ipw_priv *priv) |
a613bffd JK |
1004 | { |
1005 | unsigned long flags; | |
1006 | u32 led; | |
1007 | ||
1008 | if (priv->config & CFG_NO_LED) | |
1009 | return; | |
1010 | ||
1011 | spin_lock_irqsave(&priv->lock, flags); | |
1012 | ||
1013 | if (priv->status & STATUS_LED_ACT_ON) { | |
b095c381 | 1014 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
1015 | led &= priv->led_activity_off; |
1016 | ||
1017 | led = ipw_register_toggle(led); | |
1018 | ||
1019 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 1020 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
1021 | |
1022 | IPW_DEBUG_LED("Activity LED Off\n"); | |
1023 | ||
1024 | priv->status &= ~STATUS_LED_ACT_ON; | |
1025 | } | |
1026 | ||
1027 | spin_unlock_irqrestore(&priv->lock, flags); | |
1028 | } | |
1029 | ||
c4028958 | 1030 | static void ipw_bg_led_activity_off(struct work_struct *work) |
c848d0af | 1031 | { |
c4028958 DH |
1032 | struct ipw_priv *priv = |
1033 | container_of(work, struct ipw_priv, led_act_off.work); | |
4644151b | 1034 | mutex_lock(&priv->mutex); |
c4028958 | 1035 | ipw_led_activity_off(priv); |
4644151b | 1036 | mutex_unlock(&priv->mutex); |
c848d0af JK |
1037 | } |
1038 | ||
a73e22b2 | 1039 | static void ipw_led_band_on(struct ipw_priv *priv) |
a613bffd JK |
1040 | { |
1041 | unsigned long flags; | |
1042 | u32 led; | |
1043 | ||
1044 | /* Only nic type 1 supports mode LEDs */ | |
c848d0af JK |
1045 | if (priv->config & CFG_NO_LED || |
1046 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) | |
a613bffd JK |
1047 | return; |
1048 | ||
1049 | spin_lock_irqsave(&priv->lock, flags); | |
1050 | ||
b095c381 | 1051 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
1052 | if (priv->assoc_network->mode == IEEE_A) { |
1053 | led |= priv->led_ofdm_on; | |
1054 | led &= priv->led_association_off; | |
1055 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); | |
1056 | } else if (priv->assoc_network->mode == IEEE_G) { | |
1057 | led |= priv->led_ofdm_on; | |
1058 | led |= priv->led_association_on; | |
1059 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); | |
1060 | } else { | |
1061 | led &= priv->led_ofdm_off; | |
1062 | led |= priv->led_association_on; | |
1063 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); | |
1064 | } | |
1065 | ||
1066 | led = ipw_register_toggle(led); | |
1067 | ||
1068 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 1069 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
1070 | |
1071 | spin_unlock_irqrestore(&priv->lock, flags); | |
1072 | } | |
1073 | ||
a73e22b2 | 1074 | static void ipw_led_band_off(struct ipw_priv *priv) |
a613bffd JK |
1075 | { |
1076 | unsigned long flags; | |
1077 | u32 led; | |
1078 | ||
1079 | /* Only nic type 1 supports mode LEDs */ | |
1080 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) | |
1081 | return; | |
1082 | ||
1083 | spin_lock_irqsave(&priv->lock, flags); | |
1084 | ||
b095c381 | 1085 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
1086 | led &= priv->led_ofdm_off; |
1087 | led &= priv->led_association_off; | |
1088 | ||
1089 | led = ipw_register_toggle(led); | |
1090 | ||
1091 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 1092 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
1093 | |
1094 | spin_unlock_irqrestore(&priv->lock, flags); | |
1095 | } | |
1096 | ||
a73e22b2 | 1097 | static void ipw_led_radio_on(struct ipw_priv *priv) |
a613bffd JK |
1098 | { |
1099 | ipw_led_link_on(priv); | |
1100 | } | |
1101 | ||
a73e22b2 | 1102 | static void ipw_led_radio_off(struct ipw_priv *priv) |
a613bffd JK |
1103 | { |
1104 | ipw_led_activity_off(priv); | |
1105 | ipw_led_link_off(priv); | |
1106 | } | |
1107 | ||
a73e22b2 | 1108 | static void ipw_led_link_up(struct ipw_priv *priv) |
a613bffd JK |
1109 | { |
1110 | /* Set the Link Led on for all nic types */ | |
1111 | ipw_led_link_on(priv); | |
1112 | } | |
1113 | ||
a73e22b2 | 1114 | static void ipw_led_link_down(struct ipw_priv *priv) |
a613bffd JK |
1115 | { |
1116 | ipw_led_activity_off(priv); | |
1117 | ipw_led_link_off(priv); | |
1118 | ||
1119 | if (priv->status & STATUS_RF_KILL_MASK) | |
1120 | ipw_led_radio_off(priv); | |
1121 | } | |
1122 | ||
a73e22b2 | 1123 | static void ipw_led_init(struct ipw_priv *priv) |
a613bffd JK |
1124 | { |
1125 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; | |
1126 | ||
1127 | /* Set the default PINs for the link and activity leds */ | |
b095c381 JK |
1128 | priv->led_activity_on = IPW_ACTIVITY_LED; |
1129 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); | |
a613bffd | 1130 | |
b095c381 JK |
1131 | priv->led_association_on = IPW_ASSOCIATED_LED; |
1132 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); | |
a613bffd JK |
1133 | |
1134 | /* Set the default PINs for the OFDM leds */ | |
b095c381 JK |
1135 | priv->led_ofdm_on = IPW_OFDM_LED; |
1136 | priv->led_ofdm_off = ~(IPW_OFDM_LED); | |
a613bffd JK |
1137 | |
1138 | switch (priv->nic_type) { | |
1139 | case EEPROM_NIC_TYPE_1: | |
1140 | /* In this NIC type, the LEDs are reversed.... */ | |
b095c381 JK |
1141 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
1142 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); | |
1143 | priv->led_association_on = IPW_ACTIVITY_LED; | |
1144 | priv->led_association_off = ~(IPW_ACTIVITY_LED); | |
a613bffd JK |
1145 | |
1146 | if (!(priv->config & CFG_NO_LED)) | |
1147 | ipw_led_band_on(priv); | |
1148 | ||
1149 | /* And we don't blink link LEDs for this nic, so | |
1150 | * just return here */ | |
1151 | return; | |
1152 | ||
1153 | case EEPROM_NIC_TYPE_3: | |
1154 | case EEPROM_NIC_TYPE_2: | |
1155 | case EEPROM_NIC_TYPE_4: | |
1156 | case EEPROM_NIC_TYPE_0: | |
1157 | break; | |
1158 | ||
1159 | default: | |
1160 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", | |
1161 | priv->nic_type); | |
1162 | priv->nic_type = EEPROM_NIC_TYPE_0; | |
1163 | break; | |
1164 | } | |
1165 | ||
1166 | if (!(priv->config & CFG_NO_LED)) { | |
1167 | if (priv->status & STATUS_ASSOCIATED) | |
1168 | ipw_led_link_on(priv); | |
1169 | else | |
1170 | ipw_led_link_off(priv); | |
1171 | } | |
1172 | } | |
1173 | ||
a73e22b2 | 1174 | static void ipw_led_shutdown(struct ipw_priv *priv) |
a613bffd | 1175 | { |
a613bffd JK |
1176 | ipw_led_activity_off(priv); |
1177 | ipw_led_link_off(priv); | |
1178 | ipw_led_band_off(priv); | |
afbf30a2 JK |
1179 | cancel_delayed_work(&priv->led_link_on); |
1180 | cancel_delayed_work(&priv->led_link_off); | |
1181 | cancel_delayed_work(&priv->led_act_off); | |
a613bffd JK |
1182 | } |
1183 | ||
43f66a6c JK |
1184 | /* |
1185 | * The following adds a new attribute to the sysfs representation | |
1186 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) | |
1187 | * used for controling the debug level. | |
bf79451e | 1188 | * |
43f66a6c JK |
1189 | * See the level definitions in ipw for details. |
1190 | */ | |
1191 | static ssize_t show_debug_level(struct device_driver *d, char *buf) | |
1192 | { | |
1193 | return sprintf(buf, "0x%08X\n", ipw_debug_level); | |
1194 | } | |
a613bffd JK |
1195 | |
1196 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, | |
1197 | size_t count) | |
43f66a6c JK |
1198 | { |
1199 | char *p = (char *)buf; | |
1200 | u32 val; | |
1201 | ||
1202 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | |
1203 | p++; | |
1204 | if (p[0] == 'x' || p[0] == 'X') | |
1205 | p++; | |
1206 | val = simple_strtoul(p, &p, 16); | |
1207 | } else | |
1208 | val = simple_strtoul(p, &p, 10); | |
bf79451e JG |
1209 | if (p == buf) |
1210 | printk(KERN_INFO DRV_NAME | |
43f66a6c JK |
1211 | ": %s is not in hex or decimal form.\n", buf); |
1212 | else | |
1213 | ipw_debug_level = val; | |
1214 | ||
1215 | return strnlen(buf, count); | |
1216 | } | |
1217 | ||
bf79451e | 1218 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
43f66a6c JK |
1219 | show_debug_level, store_debug_level); |
1220 | ||
b39860c6 | 1221 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) |
43f66a6c | 1222 | { |
c8fe6679 | 1223 | /* length = 1st dword in log */ |
b39860c6 | 1224 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); |
43f66a6c | 1225 | } |
0edd5b44 | 1226 | |
b39860c6 JK |
1227 | static void ipw_capture_event_log(struct ipw_priv *priv, |
1228 | u32 log_len, struct ipw_event *log) | |
43f66a6c | 1229 | { |
b39860c6 | 1230 | u32 base; |
0edd5b44 | 1231 | |
b39860c6 JK |
1232 | if (log_len) { |
1233 | base = ipw_read32(priv, IPW_EVENT_LOG); | |
1234 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), | |
1235 | (u8 *) log, sizeof(*log) * log_len); | |
1236 | } | |
1237 | } | |
43f66a6c | 1238 | |
b39860c6 | 1239 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) |
43f66a6c | 1240 | { |
b39860c6 JK |
1241 | struct ipw_fw_error *error; |
1242 | u32 log_len = ipw_get_event_log_len(priv); | |
1243 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); | |
1244 | u32 elem_len = ipw_read_reg32(priv, base); | |
43f66a6c | 1245 | |
b39860c6 JK |
1246 | error = kmalloc(sizeof(*error) + |
1247 | sizeof(*error->elem) * elem_len + | |
1248 | sizeof(*error->log) * log_len, GFP_ATOMIC); | |
1249 | if (!error) { | |
1250 | IPW_ERROR("Memory allocation for firmware error log " | |
1251 | "failed.\n"); | |
1252 | return NULL; | |
43f66a6c | 1253 | } |
f6c5cb7c | 1254 | error->jiffies = jiffies; |
b39860c6 JK |
1255 | error->status = priv->status; |
1256 | error->config = priv->config; | |
1257 | error->elem_len = elem_len; | |
1258 | error->log_len = log_len; | |
1259 | error->elem = (struct ipw_error_elem *)error->payload; | |
3b26b110 | 1260 | error->log = (struct ipw_event *)(error->elem + elem_len); |
b39860c6 JK |
1261 | |
1262 | ipw_capture_event_log(priv, log_len, error->log); | |
bf79451e | 1263 | |
b39860c6 JK |
1264 | if (elem_len) |
1265 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, | |
1266 | sizeof(*error->elem) * elem_len); | |
1267 | ||
1268 | return error; | |
43f66a6c | 1269 | } |
0edd5b44 | 1270 | |
b39860c6 JK |
1271 | static ssize_t show_event_log(struct device *d, |
1272 | struct device_attribute *attr, char *buf) | |
43f66a6c | 1273 | { |
b39860c6 JK |
1274 | struct ipw_priv *priv = dev_get_drvdata(d); |
1275 | u32 log_len = ipw_get_event_log_len(priv); | |
412e9e78 RC |
1276 | u32 log_size; |
1277 | struct ipw_event *log; | |
b39860c6 | 1278 | u32 len = 0, i; |
43f66a6c | 1279 | |
412e9e78 RC |
1280 | /* not using min() because of its strict type checking */ |
1281 | log_size = PAGE_SIZE / sizeof(*log) > log_len ? | |
1282 | sizeof(*log) * log_len : PAGE_SIZE; | |
1283 | log = kzalloc(log_size, GFP_KERNEL); | |
1284 | if (!log) { | |
1285 | IPW_ERROR("Unable to allocate memory for log\n"); | |
1286 | return 0; | |
1287 | } | |
1288 | log_len = log_size / sizeof(*log); | |
b39860c6 | 1289 | ipw_capture_event_log(priv, log_len, log); |
43f66a6c | 1290 | |
b39860c6 JK |
1291 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); |
1292 | for (i = 0; i < log_len; i++) | |
1293 | len += snprintf(buf + len, PAGE_SIZE - len, | |
1294 | "\n%08X%08X%08X", | |
1295 | log[i].time, log[i].event, log[i].data); | |
1296 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
412e9e78 | 1297 | kfree(log); |
b39860c6 | 1298 | return len; |
43f66a6c | 1299 | } |
0edd5b44 | 1300 | |
b39860c6 | 1301 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); |
43f66a6c | 1302 | |
b39860c6 JK |
1303 | static ssize_t show_error(struct device *d, |
1304 | struct device_attribute *attr, char *buf) | |
43f66a6c | 1305 | { |
b39860c6 JK |
1306 | struct ipw_priv *priv = dev_get_drvdata(d); |
1307 | u32 len = 0, i; | |
1308 | if (!priv->error) | |
1309 | return 0; | |
1310 | len += snprintf(buf + len, PAGE_SIZE - len, | |
f6c5cb7c JK |
1311 | "%08lX%08X%08X%08X", |
1312 | priv->error->jiffies, | |
b39860c6 JK |
1313 | priv->error->status, |
1314 | priv->error->config, priv->error->elem_len); | |
1315 | for (i = 0; i < priv->error->elem_len; i++) | |
1316 | len += snprintf(buf + len, PAGE_SIZE - len, | |
1317 | "\n%08X%08X%08X%08X%08X%08X%08X", | |
1318 | priv->error->elem[i].time, | |
1319 | priv->error->elem[i].desc, | |
1320 | priv->error->elem[i].blink1, | |
1321 | priv->error->elem[i].blink2, | |
1322 | priv->error->elem[i].link1, | |
1323 | priv->error->elem[i].link2, | |
1324 | priv->error->elem[i].data); | |
1325 | ||
1326 | len += snprintf(buf + len, PAGE_SIZE - len, | |
1327 | "\n%08X", priv->error->log_len); | |
1328 | for (i = 0; i < priv->error->log_len; i++) | |
1329 | len += snprintf(buf + len, PAGE_SIZE - len, | |
1330 | "\n%08X%08X%08X", | |
1331 | priv->error->log[i].time, | |
1332 | priv->error->log[i].event, | |
1333 | priv->error->log[i].data); | |
1334 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
1335 | return len; | |
1336 | } | |
1337 | ||
1338 | static ssize_t clear_error(struct device *d, | |
1339 | struct device_attribute *attr, | |
1340 | const char *buf, size_t count) | |
1341 | { | |
1342 | struct ipw_priv *priv = dev_get_drvdata(d); | |
8f760780 JJ |
1343 | |
1344 | kfree(priv->error); | |
1345 | priv->error = NULL; | |
b39860c6 JK |
1346 | return count; |
1347 | } | |
43f66a6c | 1348 | |
b39860c6 | 1349 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); |
43f66a6c | 1350 | |
f6c5cb7c JK |
1351 | static ssize_t show_cmd_log(struct device *d, |
1352 | struct device_attribute *attr, char *buf) | |
1353 | { | |
1354 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1355 | u32 len = 0, i; | |
1356 | if (!priv->cmdlog) | |
1357 | return 0; | |
1358 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; | |
1359 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); | |
1360 | i = (i + 1) % priv->cmdlog_len) { | |
1361 | len += | |
1362 | snprintf(buf + len, PAGE_SIZE - len, | |
1363 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, | |
1364 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, | |
1365 | priv->cmdlog[i].cmd.len); | |
1366 | len += | |
1367 | snprintk_buf(buf + len, PAGE_SIZE - len, | |
1368 | (u8 *) priv->cmdlog[i].cmd.param, | |
1369 | priv->cmdlog[i].cmd.len); | |
1370 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
1371 | } | |
1372 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
1373 | return len; | |
43f66a6c | 1374 | } |
0edd5b44 | 1375 | |
f6c5cb7c | 1376 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); |
43f66a6c | 1377 | |
d685b8c2 ZY |
1378 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
1379 | static void ipw_prom_free(struct ipw_priv *priv); | |
1380 | static int ipw_prom_alloc(struct ipw_priv *priv); | |
1381 | static ssize_t store_rtap_iface(struct device *d, | |
1382 | struct device_attribute *attr, | |
1383 | const char *buf, size_t count) | |
1384 | { | |
1385 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1386 | int rc = 0; | |
1387 | ||
1388 | if (count < 1) | |
1389 | return -EINVAL; | |
1390 | ||
1391 | switch (buf[0]) { | |
1392 | case '0': | |
1393 | if (!rtap_iface) | |
1394 | return count; | |
1395 | ||
1396 | if (netif_running(priv->prom_net_dev)) { | |
1397 | IPW_WARNING("Interface is up. Cannot unregister.\n"); | |
1398 | return count; | |
1399 | } | |
1400 | ||
1401 | ipw_prom_free(priv); | |
1402 | rtap_iface = 0; | |
1403 | break; | |
1404 | ||
1405 | case '1': | |
1406 | if (rtap_iface) | |
1407 | return count; | |
1408 | ||
1409 | rc = ipw_prom_alloc(priv); | |
1410 | if (!rc) | |
1411 | rtap_iface = 1; | |
1412 | break; | |
1413 | ||
1414 | default: | |
1415 | return -EINVAL; | |
1416 | } | |
1417 | ||
1418 | if (rc) { | |
1419 | IPW_ERROR("Failed to register promiscuous network " | |
1420 | "device (error %d).\n", rc); | |
1421 | } | |
1422 | ||
1423 | return count; | |
1424 | } | |
1425 | ||
1426 | static ssize_t show_rtap_iface(struct device *d, | |
1427 | struct device_attribute *attr, | |
1428 | char *buf) | |
1429 | { | |
1430 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1431 | if (rtap_iface) | |
1432 | return sprintf(buf, "%s", priv->prom_net_dev->name); | |
1433 | else { | |
1434 | buf[0] = '-'; | |
1435 | buf[1] = '1'; | |
1436 | buf[2] = '\0'; | |
1437 | return 3; | |
1438 | } | |
1439 | } | |
1440 | ||
1441 | static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface, | |
1442 | store_rtap_iface); | |
1443 | ||
1444 | static ssize_t store_rtap_filter(struct device *d, | |
1445 | struct device_attribute *attr, | |
1446 | const char *buf, size_t count) | |
1447 | { | |
1448 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1449 | ||
1450 | if (!priv->prom_priv) { | |
1451 | IPW_ERROR("Attempting to set filter without " | |
1452 | "rtap_iface enabled.\n"); | |
1453 | return -EPERM; | |
1454 | } | |
1455 | ||
1456 | priv->prom_priv->filter = simple_strtol(buf, NULL, 0); | |
1457 | ||
1458 | IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n", | |
1459 | BIT_ARG16(priv->prom_priv->filter)); | |
1460 | ||
1461 | return count; | |
1462 | } | |
1463 | ||
1464 | static ssize_t show_rtap_filter(struct device *d, | |
1465 | struct device_attribute *attr, | |
1466 | char *buf) | |
1467 | { | |
1468 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1469 | return sprintf(buf, "0x%04X", | |
1470 | priv->prom_priv ? priv->prom_priv->filter : 0); | |
1471 | } | |
1472 | ||
1473 | static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter, | |
1474 | store_rtap_filter); | |
1475 | #endif | |
1476 | ||
a613bffd JK |
1477 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
1478 | char *buf) | |
43f66a6c | 1479 | { |
a613bffd JK |
1480 | struct ipw_priv *priv = dev_get_drvdata(d); |
1481 | return sprintf(buf, "%d\n", priv->ieee->scan_age); | |
1482 | } | |
1483 | ||
1484 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, | |
1485 | const char *buf, size_t count) | |
1486 | { | |
1487 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1488 | struct net_device *dev = priv->net_dev; | |
1489 | char buffer[] = "00000000"; | |
1490 | unsigned long len = | |
1491 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; | |
1492 | unsigned long val; | |
1493 | char *p = buffer; | |
1494 | ||
1495 | IPW_DEBUG_INFO("enter\n"); | |
1496 | ||
1497 | strncpy(buffer, buf, len); | |
1498 | buffer[len] = 0; | |
1499 | ||
1500 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | |
1501 | p++; | |
1502 | if (p[0] == 'x' || p[0] == 'X') | |
1503 | p++; | |
1504 | val = simple_strtoul(p, &p, 16); | |
1505 | } else | |
1506 | val = simple_strtoul(p, &p, 10); | |
1507 | if (p == buffer) { | |
1508 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); | |
1509 | } else { | |
1510 | priv->ieee->scan_age = val; | |
1511 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); | |
1512 | } | |
1513 | ||
1514 | IPW_DEBUG_INFO("exit\n"); | |
1515 | return len; | |
1516 | } | |
1517 | ||
1518 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); | |
1519 | ||
1520 | static ssize_t show_led(struct device *d, struct device_attribute *attr, | |
1521 | char *buf) | |
1522 | { | |
1523 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1524 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); | |
1525 | } | |
1526 | ||
1527 | static ssize_t store_led(struct device *d, struct device_attribute *attr, | |
1528 | const char *buf, size_t count) | |
1529 | { | |
1530 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1531 | ||
1532 | IPW_DEBUG_INFO("enter\n"); | |
1533 | ||
1534 | if (count == 0) | |
1535 | return 0; | |
1536 | ||
1537 | if (*buf == 0) { | |
1538 | IPW_DEBUG_LED("Disabling LED control.\n"); | |
1539 | priv->config |= CFG_NO_LED; | |
1540 | ipw_led_shutdown(priv); | |
1541 | } else { | |
1542 | IPW_DEBUG_LED("Enabling LED control.\n"); | |
1543 | priv->config &= ~CFG_NO_LED; | |
1544 | ipw_led_init(priv); | |
1545 | } | |
1546 | ||
1547 | IPW_DEBUG_INFO("exit\n"); | |
1548 | return count; | |
1549 | } | |
1550 | ||
1551 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); | |
1552 | ||
ad3fee56 | 1553 | static ssize_t show_status(struct device *d, |
0edd5b44 | 1554 | struct device_attribute *attr, char *buf) |
43f66a6c | 1555 | { |
928841b1 | 1556 | struct ipw_priv *p = dev_get_drvdata(d); |
43f66a6c JK |
1557 | return sprintf(buf, "0x%08x\n", (int)p->status); |
1558 | } | |
0edd5b44 | 1559 | |
43f66a6c JK |
1560 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
1561 | ||
ad3fee56 AM |
1562 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
1563 | char *buf) | |
43f66a6c | 1564 | { |
928841b1 | 1565 | struct ipw_priv *p = dev_get_drvdata(d); |
43f66a6c JK |
1566 | return sprintf(buf, "0x%08x\n", (int)p->config); |
1567 | } | |
0edd5b44 | 1568 | |
43f66a6c JK |
1569 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
1570 | ||
ad3fee56 | 1571 | static ssize_t show_nic_type(struct device *d, |
0edd5b44 | 1572 | struct device_attribute *attr, char *buf) |
43f66a6c | 1573 | { |
928841b1 | 1574 | struct ipw_priv *priv = dev_get_drvdata(d); |
a613bffd | 1575 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); |
43f66a6c | 1576 | } |
0edd5b44 | 1577 | |
43f66a6c JK |
1578 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
1579 | ||
ad3fee56 | 1580 | static ssize_t show_ucode_version(struct device *d, |
0edd5b44 | 1581 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1582 | { |
1583 | u32 len = sizeof(u32), tmp = 0; | |
928841b1 | 1584 | struct ipw_priv *p = dev_get_drvdata(d); |
43f66a6c | 1585 | |
0edd5b44 | 1586 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
43f66a6c JK |
1587 | return 0; |
1588 | ||
1589 | return sprintf(buf, "0x%08x\n", tmp); | |
1590 | } | |
0edd5b44 JG |
1591 | |
1592 | static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL); | |
43f66a6c | 1593 | |
ad3fee56 AM |
1594 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
1595 | char *buf) | |
43f66a6c JK |
1596 | { |
1597 | u32 len = sizeof(u32), tmp = 0; | |
928841b1 | 1598 | struct ipw_priv *p = dev_get_drvdata(d); |
43f66a6c | 1599 | |
0edd5b44 | 1600 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
43f66a6c JK |
1601 | return 0; |
1602 | ||
1603 | return sprintf(buf, "0x%08x\n", tmp); | |
1604 | } | |
0edd5b44 JG |
1605 | |
1606 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); | |
43f66a6c JK |
1607 | |
1608 | /* | |
1609 | * Add a device attribute to view/control the delay between eeprom | |
1610 | * operations. | |
1611 | */ | |
ad3fee56 | 1612 | static ssize_t show_eeprom_delay(struct device *d, |
0edd5b44 | 1613 | struct device_attribute *attr, char *buf) |
43f66a6c | 1614 | { |
928841b1 GKH |
1615 | struct ipw_priv *p = dev_get_drvdata(d); |
1616 | int n = p->eeprom_delay; | |
43f66a6c JK |
1617 | return sprintf(buf, "%i\n", n); |
1618 | } | |
ad3fee56 | 1619 | static ssize_t store_eeprom_delay(struct device *d, |
0edd5b44 JG |
1620 | struct device_attribute *attr, |
1621 | const char *buf, size_t count) | |
43f66a6c | 1622 | { |
928841b1 | 1623 | struct ipw_priv *p = dev_get_drvdata(d); |
43f66a6c JK |
1624 | sscanf(buf, "%i", &p->eeprom_delay); |
1625 | return strnlen(buf, count); | |
1626 | } | |
0edd5b44 JG |
1627 | |
1628 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, | |
1629 | show_eeprom_delay, store_eeprom_delay); | |
43f66a6c | 1630 | |
ad3fee56 | 1631 | static ssize_t show_command_event_reg(struct device *d, |
0edd5b44 | 1632 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1633 | { |
1634 | u32 reg = 0; | |
928841b1 | 1635 | struct ipw_priv *p = dev_get_drvdata(d); |
43f66a6c | 1636 | |
b095c381 | 1637 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
43f66a6c JK |
1638 | return sprintf(buf, "0x%08x\n", reg); |
1639 | } | |
ad3fee56 | 1640 | static ssize_t store_command_event_reg(struct device *d, |
0edd5b44 JG |
1641 | struct device_attribute *attr, |
1642 | const char *buf, size_t count) | |
43f66a6c JK |
1643 | { |
1644 | u32 reg; | |
928841b1 | 1645 | struct ipw_priv *p = dev_get_drvdata(d); |
43f66a6c JK |
1646 | |
1647 | sscanf(buf, "%x", ®); | |
b095c381 | 1648 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
43f66a6c JK |
1649 | return strnlen(buf, count); |
1650 | } | |
0edd5b44 JG |
1651 | |
1652 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, | |
1653 | show_command_event_reg, store_command_event_reg); | |
43f66a6c | 1654 | |
ad3fee56 | 1655 | static ssize_t show_mem_gpio_reg(struct device *d, |
0edd5b44 | 1656 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1657 | { |
1658 | u32 reg = 0; | |
928841b1 | 1659 | struct ipw_priv *p = dev_get_drvdata(d); |
43f66a6c JK |
1660 | |
1661 | reg = ipw_read_reg32(p, 0x301100); | |
1662 | return sprintf(buf, "0x%08x\n", reg); | |
1663 | } | |
ad3fee56 | 1664 | static ssize_t store_mem_gpio_reg(struct device *d, |
0edd5b44 JG |
1665 | struct device_attribute *attr, |
1666 | const char *buf, size_t count) | |
43f66a6c JK |
1667 | { |
1668 | u32 reg; | |
928841b1 | 1669 | struct ipw_priv *p = dev_get_drvdata(d); |
43f66a6c JK |
1670 | |
1671 | sscanf(buf, "%x", ®); | |
1672 | ipw_write_reg32(p, 0x301100, reg); | |
1673 | return strnlen(buf, count); | |
1674 | } | |
0edd5b44 JG |
1675 | |
1676 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, | |
1677 | show_mem_gpio_reg, store_mem_gpio_reg); | |
43f66a6c | 1678 | |
ad3fee56 | 1679 | static ssize_t show_indirect_dword(struct device *d, |
0edd5b44 | 1680 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1681 | { |
1682 | u32 reg = 0; | |
928841b1 | 1683 | struct ipw_priv *priv = dev_get_drvdata(d); |
afbf30a2 | 1684 | |
bf79451e | 1685 | if (priv->status & STATUS_INDIRECT_DWORD) |
43f66a6c | 1686 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
bf79451e | 1687 | else |
43f66a6c | 1688 | reg = 0; |
bf79451e | 1689 | |
43f66a6c JK |
1690 | return sprintf(buf, "0x%08x\n", reg); |
1691 | } | |
ad3fee56 | 1692 | static ssize_t store_indirect_dword(struct device *d, |
0edd5b44 JG |
1693 | struct device_attribute *attr, |
1694 | const char *buf, size_t count) | |
43f66a6c | 1695 | { |
928841b1 | 1696 | struct ipw_priv *priv = dev_get_drvdata(d); |
43f66a6c JK |
1697 | |
1698 | sscanf(buf, "%x", &priv->indirect_dword); | |
1699 | priv->status |= STATUS_INDIRECT_DWORD; | |
1700 | return strnlen(buf, count); | |
1701 | } | |
0edd5b44 JG |
1702 | |
1703 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, | |
1704 | show_indirect_dword, store_indirect_dword); | |
43f66a6c | 1705 | |
ad3fee56 | 1706 | static ssize_t show_indirect_byte(struct device *d, |
0edd5b44 | 1707 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1708 | { |
1709 | u8 reg = 0; | |
928841b1 | 1710 | struct ipw_priv *priv = dev_get_drvdata(d); |
afbf30a2 | 1711 | |
bf79451e | 1712 | if (priv->status & STATUS_INDIRECT_BYTE) |
43f66a6c | 1713 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
bf79451e | 1714 | else |
43f66a6c JK |
1715 | reg = 0; |
1716 | ||
1717 | return sprintf(buf, "0x%02x\n", reg); | |
1718 | } | |
ad3fee56 | 1719 | static ssize_t store_indirect_byte(struct device *d, |
0edd5b44 JG |
1720 | struct device_attribute *attr, |
1721 | const char *buf, size_t count) | |
43f66a6c | 1722 | { |
928841b1 | 1723 | struct ipw_priv *priv = dev_get_drvdata(d); |
43f66a6c JK |
1724 | |
1725 | sscanf(buf, "%x", &priv->indirect_byte); | |
1726 | priv->status |= STATUS_INDIRECT_BYTE; | |
1727 | return strnlen(buf, count); | |
1728 | } | |
0edd5b44 JG |
1729 | |
1730 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, | |
43f66a6c JK |
1731 | show_indirect_byte, store_indirect_byte); |
1732 | ||
ad3fee56 | 1733 | static ssize_t show_direct_dword(struct device *d, |
0edd5b44 | 1734 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1735 | { |
1736 | u32 reg = 0; | |
928841b1 | 1737 | struct ipw_priv *priv = dev_get_drvdata(d); |
43f66a6c | 1738 | |
bf79451e | 1739 | if (priv->status & STATUS_DIRECT_DWORD) |
43f66a6c | 1740 | reg = ipw_read32(priv, priv->direct_dword); |
bf79451e | 1741 | else |
43f66a6c JK |
1742 | reg = 0; |
1743 | ||
1744 | return sprintf(buf, "0x%08x\n", reg); | |
1745 | } | |
ad3fee56 | 1746 | static ssize_t store_direct_dword(struct device *d, |
0edd5b44 JG |
1747 | struct device_attribute *attr, |
1748 | const char *buf, size_t count) | |
43f66a6c | 1749 | { |
928841b1 | 1750 | struct ipw_priv *priv = dev_get_drvdata(d); |
43f66a6c JK |
1751 | |
1752 | sscanf(buf, "%x", &priv->direct_dword); | |
1753 | priv->status |= STATUS_DIRECT_DWORD; | |
1754 | return strnlen(buf, count); | |
1755 | } | |
43f66a6c | 1756 | |
0edd5b44 JG |
1757 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
1758 | show_direct_dword, store_direct_dword); | |
43f66a6c | 1759 | |
858119e1 | 1760 | static int rf_kill_active(struct ipw_priv *priv) |
43f66a6c | 1761 | { |
25f94aea | 1762 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) { |
43f66a6c | 1763 | priv->status |= STATUS_RF_KILL_HW; |
25f94aea MG |
1764 | wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true); |
1765 | } else { | |
43f66a6c | 1766 | priv->status &= ~STATUS_RF_KILL_HW; |
25f94aea MG |
1767 | wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false); |
1768 | } | |
43f66a6c JK |
1769 | |
1770 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; | |
1771 | } | |
1772 | ||
ad3fee56 | 1773 | static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, |
0edd5b44 | 1774 | char *buf) |
43f66a6c JK |
1775 | { |
1776 | /* 0 - RF kill not enabled | |
bf79451e | 1777 | 1 - SW based RF kill active (sysfs) |
43f66a6c JK |
1778 | 2 - HW based RF kill active |
1779 | 3 - Both HW and SW baed RF kill active */ | |
928841b1 | 1780 | struct ipw_priv *priv = dev_get_drvdata(d); |
43f66a6c | 1781 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
0edd5b44 | 1782 | (rf_kill_active(priv) ? 0x2 : 0x0); |
43f66a6c JK |
1783 | return sprintf(buf, "%i\n", val); |
1784 | } | |
1785 | ||
1786 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) | |
1787 | { | |
bf79451e | 1788 | if ((disable_radio ? 1 : 0) == |
ea2b26e0 | 1789 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
0edd5b44 | 1790 | return 0; |
43f66a6c JK |
1791 | |
1792 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", | |
1793 | disable_radio ? "OFF" : "ON"); | |
1794 | ||
1795 | if (disable_radio) { | |
1796 | priv->status |= STATUS_RF_KILL_SW; | |
1797 | ||
0b531676 | 1798 | if (priv->workqueue) { |
43f66a6c | 1799 | cancel_delayed_work(&priv->request_scan); |
ea177305 DW |
1800 | cancel_delayed_work(&priv->request_direct_scan); |
1801 | cancel_delayed_work(&priv->request_passive_scan); | |
0b531676 DW |
1802 | cancel_delayed_work(&priv->scan_event); |
1803 | } | |
43f66a6c JK |
1804 | queue_work(priv->workqueue, &priv->down); |
1805 | } else { | |
1806 | priv->status &= ~STATUS_RF_KILL_SW; | |
1807 | if (rf_kill_active(priv)) { | |
1808 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " | |
1809 | "disabled by HW switch\n"); | |
1810 | /* Make sure the RF_KILL check timer is running */ | |
1811 | cancel_delayed_work(&priv->rf_kill); | |
bf79451e | 1812 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
be84e3d6 | 1813 | round_jiffies_relative(2 * HZ)); |
bf79451e | 1814 | } else |
43f66a6c JK |
1815 | queue_work(priv->workqueue, &priv->up); |
1816 | } | |
1817 | ||
1818 | return 1; | |
1819 | } | |
1820 | ||
0edd5b44 JG |
1821 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
1822 | const char *buf, size_t count) | |
43f66a6c | 1823 | { |
928841b1 | 1824 | struct ipw_priv *priv = dev_get_drvdata(d); |
bf79451e | 1825 | |
43f66a6c JK |
1826 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
1827 | ||
1828 | return count; | |
1829 | } | |
0edd5b44 JG |
1830 | |
1831 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); | |
43f66a6c | 1832 | |
b095c381 JK |
1833 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
1834 | char *buf) | |
1835 | { | |
928841b1 | 1836 | struct ipw_priv *priv = dev_get_drvdata(d); |
b095c381 JK |
1837 | int pos = 0, len = 0; |
1838 | if (priv->config & CFG_SPEED_SCAN) { | |
1839 | while (priv->speed_scan[pos] != 0) | |
1840 | len += sprintf(&buf[len], "%d ", | |
1841 | priv->speed_scan[pos++]); | |
1842 | return len + sprintf(&buf[len], "\n"); | |
1843 | } | |
1844 | ||
1845 | return sprintf(buf, "0\n"); | |
1846 | } | |
1847 | ||
1848 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, | |
1849 | const char *buf, size_t count) | |
1850 | { | |
928841b1 | 1851 | struct ipw_priv *priv = dev_get_drvdata(d); |
b095c381 JK |
1852 | int channel, pos = 0; |
1853 | const char *p = buf; | |
1854 | ||
1855 | /* list of space separated channels to scan, optionally ending with 0 */ | |
1856 | while ((channel = simple_strtol(p, NULL, 0))) { | |
1857 | if (pos == MAX_SPEED_SCAN - 1) { | |
1858 | priv->speed_scan[pos] = 0; | |
1859 | break; | |
1860 | } | |
1861 | ||
b0a4e7d8 | 1862 | if (libipw_is_valid_channel(priv->ieee, channel)) |
b095c381 JK |
1863 | priv->speed_scan[pos++] = channel; |
1864 | else | |
1865 | IPW_WARNING("Skipping invalid channel request: %d\n", | |
1866 | channel); | |
1867 | p = strchr(p, ' '); | |
1868 | if (!p) | |
1869 | break; | |
1870 | while (*p == ' ' || *p == '\t') | |
1871 | p++; | |
1872 | } | |
1873 | ||
1874 | if (pos == 0) | |
1875 | priv->config &= ~CFG_SPEED_SCAN; | |
1876 | else { | |
1877 | priv->speed_scan_pos = 0; | |
1878 | priv->config |= CFG_SPEED_SCAN; | |
1879 | } | |
1880 | ||
1881 | return count; | |
1882 | } | |
1883 | ||
1884 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, | |
1885 | store_speed_scan); | |
1886 | ||
1887 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, | |
1888 | char *buf) | |
1889 | { | |
928841b1 | 1890 | struct ipw_priv *priv = dev_get_drvdata(d); |
b095c381 JK |
1891 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); |
1892 | } | |
1893 | ||
1894 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, | |
1895 | const char *buf, size_t count) | |
1896 | { | |
928841b1 | 1897 | struct ipw_priv *priv = dev_get_drvdata(d); |
b095c381 JK |
1898 | if (buf[0] == '1') |
1899 | priv->config |= CFG_NET_STATS; | |
1900 | else | |
1901 | priv->config &= ~CFG_NET_STATS; | |
1902 | ||
1903 | return count; | |
1904 | } | |
1905 | ||
afbf30a2 JK |
1906 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
1907 | show_net_stats, store_net_stats); | |
b095c381 | 1908 | |
375dd244 ZY |
1909 | static ssize_t show_channels(struct device *d, |
1910 | struct device_attribute *attr, | |
1911 | char *buf) | |
1912 | { | |
1913 | struct ipw_priv *priv = dev_get_drvdata(d); | |
b0a4e7d8 | 1914 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
375dd244 ZY |
1915 | int len = 0, i; |
1916 | ||
1917 | len = sprintf(&buf[len], | |
1918 | "Displaying %d channels in 2.4Ghz band " | |
1919 | "(802.11bg):\n", geo->bg_channels); | |
1920 | ||
1921 | for (i = 0; i < geo->bg_channels; i++) { | |
1922 | len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n", | |
1923 | geo->bg[i].channel, | |
b0a4e7d8 | 1924 | geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ? |
375dd244 | 1925 | " (radar spectrum)" : "", |
b0a4e7d8 JL |
1926 | ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) || |
1927 | (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)) | |
375dd244 | 1928 | ? "" : ", IBSS", |
b0a4e7d8 | 1929 | geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ? |
375dd244 | 1930 | "passive only" : "active/passive", |
b0a4e7d8 | 1931 | geo->bg[i].flags & LIBIPW_CH_B_ONLY ? |
375dd244 ZY |
1932 | "B" : "B/G"); |
1933 | } | |
1934 | ||
1935 | len += sprintf(&buf[len], | |
1936 | "Displaying %d channels in 5.2Ghz band " | |
1937 | "(802.11a):\n", geo->a_channels); | |
1938 | for (i = 0; i < geo->a_channels; i++) { | |
1939 | len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n", | |
1940 | geo->a[i].channel, | |
b0a4e7d8 | 1941 | geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ? |
375dd244 | 1942 | " (radar spectrum)" : "", |
b0a4e7d8 JL |
1943 | ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) || |
1944 | (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)) | |
375dd244 | 1945 | ? "" : ", IBSS", |
b0a4e7d8 | 1946 | geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ? |
375dd244 ZY |
1947 | "passive only" : "active/passive"); |
1948 | } | |
1949 | ||
1950 | return len; | |
1951 | } | |
1952 | ||
1953 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); | |
1954 | ||
ea2b26e0 JK |
1955 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
1956 | { | |
1957 | union iwreq_data wrqu; | |
1958 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1959 | if (priv->status & STATUS_ASSOCIATED) | |
1960 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); | |
1961 | else | |
1962 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); | |
1963 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | |
1964 | } | |
1965 | ||
43f66a6c JK |
1966 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
1967 | { | |
1968 | u32 inta, inta_mask, handled = 0; | |
1969 | unsigned long flags; | |
1970 | int rc = 0; | |
1971 | ||
89c318ed | 1972 | spin_lock_irqsave(&priv->irq_lock, flags); |
43f66a6c | 1973 | |
b095c381 JK |
1974 | inta = ipw_read32(priv, IPW_INTA_RW); |
1975 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); | |
1976 | inta &= (IPW_INTA_MASK_ALL & inta_mask); | |
43f66a6c JK |
1977 | |
1978 | /* Add any cached INTA values that need to be handled */ | |
1979 | inta |= priv->isr_inta; | |
1980 | ||
89c318ed ZY |
1981 | spin_unlock_irqrestore(&priv->irq_lock, flags); |
1982 | ||
1983 | spin_lock_irqsave(&priv->lock, flags); | |
1984 | ||
43f66a6c | 1985 | /* handle all the justifications for the interrupt */ |
b095c381 | 1986 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
43f66a6c | 1987 | ipw_rx(priv); |
b095c381 | 1988 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
43f66a6c JK |
1989 | } |
1990 | ||
b095c381 | 1991 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
43f66a6c | 1992 | IPW_DEBUG_HC("Command completed.\n"); |
0edd5b44 | 1993 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
43f66a6c JK |
1994 | priv->status &= ~STATUS_HCMD_ACTIVE; |
1995 | wake_up_interruptible(&priv->wait_command_queue); | |
b095c381 | 1996 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
43f66a6c JK |
1997 | } |
1998 | ||
b095c381 | 1999 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
43f66a6c | 2000 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
0edd5b44 | 2001 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
b095c381 | 2002 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
43f66a6c JK |
2003 | } |
2004 | ||
b095c381 | 2005 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
43f66a6c | 2006 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
0edd5b44 | 2007 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
b095c381 | 2008 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
43f66a6c JK |
2009 | } |
2010 | ||
b095c381 | 2011 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
43f66a6c | 2012 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
0edd5b44 | 2013 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
b095c381 | 2014 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
43f66a6c JK |
2015 | } |
2016 | ||
b095c381 | 2017 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
43f66a6c | 2018 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
0edd5b44 | 2019 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
b095c381 | 2020 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
43f66a6c JK |
2021 | } |
2022 | ||
b095c381 | 2023 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
43f66a6c | 2024 | IPW_WARNING("STATUS_CHANGE\n"); |
b095c381 | 2025 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
43f66a6c JK |
2026 | } |
2027 | ||
b095c381 | 2028 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
43f66a6c | 2029 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
b095c381 | 2030 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
43f66a6c JK |
2031 | } |
2032 | ||
b095c381 | 2033 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
43f66a6c | 2034 | IPW_WARNING("HOST_CMD_DONE\n"); |
b095c381 | 2035 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
43f66a6c JK |
2036 | } |
2037 | ||
b095c381 | 2038 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
43f66a6c | 2039 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
b095c381 | 2040 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
43f66a6c JK |
2041 | } |
2042 | ||
b095c381 | 2043 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
43f66a6c | 2044 | IPW_WARNING("PHY_OFF_DONE\n"); |
b095c381 | 2045 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
43f66a6c JK |
2046 | } |
2047 | ||
b095c381 | 2048 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
43f66a6c JK |
2049 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
2050 | priv->status |= STATUS_RF_KILL_HW; | |
25f94aea | 2051 | wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true); |
43f66a6c | 2052 | wake_up_interruptible(&priv->wait_command_queue); |
ea2b26e0 | 2053 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
43f66a6c | 2054 | cancel_delayed_work(&priv->request_scan); |
ea177305 DW |
2055 | cancel_delayed_work(&priv->request_direct_scan); |
2056 | cancel_delayed_work(&priv->request_passive_scan); | |
0b531676 | 2057 | cancel_delayed_work(&priv->scan_event); |
a613bffd | 2058 | schedule_work(&priv->link_down); |
43f66a6c | 2059 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
b095c381 | 2060 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
43f66a6c | 2061 | } |
bf79451e | 2062 | |
b095c381 | 2063 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
1d1b09eb | 2064 | IPW_WARNING("Firmware error detected. Restarting.\n"); |
b39860c6 | 2065 | if (priv->error) { |
1d1b09eb | 2066 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); |
b39860c6 JK |
2067 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
2068 | struct ipw_fw_error *error = | |
2069 | ipw_alloc_error_log(priv); | |
2070 | ipw_dump_error_log(priv, error); | |
8f760780 | 2071 | kfree(error); |
b39860c6 | 2072 | } |
b39860c6 JK |
2073 | } else { |
2074 | priv->error = ipw_alloc_error_log(priv); | |
2075 | if (priv->error) | |
1d1b09eb | 2076 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); |
b39860c6 | 2077 | else |
1d1b09eb ZY |
2078 | IPW_DEBUG_FW("Error allocating sysfs 'error' " |
2079 | "log.\n"); | |
b39860c6 JK |
2080 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
2081 | ipw_dump_error_log(priv, priv->error); | |
b39860c6 JK |
2082 | } |
2083 | ||
b095c381 JK |
2084 | /* XXX: If hardware encryption is for WPA/WPA2, |
2085 | * we have to notify the supplicant. */ | |
2086 | if (priv->ieee->sec.encrypt) { | |
2087 | priv->status &= ~STATUS_ASSOCIATED; | |
2088 | notify_wx_assoc_event(priv); | |
2089 | } | |
2090 | ||
2091 | /* Keep the restart process from trying to send host | |
2092 | * commands by clearing the INIT status bit */ | |
2093 | priv->status &= ~STATUS_INIT; | |
afbf30a2 JK |
2094 | |
2095 | /* Cancel currently queued command. */ | |
2096 | priv->status &= ~STATUS_HCMD_ACTIVE; | |
2097 | wake_up_interruptible(&priv->wait_command_queue); | |
2098 | ||
43f66a6c | 2099 | queue_work(priv->workqueue, &priv->adapter_restart); |
b095c381 | 2100 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
43f66a6c JK |
2101 | } |
2102 | ||
b095c381 | 2103 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
43f66a6c | 2104 | IPW_ERROR("Parity error\n"); |
b095c381 | 2105 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
43f66a6c JK |
2106 | } |
2107 | ||
2108 | if (handled != inta) { | |
0edd5b44 | 2109 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
43f66a6c JK |
2110 | } |
2111 | ||
89c318ed ZY |
2112 | spin_unlock_irqrestore(&priv->lock, flags); |
2113 | ||
43f66a6c JK |
2114 | /* enable all interrupts */ |
2115 | ipw_enable_interrupts(priv); | |
43f66a6c | 2116 | } |
bf79451e | 2117 | |
43f66a6c JK |
2118 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
2119 | static char *get_cmd_string(u8 cmd) | |
2120 | { | |
2121 | switch (cmd) { | |
2122 | IPW_CMD(HOST_COMPLETE); | |
bf79451e JG |
2123 | IPW_CMD(POWER_DOWN); |
2124 | IPW_CMD(SYSTEM_CONFIG); | |
2125 | IPW_CMD(MULTICAST_ADDRESS); | |
2126 | IPW_CMD(SSID); | |
2127 | IPW_CMD(ADAPTER_ADDRESS); | |
2128 | IPW_CMD(PORT_TYPE); | |
2129 | IPW_CMD(RTS_THRESHOLD); | |
2130 | IPW_CMD(FRAG_THRESHOLD); | |
2131 | IPW_CMD(POWER_MODE); | |
2132 | IPW_CMD(WEP_KEY); | |
2133 | IPW_CMD(TGI_TX_KEY); | |
2134 | IPW_CMD(SCAN_REQUEST); | |
2135 | IPW_CMD(SCAN_REQUEST_EXT); | |
2136 | IPW_CMD(ASSOCIATE); | |
2137 | IPW_CMD(SUPPORTED_RATES); | |
2138 | IPW_CMD(SCAN_ABORT); | |
2139 | IPW_CMD(TX_FLUSH); | |
2140 | IPW_CMD(QOS_PARAMETERS); | |
2141 | IPW_CMD(DINO_CONFIG); | |
2142 | IPW_CMD(RSN_CAPABILITIES); | |
2143 | IPW_CMD(RX_KEY); | |
2144 | IPW_CMD(CARD_DISABLE); | |
2145 | IPW_CMD(SEED_NUMBER); | |
2146 | IPW_CMD(TX_POWER); | |
2147 | IPW_CMD(COUNTRY_INFO); | |
2148 | IPW_CMD(AIRONET_INFO); | |
2149 | IPW_CMD(AP_TX_POWER); | |
2150 | IPW_CMD(CCKM_INFO); | |
2151 | IPW_CMD(CCX_VER_INFO); | |
2152 | IPW_CMD(SET_CALIBRATION); | |
2153 | IPW_CMD(SENSITIVITY_CALIB); | |
2154 | IPW_CMD(RETRY_LIMIT); | |
2155 | IPW_CMD(IPW_PRE_POWER_DOWN); | |
2156 | IPW_CMD(VAP_BEACON_TEMPLATE); | |
2157 | IPW_CMD(VAP_DTIM_PERIOD); | |
2158 | IPW_CMD(EXT_SUPPORTED_RATES); | |
2159 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); | |
2160 | IPW_CMD(VAP_QUIET_INTERVALS); | |
2161 | IPW_CMD(VAP_CHANNEL_SWITCH); | |
2162 | IPW_CMD(VAP_MANDATORY_CHANNELS); | |
2163 | IPW_CMD(VAP_CELL_PWR_LIMIT); | |
2164 | IPW_CMD(VAP_CF_PARAM_SET); | |
2165 | IPW_CMD(VAP_SET_BEACONING_STATE); | |
2166 | IPW_CMD(MEASUREMENT); | |
2167 | IPW_CMD(POWER_CAPABILITY); | |
2168 | IPW_CMD(SUPPORTED_CHANNELS); | |
2169 | IPW_CMD(TPC_REPORT); | |
2170 | IPW_CMD(WME_INFO); | |
2171 | IPW_CMD(PRODUCTION_COMMAND); | |
2172 | default: | |
43f66a6c JK |
2173 | return "UNKNOWN"; |
2174 | } | |
2175 | } | |
43f66a6c JK |
2176 | |
2177 | #define HOST_COMPLETE_TIMEOUT HZ | |
0a7bcf26 ZY |
2178 | |
2179 | static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd) | |
43f66a6c JK |
2180 | { |
2181 | int rc = 0; | |
a613bffd | 2182 | unsigned long flags; |
43f66a6c | 2183 | |
a613bffd | 2184 | spin_lock_irqsave(&priv->lock, flags); |
43f66a6c | 2185 | if (priv->status & STATUS_HCMD_ACTIVE) { |
9ddf84f6 JK |
2186 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
2187 | get_cmd_string(cmd->cmd)); | |
a613bffd | 2188 | spin_unlock_irqrestore(&priv->lock, flags); |
9ddf84f6 | 2189 | return -EAGAIN; |
43f66a6c JK |
2190 | } |
2191 | ||
2192 | priv->status |= STATUS_HCMD_ACTIVE; | |
bf79451e | 2193 | |
f6c5cb7c JK |
2194 | if (priv->cmdlog) { |
2195 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; | |
2196 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; | |
2197 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; | |
2198 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, | |
2199 | cmd->len); | |
2200 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; | |
2201 | } | |
2202 | ||
b095c381 JK |
2203 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
2204 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, | |
2205 | priv->status); | |
f516dbcd ZY |
2206 | |
2207 | #ifndef DEBUG_CMD_WEP_KEY | |
2208 | if (cmd->cmd == IPW_CMD_WEP_KEY) | |
2209 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); | |
2210 | else | |
2211 | #endif | |
2212 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); | |
2213 | ||
0a7bcf26 | 2214 | rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0); |
a613bffd JK |
2215 | if (rc) { |
2216 | priv->status &= ~STATUS_HCMD_ACTIVE; | |
9ddf84f6 JK |
2217 | IPW_ERROR("Failed to send %s: Reason %d\n", |
2218 | get_cmd_string(cmd->cmd), rc); | |
a613bffd | 2219 | spin_unlock_irqrestore(&priv->lock, flags); |
f6c5cb7c | 2220 | goto exit; |
a613bffd JK |
2221 | } |
2222 | spin_unlock_irqrestore(&priv->lock, flags); | |
43f66a6c | 2223 | |
0edd5b44 JG |
2224 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
2225 | !(priv-> | |
2226 | status & STATUS_HCMD_ACTIVE), | |
2227 | HOST_COMPLETE_TIMEOUT); | |
43f66a6c | 2228 | if (rc == 0) { |
a613bffd JK |
2229 | spin_lock_irqsave(&priv->lock, flags); |
2230 | if (priv->status & STATUS_HCMD_ACTIVE) { | |
9ddf84f6 JK |
2231 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
2232 | get_cmd_string(cmd->cmd)); | |
a613bffd JK |
2233 | priv->status &= ~STATUS_HCMD_ACTIVE; |
2234 | spin_unlock_irqrestore(&priv->lock, flags); | |
f6c5cb7c JK |
2235 | rc = -EIO; |
2236 | goto exit; | |
a613bffd JK |
2237 | } |
2238 | spin_unlock_irqrestore(&priv->lock, flags); | |
3b9990cb JK |
2239 | } else |
2240 | rc = 0; | |
a613bffd | 2241 | |
b095c381 | 2242 | if (priv->status & STATUS_RF_KILL_HW) { |
9ddf84f6 JK |
2243 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
2244 | get_cmd_string(cmd->cmd)); | |
f6c5cb7c JK |
2245 | rc = -EIO; |
2246 | goto exit; | |
43f66a6c JK |
2247 | } |
2248 | ||
2638bc39 | 2249 | exit: |
f6c5cb7c JK |
2250 | if (priv->cmdlog) { |
2251 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; | |
2252 | priv->cmdlog_pos %= priv->cmdlog_len; | |
2253 | } | |
2254 | return rc; | |
43f66a6c JK |
2255 | } |
2256 | ||
0a7bcf26 ZY |
2257 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) |
2258 | { | |
2259 | struct host_cmd cmd = { | |
2260 | .cmd = command, | |
2261 | }; | |
2262 | ||
2263 | return __ipw_send_cmd(priv, &cmd); | |
2264 | } | |
2265 | ||
2266 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, | |
2267 | void *data) | |
43f66a6c JK |
2268 | { |
2269 | struct host_cmd cmd = { | |
0a7bcf26 ZY |
2270 | .cmd = command, |
2271 | .len = len, | |
2272 | .param = data, | |
43f66a6c JK |
2273 | }; |
2274 | ||
0a7bcf26 ZY |
2275 | return __ipw_send_cmd(priv, &cmd); |
2276 | } | |
2277 | ||
2278 | static int ipw_send_host_complete(struct ipw_priv *priv) | |
2279 | { | |
43f66a6c JK |
2280 | if (!priv) { |
2281 | IPW_ERROR("Invalid args\n"); | |
2282 | return -1; | |
2283 | } | |
2284 | ||
0a7bcf26 | 2285 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); |
43f66a6c JK |
2286 | } |
2287 | ||
d685b8c2 | 2288 | static int ipw_send_system_config(struct ipw_priv *priv) |
43f66a6c | 2289 | { |
d685b8c2 ZY |
2290 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, |
2291 | sizeof(priv->sys_config), | |
2292 | &priv->sys_config); | |
43f66a6c JK |
2293 | } |
2294 | ||
0edd5b44 | 2295 | static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len) |
43f66a6c | 2296 | { |
43f66a6c JK |
2297 | if (!priv || !ssid) { |
2298 | IPW_ERROR("Invalid args\n"); | |
2299 | return -1; | |
2300 | } | |
2301 | ||
0a7bcf26 | 2302 | return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE), |
2638bc39 | 2303 | ssid); |
43f66a6c JK |
2304 | } |
2305 | ||
0edd5b44 | 2306 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
43f66a6c | 2307 | { |
43f66a6c JK |
2308 | if (!priv || !mac) { |
2309 | IPW_ERROR("Invalid args\n"); | |
2310 | return -1; | |
2311 | } | |
2312 | ||
e174961c JB |
2313 | IPW_DEBUG_INFO("%s: Setting MAC to %pM\n", |
2314 | priv->net_dev->name, mac); | |
43f66a6c | 2315 | |
2638bc39 | 2316 | return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac); |
43f66a6c JK |
2317 | } |
2318 | ||
a613bffd JK |
2319 | /* |
2320 | * NOTE: This must be executed from our workqueue as it results in udelay | |
2321 | * being called which may corrupt the keyboard if executed on default | |
2322 | * workqueue | |
2323 | */ | |
43f66a6c JK |
2324 | static void ipw_adapter_restart(void *adapter) |
2325 | { | |
2326 | struct ipw_priv *priv = adapter; | |
2327 | ||
2328 | if (priv->status & STATUS_RF_KILL_MASK) | |
2329 | return; | |
2330 | ||
2331 | ipw_down(priv); | |
b095c381 JK |
2332 | |
2333 | if (priv->assoc_network && | |
2334 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) | |
2335 | ipw_remove_current_network(priv); | |
2336 | ||
43f66a6c JK |
2337 | if (ipw_up(priv)) { |
2338 | IPW_ERROR("Failed to up device\n"); | |
2339 | return; | |
2340 | } | |
2341 | } | |
2342 | ||
c4028958 | 2343 | static void ipw_bg_adapter_restart(struct work_struct *work) |
c848d0af | 2344 | { |
c4028958 DH |
2345 | struct ipw_priv *priv = |
2346 | container_of(work, struct ipw_priv, adapter_restart); | |
4644151b | 2347 | mutex_lock(&priv->mutex); |
c4028958 | 2348 | ipw_adapter_restart(priv); |
4644151b | 2349 | mutex_unlock(&priv->mutex); |
c848d0af JK |
2350 | } |
2351 | ||
43f66a6c JK |
2352 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
2353 | ||
2354 | static void ipw_scan_check(void *data) | |
2355 | { | |
2356 | struct ipw_priv *priv = data; | |
2357 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { | |
2358 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " | |
c7b6a674 ZY |
2359 | "adapter after (%dms).\n", |
2360 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); | |
a613bffd | 2361 | queue_work(priv->workqueue, &priv->adapter_restart); |
43f66a6c JK |
2362 | } |
2363 | } | |
2364 | ||
c4028958 | 2365 | static void ipw_bg_scan_check(struct work_struct *work) |
c848d0af | 2366 | { |
c4028958 DH |
2367 | struct ipw_priv *priv = |
2368 | container_of(work, struct ipw_priv, scan_check.work); | |
4644151b | 2369 | mutex_lock(&priv->mutex); |
c4028958 | 2370 | ipw_scan_check(priv); |
4644151b | 2371 | mutex_unlock(&priv->mutex); |
c848d0af JK |
2372 | } |
2373 | ||
43f66a6c JK |
2374 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
2375 | struct ipw_scan_request_ext *request) | |
2376 | { | |
0a7bcf26 | 2377 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, |
2638bc39 | 2378 | sizeof(*request), request); |
43f66a6c JK |
2379 | } |
2380 | ||
2381 | static int ipw_send_scan_abort(struct ipw_priv *priv) | |
2382 | { | |
43f66a6c JK |
2383 | if (!priv) { |
2384 | IPW_ERROR("Invalid args\n"); | |
2385 | return -1; | |
2386 | } | |
2387 | ||
0a7bcf26 | 2388 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); |
43f66a6c JK |
2389 | } |
2390 | ||
2391 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) | |
2392 | { | |
0a7bcf26 | 2393 | struct ipw_sensitivity_calib calib = { |
851ca268 | 2394 | .beacon_rssi_raw = cpu_to_le16(sens), |
43f66a6c | 2395 | }; |
0a7bcf26 ZY |
2396 | |
2397 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), | |
2638bc39 | 2398 | &calib); |
43f66a6c JK |
2399 | } |
2400 | ||
2401 | static int ipw_send_associate(struct ipw_priv *priv, | |
2402 | struct ipw_associate *associate) | |
2403 | { | |
0a7bcf26 ZY |
2404 | if (!priv || !associate) { |
2405 | IPW_ERROR("Invalid args\n"); | |
2406 | return -1; | |
2407 | } | |
2408 | ||
5b5e807f AV |
2409 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate), |
2410 | associate); | |
43f66a6c JK |
2411 | } |
2412 | ||
2413 | static int ipw_send_supported_rates(struct ipw_priv *priv, | |
2414 | struct ipw_supported_rates *rates) | |
2415 | { | |
43f66a6c JK |
2416 | if (!priv || !rates) { |
2417 | IPW_ERROR("Invalid args\n"); | |
2418 | return -1; | |
2419 | } | |
2420 | ||
0a7bcf26 | 2421 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), |
2638bc39 | 2422 | rates); |
43f66a6c JK |
2423 | } |
2424 | ||
2425 | static int ipw_set_random_seed(struct ipw_priv *priv) | |
2426 | { | |
0a7bcf26 | 2427 | u32 val; |
43f66a6c JK |
2428 | |
2429 | if (!priv) { | |
2430 | IPW_ERROR("Invalid args\n"); | |
2431 | return -1; | |
2432 | } | |
2433 | ||
0a7bcf26 | 2434 | get_random_bytes(&val, sizeof(val)); |
43f66a6c | 2435 | |
0a7bcf26 | 2436 | return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val); |
43f66a6c JK |
2437 | } |
2438 | ||
43f66a6c JK |
2439 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
2440 | { | |
e62e1ee0 | 2441 | __le32 v = cpu_to_le32(phy_off); |
43f66a6c JK |
2442 | if (!priv) { |
2443 | IPW_ERROR("Invalid args\n"); | |
2444 | return -1; | |
2445 | } | |
2446 | ||
e62e1ee0 | 2447 | return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v); |
43f66a6c | 2448 | } |
43f66a6c | 2449 | |
0edd5b44 | 2450 | static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power) |
43f66a6c | 2451 | { |
43f66a6c JK |
2452 | if (!priv || !power) { |
2453 | IPW_ERROR("Invalid args\n"); | |
2454 | return -1; | |
2455 | } | |
2456 | ||
2638bc39 | 2457 | return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power); |
43f66a6c JK |
2458 | } |
2459 | ||
6de9f7f2 ZY |
2460 | static int ipw_set_tx_power(struct ipw_priv *priv) |
2461 | { | |
b0a4e7d8 | 2462 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
6de9f7f2 ZY |
2463 | struct ipw_tx_power tx_power; |
2464 | s8 max_power; | |
2465 | int i; | |
2466 | ||
2467 | memset(&tx_power, 0, sizeof(tx_power)); | |
2468 | ||
2469 | /* configure device for 'G' band */ | |
2470 | tx_power.ieee_mode = IPW_G_MODE; | |
2471 | tx_power.num_channels = geo->bg_channels; | |
2472 | for (i = 0; i < geo->bg_channels; i++) { | |
2473 | max_power = geo->bg[i].max_power; | |
2474 | tx_power.channels_tx_power[i].channel_number = | |
2475 | geo->bg[i].channel; | |
2476 | tx_power.channels_tx_power[i].tx_power = max_power ? | |
2477 | min(max_power, priv->tx_power) : priv->tx_power; | |
43f66a6c | 2478 | } |
6de9f7f2 ZY |
2479 | if (ipw_send_tx_power(priv, &tx_power)) |
2480 | return -EIO; | |
2481 | ||
2482 | /* configure device to also handle 'B' band */ | |
2483 | tx_power.ieee_mode = IPW_B_MODE; | |
2484 | if (ipw_send_tx_power(priv, &tx_power)) | |
2485 | return -EIO; | |
bf79451e | 2486 | |
6de9f7f2 ZY |
2487 | /* configure device to also handle 'A' band */ |
2488 | if (priv->ieee->abg_true) { | |
2489 | tx_power.ieee_mode = IPW_A_MODE; | |
2490 | tx_power.num_channels = geo->a_channels; | |
2491 | for (i = 0; i < tx_power.num_channels; i++) { | |
2492 | max_power = geo->a[i].max_power; | |
2493 | tx_power.channels_tx_power[i].channel_number = | |
2494 | geo->a[i].channel; | |
2495 | tx_power.channels_tx_power[i].tx_power = max_power ? | |
2496 | min(max_power, priv->tx_power) : priv->tx_power; | |
2497 | } | |
2498 | if (ipw_send_tx_power(priv, &tx_power)) | |
2499 | return -EIO; | |
2500 | } | |
43f66a6c JK |
2501 | return 0; |
2502 | } | |
2503 | ||
2504 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) | |
2505 | { | |
2506 | struct ipw_rts_threshold rts_threshold = { | |
851ca268 | 2507 | .rts_threshold = cpu_to_le16(rts), |
43f66a6c | 2508 | }; |
43f66a6c JK |
2509 | |
2510 | if (!priv) { | |
2511 | IPW_ERROR("Invalid args\n"); | |
2512 | return -1; | |
2513 | } | |
2514 | ||
0a7bcf26 ZY |
2515 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, |
2516 | sizeof(rts_threshold), &rts_threshold); | |
43f66a6c JK |
2517 | } |
2518 | ||
2519 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) | |
2520 | { | |
2521 | struct ipw_frag_threshold frag_threshold = { | |
851ca268 | 2522 | .frag_threshold = cpu_to_le16(frag), |
43f66a6c | 2523 | }; |
43f66a6c JK |
2524 | |
2525 | if (!priv) { | |
2526 | IPW_ERROR("Invalid args\n"); | |
2527 | return -1; | |
2528 | } | |
2529 | ||
0a7bcf26 ZY |
2530 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, |
2531 | sizeof(frag_threshold), &frag_threshold); | |
43f66a6c JK |
2532 | } |
2533 | ||
2534 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) | |
2535 | { | |
e62e1ee0 | 2536 | __le32 param; |
43f66a6c JK |
2537 | |
2538 | if (!priv) { | |
2539 | IPW_ERROR("Invalid args\n"); | |
2540 | return -1; | |
2541 | } | |
bf79451e | 2542 | |
43f66a6c JK |
2543 | /* If on battery, set to 3, if AC set to CAM, else user |
2544 | * level */ | |
2545 | switch (mode) { | |
2546 | case IPW_POWER_BATTERY: | |
e62e1ee0 | 2547 | param = cpu_to_le32(IPW_POWER_INDEX_3); |
43f66a6c JK |
2548 | break; |
2549 | case IPW_POWER_AC: | |
e62e1ee0 | 2550 | param = cpu_to_le32(IPW_POWER_MODE_CAM); |
43f66a6c JK |
2551 | break; |
2552 | default: | |
e62e1ee0 | 2553 | param = cpu_to_le32(mode); |
43f66a6c JK |
2554 | break; |
2555 | } | |
2556 | ||
0a7bcf26 | 2557 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), |
2638bc39 | 2558 | ¶m); |
43f66a6c JK |
2559 | } |
2560 | ||
afbf30a2 JK |
2561 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
2562 | { | |
2563 | struct ipw_retry_limit retry_limit = { | |
2564 | .short_retry_limit = slimit, | |
2565 | .long_retry_limit = llimit | |
2566 | }; | |
afbf30a2 JK |
2567 | |
2568 | if (!priv) { | |
2569 | IPW_ERROR("Invalid args\n"); | |
2570 | return -1; | |
2571 | } | |
2572 | ||
0a7bcf26 | 2573 | return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit), |
2638bc39 | 2574 | &retry_limit); |
afbf30a2 JK |
2575 | } |
2576 | ||
43f66a6c JK |
2577 | /* |
2578 | * The IPW device contains a Microwire compatible EEPROM that stores | |
2579 | * various data like the MAC address. Usually the firmware has exclusive | |
2580 | * access to the eeprom, but during device initialization (before the | |
2581 | * device driver has sent the HostComplete command to the firmware) the | |
2582 | * device driver has read access to the EEPROM by way of indirect addressing | |
2583 | * through a couple of memory mapped registers. | |
2584 | * | |
2585 | * The following is a simplified implementation for pulling data out of the | |
2586 | * the eeprom, along with some helper functions to find information in | |
2587 | * the per device private data's copy of the eeprom. | |
2588 | * | |
2589 | * NOTE: To better understand how these functions work (i.e what is a chip | |
2590 | * select and why do have to keep driving the eeprom clock?), read | |
2591 | * just about any data sheet for a Microwire compatible EEPROM. | |
2592 | */ | |
2593 | ||
2594 | /* write a 32 bit value into the indirect accessor register */ | |
2595 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) | |
2596 | { | |
2597 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); | |
bf79451e | 2598 | |
43f66a6c JK |
2599 | /* the eeprom requires some time to complete the operation */ |
2600 | udelay(p->eeprom_delay); | |
2601 | ||
2602 | return; | |
2603 | } | |
2604 | ||
2605 | /* perform a chip select operation */ | |
858119e1 | 2606 | static void eeprom_cs(struct ipw_priv *priv) |
43f66a6c | 2607 | { |
0edd5b44 JG |
2608 | eeprom_write_reg(priv, 0); |
2609 | eeprom_write_reg(priv, EEPROM_BIT_CS); | |
2610 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); | |
2611 | eeprom_write_reg(priv, EEPROM_BIT_CS); | |
43f66a6c JK |
2612 | } |
2613 | ||
2614 | /* perform a chip select operation */ | |
858119e1 | 2615 | static void eeprom_disable_cs(struct ipw_priv *priv) |
43f66a6c | 2616 | { |
0edd5b44 JG |
2617 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
2618 | eeprom_write_reg(priv, 0); | |
2619 | eeprom_write_reg(priv, EEPROM_BIT_SK); | |
43f66a6c JK |
2620 | } |
2621 | ||
2622 | /* push a single bit down to the eeprom */ | |
0edd5b44 | 2623 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
43f66a6c | 2624 | { |
0edd5b44 JG |
2625 | int d = (bit ? EEPROM_BIT_DI : 0); |
2626 | eeprom_write_reg(p, EEPROM_BIT_CS | d); | |
2627 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); | |
43f66a6c JK |
2628 | } |
2629 | ||
2630 | /* push an opcode followed by an address down to the eeprom */ | |
0edd5b44 | 2631 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
43f66a6c JK |
2632 | { |
2633 | int i; | |
2634 | ||
2635 | eeprom_cs(priv); | |
0edd5b44 JG |
2636 | eeprom_write_bit(priv, 1); |
2637 | eeprom_write_bit(priv, op & 2); | |
2638 | eeprom_write_bit(priv, op & 1); | |
2639 | for (i = 7; i >= 0; i--) { | |
2640 | eeprom_write_bit(priv, addr & (1 << i)); | |
43f66a6c JK |
2641 | } |
2642 | } | |
2643 | ||
2644 | /* pull 16 bits off the eeprom, one bit at a time */ | |
0edd5b44 | 2645 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
43f66a6c JK |
2646 | { |
2647 | int i; | |
0edd5b44 | 2648 | u16 r = 0; |
bf79451e | 2649 | |
43f66a6c | 2650 | /* Send READ Opcode */ |
0edd5b44 | 2651 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
43f66a6c JK |
2652 | |
2653 | /* Send dummy bit */ | |
0edd5b44 | 2654 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
43f66a6c JK |
2655 | |
2656 | /* Read the byte off the eeprom one bit at a time */ | |
0edd5b44 | 2657 | for (i = 0; i < 16; i++) { |
43f66a6c | 2658 | u32 data = 0; |
0edd5b44 JG |
2659 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
2660 | eeprom_write_reg(priv, EEPROM_BIT_CS); | |
2661 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); | |
2662 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); | |
43f66a6c | 2663 | } |
bf79451e | 2664 | |
43f66a6c | 2665 | /* Send another dummy bit */ |
0edd5b44 | 2666 | eeprom_write_reg(priv, 0); |
43f66a6c | 2667 | eeprom_disable_cs(priv); |
bf79451e | 2668 | |
43f66a6c JK |
2669 | return r; |
2670 | } | |
2671 | ||
2672 | /* helper function for pulling the mac address out of the private */ | |
2673 | /* data's copy of the eeprom data */ | |
0edd5b44 | 2674 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
43f66a6c | 2675 | { |
afbf30a2 | 2676 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
43f66a6c JK |
2677 | } |
2678 | ||
2679 | /* | |
2680 | * Either the device driver (i.e. the host) or the firmware can | |
2681 | * load eeprom data into the designated region in SRAM. If neither | |
2682 | * happens then the FW will shutdown with a fatal error. | |
2683 | * | |
2684 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE | |
2685 | * bit needs region of shared SRAM needs to be non-zero. | |
2686 | */ | |
2687 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) | |
2688 | { | |
2689 | int i; | |
e62e1ee0 | 2690 | __le16 *eeprom = (__le16 *) priv->eeprom; |
bf79451e | 2691 | |
43f66a6c JK |
2692 | IPW_DEBUG_TRACE(">>\n"); |
2693 | ||
2694 | /* read entire contents of eeprom into private buffer */ | |
0edd5b44 | 2695 | for (i = 0; i < 128; i++) |
e62e1ee0 | 2696 | eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i)); |
43f66a6c | 2697 | |
bf79451e JG |
2698 | /* |
2699 | If the data looks correct, then copy it to our private | |
43f66a6c | 2700 | copy. Otherwise let the firmware know to perform the operation |
c7b6a674 | 2701 | on its own. |
0edd5b44 | 2702 | */ |
386093ef | 2703 | if (priv->eeprom[EEPROM_VERSION] != 0) { |
43f66a6c JK |
2704 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
2705 | ||
2706 | /* write the eeprom data to sram */ | |
b095c381 | 2707 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
0edd5b44 | 2708 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
43f66a6c JK |
2709 | |
2710 | /* Do not load eeprom data on fatal error or suspend */ | |
2711 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); | |
2712 | } else { | |
2713 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); | |
2714 | ||
2715 | /* Load eeprom data on fatal error or suspend */ | |
2716 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); | |
2717 | } | |
2718 | ||
2719 | IPW_DEBUG_TRACE("<<\n"); | |
2720 | } | |
2721 | ||
858119e1 | 2722 | static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count) |
43f66a6c JK |
2723 | { |
2724 | count >>= 2; | |
0edd5b44 JG |
2725 | if (!count) |
2726 | return; | |
b095c381 | 2727 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
bf79451e | 2728 | while (count--) |
b095c381 | 2729 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
43f66a6c JK |
2730 | } |
2731 | ||
2732 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) | |
2733 | { | |
b095c381 | 2734 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
bf79451e | 2735 | CB_NUMBER_OF_ELEMENTS_SMALL * |
43f66a6c JK |
2736 | sizeof(struct command_block)); |
2737 | } | |
2738 | ||
2739 | static int ipw_fw_dma_enable(struct ipw_priv *priv) | |
0edd5b44 | 2740 | { /* start dma engine but no transfers yet */ |
43f66a6c JK |
2741 | |
2742 | IPW_DEBUG_FW(">> : \n"); | |
bf79451e | 2743 | |
43f66a6c JK |
2744 | /* Start the dma */ |
2745 | ipw_fw_dma_reset_command_blocks(priv); | |
bf79451e | 2746 | |
43f66a6c | 2747 | /* Write CB base address */ |
b095c381 | 2748 | ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL); |
43f66a6c JK |
2749 | |
2750 | IPW_DEBUG_FW("<< : \n"); | |
2751 | return 0; | |
2752 | } | |
2753 | ||
2754 | static void ipw_fw_dma_abort(struct ipw_priv *priv) | |
2755 | { | |
2756 | u32 control = 0; | |
2757 | ||
2758 | IPW_DEBUG_FW(">> :\n"); | |
bf79451e | 2759 | |
67fd6b45 | 2760 | /* set the Stop and Abort bit */ |
43f66a6c | 2761 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
b095c381 | 2762 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
43f66a6c | 2763 | priv->sram_desc.last_cb_index = 0; |
bf79451e | 2764 | |
43f66a6c JK |
2765 | IPW_DEBUG_FW("<< \n"); |
2766 | } | |
2767 | ||
0edd5b44 JG |
2768 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
2769 | struct command_block *cb) | |
43f66a6c | 2770 | { |
0edd5b44 | 2771 | u32 address = |
b095c381 | 2772 | IPW_SHARED_SRAM_DMA_CONTROL + |
0edd5b44 | 2773 | (sizeof(struct command_block) * index); |
43f66a6c JK |
2774 | IPW_DEBUG_FW(">> :\n"); |
2775 | ||
0edd5b44 JG |
2776 | ipw_write_indirect(priv, address, (u8 *) cb, |
2777 | (int)sizeof(struct command_block)); | |
43f66a6c JK |
2778 | |
2779 | IPW_DEBUG_FW("<< :\n"); | |
2780 | return 0; | |
2781 | ||
2782 | } | |
2783 | ||
2784 | static int ipw_fw_dma_kick(struct ipw_priv *priv) | |
2785 | { | |
2786 | u32 control = 0; | |
0edd5b44 | 2787 | u32 index = 0; |
43f66a6c JK |
2788 | |
2789 | IPW_DEBUG_FW(">> :\n"); | |
bf79451e | 2790 | |
43f66a6c | 2791 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
0edd5b44 JG |
2792 | ipw_fw_dma_write_command_block(priv, index, |
2793 | &priv->sram_desc.cb_list[index]); | |
43f66a6c JK |
2794 | |
2795 | /* Enable the DMA in the CSR register */ | |
b095c381 JK |
2796 | ipw_clear_bit(priv, IPW_RESET_REG, |
2797 | IPW_RESET_REG_MASTER_DISABLED | | |
2798 | IPW_RESET_REG_STOP_MASTER); | |
bf79451e | 2799 | |
0edd5b44 | 2800 | /* Set the Start bit. */ |
43f66a6c | 2801 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
b095c381 | 2802 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
43f66a6c JK |
2803 | |
2804 | IPW_DEBUG_FW("<< :\n"); | |
2805 | return 0; | |
2806 | } | |
2807 | ||
2808 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) | |
2809 | { | |
2810 | u32 address; | |
0edd5b44 JG |
2811 | u32 register_value = 0; |
2812 | u32 cb_fields_address = 0; | |
43f66a6c JK |
2813 | |
2814 | IPW_DEBUG_FW(">> :\n"); | |
b095c381 | 2815 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
0edd5b44 | 2816 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
43f66a6c JK |
2817 | |
2818 | /* Read the DMA Controlor register */ | |
b095c381 JK |
2819 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
2820 | IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value); | |
43f66a6c | 2821 | |
0edd5b44 | 2822 | /* Print the CB values */ |
43f66a6c JK |
2823 | cb_fields_address = address; |
2824 | register_value = ipw_read_reg32(priv, cb_fields_address); | |
0edd5b44 | 2825 | IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value); |
43f66a6c JK |
2826 | |
2827 | cb_fields_address += sizeof(u32); | |
2828 | register_value = ipw_read_reg32(priv, cb_fields_address); | |
0edd5b44 | 2829 | IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value); |
43f66a6c JK |
2830 | |
2831 | cb_fields_address += sizeof(u32); | |
2832 | register_value = ipw_read_reg32(priv, cb_fields_address); | |
2833 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", | |
2834 | register_value); | |
2835 | ||
2836 | cb_fields_address += sizeof(u32); | |
2837 | register_value = ipw_read_reg32(priv, cb_fields_address); | |
0edd5b44 | 2838 | IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value); |
43f66a6c JK |
2839 | |
2840 | IPW_DEBUG_FW(">> :\n"); | |
2841 | } | |
2842 | ||
2843 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) | |
2844 | { | |
2845 | u32 current_cb_address = 0; | |
2846 | u32 current_cb_index = 0; | |
2847 | ||
2848 | IPW_DEBUG_FW("<< :\n"); | |
b095c381 | 2849 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
bf79451e | 2850 | |
b095c381 | 2851 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
0edd5b44 | 2852 | sizeof(struct command_block); |
bf79451e | 2853 | |
43f66a6c | 2854 | IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n", |
0edd5b44 | 2855 | current_cb_index, current_cb_address); |
43f66a6c JK |
2856 | |
2857 | IPW_DEBUG_FW(">> :\n"); | |
2858 | return current_cb_index; | |
2859 | ||
2860 | } | |
2861 | ||
2862 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, | |
2863 | u32 src_address, | |
2864 | u32 dest_address, | |
2865 | u32 length, | |
0edd5b44 | 2866 | int interrupt_enabled, int is_last) |
43f66a6c JK |
2867 | { |
2868 | ||
bf79451e | 2869 | u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC | |
0edd5b44 JG |
2870 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
2871 | CB_DEST_SIZE_LONG; | |
43f66a6c | 2872 | struct command_block *cb; |
0edd5b44 | 2873 | u32 last_cb_element = 0; |
43f66a6c JK |
2874 | |
2875 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", | |
2876 | src_address, dest_address, length); | |
2877 | ||
2878 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) | |
2879 | return -1; | |
2880 | ||
2881 | last_cb_element = priv->sram_desc.last_cb_index; | |
2882 | cb = &priv->sram_desc.cb_list[last_cb_element]; | |
2883 | priv->sram_desc.last_cb_index++; | |
2884 | ||
2885 | /* Calculate the new CB control word */ | |
0edd5b44 | 2886 | if (interrupt_enabled) |
43f66a6c JK |
2887 | control |= CB_INT_ENABLED; |
2888 | ||
2889 | if (is_last) | |
2890 | control |= CB_LAST_VALID; | |
bf79451e | 2891 | |
43f66a6c JK |
2892 | control |= length; |
2893 | ||
2894 | /* Calculate the CB Element's checksum value */ | |
0edd5b44 | 2895 | cb->status = control ^ src_address ^ dest_address; |
43f66a6c JK |
2896 | |
2897 | /* Copy the Source and Destination addresses */ | |
2898 | cb->dest_addr = dest_address; | |
2899 | cb->source_addr = src_address; | |
2900 | ||
2901 | /* Copy the Control Word last */ | |
2902 | cb->control = control; | |
2903 | ||
2904 | return 0; | |
2905 | } | |
2906 | ||
11ebd1bf ZY |
2907 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address, |
2908 | int nr, u32 dest_address, u32 len) | |
43f66a6c | 2909 | { |
11ebd1bf ZY |
2910 | int ret, i; |
2911 | u32 size; | |
2912 | ||
43f66a6c | 2913 | IPW_DEBUG_FW(">> \n"); |
11ebd1bf ZY |
2914 | IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n", |
2915 | nr, dest_address, len); | |
2916 | ||
2917 | for (i = 0; i < nr; i++) { | |
2918 | size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH); | |
2919 | ret = ipw_fw_dma_add_command_block(priv, src_address[i], | |
2920 | dest_address + | |
2921 | i * CB_MAX_LENGTH, size, | |
2922 | 0, 0); | |
2923 | if (ret) { | |
43f66a6c JK |
2924 | IPW_DEBUG_FW_INFO(": Failed\n"); |
2925 | return -1; | |
bf79451e | 2926 | } else |
43f66a6c | 2927 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
43f66a6c | 2928 | } |
bf79451e | 2929 | |
43f66a6c JK |
2930 | IPW_DEBUG_FW("<< \n"); |
2931 | return 0; | |
2932 | } | |
2933 | ||
2934 | static int ipw_fw_dma_wait(struct ipw_priv *priv) | |
2935 | { | |
397ae121 | 2936 | u32 current_index = 0, previous_index; |
43f66a6c JK |
2937 | u32 watchdog = 0; |
2938 | ||
2939 | IPW_DEBUG_FW(">> : \n"); | |
2940 | ||
2941 | current_index = ipw_fw_dma_command_block_index(priv); | |
397ae121 | 2942 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", |
0edd5b44 | 2943 | (int)priv->sram_desc.last_cb_index); |
43f66a6c JK |
2944 | |
2945 | while (current_index < priv->sram_desc.last_cb_index) { | |
2946 | udelay(50); | |
397ae121 | 2947 | previous_index = current_index; |
43f66a6c JK |
2948 | current_index = ipw_fw_dma_command_block_index(priv); |
2949 | ||
397ae121 ZY |
2950 | if (previous_index < current_index) { |
2951 | watchdog = 0; | |
2952 | continue; | |
2953 | } | |
2954 | if (++watchdog > 400) { | |
43f66a6c JK |
2955 | IPW_DEBUG_FW_INFO("Timeout\n"); |
2956 | ipw_fw_dma_dump_command_block(priv); | |
2957 | ipw_fw_dma_abort(priv); | |
2958 | return -1; | |
2959 | } | |
2960 | } | |
2961 | ||
2962 | ipw_fw_dma_abort(priv); | |
2963 | ||
0edd5b44 | 2964 | /*Disable the DMA in the CSR register */ |
b095c381 JK |
2965 | ipw_set_bit(priv, IPW_RESET_REG, |
2966 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); | |
43f66a6c JK |
2967 | |
2968 | IPW_DEBUG_FW("<< dmaWaitSync \n"); | |
2969 | return 0; | |
2970 | } | |
2971 | ||
bf79451e | 2972 | static void ipw_remove_current_network(struct ipw_priv *priv) |
43f66a6c JK |
2973 | { |
2974 | struct list_head *element, *safe; | |
b0a4e7d8 | 2975 | struct libipw_network *network = NULL; |
a613bffd JK |
2976 | unsigned long flags; |
2977 | ||
2978 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
43f66a6c | 2979 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
b0a4e7d8 | 2980 | network = list_entry(element, struct libipw_network, list); |
43f66a6c JK |
2981 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
2982 | list_del(element); | |
bf79451e | 2983 | list_add_tail(&network->list, |
43f66a6c JK |
2984 | &priv->ieee->network_free_list); |
2985 | } | |
2986 | } | |
a613bffd | 2987 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
43f66a6c JK |
2988 | } |
2989 | ||
2990 | /** | |
bf79451e | 2991 | * Check that card is still alive. |
43f66a6c JK |
2992 | * Reads debug register from domain0. |
2993 | * If card is present, pre-defined value should | |
2994 | * be found there. | |
bf79451e | 2995 | * |
43f66a6c JK |
2996 | * @param priv |
2997 | * @return 1 if card is present, 0 otherwise | |
2998 | */ | |
2999 | static inline int ipw_alive(struct ipw_priv *priv) | |
3000 | { | |
3001 | return ipw_read32(priv, 0x90) == 0xd55555d5; | |
3002 | } | |
3003 | ||
c7b6a674 | 3004 | /* timeout in msec, attempted in 10-msec quanta */ |
858119e1 | 3005 | static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask, |
43f66a6c JK |
3006 | int timeout) |
3007 | { | |
3008 | int i = 0; | |
3009 | ||
3010 | do { | |
bf79451e | 3011 | if ((ipw_read32(priv, addr) & mask) == mask) |
43f66a6c JK |
3012 | return i; |
3013 | mdelay(10); | |
3014 | i += 10; | |
3015 | } while (i < timeout); | |
bf79451e | 3016 | |
43f66a6c JK |
3017 | return -ETIME; |
3018 | } | |
3019 | ||
bf79451e | 3020 | /* These functions load the firmware and micro code for the operation of |
43f66a6c JK |
3021 | * the ipw hardware. It assumes the buffer has all the bits for the |
3022 | * image and the caller is handling the memory allocation and clean up. | |
3023 | */ | |
3024 | ||
0edd5b44 | 3025 | static int ipw_stop_master(struct ipw_priv *priv) |
43f66a6c JK |
3026 | { |
3027 | int rc; | |
bf79451e | 3028 | |
43f66a6c JK |
3029 | IPW_DEBUG_TRACE(">> \n"); |
3030 | /* stop master. typical delay - 0 */ | |
b095c381 | 3031 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
43f66a6c | 3032 | |
c7b6a674 | 3033 | /* timeout is in msec, polled in 10-msec quanta */ |
b095c381 JK |
3034 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
3035 | IPW_RESET_REG_MASTER_DISABLED, 100); | |
43f66a6c | 3036 | if (rc < 0) { |
c7b6a674 | 3037 | IPW_ERROR("wait for stop master failed after 100ms\n"); |
43f66a6c JK |
3038 | return -1; |
3039 | } | |
3040 | ||
3041 | IPW_DEBUG_INFO("stop master %dms\n", rc); | |
3042 | ||
3043 | return rc; | |
3044 | } | |
3045 | ||
3046 | static void ipw_arc_release(struct ipw_priv *priv) | |
3047 | { | |
3048 | IPW_DEBUG_TRACE(">> \n"); | |
3049 | mdelay(5); | |
3050 | ||
b095c381 | 3051 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
43f66a6c JK |
3052 | |
3053 | /* no one knows timing, for safety add some delay */ | |
3054 | mdelay(5); | |
3055 | } | |
3056 | ||
43f66a6c | 3057 | struct fw_chunk { |
e62e1ee0 AV |
3058 | __le32 address; |
3059 | __le32 length; | |
43f66a6c JK |
3060 | }; |
3061 | ||
0edd5b44 | 3062 | static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len) |
43f66a6c JK |
3063 | { |
3064 | int rc = 0, i, addr; | |
3065 | u8 cr = 0; | |
e62e1ee0 | 3066 | __le16 *image; |
43f66a6c | 3067 | |
e62e1ee0 | 3068 | image = (__le16 *) data; |
bf79451e | 3069 | |
43f66a6c JK |
3070 | IPW_DEBUG_TRACE(">> \n"); |
3071 | ||
3072 | rc = ipw_stop_master(priv); | |
3073 | ||
3074 | if (rc < 0) | |
3075 | return rc; | |
bf79451e | 3076 | |
b095c381 JK |
3077 | for (addr = IPW_SHARED_LOWER_BOUND; |
3078 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { | |
43f66a6c JK |
3079 | ipw_write32(priv, addr, 0); |
3080 | } | |
3081 | ||
3082 | /* no ucode (yet) */ | |
3083 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); | |
3084 | /* destroy DMA queues */ | |
3085 | /* reset sequence */ | |
3086 | ||
b095c381 | 3087 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON); |
43f66a6c | 3088 | ipw_arc_release(priv); |
b095c381 | 3089 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF); |
43f66a6c JK |
3090 | mdelay(1); |
3091 | ||
3092 | /* reset PHY */ | |
b095c381 | 3093 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
43f66a6c | 3094 | mdelay(1); |
bf79451e | 3095 | |
b095c381 | 3096 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
43f66a6c | 3097 | mdelay(1); |
bf79451e | 3098 | |
43f66a6c | 3099 | /* enable ucode store */ |
c8fe6679 ZY |
3100 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
3101 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); | |
43f66a6c JK |
3102 | mdelay(1); |
3103 | ||
3104 | /* write ucode */ | |
3105 | /** | |
3106 | * @bug | |
3107 | * Do NOT set indirect address register once and then | |
3108 | * store data to indirect data register in the loop. | |
3109 | * It seems very reasonable, but in this case DINO do not | |
3110 | * accept ucode. It is essential to set address each time. | |
3111 | */ | |
3112 | /* load new ipw uCode */ | |
3113 | for (i = 0; i < len / 2; i++) | |
b095c381 | 3114 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
e62e1ee0 | 3115 | le16_to_cpu(image[i])); |
43f66a6c | 3116 | |
43f66a6c | 3117 | /* enable DINO */ |
b095c381 JK |
3118 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
3119 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); | |
43f66a6c | 3120 | |
0edd5b44 | 3121 | /* this is where the igx / win driver deveates from the VAP driver. */ |
43f66a6c JK |
3122 | |
3123 | /* wait for alive response */ | |
3124 | for (i = 0; i < 100; i++) { | |
3125 | /* poll for incoming data */ | |
b095c381 | 3126 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
43f66a6c JK |
3127 | if (cr & DINO_RXFIFO_DATA) |
3128 | break; | |
3129 | mdelay(1); | |
3130 | } | |
3131 | ||
3132 | if (cr & DINO_RXFIFO_DATA) { | |
3133 | /* alive_command_responce size is NOT multiple of 4 */ | |
e62e1ee0 | 3134 | __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; |
bf79451e JG |
3135 | |
3136 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) | |
43f66a6c | 3137 | response_buffer[i] = |
e62e1ee0 | 3138 | cpu_to_le32(ipw_read_reg32(priv, |
b095c381 | 3139 | IPW_BASEBAND_RX_FIFO_READ)); |
43f66a6c JK |
3140 | memcpy(&priv->dino_alive, response_buffer, |
3141 | sizeof(priv->dino_alive)); | |
3142 | if (priv->dino_alive.alive_command == 1 | |
3143 | && priv->dino_alive.ucode_valid == 1) { | |
3144 | rc = 0; | |
0edd5b44 JG |
3145 | IPW_DEBUG_INFO |
3146 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " | |
3147 | "of %02d/%02d/%02d %02d:%02d\n", | |
3148 | priv->dino_alive.software_revision, | |
3149 | priv->dino_alive.software_revision, | |
3150 | priv->dino_alive.device_identifier, | |
3151 | priv->dino_alive.device_identifier, | |
3152 | priv->dino_alive.time_stamp[0], | |
3153 | priv->dino_alive.time_stamp[1], | |
3154 | priv->dino_alive.time_stamp[2], | |
3155 | priv->dino_alive.time_stamp[3], | |
3156 | priv->dino_alive.time_stamp[4]); | |
43f66a6c JK |
3157 | } else { |
3158 | IPW_DEBUG_INFO("Microcode is not alive\n"); | |
3159 | rc = -EINVAL; | |
3160 | } | |
3161 | } else { | |
3162 | IPW_DEBUG_INFO("No alive response from DINO\n"); | |
3163 | rc = -ETIME; | |
3164 | } | |
3165 | ||
3166 | /* disable DINO, otherwise for some reason | |
3167 | firmware have problem getting alive resp. */ | |
b095c381 | 3168 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
43f66a6c | 3169 | |
43f66a6c JK |
3170 | return rc; |
3171 | } | |
3172 | ||
0edd5b44 | 3173 | static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len) |
43f66a6c | 3174 | { |
11ebd1bf | 3175 | int ret = -1; |
43f66a6c JK |
3176 | int offset = 0; |
3177 | struct fw_chunk *chunk; | |
11ebd1bf ZY |
3178 | int total_nr = 0; |
3179 | int i; | |
3180 | struct pci_pool *pool; | |
41093167 ZY |
3181 | void **virts; |
3182 | dma_addr_t *phys; | |
43f66a6c JK |
3183 | |
3184 | IPW_DEBUG_TRACE("<< : \n"); | |
43f66a6c | 3185 | |
41093167 ZY |
3186 | virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL, |
3187 | GFP_KERNEL); | |
3188 | if (!virts) | |
3189 | return -ENOMEM; | |
3190 | ||
3191 | phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL, | |
3192 | GFP_KERNEL); | |
3193 | if (!phys) { | |
3194 | kfree(virts); | |
3195 | return -ENOMEM; | |
3196 | } | |
11ebd1bf ZY |
3197 | pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0); |
3198 | if (!pool) { | |
3199 | IPW_ERROR("pci_pool_create failed\n"); | |
41093167 ZY |
3200 | kfree(phys); |
3201 | kfree(virts); | |
43f66a6c | 3202 | return -ENOMEM; |
11ebd1bf | 3203 | } |
43f66a6c JK |
3204 | |
3205 | /* Start the Dma */ | |
11ebd1bf | 3206 | ret = ipw_fw_dma_enable(priv); |
43f66a6c | 3207 | |
0ee904c3 AB |
3208 | /* the DMA is already ready this would be a bug. */ |
3209 | BUG_ON(priv->sram_desc.last_cb_index > 0); | |
43f66a6c JK |
3210 | |
3211 | do { | |
11ebd1bf ZY |
3212 | u32 chunk_len; |
3213 | u8 *start; | |
3214 | int size; | |
3215 | int nr = 0; | |
3216 | ||
43f66a6c JK |
3217 | chunk = (struct fw_chunk *)(data + offset); |
3218 | offset += sizeof(struct fw_chunk); | |
11ebd1bf ZY |
3219 | chunk_len = le32_to_cpu(chunk->length); |
3220 | start = data + offset; | |
3221 | ||
3222 | nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH; | |
3223 | for (i = 0; i < nr; i++) { | |
3224 | virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL, | |
3225 | &phys[total_nr]); | |
3226 | if (!virts[total_nr]) { | |
3227 | ret = -ENOMEM; | |
3228 | goto out; | |
3229 | } | |
3230 | size = min_t(u32, chunk_len - i * CB_MAX_LENGTH, | |
3231 | CB_MAX_LENGTH); | |
3232 | memcpy(virts[total_nr], start, size); | |
3233 | start += size; | |
3234 | total_nr++; | |
3235 | /* We don't support fw chunk larger than 64*8K */ | |
3236 | BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL); | |
3237 | } | |
3238 | ||
43f66a6c | 3239 | /* build DMA packet and queue up for sending */ |
bf79451e | 3240 | /* dma to chunk->address, the chunk->length bytes from data + |
43f66a6c JK |
3241 | * offeset*/ |
3242 | /* Dma loading */ | |
11ebd1bf ZY |
3243 | ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr], |
3244 | nr, le32_to_cpu(chunk->address), | |
3245 | chunk_len); | |
3246 | if (ret) { | |
43f66a6c JK |
3247 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); |
3248 | goto out; | |
3249 | } | |
bf79451e | 3250 | |
11ebd1bf | 3251 | offset += chunk_len; |
43f66a6c JK |
3252 | } while (offset < len); |
3253 | ||
0edd5b44 | 3254 | /* Run the DMA and wait for the answer */ |
11ebd1bf ZY |
3255 | ret = ipw_fw_dma_kick(priv); |
3256 | if (ret) { | |
43f66a6c JK |
3257 | IPW_ERROR("dmaKick Failed\n"); |
3258 | goto out; | |
3259 | } | |
3260 | ||
11ebd1bf ZY |
3261 | ret = ipw_fw_dma_wait(priv); |
3262 | if (ret) { | |
43f66a6c JK |
3263 | IPW_ERROR("dmaWaitSync Failed\n"); |
3264 | goto out; | |
3265 | } | |
11ebd1bf ZY |
3266 | out: |
3267 | for (i = 0; i < total_nr; i++) | |
3268 | pci_pool_free(pool, virts[i], phys[i]); | |
3269 | ||
3270 | pci_pool_destroy(pool); | |
41093167 ZY |
3271 | kfree(phys); |
3272 | kfree(virts); | |
11ebd1bf ZY |
3273 | |
3274 | return ret; | |
43f66a6c JK |
3275 | } |
3276 | ||
3277 | /* stop nic */ | |
3278 | static int ipw_stop_nic(struct ipw_priv *priv) | |
3279 | { | |
3280 | int rc = 0; | |
3281 | ||
0edd5b44 | 3282 | /* stop */ |
b095c381 | 3283 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
bf79451e | 3284 | |
b095c381 JK |
3285 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
3286 | IPW_RESET_REG_MASTER_DISABLED, 500); | |
43f66a6c | 3287 | if (rc < 0) { |
c7b6a674 | 3288 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
43f66a6c | 3289 | return rc; |
bf79451e | 3290 | } |
43f66a6c | 3291 | |
b095c381 | 3292 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
bf79451e | 3293 | |
43f66a6c JK |
3294 | return rc; |
3295 | } | |
3296 | ||
3297 | static void ipw_start_nic(struct ipw_priv *priv) | |
3298 | { | |
3299 | IPW_DEBUG_TRACE(">>\n"); | |
3300 | ||
0edd5b44 | 3301 | /* prvHwStartNic release ARC */ |
b095c381 JK |
3302 | ipw_clear_bit(priv, IPW_RESET_REG, |
3303 | IPW_RESET_REG_MASTER_DISABLED | | |
3304 | IPW_RESET_REG_STOP_MASTER | | |
43f66a6c | 3305 | CBD_RESET_REG_PRINCETON_RESET); |
bf79451e | 3306 | |
43f66a6c | 3307 | /* enable power management */ |
b095c381 JK |
3308 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
3309 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); | |
43f66a6c JK |
3310 | |
3311 | IPW_DEBUG_TRACE("<<\n"); | |
3312 | } | |
bf79451e | 3313 | |
43f66a6c JK |
3314 | static int ipw_init_nic(struct ipw_priv *priv) |
3315 | { | |
3316 | int rc; | |
3317 | ||
3318 | IPW_DEBUG_TRACE(">>\n"); | |
bf79451e | 3319 | /* reset */ |
43f66a6c JK |
3320 | /*prvHwInitNic */ |
3321 | /* set "initialization complete" bit to move adapter to D0 state */ | |
b095c381 | 3322 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); |
43f66a6c JK |
3323 | |
3324 | /* low-level PLL activation */ | |
b095c381 JK |
3325 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
3326 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); | |
43f66a6c JK |
3327 | |
3328 | /* wait for clock stabilization */ | |
b095c381 JK |
3329 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
3330 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); | |
0edd5b44 | 3331 | if (rc < 0) |
43f66a6c JK |
3332 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
3333 | ||
3334 | /* assert SW reset */ | |
b095c381 | 3335 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
43f66a6c JK |
3336 | |
3337 | udelay(10); | |
3338 | ||
3339 | /* set "initialization complete" bit to move adapter to D0 state */ | |
b095c381 | 3340 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); |
43f66a6c JK |
3341 | |
3342 | IPW_DEBUG_TRACE(">>\n"); | |
3343 | return 0; | |
3344 | } | |
3345 | ||
bf79451e | 3346 | /* Call this function from process context, it will sleep in request_firmware. |
43f66a6c JK |
3347 | * Probe is an ok place to call this from. |
3348 | */ | |
3349 | static int ipw_reset_nic(struct ipw_priv *priv) | |
3350 | { | |
3351 | int rc = 0; | |
a613bffd | 3352 | unsigned long flags; |
43f66a6c JK |
3353 | |
3354 | IPW_DEBUG_TRACE(">>\n"); | |
bf79451e | 3355 | |
43f66a6c | 3356 | rc = ipw_init_nic(priv); |
bf79451e | 3357 | |
a613bffd | 3358 | spin_lock_irqsave(&priv->lock, flags); |
43f66a6c JK |
3359 | /* Clear the 'host command active' bit... */ |
3360 | priv->status &= ~STATUS_HCMD_ACTIVE; | |
3361 | wake_up_interruptible(&priv->wait_command_queue); | |
afbf30a2 JK |
3362 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
3363 | wake_up_interruptible(&priv->wait_state); | |
a613bffd | 3364 | spin_unlock_irqrestore(&priv->lock, flags); |
43f66a6c JK |
3365 | |
3366 | IPW_DEBUG_TRACE("<<\n"); | |
3367 | return rc; | |
bf79451e | 3368 | } |
43f66a6c | 3369 | |
9006ea75 JK |
3370 | |
3371 | struct ipw_fw { | |
0070f8c7 ZY |
3372 | __le32 ver; |
3373 | __le32 boot_size; | |
3374 | __le32 ucode_size; | |
3375 | __le32 fw_size; | |
9006ea75 JK |
3376 | u8 data[0]; |
3377 | }; | |
3378 | ||
bf79451e | 3379 | static int ipw_get_fw(struct ipw_priv *priv, |
9006ea75 | 3380 | const struct firmware **raw, const char *name) |
43f66a6c | 3381 | { |
9006ea75 | 3382 | struct ipw_fw *fw; |
43f66a6c JK |
3383 | int rc; |
3384 | ||
3385 | /* ask firmware_class module to get the boot firmware off disk */ | |
9006ea75 | 3386 | rc = request_firmware(raw, name, &priv->pci_dev->dev); |
43f66a6c | 3387 | if (rc < 0) { |
9006ea75 | 3388 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); |
43f66a6c | 3389 | return rc; |
bf79451e | 3390 | } |
43f66a6c | 3391 | |
9006ea75 JK |
3392 | if ((*raw)->size < sizeof(*fw)) { |
3393 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); | |
3394 | return -EINVAL; | |
3395 | } | |
3396 | ||
3397 | fw = (void *)(*raw)->data; | |
3398 | ||
0070f8c7 ZY |
3399 | if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) + |
3400 | le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) { | |
9006ea75 JK |
3401 | IPW_ERROR("%s is too small or corrupt (%zd)\n", |
3402 | name, (*raw)->size); | |
43f66a6c JK |
3403 | return -EINVAL; |
3404 | } | |
3405 | ||
9006ea75 | 3406 | IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n", |
43f66a6c | 3407 | name, |
9006ea75 JK |
3408 | le32_to_cpu(fw->ver) >> 16, |
3409 | le32_to_cpu(fw->ver) & 0xff, | |
3410 | (*raw)->size - sizeof(*fw)); | |
43f66a6c JK |
3411 | return 0; |
3412 | } | |
3413 | ||
b095c381 | 3414 | #define IPW_RX_BUF_SIZE (3000) |
43f66a6c | 3415 | |
858119e1 | 3416 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
43f66a6c JK |
3417 | struct ipw_rx_queue *rxq) |
3418 | { | |
3419 | unsigned long flags; | |
3420 | int i; | |
3421 | ||
3422 | spin_lock_irqsave(&rxq->lock, flags); | |
3423 | ||
3424 | INIT_LIST_HEAD(&rxq->rx_free); | |
3425 | INIT_LIST_HEAD(&rxq->rx_used); | |
3426 | ||
3427 | /* Fill the rx_used queue with _all_ of the Rx buffers */ | |
3428 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { | |
3429 | /* In the reset function, these buffers may have been allocated | |
3430 | * to an SKB, so we need to unmap and free potential storage */ | |
3431 | if (rxq->pool[i].skb != NULL) { | |
3432 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, | |
b095c381 | 3433 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
43f66a6c | 3434 | dev_kfree_skb(rxq->pool[i].skb); |
a613bffd | 3435 | rxq->pool[i].skb = NULL; |
43f66a6c JK |
3436 | } |
3437 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); | |
3438 | } | |
bf79451e | 3439 | |
43f66a6c JK |
3440 | /* Set us so that we have processed and used all buffers, but have |
3441 | * not restocked the Rx queue with fresh buffers */ | |
3442 | rxq->read = rxq->write = 0; | |
43f66a6c JK |
3443 | rxq->free_count = 0; |
3444 | spin_unlock_irqrestore(&rxq->lock, flags); | |
3445 | } | |
3446 | ||
3447 | #ifdef CONFIG_PM | |
3448 | static int fw_loaded = 0; | |
9006ea75 | 3449 | static const struct firmware *raw = NULL; |
afbf30a2 JK |
3450 | |
3451 | static void free_firmware(void) | |
3452 | { | |
3453 | if (fw_loaded) { | |
9006ea75 JK |
3454 | release_firmware(raw); |
3455 | raw = NULL; | |
afbf30a2 JK |
3456 | fw_loaded = 0; |
3457 | } | |
3458 | } | |
3459 | #else | |
3460 | #define free_firmware() do {} while (0) | |
43f66a6c JK |
3461 | #endif |
3462 | ||
3463 | static int ipw_load(struct ipw_priv *priv) | |
3464 | { | |
3465 | #ifndef CONFIG_PM | |
9006ea75 | 3466 | const struct firmware *raw = NULL; |
43f66a6c | 3467 | #endif |
9006ea75 JK |
3468 | struct ipw_fw *fw; |
3469 | u8 *boot_img, *ucode_img, *fw_img; | |
3470 | u8 *name = NULL; | |
43f66a6c JK |
3471 | int rc = 0, retries = 3; |
3472 | ||
397ae121 ZY |
3473 | switch (priv->ieee->iw_mode) { |
3474 | case IW_MODE_ADHOC: | |
9006ea75 | 3475 | name = "ipw2200-ibss.fw"; |
397ae121 | 3476 | break; |
b095c381 | 3477 | #ifdef CONFIG_IPW2200_MONITOR |
397ae121 | 3478 | case IW_MODE_MONITOR: |
9006ea75 | 3479 | name = "ipw2200-sniffer.fw"; |
397ae121 | 3480 | break; |
43f66a6c | 3481 | #endif |
397ae121 | 3482 | case IW_MODE_INFRA: |
9006ea75 | 3483 | name = "ipw2200-bss.fw"; |
397ae121 | 3484 | break; |
9006ea75 JK |
3485 | } |
3486 | ||
3487 | if (!name) { | |
397ae121 | 3488 | rc = -EINVAL; |
9006ea75 JK |
3489 | goto error; |
3490 | } | |
3491 | ||
3492 | #ifdef CONFIG_PM | |
3493 | if (!fw_loaded) { | |
3494 | #endif | |
3495 | rc = ipw_get_fw(priv, &raw, name); | |
3496 | if (rc < 0) | |
3497 | goto error; | |
3498 | #ifdef CONFIG_PM | |
43f66a6c | 3499 | } |
9006ea75 JK |
3500 | #endif |
3501 | ||
3502 | fw = (void *)raw->data; | |
3503 | boot_img = &fw->data[0]; | |
0070f8c7 ZY |
3504 | ucode_img = &fw->data[le32_to_cpu(fw->boot_size)]; |
3505 | fw_img = &fw->data[le32_to_cpu(fw->boot_size) + | |
3506 | le32_to_cpu(fw->ucode_size)]; | |
397ae121 ZY |
3507 | |
3508 | if (rc < 0) | |
3509 | goto error; | |
43f66a6c JK |
3510 | |
3511 | if (!priv->rxq) | |
3512 | priv->rxq = ipw_rx_queue_alloc(priv); | |
3513 | else | |
3514 | ipw_rx_queue_reset(priv, priv->rxq); | |
3515 | if (!priv->rxq) { | |
3516 | IPW_ERROR("Unable to initialize Rx queue\n"); | |
3517 | goto error; | |
3518 | } | |
3519 | ||
0edd5b44 | 3520 | retry: |
43f66a6c | 3521 | /* Ensure interrupts are disabled */ |
b095c381 | 3522 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
43f66a6c JK |
3523 | priv->status &= ~STATUS_INT_ENABLED; |
3524 | ||
3525 | /* ack pending interrupts */ | |
b095c381 | 3526 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
bf79451e | 3527 | |
43f66a6c JK |
3528 | ipw_stop_nic(priv); |
3529 | ||
3530 | rc = ipw_reset_nic(priv); | |
397ae121 | 3531 | if (rc < 0) { |
43f66a6c JK |
3532 | IPW_ERROR("Unable to reset NIC\n"); |
3533 | goto error; | |
3534 | } | |
3535 | ||
b095c381 JK |
3536 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
3537 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); | |
43f66a6c JK |
3538 | |
3539 | /* DMA the initial boot firmware into the device */ | |
0070f8c7 | 3540 | rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size)); |
43f66a6c | 3541 | if (rc < 0) { |
a4f6bbb3 | 3542 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
43f66a6c JK |
3543 | goto error; |
3544 | } | |
3545 | ||
3546 | /* kick start the device */ | |
3547 | ipw_start_nic(priv); | |
3548 | ||
c7b6a674 | 3549 | /* wait for the device to finish its initial startup sequence */ |
b095c381 JK |
3550 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
3551 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); | |
43f66a6c JK |
3552 | if (rc < 0) { |
3553 | IPW_ERROR("device failed to boot initial fw image\n"); | |
3554 | goto error; | |
3555 | } | |
3556 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); | |
3557 | ||
bf79451e | 3558 | /* ack fw init done interrupt */ |
b095c381 | 3559 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
43f66a6c JK |
3560 | |
3561 | /* DMA the ucode into the device */ | |
0070f8c7 | 3562 | rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size)); |
43f66a6c | 3563 | if (rc < 0) { |
a4f6bbb3 | 3564 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
43f66a6c JK |
3565 | goto error; |
3566 | } | |
bf79451e | 3567 | |
43f66a6c JK |
3568 | /* stop nic */ |
3569 | ipw_stop_nic(priv); | |
3570 | ||
3571 | /* DMA bss firmware into the device */ | |
0070f8c7 | 3572 | rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size)); |
0edd5b44 | 3573 | if (rc < 0) { |
a4f6bbb3 | 3574 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
43f66a6c JK |
3575 | goto error; |
3576 | } | |
397ae121 ZY |
3577 | #ifdef CONFIG_PM |
3578 | fw_loaded = 1; | |
3579 | #endif | |
3580 | ||
43f66a6c JK |
3581 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
3582 | ||
3583 | rc = ipw_queue_reset(priv); | |
397ae121 | 3584 | if (rc < 0) { |
43f66a6c JK |
3585 | IPW_ERROR("Unable to initialize queues\n"); |
3586 | goto error; | |
3587 | } | |
3588 | ||
3589 | /* Ensure interrupts are disabled */ | |
b095c381 | 3590 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
c848d0af | 3591 | /* ack pending interrupts */ |
b095c381 | 3592 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
bf79451e | 3593 | |
43f66a6c JK |
3594 | /* kick start the device */ |
3595 | ipw_start_nic(priv); | |
3596 | ||
b095c381 | 3597 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
43f66a6c JK |
3598 | if (retries > 0) { |
3599 | IPW_WARNING("Parity error. Retrying init.\n"); | |
3600 | retries--; | |
3601 | goto retry; | |
3602 | } | |
3603 | ||
3604 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); | |
3605 | rc = -EIO; | |
3606 | goto error; | |
3607 | } | |
3608 | ||
3609 | /* wait for the device */ | |
b095c381 JK |
3610 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
3611 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); | |
43f66a6c | 3612 | if (rc < 0) { |
c7b6a674 | 3613 | IPW_ERROR("device failed to start within 500ms\n"); |
43f66a6c JK |
3614 | goto error; |
3615 | } | |
3616 | IPW_DEBUG_INFO("device response after %dms\n", rc); | |
3617 | ||
3618 | /* ack fw init done interrupt */ | |
b095c381 | 3619 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
43f66a6c JK |
3620 | |
3621 | /* read eeprom data and initialize the eeprom region of sram */ | |
3622 | priv->eeprom_delay = 1; | |
bf79451e | 3623 | ipw_eeprom_init_sram(priv); |
43f66a6c JK |
3624 | |
3625 | /* enable interrupts */ | |
3626 | ipw_enable_interrupts(priv); | |
3627 | ||
3628 | /* Ensure our queue has valid packets */ | |
3629 | ipw_rx_queue_replenish(priv); | |
3630 | ||
b095c381 | 3631 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
43f66a6c JK |
3632 | |
3633 | /* ack pending interrupts */ | |
b095c381 | 3634 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
43f66a6c JK |
3635 | |
3636 | #ifndef CONFIG_PM | |
9006ea75 | 3637 | release_firmware(raw); |
43f66a6c JK |
3638 | #endif |
3639 | return 0; | |
3640 | ||
0edd5b44 | 3641 | error: |
43f66a6c JK |
3642 | if (priv->rxq) { |
3643 | ipw_rx_queue_free(priv, priv->rxq); | |
3644 | priv->rxq = NULL; | |
3645 | } | |
3646 | ipw_tx_queue_free(priv); | |
9006ea75 JK |
3647 | if (raw) |
3648 | release_firmware(raw); | |
43f66a6c JK |
3649 | #ifdef CONFIG_PM |
3650 | fw_loaded = 0; | |
9006ea75 | 3651 | raw = NULL; |
43f66a6c JK |
3652 | #endif |
3653 | ||
3654 | return rc; | |
3655 | } | |
3656 | ||
bf79451e | 3657 | /** |
43f66a6c JK |
3658 | * DMA services |
3659 | * | |
3660 | * Theory of operation | |
3661 | * | |
3662 | * A queue is a circular buffers with 'Read' and 'Write' pointers. | |
3663 | * 2 empty entries always kept in the buffer to protect from overflow. | |
3664 | * | |
3665 | * For Tx queue, there are low mark and high mark limits. If, after queuing | |
bf79451e JG |
3666 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
3667 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, | |
43f66a6c JK |
3668 | * Tx queue resumed. |
3669 | * | |
3670 | * The IPW operates with six queues, one receive queue in the device's | |
3671 | * sram, one transmit queue for sending commands to the device firmware, | |
bf79451e | 3672 | * and four transmit queues for data. |
43f66a6c | 3673 | * |
bf79451e | 3674 | * The four transmit queues allow for performing quality of service (qos) |
43f66a6c | 3675 | * transmissions as per the 802.11 protocol. Currently Linux does not |
bf79451e | 3676 | * provide a mechanism to the user for utilizing prioritized queues, so |
43f66a6c JK |
3677 | * we only utilize the first data transmit queue (queue1). |
3678 | */ | |
3679 | ||
3680 | /** | |
3681 | * Driver allocates buffers of this size for Rx | |
3682 | */ | |
3683 | ||
943dbef4 DW |
3684 | /** |
3685 | * ipw_rx_queue_space - Return number of free slots available in queue. | |
3686 | */ | |
3687 | static int ipw_rx_queue_space(const struct ipw_rx_queue *q) | |
3688 | { | |
3689 | int s = q->read - q->write; | |
3690 | if (s <= 0) | |
3691 | s += RX_QUEUE_SIZE; | |
3692 | /* keep some buffer to not confuse full and empty queue */ | |
3693 | s -= 2; | |
3694 | if (s < 0) | |
3695 | s = 0; | |
3696 | return s; | |
3697 | } | |
3698 | ||
3699 | static inline int ipw_tx_queue_space(const struct clx2_queue *q) | |
43f66a6c JK |
3700 | { |
3701 | int s = q->last_used - q->first_empty; | |
3702 | if (s <= 0) | |
3703 | s += q->n_bd; | |
3704 | s -= 2; /* keep some reserve to not confuse empty and full situations */ | |
3705 | if (s < 0) | |
3706 | s = 0; | |
3707 | return s; | |
3708 | } | |
3709 | ||
3710 | static inline int ipw_queue_inc_wrap(int index, int n_bd) | |
3711 | { | |
3712 | return (++index == n_bd) ? 0 : index; | |
3713 | } | |
3714 | ||
3715 | /** | |
3716 | * Initialize common DMA queue structure | |
bf79451e | 3717 | * |
43f66a6c JK |
3718 | * @param q queue to init |
3719 | * @param count Number of BD's to allocate. Should be power of 2 | |
3720 | * @param read_register Address for 'read' register | |
3721 | * (not offset within BAR, full address) | |
3722 | * @param write_register Address for 'write' register | |
3723 | * (not offset within BAR, full address) | |
3724 | * @param base_register Address for 'base' register | |
3725 | * (not offset within BAR, full address) | |
3726 | * @param size Address for 'size' register | |
3727 | * (not offset within BAR, full address) | |
3728 | */ | |
bf79451e | 3729 | static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q, |
0edd5b44 | 3730 | int count, u32 read, u32 write, u32 base, u32 size) |
43f66a6c JK |
3731 | { |
3732 | q->n_bd = count; | |
3733 | ||
3734 | q->low_mark = q->n_bd / 4; | |
3735 | if (q->low_mark < 4) | |
3736 | q->low_mark = 4; | |
3737 | ||
3738 | q->high_mark = q->n_bd / 8; | |
3739 | if (q->high_mark < 2) | |
3740 | q->high_mark = 2; | |
3741 | ||
3742 | q->first_empty = q->last_used = 0; | |
3743 | q->reg_r = read; | |
3744 | q->reg_w = write; | |
3745 | ||
3746 | ipw_write32(priv, base, q->dma_addr); | |
3747 | ipw_write32(priv, size, count); | |
3748 | ipw_write32(priv, read, 0); | |
3749 | ipw_write32(priv, write, 0); | |
3750 | ||
3751 | _ipw_read32(priv, 0x90); | |
3752 | } | |
3753 | ||
bf79451e | 3754 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
43f66a6c | 3755 | struct clx2_tx_queue *q, |
0edd5b44 | 3756 | int count, u32 read, u32 write, u32 base, u32 size) |
43f66a6c JK |
3757 | { |
3758 | struct pci_dev *dev = priv->pci_dev; | |
3759 | ||
3760 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); | |
3761 | if (!q->txb) { | |
3762 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); | |
3763 | return -ENOMEM; | |
3764 | } | |
3765 | ||
0edd5b44 JG |
3766 | q->bd = |
3767 | pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr); | |
43f66a6c | 3768 | if (!q->bd) { |
aaa4d308 | 3769 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
0edd5b44 | 3770 | sizeof(q->bd[0]) * count); |
43f66a6c JK |
3771 | kfree(q->txb); |
3772 | q->txb = NULL; | |
3773 | return -ENOMEM; | |
3774 | } | |
3775 | ||
3776 | ipw_queue_init(priv, &q->q, count, read, write, base, size); | |
3777 | return 0; | |
3778 | } | |
3779 | ||
3780 | /** | |
3781 | * Free one TFD, those at index [txq->q.last_used]. | |
3782 | * Do NOT advance any indexes | |
bf79451e | 3783 | * |
43f66a6c JK |
3784 | * @param dev |
3785 | * @param txq | |
3786 | */ | |
3787 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, | |
3788 | struct clx2_tx_queue *txq) | |
3789 | { | |
3790 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; | |
3791 | struct pci_dev *dev = priv->pci_dev; | |
3792 | int i; | |
bf79451e | 3793 | |
43f66a6c JK |
3794 | /* classify bd */ |
3795 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) | |
3796 | /* nothing to cleanup after for host commands */ | |
3797 | return; | |
3798 | ||
3799 | /* sanity check */ | |
a613bffd JK |
3800 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
3801 | IPW_ERROR("Too many chunks: %i\n", | |
3802 | le32_to_cpu(bd->u.data.num_chunks)); | |
43f66a6c JK |
3803 | /** @todo issue fatal error, it is quite serious situation */ |
3804 | return; | |
3805 | } | |
3806 | ||
3807 | /* unmap chunks if any */ | |
a613bffd JK |
3808 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
3809 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), | |
3810 | le16_to_cpu(bd->u.data.chunk_len[i]), | |
3811 | PCI_DMA_TODEVICE); | |
43f66a6c | 3812 | if (txq->txb[txq->q.last_used]) { |
b0a4e7d8 | 3813 | libipw_txb_free(txq->txb[txq->q.last_used]); |
43f66a6c JK |
3814 | txq->txb[txq->q.last_used] = NULL; |
3815 | } | |
3816 | } | |
3817 | } | |
3818 | ||
3819 | /** | |
3820 | * Deallocate DMA queue. | |
bf79451e | 3821 | * |
43f66a6c JK |
3822 | * Empty queue by removing and destroying all BD's. |
3823 | * Free all buffers. | |
bf79451e | 3824 | * |
43f66a6c JK |
3825 | * @param dev |
3826 | * @param q | |
3827 | */ | |
0edd5b44 | 3828 | static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq) |
43f66a6c JK |
3829 | { |
3830 | struct clx2_queue *q = &txq->q; | |
3831 | struct pci_dev *dev = priv->pci_dev; | |
3832 | ||
bf79451e JG |
3833 | if (q->n_bd == 0) |
3834 | return; | |
43f66a6c JK |
3835 | |
3836 | /* first, empty all BD's */ | |
3837 | for (; q->first_empty != q->last_used; | |
3838 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { | |
3839 | ipw_queue_tx_free_tfd(priv, txq); | |
3840 | } | |
bf79451e | 3841 | |
43f66a6c | 3842 | /* free buffers belonging to queue itself */ |
0edd5b44 | 3843 | pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd, |
43f66a6c JK |
3844 | q->dma_addr); |
3845 | kfree(txq->txb); | |
3846 | ||
3847 | /* 0 fill whole structure */ | |
3848 | memset(txq, 0, sizeof(*txq)); | |
3849 | } | |
3850 | ||
43f66a6c JK |
3851 | /** |
3852 | * Destroy all DMA queues and structures | |
bf79451e | 3853 | * |
43f66a6c JK |
3854 | * @param priv |
3855 | */ | |
3856 | static void ipw_tx_queue_free(struct ipw_priv *priv) | |
3857 | { | |
3858 | /* Tx CMD queue */ | |
3859 | ipw_queue_tx_free(priv, &priv->txq_cmd); | |
3860 | ||
3861 | /* Tx queues */ | |
3862 | ipw_queue_tx_free(priv, &priv->txq[0]); | |
3863 | ipw_queue_tx_free(priv, &priv->txq[1]); | |
3864 | ipw_queue_tx_free(priv, &priv->txq[2]); | |
3865 | ipw_queue_tx_free(priv, &priv->txq[3]); | |
3866 | } | |
3867 | ||
858119e1 | 3868 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
43f66a6c JK |
3869 | { |
3870 | /* First 3 bytes are manufacturer */ | |
3871 | bssid[0] = priv->mac_addr[0]; | |
3872 | bssid[1] = priv->mac_addr[1]; | |
3873 | bssid[2] = priv->mac_addr[2]; | |
3874 | ||
3875 | /* Last bytes are random */ | |
0edd5b44 | 3876 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
43f66a6c | 3877 | |
0edd5b44 JG |
3878 | bssid[0] &= 0xfe; /* clear multicast bit */ |
3879 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ | |
43f66a6c JK |
3880 | } |
3881 | ||
858119e1 | 3882 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
43f66a6c JK |
3883 | { |
3884 | struct ipw_station_entry entry; | |
3885 | int i; | |
3886 | ||
3887 | for (i = 0; i < priv->num_stations; i++) { | |
3888 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { | |
3889 | /* Another node is active in network */ | |
3890 | priv->missed_adhoc_beacons = 0; | |
3891 | if (!(priv->config & CFG_STATIC_CHANNEL)) | |
3892 | /* when other nodes drop out, we drop out */ | |
3893 | priv->config &= ~CFG_ADHOC_PERSIST; | |
3894 | ||
3895 | return i; | |
3896 | } | |
3897 | } | |
3898 | ||
3899 | if (i == MAX_STATIONS) | |
3900 | return IPW_INVALID_STATION; | |
3901 | ||
e174961c | 3902 | IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid); |
43f66a6c JK |
3903 | |
3904 | entry.reserved = 0; | |
3905 | entry.support_mode = 0; | |
3906 | memcpy(entry.mac_addr, bssid, ETH_ALEN); | |
3907 | memcpy(priv->stations[i], bssid, ETH_ALEN); | |
3908 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), | |
0edd5b44 | 3909 | &entry, sizeof(entry)); |
43f66a6c JK |
3910 | priv->num_stations++; |
3911 | ||
3912 | return i; | |
3913 | } | |
3914 | ||
858119e1 | 3915 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
43f66a6c JK |
3916 | { |
3917 | int i; | |
3918 | ||
bf79451e JG |
3919 | for (i = 0; i < priv->num_stations; i++) |
3920 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) | |
43f66a6c JK |
3921 | return i; |
3922 | ||
3923 | return IPW_INVALID_STATION; | |
3924 | } | |
3925 | ||
3926 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) | |
3927 | { | |
3928 | int err; | |
3929 | ||
7b99659f HL |
3930 | if (priv->status & STATUS_ASSOCIATING) { |
3931 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); | |
3932 | queue_work(priv->workqueue, &priv->disassociate); | |
3933 | return; | |
3934 | } | |
3935 | ||
3936 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
43f66a6c JK |
3937 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
3938 | return; | |
3939 | } | |
3940 | ||
e174961c | 3941 | IPW_DEBUG_ASSOC("Disassocation attempt from %pM " |
43f66a6c | 3942 | "on channel %d.\n", |
e174961c | 3943 | priv->assoc_request.bssid, |
43f66a6c JK |
3944 | priv->assoc_request.channel); |
3945 | ||
3946 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); | |
3947 | priv->status |= STATUS_DISASSOCIATING; | |
3948 | ||
3949 | if (quiet) | |
3950 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; | |
3951 | else | |
3952 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; | |
e6324726 | 3953 | |
43f66a6c JK |
3954 | err = ipw_send_associate(priv, &priv->assoc_request); |
3955 | if (err) { | |
3956 | IPW_DEBUG_HC("Attempt to send [dis]associate command " | |
3957 | "failed.\n"); | |
3958 | return; | |
3959 | } | |
3960 | ||
3961 | } | |
3962 | ||
c848d0af | 3963 | static int ipw_disassociate(void *data) |
43f66a6c | 3964 | { |
c848d0af JK |
3965 | struct ipw_priv *priv = data; |
3966 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) | |
3967 | return 0; | |
43f66a6c | 3968 | ipw_send_disassociate(data, 0); |
b8ddafd7 | 3969 | netif_carrier_off(priv->net_dev); |
c848d0af | 3970 | return 1; |
43f66a6c JK |
3971 | } |
3972 | ||
c4028958 | 3973 | static void ipw_bg_disassociate(struct work_struct *work) |
43f66a6c | 3974 | { |
c4028958 DH |
3975 | struct ipw_priv *priv = |
3976 | container_of(work, struct ipw_priv, disassociate); | |
4644151b | 3977 | mutex_lock(&priv->mutex); |
c4028958 | 3978 | ipw_disassociate(priv); |
4644151b | 3979 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
3980 | } |
3981 | ||
c4028958 | 3982 | static void ipw_system_config(struct work_struct *work) |
d8bad6df | 3983 | { |
c4028958 DH |
3984 | struct ipw_priv *priv = |
3985 | container_of(work, struct ipw_priv, system_config); | |
d685b8c2 ZY |
3986 | |
3987 | #ifdef CONFIG_IPW2200_PROMISCUOUS | |
3988 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { | |
3989 | priv->sys_config.accept_all_data_frames = 1; | |
3990 | priv->sys_config.accept_non_directed_frames = 1; | |
3991 | priv->sys_config.accept_all_mgmt_bcpr = 1; | |
3992 | priv->sys_config.accept_all_mgmt_frames = 1; | |
3993 | } | |
3994 | #endif | |
3995 | ||
3996 | ipw_send_system_config(priv); | |
43f66a6c JK |
3997 | } |
3998 | ||
3999 | struct ipw_status_code { | |
4000 | u16 status; | |
4001 | const char *reason; | |
4002 | }; | |
4003 | ||
4004 | static const struct ipw_status_code ipw_status_codes[] = { | |
4005 | {0x00, "Successful"}, | |
4006 | {0x01, "Unspecified failure"}, | |
4007 | {0x0A, "Cannot support all requested capabilities in the " | |
4008 | "Capability information field"}, | |
4009 | {0x0B, "Reassociation denied due to inability to confirm that " | |
4010 | "association exists"}, | |
4011 | {0x0C, "Association denied due to reason outside the scope of this " | |
4012 | "standard"}, | |
0edd5b44 JG |
4013 | {0x0D, |
4014 | "Responding station does not support the specified authentication " | |
43f66a6c | 4015 | "algorithm"}, |
0edd5b44 JG |
4016 | {0x0E, |
4017 | "Received an Authentication frame with authentication sequence " | |
43f66a6c JK |
4018 | "transaction sequence number out of expected sequence"}, |
4019 | {0x0F, "Authentication rejected because of challenge failure"}, | |
4020 | {0x10, "Authentication rejected due to timeout waiting for next " | |
4021 | "frame in sequence"}, | |
4022 | {0x11, "Association denied because AP is unable to handle additional " | |
4023 | "associated stations"}, | |
0edd5b44 JG |
4024 | {0x12, |
4025 | "Association denied due to requesting station not supporting all " | |
43f66a6c | 4026 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
0edd5b44 JG |
4027 | {0x13, |
4028 | "Association denied due to requesting station not supporting " | |
43f66a6c | 4029 | "short preamble operation"}, |
0edd5b44 JG |
4030 | {0x14, |
4031 | "Association denied due to requesting station not supporting " | |
43f66a6c | 4032 | "PBCC encoding"}, |
0edd5b44 JG |
4033 | {0x15, |
4034 | "Association denied due to requesting station not supporting " | |
43f66a6c | 4035 | "channel agility"}, |
0edd5b44 JG |
4036 | {0x19, |
4037 | "Association denied due to requesting station not supporting " | |
43f66a6c | 4038 | "short slot operation"}, |
0edd5b44 JG |
4039 | {0x1A, |
4040 | "Association denied due to requesting station not supporting " | |
43f66a6c JK |
4041 | "DSSS-OFDM operation"}, |
4042 | {0x28, "Invalid Information Element"}, | |
4043 | {0x29, "Group Cipher is not valid"}, | |
4044 | {0x2A, "Pairwise Cipher is not valid"}, | |
4045 | {0x2B, "AKMP is not valid"}, | |
4046 | {0x2C, "Unsupported RSN IE version"}, | |
4047 | {0x2D, "Invalid RSN IE Capabilities"}, | |
4048 | {0x2E, "Cipher suite is rejected per security policy"}, | |
4049 | }; | |
4050 | ||
bf79451e | 4051 | static const char *ipw_get_status_code(u16 status) |
43f66a6c JK |
4052 | { |
4053 | int i; | |
bf79451e | 4054 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
ea2b26e0 | 4055 | if (ipw_status_codes[i].status == (status & 0xff)) |
43f66a6c JK |
4056 | return ipw_status_codes[i].reason; |
4057 | return "Unknown status value."; | |
4058 | } | |
43f66a6c JK |
4059 | |
4060 | static void inline average_init(struct average *avg) | |
4061 | { | |
4062 | memset(avg, 0, sizeof(*avg)); | |
4063 | } | |
4064 | ||
00d21de5 ZY |
4065 | #define DEPTH_RSSI 8 |
4066 | #define DEPTH_NOISE 16 | |
4067 | static s16 exponential_average(s16 prev_avg, s16 val, u8 depth) | |
4068 | { | |
4069 | return ((depth-1)*prev_avg + val)/depth; | |
4070 | } | |
4071 | ||
858119e1 | 4072 | static void average_add(struct average *avg, s16 val) |
43f66a6c JK |
4073 | { |
4074 | avg->sum -= avg->entries[avg->pos]; | |
4075 | avg->sum += val; | |
4076 | avg->entries[avg->pos++] = val; | |
4077 | if (unlikely(avg->pos == AVG_ENTRIES)) { | |
4078 | avg->init = 1; | |
4079 | avg->pos = 0; | |
4080 | } | |
4081 | } | |
4082 | ||
858119e1 | 4083 | static s16 average_value(struct average *avg) |
43f66a6c JK |
4084 | { |
4085 | if (!unlikely(avg->init)) { | |
4086 | if (avg->pos) | |
4087 | return avg->sum / avg->pos; | |
4088 | return 0; | |
4089 | } | |
4090 | ||
4091 | return avg->sum / AVG_ENTRIES; | |
4092 | } | |
4093 | ||
4094 | static void ipw_reset_stats(struct ipw_priv *priv) | |
4095 | { | |
4096 | u32 len = sizeof(u32); | |
4097 | ||
4098 | priv->quality = 0; | |
4099 | ||
4100 | average_init(&priv->average_missed_beacons); | |
00d21de5 ZY |
4101 | priv->exp_avg_rssi = -60; |
4102 | priv->exp_avg_noise = -85 + 0x100; | |
43f66a6c JK |
4103 | |
4104 | priv->last_rate = 0; | |
4105 | priv->last_missed_beacons = 0; | |
4106 | priv->last_rx_packets = 0; | |
4107 | priv->last_tx_packets = 0; | |
4108 | priv->last_tx_failures = 0; | |
bf79451e | 4109 | |
43f66a6c JK |
4110 | /* Firmware managed, reset only when NIC is restarted, so we have to |
4111 | * normalize on the current value */ | |
bf79451e | 4112 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
43f66a6c | 4113 | &priv->last_rx_err, &len); |
bf79451e | 4114 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
43f66a6c JK |
4115 | &priv->last_tx_failures, &len); |
4116 | ||
4117 | /* Driver managed, reset with each association */ | |
4118 | priv->missed_adhoc_beacons = 0; | |
4119 | priv->missed_beacons = 0; | |
4120 | priv->tx_packets = 0; | |
4121 | priv->rx_packets = 0; | |
4122 | ||
4123 | } | |
4124 | ||
858119e1 | 4125 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
43f66a6c JK |
4126 | { |
4127 | u32 i = 0x80000000; | |
4128 | u32 mask = priv->rates_mask; | |
4129 | /* If currently associated in B mode, restrict the maximum | |
4130 | * rate match to B rates */ | |
4131 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) | |
b0a4e7d8 | 4132 | mask &= LIBIPW_CCK_RATES_MASK; |
43f66a6c JK |
4133 | |
4134 | /* TODO: Verify that the rate is supported by the current rates | |
4135 | * list. */ | |
4136 | ||
0edd5b44 JG |
4137 | while (i && !(mask & i)) |
4138 | i >>= 1; | |
43f66a6c | 4139 | switch (i) { |
b0a4e7d8 | 4140 | case LIBIPW_CCK_RATE_1MB_MASK: |
ea2b26e0 | 4141 | return 1000000; |
b0a4e7d8 | 4142 | case LIBIPW_CCK_RATE_2MB_MASK: |
ea2b26e0 | 4143 | return 2000000; |
b0a4e7d8 | 4144 | case LIBIPW_CCK_RATE_5MB_MASK: |
ea2b26e0 | 4145 | return 5500000; |
b0a4e7d8 | 4146 | case LIBIPW_OFDM_RATE_6MB_MASK: |
ea2b26e0 | 4147 | return 6000000; |
b0a4e7d8 | 4148 | case LIBIPW_OFDM_RATE_9MB_MASK: |
ea2b26e0 | 4149 | return 9000000; |
b0a4e7d8 | 4150 | case LIBIPW_CCK_RATE_11MB_MASK: |
ea2b26e0 | 4151 | return 11000000; |
b0a4e7d8 | 4152 | case LIBIPW_OFDM_RATE_12MB_MASK: |
ea2b26e0 | 4153 | return 12000000; |
b0a4e7d8 | 4154 | case LIBIPW_OFDM_RATE_18MB_MASK: |
ea2b26e0 | 4155 | return 18000000; |
b0a4e7d8 | 4156 | case LIBIPW_OFDM_RATE_24MB_MASK: |
ea2b26e0 | 4157 | return 24000000; |
b0a4e7d8 | 4158 | case LIBIPW_OFDM_RATE_36MB_MASK: |
ea2b26e0 | 4159 | return 36000000; |
b0a4e7d8 | 4160 | case LIBIPW_OFDM_RATE_48MB_MASK: |
ea2b26e0 | 4161 | return 48000000; |
b0a4e7d8 | 4162 | case LIBIPW_OFDM_RATE_54MB_MASK: |
ea2b26e0 | 4163 | return 54000000; |
43f66a6c JK |
4164 | } |
4165 | ||
bf79451e | 4166 | if (priv->ieee->mode == IEEE_B) |
43f66a6c JK |
4167 | return 11000000; |
4168 | else | |
4169 | return 54000000; | |
4170 | } | |
4171 | ||
4172 | static u32 ipw_get_current_rate(struct ipw_priv *priv) | |
4173 | { | |
4174 | u32 rate, len = sizeof(rate); | |
4175 | int err; | |
4176 | ||
bf79451e | 4177 | if (!(priv->status & STATUS_ASSOCIATED)) |
43f66a6c JK |
4178 | return 0; |
4179 | ||
4180 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { | |
bf79451e | 4181 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
43f66a6c JK |
4182 | &len); |
4183 | if (err) { | |
4184 | IPW_DEBUG_INFO("failed querying ordinals.\n"); | |
4185 | return 0; | |
4186 | } | |
bf79451e | 4187 | } else |
43f66a6c JK |
4188 | return ipw_get_max_rate(priv); |
4189 | ||
4190 | switch (rate) { | |
ea2b26e0 JK |
4191 | case IPW_TX_RATE_1MB: |
4192 | return 1000000; | |
4193 | case IPW_TX_RATE_2MB: | |
4194 | return 2000000; | |
4195 | case IPW_TX_RATE_5MB: | |
4196 | return 5500000; | |
4197 | case IPW_TX_RATE_6MB: | |
4198 | return 6000000; | |
4199 | case IPW_TX_RATE_9MB: | |
4200 | return 9000000; | |
4201 | case IPW_TX_RATE_11MB: | |
4202 | return 11000000; | |
4203 | case IPW_TX_RATE_12MB: | |
4204 | return 12000000; | |
4205 | case IPW_TX_RATE_18MB: | |
4206 | return 18000000; | |
4207 | case IPW_TX_RATE_24MB: | |
4208 | return 24000000; | |
4209 | case IPW_TX_RATE_36MB: | |
4210 | return 36000000; | |
4211 | case IPW_TX_RATE_48MB: | |
4212 | return 48000000; | |
4213 | case IPW_TX_RATE_54MB: | |
4214 | return 54000000; | |
43f66a6c JK |
4215 | } |
4216 | ||
4217 | return 0; | |
4218 | } | |
4219 | ||
43f66a6c JK |
4220 | #define IPW_STATS_INTERVAL (2 * HZ) |
4221 | static void ipw_gather_stats(struct ipw_priv *priv) | |
4222 | { | |
4223 | u32 rx_err, rx_err_delta, rx_packets_delta; | |
4224 | u32 tx_failures, tx_failures_delta, tx_packets_delta; | |
4225 | u32 missed_beacons_percent, missed_beacons_delta; | |
4226 | u32 quality = 0; | |
4227 | u32 len = sizeof(u32); | |
4228 | s16 rssi; | |
bf79451e | 4229 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
0edd5b44 | 4230 | rate_quality; |
ea2b26e0 | 4231 | u32 max_rate; |
43f66a6c JK |
4232 | |
4233 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
4234 | priv->quality = 0; | |
4235 | return; | |
4236 | } | |
4237 | ||
4238 | /* Update the statistics */ | |
bf79451e | 4239 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
43f66a6c | 4240 | &priv->missed_beacons, &len); |
0edd5b44 | 4241 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
43f66a6c JK |
4242 | priv->last_missed_beacons = priv->missed_beacons; |
4243 | if (priv->assoc_request.beacon_interval) { | |
4244 | missed_beacons_percent = missed_beacons_delta * | |
5b5e807f | 4245 | (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) / |
0edd5b44 | 4246 | (IPW_STATS_INTERVAL * 10); |
43f66a6c JK |
4247 | } else { |
4248 | missed_beacons_percent = 0; | |
4249 | } | |
4250 | average_add(&priv->average_missed_beacons, missed_beacons_percent); | |
4251 | ||
4252 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); | |
4253 | rx_err_delta = rx_err - priv->last_rx_err; | |
4254 | priv->last_rx_err = rx_err; | |
4255 | ||
4256 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); | |
4257 | tx_failures_delta = tx_failures - priv->last_tx_failures; | |
4258 | priv->last_tx_failures = tx_failures; | |
4259 | ||
4260 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; | |
4261 | priv->last_rx_packets = priv->rx_packets; | |
4262 | ||
4263 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; | |
4264 | priv->last_tx_packets = priv->tx_packets; | |
4265 | ||
4266 | /* Calculate quality based on the following: | |
bf79451e | 4267 | * |
43f66a6c JK |
4268 | * Missed beacon: 100% = 0, 0% = 70% missed |
4269 | * Rate: 60% = 1Mbs, 100% = Max | |
4270 | * Rx and Tx errors represent a straight % of total Rx/Tx | |
4271 | * RSSI: 100% = > -50, 0% = < -80 | |
4272 | * Rx errors: 100% = 0, 0% = 50% missed | |
bf79451e | 4273 | * |
43f66a6c JK |
4274 | * The lowest computed quality is used. |
4275 | * | |
4276 | */ | |
4277 | #define BEACON_THRESHOLD 5 | |
4278 | beacon_quality = 100 - missed_beacons_percent; | |
4279 | if (beacon_quality < BEACON_THRESHOLD) | |
4280 | beacon_quality = 0; | |
4281 | else | |
bf79451e | 4282 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
0edd5b44 | 4283 | (100 - BEACON_THRESHOLD); |
bf79451e | 4284 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
43f66a6c | 4285 | beacon_quality, missed_beacons_percent); |
bf79451e | 4286 | |
43f66a6c | 4287 | priv->last_rate = ipw_get_current_rate(priv); |
ea2b26e0 JK |
4288 | max_rate = ipw_get_max_rate(priv); |
4289 | rate_quality = priv->last_rate * 40 / max_rate + 60; | |
43f66a6c JK |
4290 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
4291 | rate_quality, priv->last_rate / 1000000); | |
bf79451e | 4292 | |
0edd5b44 | 4293 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
bf79451e | 4294 | rx_quality = 100 - (rx_err_delta * 100) / |
0edd5b44 | 4295 | (rx_packets_delta + rx_err_delta); |
43f66a6c JK |
4296 | else |
4297 | rx_quality = 100; | |
4298 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", | |
4299 | rx_quality, rx_err_delta, rx_packets_delta); | |
bf79451e | 4300 | |
0edd5b44 | 4301 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
bf79451e | 4302 | tx_quality = 100 - (tx_failures_delta * 100) / |
0edd5b44 | 4303 | (tx_packets_delta + tx_failures_delta); |
43f66a6c JK |
4304 | else |
4305 | tx_quality = 100; | |
4306 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", | |
4307 | tx_quality, tx_failures_delta, tx_packets_delta); | |
bf79451e | 4308 | |
00d21de5 | 4309 | rssi = priv->exp_avg_rssi; |
c848d0af JK |
4310 | signal_quality = |
4311 | (100 * | |
4312 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * | |
4313 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - | |
4314 | (priv->ieee->perfect_rssi - rssi) * | |
4315 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + | |
4316 | 62 * (priv->ieee->perfect_rssi - rssi))) / | |
4317 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * | |
4318 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); | |
4319 | if (signal_quality > 100) | |
43f66a6c | 4320 | signal_quality = 100; |
c848d0af | 4321 | else if (signal_quality < 1) |
43f66a6c | 4322 | signal_quality = 0; |
ea2b26e0 | 4323 | |
61fb9ed9 | 4324 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
43f66a6c | 4325 | signal_quality, rssi); |
bf79451e | 4326 | |
21f8a73f RC |
4327 | quality = min(rx_quality, signal_quality); |
4328 | quality = min(tx_quality, quality); | |
4329 | quality = min(rate_quality, quality); | |
4330 | quality = min(beacon_quality, quality); | |
43f66a6c | 4331 | if (quality == beacon_quality) |
0edd5b44 JG |
4332 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
4333 | quality); | |
43f66a6c | 4334 | if (quality == rate_quality) |
0edd5b44 JG |
4335 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
4336 | quality); | |
43f66a6c | 4337 | if (quality == tx_quality) |
0edd5b44 JG |
4338 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
4339 | quality); | |
43f66a6c | 4340 | if (quality == rx_quality) |
0edd5b44 JG |
4341 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
4342 | quality); | |
43f66a6c | 4343 | if (quality == signal_quality) |
0edd5b44 JG |
4344 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
4345 | quality); | |
43f66a6c JK |
4346 | |
4347 | priv->quality = quality; | |
bf79451e JG |
4348 | |
4349 | queue_delayed_work(priv->workqueue, &priv->gather_stats, | |
43f66a6c JK |
4350 | IPW_STATS_INTERVAL); |
4351 | } | |
4352 | ||
c4028958 | 4353 | static void ipw_bg_gather_stats(struct work_struct *work) |
c848d0af | 4354 | { |
c4028958 DH |
4355 | struct ipw_priv *priv = |
4356 | container_of(work, struct ipw_priv, gather_stats.work); | |
4644151b | 4357 | mutex_lock(&priv->mutex); |
c4028958 | 4358 | ipw_gather_stats(priv); |
4644151b | 4359 | mutex_unlock(&priv->mutex); |
c848d0af JK |
4360 | } |
4361 | ||
e7582561 BC |
4362 | /* Missed beacon behavior: |
4363 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. | |
4364 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. | |
4365 | * Above disassociate threshold, give up and stop scanning. | |
4366 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ | |
858119e1 | 4367 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
ea2b26e0 JK |
4368 | int missed_count) |
4369 | { | |
4370 | priv->notif_missed_beacons = missed_count; | |
4371 | ||
afbf30a2 | 4372 | if (missed_count > priv->disassociate_threshold && |
ea2b26e0 JK |
4373 | priv->status & STATUS_ASSOCIATED) { |
4374 | /* If associated and we've hit the missed | |
4375 | * beacon threshold, disassociate, turn | |
4376 | * off roaming, and abort any active scans */ | |
4377 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | | |
afbf30a2 | 4378 | IPW_DL_STATE | IPW_DL_ASSOC, |
ea2b26e0 JK |
4379 | "Missed beacon: %d - disassociate\n", missed_count); |
4380 | priv->status &= ~STATUS_ROAMING; | |
a613bffd JK |
4381 | if (priv->status & STATUS_SCANNING) { |
4382 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | | |
4383 | IPW_DL_STATE, | |
4384 | "Aborting scan with missed beacon.\n"); | |
ea2b26e0 | 4385 | queue_work(priv->workqueue, &priv->abort_scan); |
a613bffd JK |
4386 | } |
4387 | ||
ea2b26e0 JK |
4388 | queue_work(priv->workqueue, &priv->disassociate); |
4389 | return; | |
4390 | } | |
4391 | ||
4392 | if (priv->status & STATUS_ROAMING) { | |
4393 | /* If we are currently roaming, then just | |
4394 | * print a debug statement... */ | |
4395 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | |
4396 | "Missed beacon: %d - roam in progress\n", | |
4397 | missed_count); | |
4398 | return; | |
4399 | } | |
4400 | ||
4bfdb91d ZY |
4401 | if (roaming && |
4402 | (missed_count > priv->roaming_threshold && | |
4403 | missed_count <= priv->disassociate_threshold)) { | |
ea2b26e0 | 4404 | /* If we are not already roaming, set the ROAM |
e7582561 BC |
4405 | * bit in the status and kick off a scan. |
4406 | * This can happen several times before we reach | |
4407 | * disassociate_threshold. */ | |
ea2b26e0 JK |
4408 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
4409 | "Missed beacon: %d - initiate " | |
4410 | "roaming\n", missed_count); | |
4411 | if (!(priv->status & STATUS_ROAMING)) { | |
4412 | priv->status |= STATUS_ROAMING; | |
4413 | if (!(priv->status & STATUS_SCANNING)) | |
c4028958 DH |
4414 | queue_delayed_work(priv->workqueue, |
4415 | &priv->request_scan, 0); | |
ea2b26e0 JK |
4416 | } |
4417 | return; | |
4418 | } | |
4419 | ||
14a4dfe2 HS |
4420 | if (priv->status & STATUS_SCANNING && |
4421 | missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) { | |
ea2b26e0 JK |
4422 | /* Stop scan to keep fw from getting |
4423 | * stuck (only if we aren't roaming -- | |
4424 | * otherwise we'll never scan more than 2 or 3 | |
4425 | * channels..) */ | |
b095c381 JK |
4426 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
4427 | "Aborting scan with missed beacon.\n"); | |
ea2b26e0 JK |
4428 | queue_work(priv->workqueue, &priv->abort_scan); |
4429 | } | |
4430 | ||
4431 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); | |
ea2b26e0 JK |
4432 | } |
4433 | ||
0b531676 DW |
4434 | static void ipw_scan_event(struct work_struct *work) |
4435 | { | |
4436 | union iwreq_data wrqu; | |
4437 | ||
4438 | struct ipw_priv *priv = | |
4439 | container_of(work, struct ipw_priv, scan_event.work); | |
4440 | ||
4441 | wrqu.data.length = 0; | |
4442 | wrqu.data.flags = 0; | |
4443 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); | |
4444 | } | |
4445 | ||
4446 | static void handle_scan_event(struct ipw_priv *priv) | |
4447 | { | |
4448 | /* Only userspace-requested scan completion events go out immediately */ | |
4449 | if (!priv->user_requested_scan) { | |
4450 | if (!delayed_work_pending(&priv->scan_event)) | |
4451 | queue_delayed_work(priv->workqueue, &priv->scan_event, | |
be84e3d6 | 4452 | round_jiffies_relative(msecs_to_jiffies(4000))); |
0b531676 DW |
4453 | } else { |
4454 | union iwreq_data wrqu; | |
4455 | ||
4456 | priv->user_requested_scan = 0; | |
4457 | cancel_delayed_work(&priv->scan_event); | |
4458 | ||
4459 | wrqu.data.length = 0; | |
4460 | wrqu.data.flags = 0; | |
4461 | wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL); | |
4462 | } | |
4463 | } | |
4464 | ||
43f66a6c JK |
4465 | /** |
4466 | * Handle host notification packet. | |
4467 | * Called from interrupt routine | |
4468 | */ | |
858119e1 | 4469 | static void ipw_rx_notification(struct ipw_priv *priv, |
43f66a6c JK |
4470 | struct ipw_rx_notification *notif) |
4471 | { | |
9387b7ca | 4472 | DECLARE_SSID_BUF(ssid); |
e62e1ee0 | 4473 | u16 size = le16_to_cpu(notif->size); |
a613bffd | 4474 | |
e62e1ee0 | 4475 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size); |
bf79451e | 4476 | |
43f66a6c | 4477 | switch (notif->subtype) { |
0edd5b44 JG |
4478 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
4479 | struct notif_association *assoc = ¬if->u.assoc; | |
4480 | ||
4481 | switch (assoc->state) { | |
4482 | case CMAS_ASSOCIATED:{ | |
4483 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4484 | IPW_DL_ASSOC, | |
e174961c | 4485 | "associated: '%s' %pM \n", |
9387b7ca JL |
4486 | print_ssid(ssid, priv->essid, |
4487 | priv->essid_len), | |
e174961c | 4488 | priv->bssid); |
0edd5b44 JG |
4489 | |
4490 | switch (priv->ieee->iw_mode) { | |
4491 | case IW_MODE_INFRA: | |
4492 | memcpy(priv->ieee->bssid, | |
4493 | priv->bssid, ETH_ALEN); | |
4494 | break; | |
4495 | ||
4496 | case IW_MODE_ADHOC: | |
4497 | memcpy(priv->ieee->bssid, | |
4498 | priv->bssid, ETH_ALEN); | |
4499 | ||
4500 | /* clear out the station table */ | |
4501 | priv->num_stations = 0; | |
4502 | ||
4503 | IPW_DEBUG_ASSOC | |
4504 | ("queueing adhoc check\n"); | |
4505 | queue_delayed_work(priv-> | |
4506 | workqueue, | |
4507 | &priv-> | |
4508 | adhoc_check, | |
5b5e807f | 4509 | le16_to_cpu(priv-> |
0edd5b44 | 4510 | assoc_request. |
5b5e807f | 4511 | beacon_interval)); |
0edd5b44 JG |
4512 | break; |
4513 | } | |
4514 | ||
4515 | priv->status &= ~STATUS_ASSOCIATING; | |
4516 | priv->status |= STATUS_ASSOCIATED; | |
d8bad6df ZY |
4517 | queue_work(priv->workqueue, |
4518 | &priv->system_config); | |
0edd5b44 | 4519 | |
e43e3c1e | 4520 | #ifdef CONFIG_IPW2200_QOS |
afbf30a2 | 4521 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
72118015 | 4522 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control)) |
afbf30a2 JK |
4523 | if ((priv->status & STATUS_AUTH) && |
4524 | (IPW_GET_PACKET_STYPE(¬if->u.raw) | |
4525 | == IEEE80211_STYPE_ASSOC_RESP)) { | |
b095c381 JK |
4526 | if ((sizeof |
4527 | (struct | |
b0a4e7d8 | 4528 | libipw_assoc_response) |
e62e1ee0 AV |
4529 | <= size) |
4530 | && (size <= 2314)) { | |
b095c381 | 4531 | struct |
b0a4e7d8 | 4532 | libipw_rx_stats |
b095c381 | 4533 | stats = { |
e62e1ee0 | 4534 | .len = size - 1, |
b095c381 JK |
4535 | }; |
4536 | ||
4537 | IPW_DEBUG_QOS | |
4538 | ("QoS Associate " | |
e62e1ee0 | 4539 | "size %d\n", size); |
b0a4e7d8 | 4540 | libipw_rx_mgt(priv-> |
b095c381 JK |
4541 | ieee, |
4542 | (struct | |
b0a4e7d8 | 4543 | libipw_hdr_4addr |
b095c381 JK |
4544 | *) |
4545 | ¬if->u.raw, &stats); | |
4546 | } | |
0edd5b44 | 4547 | } |
b095c381 | 4548 | #endif |
0edd5b44 | 4549 | |
a613bffd | 4550 | schedule_work(&priv->link_up); |
43f66a6c | 4551 | |
0edd5b44 JG |
4552 | break; |
4553 | } | |
bf79451e | 4554 | |
0edd5b44 JG |
4555 | case CMAS_AUTHENTICATED:{ |
4556 | if (priv-> | |
4557 | status & (STATUS_ASSOCIATED | | |
4558 | STATUS_AUTH)) { | |
0edd5b44 JG |
4559 | struct notif_authenticate *auth |
4560 | = ¬if->u.auth; | |
4561 | IPW_DEBUG(IPW_DL_NOTIF | | |
4562 | IPW_DL_STATE | | |
4563 | IPW_DL_ASSOC, | |
4564 | "deauthenticated: '%s' " | |
e174961c | 4565 | "%pM" |
0edd5b44 | 4566 | ": (0x%04X) - %s \n", |
9387b7ca JL |
4567 | print_ssid(ssid, |
4568 | priv-> | |
4569 | essid, | |
4570 | priv-> | |
4571 | essid_len), | |
e174961c | 4572 | priv->bssid, |
83f7d57c | 4573 | le16_to_cpu(auth->status), |
0edd5b44 | 4574 | ipw_get_status_code |
83f7d57c | 4575 | (le16_to_cpu |
0edd5b44 | 4576 | (auth->status))); |
43f66a6c | 4577 | |
0edd5b44 JG |
4578 | priv->status &= |
4579 | ~(STATUS_ASSOCIATING | | |
4580 | STATUS_AUTH | | |
4581 | STATUS_ASSOCIATED); | |
4582 | ||
a613bffd | 4583 | schedule_work(&priv->link_down); |
0edd5b44 JG |
4584 | break; |
4585 | } | |
4586 | ||
4587 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4588 | IPW_DL_ASSOC, | |
e174961c | 4589 | "authenticated: '%s' %pM\n", |
9387b7ca JL |
4590 | print_ssid(ssid, priv->essid, |
4591 | priv->essid_len), | |
e174961c | 4592 | priv->bssid); |
0edd5b44 JG |
4593 | break; |
4594 | } | |
4595 | ||
4596 | case CMAS_INIT:{ | |
ea2b26e0 JK |
4597 | if (priv->status & STATUS_AUTH) { |
4598 | struct | |
b0a4e7d8 | 4599 | libipw_assoc_response |
ea2b26e0 JK |
4600 | *resp; |
4601 | resp = | |
4602 | (struct | |
b0a4e7d8 | 4603 | libipw_assoc_response |
ea2b26e0 JK |
4604 | *)¬if->u.raw; |
4605 | IPW_DEBUG(IPW_DL_NOTIF | | |
4606 | IPW_DL_STATE | | |
4607 | IPW_DL_ASSOC, | |
4608 | "association failed (0x%04X): %s\n", | |
83f7d57c | 4609 | le16_to_cpu(resp->status), |
ea2b26e0 | 4610 | ipw_get_status_code |
83f7d57c | 4611 | (le16_to_cpu |
ea2b26e0 JK |
4612 | (resp->status))); |
4613 | } | |
4614 | ||
0edd5b44 JG |
4615 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
4616 | IPW_DL_ASSOC, | |
e174961c | 4617 | "disassociated: '%s' %pM \n", |
9387b7ca JL |
4618 | print_ssid(ssid, priv->essid, |
4619 | priv->essid_len), | |
e174961c | 4620 | priv->bssid); |
0edd5b44 JG |
4621 | |
4622 | priv->status &= | |
4623 | ~(STATUS_DISASSOCIATING | | |
4624 | STATUS_ASSOCIATING | | |
4625 | STATUS_ASSOCIATED | STATUS_AUTH); | |
b095c381 JK |
4626 | if (priv->assoc_network |
4627 | && (priv->assoc_network-> | |
4628 | capability & | |
4629 | WLAN_CAPABILITY_IBSS)) | |
4630 | ipw_remove_current_network | |
4631 | (priv); | |
0edd5b44 | 4632 | |
a613bffd | 4633 | schedule_work(&priv->link_down); |
0edd5b44 | 4634 | |
0edd5b44 JG |
4635 | break; |
4636 | } | |
43f66a6c | 4637 | |
b095c381 JK |
4638 | case CMAS_RX_ASSOC_RESP: |
4639 | break; | |
4640 | ||
0edd5b44 JG |
4641 | default: |
4642 | IPW_ERROR("assoc: unknown (%d)\n", | |
4643 | assoc->state); | |
43f66a6c | 4644 | break; |
bf79451e | 4645 | } |
43f66a6c | 4646 | |
43f66a6c JK |
4647 | break; |
4648 | } | |
bf79451e | 4649 | |
0edd5b44 JG |
4650 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
4651 | struct notif_authenticate *auth = ¬if->u.auth; | |
4652 | switch (auth->state) { | |
4653 | case CMAS_AUTHENTICATED: | |
4654 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | |
e174961c | 4655 | "authenticated: '%s' %pM \n", |
9387b7ca JL |
4656 | print_ssid(ssid, priv->essid, |
4657 | priv->essid_len), | |
e174961c | 4658 | priv->bssid); |
0edd5b44 JG |
4659 | priv->status |= STATUS_AUTH; |
4660 | break; | |
43f66a6c | 4661 | |
0edd5b44 JG |
4662 | case CMAS_INIT: |
4663 | if (priv->status & STATUS_AUTH) { | |
4664 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4665 | IPW_DL_ASSOC, | |
4666 | "authentication failed (0x%04X): %s\n", | |
83f7d57c AV |
4667 | le16_to_cpu(auth->status), |
4668 | ipw_get_status_code(le16_to_cpu | |
0edd5b44 JG |
4669 | (auth-> |
4670 | status))); | |
4671 | } | |
4672 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4673 | IPW_DL_ASSOC, | |
e174961c | 4674 | "deauthenticated: '%s' %pM\n", |
9387b7ca JL |
4675 | print_ssid(ssid, priv->essid, |
4676 | priv->essid_len), | |
e174961c | 4677 | priv->bssid); |
bf79451e | 4678 | |
0edd5b44 JG |
4679 | priv->status &= ~(STATUS_ASSOCIATING | |
4680 | STATUS_AUTH | | |
4681 | STATUS_ASSOCIATED); | |
43f66a6c | 4682 | |
a613bffd | 4683 | schedule_work(&priv->link_down); |
0edd5b44 | 4684 | break; |
43f66a6c | 4685 | |
0edd5b44 JG |
4686 | case CMAS_TX_AUTH_SEQ_1: |
4687 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4688 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); | |
4689 | break; | |
4690 | case CMAS_RX_AUTH_SEQ_2: | |
4691 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4692 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); | |
4693 | break; | |
4694 | case CMAS_AUTH_SEQ_1_PASS: | |
4695 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4696 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); | |
4697 | break; | |
4698 | case CMAS_AUTH_SEQ_1_FAIL: | |
4699 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4700 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); | |
4701 | break; | |
4702 | case CMAS_TX_AUTH_SEQ_3: | |
4703 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4704 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); | |
4705 | break; | |
4706 | case CMAS_RX_AUTH_SEQ_4: | |
4707 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4708 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); | |
4709 | break; | |
4710 | case CMAS_AUTH_SEQ_2_PASS: | |
4711 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4712 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); | |
4713 | break; | |
4714 | case CMAS_AUTH_SEQ_2_FAIL: | |
4715 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4716 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); | |
4717 | break; | |
4718 | case CMAS_TX_ASSOC: | |
4719 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4720 | IPW_DL_ASSOC, "TX_ASSOC\n"); | |
4721 | break; | |
4722 | case CMAS_RX_ASSOC_RESP: | |
4723 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4724 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); | |
b095c381 | 4725 | |
0edd5b44 JG |
4726 | break; |
4727 | case CMAS_ASSOCIATED: | |
4728 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4729 | IPW_DL_ASSOC, "ASSOCIATED\n"); | |
4730 | break; | |
4731 | default: | |
4732 | IPW_DEBUG_NOTIF("auth: failure - %d\n", | |
4733 | auth->state); | |
4734 | break; | |
43f66a6c | 4735 | } |
43f66a6c JK |
4736 | break; |
4737 | } | |
4738 | ||
0edd5b44 JG |
4739 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
4740 | struct notif_channel_result *x = | |
4741 | ¬if->u.channel_result; | |
43f66a6c | 4742 | |
e62e1ee0 | 4743 | if (size == sizeof(*x)) { |
0edd5b44 JG |
4744 | IPW_DEBUG_SCAN("Scan result for channel %d\n", |
4745 | x->channel_num); | |
4746 | } else { | |
4747 | IPW_DEBUG_SCAN("Scan result of wrong size %d " | |
4748 | "(should be %zd)\n", | |
e62e1ee0 | 4749 | size, sizeof(*x)); |
bf79451e | 4750 | } |
43f66a6c JK |
4751 | break; |
4752 | } | |
43f66a6c | 4753 | |
0edd5b44 JG |
4754 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
4755 | struct notif_scan_complete *x = ¬if->u.scan_complete; | |
e62e1ee0 | 4756 | if (size == sizeof(*x)) { |
0edd5b44 JG |
4757 | IPW_DEBUG_SCAN |
4758 | ("Scan completed: type %d, %d channels, " | |
4759 | "%d status\n", x->scan_type, | |
4760 | x->num_channels, x->status); | |
4761 | } else { | |
4762 | IPW_ERROR("Scan completed of wrong size %d " | |
4763 | "(should be %zd)\n", | |
e62e1ee0 | 4764 | size, sizeof(*x)); |
0edd5b44 | 4765 | } |
43f66a6c | 4766 | |
0edd5b44 JG |
4767 | priv->status &= |
4768 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); | |
4769 | ||
a0e04ab3 | 4770 | wake_up_interruptible(&priv->wait_state); |
0edd5b44 JG |
4771 | cancel_delayed_work(&priv->scan_check); |
4772 | ||
b095c381 JK |
4773 | if (priv->status & STATUS_EXIT_PENDING) |
4774 | break; | |
4775 | ||
4776 | priv->ieee->scans++; | |
4777 | ||
4778 | #ifdef CONFIG_IPW2200_MONITOR | |
4779 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | |
afbf30a2 | 4780 | priv->status |= STATUS_SCAN_FORCED; |
c4028958 DH |
4781 | queue_delayed_work(priv->workqueue, |
4782 | &priv->request_scan, 0); | |
b095c381 JK |
4783 | break; |
4784 | } | |
afbf30a2 | 4785 | priv->status &= ~STATUS_SCAN_FORCED; |
b095c381 JK |
4786 | #endif /* CONFIG_IPW2200_MONITOR */ |
4787 | ||
ea177305 DW |
4788 | /* Do queued direct scans first */ |
4789 | if (priv->status & STATUS_DIRECT_SCAN_PENDING) { | |
4790 | queue_delayed_work(priv->workqueue, | |
4791 | &priv->request_direct_scan, 0); | |
4792 | } | |
4793 | ||
0edd5b44 JG |
4794 | if (!(priv->status & (STATUS_ASSOCIATED | |
4795 | STATUS_ASSOCIATING | | |
4796 | STATUS_ROAMING | | |
4797 | STATUS_DISASSOCIATING))) | |
4798 | queue_work(priv->workqueue, &priv->associate); | |
4799 | else if (priv->status & STATUS_ROAMING) { | |
e7582561 BC |
4800 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
4801 | /* If a scan completed and we are in roam mode, then | |
4802 | * the scan that completed was the one requested as a | |
4803 | * result of entering roam... so, schedule the | |
4804 | * roam work */ | |
4805 | queue_work(priv->workqueue, | |
4806 | &priv->roam); | |
4807 | else | |
4808 | /* Don't schedule if we aborted the scan */ | |
4809 | priv->status &= ~STATUS_ROAMING; | |
0edd5b44 | 4810 | } else if (priv->status & STATUS_SCAN_PENDING) |
c4028958 DH |
4811 | queue_delayed_work(priv->workqueue, |
4812 | &priv->request_scan, 0); | |
a613bffd JK |
4813 | else if (priv->config & CFG_BACKGROUND_SCAN |
4814 | && priv->status & STATUS_ASSOCIATED) | |
4815 | queue_delayed_work(priv->workqueue, | |
1c9d5e41 | 4816 | &priv->request_scan, |
be84e3d6 | 4817 | round_jiffies_relative(HZ)); |
07f02e46 ZY |
4818 | |
4819 | /* Send an empty event to user space. | |
4820 | * We don't send the received data on the event because | |
4821 | * it would require us to do complex transcoding, and | |
4822 | * we want to minimise the work done in the irq handler | |
4823 | * Use a request to extract the data. | |
4824 | * Also, we generate this even for any scan, regardless | |
4825 | * on how the scan was initiated. User space can just | |
4826 | * sync on periodic scan to get fresh data... | |
4827 | * Jean II */ | |
0b531676 DW |
4828 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
4829 | handle_scan_event(priv); | |
0edd5b44 | 4830 | break; |
43f66a6c | 4831 | } |
43f66a6c | 4832 | |
0edd5b44 JG |
4833 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
4834 | struct notif_frag_length *x = ¬if->u.frag_len; | |
43f66a6c | 4835 | |
e62e1ee0 | 4836 | if (size == sizeof(*x)) |
a613bffd JK |
4837 | IPW_ERROR("Frag length: %d\n", |
4838 | le16_to_cpu(x->frag_length)); | |
4839 | else | |
0edd5b44 JG |
4840 | IPW_ERROR("Frag length of wrong size %d " |
4841 | "(should be %zd)\n", | |
e62e1ee0 | 4842 | size, sizeof(*x)); |
0edd5b44 | 4843 | break; |
43f66a6c | 4844 | } |
43f66a6c | 4845 | |
0edd5b44 JG |
4846 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
4847 | struct notif_link_deterioration *x = | |
4848 | ¬if->u.link_deterioration; | |
afbf30a2 | 4849 | |
e62e1ee0 | 4850 | if (size == sizeof(*x)) { |
0edd5b44 | 4851 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
12977154 BC |
4852 | "link deterioration: type %d, cnt %d\n", |
4853 | x->silence_notification_type, | |
4854 | x->silence_count); | |
0edd5b44 JG |
4855 | memcpy(&priv->last_link_deterioration, x, |
4856 | sizeof(*x)); | |
4857 | } else { | |
4858 | IPW_ERROR("Link Deterioration of wrong size %d " | |
4859 | "(should be %zd)\n", | |
e62e1ee0 | 4860 | size, sizeof(*x)); |
0edd5b44 | 4861 | } |
43f66a6c JK |
4862 | break; |
4863 | } | |
4864 | ||
0edd5b44 JG |
4865 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
4866 | IPW_ERROR("Dino config\n"); | |
4867 | if (priv->hcmd | |
a613bffd | 4868 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
0edd5b44 | 4869 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
a613bffd | 4870 | |
0edd5b44 JG |
4871 | break; |
4872 | } | |
43f66a6c | 4873 | |
0edd5b44 JG |
4874 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
4875 | struct notif_beacon_state *x = ¬if->u.beacon_state; | |
e62e1ee0 | 4876 | if (size != sizeof(*x)) { |
0edd5b44 JG |
4877 | IPW_ERROR |
4878 | ("Beacon state of wrong size %d (should " | |
e62e1ee0 | 4879 | "be %zd)\n", size, sizeof(*x)); |
0edd5b44 | 4880 | break; |
43f66a6c JK |
4881 | } |
4882 | ||
a613bffd JK |
4883 | if (le32_to_cpu(x->state) == |
4884 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) | |
4885 | ipw_handle_missed_beacon(priv, | |
4886 | le32_to_cpu(x-> | |
4887 | number)); | |
43f66a6c | 4888 | |
0edd5b44 JG |
4889 | break; |
4890 | } | |
43f66a6c | 4891 | |
0edd5b44 JG |
4892 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
4893 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; | |
e62e1ee0 | 4894 | if (size == sizeof(*x)) { |
0edd5b44 JG |
4895 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " |
4896 | "0x%02x station %d\n", | |
4897 | x->key_state, x->security_type, | |
4898 | x->station_index); | |
4899 | break; | |
4900 | } | |
43f66a6c | 4901 | |
0edd5b44 JG |
4902 | IPW_ERROR |
4903 | ("TGi Tx Key of wrong size %d (should be %zd)\n", | |
e62e1ee0 | 4904 | size, sizeof(*x)); |
43f66a6c | 4905 | break; |
bf79451e | 4906 | } |
43f66a6c | 4907 | |
0edd5b44 JG |
4908 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
4909 | struct notif_calibration *x = ¬if->u.calibration; | |
43f66a6c | 4910 | |
e62e1ee0 | 4911 | if (size == sizeof(*x)) { |
0edd5b44 JG |
4912 | memcpy(&priv->calib, x, sizeof(*x)); |
4913 | IPW_DEBUG_INFO("TODO: Calibration\n"); | |
4914 | break; | |
4915 | } | |
43f66a6c | 4916 | |
0edd5b44 JG |
4917 | IPW_ERROR |
4918 | ("Calibration of wrong size %d (should be %zd)\n", | |
e62e1ee0 | 4919 | size, sizeof(*x)); |
43f66a6c | 4920 | break; |
bf79451e JG |
4921 | } |
4922 | ||
0edd5b44 | 4923 | case HOST_NOTIFICATION_NOISE_STATS:{ |
e62e1ee0 | 4924 | if (size == sizeof(u32)) { |
00d21de5 ZY |
4925 | priv->exp_avg_noise = |
4926 | exponential_average(priv->exp_avg_noise, | |
4927 | (u8) (le32_to_cpu(notif->u.noise.value) & 0xff), | |
4928 | DEPTH_NOISE); | |
0edd5b44 JG |
4929 | break; |
4930 | } | |
43f66a6c | 4931 | |
0edd5b44 JG |
4932 | IPW_ERROR |
4933 | ("Noise stat is wrong size %d (should be %zd)\n", | |
e62e1ee0 | 4934 | size, sizeof(u32)); |
43f66a6c JK |
4935 | break; |
4936 | } | |
4937 | ||
43f66a6c | 4938 | default: |
1dd31b6c ZY |
4939 | IPW_DEBUG_NOTIF("Unknown notification: " |
4940 | "subtype=%d,flags=0x%2x,size=%d\n", | |
e62e1ee0 | 4941 | notif->subtype, notif->flags, size); |
43f66a6c JK |
4942 | } |
4943 | } | |
4944 | ||
4945 | /** | |
4946 | * Destroys all DMA structures and initialise them again | |
bf79451e | 4947 | * |
43f66a6c JK |
4948 | * @param priv |
4949 | * @return error code | |
4950 | */ | |
4951 | static int ipw_queue_reset(struct ipw_priv *priv) | |
4952 | { | |
4953 | int rc = 0; | |
4954 | /** @todo customize queue sizes */ | |
4955 | int nTx = 64, nTxCmd = 8; | |
4956 | ipw_tx_queue_free(priv); | |
4957 | /* Tx CMD queue */ | |
4958 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, | |
b095c381 JK |
4959 | IPW_TX_CMD_QUEUE_READ_INDEX, |
4960 | IPW_TX_CMD_QUEUE_WRITE_INDEX, | |
4961 | IPW_TX_CMD_QUEUE_BD_BASE, | |
4962 | IPW_TX_CMD_QUEUE_BD_SIZE); | |
43f66a6c JK |
4963 | if (rc) { |
4964 | IPW_ERROR("Tx Cmd queue init failed\n"); | |
4965 | goto error; | |
4966 | } | |
4967 | /* Tx queue(s) */ | |
4968 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, | |
b095c381 JK |
4969 | IPW_TX_QUEUE_0_READ_INDEX, |
4970 | IPW_TX_QUEUE_0_WRITE_INDEX, | |
4971 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); | |
43f66a6c JK |
4972 | if (rc) { |
4973 | IPW_ERROR("Tx 0 queue init failed\n"); | |
4974 | goto error; | |
4975 | } | |
4976 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, | |
b095c381 JK |
4977 | IPW_TX_QUEUE_1_READ_INDEX, |
4978 | IPW_TX_QUEUE_1_WRITE_INDEX, | |
4979 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); | |
43f66a6c JK |
4980 | if (rc) { |
4981 | IPW_ERROR("Tx 1 queue init failed\n"); | |
4982 | goto error; | |
4983 | } | |
4984 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, | |
b095c381 JK |
4985 | IPW_TX_QUEUE_2_READ_INDEX, |
4986 | IPW_TX_QUEUE_2_WRITE_INDEX, | |
4987 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); | |
43f66a6c JK |
4988 | if (rc) { |
4989 | IPW_ERROR("Tx 2 queue init failed\n"); | |
4990 | goto error; | |
4991 | } | |
4992 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, | |
b095c381 JK |
4993 | IPW_TX_QUEUE_3_READ_INDEX, |
4994 | IPW_TX_QUEUE_3_WRITE_INDEX, | |
4995 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); | |
43f66a6c JK |
4996 | if (rc) { |
4997 | IPW_ERROR("Tx 3 queue init failed\n"); | |
4998 | goto error; | |
4999 | } | |
5000 | /* statistics */ | |
5001 | priv->rx_bufs_min = 0; | |
5002 | priv->rx_pend_max = 0; | |
5003 | return rc; | |
5004 | ||
0edd5b44 | 5005 | error: |
43f66a6c JK |
5006 | ipw_tx_queue_free(priv); |
5007 | return rc; | |
5008 | } | |
5009 | ||
5010 | /** | |
5011 | * Reclaim Tx queue entries no more used by NIC. | |
bf79451e | 5012 | * |
8ff9d21e | 5013 | * When FW advances 'R' index, all entries between old and |
43f66a6c JK |
5014 | * new 'R' index need to be reclaimed. As result, some free space |
5015 | * forms. If there is enough free space (> low mark), wake Tx queue. | |
bf79451e | 5016 | * |
43f66a6c JK |
5017 | * @note Need to protect against garbage in 'R' index |
5018 | * @param priv | |
5019 | * @param txq | |
5020 | * @param qindex | |
5021 | * @return Number of used entries remains in the queue | |
5022 | */ | |
bf79451e | 5023 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
43f66a6c JK |
5024 | struct clx2_tx_queue *txq, int qindex) |
5025 | { | |
5026 | u32 hw_tail; | |
5027 | int used; | |
5028 | struct clx2_queue *q = &txq->q; | |
5029 | ||
5030 | hw_tail = ipw_read32(priv, q->reg_r); | |
5031 | if (hw_tail >= q->n_bd) { | |
5032 | IPW_ERROR | |
0edd5b44 JG |
5033 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
5034 | hw_tail, q->n_bd); | |
43f66a6c JK |
5035 | goto done; |
5036 | } | |
5037 | for (; q->last_used != hw_tail; | |
5038 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { | |
5039 | ipw_queue_tx_free_tfd(priv, txq); | |
5040 | priv->tx_packets++; | |
5041 | } | |
0edd5b44 | 5042 | done: |
943dbef4 | 5043 | if ((ipw_tx_queue_space(q) > q->low_mark) && |
521c4d96 | 5044 | (qindex >= 0)) |
9ddf84f6 | 5045 | netif_wake_queue(priv->net_dev); |
43f66a6c JK |
5046 | used = q->first_empty - q->last_used; |
5047 | if (used < 0) | |
5048 | used += q->n_bd; | |
5049 | ||
5050 | return used; | |
5051 | } | |
5052 | ||
5053 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, | |
5054 | int len, int sync) | |
5055 | { | |
5056 | struct clx2_tx_queue *txq = &priv->txq_cmd; | |
5057 | struct clx2_queue *q = &txq->q; | |
5058 | struct tfd_frame *tfd; | |
5059 | ||
943dbef4 | 5060 | if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) { |
43f66a6c JK |
5061 | IPW_ERROR("No space for Tx\n"); |
5062 | return -EBUSY; | |
5063 | } | |
5064 | ||
5065 | tfd = &txq->bd[q->first_empty]; | |
5066 | txq->txb[q->first_empty] = NULL; | |
5067 | ||
5068 | memset(tfd, 0, sizeof(*tfd)); | |
5069 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; | |
5070 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; | |
5071 | priv->hcmd_seq++; | |
5072 | tfd->u.cmd.index = hcmd; | |
5073 | tfd->u.cmd.length = len; | |
5074 | memcpy(tfd->u.cmd.payload, buf, len); | |
5075 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); | |
5076 | ipw_write32(priv, q->reg_w, q->first_empty); | |
5077 | _ipw_read32(priv, 0x90); | |
5078 | ||
5079 | return 0; | |
5080 | } | |
5081 | ||
bf79451e | 5082 | /* |
43f66a6c JK |
5083 | * Rx theory of operation |
5084 | * | |
5085 | * The host allocates 32 DMA target addresses and passes the host address | |
b095c381 | 5086 | * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
43f66a6c JK |
5087 | * 0 to 31 |
5088 | * | |
5089 | * Rx Queue Indexes | |
5090 | * The host/firmware share two index registers for managing the Rx buffers. | |
5091 | * | |
bf79451e JG |
5092 | * The READ index maps to the first position that the firmware may be writing |
5093 | * to -- the driver can read up to (but not including) this position and get | |
5094 | * good data. | |
43f66a6c JK |
5095 | * The READ index is managed by the firmware once the card is enabled. |
5096 | * | |
5097 | * The WRITE index maps to the last position the driver has read from -- the | |
5098 | * position preceding WRITE is the last slot the firmware can place a packet. | |
5099 | * | |
5100 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if | |
bf79451e | 5101 | * WRITE = READ. |
43f66a6c | 5102 | * |
bf79451e | 5103 | * During initialization the host sets up the READ queue position to the first |
43f66a6c JK |
5104 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
5105 | * | |
5106 | * When the firmware places a packet in a buffer it will advance the READ index | |
5107 | * and fire the RX interrupt. The driver can then query the READ index and | |
5108 | * process as many packets as possible, moving the WRITE index forward as it | |
5109 | * resets the Rx queue buffers with new memory. | |
bf79451e | 5110 | * |
43f66a6c | 5111 | * The management in the driver is as follows: |
bf79451e | 5112 | * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When |
43f66a6c | 5113 | * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled |
bf79451e | 5114 | * to replensish the ipw->rxq->rx_free. |
43f66a6c JK |
5115 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
5116 | * ipw->rxq is replenished and the READ INDEX is updated (updating the | |
5117 | * 'processed' and 'read' driver indexes as well) | |
5118 | * + A received packet is processed and handed to the kernel network stack, | |
5119 | * detached from the ipw->rxq. The driver 'processed' index is updated. | |
5120 | * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free | |
bf79451e JG |
5121 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
5122 | * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there | |
43f66a6c JK |
5123 | * were enough free buffers and RX_STALLED is set it is cleared. |
5124 | * | |
5125 | * | |
5126 | * Driver sequence: | |
5127 | * | |
bf79451e | 5128 | * ipw_rx_queue_alloc() Allocates rx_free |
43f66a6c JK |
5129 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
5130 | * ipw_rx_queue_restock | |
5131 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx | |
5132 | * queue, updates firmware pointers, and updates | |
5133 | * the WRITE index. If insufficient rx_free buffers | |
5134 | * are available, schedules ipw_rx_queue_replenish | |
5135 | * | |
5136 | * -- enable interrupts -- | |
5137 | * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the | |
bf79451e | 5138 | * READ INDEX, detaching the SKB from the pool. |
43f66a6c JK |
5139 | * Moves the packet buffer from queue to rx_used. |
5140 | * Calls ipw_rx_queue_restock to refill any empty | |
5141 | * slots. | |
5142 | * ... | |
5143 | * | |
5144 | */ | |
5145 | ||
bf79451e | 5146 | /* |
43f66a6c JK |
5147 | * If there are slots in the RX queue that need to be restocked, |
5148 | * and we have free pre-allocated buffers, fill the ranks as much | |
5149 | * as we can pulling from rx_free. | |
5150 | * | |
5151 | * This moves the 'write' index forward to catch up with 'processed', and | |
5152 | * also updates the memory address in the firmware to reference the new | |
5153 | * target buffer. | |
5154 | */ | |
5155 | static void ipw_rx_queue_restock(struct ipw_priv *priv) | |
5156 | { | |
5157 | struct ipw_rx_queue *rxq = priv->rxq; | |
5158 | struct list_head *element; | |
5159 | struct ipw_rx_mem_buffer *rxb; | |
5160 | unsigned long flags; | |
5161 | int write; | |
5162 | ||
5163 | spin_lock_irqsave(&rxq->lock, flags); | |
5164 | write = rxq->write; | |
943dbef4 | 5165 | while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
43f66a6c JK |
5166 | element = rxq->rx_free.next; |
5167 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); | |
5168 | list_del(element); | |
5169 | ||
b095c381 | 5170 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
43f66a6c JK |
5171 | rxb->dma_addr); |
5172 | rxq->queue[rxq->write] = rxb; | |
5173 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; | |
5174 | rxq->free_count--; | |
5175 | } | |
5176 | spin_unlock_irqrestore(&rxq->lock, flags); | |
5177 | ||
bf79451e | 5178 | /* If the pre-allocated buffer pool is dropping low, schedule to |
43f66a6c JK |
5179 | * refill it */ |
5180 | if (rxq->free_count <= RX_LOW_WATERMARK) | |
5181 | queue_work(priv->workqueue, &priv->rx_replenish); | |
5182 | ||
5183 | /* If we've added more space for the firmware to place data, tell it */ | |
bf79451e | 5184 | if (write != rxq->write) |
b095c381 | 5185 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
43f66a6c JK |
5186 | } |
5187 | ||
5188 | /* | |
5189 | * Move all used packet from rx_used to rx_free, allocating a new SKB for each. | |
bf79451e JG |
5190 | * Also restock the Rx queue via ipw_rx_queue_restock. |
5191 | * | |
43f66a6c JK |
5192 | * This is called as a scheduled work item (except for during intialization) |
5193 | */ | |
5194 | static void ipw_rx_queue_replenish(void *data) | |
5195 | { | |
5196 | struct ipw_priv *priv = data; | |
5197 | struct ipw_rx_queue *rxq = priv->rxq; | |
5198 | struct list_head *element; | |
5199 | struct ipw_rx_mem_buffer *rxb; | |
5200 | unsigned long flags; | |
5201 | ||
5202 | spin_lock_irqsave(&rxq->lock, flags); | |
5203 | while (!list_empty(&rxq->rx_used)) { | |
5204 | element = rxq->rx_used.next; | |
5205 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); | |
b095c381 | 5206 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
43f66a6c JK |
5207 | if (!rxb->skb) { |
5208 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", | |
5209 | priv->net_dev->name); | |
5210 | /* We don't reschedule replenish work here -- we will | |
5211 | * call the restock method and if it still needs | |
5212 | * more buffers it will schedule replenish */ | |
5213 | break; | |
5214 | } | |
5215 | list_del(element); | |
bf79451e | 5216 | |
0edd5b44 JG |
5217 | rxb->dma_addr = |
5218 | pci_map_single(priv->pci_dev, rxb->skb->data, | |
b095c381 | 5219 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
bf79451e | 5220 | |
43f66a6c JK |
5221 | list_add_tail(&rxb->list, &rxq->rx_free); |
5222 | rxq->free_count++; | |
5223 | } | |
5224 | spin_unlock_irqrestore(&rxq->lock, flags); | |
5225 | ||
5226 | ipw_rx_queue_restock(priv); | |
5227 | } | |
5228 | ||
c4028958 | 5229 | static void ipw_bg_rx_queue_replenish(struct work_struct *work) |
c848d0af | 5230 | { |
c4028958 DH |
5231 | struct ipw_priv *priv = |
5232 | container_of(work, struct ipw_priv, rx_replenish); | |
4644151b | 5233 | mutex_lock(&priv->mutex); |
c4028958 | 5234 | ipw_rx_queue_replenish(priv); |
4644151b | 5235 | mutex_unlock(&priv->mutex); |
c848d0af JK |
5236 | } |
5237 | ||
43f66a6c | 5238 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
c7b6a674 | 5239 | * If an SKB has been detached, the POOL needs to have its SKB set to NULL |
bf79451e | 5240 | * This free routine walks the list of POOL entries and if SKB is set to |
43f66a6c JK |
5241 | * non NULL it is unmapped and freed |
5242 | */ | |
0edd5b44 | 5243 | static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq) |
43f66a6c JK |
5244 | { |
5245 | int i; | |
5246 | ||
5247 | if (!rxq) | |
5248 | return; | |
bf79451e | 5249 | |
43f66a6c JK |
5250 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
5251 | if (rxq->pool[i].skb != NULL) { | |
5252 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, | |
b095c381 | 5253 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
43f66a6c JK |
5254 | dev_kfree_skb(rxq->pool[i].skb); |
5255 | } | |
5256 | } | |
5257 | ||
5258 | kfree(rxq); | |
5259 | } | |
5260 | ||
5261 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) | |
5262 | { | |
5263 | struct ipw_rx_queue *rxq; | |
5264 | int i; | |
5265 | ||
c75f4742 | 5266 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
ad18b0ea PI |
5267 | if (unlikely(!rxq)) { |
5268 | IPW_ERROR("memory allocation failed\n"); | |
5269 | return NULL; | |
5270 | } | |
43f66a6c JK |
5271 | spin_lock_init(&rxq->lock); |
5272 | INIT_LIST_HEAD(&rxq->rx_free); | |
5273 | INIT_LIST_HEAD(&rxq->rx_used); | |
5274 | ||
5275 | /* Fill the rx_used queue with _all_ of the Rx buffers */ | |
bf79451e | 5276 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
43f66a6c JK |
5277 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
5278 | ||
5279 | /* Set us so that we have processed and used all buffers, but have | |
5280 | * not restocked the Rx queue with fresh buffers */ | |
5281 | rxq->read = rxq->write = 0; | |
43f66a6c JK |
5282 | rxq->free_count = 0; |
5283 | ||
5284 | return rxq; | |
5285 | } | |
5286 | ||
5287 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) | |
5288 | { | |
b0a4e7d8 | 5289 | rate &= ~LIBIPW_BASIC_RATE_MASK; |
43f66a6c JK |
5290 | if (ieee_mode == IEEE_A) { |
5291 | switch (rate) { | |
b0a4e7d8 JL |
5292 | case LIBIPW_OFDM_RATE_6MB: |
5293 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? | |
0edd5b44 | 5294 | 1 : 0; |
b0a4e7d8 JL |
5295 | case LIBIPW_OFDM_RATE_9MB: |
5296 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? | |
0edd5b44 | 5297 | 1 : 0; |
b0a4e7d8 | 5298 | case LIBIPW_OFDM_RATE_12MB: |
0edd5b44 | 5299 | return priv-> |
b0a4e7d8 JL |
5300 | rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; |
5301 | case LIBIPW_OFDM_RATE_18MB: | |
0edd5b44 | 5302 | return priv-> |
b0a4e7d8 JL |
5303 | rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; |
5304 | case LIBIPW_OFDM_RATE_24MB: | |
0edd5b44 | 5305 | return priv-> |
b0a4e7d8 JL |
5306 | rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; |
5307 | case LIBIPW_OFDM_RATE_36MB: | |
0edd5b44 | 5308 | return priv-> |
b0a4e7d8 JL |
5309 | rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; |
5310 | case LIBIPW_OFDM_RATE_48MB: | |
0edd5b44 | 5311 | return priv-> |
b0a4e7d8 JL |
5312 | rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; |
5313 | case LIBIPW_OFDM_RATE_54MB: | |
0edd5b44 | 5314 | return priv-> |
b0a4e7d8 | 5315 | rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; |
43f66a6c JK |
5316 | default: |
5317 | return 0; | |
5318 | } | |
5319 | } | |
bf79451e | 5320 | |
43f66a6c JK |
5321 | /* B and G mixed */ |
5322 | switch (rate) { | |
b0a4e7d8 JL |
5323 | case LIBIPW_CCK_RATE_1MB: |
5324 | return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0; | |
5325 | case LIBIPW_CCK_RATE_2MB: | |
5326 | return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0; | |
5327 | case LIBIPW_CCK_RATE_5MB: | |
5328 | return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0; | |
5329 | case LIBIPW_CCK_RATE_11MB: | |
5330 | return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0; | |
43f66a6c JK |
5331 | } |
5332 | ||
5333 | /* If we are limited to B modulations, bail at this point */ | |
5334 | if (ieee_mode == IEEE_B) | |
5335 | return 0; | |
5336 | ||
5337 | /* G */ | |
5338 | switch (rate) { | |
b0a4e7d8 JL |
5339 | case LIBIPW_OFDM_RATE_6MB: |
5340 | return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0; | |
5341 | case LIBIPW_OFDM_RATE_9MB: | |
5342 | return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0; | |
5343 | case LIBIPW_OFDM_RATE_12MB: | |
5344 | return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0; | |
5345 | case LIBIPW_OFDM_RATE_18MB: | |
5346 | return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0; | |
5347 | case LIBIPW_OFDM_RATE_24MB: | |
5348 | return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0; | |
5349 | case LIBIPW_OFDM_RATE_36MB: | |
5350 | return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0; | |
5351 | case LIBIPW_OFDM_RATE_48MB: | |
5352 | return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0; | |
5353 | case LIBIPW_OFDM_RATE_54MB: | |
5354 | return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0; | |
43f66a6c JK |
5355 | } |
5356 | ||
5357 | return 0; | |
5358 | } | |
5359 | ||
bf79451e | 5360 | static int ipw_compatible_rates(struct ipw_priv *priv, |
b0a4e7d8 | 5361 | const struct libipw_network *network, |
43f66a6c JK |
5362 | struct ipw_supported_rates *rates) |
5363 | { | |
5364 | int num_rates, i; | |
5365 | ||
5366 | memset(rates, 0, sizeof(*rates)); | |
0edd5b44 | 5367 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
43f66a6c JK |
5368 | rates->num_rates = 0; |
5369 | for (i = 0; i < num_rates; i++) { | |
a613bffd JK |
5370 | if (!ipw_is_rate_in_mask(priv, network->mode, |
5371 | network->rates[i])) { | |
5372 | ||
b0a4e7d8 | 5373 | if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) { |
a613bffd JK |
5374 | IPW_DEBUG_SCAN("Adding masked mandatory " |
5375 | "rate %02X\n", | |
5376 | network->rates[i]); | |
5377 | rates->supported_rates[rates->num_rates++] = | |
5378 | network->rates[i]; | |
5379 | continue; | |
ea2b26e0 JK |
5380 | } |
5381 | ||
43f66a6c JK |
5382 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
5383 | network->rates[i], priv->rates_mask); | |
5384 | continue; | |
5385 | } | |
bf79451e | 5386 | |
43f66a6c JK |
5387 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
5388 | } | |
5389 | ||
a613bffd JK |
5390 | num_rates = min(network->rates_ex_len, |
5391 | (u8) (IPW_MAX_RATES - num_rates)); | |
43f66a6c | 5392 | for (i = 0; i < num_rates; i++) { |
a613bffd JK |
5393 | if (!ipw_is_rate_in_mask(priv, network->mode, |
5394 | network->rates_ex[i])) { | |
b0a4e7d8 | 5395 | if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) { |
a613bffd JK |
5396 | IPW_DEBUG_SCAN("Adding masked mandatory " |
5397 | "rate %02X\n", | |
5398 | network->rates_ex[i]); | |
5399 | rates->supported_rates[rates->num_rates++] = | |
5400 | network->rates[i]; | |
5401 | continue; | |
ea2b26e0 JK |
5402 | } |
5403 | ||
43f66a6c JK |
5404 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
5405 | network->rates_ex[i], priv->rates_mask); | |
5406 | continue; | |
5407 | } | |
bf79451e | 5408 | |
0edd5b44 JG |
5409 | rates->supported_rates[rates->num_rates++] = |
5410 | network->rates_ex[i]; | |
43f66a6c JK |
5411 | } |
5412 | ||
ea2b26e0 | 5413 | return 1; |
43f66a6c JK |
5414 | } |
5415 | ||
858119e1 | 5416 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
43f66a6c JK |
5417 | const struct ipw_supported_rates *src) |
5418 | { | |
5419 | u8 i; | |
5420 | for (i = 0; i < src->num_rates; i++) | |
5421 | dest->supported_rates[i] = src->supported_rates[i]; | |
5422 | dest->num_rates = src->num_rates; | |
5423 | } | |
5424 | ||
5425 | /* TODO: Look at sniffed packets in the air to determine if the basic rate | |
5426 | * mask should ever be used -- right now all callers to add the scan rates are | |
5427 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ | |
5428 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, | |
0edd5b44 | 5429 | u8 modulation, u32 rate_mask) |
43f66a6c | 5430 | { |
b0a4e7d8 JL |
5431 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
5432 | LIBIPW_BASIC_RATE_MASK : 0; | |
bf79451e | 5433 | |
b0a4e7d8 | 5434 | if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK) |
bf79451e | 5435 | rates->supported_rates[rates->num_rates++] = |
b0a4e7d8 | 5436 | LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB; |
43f66a6c | 5437 | |
b0a4e7d8 | 5438 | if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK) |
bf79451e | 5439 | rates->supported_rates[rates->num_rates++] = |
b0a4e7d8 | 5440 | LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB; |
43f66a6c | 5441 | |
b0a4e7d8 | 5442 | if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK) |
bf79451e | 5443 | rates->supported_rates[rates->num_rates++] = basic_mask | |
b0a4e7d8 | 5444 | LIBIPW_CCK_RATE_5MB; |
43f66a6c | 5445 | |
b0a4e7d8 | 5446 | if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK) |
bf79451e | 5447 | rates->supported_rates[rates->num_rates++] = basic_mask | |
b0a4e7d8 | 5448 | LIBIPW_CCK_RATE_11MB; |
43f66a6c JK |
5449 | } |
5450 | ||
5451 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, | |
0edd5b44 | 5452 | u8 modulation, u32 rate_mask) |
43f66a6c | 5453 | { |
b0a4e7d8 JL |
5454 | u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ? |
5455 | LIBIPW_BASIC_RATE_MASK : 0; | |
43f66a6c | 5456 | |
b0a4e7d8 | 5457 | if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK) |
bf79451e | 5458 | rates->supported_rates[rates->num_rates++] = basic_mask | |
b0a4e7d8 | 5459 | LIBIPW_OFDM_RATE_6MB; |
43f66a6c | 5460 | |
b0a4e7d8 | 5461 | if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK) |
bf79451e | 5462 | rates->supported_rates[rates->num_rates++] = |
b0a4e7d8 | 5463 | LIBIPW_OFDM_RATE_9MB; |
43f66a6c | 5464 | |
b0a4e7d8 | 5465 | if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK) |
bf79451e | 5466 | rates->supported_rates[rates->num_rates++] = basic_mask | |
b0a4e7d8 | 5467 | LIBIPW_OFDM_RATE_12MB; |
43f66a6c | 5468 | |
b0a4e7d8 | 5469 | if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK) |
bf79451e | 5470 | rates->supported_rates[rates->num_rates++] = |
b0a4e7d8 | 5471 | LIBIPW_OFDM_RATE_18MB; |
43f66a6c | 5472 | |
b0a4e7d8 | 5473 | if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK) |
bf79451e | 5474 | rates->supported_rates[rates->num_rates++] = basic_mask | |
b0a4e7d8 | 5475 | LIBIPW_OFDM_RATE_24MB; |
43f66a6c | 5476 | |
b0a4e7d8 | 5477 | if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK) |
bf79451e | 5478 | rates->supported_rates[rates->num_rates++] = |
b0a4e7d8 | 5479 | LIBIPW_OFDM_RATE_36MB; |
43f66a6c | 5480 | |
b0a4e7d8 | 5481 | if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK) |
bf79451e | 5482 | rates->supported_rates[rates->num_rates++] = |
b0a4e7d8 | 5483 | LIBIPW_OFDM_RATE_48MB; |
43f66a6c | 5484 | |
b0a4e7d8 | 5485 | if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK) |
bf79451e | 5486 | rates->supported_rates[rates->num_rates++] = |
b0a4e7d8 | 5487 | LIBIPW_OFDM_RATE_54MB; |
43f66a6c JK |
5488 | } |
5489 | ||
5490 | struct ipw_network_match { | |
b0a4e7d8 | 5491 | struct libipw_network *network; |
43f66a6c JK |
5492 | struct ipw_supported_rates rates; |
5493 | }; | |
5494 | ||
c848d0af JK |
5495 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
5496 | struct ipw_network_match *match, | |
b0a4e7d8 | 5497 | struct libipw_network *network, |
c848d0af | 5498 | int roaming) |
43f66a6c JK |
5499 | { |
5500 | struct ipw_supported_rates rates; | |
9387b7ca | 5501 | DECLARE_SSID_BUF(ssid); |
43f66a6c JK |
5502 | |
5503 | /* Verify that this network's capability is compatible with the | |
5504 | * current mode (AdHoc or Infrastructure) */ | |
c848d0af | 5505 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
43f66a6c | 5506 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
e174961c | 5507 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to " |
bf79451e | 5508 | "capability mismatch.\n", |
9387b7ca JL |
5509 | print_ssid(ssid, network->ssid, |
5510 | network->ssid_len), | |
e174961c | 5511 | network->bssid); |
43f66a6c JK |
5512 | return 0; |
5513 | } | |
5514 | ||
43f66a6c JK |
5515 | if (unlikely(roaming)) { |
5516 | /* If we are roaming, then ensure check if this is a valid | |
5517 | * network to try and roam to */ | |
5518 | if ((network->ssid_len != match->network->ssid_len) || | |
bf79451e | 5519 | memcmp(network->ssid, match->network->ssid, |
43f66a6c | 5520 | network->ssid_len)) { |
e174961c | 5521 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
43f66a6c | 5522 | "because of non-network ESSID.\n", |
9387b7ca JL |
5523 | print_ssid(ssid, network->ssid, |
5524 | network->ssid_len), | |
e174961c | 5525 | network->bssid); |
43f66a6c JK |
5526 | return 0; |
5527 | } | |
5528 | } else { | |
bf79451e JG |
5529 | /* If an ESSID has been configured then compare the broadcast |
5530 | * ESSID to ours */ | |
5531 | if ((priv->config & CFG_STATIC_ESSID) && | |
43f66a6c | 5532 | ((network->ssid_len != priv->essid_len) || |
bf79451e | 5533 | memcmp(network->ssid, priv->essid, |
43f66a6c JK |
5534 | min(network->ssid_len, priv->essid_len)))) { |
5535 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | |
afbf30a2 | 5536 | |
0edd5b44 | 5537 | strncpy(escaped, |
9387b7ca JL |
5538 | print_ssid(ssid, network->ssid, |
5539 | network->ssid_len), | |
43f66a6c | 5540 | sizeof(escaped)); |
e174961c | 5541 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
bf79451e | 5542 | "because of ESSID mismatch: '%s'.\n", |
e174961c | 5543 | escaped, network->bssid, |
9387b7ca JL |
5544 | print_ssid(ssid, priv->essid, |
5545 | priv->essid_len)); | |
43f66a6c JK |
5546 | return 0; |
5547 | } | |
5548 | } | |
5549 | ||
5550 | /* If the old network rate is better than this one, don't bother | |
5551 | * testing everything else. */ | |
c848d0af JK |
5552 | |
5553 | if (network->time_stamp[0] < match->network->time_stamp[0]) { | |
afbf30a2 JK |
5554 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
5555 | "current network.\n", | |
9387b7ca JL |
5556 | print_ssid(ssid, match->network->ssid, |
5557 | match->network->ssid_len)); | |
43f66a6c | 5558 | return 0; |
c848d0af | 5559 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
afbf30a2 JK |
5560 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
5561 | "current network.\n", | |
9387b7ca JL |
5562 | print_ssid(ssid, match->network->ssid, |
5563 | match->network->ssid_len)); | |
43f66a6c JK |
5564 | return 0; |
5565 | } | |
5566 | ||
5567 | /* Now go through and see if the requested network is valid... */ | |
bf79451e | 5568 | if (priv->ieee->scan_age != 0 && |
c848d0af | 5569 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
e174961c | 5570 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
c7b6a674 | 5571 | "because of age: %ums.\n", |
9387b7ca JL |
5572 | print_ssid(ssid, network->ssid, |
5573 | network->ssid_len), | |
e174961c | 5574 | network->bssid, |
2638bc39 ZY |
5575 | jiffies_to_msecs(jiffies - |
5576 | network->last_scanned)); | |
43f66a6c | 5577 | return 0; |
bf79451e | 5578 | } |
43f66a6c | 5579 | |
bf79451e | 5580 | if ((priv->config & CFG_STATIC_CHANNEL) && |
43f66a6c | 5581 | (network->channel != priv->channel)) { |
e174961c | 5582 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
43f66a6c | 5583 | "because of channel mismatch: %d != %d.\n", |
9387b7ca JL |
5584 | print_ssid(ssid, network->ssid, |
5585 | network->ssid_len), | |
e174961c | 5586 | network->bssid, |
43f66a6c JK |
5587 | network->channel, priv->channel); |
5588 | return 0; | |
5589 | } | |
bf79451e | 5590 | |
43f66a6c | 5591 | /* Verify privacy compatability */ |
bf79451e | 5592 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
43f66a6c | 5593 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
e174961c | 5594 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
43f66a6c | 5595 | "because of privacy mismatch: %s != %s.\n", |
9387b7ca JL |
5596 | print_ssid(ssid, network->ssid, |
5597 | network->ssid_len), | |
e174961c | 5598 | network->bssid, |
afbf30a2 JK |
5599 | priv-> |
5600 | capability & CAP_PRIVACY_ON ? "on" : "off", | |
5601 | network-> | |
5602 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : | |
5603 | "off"); | |
43f66a6c JK |
5604 | return 0; |
5605 | } | |
bf79451e | 5606 | |
c848d0af | 5607 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
e174961c JB |
5608 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
5609 | "because of the same BSSID match: %pM" | |
9387b7ca JL |
5610 | ".\n", print_ssid(ssid, network->ssid, |
5611 | network->ssid_len), | |
e174961c JB |
5612 | network->bssid, |
5613 | priv->bssid); | |
43f66a6c JK |
5614 | return 0; |
5615 | } | |
bf79451e | 5616 | |
43f66a6c | 5617 | /* Filter out any incompatible freq / mode combinations */ |
b0a4e7d8 | 5618 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
e174961c | 5619 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
43f66a6c JK |
5620 | "because of invalid frequency/mode " |
5621 | "combination.\n", | |
9387b7ca JL |
5622 | print_ssid(ssid, network->ssid, |
5623 | network->ssid_len), | |
e174961c | 5624 | network->bssid); |
43f66a6c JK |
5625 | return 0; |
5626 | } | |
bf79451e | 5627 | |
c848d0af JK |
5628 | /* Ensure that the rates supported by the driver are compatible with |
5629 | * this AP, including verification of basic rates (mandatory) */ | |
5630 | if (!ipw_compatible_rates(priv, network, &rates)) { | |
e174961c | 5631 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
c848d0af JK |
5632 | "because configured rate mask excludes " |
5633 | "AP mandatory rate.\n", | |
9387b7ca JL |
5634 | print_ssid(ssid, network->ssid, |
5635 | network->ssid_len), | |
e174961c | 5636 | network->bssid); |
c848d0af JK |
5637 | return 0; |
5638 | } | |
5639 | ||
43f66a6c | 5640 | if (rates.num_rates == 0) { |
e174961c | 5641 | IPW_DEBUG_MERGE("Network '%s (%pM)' excluded " |
43f66a6c | 5642 | "because of no compatible rates.\n", |
9387b7ca JL |
5643 | print_ssid(ssid, network->ssid, |
5644 | network->ssid_len), | |
e174961c | 5645 | network->bssid); |
43f66a6c JK |
5646 | return 0; |
5647 | } | |
bf79451e | 5648 | |
43f66a6c JK |
5649 | /* TODO: Perform any further minimal comparititive tests. We do not |
5650 | * want to put too much policy logic here; intelligent scan selection | |
5651 | * should occur within a generic IEEE 802.11 user space tool. */ | |
5652 | ||
5653 | /* Set up 'new' AP to this network */ | |
5654 | ipw_copy_rates(&match->rates, &rates); | |
5655 | match->network = network; | |
e174961c | 5656 | IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n", |
9387b7ca | 5657 | print_ssid(ssid, network->ssid, network->ssid_len), |
e174961c | 5658 | network->bssid); |
43f66a6c JK |
5659 | |
5660 | return 1; | |
5661 | } | |
5662 | ||
c4028958 | 5663 | static void ipw_merge_adhoc_network(struct work_struct *work) |
43f66a6c | 5664 | { |
9387b7ca | 5665 | DECLARE_SSID_BUF(ssid); |
c4028958 DH |
5666 | struct ipw_priv *priv = |
5667 | container_of(work, struct ipw_priv, merge_networks); | |
b0a4e7d8 | 5668 | struct libipw_network *network = NULL; |
c848d0af JK |
5669 | struct ipw_network_match match = { |
5670 | .network = priv->assoc_network | |
5671 | }; | |
5672 | ||
afbf30a2 JK |
5673 | if ((priv->status & STATUS_ASSOCIATED) && |
5674 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { | |
c848d0af JK |
5675 | /* First pass through ROAM process -- look for a better |
5676 | * network */ | |
5677 | unsigned long flags; | |
5678 | ||
5679 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
5680 | list_for_each_entry(network, &priv->ieee->network_list, list) { | |
5681 | if (network != priv->assoc_network) | |
5682 | ipw_find_adhoc_network(priv, &match, network, | |
5683 | 1); | |
5684 | } | |
5685 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
5686 | ||
5687 | if (match.network == priv->assoc_network) { | |
5688 | IPW_DEBUG_MERGE("No better ADHOC in this network to " | |
5689 | "merge to.\n"); | |
5690 | return; | |
5691 | } | |
5692 | ||
4644151b | 5693 | mutex_lock(&priv->mutex); |
c848d0af JK |
5694 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
5695 | IPW_DEBUG_MERGE("remove network %s\n", | |
9387b7ca JL |
5696 | print_ssid(ssid, priv->essid, |
5697 | priv->essid_len)); | |
c848d0af | 5698 | ipw_remove_current_network(priv); |
43f66a6c | 5699 | } |
c848d0af JK |
5700 | |
5701 | ipw_disassociate(priv); | |
5702 | priv->assoc_network = match.network; | |
4644151b | 5703 | mutex_unlock(&priv->mutex); |
c848d0af | 5704 | return; |
43f66a6c | 5705 | } |
c848d0af | 5706 | } |
43f66a6c | 5707 | |
0edd5b44 JG |
5708 | static int ipw_best_network(struct ipw_priv *priv, |
5709 | struct ipw_network_match *match, | |
b0a4e7d8 | 5710 | struct libipw_network *network, int roaming) |
43f66a6c JK |
5711 | { |
5712 | struct ipw_supported_rates rates; | |
9387b7ca | 5713 | DECLARE_SSID_BUF(ssid); |
43f66a6c JK |
5714 | |
5715 | /* Verify that this network's capability is compatible with the | |
5716 | * current mode (AdHoc or Infrastructure) */ | |
5717 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && | |
2474385e | 5718 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
43f66a6c JK |
5719 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
5720 | !(network->capability & WLAN_CAPABILITY_IBSS))) { | |
e174961c | 5721 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to " |
bf79451e | 5722 | "capability mismatch.\n", |
9387b7ca JL |
5723 | print_ssid(ssid, network->ssid, |
5724 | network->ssid_len), | |
e174961c | 5725 | network->bssid); |
43f66a6c JK |
5726 | return 0; |
5727 | } | |
5728 | ||
43f66a6c JK |
5729 | if (unlikely(roaming)) { |
5730 | /* If we are roaming, then ensure check if this is a valid | |
5731 | * network to try and roam to */ | |
5732 | if ((network->ssid_len != match->network->ssid_len) || | |
bf79451e | 5733 | memcmp(network->ssid, match->network->ssid, |
43f66a6c | 5734 | network->ssid_len)) { |
e174961c | 5735 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
43f66a6c | 5736 | "because of non-network ESSID.\n", |
9387b7ca JL |
5737 | print_ssid(ssid, network->ssid, |
5738 | network->ssid_len), | |
e174961c | 5739 | network->bssid); |
43f66a6c JK |
5740 | return 0; |
5741 | } | |
5742 | } else { | |
bf79451e JG |
5743 | /* If an ESSID has been configured then compare the broadcast |
5744 | * ESSID to ours */ | |
5745 | if ((priv->config & CFG_STATIC_ESSID) && | |
43f66a6c | 5746 | ((network->ssid_len != priv->essid_len) || |
bf79451e | 5747 | memcmp(network->ssid, priv->essid, |
43f66a6c JK |
5748 | min(network->ssid_len, priv->essid_len)))) { |
5749 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | |
0edd5b44 | 5750 | strncpy(escaped, |
9387b7ca JL |
5751 | print_ssid(ssid, network->ssid, |
5752 | network->ssid_len), | |
43f66a6c | 5753 | sizeof(escaped)); |
e174961c | 5754 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
bf79451e | 5755 | "because of ESSID mismatch: '%s'.\n", |
e174961c | 5756 | escaped, network->bssid, |
9387b7ca JL |
5757 | print_ssid(ssid, priv->essid, |
5758 | priv->essid_len)); | |
43f66a6c JK |
5759 | return 0; |
5760 | } | |
5761 | } | |
5762 | ||
5763 | /* If the old network rate is better than this one, don't bother | |
5764 | * testing everything else. */ | |
0edd5b44 | 5765 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
43f66a6c | 5766 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
bf79451e | 5767 | strncpy(escaped, |
9387b7ca | 5768 | print_ssid(ssid, network->ssid, network->ssid_len), |
43f66a6c | 5769 | sizeof(escaped)); |
e174961c JB |
5770 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because " |
5771 | "'%s (%pM)' has a stronger signal.\n", | |
5772 | escaped, network->bssid, | |
9387b7ca JL |
5773 | print_ssid(ssid, match->network->ssid, |
5774 | match->network->ssid_len), | |
e174961c | 5775 | match->network->bssid); |
43f66a6c JK |
5776 | return 0; |
5777 | } | |
bf79451e | 5778 | |
43f66a6c JK |
5779 | /* If this network has already had an association attempt within the |
5780 | * last 3 seconds, do not try and associate again... */ | |
5781 | if (network->last_associate && | |
ea2b26e0 | 5782 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
e174961c | 5783 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
c7b6a674 | 5784 | "because of storming (%ums since last " |
43f66a6c | 5785 | "assoc attempt).\n", |
9387b7ca JL |
5786 | print_ssid(ssid, network->ssid, |
5787 | network->ssid_len), | |
e174961c | 5788 | network->bssid, |
2638bc39 ZY |
5789 | jiffies_to_msecs(jiffies - |
5790 | network->last_associate)); | |
43f66a6c JK |
5791 | return 0; |
5792 | } | |
5793 | ||
5794 | /* Now go through and see if the requested network is valid... */ | |
bf79451e | 5795 | if (priv->ieee->scan_age != 0 && |
ea2b26e0 | 5796 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
e174961c | 5797 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
c7b6a674 | 5798 | "because of age: %ums.\n", |
9387b7ca JL |
5799 | print_ssid(ssid, network->ssid, |
5800 | network->ssid_len), | |
e174961c | 5801 | network->bssid, |
2638bc39 ZY |
5802 | jiffies_to_msecs(jiffies - |
5803 | network->last_scanned)); | |
43f66a6c | 5804 | return 0; |
bf79451e | 5805 | } |
43f66a6c | 5806 | |
bf79451e | 5807 | if ((priv->config & CFG_STATIC_CHANNEL) && |
43f66a6c | 5808 | (network->channel != priv->channel)) { |
e174961c | 5809 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
43f66a6c | 5810 | "because of channel mismatch: %d != %d.\n", |
9387b7ca JL |
5811 | print_ssid(ssid, network->ssid, |
5812 | network->ssid_len), | |
e174961c | 5813 | network->bssid, |
43f66a6c JK |
5814 | network->channel, priv->channel); |
5815 | return 0; | |
5816 | } | |
bf79451e | 5817 | |
43f66a6c | 5818 | /* Verify privacy compatability */ |
bf79451e | 5819 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
43f66a6c | 5820 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
e174961c | 5821 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
43f66a6c | 5822 | "because of privacy mismatch: %s != %s.\n", |
9387b7ca JL |
5823 | print_ssid(ssid, network->ssid, |
5824 | network->ssid_len), | |
e174961c | 5825 | network->bssid, |
bf79451e | 5826 | priv->capability & CAP_PRIVACY_ON ? "on" : |
43f66a6c | 5827 | "off", |
bf79451e | 5828 | network->capability & |
0edd5b44 | 5829 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
43f66a6c JK |
5830 | return 0; |
5831 | } | |
bf79451e JG |
5832 | |
5833 | if ((priv->config & CFG_STATIC_BSSID) && | |
43f66a6c | 5834 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
e174961c JB |
5835 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
5836 | "because of BSSID mismatch: %pM.\n", | |
9387b7ca JL |
5837 | print_ssid(ssid, network->ssid, |
5838 | network->ssid_len), | |
e174961c | 5839 | network->bssid, priv->bssid); |
43f66a6c JK |
5840 | return 0; |
5841 | } | |
bf79451e | 5842 | |
43f66a6c | 5843 | /* Filter out any incompatible freq / mode combinations */ |
b0a4e7d8 | 5844 | if (!libipw_is_valid_mode(priv->ieee, network->mode)) { |
e174961c | 5845 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
43f66a6c JK |
5846 | "because of invalid frequency/mode " |
5847 | "combination.\n", | |
9387b7ca JL |
5848 | print_ssid(ssid, network->ssid, |
5849 | network->ssid_len), | |
e174961c | 5850 | network->bssid); |
43f66a6c JK |
5851 | return 0; |
5852 | } | |
bf79451e | 5853 | |
1fe0adb4 | 5854 | /* Filter out invalid channel in current GEO */ |
b0a4e7d8 | 5855 | if (!libipw_is_valid_channel(priv->ieee, network->channel)) { |
e174961c | 5856 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
1fe0adb4 | 5857 | "because of invalid channel in current GEO\n", |
9387b7ca JL |
5858 | print_ssid(ssid, network->ssid, |
5859 | network->ssid_len), | |
e174961c | 5860 | network->bssid); |
1fe0adb4 LH |
5861 | return 0; |
5862 | } | |
5863 | ||
ea2b26e0 JK |
5864 | /* Ensure that the rates supported by the driver are compatible with |
5865 | * this AP, including verification of basic rates (mandatory) */ | |
5866 | if (!ipw_compatible_rates(priv, network, &rates)) { | |
e174961c | 5867 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
ea2b26e0 JK |
5868 | "because configured rate mask excludes " |
5869 | "AP mandatory rate.\n", | |
9387b7ca JL |
5870 | print_ssid(ssid, network->ssid, |
5871 | network->ssid_len), | |
e174961c | 5872 | network->bssid); |
ea2b26e0 JK |
5873 | return 0; |
5874 | } | |
5875 | ||
43f66a6c | 5876 | if (rates.num_rates == 0) { |
e174961c | 5877 | IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded " |
43f66a6c | 5878 | "because of no compatible rates.\n", |
9387b7ca JL |
5879 | print_ssid(ssid, network->ssid, |
5880 | network->ssid_len), | |
e174961c | 5881 | network->bssid); |
43f66a6c JK |
5882 | return 0; |
5883 | } | |
bf79451e | 5884 | |
43f66a6c JK |
5885 | /* TODO: Perform any further minimal comparititive tests. We do not |
5886 | * want to put too much policy logic here; intelligent scan selection | |
5887 | * should occur within a generic IEEE 802.11 user space tool. */ | |
5888 | ||
5889 | /* Set up 'new' AP to this network */ | |
5890 | ipw_copy_rates(&match->rates, &rates); | |
5891 | match->network = network; | |
5892 | ||
e174961c | 5893 | IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n", |
9387b7ca | 5894 | print_ssid(ssid, network->ssid, network->ssid_len), |
e174961c | 5895 | network->bssid); |
43f66a6c JK |
5896 | |
5897 | return 1; | |
5898 | } | |
5899 | ||
bf79451e | 5900 | static void ipw_adhoc_create(struct ipw_priv *priv, |
b0a4e7d8 | 5901 | struct libipw_network *network) |
43f66a6c | 5902 | { |
b0a4e7d8 | 5903 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
afbf30a2 JK |
5904 | int i; |
5905 | ||
43f66a6c JK |
5906 | /* |
5907 | * For the purposes of scanning, we can set our wireless mode | |
5908 | * to trigger scans across combinations of bands, but when it | |
5909 | * comes to creating a new ad-hoc network, we have tell the FW | |
5910 | * exactly which band to use. | |
5911 | * | |
bf79451e | 5912 | * We also have the possibility of an invalid channel for the |
43f66a6c JK |
5913 | * chossen band. Attempting to create a new ad-hoc network |
5914 | * with an invalid channel for wireless mode will trigger a | |
5915 | * FW fatal error. | |
afbf30a2 | 5916 | * |
43f66a6c | 5917 | */ |
b0a4e7d8 JL |
5918 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
5919 | case LIBIPW_52GHZ_BAND: | |
afbf30a2 | 5920 | network->mode = IEEE_A; |
b0a4e7d8 | 5921 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
5d9428de | 5922 | BUG_ON(i == -1); |
b0a4e7d8 | 5923 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
afbf30a2 JK |
5924 | IPW_WARNING("Overriding invalid channel\n"); |
5925 | priv->channel = geo->a[0].channel; | |
5926 | } | |
5927 | break; | |
5928 | ||
b0a4e7d8 | 5929 | case LIBIPW_24GHZ_BAND: |
afbf30a2 JK |
5930 | if (priv->ieee->mode & IEEE_G) |
5931 | network->mode = IEEE_G; | |
5932 | else | |
5933 | network->mode = IEEE_B; | |
b0a4e7d8 | 5934 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
5d9428de | 5935 | BUG_ON(i == -1); |
b0a4e7d8 | 5936 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) { |
1fe0adb4 LH |
5937 | IPW_WARNING("Overriding invalid channel\n"); |
5938 | priv->channel = geo->bg[0].channel; | |
5939 | } | |
afbf30a2 JK |
5940 | break; |
5941 | ||
5942 | default: | |
43f66a6c JK |
5943 | IPW_WARNING("Overriding invalid channel\n"); |
5944 | if (priv->ieee->mode & IEEE_A) { | |
5945 | network->mode = IEEE_A; | |
b095c381 | 5946 | priv->channel = geo->a[0].channel; |
43f66a6c JK |
5947 | } else if (priv->ieee->mode & IEEE_G) { |
5948 | network->mode = IEEE_G; | |
b095c381 | 5949 | priv->channel = geo->bg[0].channel; |
43f66a6c JK |
5950 | } else { |
5951 | network->mode = IEEE_B; | |
b095c381 | 5952 | priv->channel = geo->bg[0].channel; |
43f66a6c | 5953 | } |
afbf30a2 JK |
5954 | break; |
5955 | } | |
43f66a6c JK |
5956 | |
5957 | network->channel = priv->channel; | |
5958 | priv->config |= CFG_ADHOC_PERSIST; | |
5959 | ipw_create_bssid(priv, network->bssid); | |
5960 | network->ssid_len = priv->essid_len; | |
5961 | memcpy(network->ssid, priv->essid, priv->essid_len); | |
5962 | memset(&network->stats, 0, sizeof(network->stats)); | |
5963 | network->capability = WLAN_CAPABILITY_IBSS; | |
ea2b26e0 JK |
5964 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
5965 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; | |
43f66a6c JK |
5966 | if (priv->capability & CAP_PRIVACY_ON) |
5967 | network->capability |= WLAN_CAPABILITY_PRIVACY; | |
5968 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); | |
0edd5b44 | 5969 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
43f66a6c | 5970 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
bf79451e | 5971 | memcpy(network->rates_ex, |
43f66a6c JK |
5972 | &priv->rates.supported_rates[network->rates_len], |
5973 | network->rates_ex_len); | |
5974 | network->last_scanned = 0; | |
5975 | network->flags = 0; | |
5976 | network->last_associate = 0; | |
5977 | network->time_stamp[0] = 0; | |
5978 | network->time_stamp[1] = 0; | |
0edd5b44 JG |
5979 | network->beacon_interval = 100; /* Default */ |
5980 | network->listen_interval = 10; /* Default */ | |
5981 | network->atim_window = 0; /* Default */ | |
43f66a6c JK |
5982 | network->wpa_ie_len = 0; |
5983 | network->rsn_ie_len = 0; | |
43f66a6c JK |
5984 | } |
5985 | ||
b095c381 JK |
5986 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
5987 | { | |
0a7bcf26 | 5988 | struct ipw_tgi_tx_key key; |
b095c381 JK |
5989 | |
5990 | if (!(priv->ieee->sec.flags & (1 << index))) | |
5991 | return; | |
5992 | ||
0a7bcf26 ZY |
5993 | key.key_id = index; |
5994 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); | |
5995 | key.security_type = type; | |
5996 | key.station_index = 0; /* always 0 for BSS */ | |
5997 | key.flags = 0; | |
b095c381 | 5998 | /* 0 for new key; previous value of counter (after fatal error) */ |
851ca268 ZY |
5999 | key.tx_counter[0] = cpu_to_le32(0); |
6000 | key.tx_counter[1] = cpu_to_le32(0); | |
b095c381 | 6001 | |
0a7bcf26 | 6002 | ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key); |
b095c381 JK |
6003 | } |
6004 | ||
6005 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) | |
43f66a6c | 6006 | { |
0a7bcf26 | 6007 | struct ipw_wep_key key; |
43f66a6c | 6008 | int i; |
43f66a6c | 6009 | |
0a7bcf26 ZY |
6010 | key.cmd_id = DINO_CMD_WEP_KEY; |
6011 | key.seq_num = 0; | |
43f66a6c | 6012 | |
b095c381 JK |
6013 | /* Note: AES keys cannot be set for multiple times. |
6014 | * Only set it at the first time. */ | |
bf79451e | 6015 | for (i = 0; i < 4; i++) { |
0a7bcf26 | 6016 | key.key_index = i | type; |
b095c381 | 6017 | if (!(priv->ieee->sec.flags & (1 << i))) { |
0a7bcf26 | 6018 | key.key_size = 0; |
b095c381 | 6019 | continue; |
43f66a6c JK |
6020 | } |
6021 | ||
0a7bcf26 ZY |
6022 | key.key_size = priv->ieee->sec.key_sizes[i]; |
6023 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); | |
b095c381 | 6024 | |
0a7bcf26 | 6025 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
bf79451e | 6026 | } |
43f66a6c JK |
6027 | } |
6028 | ||
1fbfea54 | 6029 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
43f66a6c | 6030 | { |
1fbfea54 | 6031 | if (priv->ieee->host_encrypt) |
43f66a6c | 6032 | return; |
43f66a6c | 6033 | |
1fbfea54 ZY |
6034 | switch (level) { |
6035 | case SEC_LEVEL_3: | |
6036 | priv->sys_config.disable_unicast_decryption = 0; | |
6037 | priv->ieee->host_decrypt = 0; | |
6038 | break; | |
6039 | case SEC_LEVEL_2: | |
6040 | priv->sys_config.disable_unicast_decryption = 1; | |
6041 | priv->ieee->host_decrypt = 1; | |
6042 | break; | |
6043 | case SEC_LEVEL_1: | |
6044 | priv->sys_config.disable_unicast_decryption = 0; | |
6045 | priv->ieee->host_decrypt = 0; | |
6046 | break; | |
6047 | case SEC_LEVEL_0: | |
6048 | priv->sys_config.disable_unicast_decryption = 1; | |
6049 | break; | |
6050 | default: | |
6051 | break; | |
6052 | } | |
6053 | } | |
6054 | ||
6055 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) | |
6056 | { | |
6057 | if (priv->ieee->host_encrypt) | |
6058 | return; | |
6059 | ||
6060 | switch (level) { | |
6061 | case SEC_LEVEL_3: | |
6062 | priv->sys_config.disable_multicast_decryption = 0; | |
6063 | break; | |
6064 | case SEC_LEVEL_2: | |
6065 | priv->sys_config.disable_multicast_decryption = 1; | |
6066 | break; | |
6067 | case SEC_LEVEL_1: | |
6068 | priv->sys_config.disable_multicast_decryption = 0; | |
6069 | break; | |
6070 | case SEC_LEVEL_0: | |
6071 | priv->sys_config.disable_multicast_decryption = 1; | |
6072 | break; | |
6073 | default: | |
6074 | break; | |
6075 | } | |
6076 | } | |
6077 | ||
b095c381 JK |
6078 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
6079 | { | |
6080 | switch (priv->ieee->sec.level) { | |
6081 | case SEC_LEVEL_3: | |
d8bad6df ZY |
6082 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
6083 | ipw_send_tgi_tx_key(priv, | |
6084 | DCT_FLAG_EXT_SECURITY_CCM, | |
6085 | priv->ieee->sec.active_key); | |
afbf30a2 | 6086 | |
567deaf6 HL |
6087 | if (!priv->ieee->host_mc_decrypt) |
6088 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); | |
b095c381 JK |
6089 | break; |
6090 | case SEC_LEVEL_2: | |
d8bad6df ZY |
6091 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
6092 | ipw_send_tgi_tx_key(priv, | |
6093 | DCT_FLAG_EXT_SECURITY_TKIP, | |
6094 | priv->ieee->sec.active_key); | |
b095c381 JK |
6095 | break; |
6096 | case SEC_LEVEL_1: | |
6097 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); | |
29cb843e HL |
6098 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
6099 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); | |
b095c381 JK |
6100 | break; |
6101 | case SEC_LEVEL_0: | |
6102 | default: | |
6103 | break; | |
6104 | } | |
6105 | } | |
6106 | ||
43f66a6c JK |
6107 | static void ipw_adhoc_check(void *data) |
6108 | { | |
6109 | struct ipw_priv *priv = data; | |
bf79451e | 6110 | |
afbf30a2 | 6111 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
43f66a6c | 6112 | !(priv->config & CFG_ADHOC_PERSIST)) { |
afbf30a2 JK |
6113 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
6114 | IPW_DL_STATE | IPW_DL_ASSOC, | |
6115 | "Missed beacon: %d - disassociate\n", | |
6116 | priv->missed_adhoc_beacons); | |
43f66a6c JK |
6117 | ipw_remove_current_network(priv); |
6118 | ipw_disassociate(priv); | |
6119 | return; | |
6120 | } | |
6121 | ||
bf79451e | 6122 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
5b5e807f | 6123 | le16_to_cpu(priv->assoc_request.beacon_interval)); |
43f66a6c JK |
6124 | } |
6125 | ||
c4028958 | 6126 | static void ipw_bg_adhoc_check(struct work_struct *work) |
c848d0af | 6127 | { |
c4028958 DH |
6128 | struct ipw_priv *priv = |
6129 | container_of(work, struct ipw_priv, adhoc_check.work); | |
4644151b | 6130 | mutex_lock(&priv->mutex); |
c4028958 | 6131 | ipw_adhoc_check(priv); |
4644151b | 6132 | mutex_unlock(&priv->mutex); |
c848d0af JK |
6133 | } |
6134 | ||
43f66a6c JK |
6135 | static void ipw_debug_config(struct ipw_priv *priv) |
6136 | { | |
9387b7ca | 6137 | DECLARE_SSID_BUF(ssid); |
43f66a6c JK |
6138 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " |
6139 | "[CFG 0x%08X]\n", priv->config); | |
6140 | if (priv->config & CFG_STATIC_CHANNEL) | |
0edd5b44 | 6141 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
43f66a6c JK |
6142 | else |
6143 | IPW_DEBUG_INFO("Channel unlocked.\n"); | |
6144 | if (priv->config & CFG_STATIC_ESSID) | |
bf79451e | 6145 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
9387b7ca | 6146 | print_ssid(ssid, priv->essid, priv->essid_len)); |
43f66a6c JK |
6147 | else |
6148 | IPW_DEBUG_INFO("ESSID unlocked.\n"); | |
6149 | if (priv->config & CFG_STATIC_BSSID) | |
e174961c | 6150 | IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid); |
43f66a6c JK |
6151 | else |
6152 | IPW_DEBUG_INFO("BSSID unlocked.\n"); | |
6153 | if (priv->capability & CAP_PRIVACY_ON) | |
6154 | IPW_DEBUG_INFO("PRIVACY on\n"); | |
6155 | else | |
6156 | IPW_DEBUG_INFO("PRIVACY off\n"); | |
6157 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); | |
6158 | } | |
43f66a6c | 6159 | |
858119e1 | 6160 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
43f66a6c JK |
6161 | { |
6162 | /* TODO: Verify that this works... */ | |
21f8a73f | 6163 | struct ipw_fixed_rate fr; |
43f66a6c JK |
6164 | u32 reg; |
6165 | u16 mask = 0; | |
21f8a73f | 6166 | u16 new_tx_rates = priv->rates_mask; |
43f66a6c | 6167 | |
bf79451e | 6168 | /* Identify 'current FW band' and match it with the fixed |
43f66a6c | 6169 | * Tx rates */ |
bf79451e | 6170 | |
43f66a6c | 6171 | switch (priv->ieee->freq_band) { |
b0a4e7d8 | 6172 | case LIBIPW_52GHZ_BAND: /* A only */ |
43f66a6c | 6173 | /* IEEE_A */ |
b0a4e7d8 | 6174 | if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) { |
43f66a6c | 6175 | /* Invalid fixed rate mask */ |
ea2b26e0 JK |
6176 | IPW_DEBUG_WX |
6177 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | |
21f8a73f | 6178 | new_tx_rates = 0; |
43f66a6c JK |
6179 | break; |
6180 | } | |
bf79451e | 6181 | |
b0a4e7d8 | 6182 | new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A; |
43f66a6c JK |
6183 | break; |
6184 | ||
0edd5b44 | 6185 | default: /* 2.4Ghz or Mixed */ |
43f66a6c | 6186 | /* IEEE_B */ |
b095c381 | 6187 | if (mode == IEEE_B) { |
b0a4e7d8 | 6188 | if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) { |
43f66a6c | 6189 | /* Invalid fixed rate mask */ |
ea2b26e0 JK |
6190 | IPW_DEBUG_WX |
6191 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | |
21f8a73f | 6192 | new_tx_rates = 0; |
43f66a6c JK |
6193 | } |
6194 | break; | |
bf79451e | 6195 | } |
43f66a6c JK |
6196 | |
6197 | /* IEEE_G */ | |
b0a4e7d8 JL |
6198 | if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK | |
6199 | LIBIPW_OFDM_RATES_MASK)) { | |
43f66a6c | 6200 | /* Invalid fixed rate mask */ |
ea2b26e0 JK |
6201 | IPW_DEBUG_WX |
6202 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | |
21f8a73f | 6203 | new_tx_rates = 0; |
43f66a6c JK |
6204 | break; |
6205 | } | |
bf79451e | 6206 | |
b0a4e7d8 JL |
6207 | if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) { |
6208 | mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1); | |
6209 | new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK; | |
43f66a6c | 6210 | } |
bf79451e | 6211 | |
b0a4e7d8 JL |
6212 | if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) { |
6213 | mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1); | |
6214 | new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK; | |
43f66a6c | 6215 | } |
bf79451e | 6216 | |
b0a4e7d8 JL |
6217 | if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) { |
6218 | mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1); | |
6219 | new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK; | |
43f66a6c | 6220 | } |
bf79451e | 6221 | |
21f8a73f | 6222 | new_tx_rates |= mask; |
43f66a6c JK |
6223 | break; |
6224 | } | |
6225 | ||
21f8a73f RC |
6226 | fr.tx_rates = cpu_to_le16(new_tx_rates); |
6227 | ||
43f66a6c | 6228 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); |
0edd5b44 | 6229 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
43f66a6c JK |
6230 | } |
6231 | ||
ea2b26e0 | 6232 | static void ipw_abort_scan(struct ipw_priv *priv) |
43f66a6c JK |
6233 | { |
6234 | int err; | |
6235 | ||
ea2b26e0 JK |
6236 | if (priv->status & STATUS_SCAN_ABORTING) { |
6237 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); | |
6238 | return; | |
6239 | } | |
6240 | priv->status |= STATUS_SCAN_ABORTING; | |
43f66a6c | 6241 | |
ea2b26e0 JK |
6242 | err = ipw_send_scan_abort(priv); |
6243 | if (err) | |
6244 | IPW_DEBUG_HC("Request to abort scan failed.\n"); | |
6245 | } | |
6246 | ||
afbf30a2 JK |
6247 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
6248 | struct ipw_scan_request_ext *scan, | |
6249 | int scan_type) | |
ea2b26e0 | 6250 | { |
ea2b26e0 | 6251 | int channel_index = 0; |
b0a4e7d8 | 6252 | const struct libipw_geo *geo; |
afbf30a2 | 6253 | int i; |
b095c381 | 6254 | |
b0a4e7d8 | 6255 | geo = libipw_get_geo(priv->ieee); |
43f66a6c | 6256 | |
b0a4e7d8 | 6257 | if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) { |
afbf30a2 JK |
6258 | int start = channel_index; |
6259 | for (i = 0; i < geo->a_channels; i++) { | |
6260 | if ((priv->status & STATUS_ASSOCIATED) && | |
6261 | geo->a[i].channel == priv->channel) | |
6262 | continue; | |
6263 | channel_index++; | |
6264 | scan->channels_list[channel_index] = geo->a[i].channel; | |
1fe0adb4 LH |
6265 | ipw_set_scan_type(scan, channel_index, |
6266 | geo->a[i]. | |
b0a4e7d8 | 6267 | flags & LIBIPW_CH_PASSIVE_ONLY ? |
1fe0adb4 LH |
6268 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : |
6269 | scan_type); | |
afbf30a2 JK |
6270 | } |
6271 | ||
6272 | if (start != channel_index) { | |
6273 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | | |
6274 | (channel_index - start); | |
6275 | channel_index++; | |
6276 | } | |
6277 | } | |
6278 | ||
b0a4e7d8 | 6279 | if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) { |
afbf30a2 JK |
6280 | int start = channel_index; |
6281 | if (priv->config & CFG_SPEED_SCAN) { | |
1fe0adb4 | 6282 | int index; |
b0a4e7d8 | 6283 | u8 channels[LIBIPW_24GHZ_CHANNELS] = { |
afbf30a2 JK |
6284 | /* nop out the list */ |
6285 | [0] = 0 | |
6286 | }; | |
6287 | ||
6288 | u8 channel; | |
7dd2459d | 6289 | while (channel_index < IPW_SCAN_CHANNELS - 1) { |
afbf30a2 JK |
6290 | channel = |
6291 | priv->speed_scan[priv->speed_scan_pos]; | |
6292 | if (channel == 0) { | |
6293 | priv->speed_scan_pos = 0; | |
6294 | channel = priv->speed_scan[0]; | |
6295 | } | |
6296 | if ((priv->status & STATUS_ASSOCIATED) && | |
6297 | channel == priv->channel) { | |
6298 | priv->speed_scan_pos++; | |
6299 | continue; | |
6300 | } | |
6301 | ||
6302 | /* If this channel has already been | |
6303 | * added in scan, break from loop | |
6304 | * and this will be the first channel | |
6305 | * in the next scan. | |
6306 | */ | |
6307 | if (channels[channel - 1] != 0) | |
6308 | break; | |
6309 | ||
6310 | channels[channel - 1] = 1; | |
6311 | priv->speed_scan_pos++; | |
6312 | channel_index++; | |
6313 | scan->channels_list[channel_index] = channel; | |
1fe0adb4 | 6314 | index = |
b0a4e7d8 | 6315 | libipw_channel_to_index(priv->ieee, channel); |
afbf30a2 | 6316 | ipw_set_scan_type(scan, channel_index, |
1fe0adb4 LH |
6317 | geo->bg[index]. |
6318 | flags & | |
b0a4e7d8 | 6319 | LIBIPW_CH_PASSIVE_ONLY ? |
1fe0adb4 LH |
6320 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
6321 | : scan_type); | |
afbf30a2 JK |
6322 | } |
6323 | } else { | |
6324 | for (i = 0; i < geo->bg_channels; i++) { | |
6325 | if ((priv->status & STATUS_ASSOCIATED) && | |
6326 | geo->bg[i].channel == priv->channel) | |
6327 | continue; | |
6328 | channel_index++; | |
6329 | scan->channels_list[channel_index] = | |
6330 | geo->bg[i].channel; | |
6331 | ipw_set_scan_type(scan, channel_index, | |
1fe0adb4 LH |
6332 | geo->bg[i]. |
6333 | flags & | |
b0a4e7d8 | 6334 | LIBIPW_CH_PASSIVE_ONLY ? |
1fe0adb4 LH |
6335 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN |
6336 | : scan_type); | |
afbf30a2 JK |
6337 | } |
6338 | } | |
6339 | ||
6340 | if (start != channel_index) { | |
6341 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | | |
6342 | (channel_index - start); | |
6343 | } | |
6344 | } | |
6345 | } | |
6346 | ||
14a4dfe2 HS |
6347 | static int ipw_passive_dwell_time(struct ipw_priv *priv) |
6348 | { | |
6349 | /* staying on passive channels longer than the DTIM interval during a | |
6350 | * scan, while associated, causes the firmware to cancel the scan | |
6351 | * without notification. Hence, don't stay on passive channels longer | |
6352 | * than the beacon interval. | |
6353 | */ | |
6354 | if (priv->status & STATUS_ASSOCIATED | |
6355 | && priv->assoc_network->beacon_interval > 10) | |
6356 | return priv->assoc_network->beacon_interval - 10; | |
6357 | else | |
6358 | return 120; | |
6359 | } | |
6360 | ||
ea177305 | 6361 | static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct) |
afbf30a2 JK |
6362 | { |
6363 | struct ipw_scan_request_ext scan; | |
6364 | int err = 0, scan_type; | |
6365 | ||
6366 | if (!(priv->status & STATUS_INIT) || | |
6367 | (priv->status & STATUS_EXIT_PENDING)) | |
6368 | return 0; | |
6369 | ||
4644151b | 6370 | mutex_lock(&priv->mutex); |
afbf30a2 | 6371 | |
ea177305 DW |
6372 | if (direct && (priv->direct_scan_ssid_len == 0)) { |
6373 | IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n"); | |
6374 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; | |
6375 | goto done; | |
6376 | } | |
6377 | ||
ea2b26e0 | 6378 | if (priv->status & STATUS_SCANNING) { |
ea177305 DW |
6379 | IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n"); |
6380 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : | |
6381 | STATUS_SCAN_PENDING; | |
b095c381 | 6382 | goto done; |
ea2b26e0 | 6383 | } |
43f66a6c | 6384 | |
afbf30a2 JK |
6385 | if (!(priv->status & STATUS_SCAN_FORCED) && |
6386 | priv->status & STATUS_SCAN_ABORTING) { | |
ea2b26e0 | 6387 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
ea177305 DW |
6388 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : |
6389 | STATUS_SCAN_PENDING; | |
b095c381 | 6390 | goto done; |
43f66a6c JK |
6391 | } |
6392 | ||
ea2b26e0 | 6393 | if (priv->status & STATUS_RF_KILL_MASK) { |
ea177305 DW |
6394 | IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n"); |
6395 | priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING : | |
6396 | STATUS_SCAN_PENDING; | |
b095c381 | 6397 | goto done; |
ea2b26e0 | 6398 | } |
43f66a6c | 6399 | |
ea2b26e0 | 6400 | memset(&scan, 0, sizeof(scan)); |
b0a4e7d8 | 6401 | scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee)); |
43f66a6c | 6402 | |
094c4d2d | 6403 | if (type == IW_SCAN_TYPE_PASSIVE) { |
14a4dfe2 HS |
6404 | IPW_DEBUG_WX("use passive scanning\n"); |
6405 | scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN; | |
094c4d2d | 6406 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
14a4dfe2 | 6407 | cpu_to_le16(ipw_passive_dwell_time(priv)); |
094c4d2d ZY |
6408 | ipw_add_scan_channels(priv, &scan, scan_type); |
6409 | goto send_request; | |
6410 | } | |
6411 | ||
6412 | /* Use active scan by default. */ | |
14a4dfe2 | 6413 | if (priv->config & CFG_SPEED_SCAN) |
b095c381 | 6414 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = |
094c4d2d | 6415 | cpu_to_le16(30); |
b095c381 JK |
6416 | else |
6417 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | |
094c4d2d | 6418 | cpu_to_le16(20); |
b095c381 | 6419 | |
a613bffd | 6420 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
094c4d2d | 6421 | cpu_to_le16(20); |
43f66a6c | 6422 | |
14a4dfe2 HS |
6423 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
6424 | cpu_to_le16(ipw_passive_dwell_time(priv)); | |
ea177305 | 6425 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
43f66a6c | 6426 | |
b095c381 | 6427 | #ifdef CONFIG_IPW2200_MONITOR |
ea2b26e0 | 6428 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
afbf30a2 | 6429 | u8 channel; |
b095c381 | 6430 | u8 band = 0; |
43f66a6c | 6431 | |
b0a4e7d8 JL |
6432 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
6433 | case LIBIPW_52GHZ_BAND: | |
ea2b26e0 | 6434 | band = (u8) (IPW_A_MODE << 6) | 1; |
b095c381 JK |
6435 | channel = priv->channel; |
6436 | break; | |
ea2b26e0 | 6437 | |
b0a4e7d8 | 6438 | case LIBIPW_24GHZ_BAND: |
ea2b26e0 | 6439 | band = (u8) (IPW_B_MODE << 6) | 1; |
b095c381 JK |
6440 | channel = priv->channel; |
6441 | break; | |
ea2b26e0 | 6442 | |
b095c381 | 6443 | default: |
ea2b26e0 JK |
6444 | band = (u8) (IPW_B_MODE << 6) | 1; |
6445 | channel = 9; | |
b095c381 | 6446 | break; |
ea2b26e0 JK |
6447 | } |
6448 | ||
b095c381 JK |
6449 | scan.channels_list[0] = band; |
6450 | scan.channels_list[1] = channel; | |
6451 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); | |
ea2b26e0 | 6452 | |
b095c381 JK |
6453 | /* NOTE: The card will sit on this channel for this time |
6454 | * period. Scan aborts are timing sensitive and frequently | |
6455 | * result in firmware restarts. As such, it is best to | |
6456 | * set a small dwell_time here and just keep re-issuing | |
6457 | * scans. Otherwise fast channel hopping will not actually | |
6458 | * hop channels. | |
6459 | * | |
6460 | * TODO: Move SPEED SCAN support to all modes and bands */ | |
a613bffd | 6461 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
094c4d2d | 6462 | cpu_to_le16(2000); |
43f66a6c | 6463 | } else { |
b095c381 | 6464 | #endif /* CONFIG_IPW2200_MONITOR */ |
ea177305 DW |
6465 | /* Honor direct scans first, otherwise if we are roaming make |
6466 | * this a direct scan for the current network. Finally, | |
6467 | * ensure that every other scan is a fast channel hop scan */ | |
6468 | if (direct) { | |
6469 | err = ipw_send_ssid(priv, priv->direct_scan_ssid, | |
6470 | priv->direct_scan_ssid_len); | |
6471 | if (err) { | |
6472 | IPW_DEBUG_HC("Attempt to send SSID command " | |
6473 | "failed\n"); | |
6474 | goto done; | |
6475 | } | |
6476 | ||
6477 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; | |
6478 | } else if ((priv->status & STATUS_ROAMING) | |
6479 | || (!(priv->status & STATUS_ASSOCIATED) | |
6480 | && (priv->config & CFG_STATIC_ESSID) | |
6481 | && (le32_to_cpu(scan.full_scan_index) % 2))) { | |
ea2b26e0 JK |
6482 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
6483 | if (err) { | |
b095c381 JK |
6484 | IPW_DEBUG_HC("Attempt to send SSID command " |
6485 | "failed.\n"); | |
6486 | goto done; | |
ea2b26e0 | 6487 | } |
43f66a6c | 6488 | |
ea2b26e0 | 6489 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
afbf30a2 | 6490 | } else |
ea2b26e0 | 6491 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
ea2b26e0 | 6492 | |
afbf30a2 | 6493 | ipw_add_scan_channels(priv, &scan, scan_type); |
b095c381 | 6494 | #ifdef CONFIG_IPW2200_MONITOR |
43f66a6c | 6495 | } |
ea2b26e0 | 6496 | #endif |
bf79451e | 6497 | |
094c4d2d | 6498 | send_request: |
ea2b26e0 | 6499 | err = ipw_send_scan_request_ext(priv, &scan); |
43f66a6c | 6500 | if (err) { |
ea2b26e0 | 6501 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
b095c381 | 6502 | goto done; |
43f66a6c JK |
6503 | } |
6504 | ||
ea2b26e0 | 6505 | priv->status |= STATUS_SCANNING; |
ea177305 DW |
6506 | if (direct) { |
6507 | priv->status &= ~STATUS_DIRECT_SCAN_PENDING; | |
6508 | priv->direct_scan_ssid_len = 0; | |
6509 | } else | |
6510 | priv->status &= ~STATUS_SCAN_PENDING; | |
6511 | ||
afbf30a2 JK |
6512 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
6513 | IPW_SCAN_CHECK_WATCHDOG); | |
094c4d2d | 6514 | done: |
4644151b | 6515 | mutex_unlock(&priv->mutex); |
b095c381 | 6516 | return err; |
c848d0af JK |
6517 | } |
6518 | ||
c4028958 DH |
6519 | static void ipw_request_passive_scan(struct work_struct *work) |
6520 | { | |
6521 | struct ipw_priv *priv = | |
ea177305 DW |
6522 | container_of(work, struct ipw_priv, request_passive_scan.work); |
6523 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0); | |
094c4d2d ZY |
6524 | } |
6525 | ||
c4028958 DH |
6526 | static void ipw_request_scan(struct work_struct *work) |
6527 | { | |
6528 | struct ipw_priv *priv = | |
6529 | container_of(work, struct ipw_priv, request_scan.work); | |
ea177305 DW |
6530 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0); |
6531 | } | |
6532 | ||
6533 | static void ipw_request_direct_scan(struct work_struct *work) | |
6534 | { | |
6535 | struct ipw_priv *priv = | |
6536 | container_of(work, struct ipw_priv, request_direct_scan.work); | |
6537 | ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1); | |
094c4d2d ZY |
6538 | } |
6539 | ||
c4028958 | 6540 | static void ipw_bg_abort_scan(struct work_struct *work) |
c848d0af | 6541 | { |
c4028958 DH |
6542 | struct ipw_priv *priv = |
6543 | container_of(work, struct ipw_priv, abort_scan); | |
4644151b | 6544 | mutex_lock(&priv->mutex); |
c4028958 | 6545 | ipw_abort_scan(priv); |
4644151b | 6546 | mutex_unlock(&priv->mutex); |
c848d0af JK |
6547 | } |
6548 | ||
ea2b26e0 JK |
6549 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
6550 | { | |
b095c381 JK |
6551 | /* This is called when wpa_supplicant loads and closes the driver |
6552 | * interface. */ | |
cdd1fa1e | 6553 | priv->ieee->wpa_enabled = value; |
b095c381 | 6554 | return 0; |
ea2b26e0 JK |
6555 | } |
6556 | ||
ea2b26e0 JK |
6557 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
6558 | { | |
b0a4e7d8 JL |
6559 | struct libipw_device *ieee = priv->ieee; |
6560 | struct libipw_security sec = { | |
ea2b26e0 JK |
6561 | .flags = SEC_AUTH_MODE, |
6562 | }; | |
6563 | int ret = 0; | |
6564 | ||
afbf30a2 | 6565 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
ea2b26e0 JK |
6566 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
6567 | ieee->open_wep = 0; | |
afbf30a2 | 6568 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
ea2b26e0 JK |
6569 | sec.auth_mode = WLAN_AUTH_OPEN; |
6570 | ieee->open_wep = 1; | |
3e234b4e ZY |
6571 | } else if (value & IW_AUTH_ALG_LEAP) { |
6572 | sec.auth_mode = WLAN_AUTH_LEAP; | |
6573 | ieee->open_wep = 1; | |
afbf30a2 JK |
6574 | } else |
6575 | return -EINVAL; | |
ea2b26e0 JK |
6576 | |
6577 | if (ieee->set_security) | |
6578 | ieee->set_security(ieee->dev, &sec); | |
6579 | else | |
6580 | ret = -EOPNOTSUPP; | |
6581 | ||
6582 | return ret; | |
6583 | } | |
6584 | ||
a73e22b2 AB |
6585 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
6586 | int wpa_ie_len) | |
afbf30a2 JK |
6587 | { |
6588 | /* make sure WPA is enabled */ | |
6589 | ipw_wpa_enable(priv, 1); | |
afbf30a2 JK |
6590 | } |
6591 | ||
6592 | static int ipw_set_rsn_capa(struct ipw_priv *priv, | |
6593 | char *capabilities, int length) | |
6594 | { | |
afbf30a2 JK |
6595 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
6596 | ||
0a7bcf26 | 6597 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
2638bc39 | 6598 | capabilities); |
afbf30a2 JK |
6599 | } |
6600 | ||
b095c381 | 6601 | /* |
afbf30a2 JK |
6602 | * WE-18 support |
6603 | */ | |
6604 | ||
6605 | /* SIOCSIWGENIE */ | |
6606 | static int ipw_wx_set_genie(struct net_device *dev, | |
6607 | struct iw_request_info *info, | |
6608 | union iwreq_data *wrqu, char *extra) | |
ea2b26e0 | 6609 | { |
b0a4e7d8 JL |
6610 | struct ipw_priv *priv = libipw_priv(dev); |
6611 | struct libipw_device *ieee = priv->ieee; | |
afbf30a2 JK |
6612 | u8 *buf; |
6613 | int err = 0; | |
ea2b26e0 | 6614 | |
afbf30a2 JK |
6615 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
6616 | (wrqu->data.length && extra == NULL)) | |
6617 | return -EINVAL; | |
ea2b26e0 | 6618 | |
afbf30a2 JK |
6619 | if (wrqu->data.length) { |
6620 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); | |
6621 | if (buf == NULL) { | |
6622 | err = -ENOMEM; | |
6623 | goto out; | |
6624 | } | |
6625 | ||
6626 | memcpy(buf, extra, wrqu->data.length); | |
6627 | kfree(ieee->wpa_ie); | |
6628 | ieee->wpa_ie = buf; | |
6629 | ieee->wpa_ie_len = wrqu->data.length; | |
b095c381 | 6630 | } else { |
afbf30a2 JK |
6631 | kfree(ieee->wpa_ie); |
6632 | ieee->wpa_ie = NULL; | |
6633 | ieee->wpa_ie_len = 0; | |
ea2b26e0 | 6634 | } |
afbf30a2 JK |
6635 | |
6636 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); | |
6637 | out: | |
afbf30a2 JK |
6638 | return err; |
6639 | } | |
6640 | ||
6641 | /* SIOCGIWGENIE */ | |
6642 | static int ipw_wx_get_genie(struct net_device *dev, | |
6643 | struct iw_request_info *info, | |
6644 | union iwreq_data *wrqu, char *extra) | |
6645 | { | |
b0a4e7d8 JL |
6646 | struct ipw_priv *priv = libipw_priv(dev); |
6647 | struct libipw_device *ieee = priv->ieee; | |
afbf30a2 JK |
6648 | int err = 0; |
6649 | ||
afbf30a2 JK |
6650 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { |
6651 | wrqu->data.length = 0; | |
6652 | goto out; | |
6653 | } | |
6654 | ||
6655 | if (wrqu->data.length < ieee->wpa_ie_len) { | |
6656 | err = -E2BIG; | |
6657 | goto out; | |
6658 | } | |
6659 | ||
6660 | wrqu->data.length = ieee->wpa_ie_len; | |
6661 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); | |
6662 | ||
6663 | out: | |
afbf30a2 JK |
6664 | return err; |
6665 | } | |
6666 | ||
1fbfea54 ZY |
6667 | static int wext_cipher2level(int cipher) |
6668 | { | |
6669 | switch (cipher) { | |
6670 | case IW_AUTH_CIPHER_NONE: | |
6671 | return SEC_LEVEL_0; | |
6672 | case IW_AUTH_CIPHER_WEP40: | |
6673 | case IW_AUTH_CIPHER_WEP104: | |
6674 | return SEC_LEVEL_1; | |
6675 | case IW_AUTH_CIPHER_TKIP: | |
6676 | return SEC_LEVEL_2; | |
6677 | case IW_AUTH_CIPHER_CCMP: | |
6678 | return SEC_LEVEL_3; | |
6679 | default: | |
6680 | return -1; | |
6681 | } | |
6682 | } | |
6683 | ||
afbf30a2 JK |
6684 | /* SIOCSIWAUTH */ |
6685 | static int ipw_wx_set_auth(struct net_device *dev, | |
6686 | struct iw_request_info *info, | |
6687 | union iwreq_data *wrqu, char *extra) | |
6688 | { | |
b0a4e7d8 JL |
6689 | struct ipw_priv *priv = libipw_priv(dev); |
6690 | struct libipw_device *ieee = priv->ieee; | |
afbf30a2 | 6691 | struct iw_param *param = &wrqu->param; |
274bfb8d | 6692 | struct lib80211_crypt_data *crypt; |
afbf30a2 JK |
6693 | unsigned long flags; |
6694 | int ret = 0; | |
6695 | ||
6696 | switch (param->flags & IW_AUTH_INDEX) { | |
6697 | case IW_AUTH_WPA_VERSION: | |
1fbfea54 | 6698 | break; |
afbf30a2 | 6699 | case IW_AUTH_CIPHER_PAIRWISE: |
1fbfea54 ZY |
6700 | ipw_set_hw_decrypt_unicast(priv, |
6701 | wext_cipher2level(param->value)); | |
6702 | break; | |
afbf30a2 | 6703 | case IW_AUTH_CIPHER_GROUP: |
1fbfea54 ZY |
6704 | ipw_set_hw_decrypt_multicast(priv, |
6705 | wext_cipher2level(param->value)); | |
6706 | break; | |
afbf30a2 JK |
6707 | case IW_AUTH_KEY_MGMT: |
6708 | /* | |
6709 | * ipw2200 does not use these parameters | |
6710 | */ | |
6711 | break; | |
6712 | ||
6713 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
274bfb8d | 6714 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
991d1cc5 | 6715 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
afbf30a2 | 6716 | break; |
afbf30a2 JK |
6717 | |
6718 | flags = crypt->ops->get_flags(crypt->priv); | |
6719 | ||
6720 | if (param->value) | |
6721 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | |
6722 | else | |
6723 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | |
6724 | ||
6725 | crypt->ops->set_flags(flags, crypt->priv); | |
6726 | ||
6727 | break; | |
6728 | ||
6729 | case IW_AUTH_DROP_UNENCRYPTED:{ | |
6730 | /* HACK: | |
6731 | * | |
6732 | * wpa_supplicant calls set_wpa_enabled when the driver | |
6733 | * is loaded and unloaded, regardless of if WPA is being | |
6734 | * used. No other calls are made which can be used to | |
6735 | * determine if encryption will be used or not prior to | |
6736 | * association being expected. If encryption is not being | |
6737 | * used, drop_unencrypted is set to false, else true -- we | |
6738 | * can use this to determine if the CAP_PRIVACY_ON bit should | |
6739 | * be set. | |
6740 | */ | |
b0a4e7d8 | 6741 | struct libipw_security sec = { |
afbf30a2 JK |
6742 | .flags = SEC_ENABLED, |
6743 | .enabled = param->value, | |
6744 | }; | |
6745 | priv->ieee->drop_unencrypted = param->value; | |
6746 | /* We only change SEC_LEVEL for open mode. Others | |
6747 | * are set by ipw_wpa_set_encryption. | |
6748 | */ | |
6749 | if (!param->value) { | |
6750 | sec.flags |= SEC_LEVEL; | |
6751 | sec.level = SEC_LEVEL_0; | |
6752 | } else { | |
6753 | sec.flags |= SEC_LEVEL; | |
6754 | sec.level = SEC_LEVEL_1; | |
6755 | } | |
6756 | if (priv->ieee->set_security) | |
6757 | priv->ieee->set_security(priv->ieee->dev, &sec); | |
6758 | break; | |
6759 | } | |
6760 | ||
6761 | case IW_AUTH_80211_AUTH_ALG: | |
6762 | ret = ipw_wpa_set_auth_algs(priv, param->value); | |
6763 | break; | |
6764 | ||
6765 | case IW_AUTH_WPA_ENABLED: | |
6766 | ret = ipw_wpa_enable(priv, param->value); | |
e3c5a64e | 6767 | ipw_disassociate(priv); |
afbf30a2 JK |
6768 | break; |
6769 | ||
6770 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
6771 | ieee->ieee802_1x = param->value; | |
6772 | break; | |
6773 | ||
afbf30a2 JK |
6774 | case IW_AUTH_PRIVACY_INVOKED: |
6775 | ieee->privacy_invoked = param->value; | |
6776 | break; | |
6777 | ||
6778 | default: | |
6779 | return -EOPNOTSUPP; | |
6780 | } | |
6781 | return ret; | |
6782 | } | |
6783 | ||
6784 | /* SIOCGIWAUTH */ | |
6785 | static int ipw_wx_get_auth(struct net_device *dev, | |
6786 | struct iw_request_info *info, | |
6787 | union iwreq_data *wrqu, char *extra) | |
6788 | { | |
b0a4e7d8 JL |
6789 | struct ipw_priv *priv = libipw_priv(dev); |
6790 | struct libipw_device *ieee = priv->ieee; | |
274bfb8d | 6791 | struct lib80211_crypt_data *crypt; |
afbf30a2 JK |
6792 | struct iw_param *param = &wrqu->param; |
6793 | int ret = 0; | |
6794 | ||
6795 | switch (param->flags & IW_AUTH_INDEX) { | |
6796 | case IW_AUTH_WPA_VERSION: | |
6797 | case IW_AUTH_CIPHER_PAIRWISE: | |
6798 | case IW_AUTH_CIPHER_GROUP: | |
6799 | case IW_AUTH_KEY_MGMT: | |
6800 | /* | |
6801 | * wpa_supplicant will control these internally | |
6802 | */ | |
6803 | ret = -EOPNOTSUPP; | |
6804 | break; | |
6805 | ||
6806 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
274bfb8d | 6807 | crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx]; |
991d1cc5 | 6808 | if (!crypt || !crypt->ops->get_flags) |
afbf30a2 | 6809 | break; |
afbf30a2 JK |
6810 | |
6811 | param->value = (crypt->ops->get_flags(crypt->priv) & | |
6812 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; | |
6813 | ||
6814 | break; | |
6815 | ||
6816 | case IW_AUTH_DROP_UNENCRYPTED: | |
6817 | param->value = ieee->drop_unencrypted; | |
6818 | break; | |
6819 | ||
6820 | case IW_AUTH_80211_AUTH_ALG: | |
6821 | param->value = ieee->sec.auth_mode; | |
6822 | break; | |
6823 | ||
6824 | case IW_AUTH_WPA_ENABLED: | |
6825 | param->value = ieee->wpa_enabled; | |
6826 | break; | |
6827 | ||
6828 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
6829 | param->value = ieee->ieee802_1x; | |
6830 | break; | |
6831 | ||
6832 | case IW_AUTH_ROAMING_CONTROL: | |
6833 | case IW_AUTH_PRIVACY_INVOKED: | |
6834 | param->value = ieee->privacy_invoked; | |
6835 | break; | |
6836 | ||
6837 | default: | |
6838 | return -EOPNOTSUPP; | |
6839 | } | |
6840 | return 0; | |
6841 | } | |
6842 | ||
6843 | /* SIOCSIWENCODEEXT */ | |
6844 | static int ipw_wx_set_encodeext(struct net_device *dev, | |
6845 | struct iw_request_info *info, | |
6846 | union iwreq_data *wrqu, char *extra) | |
6847 | { | |
b0a4e7d8 | 6848 | struct ipw_priv *priv = libipw_priv(dev); |
afbf30a2 JK |
6849 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
6850 | ||
6851 | if (hwcrypto) { | |
afbf30a2 | 6852 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
567deaf6 HL |
6853 | /* IPW HW can't build TKIP MIC, |
6854 | host decryption still needed */ | |
6855 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) | |
6856 | priv->ieee->host_mc_decrypt = 1; | |
6857 | else { | |
6858 | priv->ieee->host_encrypt = 0; | |
6859 | priv->ieee->host_encrypt_msdu = 1; | |
6860 | priv->ieee->host_decrypt = 1; | |
6861 | } | |
afbf30a2 JK |
6862 | } else { |
6863 | priv->ieee->host_encrypt = 0; | |
6864 | priv->ieee->host_encrypt_msdu = 0; | |
6865 | priv->ieee->host_decrypt = 0; | |
567deaf6 | 6866 | priv->ieee->host_mc_decrypt = 0; |
afbf30a2 JK |
6867 | } |
6868 | } | |
6869 | ||
b0a4e7d8 | 6870 | return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra); |
afbf30a2 JK |
6871 | } |
6872 | ||
6873 | /* SIOCGIWENCODEEXT */ | |
6874 | static int ipw_wx_get_encodeext(struct net_device *dev, | |
6875 | struct iw_request_info *info, | |
6876 | union iwreq_data *wrqu, char *extra) | |
6877 | { | |
b0a4e7d8 JL |
6878 | struct ipw_priv *priv = libipw_priv(dev); |
6879 | return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra); | |
afbf30a2 JK |
6880 | } |
6881 | ||
6882 | /* SIOCSIWMLME */ | |
6883 | static int ipw_wx_set_mlme(struct net_device *dev, | |
6884 | struct iw_request_info *info, | |
6885 | union iwreq_data *wrqu, char *extra) | |
6886 | { | |
b0a4e7d8 | 6887 | struct ipw_priv *priv = libipw_priv(dev); |
afbf30a2 | 6888 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
e62e1ee0 | 6889 | __le16 reason; |
afbf30a2 JK |
6890 | |
6891 | reason = cpu_to_le16(mlme->reason_code); | |
6892 | ||
6893 | switch (mlme->cmd) { | |
6894 | case IW_MLME_DEAUTH: | |
67fd6b45 | 6895 | /* silently ignore */ |
afbf30a2 JK |
6896 | break; |
6897 | ||
6898 | case IW_MLME_DISASSOC: | |
6899 | ipw_disassociate(priv); | |
6900 | break; | |
6901 | ||
6902 | default: | |
6903 | return -EOPNOTSUPP; | |
6904 | } | |
6905 | return 0; | |
6906 | } | |
afbf30a2 | 6907 | |
e43e3c1e | 6908 | #ifdef CONFIG_IPW2200_QOS |
afbf30a2 JK |
6909 | |
6910 | /* QoS */ | |
6911 | /* | |
6912 | * get the modulation type of the current network or | |
6913 | * the card current mode | |
6914 | */ | |
53d0bcf8 | 6915 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
afbf30a2 JK |
6916 | { |
6917 | u8 mode = 0; | |
6918 | ||
6919 | if (priv->status & STATUS_ASSOCIATED) { | |
6920 | unsigned long flags; | |
6921 | ||
6922 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
6923 | mode = priv->assoc_network->mode; | |
6924 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
6925 | } else { | |
6926 | mode = priv->ieee->mode; | |
6927 | } | |
6928 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); | |
6929 | return mode; | |
b095c381 | 6930 | } |
ea2b26e0 | 6931 | |
b095c381 JK |
6932 | /* |
6933 | * Handle management frame beacon and probe response | |
6934 | */ | |
3b9990cb JK |
6935 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
6936 | int active_network, | |
b0a4e7d8 | 6937 | struct libipw_network *network) |
b095c381 | 6938 | { |
b0a4e7d8 | 6939 | u32 size = sizeof(struct libipw_qos_parameters); |
b095c381 | 6940 | |
afbf30a2 | 6941 | if (network->capability & WLAN_CAPABILITY_IBSS) |
b095c381 JK |
6942 | network->qos_data.active = network->qos_data.supported; |
6943 | ||
6944 | if (network->flags & NETWORK_HAS_QOS_MASK) { | |
afbf30a2 JK |
6945 | if (active_network && |
6946 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) | |
b095c381 JK |
6947 | network->qos_data.active = network->qos_data.supported; |
6948 | ||
6949 | if ((network->qos_data.active == 1) && (active_network == 1) && | |
6950 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && | |
6951 | (network->qos_data.old_param_count != | |
6952 | network->qos_data.param_count)) { | |
6953 | network->qos_data.old_param_count = | |
6954 | network->qos_data.param_count; | |
6955 | schedule_work(&priv->qos_activate); | |
afbf30a2 JK |
6956 | IPW_DEBUG_QOS("QoS parameters change call " |
6957 | "qos_activate\n"); | |
b095c381 | 6958 | } |
ea2b26e0 | 6959 | } else { |
afbf30a2 JK |
6960 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
6961 | memcpy(&network->qos_data.parameters, | |
b095c381 | 6962 | &def_parameters_CCK, size); |
afbf30a2 JK |
6963 | else |
6964 | memcpy(&network->qos_data.parameters, | |
b095c381 | 6965 | &def_parameters_OFDM, size); |
afbf30a2 | 6966 | |
b095c381 JK |
6967 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
6968 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); | |
6969 | schedule_work(&priv->qos_activate); | |
6970 | } | |
6971 | ||
6972 | network->qos_data.active = 0; | |
6973 | network->qos_data.supported = 0; | |
ea2b26e0 | 6974 | } |
afbf30a2 JK |
6975 | if ((priv->status & STATUS_ASSOCIATED) && |
6976 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { | |
6977 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) | |
c5d3dce8 | 6978 | if (network->capability & WLAN_CAPABILITY_IBSS) |
b095c381 | 6979 | if ((network->ssid_len == |
afbf30a2 JK |
6980 | priv->assoc_network->ssid_len) && |
6981 | !memcmp(network->ssid, | |
6982 | priv->assoc_network->ssid, | |
6983 | network->ssid_len)) { | |
b095c381 JK |
6984 | queue_work(priv->workqueue, |
6985 | &priv->merge_networks); | |
6986 | } | |
b095c381 | 6987 | } |
ea2b26e0 | 6988 | |
b095c381 JK |
6989 | return 0; |
6990 | } | |
6991 | ||
6992 | /* | |
6993 | * This function set up the firmware to support QoS. It sends | |
6994 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO | |
6995 | */ | |
6996 | static int ipw_qos_activate(struct ipw_priv *priv, | |
b0a4e7d8 | 6997 | struct libipw_qos_data *qos_network_data) |
b095c381 JK |
6998 | { |
6999 | int err; | |
b0a4e7d8 JL |
7000 | struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS]; |
7001 | struct libipw_qos_parameters *active_one = NULL; | |
7002 | u32 size = sizeof(struct libipw_qos_parameters); | |
b095c381 JK |
7003 | u32 burst_duration; |
7004 | int i; | |
7005 | u8 type; | |
7006 | ||
7007 | type = ipw_qos_current_mode(priv); | |
7008 | ||
7009 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); | |
7010 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); | |
7011 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); | |
7012 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); | |
7013 | ||
7014 | if (qos_network_data == NULL) { | |
7015 | if (type == IEEE_B) { | |
7016 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); | |
7017 | active_one = &def_parameters_CCK; | |
7018 | } else | |
7019 | active_one = &def_parameters_OFDM; | |
7020 | ||
afbf30a2 | 7021 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
b095c381 JK |
7022 | burst_duration = ipw_qos_get_burst_duration(priv); |
7023 | for (i = 0; i < QOS_QUEUE_NUM; i++) | |
afbf30a2 | 7024 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
8fffc15d | 7025 | cpu_to_le16(burst_duration); |
afbf30a2 | 7026 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
b095c381 JK |
7027 | if (type == IEEE_B) { |
7028 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", | |
7029 | type); | |
7030 | if (priv->qos_data.qos_enable == 0) | |
7031 | active_one = &def_parameters_CCK; | |
7032 | else | |
7033 | active_one = priv->qos_data.def_qos_parm_CCK; | |
7034 | } else { | |
7035 | if (priv->qos_data.qos_enable == 0) | |
7036 | active_one = &def_parameters_OFDM; | |
7037 | else | |
7038 | active_one = priv->qos_data.def_qos_parm_OFDM; | |
7039 | } | |
afbf30a2 | 7040 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
b095c381 JK |
7041 | } else { |
7042 | unsigned long flags; | |
7043 | int active; | |
7044 | ||
7045 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
7046 | active_one = &(qos_network_data->parameters); | |
7047 | qos_network_data->old_param_count = | |
7048 | qos_network_data->param_count; | |
afbf30a2 | 7049 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
b095c381 JK |
7050 | active = qos_network_data->supported; |
7051 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
7052 | ||
7053 | if (active == 0) { | |
7054 | burst_duration = ipw_qos_get_burst_duration(priv); | |
7055 | for (i = 0; i < QOS_QUEUE_NUM; i++) | |
7056 | qos_parameters[QOS_PARAM_SET_ACTIVE]. | |
8fffc15d | 7057 | tx_op_limit[i] = cpu_to_le16(burst_duration); |
b095c381 JK |
7058 | } |
7059 | } | |
7060 | ||
7061 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); | |
afbf30a2 | 7062 | err = ipw_send_qos_params_command(priv, |
b0a4e7d8 | 7063 | (struct libipw_qos_parameters *) |
afbf30a2 | 7064 | &(qos_parameters[0])); |
b095c381 JK |
7065 | if (err) |
7066 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); | |
7067 | ||
7068 | return err; | |
7069 | } | |
7070 | ||
7071 | /* | |
7072 | * send IPW_CMD_WME_INFO to the firmware | |
7073 | */ | |
7074 | static int ipw_qos_set_info_element(struct ipw_priv *priv) | |
7075 | { | |
7076 | int ret = 0; | |
b0a4e7d8 | 7077 | struct libipw_qos_information_element qos_info; |
b095c381 JK |
7078 | |
7079 | if (priv == NULL) | |
7080 | return -1; | |
7081 | ||
7082 | qos_info.elementID = QOS_ELEMENT_ID; | |
b0a4e7d8 | 7083 | qos_info.length = sizeof(struct libipw_qos_information_element) - 2; |
b095c381 JK |
7084 | |
7085 | qos_info.version = QOS_VERSION_1; | |
7086 | qos_info.ac_info = 0; | |
7087 | ||
7088 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); | |
7089 | qos_info.qui_type = QOS_OUI_TYPE; | |
7090 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; | |
7091 | ||
7092 | ret = ipw_send_qos_info_command(priv, &qos_info); | |
7093 | if (ret != 0) { | |
7094 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); | |
7095 | } | |
7096 | return ret; | |
7097 | } | |
7098 | ||
7099 | /* | |
7100 | * Set the QoS parameter with the association request structure | |
7101 | */ | |
7102 | static int ipw_qos_association(struct ipw_priv *priv, | |
b0a4e7d8 | 7103 | struct libipw_network *network) |
b095c381 JK |
7104 | { |
7105 | int err = 0; | |
b0a4e7d8 JL |
7106 | struct libipw_qos_data *qos_data = NULL; |
7107 | struct libipw_qos_data ibss_data = { | |
b095c381 JK |
7108 | .supported = 1, |
7109 | .active = 1, | |
7110 | }; | |
7111 | ||
7112 | switch (priv->ieee->iw_mode) { | |
7113 | case IW_MODE_ADHOC: | |
5d9428de | 7114 | BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS)); |
b095c381 JK |
7115 | |
7116 | qos_data = &ibss_data; | |
7117 | break; | |
7118 | ||
7119 | case IW_MODE_INFRA: | |
7120 | qos_data = &network->qos_data; | |
7121 | break; | |
7122 | ||
7123 | default: | |
7124 | BUG(); | |
7125 | break; | |
7126 | } | |
7127 | ||
7128 | err = ipw_qos_activate(priv, qos_data); | |
7129 | if (err) { | |
7130 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; | |
7131 | return err; | |
7132 | } | |
7133 | ||
7134 | if (priv->qos_data.qos_enable && qos_data->supported) { | |
7135 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); | |
7136 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; | |
7137 | return ipw_qos_set_info_element(priv); | |
7138 | } | |
7139 | ||
7140 | return 0; | |
7141 | } | |
7142 | ||
7143 | /* | |
0779bf2d ML |
7144 | * handling the beaconing responses. if we get different QoS setting |
7145 | * off the network from the associated setting, adjust the QoS | |
b095c381 JK |
7146 | * setting |
7147 | */ | |
7148 | static int ipw_qos_association_resp(struct ipw_priv *priv, | |
b0a4e7d8 | 7149 | struct libipw_network *network) |
b095c381 JK |
7150 | { |
7151 | int ret = 0; | |
7152 | unsigned long flags; | |
b0a4e7d8 | 7153 | u32 size = sizeof(struct libipw_qos_parameters); |
b095c381 JK |
7154 | int set_qos_param = 0; |
7155 | ||
afbf30a2 JK |
7156 | if ((priv == NULL) || (network == NULL) || |
7157 | (priv->assoc_network == NULL)) | |
b095c381 JK |
7158 | return ret; |
7159 | ||
7160 | if (!(priv->status & STATUS_ASSOCIATED)) | |
7161 | return ret; | |
7162 | ||
afbf30a2 | 7163 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
b095c381 | 7164 | return ret; |
b095c381 JK |
7165 | |
7166 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
7167 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { | |
afbf30a2 | 7168 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
b0a4e7d8 | 7169 | sizeof(struct libipw_qos_data)); |
b095c381 JK |
7170 | priv->assoc_network->qos_data.active = 1; |
7171 | if ((network->qos_data.old_param_count != | |
7172 | network->qos_data.param_count)) { | |
7173 | set_qos_param = 1; | |
7174 | network->qos_data.old_param_count = | |
7175 | network->qos_data.param_count; | |
7176 | } | |
7177 | ||
7178 | } else { | |
afbf30a2 JK |
7179 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
7180 | memcpy(&priv->assoc_network->qos_data.parameters, | |
b095c381 | 7181 | &def_parameters_CCK, size); |
afbf30a2 JK |
7182 | else |
7183 | memcpy(&priv->assoc_network->qos_data.parameters, | |
b095c381 | 7184 | &def_parameters_OFDM, size); |
b095c381 JK |
7185 | priv->assoc_network->qos_data.active = 0; |
7186 | priv->assoc_network->qos_data.supported = 0; | |
7187 | set_qos_param = 1; | |
7188 | } | |
7189 | ||
7190 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
7191 | ||
7192 | if (set_qos_param == 1) | |
7193 | schedule_work(&priv->qos_activate); | |
7194 | ||
7195 | return ret; | |
7196 | } | |
7197 | ||
7198 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) | |
7199 | { | |
7200 | u32 ret = 0; | |
7201 | ||
7202 | if ((priv == NULL)) | |
7203 | return 0; | |
7204 | ||
b0a4e7d8 | 7205 | if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION)) |
b095c381 | 7206 | ret = priv->qos_data.burst_duration_CCK; |
afbf30a2 | 7207 | else |
b095c381 | 7208 | ret = priv->qos_data.burst_duration_OFDM; |
afbf30a2 | 7209 | |
b095c381 JK |
7210 | return ret; |
7211 | } | |
7212 | ||
7213 | /* | |
7214 | * Initialize the setting of QoS global | |
7215 | */ | |
7216 | static void ipw_qos_init(struct ipw_priv *priv, int enable, | |
7217 | int burst_enable, u32 burst_duration_CCK, | |
7218 | u32 burst_duration_OFDM) | |
7219 | { | |
7220 | priv->qos_data.qos_enable = enable; | |
7221 | ||
7222 | if (priv->qos_data.qos_enable) { | |
7223 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; | |
7224 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; | |
7225 | IPW_DEBUG_QOS("QoS is enabled\n"); | |
7226 | } else { | |
7227 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; | |
7228 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; | |
7229 | IPW_DEBUG_QOS("QoS is not enabled\n"); | |
7230 | } | |
7231 | ||
7232 | priv->qos_data.burst_enable = burst_enable; | |
7233 | ||
7234 | if (burst_enable) { | |
7235 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; | |
7236 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; | |
7237 | } else { | |
7238 | priv->qos_data.burst_duration_CCK = 0; | |
7239 | priv->qos_data.burst_duration_OFDM = 0; | |
7240 | } | |
7241 | } | |
7242 | ||
7243 | /* | |
7244 | * map the packet priority to the right TX Queue | |
7245 | */ | |
7246 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) | |
7247 | { | |
7248 | if (priority > 7 || !priv->qos_data.qos_enable) | |
7249 | priority = 0; | |
7250 | ||
7251 | return from_priority_to_tx_queue[priority] - 1; | |
7252 | } | |
7253 | ||
a5cf4fe6 ZY |
7254 | static int ipw_is_qos_active(struct net_device *dev, |
7255 | struct sk_buff *skb) | |
b095c381 | 7256 | { |
b0a4e7d8 JL |
7257 | struct ipw_priv *priv = libipw_priv(dev); |
7258 | struct libipw_qos_data *qos_data = NULL; | |
b095c381 | 7259 | int active, supported; |
a5cf4fe6 ZY |
7260 | u8 *daddr = skb->data + ETH_ALEN; |
7261 | int unicast = !is_multicast_ether_addr(daddr); | |
b095c381 JK |
7262 | |
7263 | if (!(priv->status & STATUS_ASSOCIATED)) | |
7264 | return 0; | |
7265 | ||
7266 | qos_data = &priv->assoc_network->qos_data; | |
7267 | ||
b095c381 JK |
7268 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
7269 | if (unicast == 0) | |
7270 | qos_data->active = 0; | |
7271 | else | |
7272 | qos_data->active = qos_data->supported; | |
7273 | } | |
b095c381 JK |
7274 | active = qos_data->active; |
7275 | supported = qos_data->supported; | |
afbf30a2 JK |
7276 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
7277 | "unicast %d\n", | |
7278 | priv->qos_data.qos_enable, active, supported, unicast); | |
a5cf4fe6 ZY |
7279 | if (active && priv->qos_data.qos_enable) |
7280 | return 1; | |
b095c381 | 7281 | |
a5cf4fe6 ZY |
7282 | return 0; |
7283 | ||
7284 | } | |
7285 | /* | |
7286 | * add QoS parameter to the TX command | |
7287 | */ | |
7288 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, | |
7289 | u16 priority, | |
7290 | struct tfd_data *tfd) | |
7291 | { | |
7292 | int tx_queue_id = 0; | |
7293 | ||
7294 | ||
7295 | tx_queue_id = from_priority_to_tx_queue[priority] - 1; | |
7296 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; | |
7297 | ||
7298 | if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) { | |
7299 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; | |
851ca268 | 7300 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK); |
a5cf4fe6 ZY |
7301 | } |
7302 | return 0; | |
b095c381 JK |
7303 | } |
7304 | ||
7305 | /* | |
7306 | * background support to run QoS activate functionality | |
7307 | */ | |
c4028958 | 7308 | static void ipw_bg_qos_activate(struct work_struct *work) |
b095c381 | 7309 | { |
c4028958 DH |
7310 | struct ipw_priv *priv = |
7311 | container_of(work, struct ipw_priv, qos_activate); | |
b095c381 | 7312 | |
4644151b | 7313 | mutex_lock(&priv->mutex); |
b095c381 JK |
7314 | |
7315 | if (priv->status & STATUS_ASSOCIATED) | |
7316 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); | |
7317 | ||
4644151b | 7318 | mutex_unlock(&priv->mutex); |
b095c381 JK |
7319 | } |
7320 | ||
3b9990cb | 7321 | static int ipw_handle_probe_response(struct net_device *dev, |
b0a4e7d8 JL |
7322 | struct libipw_probe_response *resp, |
7323 | struct libipw_network *network) | |
b095c381 | 7324 | { |
b0a4e7d8 | 7325 | struct ipw_priv *priv = libipw_priv(dev); |
3b9990cb JK |
7326 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
7327 | (network == priv->assoc_network)); | |
43f66a6c | 7328 | |
3b9990cb | 7329 | ipw_qos_handle_probe_response(priv, active_network, network); |
43f66a6c | 7330 | |
3b9990cb JK |
7331 | return 0; |
7332 | } | |
43f66a6c | 7333 | |
3b9990cb | 7334 | static int ipw_handle_beacon(struct net_device *dev, |
b0a4e7d8 JL |
7335 | struct libipw_beacon *resp, |
7336 | struct libipw_network *network) | |
3b9990cb | 7337 | { |
b0a4e7d8 | 7338 | struct ipw_priv *priv = libipw_priv(dev); |
3b9990cb JK |
7339 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
7340 | (network == priv->assoc_network)); | |
bf79451e | 7341 | |
3b9990cb | 7342 | ipw_qos_handle_probe_response(priv, active_network, network); |
bf79451e | 7343 | |
b095c381 JK |
7344 | return 0; |
7345 | } | |
bf79451e | 7346 | |
3b9990cb | 7347 | static int ipw_handle_assoc_response(struct net_device *dev, |
b0a4e7d8 JL |
7348 | struct libipw_assoc_response *resp, |
7349 | struct libipw_network *network) | |
3b9990cb | 7350 | { |
b0a4e7d8 | 7351 | struct ipw_priv *priv = libipw_priv(dev); |
3b9990cb JK |
7352 | ipw_qos_association_resp(priv, network); |
7353 | return 0; | |
7354 | } | |
43f66a6c | 7355 | |
b0a4e7d8 | 7356 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters |
b095c381 JK |
7357 | *qos_param) |
7358 | { | |
4e22699f ZY |
7359 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
7360 | sizeof(*qos_param) * 3, qos_param); | |
b095c381 JK |
7361 | } |
7362 | ||
b0a4e7d8 | 7363 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element |
b095c381 JK |
7364 | *qos_param) |
7365 | { | |
4e22699f ZY |
7366 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
7367 | qos_param); | |
43f66a6c JK |
7368 | } |
7369 | ||
e43e3c1e | 7370 | #endif /* CONFIG_IPW2200_QOS */ |
b095c381 | 7371 | |
43f66a6c | 7372 | static int ipw_associate_network(struct ipw_priv *priv, |
b0a4e7d8 | 7373 | struct libipw_network *network, |
0edd5b44 | 7374 | struct ipw_supported_rates *rates, int roaming) |
43f66a6c JK |
7375 | { |
7376 | int err; | |
9387b7ca | 7377 | DECLARE_SSID_BUF(ssid); |
43f66a6c JK |
7378 | |
7379 | if (priv->config & CFG_FIXED_RATE) | |
b095c381 | 7380 | ipw_set_fixed_rate(priv, network->mode); |
43f66a6c JK |
7381 | |
7382 | if (!(priv->config & CFG_STATIC_ESSID)) { | |
bf79451e | 7383 | priv->essid_len = min(network->ssid_len, |
0edd5b44 | 7384 | (u8) IW_ESSID_MAX_SIZE); |
43f66a6c JK |
7385 | memcpy(priv->essid, network->ssid, priv->essid_len); |
7386 | } | |
7387 | ||
7388 | network->last_associate = jiffies; | |
7389 | ||
7390 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); | |
7391 | priv->assoc_request.channel = network->channel; | |
3e234b4e ZY |
7392 | priv->assoc_request.auth_key = 0; |
7393 | ||
43f66a6c | 7394 | if ((priv->capability & CAP_PRIVACY_ON) && |
3e234b4e | 7395 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
43f66a6c | 7396 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
b095c381 JK |
7397 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
7398 | ||
1ba61e05 | 7399 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
b095c381 | 7400 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
3e234b4e ZY |
7401 | |
7402 | } else if ((priv->capability & CAP_PRIVACY_ON) && | |
7403 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) | |
7404 | priv->assoc_request.auth_type = AUTH_LEAP; | |
7405 | else | |
43f66a6c | 7406 | priv->assoc_request.auth_type = AUTH_OPEN; |
43f66a6c | 7407 | |
b095c381 | 7408 | if (priv->ieee->wpa_ie_len) { |
5b5e807f | 7409 | priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */ |
ea2b26e0 JK |
7410 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, |
7411 | priv->ieee->wpa_ie_len); | |
7412 | } | |
43f66a6c | 7413 | |
bf79451e JG |
7414 | /* |
7415 | * It is valid for our ieee device to support multiple modes, but | |
7416 | * when it comes to associating to a given network we have to choose | |
43f66a6c JK |
7417 | * just one mode. |
7418 | */ | |
7419 | if (network->mode & priv->ieee->mode & IEEE_A) | |
7420 | priv->assoc_request.ieee_mode = IPW_A_MODE; | |
7421 | else if (network->mode & priv->ieee->mode & IEEE_G) | |
7422 | priv->assoc_request.ieee_mode = IPW_G_MODE; | |
7423 | else if (network->mode & priv->ieee->mode & IEEE_B) | |
7424 | priv->assoc_request.ieee_mode = IPW_B_MODE; | |
7425 | ||
5b5e807f | 7426 | priv->assoc_request.capability = cpu_to_le16(network->capability); |
ea2b26e0 JK |
7427 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
7428 | && !(priv->config & CFG_PREAMBLE_LONG)) { | |
7429 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; | |
7430 | } else { | |
7431 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; | |
7432 | ||
7433 | /* Clear the short preamble if we won't be supporting it */ | |
7434 | priv->assoc_request.capability &= | |
5b5e807f | 7435 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); |
ea2b26e0 JK |
7436 | } |
7437 | ||
afbf30a2 JK |
7438 | /* Clear capability bits that aren't used in Ad Hoc */ |
7439 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | |
7440 | priv->assoc_request.capability &= | |
5b5e807f | 7441 | ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); |
afbf30a2 | 7442 | |
43f66a6c | 7443 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
ea2b26e0 | 7444 | "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n", |
43f66a6c | 7445 | roaming ? "Rea" : "A", |
9387b7ca | 7446 | print_ssid(ssid, priv->essid, priv->essid_len), |
bf79451e JG |
7447 | network->channel, |
7448 | ipw_modes[priv->assoc_request.ieee_mode], | |
7449 | rates->num_rates, | |
ea2b26e0 JK |
7450 | (priv->assoc_request.preamble_length == |
7451 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", | |
7452 | network->capability & | |
7453 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", | |
43f66a6c | 7454 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
bf79451e JG |
7455 | priv->capability & CAP_PRIVACY_ON ? |
7456 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : | |
43f66a6c JK |
7457 | "(open)") : "", |
7458 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", | |
bf79451e | 7459 | priv->capability & CAP_PRIVACY_ON ? |
b095c381 | 7460 | '1' + priv->ieee->sec.active_key : '.', |
0edd5b44 | 7461 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
43f66a6c | 7462 | |
5b5e807f | 7463 | priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval); |
43f66a6c | 7464 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && |
0edd5b44 | 7465 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
43f66a6c JK |
7466 | priv->assoc_request.assoc_type = HC_IBSS_START; |
7467 | priv->assoc_request.assoc_tsf_msw = 0; | |
7468 | priv->assoc_request.assoc_tsf_lsw = 0; | |
7469 | } else { | |
7470 | if (unlikely(roaming)) | |
7471 | priv->assoc_request.assoc_type = HC_REASSOCIATE; | |
7472 | else | |
7473 | priv->assoc_request.assoc_type = HC_ASSOCIATE; | |
5b5e807f AV |
7474 | priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]); |
7475 | priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]); | |
43f66a6c JK |
7476 | } |
7477 | ||
afbf30a2 | 7478 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
43f66a6c JK |
7479 | |
7480 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
7481 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); | |
5b5e807f | 7482 | priv->assoc_request.atim_window = cpu_to_le16(network->atim_window); |
43f66a6c | 7483 | } else { |
afbf30a2 | 7484 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
43f66a6c JK |
7485 | priv->assoc_request.atim_window = 0; |
7486 | } | |
7487 | ||
5b5e807f | 7488 | priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval); |
bf79451e | 7489 | |
43f66a6c JK |
7490 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
7491 | if (err) { | |
7492 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); | |
7493 | return err; | |
7494 | } | |
7495 | ||
7496 | rates->ieee_mode = priv->assoc_request.ieee_mode; | |
7497 | rates->purpose = IPW_RATE_CONNECT; | |
7498 | ipw_send_supported_rates(priv, rates); | |
bf79451e | 7499 | |
43f66a6c JK |
7500 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
7501 | priv->sys_config.dot11g_auto_detection = 1; | |
7502 | else | |
7503 | priv->sys_config.dot11g_auto_detection = 0; | |
c848d0af JK |
7504 | |
7505 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | |
7506 | priv->sys_config.answer_broadcast_ssid_probe = 1; | |
7507 | else | |
7508 | priv->sys_config.answer_broadcast_ssid_probe = 0; | |
7509 | ||
d685b8c2 | 7510 | err = ipw_send_system_config(priv); |
43f66a6c JK |
7511 | if (err) { |
7512 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); | |
7513 | return err; | |
7514 | } | |
bf79451e | 7515 | |
43f66a6c | 7516 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
ea2b26e0 | 7517 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
43f66a6c JK |
7518 | if (err) { |
7519 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); | |
7520 | return err; | |
7521 | } | |
7522 | ||
7523 | /* | |
7524 | * If preemption is enabled, it is possible for the association | |
7525 | * to complete before we return from ipw_send_associate. Therefore | |
7526 | * we have to be sure and update our priviate data first. | |
7527 | */ | |
7528 | priv->channel = network->channel; | |
7529 | memcpy(priv->bssid, network->bssid, ETH_ALEN); | |
bf79451e | 7530 | priv->status |= STATUS_ASSOCIATING; |
43f66a6c JK |
7531 | priv->status &= ~STATUS_SECURITY_UPDATED; |
7532 | ||
7533 | priv->assoc_network = network; | |
7534 | ||
e43e3c1e | 7535 | #ifdef CONFIG_IPW2200_QOS |
b095c381 JK |
7536 | ipw_qos_association(priv, network); |
7537 | #endif | |
7538 | ||
43f66a6c JK |
7539 | err = ipw_send_associate(priv, &priv->assoc_request); |
7540 | if (err) { | |
7541 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); | |
7542 | return err; | |
7543 | } | |
bf79451e | 7544 | |
e174961c | 7545 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n", |
9387b7ca | 7546 | print_ssid(ssid, priv->essid, priv->essid_len), |
e174961c | 7547 | priv->bssid); |
43f66a6c JK |
7548 | |
7549 | return 0; | |
7550 | } | |
7551 | ||
7552 | static void ipw_roam(void *data) | |
7553 | { | |
7554 | struct ipw_priv *priv = data; | |
b0a4e7d8 | 7555 | struct libipw_network *network = NULL; |
43f66a6c JK |
7556 | struct ipw_network_match match = { |
7557 | .network = priv->assoc_network | |
7558 | }; | |
7559 | ||
7560 | /* The roaming process is as follows: | |
bf79451e JG |
7561 | * |
7562 | * 1. Missed beacon threshold triggers the roaming process by | |
43f66a6c JK |
7563 | * setting the status ROAM bit and requesting a scan. |
7564 | * 2. When the scan completes, it schedules the ROAM work | |
7565 | * 3. The ROAM work looks at all of the known networks for one that | |
7566 | * is a better network than the currently associated. If none | |
7567 | * found, the ROAM process is over (ROAM bit cleared) | |
7568 | * 4. If a better network is found, a disassociation request is | |
7569 | * sent. | |
7570 | * 5. When the disassociation completes, the roam work is again | |
7571 | * scheduled. The second time through, the driver is no longer | |
7572 | * associated, and the newly selected network is sent an | |
bf79451e | 7573 | * association request. |
43f66a6c JK |
7574 | * 6. At this point ,the roaming process is complete and the ROAM |
7575 | * status bit is cleared. | |
7576 | */ | |
7577 | ||
7578 | /* If we are no longer associated, and the roaming bit is no longer | |
7579 | * set, then we are not actively roaming, so just return */ | |
7580 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) | |
7581 | return; | |
bf79451e | 7582 | |
43f66a6c | 7583 | if (priv->status & STATUS_ASSOCIATED) { |
bf79451e | 7584 | /* First pass through ROAM process -- look for a better |
43f66a6c | 7585 | * network */ |
a613bffd | 7586 | unsigned long flags; |
43f66a6c JK |
7587 | u8 rssi = priv->assoc_network->stats.rssi; |
7588 | priv->assoc_network->stats.rssi = -128; | |
a613bffd | 7589 | spin_lock_irqsave(&priv->ieee->lock, flags); |
43f66a6c JK |
7590 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
7591 | if (network != priv->assoc_network) | |
7592 | ipw_best_network(priv, &match, network, 1); | |
7593 | } | |
a613bffd | 7594 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
43f66a6c | 7595 | priv->assoc_network->stats.rssi = rssi; |
bf79451e | 7596 | |
43f66a6c JK |
7597 | if (match.network == priv->assoc_network) { |
7598 | IPW_DEBUG_ASSOC("No better APs in this network to " | |
7599 | "roam to.\n"); | |
7600 | priv->status &= ~STATUS_ROAMING; | |
7601 | ipw_debug_config(priv); | |
7602 | return; | |
7603 | } | |
bf79451e | 7604 | |
43f66a6c JK |
7605 | ipw_send_disassociate(priv, 1); |
7606 | priv->assoc_network = match.network; | |
7607 | ||
7608 | return; | |
bf79451e | 7609 | } |
43f66a6c JK |
7610 | |
7611 | /* Second pass through ROAM process -- request association */ | |
7612 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); | |
7613 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); | |
7614 | priv->status &= ~STATUS_ROAMING; | |
7615 | } | |
7616 | ||
c4028958 | 7617 | static void ipw_bg_roam(struct work_struct *work) |
c848d0af | 7618 | { |
c4028958 DH |
7619 | struct ipw_priv *priv = |
7620 | container_of(work, struct ipw_priv, roam); | |
4644151b | 7621 | mutex_lock(&priv->mutex); |
c4028958 | 7622 | ipw_roam(priv); |
4644151b | 7623 | mutex_unlock(&priv->mutex); |
c848d0af JK |
7624 | } |
7625 | ||
7626 | static int ipw_associate(void *data) | |
43f66a6c JK |
7627 | { |
7628 | struct ipw_priv *priv = data; | |
7629 | ||
b0a4e7d8 | 7630 | struct libipw_network *network = NULL; |
43f66a6c JK |
7631 | struct ipw_network_match match = { |
7632 | .network = NULL | |
7633 | }; | |
7634 | struct ipw_supported_rates *rates; | |
7635 | struct list_head *element; | |
a613bffd | 7636 | unsigned long flags; |
9387b7ca | 7637 | DECLARE_SSID_BUF(ssid); |
43f66a6c | 7638 | |
b095c381 JK |
7639 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
7640 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); | |
7641 | return 0; | |
7642 | } | |
7643 | ||
c848d0af | 7644 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
afbf30a2 JK |
7645 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
7646 | "progress)\n"); | |
c848d0af JK |
7647 | return 0; |
7648 | } | |
7649 | ||
e6324726 HL |
7650 | if (priv->status & STATUS_DISASSOCIATING) { |
7651 | IPW_DEBUG_ASSOC("Not attempting association (in " | |
7652 | "disassociating)\n "); | |
7653 | queue_work(priv->workqueue, &priv->associate); | |
7654 | return 0; | |
7655 | } | |
7656 | ||
c848d0af | 7657 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
afbf30a2 JK |
7658 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
7659 | "initialized)\n"); | |
c848d0af JK |
7660 | return 0; |
7661 | } | |
43f66a6c JK |
7662 | |
7663 | if (!(priv->config & CFG_ASSOCIATE) && | |
3e4127fa | 7664 | !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) { |
43f66a6c | 7665 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
c848d0af | 7666 | return 0; |
43f66a6c JK |
7667 | } |
7668 | ||
a613bffd JK |
7669 | /* Protect our use of the network_list */ |
7670 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
bf79451e | 7671 | list_for_each_entry(network, &priv->ieee->network_list, list) |
0edd5b44 | 7672 | ipw_best_network(priv, &match, network, 0); |
43f66a6c JK |
7673 | |
7674 | network = match.network; | |
7675 | rates = &match.rates; | |
7676 | ||
7677 | if (network == NULL && | |
7678 | priv->ieee->iw_mode == IW_MODE_ADHOC && | |
7679 | priv->config & CFG_ADHOC_CREATE && | |
7680 | priv->config & CFG_STATIC_ESSID && | |
a6d4eae8 DW |
7681 | priv->config & CFG_STATIC_CHANNEL) { |
7682 | /* Use oldest network if the free list is empty */ | |
7683 | if (list_empty(&priv->ieee->network_free_list)) { | |
b0a4e7d8 JL |
7684 | struct libipw_network *oldest = NULL; |
7685 | struct libipw_network *target; | |
a6d4eae8 DW |
7686 | |
7687 | list_for_each_entry(target, &priv->ieee->network_list, list) { | |
7688 | if ((oldest == NULL) || | |
7689 | (target->last_scanned < oldest->last_scanned)) | |
7690 | oldest = target; | |
7691 | } | |
7692 | ||
7693 | /* If there are no more slots, expire the oldest */ | |
7694 | list_del(&oldest->list); | |
7695 | target = oldest; | |
e174961c | 7696 | IPW_DEBUG_ASSOC("Expired '%s' (%pM) from " |
a6d4eae8 | 7697 | "network list.\n", |
9387b7ca JL |
7698 | print_ssid(ssid, target->ssid, |
7699 | target->ssid_len), | |
e174961c | 7700 | target->bssid); |
a6d4eae8 DW |
7701 | list_add_tail(&target->list, |
7702 | &priv->ieee->network_free_list); | |
7703 | } | |
7704 | ||
43f66a6c | 7705 | element = priv->ieee->network_free_list.next; |
b0a4e7d8 | 7706 | network = list_entry(element, struct libipw_network, list); |
43f66a6c JK |
7707 | ipw_adhoc_create(priv, network); |
7708 | rates = &priv->rates; | |
7709 | list_del(element); | |
7710 | list_add_tail(&network->list, &priv->ieee->network_list); | |
7711 | } | |
a613bffd | 7712 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
bf79451e | 7713 | |
43f66a6c JK |
7714 | /* If we reached the end of the list, then we don't have any valid |
7715 | * matching APs */ | |
7716 | if (!network) { | |
7717 | ipw_debug_config(priv); | |
7718 | ||
b095c381 JK |
7719 | if (!(priv->status & STATUS_SCANNING)) { |
7720 | if (!(priv->config & CFG_SPEED_SCAN)) | |
7721 | queue_delayed_work(priv->workqueue, | |
7722 | &priv->request_scan, | |
7723 | SCAN_INTERVAL); | |
7724 | else | |
c4028958 DH |
7725 | queue_delayed_work(priv->workqueue, |
7726 | &priv->request_scan, 0); | |
b095c381 | 7727 | } |
bf79451e | 7728 | |
c848d0af | 7729 | return 0; |
43f66a6c JK |
7730 | } |
7731 | ||
7732 | ipw_associate_network(priv, network, rates, 0); | |
c848d0af JK |
7733 | |
7734 | return 1; | |
7735 | } | |
7736 | ||
c4028958 | 7737 | static void ipw_bg_associate(struct work_struct *work) |
c848d0af | 7738 | { |
c4028958 DH |
7739 | struct ipw_priv *priv = |
7740 | container_of(work, struct ipw_priv, associate); | |
4644151b | 7741 | mutex_lock(&priv->mutex); |
c4028958 | 7742 | ipw_associate(priv); |
4644151b | 7743 | mutex_unlock(&priv->mutex); |
43f66a6c | 7744 | } |
bf79451e | 7745 | |
b095c381 JK |
7746 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
7747 | struct sk_buff *skb) | |
7748 | { | |
7749 | struct ieee80211_hdr *hdr; | |
7750 | u16 fc; | |
7751 | ||
7752 | hdr = (struct ieee80211_hdr *)skb->data; | |
72118015 | 7753 | fc = le16_to_cpu(hdr->frame_control); |
b095c381 JK |
7754 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
7755 | return; | |
7756 | ||
7757 | fc &= ~IEEE80211_FCTL_PROTECTED; | |
72118015 | 7758 | hdr->frame_control = cpu_to_le16(fc); |
b095c381 JK |
7759 | switch (priv->ieee->sec.level) { |
7760 | case SEC_LEVEL_3: | |
7761 | /* Remove CCMP HDR */ | |
b0a4e7d8 JL |
7762 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
7763 | skb->data + LIBIPW_3ADDR_LEN + 8, | |
7764 | skb->len - LIBIPW_3ADDR_LEN - 8); | |
f4ff497d | 7765 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
b095c381 JK |
7766 | break; |
7767 | case SEC_LEVEL_2: | |
7768 | break; | |
7769 | case SEC_LEVEL_1: | |
7770 | /* Remove IV */ | |
b0a4e7d8 JL |
7771 | memmove(skb->data + LIBIPW_3ADDR_LEN, |
7772 | skb->data + LIBIPW_3ADDR_LEN + 4, | |
7773 | skb->len - LIBIPW_3ADDR_LEN - 4); | |
f4ff497d | 7774 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
b095c381 JK |
7775 | break; |
7776 | case SEC_LEVEL_0: | |
7777 | break; | |
7778 | default: | |
af901ca1 | 7779 | printk(KERN_ERR "Unknown security level %d\n", |
b095c381 JK |
7780 | priv->ieee->sec.level); |
7781 | break; | |
7782 | } | |
43f66a6c | 7783 | } |
bf79451e | 7784 | |
b095c381 JK |
7785 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
7786 | struct ipw_rx_mem_buffer *rxb, | |
b0a4e7d8 | 7787 | struct libipw_rx_stats *stats) |
43f66a6c | 7788 | { |
ce55cbaf | 7789 | struct net_device *dev = priv->net_dev; |
b0a4e7d8 | 7790 | struct libipw_hdr_4addr *hdr; |
43f66a6c JK |
7791 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
7792 | ||
7793 | /* We received data from the HW, so stop the watchdog */ | |
ce55cbaf | 7794 | dev->trans_start = jiffies; |
43f66a6c | 7795 | |
bf79451e | 7796 | /* We only process data packets if the |
43f66a6c | 7797 | * interface is open */ |
a613bffd | 7798 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
43f66a6c | 7799 | skb_tailroom(rxb->skb))) { |
ce55cbaf | 7800 | dev->stats.rx_errors++; |
43f66a6c JK |
7801 | priv->wstats.discard.misc++; |
7802 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); | |
7803 | return; | |
7804 | } else if (unlikely(!netif_running(priv->net_dev))) { | |
ce55cbaf | 7805 | dev->stats.rx_dropped++; |
43f66a6c JK |
7806 | priv->wstats.discard.misc++; |
7807 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | |
7808 | return; | |
7809 | } | |
7810 | ||
7811 | /* Advance skb->data to the start of the actual payload */ | |
aaa4d308 | 7812 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
43f66a6c JK |
7813 | |
7814 | /* Set the size of the skb to the size of the frame */ | |
a613bffd | 7815 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
43f66a6c JK |
7816 | |
7817 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); | |
7818 | ||
b095c381 | 7819 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
b0a4e7d8 | 7820 | hdr = (struct libipw_hdr_4addr *)rxb->skb->data; |
567deaf6 | 7821 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && |
3c19065a | 7822 | (is_multicast_ether_addr(hdr->addr1) ? |
567deaf6 | 7823 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
b095c381 JK |
7824 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
7825 | ||
b0a4e7d8 | 7826 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
ce55cbaf | 7827 | dev->stats.rx_errors++; |
b0a4e7d8 | 7828 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
43f66a6c | 7829 | rxb->skb = NULL; |
b095c381 | 7830 | __ipw_led_activity_on(priv); |
a613bffd | 7831 | } |
43f66a6c JK |
7832 | } |
7833 | ||
459d4087 | 7834 | #ifdef CONFIG_IPW2200_RADIOTAP |
24a47dbd MK |
7835 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, |
7836 | struct ipw_rx_mem_buffer *rxb, | |
b0a4e7d8 | 7837 | struct libipw_rx_stats *stats) |
24a47dbd | 7838 | { |
ce55cbaf | 7839 | struct net_device *dev = priv->net_dev; |
24a47dbd MK |
7840 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
7841 | struct ipw_rx_frame *frame = &pkt->u.frame; | |
7842 | ||
7843 | /* initial pull of some data */ | |
7844 | u16 received_channel = frame->received_channel; | |
7845 | u8 antennaAndPhy = frame->antennaAndPhy; | |
7846 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ | |
7847 | u16 pktrate = frame->rate; | |
7848 | ||
7849 | /* Magic struct that slots into the radiotap header -- no reason | |
7850 | * to build this manually element by element, we can write it much | |
7851 | * more efficiently than we can parse it. ORDER MATTERS HERE */ | |
d685b8c2 | 7852 | struct ipw_rt_hdr *ipw_rt; |
24a47dbd MK |
7853 | |
7854 | short len = le16_to_cpu(pkt->u.frame.length); | |
7855 | ||
7856 | /* We received data from the HW, so stop the watchdog */ | |
ce55cbaf | 7857 | dev->trans_start = jiffies; |
24a47dbd MK |
7858 | |
7859 | /* We only process data packets if the | |
7860 | * interface is open */ | |
7861 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > | |
7862 | skb_tailroom(rxb->skb))) { | |
ce55cbaf | 7863 | dev->stats.rx_errors++; |
24a47dbd MK |
7864 | priv->wstats.discard.misc++; |
7865 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); | |
7866 | return; | |
7867 | } else if (unlikely(!netif_running(priv->net_dev))) { | |
ce55cbaf | 7868 | dev->stats.rx_dropped++; |
24a47dbd MK |
7869 | priv->wstats.discard.misc++; |
7870 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | |
7871 | return; | |
7872 | } | |
7873 | ||
7874 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use | |
7875 | * that now */ | |
7876 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { | |
7877 | /* FIXME: Should alloc bigger skb instead */ | |
ce55cbaf | 7878 | dev->stats.rx_dropped++; |
24a47dbd MK |
7879 | priv->wstats.discard.misc++; |
7880 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); | |
7881 | return; | |
7882 | } | |
7883 | ||
7884 | /* copy the frame itself */ | |
7885 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), | |
7886 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); | |
7887 | ||
24a47dbd MK |
7888 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; |
7889 | ||
7890 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; | |
7891 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ | |
743b84d2 | 7892 | ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */ |
24a47dbd MK |
7893 | |
7894 | /* Big bitfield of all the fields we provide in radiotap */ | |
743b84d2 AV |
7895 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
7896 | (1 << IEEE80211_RADIOTAP_TSFT) | | |
4b1f8a99 | 7897 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
24a47dbd MK |
7898 | (1 << IEEE80211_RADIOTAP_RATE) | |
7899 | (1 << IEEE80211_RADIOTAP_CHANNEL) | | |
7900 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | | |
d685b8c2 | 7901 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
24a47dbd MK |
7902 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
7903 | ||
7904 | /* Zero the flags, we'll add to them as we go */ | |
7905 | ipw_rt->rt_flags = 0; | |
4b1f8a99 ZY |
7906 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
7907 | frame->parent_tsf[2] << 16 | | |
7908 | frame->parent_tsf[1] << 8 | | |
7909 | frame->parent_tsf[0]); | |
24a47dbd MK |
7910 | |
7911 | /* Convert signal to DBM */ | |
7912 | ipw_rt->rt_dbmsignal = antsignal; | |
21f8a73f | 7913 | ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise); |
24a47dbd MK |
7914 | |
7915 | /* Convert the channel data and set the flags */ | |
7916 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); | |
7917 | if (received_channel > 14) { /* 802.11a */ | |
7918 | ipw_rt->rt_chbitmask = | |
7919 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); | |
7920 | } else if (antennaAndPhy & 32) { /* 802.11b */ | |
7921 | ipw_rt->rt_chbitmask = | |
7922 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); | |
7923 | } else { /* 802.11g */ | |
7924 | ipw_rt->rt_chbitmask = | |
472caf8c | 7925 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
24a47dbd MK |
7926 | } |
7927 | ||
7928 | /* set the rate in multiples of 500k/s */ | |
7929 | switch (pktrate) { | |
7930 | case IPW_TX_RATE_1MB: | |
7931 | ipw_rt->rt_rate = 2; | |
7932 | break; | |
7933 | case IPW_TX_RATE_2MB: | |
7934 | ipw_rt->rt_rate = 4; | |
7935 | break; | |
7936 | case IPW_TX_RATE_5MB: | |
7937 | ipw_rt->rt_rate = 10; | |
7938 | break; | |
7939 | case IPW_TX_RATE_6MB: | |
7940 | ipw_rt->rt_rate = 12; | |
7941 | break; | |
7942 | case IPW_TX_RATE_9MB: | |
7943 | ipw_rt->rt_rate = 18; | |
7944 | break; | |
7945 | case IPW_TX_RATE_11MB: | |
7946 | ipw_rt->rt_rate = 22; | |
7947 | break; | |
7948 | case IPW_TX_RATE_12MB: | |
7949 | ipw_rt->rt_rate = 24; | |
7950 | break; | |
7951 | case IPW_TX_RATE_18MB: | |
7952 | ipw_rt->rt_rate = 36; | |
7953 | break; | |
7954 | case IPW_TX_RATE_24MB: | |
7955 | ipw_rt->rt_rate = 48; | |
7956 | break; | |
7957 | case IPW_TX_RATE_36MB: | |
7958 | ipw_rt->rt_rate = 72; | |
7959 | break; | |
7960 | case IPW_TX_RATE_48MB: | |
7961 | ipw_rt->rt_rate = 96; | |
7962 | break; | |
7963 | case IPW_TX_RATE_54MB: | |
7964 | ipw_rt->rt_rate = 108; | |
7965 | break; | |
7966 | default: | |
7967 | ipw_rt->rt_rate = 0; | |
7968 | break; | |
7969 | } | |
7970 | ||
7971 | /* antenna number */ | |
7972 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ | |
7973 | ||
7974 | /* set the preamble flag if we have it */ | |
7975 | if ((antennaAndPhy & 64)) | |
7976 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; | |
7977 | ||
7978 | /* Set the size of the skb to the size of the frame */ | |
7979 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); | |
43f66a6c JK |
7980 | |
7981 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); | |
7982 | ||
b0a4e7d8 | 7983 | if (!libipw_rx(priv->ieee, rxb->skb, stats)) |
ce55cbaf | 7984 | dev->stats.rx_errors++; |
b0a4e7d8 | 7985 | else { /* libipw_rx succeeded, so it now owns the SKB */ |
24a47dbd MK |
7986 | rxb->skb = NULL; |
7987 | /* no LED during capture */ | |
7988 | } | |
7989 | } | |
7990 | #endif | |
7991 | ||
d685b8c2 | 7992 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
b0a4e7d8 | 7993 | #define libipw_is_probe_response(fc) \ |
d685b8c2 ZY |
7994 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \ |
7995 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP ) | |
7996 | ||
b0a4e7d8 | 7997 | #define libipw_is_management(fc) \ |
d685b8c2 ZY |
7998 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
7999 | ||
b0a4e7d8 | 8000 | #define libipw_is_control(fc) \ |
d685b8c2 ZY |
8001 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) |
8002 | ||
b0a4e7d8 | 8003 | #define libipw_is_data(fc) \ |
d685b8c2 ZY |
8004 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) |
8005 | ||
b0a4e7d8 | 8006 | #define libipw_is_assoc_request(fc) \ |
d685b8c2 ZY |
8007 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ) |
8008 | ||
b0a4e7d8 | 8009 | #define libipw_is_reassoc_request(fc) \ |
d685b8c2 ZY |
8010 | ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
8011 | ||
8012 | static void ipw_handle_promiscuous_rx(struct ipw_priv *priv, | |
8013 | struct ipw_rx_mem_buffer *rxb, | |
b0a4e7d8 | 8014 | struct libipw_rx_stats *stats) |
d685b8c2 | 8015 | { |
ce55cbaf | 8016 | struct net_device *dev = priv->prom_net_dev; |
d685b8c2 ZY |
8017 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
8018 | struct ipw_rx_frame *frame = &pkt->u.frame; | |
8019 | struct ipw_rt_hdr *ipw_rt; | |
8020 | ||
8021 | /* First cache any information we need before we overwrite | |
8022 | * the information provided in the skb from the hardware */ | |
8023 | struct ieee80211_hdr *hdr; | |
8024 | u16 channel = frame->received_channel; | |
8025 | u8 phy_flags = frame->antennaAndPhy; | |
8026 | s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM; | |
21f8a73f | 8027 | s8 noise = (s8) le16_to_cpu(frame->noise); |
d685b8c2 ZY |
8028 | u8 rate = frame->rate; |
8029 | short len = le16_to_cpu(pkt->u.frame.length); | |
d685b8c2 ZY |
8030 | struct sk_buff *skb; |
8031 | int hdr_only = 0; | |
8032 | u16 filter = priv->prom_priv->filter; | |
8033 | ||
8034 | /* If the filter is set to not include Rx frames then return */ | |
8035 | if (filter & IPW_PROM_NO_RX) | |
8036 | return; | |
8037 | ||
d685b8c2 | 8038 | /* We received data from the HW, so stop the watchdog */ |
ce55cbaf | 8039 | dev->trans_start = jiffies; |
d685b8c2 ZY |
8040 | |
8041 | if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) { | |
ce55cbaf | 8042 | dev->stats.rx_errors++; |
d685b8c2 ZY |
8043 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); |
8044 | return; | |
8045 | } | |
8046 | ||
8047 | /* We only process data packets if the interface is open */ | |
ce55cbaf SH |
8048 | if (unlikely(!netif_running(dev))) { |
8049 | dev->stats.rx_dropped++; | |
d685b8c2 ZY |
8050 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); |
8051 | return; | |
8052 | } | |
8053 | ||
8054 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use | |
8055 | * that now */ | |
8056 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { | |
8057 | /* FIXME: Should alloc bigger skb instead */ | |
ce55cbaf | 8058 | dev->stats.rx_dropped++; |
d685b8c2 ZY |
8059 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); |
8060 | return; | |
8061 | } | |
8062 | ||
8063 | hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE; | |
b0a4e7d8 | 8064 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
d685b8c2 ZY |
8065 | if (filter & IPW_PROM_NO_MGMT) |
8066 | return; | |
8067 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) | |
8068 | hdr_only = 1; | |
b0a4e7d8 | 8069 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
d685b8c2 ZY |
8070 | if (filter & IPW_PROM_NO_CTL) |
8071 | return; | |
8072 | if (filter & IPW_PROM_CTL_HEADER_ONLY) | |
8073 | hdr_only = 1; | |
b0a4e7d8 | 8074 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
d685b8c2 ZY |
8075 | if (filter & IPW_PROM_NO_DATA) |
8076 | return; | |
8077 | if (filter & IPW_PROM_DATA_HEADER_ONLY) | |
8078 | hdr_only = 1; | |
8079 | } | |
8080 | ||
8081 | /* Copy the SKB since this is for the promiscuous side */ | |
8082 | skb = skb_copy(rxb->skb, GFP_ATOMIC); | |
8083 | if (skb == NULL) { | |
8084 | IPW_ERROR("skb_clone failed for promiscuous copy.\n"); | |
8085 | return; | |
8086 | } | |
8087 | ||
8088 | /* copy the frame data to write after where the radiotap header goes */ | |
8089 | ipw_rt = (void *)skb->data; | |
8090 | ||
8091 | if (hdr_only) | |
b0a4e7d8 | 8092 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
d685b8c2 ZY |
8093 | |
8094 | memcpy(ipw_rt->payload, hdr, len); | |
8095 | ||
d685b8c2 ZY |
8096 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
8097 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ | |
743b84d2 | 8098 | ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */ |
d685b8c2 ZY |
8099 | |
8100 | /* Set the size of the skb to the size of the frame */ | |
743b84d2 | 8101 | skb_put(skb, sizeof(*ipw_rt) + len); |
d685b8c2 ZY |
8102 | |
8103 | /* Big bitfield of all the fields we provide in radiotap */ | |
743b84d2 AV |
8104 | ipw_rt->rt_hdr.it_present = cpu_to_le32( |
8105 | (1 << IEEE80211_RADIOTAP_TSFT) | | |
4b1f8a99 | 8106 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
d685b8c2 ZY |
8107 | (1 << IEEE80211_RADIOTAP_RATE) | |
8108 | (1 << IEEE80211_RADIOTAP_CHANNEL) | | |
8109 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | | |
8110 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | | |
8111 | (1 << IEEE80211_RADIOTAP_ANTENNA)); | |
8112 | ||
8113 | /* Zero the flags, we'll add to them as we go */ | |
8114 | ipw_rt->rt_flags = 0; | |
4b1f8a99 ZY |
8115 | ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 | |
8116 | frame->parent_tsf[2] << 16 | | |
8117 | frame->parent_tsf[1] << 8 | | |
8118 | frame->parent_tsf[0]); | |
d685b8c2 ZY |
8119 | |
8120 | /* Convert to DBM */ | |
8121 | ipw_rt->rt_dbmsignal = signal; | |
8122 | ipw_rt->rt_dbmnoise = noise; | |
8123 | ||
8124 | /* Convert the channel data and set the flags */ | |
8125 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel)); | |
8126 | if (channel > 14) { /* 802.11a */ | |
8127 | ipw_rt->rt_chbitmask = | |
8128 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); | |
8129 | } else if (phy_flags & (1 << 5)) { /* 802.11b */ | |
8130 | ipw_rt->rt_chbitmask = | |
8131 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); | |
8132 | } else { /* 802.11g */ | |
8133 | ipw_rt->rt_chbitmask = | |
472caf8c | 8134 | cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); |
d685b8c2 ZY |
8135 | } |
8136 | ||
8137 | /* set the rate in multiples of 500k/s */ | |
8138 | switch (rate) { | |
8139 | case IPW_TX_RATE_1MB: | |
8140 | ipw_rt->rt_rate = 2; | |
8141 | break; | |
8142 | case IPW_TX_RATE_2MB: | |
8143 | ipw_rt->rt_rate = 4; | |
8144 | break; | |
8145 | case IPW_TX_RATE_5MB: | |
8146 | ipw_rt->rt_rate = 10; | |
8147 | break; | |
8148 | case IPW_TX_RATE_6MB: | |
8149 | ipw_rt->rt_rate = 12; | |
8150 | break; | |
8151 | case IPW_TX_RATE_9MB: | |
8152 | ipw_rt->rt_rate = 18; | |
8153 | break; | |
8154 | case IPW_TX_RATE_11MB: | |
8155 | ipw_rt->rt_rate = 22; | |
8156 | break; | |
8157 | case IPW_TX_RATE_12MB: | |
8158 | ipw_rt->rt_rate = 24; | |
8159 | break; | |
8160 | case IPW_TX_RATE_18MB: | |
8161 | ipw_rt->rt_rate = 36; | |
8162 | break; | |
8163 | case IPW_TX_RATE_24MB: | |
8164 | ipw_rt->rt_rate = 48; | |
8165 | break; | |
8166 | case IPW_TX_RATE_36MB: | |
8167 | ipw_rt->rt_rate = 72; | |
8168 | break; | |
8169 | case IPW_TX_RATE_48MB: | |
8170 | ipw_rt->rt_rate = 96; | |
8171 | break; | |
8172 | case IPW_TX_RATE_54MB: | |
8173 | ipw_rt->rt_rate = 108; | |
8174 | break; | |
8175 | default: | |
8176 | ipw_rt->rt_rate = 0; | |
8177 | break; | |
8178 | } | |
8179 | ||
8180 | /* antenna number */ | |
8181 | ipw_rt->rt_antenna = (phy_flags & 3); | |
8182 | ||
8183 | /* set the preamble flag if we have it */ | |
8184 | if (phy_flags & (1 << 6)) | |
8185 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; | |
8186 | ||
8187 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len); | |
8188 | ||
b0a4e7d8 | 8189 | if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) { |
ce55cbaf | 8190 | dev->stats.rx_errors++; |
d685b8c2 ZY |
8191 | dev_kfree_skb_any(skb); |
8192 | } | |
8193 | } | |
8194 | #endif | |
8195 | ||
858119e1 | 8196 | static int is_network_packet(struct ipw_priv *priv, |
b0a4e7d8 | 8197 | struct libipw_hdr_4addr *header) |
ea2b26e0 JK |
8198 | { |
8199 | /* Filter incoming packets to determine if they are targetted toward | |
8200 | * this network, discarding packets coming from ourselves */ | |
8201 | switch (priv->ieee->iw_mode) { | |
a613bffd | 8202 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
c848d0af JK |
8203 | /* packets from our adapter are dropped (echo) */ |
8204 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) | |
8205 | return 0; | |
8206 | ||
90700fd9 | 8207 | /* {broad,multi}cast packets to our BSSID go through */ |
3c19065a | 8208 | if (is_multicast_ether_addr(header->addr1)) |
ea2b26e0 | 8209 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
a613bffd JK |
8210 | |
8211 | /* packets to our adapter go through */ | |
8212 | return !memcmp(header->addr1, priv->net_dev->dev_addr, | |
8213 | ETH_ALEN); | |
a613bffd | 8214 | |
90700fd9 | 8215 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
c848d0af JK |
8216 | /* packets from our adapter are dropped (echo) */ |
8217 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) | |
8218 | return 0; | |
8219 | ||
90700fd9 | 8220 | /* {broad,multi}cast packets to our BSS go through */ |
3c19065a | 8221 | if (is_multicast_ether_addr(header->addr1)) |
a613bffd JK |
8222 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
8223 | ||
8224 | /* packets to our adapter go through */ | |
8225 | return !memcmp(header->addr1, priv->net_dev->dev_addr, | |
8226 | ETH_ALEN); | |
ea2b26e0 | 8227 | } |
a613bffd | 8228 | |
ea2b26e0 JK |
8229 | return 1; |
8230 | } | |
8231 | ||
afbf30a2 JK |
8232 | #define IPW_PACKET_RETRY_TIME HZ |
8233 | ||
858119e1 | 8234 | static int is_duplicate_packet(struct ipw_priv *priv, |
b0a4e7d8 | 8235 | struct libipw_hdr_4addr *header) |
afbf30a2 | 8236 | { |
afbf30a2 JK |
8237 | u16 sc = le16_to_cpu(header->seq_ctl); |
8238 | u16 seq = WLAN_GET_SEQ_SEQ(sc); | |
8239 | u16 frag = WLAN_GET_SEQ_FRAG(sc); | |
8240 | u16 *last_seq, *last_frag; | |
8241 | unsigned long *last_time; | |
8242 | ||
8243 | switch (priv->ieee->iw_mode) { | |
8244 | case IW_MODE_ADHOC: | |
8245 | { | |
8246 | struct list_head *p; | |
8247 | struct ipw_ibss_seq *entry = NULL; | |
8248 | u8 *mac = header->addr2; | |
8249 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; | |
8250 | ||
8251 | __list_for_each(p, &priv->ibss_mac_hash[index]) { | |
8252 | entry = | |
8253 | list_entry(p, struct ipw_ibss_seq, list); | |
8254 | if (!memcmp(entry->mac, mac, ETH_ALEN)) | |
8255 | break; | |
8256 | } | |
8257 | if (p == &priv->ibss_mac_hash[index]) { | |
8258 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); | |
8259 | if (!entry) { | |
8260 | IPW_ERROR | |
8261 | ("Cannot malloc new mac entry\n"); | |
8262 | return 0; | |
8263 | } | |
8264 | memcpy(entry->mac, mac, ETH_ALEN); | |
8265 | entry->seq_num = seq; | |
8266 | entry->frag_num = frag; | |
8267 | entry->packet_time = jiffies; | |
8268 | list_add(&entry->list, | |
8269 | &priv->ibss_mac_hash[index]); | |
8270 | return 0; | |
8271 | } | |
8272 | last_seq = &entry->seq_num; | |
8273 | last_frag = &entry->frag_num; | |
8274 | last_time = &entry->packet_time; | |
8275 | break; | |
8276 | } | |
8277 | case IW_MODE_INFRA: | |
8278 | last_seq = &priv->last_seq_num; | |
8279 | last_frag = &priv->last_frag_num; | |
8280 | last_time = &priv->last_packet_time; | |
8281 | break; | |
8282 | default: | |
8283 | return 0; | |
8284 | } | |
8285 | if ((*last_seq == seq) && | |
8286 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { | |
8287 | if (*last_frag == frag) | |
8288 | goto drop; | |
8289 | if (*last_frag + 1 != frag) | |
8290 | /* out-of-order fragment */ | |
8291 | goto drop; | |
afbf30a2 JK |
8292 | } else |
8293 | *last_seq = seq; | |
8294 | ||
f57ce7ce | 8295 | *last_frag = frag; |
afbf30a2 JK |
8296 | *last_time = jiffies; |
8297 | return 0; | |
8298 | ||
8299 | drop: | |
87b016cb ZY |
8300 | /* Comment this line now since we observed the card receives |
8301 | * duplicate packets but the FCTL_RETRY bit is not set in the | |
8302 | * IBSS mode with fragmentation enabled. | |
72118015 | 8303 | BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */ |
afbf30a2 JK |
8304 | return 1; |
8305 | } | |
8306 | ||
b095c381 JK |
8307 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
8308 | struct ipw_rx_mem_buffer *rxb, | |
b0a4e7d8 | 8309 | struct libipw_rx_stats *stats) |
b095c381 JK |
8310 | { |
8311 | struct sk_buff *skb = rxb->skb; | |
8312 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; | |
b0a4e7d8 | 8313 | struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *) |
b095c381 JK |
8314 | (skb->data + IPW_RX_FRAME_SIZE); |
8315 | ||
b0a4e7d8 | 8316 | libipw_rx_mgt(priv->ieee, header, stats); |
b095c381 JK |
8317 | |
8318 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && | |
8319 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == | |
8320 | IEEE80211_STYPE_PROBE_RESP) || | |
8321 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == | |
8322 | IEEE80211_STYPE_BEACON))) { | |
8323 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) | |
8324 | ipw_add_station(priv, header->addr2); | |
8325 | } | |
8326 | ||
8327 | if (priv->config & CFG_NET_STATS) { | |
8328 | IPW_DEBUG_HC("sending stat packet\n"); | |
8329 | ||
8330 | /* Set the size of the skb to the size of the full | |
8331 | * ipw header and 802.11 frame */ | |
8332 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + | |
8333 | IPW_RX_FRAME_SIZE); | |
8334 | ||
8335 | /* Advance past the ipw packet header to the 802.11 frame */ | |
8336 | skb_pull(skb, IPW_RX_FRAME_SIZE); | |
8337 | ||
b0a4e7d8 | 8338 | /* Push the libipw_rx_stats before the 802.11 frame */ |
b095c381 JK |
8339 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); |
8340 | ||
8341 | skb->dev = priv->ieee->dev; | |
8342 | ||
b0a4e7d8 | 8343 | /* Point raw at the libipw_stats */ |
459a98ed | 8344 | skb_reset_mac_header(skb); |
b095c381 JK |
8345 | |
8346 | skb->pkt_type = PACKET_OTHERHOST; | |
c1b4aa3f | 8347 | skb->protocol = cpu_to_be16(ETH_P_80211_STATS); |
b095c381 JK |
8348 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); |
8349 | netif_rx(skb); | |
43f66a6c | 8350 | rxb->skb = NULL; |
b095c381 | 8351 | } |
43f66a6c JK |
8352 | } |
8353 | ||
43f66a6c JK |
8354 | /* |
8355 | * Main entry function for recieving a packet with 80211 headers. This | |
8356 | * should be called when ever the FW has notified us that there is a new | |
8357 | * skb in the recieve queue. | |
8358 | */ | |
8359 | static void ipw_rx(struct ipw_priv *priv) | |
8360 | { | |
8361 | struct ipw_rx_mem_buffer *rxb; | |
8362 | struct ipw_rx_packet *pkt; | |
b0a4e7d8 | 8363 | struct libipw_hdr_4addr *header; |
43f66a6c JK |
8364 | u32 r, w, i; |
8365 | u8 network_packet; | |
943dbef4 | 8366 | u8 fill_rx = 0; |
43f66a6c | 8367 | |
b095c381 JK |
8368 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
8369 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); | |
943dbef4 DW |
8370 | i = priv->rxq->read; |
8371 | ||
8372 | if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2)) | |
8373 | fill_rx = 1; | |
43f66a6c JK |
8374 | |
8375 | while (i != r) { | |
8376 | rxb = priv->rxq->queue[i]; | |
43f66a6c JK |
8377 | if (unlikely(rxb == NULL)) { |
8378 | printk(KERN_CRIT "Queue not allocated!\n"); | |
8379 | break; | |
8380 | } | |
43f66a6c JK |
8381 | priv->rxq->queue[i] = NULL; |
8382 | ||
8383 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, | |
b095c381 | 8384 | IPW_RX_BUF_SIZE, |
43f66a6c JK |
8385 | PCI_DMA_FROMDEVICE); |
8386 | ||
8387 | pkt = (struct ipw_rx_packet *)rxb->skb->data; | |
8388 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", | |
8389 | pkt->header.message_type, | |
0edd5b44 | 8390 | pkt->header.rx_seq_num, pkt->header.control_bits); |
43f66a6c JK |
8391 | |
8392 | switch (pkt->header.message_type) { | |
0edd5b44 | 8393 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
b0a4e7d8 | 8394 | struct libipw_rx_stats stats = { |
851ca268 | 8395 | .rssi = pkt->u.frame.rssi_dbm - |
0edd5b44 | 8396 | IPW_RSSI_TO_DBM, |
c848d0af | 8397 | .signal = |
21f8a73f | 8398 | pkt->u.frame.rssi_dbm - |
b191608a | 8399 | IPW_RSSI_TO_DBM + 0x100, |
c848d0af JK |
8400 | .noise = |
8401 | le16_to_cpu(pkt->u.frame.noise), | |
0edd5b44 JG |
8402 | .rate = pkt->u.frame.rate, |
8403 | .mac_time = jiffies, | |
8404 | .received_channel = | |
8405 | pkt->u.frame.received_channel, | |
8406 | .freq = | |
8407 | (pkt->u.frame. | |
8408 | control & (1 << 0)) ? | |
b0a4e7d8 JL |
8409 | LIBIPW_24GHZ_BAND : |
8410 | LIBIPW_52GHZ_BAND, | |
a613bffd | 8411 | .len = le16_to_cpu(pkt->u.frame.length), |
0edd5b44 JG |
8412 | }; |
8413 | ||
8414 | if (stats.rssi != 0) | |
b0a4e7d8 | 8415 | stats.mask |= LIBIPW_STATMASK_RSSI; |
0edd5b44 | 8416 | if (stats.signal != 0) |
b0a4e7d8 | 8417 | stats.mask |= LIBIPW_STATMASK_SIGNAL; |
c848d0af | 8418 | if (stats.noise != 0) |
b0a4e7d8 | 8419 | stats.mask |= LIBIPW_STATMASK_NOISE; |
0edd5b44 | 8420 | if (stats.rate != 0) |
b0a4e7d8 | 8421 | stats.mask |= LIBIPW_STATMASK_RATE; |
0edd5b44 JG |
8422 | |
8423 | priv->rx_packets++; | |
43f66a6c | 8424 | |
d685b8c2 ZY |
8425 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
8426 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) | |
8427 | ipw_handle_promiscuous_rx(priv, rxb, &stats); | |
8428 | #endif | |
8429 | ||
b095c381 | 8430 | #ifdef CONFIG_IPW2200_MONITOR |
0edd5b44 | 8431 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
459d4087 | 8432 | #ifdef CONFIG_IPW2200_RADIOTAP |
d685b8c2 ZY |
8433 | |
8434 | ipw_handle_data_packet_monitor(priv, | |
8435 | rxb, | |
8436 | &stats); | |
24a47dbd | 8437 | #else |
d685b8c2 ZY |
8438 | ipw_handle_data_packet(priv, rxb, |
8439 | &stats); | |
24a47dbd | 8440 | #endif |
0edd5b44 JG |
8441 | break; |
8442 | } | |
43f66a6c | 8443 | #endif |
bf79451e | 8444 | |
0edd5b44 | 8445 | header = |
b0a4e7d8 | 8446 | (struct libipw_hdr_4addr *)(rxb->skb-> |
0dacca1f JK |
8447 | data + |
8448 | IPW_RX_FRAME_SIZE); | |
43f66a6c JK |
8449 | /* TODO: Check Ad-Hoc dest/source and make sure |
8450 | * that we are actually parsing these packets | |
bf79451e | 8451 | * correctly -- we should probably use the |
43f66a6c JK |
8452 | * frame control of the packet and disregard |
8453 | * the current iw_mode */ | |
0edd5b44 | 8454 | |
ea2b26e0 JK |
8455 | network_packet = |
8456 | is_network_packet(priv, header); | |
0edd5b44 JG |
8457 | if (network_packet && priv->assoc_network) { |
8458 | priv->assoc_network->stats.rssi = | |
8459 | stats.rssi; | |
00d21de5 ZY |
8460 | priv->exp_avg_rssi = |
8461 | exponential_average(priv->exp_avg_rssi, | |
8462 | stats.rssi, DEPTH_RSSI); | |
0edd5b44 JG |
8463 | } |
8464 | ||
8465 | IPW_DEBUG_RX("Frame: len=%u\n", | |
a613bffd | 8466 | le16_to_cpu(pkt->u.frame.length)); |
0edd5b44 | 8467 | |
a613bffd | 8468 | if (le16_to_cpu(pkt->u.frame.length) < |
b0a4e7d8 | 8469 | libipw_get_hdrlen(le16_to_cpu( |
9d0be03a | 8470 | header->frame_ctl))) { |
0edd5b44 JG |
8471 | IPW_DEBUG_DROP |
8472 | ("Received packet is too small. " | |
8473 | "Dropping.\n"); | |
ce55cbaf | 8474 | priv->net_dev->stats.rx_errors++; |
0edd5b44 JG |
8475 | priv->wstats.discard.misc++; |
8476 | break; | |
8477 | } | |
8478 | ||
a613bffd JK |
8479 | switch (WLAN_FC_GET_TYPE |
8480 | (le16_to_cpu(header->frame_ctl))) { | |
b095c381 | 8481 | |
0edd5b44 | 8482 | case IEEE80211_FTYPE_MGMT: |
b095c381 JK |
8483 | ipw_handle_mgmt_packet(priv, rxb, |
8484 | &stats); | |
0edd5b44 JG |
8485 | break; |
8486 | ||
8487 | case IEEE80211_FTYPE_CTL: | |
8488 | break; | |
8489 | ||
8490 | case IEEE80211_FTYPE_DATA: | |
afbf30a2 JK |
8491 | if (unlikely(!network_packet || |
8492 | is_duplicate_packet(priv, | |
8493 | header))) | |
8494 | { | |
0edd5b44 | 8495 | IPW_DEBUG_DROP("Dropping: " |
e174961c JB |
8496 | "%pM, " |
8497 | "%pM, " | |
8498 | "%pM\n", | |
8499 | header->addr1, | |
8500 | header->addr2, | |
8501 | header->addr3); | |
b095c381 JK |
8502 | break; |
8503 | } | |
8504 | ||
8505 | ipw_handle_data_packet(priv, rxb, | |
8506 | &stats); | |
8507 | ||
0edd5b44 JG |
8508 | break; |
8509 | } | |
43f66a6c JK |
8510 | break; |
8511 | } | |
bf79451e | 8512 | |
0edd5b44 JG |
8513 | case RX_HOST_NOTIFICATION_TYPE:{ |
8514 | IPW_DEBUG_RX | |
8515 | ("Notification: subtype=%02X flags=%02X size=%d\n", | |
43f66a6c JK |
8516 | pkt->u.notification.subtype, |
8517 | pkt->u.notification.flags, | |
720eeb43 | 8518 | le16_to_cpu(pkt->u.notification.size)); |
0edd5b44 JG |
8519 | ipw_rx_notification(priv, &pkt->u.notification); |
8520 | break; | |
8521 | } | |
43f66a6c JK |
8522 | |
8523 | default: | |
8524 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", | |
8525 | pkt->header.message_type); | |
8526 | break; | |
8527 | } | |
bf79451e JG |
8528 | |
8529 | /* For now we just don't re-use anything. We can tweak this | |
8530 | * later to try and re-use notification packets and SKBs that | |
43f66a6c JK |
8531 | * fail to Rx correctly */ |
8532 | if (rxb->skb != NULL) { | |
8533 | dev_kfree_skb_any(rxb->skb); | |
8534 | rxb->skb = NULL; | |
8535 | } | |
bf79451e | 8536 | |
43f66a6c | 8537 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
b095c381 | 8538 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
43f66a6c | 8539 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
bf79451e | 8540 | |
43f66a6c | 8541 | i = (i + 1) % RX_QUEUE_SIZE; |
943dbef4 DW |
8542 | |
8543 | /* If there are a lot of unsued frames, restock the Rx queue | |
8544 | * so the ucode won't assert */ | |
8545 | if (fill_rx) { | |
8546 | priv->rxq->read = i; | |
8547 | ipw_rx_queue_replenish(priv); | |
8548 | } | |
43f66a6c JK |
8549 | } |
8550 | ||
8551 | /* Backtrack one entry */ | |
943dbef4 | 8552 | priv->rxq->read = i; |
43f66a6c JK |
8553 | ipw_rx_queue_restock(priv); |
8554 | } | |
8555 | ||
afbf30a2 JK |
8556 | #define DEFAULT_RTS_THRESHOLD 2304U |
8557 | #define MIN_RTS_THRESHOLD 1U | |
8558 | #define MAX_RTS_THRESHOLD 2304U | |
8559 | #define DEFAULT_BEACON_INTERVAL 100U | |
8560 | #define DEFAULT_SHORT_RETRY_LIMIT 7U | |
8561 | #define DEFAULT_LONG_RETRY_LIMIT 4U | |
8562 | ||
d6d5b5c1 ZY |
8563 | /** |
8564 | * ipw_sw_reset | |
8565 | * @option: options to control different reset behaviour | |
8566 | * 0 = reset everything except the 'disable' module_param | |
8567 | * 1 = reset everything and print out driver info (for probe only) | |
8568 | * 2 = reset everything | |
8569 | */ | |
8570 | static int ipw_sw_reset(struct ipw_priv *priv, int option) | |
43f66a6c | 8571 | { |
afbf30a2 JK |
8572 | int band, modulation; |
8573 | int old_mode = priv->ieee->iw_mode; | |
43f66a6c | 8574 | |
afbf30a2 JK |
8575 | /* Initialize module parameter values here */ |
8576 | priv->config = 0; | |
43f66a6c | 8577 | |
afbf30a2 JK |
8578 | /* We default to disabling the LED code as right now it causes |
8579 | * too many systems to lock up... */ | |
21f8a73f | 8580 | if (!led_support) |
afbf30a2 | 8581 | priv->config |= CFG_NO_LED; |
43f66a6c | 8582 | |
afbf30a2 JK |
8583 | if (associate) |
8584 | priv->config |= CFG_ASSOCIATE; | |
8585 | else | |
8586 | IPW_DEBUG_INFO("Auto associate disabled.\n"); | |
bf79451e | 8587 | |
afbf30a2 JK |
8588 | if (auto_create) |
8589 | priv->config |= CFG_ADHOC_CREATE; | |
8590 | else | |
8591 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); | |
43f66a6c | 8592 | |
17ed081d ZY |
8593 | priv->config &= ~CFG_STATIC_ESSID; |
8594 | priv->essid_len = 0; | |
8595 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); | |
8596 | ||
d6d5b5c1 | 8597 | if (disable && option) { |
afbf30a2 JK |
8598 | priv->status |= STATUS_RF_KILL_SW; |
8599 | IPW_DEBUG_INFO("Radio disabled.\n"); | |
43f66a6c | 8600 | } |
bf79451e | 8601 | |
21f8a73f | 8602 | if (default_channel != 0) { |
afbf30a2 | 8603 | priv->config |= CFG_STATIC_CHANNEL; |
21f8a73f RC |
8604 | priv->channel = default_channel; |
8605 | IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel); | |
afbf30a2 | 8606 | /* TODO: Validate that provided channel is in range */ |
43f66a6c | 8607 | } |
e43e3c1e | 8608 | #ifdef CONFIG_IPW2200_QOS |
afbf30a2 JK |
8609 | ipw_qos_init(priv, qos_enable, qos_burst_enable, |
8610 | burst_duration_CCK, burst_duration_OFDM); | |
e43e3c1e | 8611 | #endif /* CONFIG_IPW2200_QOS */ |
43f66a6c | 8612 | |
21f8a73f | 8613 | switch (network_mode) { |
afbf30a2 JK |
8614 | case 1: |
8615 | priv->ieee->iw_mode = IW_MODE_ADHOC; | |
8616 | priv->net_dev->type = ARPHRD_ETHER; | |
8617 | ||
8618 | break; | |
8619 | #ifdef CONFIG_IPW2200_MONITOR | |
8620 | case 2: | |
8621 | priv->ieee->iw_mode = IW_MODE_MONITOR; | |
459d4087 | 8622 | #ifdef CONFIG_IPW2200_RADIOTAP |
24a47dbd MK |
8623 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
8624 | #else | |
afbf30a2 | 8625 | priv->net_dev->type = ARPHRD_IEEE80211; |
24a47dbd | 8626 | #endif |
afbf30a2 JK |
8627 | break; |
8628 | #endif | |
8629 | default: | |
8630 | case 0: | |
8631 | priv->net_dev->type = ARPHRD_ETHER; | |
8632 | priv->ieee->iw_mode = IW_MODE_INFRA; | |
8633 | break; | |
43f66a6c JK |
8634 | } |
8635 | ||
afbf30a2 JK |
8636 | if (hwcrypto) { |
8637 | priv->ieee->host_encrypt = 0; | |
8638 | priv->ieee->host_encrypt_msdu = 0; | |
8639 | priv->ieee->host_decrypt = 0; | |
567deaf6 | 8640 | priv->ieee->host_mc_decrypt = 0; |
afbf30a2 JK |
8641 | } |
8642 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); | |
43f66a6c | 8643 | |
e402c937 ZY |
8644 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
8645 | priv->ieee->host_open_frag = 0; | |
bf79451e | 8646 | |
afbf30a2 JK |
8647 | if ((priv->pci_dev->device == 0x4223) || |
8648 | (priv->pci_dev->device == 0x4224)) { | |
e8c69e27 | 8649 | if (option == 1) |
afbf30a2 JK |
8650 | printk(KERN_INFO DRV_NAME |
8651 | ": Detected Intel PRO/Wireless 2915ABG Network " | |
8652 | "Connection\n"); | |
8653 | priv->ieee->abg_true = 1; | |
b0a4e7d8 JL |
8654 | band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND; |
8655 | modulation = LIBIPW_OFDM_MODULATION | | |
8656 | LIBIPW_CCK_MODULATION; | |
afbf30a2 JK |
8657 | priv->adapter = IPW_2915ABG; |
8658 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; | |
43f66a6c | 8659 | } else { |
e8c69e27 | 8660 | if (option == 1) |
afbf30a2 JK |
8661 | printk(KERN_INFO DRV_NAME |
8662 | ": Detected Intel PRO/Wireless 2200BG Network " | |
8663 | "Connection\n"); | |
bf79451e | 8664 | |
afbf30a2 | 8665 | priv->ieee->abg_true = 0; |
b0a4e7d8 JL |
8666 | band = LIBIPW_24GHZ_BAND; |
8667 | modulation = LIBIPW_OFDM_MODULATION | | |
8668 | LIBIPW_CCK_MODULATION; | |
afbf30a2 JK |
8669 | priv->adapter = IPW_2200BG; |
8670 | priv->ieee->mode = IEEE_G | IEEE_B; | |
43f66a6c JK |
8671 | } |
8672 | ||
afbf30a2 JK |
8673 | priv->ieee->freq_band = band; |
8674 | priv->ieee->modulation = modulation; | |
43f66a6c | 8675 | |
b0a4e7d8 | 8676 | priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK; |
bf79451e | 8677 | |
afbf30a2 JK |
8678 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
8679 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; | |
43f66a6c | 8680 | |
afbf30a2 JK |
8681 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
8682 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; | |
8683 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; | |
43f66a6c | 8684 | |
afbf30a2 JK |
8685 | /* If power management is turned on, default to AC mode */ |
8686 | priv->power_mode = IPW_POWER_AC; | |
8687 | priv->tx_power = IPW_TX_POWER_DEFAULT; | |
8688 | ||
0ece35b5 | 8689 | return old_mode == priv->ieee->iw_mode; |
43f66a6c JK |
8690 | } |
8691 | ||
8692 | /* | |
8693 | * This file defines the Wireless Extension handlers. It does not | |
8694 | * define any methods of hardware manipulation and relies on the | |
8695 | * functions defined in ipw_main to provide the HW interaction. | |
bf79451e JG |
8696 | * |
8697 | * The exception to this is the use of the ipw_get_ordinal() | |
43f66a6c JK |
8698 | * function used to poll the hardware vs. making unecessary calls. |
8699 | * | |
8700 | */ | |
8701 | ||
43f66a6c JK |
8702 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) |
8703 | { | |
8704 | if (channel == 0) { | |
8705 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); | |
8706 | priv->config &= ~CFG_STATIC_CHANNEL; | |
c848d0af JK |
8707 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
8708 | "parameters.\n"); | |
8709 | ipw_associate(priv); | |
43f66a6c JK |
8710 | return 0; |
8711 | } | |
8712 | ||
8713 | priv->config |= CFG_STATIC_CHANNEL; | |
8714 | ||
8715 | if (priv->channel == channel) { | |
0edd5b44 JG |
8716 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
8717 | channel); | |
43f66a6c JK |
8718 | return 0; |
8719 | } | |
8720 | ||
8721 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); | |
8722 | priv->channel = channel; | |
8723 | ||
b095c381 JK |
8724 | #ifdef CONFIG_IPW2200_MONITOR |
8725 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | |
afbf30a2 | 8726 | int i; |
b095c381 | 8727 | if (priv->status & STATUS_SCANNING) { |
afbf30a2 | 8728 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
b095c381 | 8729 | "channel change.\n"); |
afbf30a2 | 8730 | ipw_abort_scan(priv); |
b095c381 JK |
8731 | } |
8732 | ||
8733 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) | |
8734 | udelay(10); | |
8735 | ||
8736 | if (priv->status & STATUS_SCANNING) | |
8737 | IPW_DEBUG_SCAN("Still scanning...\n"); | |
8738 | else | |
8739 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", | |
8740 | 1000 - i); | |
8741 | ||
8742 | return 0; | |
43f66a6c | 8743 | } |
b095c381 JK |
8744 | #endif /* CONFIG_IPW2200_MONITOR */ |
8745 | ||
c848d0af JK |
8746 | /* Network configuration changed -- force [re]association */ |
8747 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); | |
8748 | if (!ipw_disassociate(priv)) | |
43f66a6c | 8749 | ipw_associate(priv); |
43f66a6c JK |
8750 | |
8751 | return 0; | |
8752 | } | |
8753 | ||
bf79451e JG |
8754 | static int ipw_wx_set_freq(struct net_device *dev, |
8755 | struct iw_request_info *info, | |
8756 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 8757 | { |
b0a4e7d8 JL |
8758 | struct ipw_priv *priv = libipw_priv(dev); |
8759 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); | |
43f66a6c | 8760 | struct iw_freq *fwrq = &wrqu->freq; |
afbf30a2 | 8761 | int ret = 0, i; |
1fe0adb4 LH |
8762 | u8 channel, flags; |
8763 | int band; | |
b095c381 JK |
8764 | |
8765 | if (fwrq->m == 0) { | |
8766 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); | |
4644151b | 8767 | mutex_lock(&priv->mutex); |
b095c381 | 8768 | ret = ipw_set_channel(priv, 0); |
4644151b | 8769 | mutex_unlock(&priv->mutex); |
b095c381 JK |
8770 | return ret; |
8771 | } | |
43f66a6c JK |
8772 | /* if setting by freq convert to channel */ |
8773 | if (fwrq->e == 1) { | |
b0a4e7d8 | 8774 | channel = libipw_freq_to_channel(priv->ieee, fwrq->m); |
b095c381 JK |
8775 | if (channel == 0) |
8776 | return -EINVAL; | |
8777 | } else | |
8778 | channel = fwrq->m; | |
bf79451e | 8779 | |
b0a4e7d8 | 8780 | if (!(band = libipw_is_valid_channel(priv->ieee, channel))) |
b095c381 | 8781 | return -EINVAL; |
43f66a6c | 8782 | |
1fe0adb4 | 8783 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
b0a4e7d8 | 8784 | i = libipw_channel_to_index(priv->ieee, channel); |
afbf30a2 JK |
8785 | if (i == -1) |
8786 | return -EINVAL; | |
bf79451e | 8787 | |
b0a4e7d8 | 8788 | flags = (band == LIBIPW_24GHZ_BAND) ? |
1fe0adb4 | 8789 | geo->bg[i].flags : geo->a[i].flags; |
b0a4e7d8 | 8790 | if (flags & LIBIPW_CH_PASSIVE_ONLY) { |
afbf30a2 JK |
8791 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
8792 | return -EINVAL; | |
43f66a6c JK |
8793 | } |
8794 | } | |
bf79451e | 8795 | |
43f66a6c | 8796 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
4644151b | 8797 | mutex_lock(&priv->mutex); |
b095c381 | 8798 | ret = ipw_set_channel(priv, channel); |
4644151b | 8799 | mutex_unlock(&priv->mutex); |
c848d0af | 8800 | return ret; |
43f66a6c JK |
8801 | } |
8802 | ||
bf79451e JG |
8803 | static int ipw_wx_get_freq(struct net_device *dev, |
8804 | struct iw_request_info *info, | |
43f66a6c JK |
8805 | union iwreq_data *wrqu, char *extra) |
8806 | { | |
b0a4e7d8 | 8807 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c JK |
8808 | |
8809 | wrqu->freq.e = 0; | |
8810 | ||
8811 | /* If we are associated, trying to associate, or have a statically | |
8812 | * configured CHANNEL then return that; otherwise return ANY */ | |
4644151b | 8813 | mutex_lock(&priv->mutex); |
43f66a6c | 8814 | if (priv->config & CFG_STATIC_CHANNEL || |
c580f67f ZY |
8815 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) { |
8816 | int i; | |
8817 | ||
b0a4e7d8 | 8818 | i = libipw_channel_to_index(priv->ieee, priv->channel); |
c580f67f ZY |
8819 | BUG_ON(i == -1); |
8820 | wrqu->freq.e = 1; | |
8821 | ||
b0a4e7d8 JL |
8822 | switch (libipw_is_valid_channel(priv->ieee, priv->channel)) { |
8823 | case LIBIPW_52GHZ_BAND: | |
c580f67f ZY |
8824 | wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000; |
8825 | break; | |
8826 | ||
b0a4e7d8 | 8827 | case LIBIPW_24GHZ_BAND: |
c580f67f ZY |
8828 | wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000; |
8829 | break; | |
8830 | ||
8831 | default: | |
8832 | BUG(); | |
8833 | } | |
8834 | } else | |
43f66a6c JK |
8835 | wrqu->freq.m = 0; |
8836 | ||
4644151b | 8837 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8838 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
8839 | return 0; | |
8840 | } | |
8841 | ||
bf79451e JG |
8842 | static int ipw_wx_set_mode(struct net_device *dev, |
8843 | struct iw_request_info *info, | |
43f66a6c JK |
8844 | union iwreq_data *wrqu, char *extra) |
8845 | { | |
b0a4e7d8 | 8846 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c JK |
8847 | int err = 0; |
8848 | ||
8849 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); | |
8850 | ||
43f66a6c | 8851 | switch (wrqu->mode) { |
b095c381 | 8852 | #ifdef CONFIG_IPW2200_MONITOR |
43f66a6c JK |
8853 | case IW_MODE_MONITOR: |
8854 | #endif | |
8855 | case IW_MODE_ADHOC: | |
8856 | case IW_MODE_INFRA: | |
8857 | break; | |
8858 | case IW_MODE_AUTO: | |
8859 | wrqu->mode = IW_MODE_INFRA; | |
8860 | break; | |
8861 | default: | |
8862 | return -EINVAL; | |
8863 | } | |
b095c381 JK |
8864 | if (wrqu->mode == priv->ieee->iw_mode) |
8865 | return 0; | |
43f66a6c | 8866 | |
4644151b | 8867 | mutex_lock(&priv->mutex); |
43f66a6c | 8868 | |
afbf30a2 JK |
8869 | ipw_sw_reset(priv, 0); |
8870 | ||
b095c381 | 8871 | #ifdef CONFIG_IPW2200_MONITOR |
bf79451e | 8872 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
43f66a6c | 8873 | priv->net_dev->type = ARPHRD_ETHER; |
bf79451e JG |
8874 | |
8875 | if (wrqu->mode == IW_MODE_MONITOR) | |
459d4087 | 8876 | #ifdef CONFIG_IPW2200_RADIOTAP |
24a47dbd MK |
8877 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
8878 | #else | |
43f66a6c | 8879 | priv->net_dev->type = ARPHRD_IEEE80211; |
24a47dbd | 8880 | #endif |
b095c381 | 8881 | #endif /* CONFIG_IPW2200_MONITOR */ |
bf79451e | 8882 | |
bf79451e | 8883 | /* Free the existing firmware and reset the fw_loaded |
877d0310 | 8884 | * flag so ipw_load() will bring in the new firmware */ |
afbf30a2 | 8885 | free_firmware(); |
43f66a6c JK |
8886 | |
8887 | priv->ieee->iw_mode = wrqu->mode; | |
bf79451e | 8888 | |
c848d0af | 8889 | queue_work(priv->workqueue, &priv->adapter_restart); |
4644151b | 8890 | mutex_unlock(&priv->mutex); |
0edd5b44 | 8891 | return err; |
43f66a6c JK |
8892 | } |
8893 | ||
bf79451e | 8894 | static int ipw_wx_get_mode(struct net_device *dev, |
0edd5b44 JG |
8895 | struct iw_request_info *info, |
8896 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 8897 | { |
b0a4e7d8 | 8898 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 8899 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8900 | wrqu->mode = priv->ieee->iw_mode; |
8901 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); | |
4644151b | 8902 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8903 | return 0; |
8904 | } | |
8905 | ||
43f66a6c JK |
8906 | /* Values are in microsecond */ |
8907 | static const s32 timeout_duration[] = { | |
8908 | 350000, | |
8909 | 250000, | |
8910 | 75000, | |
8911 | 37000, | |
8912 | 25000, | |
8913 | }; | |
8914 | ||
8915 | static const s32 period_duration[] = { | |
8916 | 400000, | |
8917 | 700000, | |
8918 | 1000000, | |
8919 | 1000000, | |
8920 | 1000000 | |
8921 | }; | |
8922 | ||
bf79451e JG |
8923 | static int ipw_wx_get_range(struct net_device *dev, |
8924 | struct iw_request_info *info, | |
43f66a6c JK |
8925 | union iwreq_data *wrqu, char *extra) |
8926 | { | |
b0a4e7d8 | 8927 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c | 8928 | struct iw_range *range = (struct iw_range *)extra; |
b0a4e7d8 | 8929 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
b095c381 | 8930 | int i = 0, j; |
43f66a6c JK |
8931 | |
8932 | wrqu->data.length = sizeof(*range); | |
8933 | memset(range, 0, sizeof(*range)); | |
8934 | ||
8935 | /* 54Mbs == ~27 Mb/s real (802.11g) */ | |
bf79451e | 8936 | range->throughput = 27 * 1000 * 1000; |
43f66a6c JK |
8937 | |
8938 | range->max_qual.qual = 100; | |
8939 | /* TODO: Find real max RSSI and stick here */ | |
8940 | range->max_qual.level = 0; | |
b191608a | 8941 | range->max_qual.noise = 0; |
0edd5b44 | 8942 | range->max_qual.updated = 7; /* Updated all three */ |
43f66a6c JK |
8943 | |
8944 | range->avg_qual.qual = 70; | |
af901ca1 | 8945 | /* TODO: Find real 'good' to 'bad' threshold value for RSSI */ |
0edd5b44 | 8946 | range->avg_qual.level = 0; /* FIXME to real average level */ |
43f66a6c | 8947 | range->avg_qual.noise = 0; |
0edd5b44 | 8948 | range->avg_qual.updated = 7; /* Updated all three */ |
4644151b | 8949 | mutex_lock(&priv->mutex); |
0edd5b44 | 8950 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
43f66a6c | 8951 | |
bf79451e JG |
8952 | for (i = 0; i < range->num_bitrates; i++) |
8953 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * | |
0edd5b44 | 8954 | 500000; |
bf79451e | 8955 | |
43f66a6c JK |
8956 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
8957 | range->min_frag = MIN_FRAG_THRESHOLD; | |
8958 | range->max_frag = MAX_FRAG_THRESHOLD; | |
8959 | ||
8960 | range->encoding_size[0] = 5; | |
bf79451e | 8961 | range->encoding_size[1] = 13; |
43f66a6c JK |
8962 | range->num_encoding_sizes = 2; |
8963 | range->max_encoding_tokens = WEP_KEYS; | |
8964 | ||
8965 | /* Set the Wireless Extension versions */ | |
8966 | range->we_version_compiled = WIRELESS_EXT; | |
f1b50863 | 8967 | range->we_version_source = 18; |
43f66a6c | 8968 | |
b095c381 JK |
8969 | i = 0; |
8970 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { | |
e815de42 ZY |
8971 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { |
8972 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && | |
b0a4e7d8 | 8973 | (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY)) |
e815de42 ZY |
8974 | continue; |
8975 | ||
b095c381 JK |
8976 | range->freq[i].i = geo->bg[j].channel; |
8977 | range->freq[i].m = geo->bg[j].freq * 100000; | |
8978 | range->freq[i].e = 1; | |
e815de42 | 8979 | i++; |
b095c381 JK |
8980 | } |
8981 | } | |
43f66a6c | 8982 | |
b095c381 | 8983 | if (priv->ieee->mode & IEEE_A) { |
e815de42 ZY |
8984 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
8985 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && | |
b0a4e7d8 | 8986 | (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY)) |
e815de42 ZY |
8987 | continue; |
8988 | ||
b095c381 JK |
8989 | range->freq[i].i = geo->a[j].channel; |
8990 | range->freq[i].m = geo->a[j].freq * 100000; | |
8991 | range->freq[i].e = 1; | |
e815de42 | 8992 | i++; |
b095c381 | 8993 | } |
43f66a6c | 8994 | } |
b095c381 JK |
8995 | |
8996 | range->num_channels = i; | |
8997 | range->num_frequency = i; | |
8998 | ||
4644151b | 8999 | mutex_unlock(&priv->mutex); |
97a78ca9 BB |
9000 | |
9001 | /* Event capability (kernel + driver) */ | |
9002 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | | |
9003 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | | |
07f02e46 ZY |
9004 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
9005 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); | |
97a78ca9 | 9006 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
43f66a6c | 9007 | |
f1b50863 DW |
9008 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
9009 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | |
9010 | ||
374fdfbc DW |
9011 | range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE; |
9012 | ||
43f66a6c JK |
9013 | IPW_DEBUG_WX("GET Range\n"); |
9014 | return 0; | |
9015 | } | |
9016 | ||
bf79451e JG |
9017 | static int ipw_wx_set_wap(struct net_device *dev, |
9018 | struct iw_request_info *info, | |
43f66a6c JK |
9019 | union iwreq_data *wrqu, char *extra) |
9020 | { | |
b0a4e7d8 | 9021 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c JK |
9022 | |
9023 | static const unsigned char any[] = { | |
9024 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
9025 | }; | |
9026 | static const unsigned char off[] = { | |
9027 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
9028 | }; | |
9029 | ||
bf79451e | 9030 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
43f66a6c | 9031 | return -EINVAL; |
4644151b | 9032 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9033 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
9034 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { | |
9035 | /* we disable mandatory BSSID association */ | |
9036 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); | |
9037 | priv->config &= ~CFG_STATIC_BSSID; | |
c848d0af JK |
9038 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
9039 | "parameters.\n"); | |
9040 | ipw_associate(priv); | |
4644151b | 9041 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9042 | return 0; |
9043 | } | |
9044 | ||
9045 | priv->config |= CFG_STATIC_BSSID; | |
9046 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { | |
9047 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); | |
4644151b | 9048 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9049 | return 0; |
9050 | } | |
9051 | ||
e174961c JB |
9052 | IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n", |
9053 | wrqu->ap_addr.sa_data); | |
43f66a6c JK |
9054 | |
9055 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); | |
9056 | ||
c848d0af JK |
9057 | /* Network configuration changed -- force [re]association */ |
9058 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); | |
9059 | if (!ipw_disassociate(priv)) | |
43f66a6c | 9060 | ipw_associate(priv); |
43f66a6c | 9061 | |
4644151b | 9062 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9063 | return 0; |
9064 | } | |
9065 | ||
bf79451e JG |
9066 | static int ipw_wx_get_wap(struct net_device *dev, |
9067 | struct iw_request_info *info, | |
43f66a6c JK |
9068 | union iwreq_data *wrqu, char *extra) |
9069 | { | |
b0a4e7d8 | 9070 | struct ipw_priv *priv = libipw_priv(dev); |
0795af57 | 9071 | |
43f66a6c JK |
9072 | /* If we are associated, trying to associate, or have a statically |
9073 | * configured BSSID then return that; otherwise return ANY */ | |
4644151b | 9074 | mutex_lock(&priv->mutex); |
bf79451e | 9075 | if (priv->config & CFG_STATIC_BSSID || |
43f66a6c JK |
9076 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
9077 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; | |
afbf30a2 | 9078 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
43f66a6c JK |
9079 | } else |
9080 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); | |
9081 | ||
e174961c JB |
9082 | IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", |
9083 | wrqu->ap_addr.sa_data); | |
4644151b | 9084 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9085 | return 0; |
9086 | } | |
9087 | ||
bf79451e JG |
9088 | static int ipw_wx_set_essid(struct net_device *dev, |
9089 | struct iw_request_info *info, | |
43f66a6c JK |
9090 | union iwreq_data *wrqu, char *extra) |
9091 | { | |
b0a4e7d8 | 9092 | struct ipw_priv *priv = libipw_priv(dev); |
ab644b0b | 9093 | int length; |
9387b7ca | 9094 | DECLARE_SSID_BUF(ssid); |
ab644b0b ZY |
9095 | |
9096 | mutex_lock(&priv->mutex); | |
43f66a6c | 9097 | |
ab644b0b ZY |
9098 | if (!wrqu->essid.flags) |
9099 | { | |
9100 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); | |
9101 | ipw_disassociate(priv); | |
9102 | priv->config &= ~CFG_STATIC_ESSID; | |
9103 | ipw_associate(priv); | |
9104 | mutex_unlock(&priv->mutex); | |
9105 | return 0; | |
9106 | } | |
43f66a6c | 9107 | |
a9f0d423 | 9108 | length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE); |
43f66a6c JK |
9109 | |
9110 | priv->config |= CFG_STATIC_ESSID; | |
9111 | ||
a9f0d423 ZY |
9112 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length) |
9113 | && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) { | |
43f66a6c | 9114 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); |
4644151b | 9115 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9116 | return 0; |
9117 | } | |
9118 | ||
9387b7ca JL |
9119 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", |
9120 | print_ssid(ssid, extra, length), length); | |
43f66a6c JK |
9121 | |
9122 | priv->essid_len = length; | |
a9f0d423 | 9123 | memcpy(priv->essid, extra, priv->essid_len); |
bf79451e | 9124 | |
c848d0af JK |
9125 | /* Network configuration changed -- force [re]association */ |
9126 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); | |
9127 | if (!ipw_disassociate(priv)) | |
43f66a6c | 9128 | ipw_associate(priv); |
43f66a6c | 9129 | |
4644151b | 9130 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9131 | return 0; |
9132 | } | |
9133 | ||
bf79451e JG |
9134 | static int ipw_wx_get_essid(struct net_device *dev, |
9135 | struct iw_request_info *info, | |
43f66a6c JK |
9136 | union iwreq_data *wrqu, char *extra) |
9137 | { | |
b0a4e7d8 | 9138 | struct ipw_priv *priv = libipw_priv(dev); |
9387b7ca | 9139 | DECLARE_SSID_BUF(ssid); |
43f66a6c JK |
9140 | |
9141 | /* If we are associated, trying to associate, or have a statically | |
9142 | * configured ESSID then return that; otherwise return ANY */ | |
4644151b | 9143 | mutex_lock(&priv->mutex); |
43f66a6c | 9144 | if (priv->config & CFG_STATIC_ESSID || |
bf79451e JG |
9145 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
9146 | IPW_DEBUG_WX("Getting essid: '%s'\n", | |
9387b7ca | 9147 | print_ssid(ssid, priv->essid, priv->essid_len)); |
bf79451e | 9148 | memcpy(extra, priv->essid, priv->essid_len); |
43f66a6c | 9149 | wrqu->essid.length = priv->essid_len; |
0edd5b44 | 9150 | wrqu->essid.flags = 1; /* active */ |
43f66a6c JK |
9151 | } else { |
9152 | IPW_DEBUG_WX("Getting essid: ANY\n"); | |
9153 | wrqu->essid.length = 0; | |
0edd5b44 | 9154 | wrqu->essid.flags = 0; /* active */ |
43f66a6c | 9155 | } |
4644151b | 9156 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9157 | return 0; |
9158 | } | |
9159 | ||
bf79451e JG |
9160 | static int ipw_wx_set_nick(struct net_device *dev, |
9161 | struct iw_request_info *info, | |
43f66a6c | 9162 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9163 | { |
b0a4e7d8 | 9164 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c JK |
9165 | |
9166 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); | |
9167 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) | |
9168 | return -E2BIG; | |
4644151b | 9169 | mutex_lock(&priv->mutex); |
0edd5b44 | 9170 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
43f66a6c | 9171 | memset(priv->nick, 0, sizeof(priv->nick)); |
0edd5b44 | 9172 | memcpy(priv->nick, extra, wrqu->data.length); |
43f66a6c | 9173 | IPW_DEBUG_TRACE("<<\n"); |
4644151b | 9174 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9175 | return 0; |
9176 | ||
9177 | } | |
9178 | ||
bf79451e JG |
9179 | static int ipw_wx_get_nick(struct net_device *dev, |
9180 | struct iw_request_info *info, | |
43f66a6c | 9181 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9182 | { |
b0a4e7d8 | 9183 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c | 9184 | IPW_DEBUG_WX("Getting nick\n"); |
4644151b | 9185 | mutex_lock(&priv->mutex); |
919ee6dd | 9186 | wrqu->data.length = strlen(priv->nick); |
43f66a6c | 9187 | memcpy(extra, priv->nick, wrqu->data.length); |
0edd5b44 | 9188 | wrqu->data.flags = 1; /* active */ |
4644151b | 9189 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9190 | return 0; |
9191 | } | |
9192 | ||
651be26f OH |
9193 | static int ipw_wx_set_sens(struct net_device *dev, |
9194 | struct iw_request_info *info, | |
9195 | union iwreq_data *wrqu, char *extra) | |
9196 | { | |
b0a4e7d8 | 9197 | struct ipw_priv *priv = libipw_priv(dev); |
651be26f OH |
9198 | int err = 0; |
9199 | ||
9200 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); | |
9201 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); | |
9202 | mutex_lock(&priv->mutex); | |
9203 | ||
9204 | if (wrqu->sens.fixed == 0) | |
9205 | { | |
9206 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; | |
9207 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; | |
9208 | goto out; | |
9209 | } | |
9210 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || | |
9211 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { | |
9212 | err = -EINVAL; | |
9213 | goto out; | |
9214 | } | |
9215 | ||
9216 | priv->roaming_threshold = wrqu->sens.value; | |
9217 | priv->disassociate_threshold = 3*wrqu->sens.value; | |
9218 | out: | |
9219 | mutex_unlock(&priv->mutex); | |
9220 | return err; | |
9221 | } | |
9222 | ||
9223 | static int ipw_wx_get_sens(struct net_device *dev, | |
9224 | struct iw_request_info *info, | |
9225 | union iwreq_data *wrqu, char *extra) | |
9226 | { | |
b0a4e7d8 | 9227 | struct ipw_priv *priv = libipw_priv(dev); |
651be26f OH |
9228 | mutex_lock(&priv->mutex); |
9229 | wrqu->sens.fixed = 1; | |
9230 | wrqu->sens.value = priv->roaming_threshold; | |
9231 | mutex_unlock(&priv->mutex); | |
9232 | ||
9233 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", | |
9234 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); | |
9235 | ||
9236 | return 0; | |
9237 | } | |
9238 | ||
43f66a6c JK |
9239 | static int ipw_wx_set_rate(struct net_device *dev, |
9240 | struct iw_request_info *info, | |
9241 | union iwreq_data *wrqu, char *extra) | |
bf79451e | 9242 | { |
ea2b26e0 | 9243 | /* TODO: We should use semaphores or locks for access to priv */ |
b0a4e7d8 | 9244 | struct ipw_priv *priv = libipw_priv(dev); |
ea2b26e0 JK |
9245 | u32 target_rate = wrqu->bitrate.value; |
9246 | u32 fixed, mask; | |
9247 | ||
9248 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ | |
9249 | /* value = X, fixed = 1 means only rate X */ | |
9250 | /* value = X, fixed = 0 means all rates lower equal X */ | |
9251 | ||
9252 | if (target_rate == -1) { | |
9253 | fixed = 0; | |
b0a4e7d8 | 9254 | mask = LIBIPW_DEFAULT_RATES_MASK; |
ea2b26e0 JK |
9255 | /* Now we should reassociate */ |
9256 | goto apply; | |
9257 | } | |
9258 | ||
9259 | mask = 0; | |
9260 | fixed = wrqu->bitrate.fixed; | |
9261 | ||
9262 | if (target_rate == 1000000 || !fixed) | |
b0a4e7d8 | 9263 | mask |= LIBIPW_CCK_RATE_1MB_MASK; |
ea2b26e0 JK |
9264 | if (target_rate == 1000000) |
9265 | goto apply; | |
9266 | ||
9267 | if (target_rate == 2000000 || !fixed) | |
b0a4e7d8 | 9268 | mask |= LIBIPW_CCK_RATE_2MB_MASK; |
ea2b26e0 JK |
9269 | if (target_rate == 2000000) |
9270 | goto apply; | |
9271 | ||
9272 | if (target_rate == 5500000 || !fixed) | |
b0a4e7d8 | 9273 | mask |= LIBIPW_CCK_RATE_5MB_MASK; |
ea2b26e0 JK |
9274 | if (target_rate == 5500000) |
9275 | goto apply; | |
9276 | ||
9277 | if (target_rate == 6000000 || !fixed) | |
b0a4e7d8 | 9278 | mask |= LIBIPW_OFDM_RATE_6MB_MASK; |
ea2b26e0 JK |
9279 | if (target_rate == 6000000) |
9280 | goto apply; | |
9281 | ||
9282 | if (target_rate == 9000000 || !fixed) | |
b0a4e7d8 | 9283 | mask |= LIBIPW_OFDM_RATE_9MB_MASK; |
ea2b26e0 JK |
9284 | if (target_rate == 9000000) |
9285 | goto apply; | |
9286 | ||
9287 | if (target_rate == 11000000 || !fixed) | |
b0a4e7d8 | 9288 | mask |= LIBIPW_CCK_RATE_11MB_MASK; |
ea2b26e0 JK |
9289 | if (target_rate == 11000000) |
9290 | goto apply; | |
9291 | ||
9292 | if (target_rate == 12000000 || !fixed) | |
b0a4e7d8 | 9293 | mask |= LIBIPW_OFDM_RATE_12MB_MASK; |
ea2b26e0 JK |
9294 | if (target_rate == 12000000) |
9295 | goto apply; | |
9296 | ||
9297 | if (target_rate == 18000000 || !fixed) | |
b0a4e7d8 | 9298 | mask |= LIBIPW_OFDM_RATE_18MB_MASK; |
ea2b26e0 JK |
9299 | if (target_rate == 18000000) |
9300 | goto apply; | |
9301 | ||
9302 | if (target_rate == 24000000 || !fixed) | |
b0a4e7d8 | 9303 | mask |= LIBIPW_OFDM_RATE_24MB_MASK; |
ea2b26e0 JK |
9304 | if (target_rate == 24000000) |
9305 | goto apply; | |
9306 | ||
9307 | if (target_rate == 36000000 || !fixed) | |
b0a4e7d8 | 9308 | mask |= LIBIPW_OFDM_RATE_36MB_MASK; |
ea2b26e0 JK |
9309 | if (target_rate == 36000000) |
9310 | goto apply; | |
9311 | ||
9312 | if (target_rate == 48000000 || !fixed) | |
b0a4e7d8 | 9313 | mask |= LIBIPW_OFDM_RATE_48MB_MASK; |
ea2b26e0 JK |
9314 | if (target_rate == 48000000) |
9315 | goto apply; | |
9316 | ||
9317 | if (target_rate == 54000000 || !fixed) | |
b0a4e7d8 | 9318 | mask |= LIBIPW_OFDM_RATE_54MB_MASK; |
ea2b26e0 JK |
9319 | if (target_rate == 54000000) |
9320 | goto apply; | |
9321 | ||
9322 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); | |
9323 | return -EINVAL; | |
9324 | ||
9325 | apply: | |
9326 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", | |
9327 | mask, fixed ? "fixed" : "sub-rates"); | |
4644151b | 9328 | mutex_lock(&priv->mutex); |
b0a4e7d8 | 9329 | if (mask == LIBIPW_DEFAULT_RATES_MASK) { |
ea2b26e0 | 9330 | priv->config &= ~CFG_FIXED_RATE; |
b095c381 JK |
9331 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
9332 | } else | |
ea2b26e0 JK |
9333 | priv->config |= CFG_FIXED_RATE; |
9334 | ||
c848d0af JK |
9335 | if (priv->rates_mask == mask) { |
9336 | IPW_DEBUG_WX("Mask set to current mask.\n"); | |
4644151b | 9337 | mutex_unlock(&priv->mutex); |
c848d0af | 9338 | return 0; |
ea2b26e0 JK |
9339 | } |
9340 | ||
c848d0af JK |
9341 | priv->rates_mask = mask; |
9342 | ||
9343 | /* Network configuration changed -- force [re]association */ | |
9344 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); | |
9345 | if (!ipw_disassociate(priv)) | |
9346 | ipw_associate(priv); | |
9347 | ||
4644151b | 9348 | mutex_unlock(&priv->mutex); |
ea2b26e0 | 9349 | return 0; |
43f66a6c JK |
9350 | } |
9351 | ||
bf79451e JG |
9352 | static int ipw_wx_get_rate(struct net_device *dev, |
9353 | struct iw_request_info *info, | |
43f66a6c | 9354 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9355 | { |
b0a4e7d8 | 9356 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 9357 | mutex_lock(&priv->mutex); |
43f66a6c | 9358 | wrqu->bitrate.value = priv->last_rate; |
455936c7 | 9359 | wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0; |
4644151b | 9360 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9361 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
9362 | return 0; | |
9363 | } | |
9364 | ||
bf79451e JG |
9365 | static int ipw_wx_set_rts(struct net_device *dev, |
9366 | struct iw_request_info *info, | |
43f66a6c | 9367 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9368 | { |
b0a4e7d8 | 9369 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 9370 | mutex_lock(&priv->mutex); |
ea8862dc | 9371 | if (wrqu->rts.disabled || !wrqu->rts.fixed) |
43f66a6c JK |
9372 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
9373 | else { | |
9374 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || | |
c848d0af | 9375 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
4644151b | 9376 | mutex_unlock(&priv->mutex); |
43f66a6c | 9377 | return -EINVAL; |
c848d0af | 9378 | } |
43f66a6c JK |
9379 | priv->rts_threshold = wrqu->rts.value; |
9380 | } | |
9381 | ||
9382 | ipw_send_rts_threshold(priv, priv->rts_threshold); | |
4644151b | 9383 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9384 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
9385 | return 0; | |
9386 | } | |
9387 | ||
bf79451e JG |
9388 | static int ipw_wx_get_rts(struct net_device *dev, |
9389 | struct iw_request_info *info, | |
43f66a6c | 9390 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9391 | { |
b0a4e7d8 | 9392 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 9393 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9394 | wrqu->rts.value = priv->rts_threshold; |
9395 | wrqu->rts.fixed = 0; /* no auto select */ | |
0edd5b44 | 9396 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
4644151b | 9397 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9398 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
9399 | return 0; | |
9400 | } | |
9401 | ||
bf79451e JG |
9402 | static int ipw_wx_set_txpow(struct net_device *dev, |
9403 | struct iw_request_info *info, | |
43f66a6c | 9404 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9405 | { |
b0a4e7d8 | 9406 | struct ipw_priv *priv = libipw_priv(dev); |
6de9f7f2 | 9407 | int err = 0; |
43f66a6c | 9408 | |
4644151b | 9409 | mutex_lock(&priv->mutex); |
c848d0af | 9410 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
6de9f7f2 ZY |
9411 | err = -EINPROGRESS; |
9412 | goto out; | |
43f66a6c | 9413 | } |
43f66a6c | 9414 | |
b095c381 JK |
9415 | if (!wrqu->power.fixed) |
9416 | wrqu->power.value = IPW_TX_POWER_DEFAULT; | |
9417 | ||
c848d0af | 9418 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
6de9f7f2 ZY |
9419 | err = -EINVAL; |
9420 | goto out; | |
c848d0af | 9421 | } |
43f66a6c | 9422 | |
b095c381 | 9423 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
afbf30a2 | 9424 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
6de9f7f2 ZY |
9425 | err = -EINVAL; |
9426 | goto out; | |
c848d0af | 9427 | } |
43f66a6c | 9428 | |
43f66a6c | 9429 | priv->tx_power = wrqu->power.value; |
6de9f7f2 ZY |
9430 | err = ipw_set_tx_power(priv); |
9431 | out: | |
4644151b | 9432 | mutex_unlock(&priv->mutex); |
6de9f7f2 | 9433 | return err; |
43f66a6c JK |
9434 | } |
9435 | ||
bf79451e JG |
9436 | static int ipw_wx_get_txpow(struct net_device *dev, |
9437 | struct iw_request_info *info, | |
43f66a6c | 9438 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9439 | { |
b0a4e7d8 | 9440 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 9441 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9442 | wrqu->power.value = priv->tx_power; |
9443 | wrqu->power.fixed = 1; | |
9444 | wrqu->power.flags = IW_TXPOW_DBM; | |
9445 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; | |
4644151b | 9446 | mutex_unlock(&priv->mutex); |
43f66a6c | 9447 | |
bf79451e | 9448 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
22501c8e | 9449 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
43f66a6c JK |
9450 | |
9451 | return 0; | |
9452 | } | |
9453 | ||
bf79451e | 9454 | static int ipw_wx_set_frag(struct net_device *dev, |
0edd5b44 JG |
9455 | struct iw_request_info *info, |
9456 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9457 | { |
b0a4e7d8 | 9458 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 9459 | mutex_lock(&priv->mutex); |
ea8862dc | 9460 | if (wrqu->frag.disabled || !wrqu->frag.fixed) |
43f66a6c JK |
9461 | priv->ieee->fts = DEFAULT_FTS; |
9462 | else { | |
9463 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || | |
b095c381 | 9464 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
4644151b | 9465 | mutex_unlock(&priv->mutex); |
43f66a6c | 9466 | return -EINVAL; |
b095c381 | 9467 | } |
bf79451e | 9468 | |
43f66a6c JK |
9469 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
9470 | } | |
9471 | ||
9472 | ipw_send_frag_threshold(priv, wrqu->frag.value); | |
4644151b | 9473 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9474 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
9475 | return 0; | |
9476 | } | |
9477 | ||
bf79451e | 9478 | static int ipw_wx_get_frag(struct net_device *dev, |
0edd5b44 JG |
9479 | struct iw_request_info *info, |
9480 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9481 | { |
b0a4e7d8 | 9482 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 9483 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9484 | wrqu->frag.value = priv->ieee->fts; |
9485 | wrqu->frag.fixed = 0; /* no auto select */ | |
0edd5b44 | 9486 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
4644151b | 9487 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9488 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
9489 | ||
9490 | return 0; | |
9491 | } | |
9492 | ||
bf79451e JG |
9493 | static int ipw_wx_set_retry(struct net_device *dev, |
9494 | struct iw_request_info *info, | |
43f66a6c | 9495 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9496 | { |
b0a4e7d8 | 9497 | struct ipw_priv *priv = libipw_priv(dev); |
afbf30a2 JK |
9498 | |
9499 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) | |
9500 | return -EINVAL; | |
9501 | ||
9502 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) | |
9503 | return 0; | |
9504 | ||
d5f7ac20 | 9505 | if (wrqu->retry.value < 0 || wrqu->retry.value >= 255) |
afbf30a2 JK |
9506 | return -EINVAL; |
9507 | ||
4644151b | 9508 | mutex_lock(&priv->mutex); |
919ee6dd | 9509 | if (wrqu->retry.flags & IW_RETRY_SHORT) |
afbf30a2 | 9510 | priv->short_retry_limit = (u8) wrqu->retry.value; |
919ee6dd | 9511 | else if (wrqu->retry.flags & IW_RETRY_LONG) |
afbf30a2 JK |
9512 | priv->long_retry_limit = (u8) wrqu->retry.value; |
9513 | else { | |
9514 | priv->short_retry_limit = (u8) wrqu->retry.value; | |
9515 | priv->long_retry_limit = (u8) wrqu->retry.value; | |
9516 | } | |
9517 | ||
9518 | ipw_send_retry_limit(priv, priv->short_retry_limit, | |
9519 | priv->long_retry_limit); | |
4644151b | 9520 | mutex_unlock(&priv->mutex); |
afbf30a2 JK |
9521 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
9522 | priv->short_retry_limit, priv->long_retry_limit); | |
9523 | return 0; | |
43f66a6c JK |
9524 | } |
9525 | ||
bf79451e JG |
9526 | static int ipw_wx_get_retry(struct net_device *dev, |
9527 | struct iw_request_info *info, | |
43f66a6c | 9528 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9529 | { |
b0a4e7d8 | 9530 | struct ipw_priv *priv = libipw_priv(dev); |
afbf30a2 | 9531 | |
4644151b | 9532 | mutex_lock(&priv->mutex); |
afbf30a2 JK |
9533 | wrqu->retry.disabled = 0; |
9534 | ||
9535 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { | |
4644151b | 9536 | mutex_unlock(&priv->mutex); |
afbf30a2 JK |
9537 | return -EINVAL; |
9538 | } | |
9539 | ||
919ee6dd JT |
9540 | if (wrqu->retry.flags & IW_RETRY_LONG) { |
9541 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG; | |
afbf30a2 | 9542 | wrqu->retry.value = priv->long_retry_limit; |
919ee6dd JT |
9543 | } else if (wrqu->retry.flags & IW_RETRY_SHORT) { |
9544 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT; | |
afbf30a2 JK |
9545 | wrqu->retry.value = priv->short_retry_limit; |
9546 | } else { | |
9547 | wrqu->retry.flags = IW_RETRY_LIMIT; | |
9548 | wrqu->retry.value = priv->short_retry_limit; | |
9549 | } | |
4644151b | 9550 | mutex_unlock(&priv->mutex); |
afbf30a2 JK |
9551 | |
9552 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); | |
9553 | ||
9554 | return 0; | |
9555 | } | |
9556 | ||
bf79451e JG |
9557 | static int ipw_wx_set_scan(struct net_device *dev, |
9558 | struct iw_request_info *info, | |
43f66a6c JK |
9559 | union iwreq_data *wrqu, char *extra) |
9560 | { | |
b0a4e7d8 | 9561 | struct ipw_priv *priv = libipw_priv(dev); |
094c4d2d | 9562 | struct iw_scan_req *req = (struct iw_scan_req *)extra; |
ea177305 | 9563 | struct delayed_work *work = NULL; |
094c4d2d | 9564 | |
0b531676 | 9565 | mutex_lock(&priv->mutex); |
ea177305 | 9566 | |
0b531676 | 9567 | priv->user_requested_scan = 1; |
0b531676 | 9568 | |
094c4d2d | 9569 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { |
afbf30a2 | 9570 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
ea177305 DW |
9571 | int len = min((int)req->essid_len, |
9572 | (int)sizeof(priv->direct_scan_ssid)); | |
9573 | memcpy(priv->direct_scan_ssid, req->essid, len); | |
9574 | priv->direct_scan_ssid_len = len; | |
9575 | work = &priv->request_direct_scan; | |
9576 | } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { | |
9577 | work = &priv->request_passive_scan; | |
094c4d2d | 9578 | } |
ea177305 DW |
9579 | } else { |
9580 | /* Normal active broadcast scan */ | |
9581 | work = &priv->request_scan; | |
afbf30a2 | 9582 | } |
8935f39e | 9583 | |
ea177305 DW |
9584 | mutex_unlock(&priv->mutex); |
9585 | ||
43f66a6c | 9586 | IPW_DEBUG_WX("Start scan\n"); |
b095c381 | 9587 | |
ea177305 | 9588 | queue_delayed_work(priv->workqueue, work, 0); |
b095c381 | 9589 | |
43f66a6c JK |
9590 | return 0; |
9591 | } | |
9592 | ||
bf79451e JG |
9593 | static int ipw_wx_get_scan(struct net_device *dev, |
9594 | struct iw_request_info *info, | |
43f66a6c | 9595 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9596 | { |
b0a4e7d8 JL |
9597 | struct ipw_priv *priv = libipw_priv(dev); |
9598 | return libipw_wx_get_scan(priv->ieee, info, wrqu, extra); | |
43f66a6c JK |
9599 | } |
9600 | ||
bf79451e | 9601 | static int ipw_wx_set_encode(struct net_device *dev, |
0edd5b44 JG |
9602 | struct iw_request_info *info, |
9603 | union iwreq_data *wrqu, char *key) | |
43f66a6c | 9604 | { |
b0a4e7d8 | 9605 | struct ipw_priv *priv = libipw_priv(dev); |
afbf30a2 | 9606 | int ret; |
caeff81b | 9607 | u32 cap = priv->capability; |
afbf30a2 | 9608 | |
4644151b | 9609 | mutex_lock(&priv->mutex); |
b0a4e7d8 | 9610 | ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key); |
afbf30a2 | 9611 | |
caeff81b HL |
9612 | /* In IBSS mode, we need to notify the firmware to update |
9613 | * the beacon info after we changed the capability. */ | |
9614 | if (cap != priv->capability && | |
9615 | priv->ieee->iw_mode == IW_MODE_ADHOC && | |
9616 | priv->status & STATUS_ASSOCIATED) | |
9617 | ipw_disassociate(priv); | |
9618 | ||
4644151b | 9619 | mutex_unlock(&priv->mutex); |
afbf30a2 | 9620 | return ret; |
43f66a6c JK |
9621 | } |
9622 | ||
bf79451e | 9623 | static int ipw_wx_get_encode(struct net_device *dev, |
0edd5b44 JG |
9624 | struct iw_request_info *info, |
9625 | union iwreq_data *wrqu, char *key) | |
43f66a6c | 9626 | { |
b0a4e7d8 JL |
9627 | struct ipw_priv *priv = libipw_priv(dev); |
9628 | return libipw_wx_get_encode(priv->ieee, info, wrqu, key); | |
43f66a6c JK |
9629 | } |
9630 | ||
bf79451e | 9631 | static int ipw_wx_set_power(struct net_device *dev, |
0edd5b44 JG |
9632 | struct iw_request_info *info, |
9633 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9634 | { |
b0a4e7d8 | 9635 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c | 9636 | int err; |
4644151b | 9637 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9638 | if (wrqu->power.disabled) { |
9639 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | |
9640 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); | |
9641 | if (err) { | |
9642 | IPW_DEBUG_WX("failed setting power mode.\n"); | |
4644151b | 9643 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9644 | return err; |
9645 | } | |
43f66a6c | 9646 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
4644151b | 9647 | mutex_unlock(&priv->mutex); |
43f66a6c | 9648 | return 0; |
bf79451e | 9649 | } |
43f66a6c JK |
9650 | |
9651 | switch (wrqu->power.flags & IW_POWER_MODE) { | |
0edd5b44 JG |
9652 | case IW_POWER_ON: /* If not specified */ |
9653 | case IW_POWER_MODE: /* If set all mask */ | |
c03983ac | 9654 | case IW_POWER_ALL_R: /* If explicitly state all */ |
43f66a6c | 9655 | break; |
0edd5b44 | 9656 | default: /* Otherwise we don't support it */ |
43f66a6c JK |
9657 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
9658 | wrqu->power.flags); | |
4644151b | 9659 | mutex_unlock(&priv->mutex); |
bf79451e | 9660 | return -EOPNOTSUPP; |
43f66a6c | 9661 | } |
bf79451e | 9662 | |
43f66a6c JK |
9663 | /* If the user hasn't specified a power management mode yet, default |
9664 | * to BATTERY */ | |
0edd5b44 | 9665 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
43f66a6c | 9666 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
bf79451e | 9667 | else |
43f66a6c | 9668 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
4e157f08 | 9669 | |
43f66a6c JK |
9670 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); |
9671 | if (err) { | |
9672 | IPW_DEBUG_WX("failed setting power mode.\n"); | |
4644151b | 9673 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9674 | return err; |
9675 | } | |
9676 | ||
0edd5b44 | 9677 | IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); |
4644151b | 9678 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9679 | return 0; |
9680 | } | |
9681 | ||
bf79451e | 9682 | static int ipw_wx_get_power(struct net_device *dev, |
0edd5b44 JG |
9683 | struct iw_request_info *info, |
9684 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9685 | { |
b0a4e7d8 | 9686 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 9687 | mutex_lock(&priv->mutex); |
a613bffd | 9688 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
43f66a6c | 9689 | wrqu->power.disabled = 1; |
a613bffd | 9690 | else |
43f66a6c | 9691 | wrqu->power.disabled = 0; |
43f66a6c | 9692 | |
4644151b | 9693 | mutex_unlock(&priv->mutex); |
43f66a6c | 9694 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
bf79451e | 9695 | |
43f66a6c JK |
9696 | return 0; |
9697 | } | |
9698 | ||
bf79451e | 9699 | static int ipw_wx_set_powermode(struct net_device *dev, |
0edd5b44 JG |
9700 | struct iw_request_info *info, |
9701 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9702 | { |
b0a4e7d8 | 9703 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c JK |
9704 | int mode = *(int *)extra; |
9705 | int err; | |
4e157f08 | 9706 | |
4644151b | 9707 | mutex_lock(&priv->mutex); |
4e157f08 | 9708 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) |
43f66a6c | 9709 | mode = IPW_POWER_AC; |
bf79451e | 9710 | |
4e157f08 | 9711 | if (IPW_POWER_LEVEL(priv->power_mode) != mode) { |
43f66a6c | 9712 | err = ipw_send_power_mode(priv, mode); |
43f66a6c JK |
9713 | if (err) { |
9714 | IPW_DEBUG_WX("failed setting power mode.\n"); | |
4644151b | 9715 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9716 | return err; |
9717 | } | |
4e157f08 | 9718 | priv->power_mode = IPW_POWER_ENABLED | mode; |
43f66a6c | 9719 | } |
4644151b | 9720 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9721 | return 0; |
9722 | } | |
9723 | ||
9724 | #define MAX_WX_STRING 80 | |
bf79451e | 9725 | static int ipw_wx_get_powermode(struct net_device *dev, |
0edd5b44 JG |
9726 | struct iw_request_info *info, |
9727 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9728 | { |
b0a4e7d8 | 9729 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c JK |
9730 | int level = IPW_POWER_LEVEL(priv->power_mode); |
9731 | char *p = extra; | |
9732 | ||
9733 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); | |
9734 | ||
9735 | switch (level) { | |
9736 | case IPW_POWER_AC: | |
9737 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); | |
9738 | break; | |
9739 | case IPW_POWER_BATTERY: | |
9740 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); | |
9741 | break; | |
9742 | default: | |
9743 | p += snprintf(p, MAX_WX_STRING - (p - extra), | |
bf79451e | 9744 | "(Timeout %dms, Period %dms)", |
43f66a6c JK |
9745 | timeout_duration[level - 1] / 1000, |
9746 | period_duration[level - 1] / 1000); | |
9747 | } | |
9748 | ||
9749 | if (!(priv->power_mode & IPW_POWER_ENABLED)) | |
0edd5b44 | 9750 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
43f66a6c JK |
9751 | |
9752 | wrqu->data.length = p - extra + 1; | |
9753 | ||
9754 | return 0; | |
9755 | } | |
9756 | ||
9757 | static int ipw_wx_set_wireless_mode(struct net_device *dev, | |
0edd5b44 JG |
9758 | struct iw_request_info *info, |
9759 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9760 | { |
b0a4e7d8 | 9761 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c JK |
9762 | int mode = *(int *)extra; |
9763 | u8 band = 0, modulation = 0; | |
9764 | ||
9765 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { | |
0edd5b44 | 9766 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
43f66a6c JK |
9767 | return -EINVAL; |
9768 | } | |
4644151b | 9769 | mutex_lock(&priv->mutex); |
43f66a6c | 9770 | if (priv->adapter == IPW_2915ABG) { |
a33a1982 | 9771 | priv->ieee->abg_true = 1; |
43f66a6c | 9772 | if (mode & IEEE_A) { |
b0a4e7d8 JL |
9773 | band |= LIBIPW_52GHZ_BAND; |
9774 | modulation |= LIBIPW_OFDM_MODULATION; | |
43f66a6c | 9775 | } else |
a33a1982 | 9776 | priv->ieee->abg_true = 0; |
43f66a6c JK |
9777 | } else { |
9778 | if (mode & IEEE_A) { | |
9779 | IPW_WARNING("Attempt to set 2200BG into " | |
9780 | "802.11a mode\n"); | |
4644151b | 9781 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9782 | return -EINVAL; |
9783 | } | |
9784 | ||
a33a1982 | 9785 | priv->ieee->abg_true = 0; |
43f66a6c JK |
9786 | } |
9787 | ||
9788 | if (mode & IEEE_B) { | |
b0a4e7d8 JL |
9789 | band |= LIBIPW_24GHZ_BAND; |
9790 | modulation |= LIBIPW_CCK_MODULATION; | |
43f66a6c | 9791 | } else |
a33a1982 | 9792 | priv->ieee->abg_true = 0; |
bf79451e | 9793 | |
43f66a6c | 9794 | if (mode & IEEE_G) { |
b0a4e7d8 JL |
9795 | band |= LIBIPW_24GHZ_BAND; |
9796 | modulation |= LIBIPW_OFDM_MODULATION; | |
43f66a6c | 9797 | } else |
a33a1982 | 9798 | priv->ieee->abg_true = 0; |
43f66a6c JK |
9799 | |
9800 | priv->ieee->mode = mode; | |
9801 | priv->ieee->freq_band = band; | |
9802 | priv->ieee->modulation = modulation; | |
0edd5b44 | 9803 | init_supported_rates(priv, &priv->rates); |
43f66a6c | 9804 | |
c848d0af JK |
9805 | /* Network configuration changed -- force [re]association */ |
9806 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); | |
9807 | if (!ipw_disassociate(priv)) { | |
43f66a6c | 9808 | ipw_send_supported_rates(priv, &priv->rates); |
c848d0af JK |
9809 | ipw_associate(priv); |
9810 | } | |
43f66a6c | 9811 | |
a613bffd JK |
9812 | /* Update the band LEDs */ |
9813 | ipw_led_band_on(priv); | |
43f66a6c | 9814 | |
bf79451e | 9815 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
43f66a6c | 9816 | mode & IEEE_A ? 'a' : '.', |
0edd5b44 | 9817 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
4644151b | 9818 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9819 | return 0; |
9820 | } | |
9821 | ||
9822 | static int ipw_wx_get_wireless_mode(struct net_device *dev, | |
0edd5b44 JG |
9823 | struct iw_request_info *info, |
9824 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9825 | { |
b0a4e7d8 | 9826 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 9827 | mutex_lock(&priv->mutex); |
ea2b26e0 JK |
9828 | switch (priv->ieee->mode) { |
9829 | case IEEE_A: | |
43f66a6c JK |
9830 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
9831 | break; | |
ea2b26e0 JK |
9832 | case IEEE_B: |
9833 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); | |
9834 | break; | |
9835 | case IEEE_A | IEEE_B: | |
9836 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); | |
9837 | break; | |
9838 | case IEEE_G: | |
9839 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); | |
9840 | break; | |
9841 | case IEEE_A | IEEE_G: | |
9842 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); | |
9843 | break; | |
9844 | case IEEE_B | IEEE_G: | |
9845 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); | |
9846 | break; | |
9847 | case IEEE_A | IEEE_B | IEEE_G: | |
9848 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); | |
9849 | break; | |
9850 | default: | |
9851 | strncpy(extra, "unknown", MAX_WX_STRING); | |
43f66a6c | 9852 | break; |
bf79451e JG |
9853 | } |
9854 | ||
43f66a6c JK |
9855 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
9856 | ||
0edd5b44 | 9857 | wrqu->data.length = strlen(extra) + 1; |
4644151b | 9858 | mutex_unlock(&priv->mutex); |
b095c381 JK |
9859 | |
9860 | return 0; | |
9861 | } | |
9862 | ||
9863 | static int ipw_wx_set_preamble(struct net_device *dev, | |
9864 | struct iw_request_info *info, | |
9865 | union iwreq_data *wrqu, char *extra) | |
9866 | { | |
b0a4e7d8 | 9867 | struct ipw_priv *priv = libipw_priv(dev); |
b095c381 | 9868 | int mode = *(int *)extra; |
4644151b | 9869 | mutex_lock(&priv->mutex); |
b095c381 JK |
9870 | /* Switching from SHORT -> LONG requires a disassociation */ |
9871 | if (mode == 1) { | |
9872 | if (!(priv->config & CFG_PREAMBLE_LONG)) { | |
9873 | priv->config |= CFG_PREAMBLE_LONG; | |
9874 | ||
9875 | /* Network configuration changed -- force [re]association */ | |
9876 | IPW_DEBUG_ASSOC | |
9877 | ("[re]association triggered due to preamble change.\n"); | |
9878 | if (!ipw_disassociate(priv)) | |
9879 | ipw_associate(priv); | |
9880 | } | |
9881 | goto done; | |
9882 | } | |
43f66a6c | 9883 | |
b095c381 JK |
9884 | if (mode == 0) { |
9885 | priv->config &= ~CFG_PREAMBLE_LONG; | |
9886 | goto done; | |
9887 | } | |
4644151b | 9888 | mutex_unlock(&priv->mutex); |
b095c381 JK |
9889 | return -EINVAL; |
9890 | ||
9891 | done: | |
4644151b | 9892 | mutex_unlock(&priv->mutex); |
b095c381 JK |
9893 | return 0; |
9894 | } | |
9895 | ||
9896 | static int ipw_wx_get_preamble(struct net_device *dev, | |
9897 | struct iw_request_info *info, | |
9898 | union iwreq_data *wrqu, char *extra) | |
9899 | { | |
b0a4e7d8 | 9900 | struct ipw_priv *priv = libipw_priv(dev); |
4644151b | 9901 | mutex_lock(&priv->mutex); |
b095c381 JK |
9902 | if (priv->config & CFG_PREAMBLE_LONG) |
9903 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); | |
9904 | else | |
9905 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); | |
4644151b | 9906 | mutex_unlock(&priv->mutex); |
0edd5b44 | 9907 | return 0; |
43f66a6c JK |
9908 | } |
9909 | ||
b095c381 JK |
9910 | #ifdef CONFIG_IPW2200_MONITOR |
9911 | static int ipw_wx_set_monitor(struct net_device *dev, | |
bf79451e | 9912 | struct iw_request_info *info, |
43f66a6c | 9913 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9914 | { |
b0a4e7d8 | 9915 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c JK |
9916 | int *parms = (int *)extra; |
9917 | int enable = (parms[0] > 0); | |
4644151b | 9918 | mutex_lock(&priv->mutex); |
b095c381 | 9919 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
43f66a6c JK |
9920 | if (enable) { |
9921 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { | |
459d4087 | 9922 | #ifdef CONFIG_IPW2200_RADIOTAP |
24a47dbd MK |
9923 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; |
9924 | #else | |
43f66a6c | 9925 | priv->net_dev->type = ARPHRD_IEEE80211; |
24a47dbd | 9926 | #endif |
b095c381 | 9927 | queue_work(priv->workqueue, &priv->adapter_restart); |
43f66a6c | 9928 | } |
bf79451e | 9929 | |
43f66a6c JK |
9930 | ipw_set_channel(priv, parms[1]); |
9931 | } else { | |
b095c381 | 9932 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
4644151b | 9933 | mutex_unlock(&priv->mutex); |
43f66a6c | 9934 | return 0; |
b095c381 | 9935 | } |
43f66a6c | 9936 | priv->net_dev->type = ARPHRD_ETHER; |
b095c381 | 9937 | queue_work(priv->workqueue, &priv->adapter_restart); |
43f66a6c | 9938 | } |
4644151b | 9939 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9940 | return 0; |
9941 | } | |
9942 | ||
67fd6b45 | 9943 | #endif /* CONFIG_IPW2200_MONITOR */ |
b095c381 | 9944 | |
bf79451e JG |
9945 | static int ipw_wx_reset(struct net_device *dev, |
9946 | struct iw_request_info *info, | |
43f66a6c | 9947 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9948 | { |
b0a4e7d8 | 9949 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c | 9950 | IPW_DEBUG_WX("RESET\n"); |
b095c381 JK |
9951 | queue_work(priv->workqueue, &priv->adapter_restart); |
9952 | return 0; | |
9953 | } | |
9954 | ||
b095c381 JK |
9955 | static int ipw_wx_sw_reset(struct net_device *dev, |
9956 | struct iw_request_info *info, | |
9957 | union iwreq_data *wrqu, char *extra) | |
ea2b26e0 | 9958 | { |
b0a4e7d8 | 9959 | struct ipw_priv *priv = libipw_priv(dev); |
b095c381 JK |
9960 | union iwreq_data wrqu_sec = { |
9961 | .encoding = { | |
9962 | .flags = IW_ENCODE_DISABLED, | |
9963 | }, | |
9964 | }; | |
afbf30a2 | 9965 | int ret; |
c848d0af | 9966 | |
b095c381 | 9967 | IPW_DEBUG_WX("SW_RESET\n"); |
ea2b26e0 | 9968 | |
4644151b | 9969 | mutex_lock(&priv->mutex); |
ea2b26e0 | 9970 | |
d6d5b5c1 | 9971 | ret = ipw_sw_reset(priv, 2); |
afbf30a2 JK |
9972 | if (!ret) { |
9973 | free_firmware(); | |
9974 | ipw_adapter_restart(priv); | |
9975 | } | |
ea2b26e0 | 9976 | |
b095c381 JK |
9977 | /* The SW reset bit might have been toggled on by the 'disable' |
9978 | * module parameter, so take appropriate action */ | |
9979 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); | |
ea2b26e0 | 9980 | |
4644151b | 9981 | mutex_unlock(&priv->mutex); |
b0a4e7d8 | 9982 | libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
4644151b | 9983 | mutex_lock(&priv->mutex); |
bf79451e | 9984 | |
b095c381 JK |
9985 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
9986 | /* Configuration likely changed -- force [re]association */ | |
9987 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " | |
9988 | "reset.\n"); | |
9989 | if (!ipw_disassociate(priv)) | |
9990 | ipw_associate(priv); | |
43f66a6c | 9991 | } |
b095c381 | 9992 | |
4644151b | 9993 | mutex_unlock(&priv->mutex); |
43f66a6c | 9994 | |
43f66a6c JK |
9995 | return 0; |
9996 | } | |
43f66a6c JK |
9997 | |
9998 | /* Rebase the WE IOCTLs to zero for the handler array */ | |
9999 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] | |
0edd5b44 | 10000 | static iw_handler ipw_wx_handlers[] = { |
a3caa99e | 10001 | IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname, |
ea2b26e0 JK |
10002 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, |
10003 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, | |
10004 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, | |
10005 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, | |
651be26f OH |
10006 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, |
10007 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, | |
ea2b26e0 JK |
10008 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
10009 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, | |
10010 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, | |
10011 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, | |
10012 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, | |
10013 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, | |
10014 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, | |
10015 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, | |
10016 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, | |
10017 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, | |
10018 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, | |
10019 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, | |
10020 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, | |
10021 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, | |
10022 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, | |
10023 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, | |
10024 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, | |
10025 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, | |
10026 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, | |
10027 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, | |
10028 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, | |
10029 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, | |
10030 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, | |
a613bffd JK |
10031 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
10032 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, | |
10033 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, | |
10034 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, | |
afbf30a2 JK |
10035 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
10036 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, | |
10037 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, | |
10038 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, | |
10039 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, | |
10040 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, | |
10041 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, | |
43f66a6c JK |
10042 | }; |
10043 | ||
b095c381 JK |
10044 | enum { |
10045 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, | |
10046 | IPW_PRIV_GET_POWER, | |
10047 | IPW_PRIV_SET_MODE, | |
10048 | IPW_PRIV_GET_MODE, | |
10049 | IPW_PRIV_SET_PREAMBLE, | |
10050 | IPW_PRIV_GET_PREAMBLE, | |
10051 | IPW_PRIV_RESET, | |
10052 | IPW_PRIV_SW_RESET, | |
10053 | #ifdef CONFIG_IPW2200_MONITOR | |
10054 | IPW_PRIV_SET_MONITOR, | |
10055 | #endif | |
10056 | }; | |
43f66a6c | 10057 | |
bf79451e | 10058 | static struct iw_priv_args ipw_priv_args[] = { |
43f66a6c | 10059 | { |
0edd5b44 JG |
10060 | .cmd = IPW_PRIV_SET_POWER, |
10061 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
10062 | .name = "set_power"}, | |
43f66a6c | 10063 | { |
0edd5b44 JG |
10064 | .cmd = IPW_PRIV_GET_POWER, |
10065 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, | |
10066 | .name = "get_power"}, | |
43f66a6c | 10067 | { |
0edd5b44 JG |
10068 | .cmd = IPW_PRIV_SET_MODE, |
10069 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
10070 | .name = "set_mode"}, | |
43f66a6c | 10071 | { |
0edd5b44 JG |
10072 | .cmd = IPW_PRIV_GET_MODE, |
10073 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, | |
10074 | .name = "get_mode"}, | |
43f66a6c | 10075 | { |
ea2b26e0 JK |
10076 | .cmd = IPW_PRIV_SET_PREAMBLE, |
10077 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
10078 | .name = "set_preamble"}, | |
10079 | { | |
10080 | .cmd = IPW_PRIV_GET_PREAMBLE, | |
10081 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, | |
10082 | .name = "get_preamble"}, | |
43f66a6c | 10083 | { |
0edd5b44 JG |
10084 | IPW_PRIV_RESET, |
10085 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, | |
b095c381 JK |
10086 | { |
10087 | IPW_PRIV_SW_RESET, | |
10088 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, | |
10089 | #ifdef CONFIG_IPW2200_MONITOR | |
10090 | { | |
10091 | IPW_PRIV_SET_MONITOR, | |
10092 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, | |
10093 | #endif /* CONFIG_IPW2200_MONITOR */ | |
43f66a6c JK |
10094 | }; |
10095 | ||
10096 | static iw_handler ipw_priv_handler[] = { | |
10097 | ipw_wx_set_powermode, | |
10098 | ipw_wx_get_powermode, | |
10099 | ipw_wx_set_wireless_mode, | |
10100 | ipw_wx_get_wireless_mode, | |
ea2b26e0 JK |
10101 | ipw_wx_set_preamble, |
10102 | ipw_wx_get_preamble, | |
bf79451e | 10103 | ipw_wx_reset, |
b095c381 JK |
10104 | ipw_wx_sw_reset, |
10105 | #ifdef CONFIG_IPW2200_MONITOR | |
10106 | ipw_wx_set_monitor, | |
43f66a6c JK |
10107 | #endif |
10108 | }; | |
10109 | ||
0edd5b44 | 10110 | static struct iw_handler_def ipw_wx_handler_def = { |
ea2b26e0 JK |
10111 | .standard = ipw_wx_handlers, |
10112 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), | |
10113 | .num_private = ARRAY_SIZE(ipw_priv_handler), | |
10114 | .num_private_args = ARRAY_SIZE(ipw_priv_args), | |
10115 | .private = ipw_priv_handler, | |
10116 | .private_args = ipw_priv_args, | |
97a78ca9 | 10117 | .get_wireless_stats = ipw_get_wireless_stats, |
43f66a6c JK |
10118 | }; |
10119 | ||
43f66a6c JK |
10120 | /* |
10121 | * Get wireless statistics. | |
10122 | * Called by /proc/net/wireless | |
10123 | * Also called by SIOCGIWSTATS | |
10124 | */ | |
0edd5b44 | 10125 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
43f66a6c | 10126 | { |
b0a4e7d8 | 10127 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c | 10128 | struct iw_statistics *wstats; |
bf79451e | 10129 | |
43f66a6c JK |
10130 | wstats = &priv->wstats; |
10131 | ||
ea2b26e0 | 10132 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
afbf30a2 | 10133 | * netdev->get_wireless_stats seems to be called before fw is |
43f66a6c JK |
10134 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
10135 | * and associated; if not associcated, the values are all meaningless | |
10136 | * anyway, so set them all to NULL and INVALID */ | |
10137 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
10138 | wstats->miss.beacon = 0; | |
10139 | wstats->discard.retries = 0; | |
10140 | wstats->qual.qual = 0; | |
10141 | wstats->qual.level = 0; | |
10142 | wstats->qual.noise = 0; | |
10143 | wstats->qual.updated = 7; | |
10144 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | | |
0edd5b44 | 10145 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
43f66a6c | 10146 | return wstats; |
bf79451e | 10147 | } |
43f66a6c JK |
10148 | |
10149 | wstats->qual.qual = priv->quality; | |
00d21de5 ZY |
10150 | wstats->qual.level = priv->exp_avg_rssi; |
10151 | wstats->qual.noise = priv->exp_avg_noise; | |
43f66a6c | 10152 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | |
b191608a | 10153 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
43f66a6c JK |
10154 | |
10155 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); | |
10156 | wstats->discard.retries = priv->last_tx_failures; | |
10157 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; | |
bf79451e | 10158 | |
43f66a6c JK |
10159 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
10160 | goto fail_get_ordinal; | |
10161 | wstats->discard.retries += tx_retry; */ | |
bf79451e | 10162 | |
43f66a6c JK |
10163 | return wstats; |
10164 | } | |
10165 | ||
43f66a6c JK |
10166 | /* net device stuff */ |
10167 | ||
858119e1 | 10168 | static void init_sys_config(struct ipw_sys_config *sys_config) |
43f66a6c | 10169 | { |
0edd5b44 | 10170 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
810dabd4 | 10171 | sys_config->bt_coexistence = 0; |
43f66a6c JK |
10172 | sys_config->answer_broadcast_ssid_probe = 0; |
10173 | sys_config->accept_all_data_frames = 0; | |
10174 | sys_config->accept_non_directed_frames = 1; | |
10175 | sys_config->exclude_unicast_unencrypted = 0; | |
10176 | sys_config->disable_unicast_decryption = 1; | |
10177 | sys_config->exclude_multicast_unencrypted = 0; | |
10178 | sys_config->disable_multicast_decryption = 1; | |
d2b83e12 ZY |
10179 | if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B) |
10180 | antenna = CFG_SYS_ANTENNA_BOTH; | |
10181 | sys_config->antenna_diversity = antenna; | |
0edd5b44 | 10182 | sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */ |
43f66a6c | 10183 | sys_config->dot11g_auto_detection = 0; |
bf79451e | 10184 | sys_config->enable_cts_to_self = 0; |
43f66a6c | 10185 | sys_config->bt_coexist_collision_thr = 0; |
67fd6b45 | 10186 | sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */ |
12977154 | 10187 | sys_config->silence_threshold = 0x1e; |
43f66a6c JK |
10188 | } |
10189 | ||
10190 | static int ipw_net_open(struct net_device *dev) | |
10191 | { | |
43f66a6c | 10192 | IPW_DEBUG_INFO("dev->open\n"); |
521c4d96 | 10193 | netif_start_queue(dev); |
43f66a6c JK |
10194 | return 0; |
10195 | } | |
10196 | ||
10197 | static int ipw_net_stop(struct net_device *dev) | |
10198 | { | |
10199 | IPW_DEBUG_INFO("dev->close\n"); | |
10200 | netif_stop_queue(dev); | |
10201 | return 0; | |
10202 | } | |
10203 | ||
10204 | /* | |
10205 | todo: | |
10206 | ||
10207 | modify to send one tfd per fragment instead of using chunking. otherwise | |
b0a4e7d8 | 10208 | we need to heavily modify the libipw_skb_to_txb. |
43f66a6c JK |
10209 | */ |
10210 | ||
b0a4e7d8 | 10211 | static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb, |
227d2dc1 | 10212 | int pri) |
43f66a6c | 10213 | { |
b0a4e7d8 | 10214 | struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *) |
0edd5b44 | 10215 | txb->fragments[0]->data; |
43f66a6c JK |
10216 | int i = 0; |
10217 | struct tfd_frame *tfd; | |
e43e3c1e | 10218 | #ifdef CONFIG_IPW2200_QOS |
b095c381 JK |
10219 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
10220 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; | |
10221 | #else | |
43f66a6c | 10222 | struct clx2_tx_queue *txq = &priv->txq[0]; |
b095c381 | 10223 | #endif |
43f66a6c JK |
10224 | struct clx2_queue *q = &txq->q; |
10225 | u8 id, hdr_len, unicast; | |
c848d0af | 10226 | int fc; |
43f66a6c | 10227 | |
b8ddafd7 ZY |
10228 | if (!(priv->status & STATUS_ASSOCIATED)) |
10229 | goto drop; | |
10230 | ||
b0a4e7d8 | 10231 | hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl)); |
43f66a6c JK |
10232 | switch (priv->ieee->iw_mode) { |
10233 | case IW_MODE_ADHOC: | |
3c19065a | 10234 | unicast = !is_multicast_ether_addr(hdr->addr1); |
43f66a6c JK |
10235 | id = ipw_find_station(priv, hdr->addr1); |
10236 | if (id == IPW_INVALID_STATION) { | |
10237 | id = ipw_add_station(priv, hdr->addr1); | |
10238 | if (id == IPW_INVALID_STATION) { | |
10239 | IPW_WARNING("Attempt to send data to " | |
e174961c JB |
10240 | "invalid cell: %pM\n", |
10241 | hdr->addr1); | |
43f66a6c JK |
10242 | goto drop; |
10243 | } | |
10244 | } | |
10245 | break; | |
10246 | ||
10247 | case IW_MODE_INFRA: | |
10248 | default: | |
3c19065a | 10249 | unicast = !is_multicast_ether_addr(hdr->addr3); |
43f66a6c JK |
10250 | id = 0; |
10251 | break; | |
10252 | } | |
10253 | ||
10254 | tfd = &txq->bd[q->first_empty]; | |
10255 | txq->txb[q->first_empty] = txb; | |
10256 | memset(tfd, 0, sizeof(*tfd)); | |
10257 | tfd->u.data.station_number = id; | |
10258 | ||
10259 | tfd->control_flags.message_type = TX_FRAME_TYPE; | |
10260 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; | |
10261 | ||
10262 | tfd->u.data.cmd_id = DINO_CMD_TX; | |
a613bffd | 10263 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
bf79451e | 10264 | |
43f66a6c | 10265 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
b095c381 | 10266 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
43f66a6c | 10267 | else |
b095c381 | 10268 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
43f66a6c | 10269 | |
ea2b26e0 JK |
10270 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
10271 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; | |
43f66a6c | 10272 | |
c848d0af JK |
10273 | fc = le16_to_cpu(hdr->frame_ctl); |
10274 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); | |
43f66a6c JK |
10275 | |
10276 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); | |
10277 | ||
b095c381 JK |
10278 | if (likely(unicast)) |
10279 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; | |
10280 | ||
10281 | if (txb->encrypted && !priv->ieee->host_encrypt) { | |
10282 | switch (priv->ieee->sec.level) { | |
10283 | case SEC_LEVEL_3: | |
10284 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | |
851ca268 | 10285 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
b095c381 JK |
10286 | /* XXX: ACK flag must be set for CCMP even if it |
10287 | * is a multicast/broadcast packet, because CCMP | |
10288 | * group communication encrypted by GTK is | |
10289 | * actually done by the AP. */ | |
10290 | if (!unicast) | |
10291 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; | |
10292 | ||
10293 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; | |
10294 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; | |
10295 | tfd->u.data.key_index = 0; | |
10296 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; | |
10297 | break; | |
10298 | case SEC_LEVEL_2: | |
10299 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | |
851ca268 | 10300 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
b095c381 JK |
10301 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; |
10302 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; | |
10303 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; | |
10304 | break; | |
10305 | case SEC_LEVEL_1: | |
10306 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | |
851ca268 | 10307 | cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
274bfb8d JL |
10308 | tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx; |
10309 | if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <= | |
b095c381 JK |
10310 | 40) |
10311 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; | |
10312 | else | |
10313 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; | |
10314 | break; | |
10315 | case SEC_LEVEL_0: | |
10316 | break; | |
10317 | default: | |
af901ca1 | 10318 | printk(KERN_ERR "Unknown security level %d\n", |
b095c381 JK |
10319 | priv->ieee->sec.level); |
10320 | break; | |
10321 | } | |
10322 | } else | |
10323 | /* No hardware encryption */ | |
10324 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; | |
10325 | ||
e43e3c1e | 10326 | #ifdef CONFIG_IPW2200_QOS |
a5cf4fe6 ZY |
10327 | if (fc & IEEE80211_STYPE_QOS_DATA) |
10328 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data)); | |
e43e3c1e | 10329 | #endif /* CONFIG_IPW2200_QOS */ |
b095c381 | 10330 | |
43f66a6c | 10331 | /* payload */ |
a613bffd JK |
10332 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
10333 | txb->nr_frags)); | |
10334 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", | |
10335 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); | |
10336 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { | |
10337 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", | |
10338 | i, le32_to_cpu(tfd->u.data.num_chunks), | |
10339 | txb->fragments[i]->len - hdr_len); | |
bf79451e | 10340 | IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n", |
43f66a6c JK |
10341 | i, tfd->u.data.num_chunks, |
10342 | txb->fragments[i]->len - hdr_len); | |
bf79451e | 10343 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
43f66a6c JK |
10344 | txb->fragments[i]->len - hdr_len); |
10345 | ||
0edd5b44 | 10346 | tfd->u.data.chunk_ptr[i] = |
a613bffd JK |
10347 | cpu_to_le32(pci_map_single |
10348 | (priv->pci_dev, | |
10349 | txb->fragments[i]->data + hdr_len, | |
10350 | txb->fragments[i]->len - hdr_len, | |
10351 | PCI_DMA_TODEVICE)); | |
10352 | tfd->u.data.chunk_len[i] = | |
10353 | cpu_to_le16(txb->fragments[i]->len - hdr_len); | |
43f66a6c JK |
10354 | } |
10355 | ||
10356 | if (i != txb->nr_frags) { | |
10357 | struct sk_buff *skb; | |
10358 | u16 remaining_bytes = 0; | |
10359 | int j; | |
10360 | ||
10361 | for (j = i; j < txb->nr_frags; j++) | |
10362 | remaining_bytes += txb->fragments[j]->len - hdr_len; | |
10363 | ||
10364 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", | |
10365 | remaining_bytes); | |
10366 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); | |
10367 | if (skb != NULL) { | |
a613bffd | 10368 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
43f66a6c JK |
10369 | for (j = i; j < txb->nr_frags; j++) { |
10370 | int size = txb->fragments[j]->len - hdr_len; | |
afbf30a2 | 10371 | |
43f66a6c | 10372 | printk(KERN_INFO "Adding frag %d %d...\n", |
0edd5b44 | 10373 | j, size); |
43f66a6c | 10374 | memcpy(skb_put(skb, size), |
0edd5b44 | 10375 | txb->fragments[j]->data + hdr_len, size); |
43f66a6c JK |
10376 | } |
10377 | dev_kfree_skb_any(txb->fragments[i]); | |
10378 | txb->fragments[i] = skb; | |
0edd5b44 | 10379 | tfd->u.data.chunk_ptr[i] = |
a613bffd JK |
10380 | cpu_to_le32(pci_map_single |
10381 | (priv->pci_dev, skb->data, | |
4958730e | 10382 | remaining_bytes, |
a613bffd JK |
10383 | PCI_DMA_TODEVICE)); |
10384 | ||
5c05863d | 10385 | le32_add_cpu(&tfd->u.data.num_chunks, 1); |
bf79451e | 10386 | } |
43f66a6c JK |
10387 | } |
10388 | ||
10389 | /* kick DMA */ | |
10390 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); | |
10391 | ipw_write32(priv, q->reg_w, q->first_empty); | |
10392 | ||
943dbef4 | 10393 | if (ipw_tx_queue_space(q) < q->high_mark) |
f697014a JK |
10394 | netif_stop_queue(priv->net_dev); |
10395 | ||
227d2dc1 | 10396 | return NETDEV_TX_OK; |
43f66a6c | 10397 | |
0edd5b44 | 10398 | drop: |
43f66a6c | 10399 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
b0a4e7d8 | 10400 | libipw_txb_free(txb); |
227d2dc1 JK |
10401 | return NETDEV_TX_OK; |
10402 | } | |
10403 | ||
10404 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) | |
10405 | { | |
b0a4e7d8 | 10406 | struct ipw_priv *priv = libipw_priv(dev); |
e43e3c1e | 10407 | #ifdef CONFIG_IPW2200_QOS |
227d2dc1 JK |
10408 | int tx_id = ipw_get_tx_queue_number(priv, pri); |
10409 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; | |
10410 | #else | |
10411 | struct clx2_tx_queue *txq = &priv->txq[0]; | |
e43e3c1e | 10412 | #endif /* CONFIG_IPW2200_QOS */ |
227d2dc1 | 10413 | |
943dbef4 | 10414 | if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark) |
227d2dc1 JK |
10415 | return 1; |
10416 | ||
10417 | return 0; | |
43f66a6c JK |
10418 | } |
10419 | ||
d685b8c2 ZY |
10420 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
10421 | static void ipw_handle_promiscuous_tx(struct ipw_priv *priv, | |
b0a4e7d8 | 10422 | struct libipw_txb *txb) |
d685b8c2 | 10423 | { |
b0a4e7d8 | 10424 | struct libipw_rx_stats dummystats; |
d685b8c2 ZY |
10425 | struct ieee80211_hdr *hdr; |
10426 | u8 n; | |
10427 | u16 filter = priv->prom_priv->filter; | |
10428 | int hdr_only = 0; | |
10429 | ||
10430 | if (filter & IPW_PROM_NO_TX) | |
10431 | return; | |
10432 | ||
10433 | memset(&dummystats, 0, sizeof(dummystats)); | |
10434 | ||
10435 | /* Filtering of fragment chains is done agains the first fragment */ | |
10436 | hdr = (void *)txb->fragments[0]->data; | |
b0a4e7d8 | 10437 | if (libipw_is_management(le16_to_cpu(hdr->frame_control))) { |
d685b8c2 ZY |
10438 | if (filter & IPW_PROM_NO_MGMT) |
10439 | return; | |
10440 | if (filter & IPW_PROM_MGMT_HEADER_ONLY) | |
10441 | hdr_only = 1; | |
b0a4e7d8 | 10442 | } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) { |
d685b8c2 ZY |
10443 | if (filter & IPW_PROM_NO_CTL) |
10444 | return; | |
10445 | if (filter & IPW_PROM_CTL_HEADER_ONLY) | |
10446 | hdr_only = 1; | |
b0a4e7d8 | 10447 | } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) { |
d685b8c2 ZY |
10448 | if (filter & IPW_PROM_NO_DATA) |
10449 | return; | |
10450 | if (filter & IPW_PROM_DATA_HEADER_ONLY) | |
10451 | hdr_only = 1; | |
10452 | } | |
10453 | ||
10454 | for(n=0; n<txb->nr_frags; ++n) { | |
10455 | struct sk_buff *src = txb->fragments[n]; | |
10456 | struct sk_buff *dst; | |
10457 | struct ieee80211_radiotap_header *rt_hdr; | |
10458 | int len; | |
10459 | ||
10460 | if (hdr_only) { | |
10461 | hdr = (void *)src->data; | |
b0a4e7d8 | 10462 | len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control)); |
d685b8c2 ZY |
10463 | } else |
10464 | len = src->len; | |
10465 | ||
007e5ddd JB |
10466 | dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC); |
10467 | if (!dst) | |
10468 | continue; | |
d685b8c2 ZY |
10469 | |
10470 | rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr)); | |
10471 | ||
10472 | rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION; | |
10473 | rt_hdr->it_pad = 0; | |
10474 | rt_hdr->it_present = 0; /* after all, it's just an idea */ | |
743b84d2 | 10475 | rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL); |
d685b8c2 | 10476 | |
e62e1ee0 | 10477 | *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16( |
d685b8c2 ZY |
10478 | ieee80211chan2mhz(priv->channel)); |
10479 | if (priv->channel > 14) /* 802.11a */ | |
e62e1ee0 | 10480 | *(__le16*)skb_put(dst, sizeof(u16)) = |
d685b8c2 ZY |
10481 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
10482 | IEEE80211_CHAN_5GHZ); | |
10483 | else if (priv->ieee->mode == IEEE_B) /* 802.11b */ | |
e62e1ee0 | 10484 | *(__le16*)skb_put(dst, sizeof(u16)) = |
d685b8c2 ZY |
10485 | cpu_to_le16(IEEE80211_CHAN_CCK | |
10486 | IEEE80211_CHAN_2GHZ); | |
10487 | else /* 802.11g */ | |
e62e1ee0 | 10488 | *(__le16*)skb_put(dst, sizeof(u16)) = |
d685b8c2 ZY |
10489 | cpu_to_le16(IEEE80211_CHAN_OFDM | |
10490 | IEEE80211_CHAN_2GHZ); | |
10491 | ||
743b84d2 | 10492 | rt_hdr->it_len = cpu_to_le16(dst->len); |
d685b8c2 | 10493 | |
d626f62b | 10494 | skb_copy_from_linear_data(src, skb_put(dst, len), len); |
d685b8c2 | 10495 | |
b0a4e7d8 | 10496 | if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats)) |
d685b8c2 ZY |
10497 | dev_kfree_skb_any(dst); |
10498 | } | |
10499 | } | |
10500 | #endif | |
10501 | ||
d0cf9c0d SH |
10502 | static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb, |
10503 | struct net_device *dev, int pri) | |
43f66a6c | 10504 | { |
b0a4e7d8 | 10505 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c | 10506 | unsigned long flags; |
d0cf9c0d | 10507 | netdev_tx_t ret; |
43f66a6c JK |
10508 | |
10509 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); | |
43f66a6c JK |
10510 | spin_lock_irqsave(&priv->lock, flags); |
10511 | ||
d685b8c2 ZY |
10512 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
10513 | if (rtap_iface && netif_running(priv->prom_net_dev)) | |
10514 | ipw_handle_promiscuous_tx(priv, txb); | |
10515 | #endif | |
10516 | ||
227d2dc1 JK |
10517 | ret = ipw_tx_skb(priv, txb, pri); |
10518 | if (ret == NETDEV_TX_OK) | |
10519 | __ipw_led_activity_on(priv); | |
43f66a6c | 10520 | spin_unlock_irqrestore(&priv->lock, flags); |
43f66a6c | 10521 | |
227d2dc1 | 10522 | return ret; |
43f66a6c JK |
10523 | } |
10524 | ||
43f66a6c JK |
10525 | static void ipw_net_set_multicast_list(struct net_device *dev) |
10526 | { | |
10527 | ||
10528 | } | |
10529 | ||
10530 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) | |
10531 | { | |
b0a4e7d8 | 10532 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c | 10533 | struct sockaddr *addr = p; |
0795af57 | 10534 | |
43f66a6c JK |
10535 | if (!is_valid_ether_addr(addr->sa_data)) |
10536 | return -EADDRNOTAVAIL; | |
4644151b | 10537 | mutex_lock(&priv->mutex); |
43f66a6c JK |
10538 | priv->config |= CFG_CUSTOM_MAC; |
10539 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); | |
e174961c JB |
10540 | printk(KERN_INFO "%s: Setting MAC to %pM\n", |
10541 | priv->net_dev->name, priv->mac_addr); | |
a613bffd | 10542 | queue_work(priv->workqueue, &priv->adapter_restart); |
4644151b | 10543 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10544 | return 0; |
10545 | } | |
10546 | ||
bf79451e | 10547 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
43f66a6c JK |
10548 | struct ethtool_drvinfo *info) |
10549 | { | |
b0a4e7d8 | 10550 | struct ipw_priv *p = libipw_priv(dev); |
43f66a6c JK |
10551 | char vers[64]; |
10552 | char date[32]; | |
10553 | u32 len; | |
10554 | ||
10555 | strcpy(info->driver, DRV_NAME); | |
10556 | strcpy(info->version, DRV_VERSION); | |
10557 | ||
10558 | len = sizeof(vers); | |
10559 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); | |
10560 | len = sizeof(date); | |
10561 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); | |
10562 | ||
0edd5b44 | 10563 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
43f66a6c JK |
10564 | vers, date); |
10565 | strcpy(info->bus_info, pci_name(p->pci_dev)); | |
b095c381 | 10566 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
43f66a6c JK |
10567 | } |
10568 | ||
10569 | static u32 ipw_ethtool_get_link(struct net_device *dev) | |
10570 | { | |
b0a4e7d8 | 10571 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c JK |
10572 | return (priv->status & STATUS_ASSOCIATED) != 0; |
10573 | } | |
10574 | ||
10575 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) | |
10576 | { | |
b095c381 | 10577 | return IPW_EEPROM_IMAGE_SIZE; |
43f66a6c JK |
10578 | } |
10579 | ||
10580 | static int ipw_ethtool_get_eeprom(struct net_device *dev, | |
0edd5b44 | 10581 | struct ethtool_eeprom *eeprom, u8 * bytes) |
43f66a6c | 10582 | { |
b0a4e7d8 | 10583 | struct ipw_priv *p = libipw_priv(dev); |
43f66a6c | 10584 | |
b095c381 | 10585 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
43f66a6c | 10586 | return -EINVAL; |
4644151b | 10587 | mutex_lock(&p->mutex); |
afbf30a2 | 10588 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
4644151b | 10589 | mutex_unlock(&p->mutex); |
43f66a6c JK |
10590 | return 0; |
10591 | } | |
10592 | ||
10593 | static int ipw_ethtool_set_eeprom(struct net_device *dev, | |
0edd5b44 | 10594 | struct ethtool_eeprom *eeprom, u8 * bytes) |
43f66a6c | 10595 | { |
b0a4e7d8 | 10596 | struct ipw_priv *p = libipw_priv(dev); |
43f66a6c JK |
10597 | int i; |
10598 | ||
b095c381 | 10599 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
43f66a6c | 10600 | return -EINVAL; |
4644151b | 10601 | mutex_lock(&p->mutex); |
afbf30a2 | 10602 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
71e585fc AB |
10603 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
10604 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); | |
4644151b | 10605 | mutex_unlock(&p->mutex); |
43f66a6c JK |
10606 | return 0; |
10607 | } | |
10608 | ||
7282d491 | 10609 | static const struct ethtool_ops ipw_ethtool_ops = { |
ea2b26e0 JK |
10610 | .get_link = ipw_ethtool_get_link, |
10611 | .get_drvinfo = ipw_ethtool_get_drvinfo, | |
10612 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, | |
10613 | .get_eeprom = ipw_ethtool_get_eeprom, | |
10614 | .set_eeprom = ipw_ethtool_set_eeprom, | |
43f66a6c JK |
10615 | }; |
10616 | ||
7d12e780 | 10617 | static irqreturn_t ipw_isr(int irq, void *data) |
43f66a6c JK |
10618 | { |
10619 | struct ipw_priv *priv = data; | |
10620 | u32 inta, inta_mask; | |
bf79451e | 10621 | |
43f66a6c JK |
10622 | if (!priv) |
10623 | return IRQ_NONE; | |
10624 | ||
89c318ed | 10625 | spin_lock(&priv->irq_lock); |
43f66a6c JK |
10626 | |
10627 | if (!(priv->status & STATUS_INT_ENABLED)) { | |
d00d0121 | 10628 | /* IRQ is disabled */ |
43f66a6c JK |
10629 | goto none; |
10630 | } | |
10631 | ||
b095c381 JK |
10632 | inta = ipw_read32(priv, IPW_INTA_RW); |
10633 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); | |
bf79451e | 10634 | |
43f66a6c JK |
10635 | if (inta == 0xFFFFFFFF) { |
10636 | /* Hardware disappeared */ | |
10637 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); | |
10638 | goto none; | |
10639 | } | |
10640 | ||
b095c381 | 10641 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
43f66a6c JK |
10642 | /* Shared interrupt */ |
10643 | goto none; | |
10644 | } | |
10645 | ||
10646 | /* tell the device to stop sending interrupts */ | |
89c318ed | 10647 | __ipw_disable_interrupts(priv); |
bf79451e | 10648 | |
43f66a6c | 10649 | /* ack current interrupts */ |
b095c381 JK |
10650 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
10651 | ipw_write32(priv, IPW_INTA_RW, inta); | |
bf79451e | 10652 | |
43f66a6c JK |
10653 | /* Cache INTA value for our tasklet */ |
10654 | priv->isr_inta = inta; | |
10655 | ||
10656 | tasklet_schedule(&priv->irq_tasklet); | |
10657 | ||
89c318ed | 10658 | spin_unlock(&priv->irq_lock); |
43f66a6c JK |
10659 | |
10660 | return IRQ_HANDLED; | |
0edd5b44 | 10661 | none: |
89c318ed | 10662 | spin_unlock(&priv->irq_lock); |
43f66a6c JK |
10663 | return IRQ_NONE; |
10664 | } | |
10665 | ||
10666 | static void ipw_rf_kill(void *adapter) | |
10667 | { | |
10668 | struct ipw_priv *priv = adapter; | |
10669 | unsigned long flags; | |
bf79451e | 10670 | |
43f66a6c JK |
10671 | spin_lock_irqsave(&priv->lock, flags); |
10672 | ||
10673 | if (rf_kill_active(priv)) { | |
10674 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); | |
10675 | if (priv->workqueue) | |
10676 | queue_delayed_work(priv->workqueue, | |
10677 | &priv->rf_kill, 2 * HZ); | |
10678 | goto exit_unlock; | |
10679 | } | |
10680 | ||
10681 | /* RF Kill is now disabled, so bring the device back up */ | |
10682 | ||
10683 | if (!(priv->status & STATUS_RF_KILL_MASK)) { | |
10684 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " | |
10685 | "device\n"); | |
10686 | ||
10687 | /* we can not do an adapter restart while inside an irq lock */ | |
10688 | queue_work(priv->workqueue, &priv->adapter_restart); | |
bf79451e | 10689 | } else |
43f66a6c JK |
10690 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
10691 | "enabled\n"); | |
10692 | ||
0edd5b44 | 10693 | exit_unlock: |
43f66a6c JK |
10694 | spin_unlock_irqrestore(&priv->lock, flags); |
10695 | } | |
10696 | ||
c4028958 | 10697 | static void ipw_bg_rf_kill(struct work_struct *work) |
c848d0af | 10698 | { |
c4028958 DH |
10699 | struct ipw_priv *priv = |
10700 | container_of(work, struct ipw_priv, rf_kill.work); | |
4644151b | 10701 | mutex_lock(&priv->mutex); |
c4028958 | 10702 | ipw_rf_kill(priv); |
4644151b | 10703 | mutex_unlock(&priv->mutex); |
c848d0af JK |
10704 | } |
10705 | ||
a73e22b2 | 10706 | static void ipw_link_up(struct ipw_priv *priv) |
a613bffd | 10707 | { |
afbf30a2 JK |
10708 | priv->last_seq_num = -1; |
10709 | priv->last_frag_num = -1; | |
10710 | priv->last_packet_time = 0; | |
10711 | ||
a613bffd | 10712 | netif_carrier_on(priv->net_dev); |
a613bffd | 10713 | |
c848d0af | 10714 | cancel_delayed_work(&priv->request_scan); |
ea177305 DW |
10715 | cancel_delayed_work(&priv->request_direct_scan); |
10716 | cancel_delayed_work(&priv->request_passive_scan); | |
0b531676 | 10717 | cancel_delayed_work(&priv->scan_event); |
a613bffd JK |
10718 | ipw_reset_stats(priv); |
10719 | /* Ensure the rate is updated immediately */ | |
10720 | priv->last_rate = ipw_get_current_rate(priv); | |
10721 | ipw_gather_stats(priv); | |
10722 | ipw_led_link_up(priv); | |
10723 | notify_wx_assoc_event(priv); | |
10724 | ||
10725 | if (priv->config & CFG_BACKGROUND_SCAN) | |
10726 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); | |
10727 | } | |
10728 | ||
c4028958 | 10729 | static void ipw_bg_link_up(struct work_struct *work) |
c848d0af | 10730 | { |
c4028958 DH |
10731 | struct ipw_priv *priv = |
10732 | container_of(work, struct ipw_priv, link_up); | |
4644151b | 10733 | mutex_lock(&priv->mutex); |
c4028958 | 10734 | ipw_link_up(priv); |
4644151b | 10735 | mutex_unlock(&priv->mutex); |
c848d0af JK |
10736 | } |
10737 | ||
a73e22b2 | 10738 | static void ipw_link_down(struct ipw_priv *priv) |
a613bffd JK |
10739 | { |
10740 | ipw_led_link_down(priv); | |
10741 | netif_carrier_off(priv->net_dev); | |
a613bffd JK |
10742 | notify_wx_assoc_event(priv); |
10743 | ||
10744 | /* Cancel any queued work ... */ | |
10745 | cancel_delayed_work(&priv->request_scan); | |
ea177305 DW |
10746 | cancel_delayed_work(&priv->request_direct_scan); |
10747 | cancel_delayed_work(&priv->request_passive_scan); | |
a613bffd JK |
10748 | cancel_delayed_work(&priv->adhoc_check); |
10749 | cancel_delayed_work(&priv->gather_stats); | |
10750 | ||
10751 | ipw_reset_stats(priv); | |
10752 | ||
afbf30a2 JK |
10753 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
10754 | /* Queue up another scan... */ | |
c4028958 | 10755 | queue_delayed_work(priv->workqueue, &priv->request_scan, 0); |
0b531676 DW |
10756 | } else |
10757 | cancel_delayed_work(&priv->scan_event); | |
a613bffd JK |
10758 | } |
10759 | ||
c4028958 | 10760 | static void ipw_bg_link_down(struct work_struct *work) |
c848d0af | 10761 | { |
c4028958 DH |
10762 | struct ipw_priv *priv = |
10763 | container_of(work, struct ipw_priv, link_down); | |
4644151b | 10764 | mutex_lock(&priv->mutex); |
c4028958 | 10765 | ipw_link_down(priv); |
4644151b | 10766 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10767 | } |
10768 | ||
2ef19e63 | 10769 | static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv) |
43f66a6c JK |
10770 | { |
10771 | int ret = 0; | |
10772 | ||
43f66a6c | 10773 | priv->workqueue = create_workqueue(DRV_NAME); |
43f66a6c | 10774 | init_waitqueue_head(&priv->wait_command_queue); |
afbf30a2 | 10775 | init_waitqueue_head(&priv->wait_state); |
43f66a6c | 10776 | |
c4028958 DH |
10777 | INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check); |
10778 | INIT_WORK(&priv->associate, ipw_bg_associate); | |
10779 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate); | |
10780 | INIT_WORK(&priv->system_config, ipw_system_config); | |
10781 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish); | |
10782 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart); | |
10783 | INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill); | |
10784 | INIT_WORK(&priv->up, ipw_bg_up); | |
10785 | INIT_WORK(&priv->down, ipw_bg_down); | |
10786 | INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan); | |
ea177305 DW |
10787 | INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan); |
10788 | INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan); | |
0b531676 | 10789 | INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event); |
c4028958 DH |
10790 | INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats); |
10791 | INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan); | |
10792 | INIT_WORK(&priv->roam, ipw_bg_roam); | |
10793 | INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check); | |
10794 | INIT_WORK(&priv->link_up, ipw_bg_link_up); | |
10795 | INIT_WORK(&priv->link_down, ipw_bg_link_down); | |
10796 | INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on); | |
10797 | INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off); | |
10798 | INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off); | |
10799 | INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network); | |
43f66a6c | 10800 | |
e43e3c1e | 10801 | #ifdef CONFIG_IPW2200_QOS |
c4028958 | 10802 | INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate); |
e43e3c1e | 10803 | #endif /* CONFIG_IPW2200_QOS */ |
43f66a6c JK |
10804 | |
10805 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) | |
10806 | ipw_irq_tasklet, (unsigned long)priv); | |
10807 | ||
10808 | return ret; | |
10809 | } | |
10810 | ||
43f66a6c | 10811 | static void shim__set_security(struct net_device *dev, |
b0a4e7d8 | 10812 | struct libipw_security *sec) |
43f66a6c | 10813 | { |
b0a4e7d8 | 10814 | struct ipw_priv *priv = libipw_priv(dev); |
43f66a6c | 10815 | int i; |
bf79451e | 10816 | for (i = 0; i < 4; i++) { |
43f66a6c | 10817 | if (sec->flags & (1 << i)) { |
afbf30a2 | 10818 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
b095c381 | 10819 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
43f66a6c | 10820 | if (sec->key_sizes[i] == 0) |
b095c381 JK |
10821 | priv->ieee->sec.flags &= ~(1 << i); |
10822 | else { | |
10823 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], | |
43f66a6c | 10824 | sec->key_sizes[i]); |
b095c381 JK |
10825 | priv->ieee->sec.flags |= (1 << i); |
10826 | } | |
43f66a6c | 10827 | priv->status |= STATUS_SECURITY_UPDATED; |
b095c381 JK |
10828 | } else if (sec->level != SEC_LEVEL_1) |
10829 | priv->ieee->sec.flags &= ~(1 << i); | |
43f66a6c JK |
10830 | } |
10831 | ||
b095c381 | 10832 | if (sec->flags & SEC_ACTIVE_KEY) { |
43f66a6c | 10833 | if (sec->active_key <= 3) { |
b095c381 JK |
10834 | priv->ieee->sec.active_key = sec->active_key; |
10835 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; | |
bf79451e | 10836 | } else |
b095c381 | 10837 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
43f66a6c | 10838 | priv->status |= STATUS_SECURITY_UPDATED; |
b095c381 JK |
10839 | } else |
10840 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; | |
43f66a6c JK |
10841 | |
10842 | if ((sec->flags & SEC_AUTH_MODE) && | |
b095c381 JK |
10843 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
10844 | priv->ieee->sec.auth_mode = sec->auth_mode; | |
10845 | priv->ieee->sec.flags |= SEC_AUTH_MODE; | |
43f66a6c JK |
10846 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
10847 | priv->capability |= CAP_SHARED_KEY; | |
10848 | else | |
10849 | priv->capability &= ~CAP_SHARED_KEY; | |
10850 | priv->status |= STATUS_SECURITY_UPDATED; | |
10851 | } | |
bf79451e | 10852 | |
b095c381 JK |
10853 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
10854 | priv->ieee->sec.flags |= SEC_ENABLED; | |
10855 | priv->ieee->sec.enabled = sec->enabled; | |
43f66a6c | 10856 | priv->status |= STATUS_SECURITY_UPDATED; |
bf79451e | 10857 | if (sec->enabled) |
43f66a6c JK |
10858 | priv->capability |= CAP_PRIVACY_ON; |
10859 | else | |
10860 | priv->capability &= ~CAP_PRIVACY_ON; | |
10861 | } | |
bf79451e | 10862 | |
afbf30a2 JK |
10863 | if (sec->flags & SEC_ENCRYPT) |
10864 | priv->ieee->sec.encrypt = sec->encrypt; | |
bf79451e | 10865 | |
b095c381 JK |
10866 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
10867 | priv->ieee->sec.level = sec->level; | |
10868 | priv->ieee->sec.flags |= SEC_LEVEL; | |
43f66a6c JK |
10869 | priv->status |= STATUS_SECURITY_UPDATED; |
10870 | } | |
10871 | ||
1fbfea54 ZY |
10872 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
10873 | ipw_set_hwcrypto_keys(priv); | |
10874 | ||
bf79451e JG |
10875 | /* To match current functionality of ipw2100 (which works well w/ |
10876 | * various supplicants, we don't force a disassociate if the | |
43f66a6c JK |
10877 | * privacy capability changes ... */ |
10878 | #if 0 | |
10879 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && | |
bf79451e | 10880 | (((priv->assoc_request.capability & |
5b5e807f | 10881 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) || |
bf79451e | 10882 | (!(priv->assoc_request.capability & |
5b5e807f | 10883 | cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) { |
43f66a6c JK |
10884 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
10885 | "change.\n"); | |
10886 | ipw_disassociate(priv); | |
10887 | } | |
10888 | #endif | |
10889 | } | |
10890 | ||
bf79451e | 10891 | static int init_supported_rates(struct ipw_priv *priv, |
43f66a6c JK |
10892 | struct ipw_supported_rates *rates) |
10893 | { | |
10894 | /* TODO: Mask out rates based on priv->rates_mask */ | |
10895 | ||
10896 | memset(rates, 0, sizeof(*rates)); | |
0edd5b44 | 10897 | /* configure supported rates */ |
43f66a6c | 10898 | switch (priv->ieee->freq_band) { |
b0a4e7d8 | 10899 | case LIBIPW_52GHZ_BAND: |
43f66a6c JK |
10900 | rates->ieee_mode = IPW_A_MODE; |
10901 | rates->purpose = IPW_RATE_CAPABILITIES; | |
b0a4e7d8 JL |
10902 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, |
10903 | LIBIPW_OFDM_DEFAULT_RATES_MASK); | |
43f66a6c JK |
10904 | break; |
10905 | ||
0edd5b44 | 10906 | default: /* Mixed or 2.4Ghz */ |
43f66a6c JK |
10907 | rates->ieee_mode = IPW_G_MODE; |
10908 | rates->purpose = IPW_RATE_CAPABILITIES; | |
b0a4e7d8 JL |
10909 | ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION, |
10910 | LIBIPW_CCK_DEFAULT_RATES_MASK); | |
10911 | if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) { | |
10912 | ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION, | |
10913 | LIBIPW_OFDM_DEFAULT_RATES_MASK); | |
43f66a6c JK |
10914 | } |
10915 | break; | |
10916 | } | |
10917 | ||
10918 | return 0; | |
10919 | } | |
10920 | ||
bf79451e | 10921 | static int ipw_config(struct ipw_priv *priv) |
43f66a6c | 10922 | { |
43f66a6c JK |
10923 | /* This is only called from ipw_up, which resets/reloads the firmware |
10924 | so, we don't need to first disable the card before we configure | |
10925 | it */ | |
6de9f7f2 | 10926 | if (ipw_set_tx_power(priv)) |
43f66a6c JK |
10927 | goto error; |
10928 | ||
10929 | /* initialize adapter address */ | |
10930 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) | |
10931 | goto error; | |
10932 | ||
10933 | /* set basic system config settings */ | |
10934 | init_sys_config(&priv->sys_config); | |
810dabd4 ZY |
10935 | |
10936 | /* Support Bluetooth if we have BT h/w on board, and user wants to. | |
10937 | * Does not support BT priority yet (don't abort or defer our Tx) */ | |
10938 | if (bt_coexist) { | |
2638bc39 | 10939 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
810dabd4 ZY |
10940 | |
10941 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) | |
10942 | priv->sys_config.bt_coexistence | |
2638bc39 | 10943 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
810dabd4 ZY |
10944 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
10945 | priv->sys_config.bt_coexistence | |
2638bc39 | 10946 | |= CFG_BT_COEXISTENCE_OOB; |
810dabd4 ZY |
10947 | } |
10948 | ||
d685b8c2 ZY |
10949 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
10950 | if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) { | |
10951 | priv->sys_config.accept_all_data_frames = 1; | |
10952 | priv->sys_config.accept_non_directed_frames = 1; | |
10953 | priv->sys_config.accept_all_mgmt_bcpr = 1; | |
10954 | priv->sys_config.accept_all_mgmt_frames = 1; | |
10955 | } | |
10956 | #endif | |
10957 | ||
c848d0af JK |
10958 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
10959 | priv->sys_config.answer_broadcast_ssid_probe = 1; | |
10960 | else | |
10961 | priv->sys_config.answer_broadcast_ssid_probe = 0; | |
10962 | ||
d685b8c2 | 10963 | if (ipw_send_system_config(priv)) |
43f66a6c JK |
10964 | goto error; |
10965 | ||
0edd5b44 JG |
10966 | init_supported_rates(priv, &priv->rates); |
10967 | if (ipw_send_supported_rates(priv, &priv->rates)) | |
43f66a6c JK |
10968 | goto error; |
10969 | ||
10970 | /* Set request-to-send threshold */ | |
10971 | if (priv->rts_threshold) { | |
10972 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) | |
10973 | goto error; | |
10974 | } | |
e43e3c1e | 10975 | #ifdef CONFIG_IPW2200_QOS |
b095c381 JK |
10976 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); |
10977 | ipw_qos_activate(priv, NULL); | |
e43e3c1e | 10978 | #endif /* CONFIG_IPW2200_QOS */ |
43f66a6c JK |
10979 | |
10980 | if (ipw_set_random_seed(priv)) | |
10981 | goto error; | |
bf79451e | 10982 | |
43f66a6c JK |
10983 | /* final state transition to the RUN state */ |
10984 | if (ipw_send_host_complete(priv)) | |
10985 | goto error; | |
10986 | ||
e666619e JK |
10987 | priv->status |= STATUS_INIT; |
10988 | ||
10989 | ipw_led_init(priv); | |
10990 | ipw_led_radio_on(priv); | |
10991 | priv->notif_missed_beacons = 0; | |
10992 | ||
10993 | /* Set hardware WEP key if it is configured. */ | |
10994 | if ((priv->capability & CAP_PRIVACY_ON) && | |
10995 | (priv->ieee->sec.level == SEC_LEVEL_1) && | |
10996 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) | |
10997 | ipw_set_hwcrypto_keys(priv); | |
43f66a6c JK |
10998 | |
10999 | return 0; | |
bf79451e | 11000 | |
0edd5b44 | 11001 | error: |
43f66a6c JK |
11002 | return -EIO; |
11003 | } | |
11004 | ||
4f36f808 JK |
11005 | /* |
11006 | * NOTE: | |
11007 | * | |
11008 | * These tables have been tested in conjunction with the | |
11009 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. | |
11010 | * | |
11011 | * Altering this values, using it on other hardware, or in geographies | |
11012 | * not intended for resale of the above mentioned Intel adapters has | |
11013 | * not been tested. | |
11014 | * | |
48a84770 HBA |
11015 | * Remember to update the table in README.ipw2200 when changing this |
11016 | * table. | |
11017 | * | |
4f36f808 | 11018 | */ |
b0a4e7d8 | 11019 | static const struct libipw_geo ipw_geos[] = { |
4f36f808 JK |
11020 | { /* Restricted */ |
11021 | "---", | |
11022 | .bg_channels = 11, | |
11023 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11024 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11025 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11026 | {2457, 10}, {2462, 11}}, | |
11027 | }, | |
11028 | ||
11029 | { /* Custom US/Canada */ | |
11030 | "ZZF", | |
11031 | .bg_channels = 11, | |
11032 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11033 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11034 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11035 | {2457, 10}, {2462, 11}}, | |
11036 | .a_channels = 8, | |
11037 | .a = {{5180, 36}, | |
11038 | {5200, 40}, | |
11039 | {5220, 44}, | |
11040 | {5240, 48}, | |
b0a4e7d8 JL |
11041 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
11042 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, | |
11043 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, | |
11044 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}}, | |
4f36f808 JK |
11045 | }, |
11046 | ||
11047 | { /* Rest of World */ | |
11048 | "ZZD", | |
11049 | .bg_channels = 13, | |
11050 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11051 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11052 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11053 | {2457, 10}, {2462, 11}, {2467, 12}, | |
11054 | {2472, 13}}, | |
11055 | }, | |
11056 | ||
11057 | { /* Custom USA & Europe & High */ | |
11058 | "ZZA", | |
11059 | .bg_channels = 11, | |
11060 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11061 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11062 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11063 | {2457, 10}, {2462, 11}}, | |
11064 | .a_channels = 13, | |
11065 | .a = {{5180, 36}, | |
11066 | {5200, 40}, | |
11067 | {5220, 44}, | |
11068 | {5240, 48}, | |
b0a4e7d8 JL |
11069 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
11070 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, | |
11071 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, | |
11072 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, | |
4f36f808 JK |
11073 | {5745, 149}, |
11074 | {5765, 153}, | |
11075 | {5785, 157}, | |
11076 | {5805, 161}, | |
11077 | {5825, 165}}, | |
11078 | }, | |
11079 | ||
11080 | { /* Custom NA & Europe */ | |
11081 | "ZZB", | |
11082 | .bg_channels = 11, | |
11083 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11084 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11085 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11086 | {2457, 10}, {2462, 11}}, | |
11087 | .a_channels = 13, | |
11088 | .a = {{5180, 36}, | |
11089 | {5200, 40}, | |
11090 | {5220, 44}, | |
11091 | {5240, 48}, | |
b0a4e7d8 JL |
11092 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
11093 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, | |
11094 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, | |
11095 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, | |
11096 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, | |
11097 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, | |
11098 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, | |
11099 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, | |
11100 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, | |
4f36f808 JK |
11101 | }, |
11102 | ||
11103 | { /* Custom Japan */ | |
11104 | "ZZC", | |
11105 | .bg_channels = 11, | |
11106 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11107 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11108 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11109 | {2457, 10}, {2462, 11}}, | |
11110 | .a_channels = 4, | |
11111 | .a = {{5170, 34}, {5190, 38}, | |
11112 | {5210, 42}, {5230, 46}}, | |
11113 | }, | |
11114 | ||
11115 | { /* Custom */ | |
11116 | "ZZM", | |
11117 | .bg_channels = 11, | |
11118 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11119 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11120 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11121 | {2457, 10}, {2462, 11}}, | |
11122 | }, | |
11123 | ||
11124 | { /* Europe */ | |
11125 | "ZZE", | |
11126 | .bg_channels = 13, | |
11127 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11128 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11129 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11130 | {2457, 10}, {2462, 11}, {2467, 12}, | |
11131 | {2472, 13}}, | |
11132 | .a_channels = 19, | |
11133 | .a = {{5180, 36}, | |
11134 | {5200, 40}, | |
11135 | {5220, 44}, | |
11136 | {5240, 48}, | |
b0a4e7d8 JL |
11137 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, |
11138 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, | |
11139 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, | |
11140 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, | |
11141 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, | |
11142 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, | |
11143 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, | |
11144 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, | |
11145 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, | |
11146 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, | |
11147 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, | |
11148 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, | |
11149 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, | |
11150 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, | |
11151 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}}, | |
4f36f808 JK |
11152 | }, |
11153 | ||
11154 | { /* Custom Japan */ | |
11155 | "ZZJ", | |
11156 | .bg_channels = 14, | |
11157 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11158 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11159 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11160 | {2457, 10}, {2462, 11}, {2467, 12}, | |
b0a4e7d8 | 11161 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}}, |
4f36f808 JK |
11162 | .a_channels = 4, |
11163 | .a = {{5170, 34}, {5190, 38}, | |
11164 | {5210, 42}, {5230, 46}}, | |
11165 | }, | |
11166 | ||
03520576 JK |
11167 | { /* Rest of World */ |
11168 | "ZZR", | |
11169 | .bg_channels = 14, | |
11170 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11171 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11172 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11173 | {2457, 10}, {2462, 11}, {2467, 12}, | |
b0a4e7d8 JL |
11174 | {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY | |
11175 | LIBIPW_CH_PASSIVE_ONLY}}, | |
03520576 JK |
11176 | }, |
11177 | ||
4f36f808 JK |
11178 | { /* High Band */ |
11179 | "ZZH", | |
11180 | .bg_channels = 13, | |
11181 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11182 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11183 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11184 | {2457, 10}, {2462, 11}, | |
b0a4e7d8 JL |
11185 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
11186 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, | |
4f36f808 JK |
11187 | .a_channels = 4, |
11188 | .a = {{5745, 149}, {5765, 153}, | |
11189 | {5785, 157}, {5805, 161}}, | |
11190 | }, | |
11191 | ||
11192 | { /* Custom Europe */ | |
11193 | "ZZG", | |
11194 | .bg_channels = 13, | |
11195 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11196 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11197 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11198 | {2457, 10}, {2462, 11}, | |
11199 | {2467, 12}, {2472, 13}}, | |
11200 | .a_channels = 4, | |
11201 | .a = {{5180, 36}, {5200, 40}, | |
11202 | {5220, 44}, {5240, 48}}, | |
11203 | }, | |
11204 | ||
11205 | { /* Europe */ | |
11206 | "ZZK", | |
11207 | .bg_channels = 13, | |
11208 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11209 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11210 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11211 | {2457, 10}, {2462, 11}, | |
b0a4e7d8 JL |
11212 | {2467, 12, LIBIPW_CH_PASSIVE_ONLY}, |
11213 | {2472, 13, LIBIPW_CH_PASSIVE_ONLY}}, | |
4f36f808 | 11214 | .a_channels = 24, |
b0a4e7d8 JL |
11215 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
11216 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, | |
11217 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, | |
11218 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, | |
11219 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, | |
11220 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, | |
11221 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, | |
11222 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, | |
11223 | {5500, 100, LIBIPW_CH_PASSIVE_ONLY}, | |
11224 | {5520, 104, LIBIPW_CH_PASSIVE_ONLY}, | |
11225 | {5540, 108, LIBIPW_CH_PASSIVE_ONLY}, | |
11226 | {5560, 112, LIBIPW_CH_PASSIVE_ONLY}, | |
11227 | {5580, 116, LIBIPW_CH_PASSIVE_ONLY}, | |
11228 | {5600, 120, LIBIPW_CH_PASSIVE_ONLY}, | |
11229 | {5620, 124, LIBIPW_CH_PASSIVE_ONLY}, | |
11230 | {5640, 128, LIBIPW_CH_PASSIVE_ONLY}, | |
11231 | {5660, 132, LIBIPW_CH_PASSIVE_ONLY}, | |
11232 | {5680, 136, LIBIPW_CH_PASSIVE_ONLY}, | |
11233 | {5700, 140, LIBIPW_CH_PASSIVE_ONLY}, | |
11234 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, | |
11235 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, | |
11236 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, | |
11237 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, | |
11238 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, | |
4f36f808 JK |
11239 | }, |
11240 | ||
11241 | { /* Europe */ | |
11242 | "ZZL", | |
11243 | .bg_channels = 11, | |
11244 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
11245 | {2427, 4}, {2432, 5}, {2437, 6}, | |
11246 | {2442, 7}, {2447, 8}, {2452, 9}, | |
11247 | {2457, 10}, {2462, 11}}, | |
11248 | .a_channels = 13, | |
b0a4e7d8 JL |
11249 | .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY}, |
11250 | {5200, 40, LIBIPW_CH_PASSIVE_ONLY}, | |
11251 | {5220, 44, LIBIPW_CH_PASSIVE_ONLY}, | |
11252 | {5240, 48, LIBIPW_CH_PASSIVE_ONLY}, | |
11253 | {5260, 52, LIBIPW_CH_PASSIVE_ONLY}, | |
11254 | {5280, 56, LIBIPW_CH_PASSIVE_ONLY}, | |
11255 | {5300, 60, LIBIPW_CH_PASSIVE_ONLY}, | |
11256 | {5320, 64, LIBIPW_CH_PASSIVE_ONLY}, | |
11257 | {5745, 149, LIBIPW_CH_PASSIVE_ONLY}, | |
11258 | {5765, 153, LIBIPW_CH_PASSIVE_ONLY}, | |
11259 | {5785, 157, LIBIPW_CH_PASSIVE_ONLY}, | |
11260 | {5805, 161, LIBIPW_CH_PASSIVE_ONLY}, | |
11261 | {5825, 165, LIBIPW_CH_PASSIVE_ONLY}}, | |
4f36f808 | 11262 | } |
afbf30a2 JK |
11263 | }; |
11264 | ||
43f66a6c JK |
11265 | #define MAX_HW_RESTARTS 5 |
11266 | static int ipw_up(struct ipw_priv *priv) | |
11267 | { | |
4f36f808 | 11268 | int rc, i, j; |
43f66a6c | 11269 | |
c3d72b96 DW |
11270 | /* Age scan list entries found before suspend */ |
11271 | if (priv->suspend_time) { | |
b0a4e7d8 | 11272 | libipw_networks_age(priv->ieee, priv->suspend_time); |
c3d72b96 DW |
11273 | priv->suspend_time = 0; |
11274 | } | |
11275 | ||
43f66a6c JK |
11276 | if (priv->status & STATUS_EXIT_PENDING) |
11277 | return -EIO; | |
11278 | ||
f6c5cb7c | 11279 | if (cmdlog && !priv->cmdlog) { |
e6e3f12a | 11280 | priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog), |
f6c5cb7c JK |
11281 | GFP_KERNEL); |
11282 | if (priv->cmdlog == NULL) { | |
11283 | IPW_ERROR("Error allocating %d command log entries.\n", | |
11284 | cmdlog); | |
d0b526b7 | 11285 | return -ENOMEM; |
f6c5cb7c | 11286 | } else { |
f6c5cb7c JK |
11287 | priv->cmdlog_len = cmdlog; |
11288 | } | |
11289 | } | |
11290 | ||
0edd5b44 | 11291 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
bf79451e | 11292 | /* Load the microcode, firmware, and eeprom. |
43f66a6c JK |
11293 | * Also start the clocks. */ |
11294 | rc = ipw_load(priv); | |
11295 | if (rc) { | |
a4f6bbb3 | 11296 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
43f66a6c JK |
11297 | return rc; |
11298 | } | |
11299 | ||
11300 | ipw_init_ordinals(priv); | |
11301 | if (!(priv->config & CFG_CUSTOM_MAC)) | |
11302 | eeprom_parse_mac(priv, priv->mac_addr); | |
11303 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); | |
5e5eab5d | 11304 | memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN); |
43f66a6c | 11305 | |
4f36f808 JK |
11306 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
11307 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], | |
11308 | ipw_geos[j].name, 3)) | |
11309 | break; | |
11310 | } | |
03520576 JK |
11311 | if (j == ARRAY_SIZE(ipw_geos)) { |
11312 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", | |
11313 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], | |
11314 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], | |
11315 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); | |
4f36f808 | 11316 | j = 0; |
03520576 | 11317 | } |
b0a4e7d8 | 11318 | if (libipw_set_geo(priv->ieee, &ipw_geos[j])) { |
4f36f808 JK |
11319 | IPW_WARNING("Could not set geography."); |
11320 | return 0; | |
11321 | } | |
11322 | ||
b095c381 JK |
11323 | if (priv->status & STATUS_RF_KILL_SW) { |
11324 | IPW_WARNING("Radio disabled by module parameter.\n"); | |
11325 | return 0; | |
11326 | } else if (rf_kill_active(priv)) { | |
11327 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" | |
11328 | "Kill switch must be turned off for " | |
11329 | "wireless networking to work.\n"); | |
11330 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | |
11331 | 2 * HZ); | |
43f66a6c | 11332 | return 0; |
c848d0af | 11333 | } |
43f66a6c JK |
11334 | |
11335 | rc = ipw_config(priv); | |
11336 | if (!rc) { | |
11337 | IPW_DEBUG_INFO("Configured device on count %i\n", i); | |
e666619e JK |
11338 | |
11339 | /* If configure to try and auto-associate, kick | |
11340 | * off a scan. */ | |
c4028958 DH |
11341 | queue_delayed_work(priv->workqueue, |
11342 | &priv->request_scan, 0); | |
afbf30a2 | 11343 | |
43f66a6c | 11344 | return 0; |
43f66a6c | 11345 | } |
bf79451e | 11346 | |
c848d0af | 11347 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
43f66a6c JK |
11348 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
11349 | i, MAX_HW_RESTARTS); | |
11350 | ||
11351 | /* We had an error bringing up the hardware, so take it | |
11352 | * all the way back down so we can try again */ | |
11353 | ipw_down(priv); | |
11354 | } | |
11355 | ||
bf79451e | 11356 | /* tried to restart and config the device for as long as our |
43f66a6c | 11357 | * patience could withstand */ |
0edd5b44 | 11358 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
c848d0af | 11359 | |
43f66a6c JK |
11360 | return -EIO; |
11361 | } | |
11362 | ||
c4028958 | 11363 | static void ipw_bg_up(struct work_struct *work) |
c848d0af | 11364 | { |
c4028958 DH |
11365 | struct ipw_priv *priv = |
11366 | container_of(work, struct ipw_priv, up); | |
4644151b | 11367 | mutex_lock(&priv->mutex); |
c4028958 | 11368 | ipw_up(priv); |
4644151b | 11369 | mutex_unlock(&priv->mutex); |
c848d0af JK |
11370 | } |
11371 | ||
b095c381 | 11372 | static void ipw_deinit(struct ipw_priv *priv) |
43f66a6c | 11373 | { |
b095c381 JK |
11374 | int i; |
11375 | ||
11376 | if (priv->status & STATUS_SCANNING) { | |
11377 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); | |
11378 | ipw_abort_scan(priv); | |
11379 | } | |
11380 | ||
11381 | if (priv->status & STATUS_ASSOCIATED) { | |
11382 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); | |
11383 | ipw_disassociate(priv); | |
11384 | } | |
11385 | ||
11386 | ipw_led_shutdown(priv); | |
11387 | ||
11388 | /* Wait up to 1s for status to change to not scanning and not | |
11389 | * associated (disassociation can take a while for a ful 802.11 | |
11390 | * exchange */ | |
11391 | for (i = 1000; i && (priv->status & | |
11392 | (STATUS_DISASSOCIATING | | |
11393 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) | |
11394 | udelay(10); | |
11395 | ||
11396 | if (priv->status & (STATUS_DISASSOCIATING | | |
11397 | STATUS_ASSOCIATED | STATUS_SCANNING)) | |
11398 | IPW_DEBUG_INFO("Still associated or scanning...\n"); | |
11399 | else | |
11400 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); | |
11401 | ||
43f66a6c | 11402 | /* Attempt to disable the card */ |
43f66a6c | 11403 | ipw_send_card_disable(priv, 0); |
b095c381 JK |
11404 | |
11405 | priv->status &= ~STATUS_INIT; | |
11406 | } | |
11407 | ||
11408 | static void ipw_down(struct ipw_priv *priv) | |
11409 | { | |
11410 | int exit_pending = priv->status & STATUS_EXIT_PENDING; | |
11411 | ||
11412 | priv->status |= STATUS_EXIT_PENDING; | |
11413 | ||
11414 | if (ipw_is_init(priv)) | |
11415 | ipw_deinit(priv); | |
11416 | ||
11417 | /* Wipe out the EXIT_PENDING status bit if we are not actually | |
11418 | * exiting the module */ | |
11419 | if (!exit_pending) | |
11420 | priv->status &= ~STATUS_EXIT_PENDING; | |
43f66a6c JK |
11421 | |
11422 | /* tell the device to stop sending interrupts */ | |
11423 | ipw_disable_interrupts(priv); | |
11424 | ||
11425 | /* Clear all bits but the RF Kill */ | |
b095c381 | 11426 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
43f66a6c | 11427 | netif_carrier_off(priv->net_dev); |
43f66a6c JK |
11428 | |
11429 | ipw_stop_nic(priv); | |
a613bffd JK |
11430 | |
11431 | ipw_led_radio_off(priv); | |
43f66a6c JK |
11432 | } |
11433 | ||
c4028958 | 11434 | static void ipw_bg_down(struct work_struct *work) |
c848d0af | 11435 | { |
c4028958 DH |
11436 | struct ipw_priv *priv = |
11437 | container_of(work, struct ipw_priv, down); | |
4644151b | 11438 | mutex_lock(&priv->mutex); |
c4028958 | 11439 | ipw_down(priv); |
4644151b | 11440 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
11441 | } |
11442 | ||
11443 | /* Called by register_netdev() */ | |
11444 | static int ipw_net_init(struct net_device *dev) | |
11445 | { | |
a3caa99e | 11446 | int i, rc = 0; |
b0a4e7d8 | 11447 | struct ipw_priv *priv = libipw_priv(dev); |
a3caa99e JL |
11448 | const struct libipw_geo *geo = libipw_get_geo(priv->ieee); |
11449 | struct wireless_dev *wdev = &priv->ieee->wdev; | |
4644151b | 11450 | mutex_lock(&priv->mutex); |
43f66a6c | 11451 | |
c848d0af | 11452 | if (ipw_up(priv)) { |
a3caa99e JL |
11453 | rc = -EIO; |
11454 | goto out; | |
b8ecd988 JL |
11455 | } |
11456 | ||
a3caa99e JL |
11457 | memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN); |
11458 | ||
11459 | /* fill-out priv->ieee->bg_band */ | |
11460 | if (geo->bg_channels) { | |
11461 | struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band; | |
11462 | ||
11463 | bg_band->band = IEEE80211_BAND_2GHZ; | |
11464 | bg_band->n_channels = geo->bg_channels; | |
11465 | bg_band->channels = | |
11466 | kzalloc(geo->bg_channels * | |
11467 | sizeof(struct ieee80211_channel), GFP_KERNEL); | |
11468 | /* translate geo->bg to bg_band.channels */ | |
11469 | for (i = 0; i < geo->bg_channels; i++) { | |
11470 | bg_band->channels[i].band = IEEE80211_BAND_2GHZ; | |
11471 | bg_band->channels[i].center_freq = geo->bg[i].freq; | |
11472 | bg_band->channels[i].hw_value = geo->bg[i].channel; | |
11473 | bg_band->channels[i].max_power = geo->bg[i].max_power; | |
11474 | if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) | |
11475 | bg_band->channels[i].flags |= | |
11476 | IEEE80211_CHAN_PASSIVE_SCAN; | |
11477 | if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS) | |
11478 | bg_band->channels[i].flags |= | |
11479 | IEEE80211_CHAN_NO_IBSS; | |
11480 | if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT) | |
11481 | bg_band->channels[i].flags |= | |
11482 | IEEE80211_CHAN_RADAR; | |
11483 | /* No equivalent for LIBIPW_CH_80211H_RULES, | |
11484 | LIBIPW_CH_UNIFORM_SPREADING, or | |
11485 | LIBIPW_CH_B_ONLY... */ | |
11486 | } | |
11487 | /* point at bitrate info */ | |
11488 | bg_band->bitrates = ipw2200_bg_rates; | |
11489 | bg_band->n_bitrates = ipw2200_num_bg_rates; | |
11490 | ||
11491 | wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band; | |
b8ecd988 JL |
11492 | } |
11493 | ||
a3caa99e JL |
11494 | /* fill-out priv->ieee->a_band */ |
11495 | if (geo->a_channels) { | |
11496 | struct ieee80211_supported_band *a_band = &priv->ieee->a_band; | |
11497 | ||
11498 | a_band->band = IEEE80211_BAND_5GHZ; | |
11499 | a_band->n_channels = geo->a_channels; | |
11500 | a_band->channels = | |
11501 | kzalloc(geo->a_channels * | |
11502 | sizeof(struct ieee80211_channel), GFP_KERNEL); | |
11503 | /* translate geo->bg to a_band.channels */ | |
11504 | for (i = 0; i < geo->a_channels; i++) { | |
11505 | a_band->channels[i].band = IEEE80211_BAND_2GHZ; | |
11506 | a_band->channels[i].center_freq = geo->a[i].freq; | |
11507 | a_band->channels[i].hw_value = geo->a[i].channel; | |
11508 | a_band->channels[i].max_power = geo->a[i].max_power; | |
11509 | if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) | |
11510 | a_band->channels[i].flags |= | |
11511 | IEEE80211_CHAN_PASSIVE_SCAN; | |
11512 | if (geo->a[i].flags & LIBIPW_CH_NO_IBSS) | |
11513 | a_band->channels[i].flags |= | |
11514 | IEEE80211_CHAN_NO_IBSS; | |
11515 | if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT) | |
11516 | a_band->channels[i].flags |= | |
11517 | IEEE80211_CHAN_RADAR; | |
11518 | /* No equivalent for LIBIPW_CH_80211H_RULES, | |
11519 | LIBIPW_CH_UNIFORM_SPREADING, or | |
11520 | LIBIPW_CH_B_ONLY... */ | |
11521 | } | |
11522 | /* point at bitrate info */ | |
11523 | a_band->bitrates = ipw2200_a_rates; | |
11524 | a_band->n_bitrates = ipw2200_num_a_rates; | |
11525 | ||
11526 | wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band; | |
11527 | } | |
11528 | ||
11529 | set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev); | |
11530 | ||
11531 | /* With that information in place, we can now register the wiphy... */ | |
11532 | if (wiphy_register(wdev->wiphy)) { | |
11533 | rc = -EIO; | |
11534 | goto out; | |
11535 | } | |
11536 | ||
11537 | out: | |
4644151b | 11538 | mutex_unlock(&priv->mutex); |
a3caa99e | 11539 | return rc; |
43f66a6c JK |
11540 | } |
11541 | ||
11542 | /* PCI driver stuff */ | |
a3aa1884 | 11543 | static DEFINE_PCI_DEVICE_TABLE(card_ids) = { |
43f66a6c JK |
11544 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, |
11545 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, | |
11546 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, | |
11547 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, | |
11548 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, | |
11549 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, | |
11550 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, | |
11551 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, | |
11552 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, | |
11553 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, | |
11554 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, | |
11555 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, | |
11556 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, | |
11557 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, | |
11558 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, | |
11559 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, | |
11560 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, | |
8ab0ea77 JP |
11561 | {PCI_VDEVICE(INTEL, 0x104f), 0}, |
11562 | {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */ | |
11563 | {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */ | |
11564 | {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */ | |
11565 | {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */ | |
bf79451e | 11566 | |
43f66a6c JK |
11567 | /* required last entry */ |
11568 | {0,} | |
11569 | }; | |
11570 | ||
11571 | MODULE_DEVICE_TABLE(pci, card_ids); | |
11572 | ||
11573 | static struct attribute *ipw_sysfs_entries[] = { | |
11574 | &dev_attr_rf_kill.attr, | |
11575 | &dev_attr_direct_dword.attr, | |
11576 | &dev_attr_indirect_byte.attr, | |
11577 | &dev_attr_indirect_dword.attr, | |
11578 | &dev_attr_mem_gpio_reg.attr, | |
11579 | &dev_attr_command_event_reg.attr, | |
11580 | &dev_attr_nic_type.attr, | |
11581 | &dev_attr_status.attr, | |
11582 | &dev_attr_cfg.attr, | |
b39860c6 JK |
11583 | &dev_attr_error.attr, |
11584 | &dev_attr_event_log.attr, | |
f6c5cb7c | 11585 | &dev_attr_cmd_log.attr, |
43f66a6c JK |
11586 | &dev_attr_eeprom_delay.attr, |
11587 | &dev_attr_ucode_version.attr, | |
11588 | &dev_attr_rtc.attr, | |
a613bffd JK |
11589 | &dev_attr_scan_age.attr, |
11590 | &dev_attr_led.attr, | |
b095c381 JK |
11591 | &dev_attr_speed_scan.attr, |
11592 | &dev_attr_net_stats.attr, | |
375dd244 | 11593 | &dev_attr_channels.attr, |
d685b8c2 ZY |
11594 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
11595 | &dev_attr_rtap_iface.attr, | |
11596 | &dev_attr_rtap_filter.attr, | |
11597 | #endif | |
43f66a6c JK |
11598 | NULL |
11599 | }; | |
11600 | ||
11601 | static struct attribute_group ipw_attribute_group = { | |
11602 | .name = NULL, /* put in device directory */ | |
0edd5b44 | 11603 | .attrs = ipw_sysfs_entries, |
43f66a6c JK |
11604 | }; |
11605 | ||
d685b8c2 ZY |
11606 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
11607 | static int ipw_prom_open(struct net_device *dev) | |
11608 | { | |
b0a4e7d8 | 11609 | struct ipw_prom_priv *prom_priv = libipw_priv(dev); |
d685b8c2 ZY |
11610 | struct ipw_priv *priv = prom_priv->priv; |
11611 | ||
11612 | IPW_DEBUG_INFO("prom dev->open\n"); | |
11613 | netif_carrier_off(dev); | |
d685b8c2 ZY |
11614 | |
11615 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { | |
11616 | priv->sys_config.accept_all_data_frames = 1; | |
11617 | priv->sys_config.accept_non_directed_frames = 1; | |
11618 | priv->sys_config.accept_all_mgmt_bcpr = 1; | |
11619 | priv->sys_config.accept_all_mgmt_frames = 1; | |
11620 | ||
11621 | ipw_send_system_config(priv); | |
11622 | } | |
11623 | ||
11624 | return 0; | |
11625 | } | |
11626 | ||
11627 | static int ipw_prom_stop(struct net_device *dev) | |
11628 | { | |
b0a4e7d8 | 11629 | struct ipw_prom_priv *prom_priv = libipw_priv(dev); |
d685b8c2 ZY |
11630 | struct ipw_priv *priv = prom_priv->priv; |
11631 | ||
11632 | IPW_DEBUG_INFO("prom dev->stop\n"); | |
11633 | ||
11634 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { | |
11635 | priv->sys_config.accept_all_data_frames = 0; | |
11636 | priv->sys_config.accept_non_directed_frames = 0; | |
11637 | priv->sys_config.accept_all_mgmt_bcpr = 0; | |
11638 | priv->sys_config.accept_all_mgmt_frames = 0; | |
11639 | ||
11640 | ipw_send_system_config(priv); | |
11641 | } | |
11642 | ||
11643 | return 0; | |
11644 | } | |
11645 | ||
d0cf9c0d SH |
11646 | static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb, |
11647 | struct net_device *dev) | |
d685b8c2 ZY |
11648 | { |
11649 | IPW_DEBUG_INFO("prom dev->xmit\n"); | |
4153e775 PM |
11650 | dev_kfree_skb(skb); |
11651 | return NETDEV_TX_OK; | |
d685b8c2 ZY |
11652 | } |
11653 | ||
44e9ad0b SH |
11654 | static const struct net_device_ops ipw_prom_netdev_ops = { |
11655 | .ndo_open = ipw_prom_open, | |
11656 | .ndo_stop = ipw_prom_stop, | |
11657 | .ndo_start_xmit = ipw_prom_hard_start_xmit, | |
b0a4e7d8 | 11658 | .ndo_change_mtu = libipw_change_mtu, |
44e9ad0b SH |
11659 | .ndo_set_mac_address = eth_mac_addr, |
11660 | .ndo_validate_addr = eth_validate_addr, | |
11661 | }; | |
11662 | ||
d685b8c2 ZY |
11663 | static int ipw_prom_alloc(struct ipw_priv *priv) |
11664 | { | |
11665 | int rc = 0; | |
11666 | ||
11667 | if (priv->prom_net_dev) | |
11668 | return -EPERM; | |
11669 | ||
a3caa99e | 11670 | priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv), 1); |
d685b8c2 ZY |
11671 | if (priv->prom_net_dev == NULL) |
11672 | return -ENOMEM; | |
11673 | ||
b0a4e7d8 | 11674 | priv->prom_priv = libipw_priv(priv->prom_net_dev); |
d685b8c2 ZY |
11675 | priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev); |
11676 | priv->prom_priv->priv = priv; | |
11677 | ||
11678 | strcpy(priv->prom_net_dev->name, "rtap%d"); | |
3f2eeac9 | 11679 | memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN); |
d685b8c2 ZY |
11680 | |
11681 | priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | |
44e9ad0b | 11682 | priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops; |
d685b8c2 ZY |
11683 | |
11684 | priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR; | |
229ce3ab | 11685 | SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev); |
d685b8c2 ZY |
11686 | |
11687 | rc = register_netdev(priv->prom_net_dev); | |
11688 | if (rc) { | |
a3caa99e | 11689 | free_ieee80211(priv->prom_net_dev, 1); |
d685b8c2 ZY |
11690 | priv->prom_net_dev = NULL; |
11691 | return rc; | |
11692 | } | |
11693 | ||
11694 | return 0; | |
11695 | } | |
11696 | ||
11697 | static void ipw_prom_free(struct ipw_priv *priv) | |
11698 | { | |
11699 | if (!priv->prom_net_dev) | |
11700 | return; | |
11701 | ||
11702 | unregister_netdev(priv->prom_net_dev); | |
a3caa99e | 11703 | free_ieee80211(priv->prom_net_dev, 1); |
d685b8c2 ZY |
11704 | |
11705 | priv->prom_net_dev = NULL; | |
11706 | } | |
11707 | ||
11708 | #endif | |
11709 | ||
44e9ad0b SH |
11710 | static const struct net_device_ops ipw_netdev_ops = { |
11711 | .ndo_init = ipw_net_init, | |
11712 | .ndo_open = ipw_net_open, | |
11713 | .ndo_stop = ipw_net_stop, | |
11714 | .ndo_set_multicast_list = ipw_net_set_multicast_list, | |
11715 | .ndo_set_mac_address = ipw_net_set_mac_address, | |
b0a4e7d8 JL |
11716 | .ndo_start_xmit = libipw_xmit, |
11717 | .ndo_change_mtu = libipw_change_mtu, | |
44e9ad0b SH |
11718 | .ndo_validate_addr = eth_validate_addr, |
11719 | }; | |
d685b8c2 | 11720 | |
2ef19e63 AB |
11721 | static int __devinit ipw_pci_probe(struct pci_dev *pdev, |
11722 | const struct pci_device_id *ent) | |
43f66a6c JK |
11723 | { |
11724 | int err = 0; | |
11725 | struct net_device *net_dev; | |
11726 | void __iomem *base; | |
11727 | u32 length, val; | |
11728 | struct ipw_priv *priv; | |
afbf30a2 | 11729 | int i; |
43f66a6c | 11730 | |
a3caa99e | 11731 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv), 0); |
43f66a6c JK |
11732 | if (net_dev == NULL) { |
11733 | err = -ENOMEM; | |
11734 | goto out; | |
11735 | } | |
11736 | ||
b0a4e7d8 | 11737 | priv = libipw_priv(net_dev); |
43f66a6c | 11738 | priv->ieee = netdev_priv(net_dev); |
a613bffd | 11739 | |
43f66a6c JK |
11740 | priv->net_dev = net_dev; |
11741 | priv->pci_dev = pdev; | |
43f66a6c | 11742 | ipw_debug_level = debug; |
89c318ed | 11743 | spin_lock_init(&priv->irq_lock); |
43f66a6c | 11744 | spin_lock_init(&priv->lock); |
afbf30a2 JK |
11745 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
11746 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); | |
43f66a6c | 11747 | |
4644151b | 11748 | mutex_init(&priv->mutex); |
43f66a6c JK |
11749 | if (pci_enable_device(pdev)) { |
11750 | err = -ENODEV; | |
11751 | goto out_free_ieee80211; | |
11752 | } | |
11753 | ||
11754 | pci_set_master(pdev); | |
11755 | ||
284901a9 | 11756 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
bf79451e | 11757 | if (!err) |
284901a9 | 11758 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
43f66a6c JK |
11759 | if (err) { |
11760 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); | |
11761 | goto out_pci_disable_device; | |
11762 | } | |
11763 | ||
11764 | pci_set_drvdata(pdev, priv); | |
11765 | ||
11766 | err = pci_request_regions(pdev, DRV_NAME); | |
bf79451e | 11767 | if (err) |
43f66a6c JK |
11768 | goto out_pci_disable_device; |
11769 | ||
bf79451e | 11770 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
43f66a6c | 11771 | * PCI Tx retries from interfering with C3 CPU state */ |
bf79451e JG |
11772 | pci_read_config_dword(pdev, 0x40, &val); |
11773 | if ((val & 0x0000ff00) != 0) | |
43f66a6c | 11774 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
bf79451e | 11775 | |
43f66a6c JK |
11776 | length = pci_resource_len(pdev, 0); |
11777 | priv->hw_len = length; | |
bf79451e | 11778 | |
275f165f | 11779 | base = pci_ioremap_bar(pdev, 0); |
43f66a6c JK |
11780 | if (!base) { |
11781 | err = -ENODEV; | |
11782 | goto out_pci_release_regions; | |
11783 | } | |
11784 | ||
11785 | priv->hw_base = base; | |
11786 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); | |
11787 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); | |
11788 | ||
11789 | err = ipw_setup_deferred_work(priv); | |
11790 | if (err) { | |
11791 | IPW_ERROR("Unable to setup deferred work\n"); | |
11792 | goto out_iounmap; | |
11793 | } | |
11794 | ||
b095c381 | 11795 | ipw_sw_reset(priv, 1); |
43f66a6c | 11796 | |
1fb9df5d | 11797 | err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv); |
43f66a6c JK |
11798 | if (err) { |
11799 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); | |
11800 | goto out_destroy_workqueue; | |
11801 | } | |
11802 | ||
43f66a6c JK |
11803 | SET_NETDEV_DEV(net_dev, &pdev->dev); |
11804 | ||
4644151b | 11805 | mutex_lock(&priv->mutex); |
c848d0af | 11806 | |
43f66a6c JK |
11807 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
11808 | priv->ieee->set_security = shim__set_security; | |
227d2dc1 | 11809 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
43f66a6c | 11810 | |
e43e3c1e | 11811 | #ifdef CONFIG_IPW2200_QOS |
a5cf4fe6 | 11812 | priv->ieee->is_qos_active = ipw_is_qos_active; |
3b9990cb JK |
11813 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
11814 | priv->ieee->handle_beacon = ipw_handle_probe_response; | |
11815 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; | |
e43e3c1e | 11816 | #endif /* CONFIG_IPW2200_QOS */ |
b095c381 | 11817 | |
c848d0af JK |
11818 | priv->ieee->perfect_rssi = -20; |
11819 | priv->ieee->worst_rssi = -85; | |
43f66a6c | 11820 | |
44e9ad0b | 11821 | net_dev->netdev_ops = &ipw_netdev_ops; |
97a78ca9 | 11822 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
97a78ca9 | 11823 | net_dev->wireless_data = &priv->wireless_data; |
43f66a6c JK |
11824 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
11825 | net_dev->ethtool_ops = &ipw_ethtool_ops; | |
11826 | net_dev->irq = pdev->irq; | |
0edd5b44 | 11827 | net_dev->base_addr = (unsigned long)priv->hw_base; |
43f66a6c JK |
11828 | net_dev->mem_start = pci_resource_start(pdev, 0); |
11829 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; | |
11830 | ||
11831 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); | |
11832 | if (err) { | |
11833 | IPW_ERROR("failed to create sysfs device attributes\n"); | |
4644151b | 11834 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
11835 | goto out_release_irq; |
11836 | } | |
11837 | ||
4644151b | 11838 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
11839 | err = register_netdev(net_dev); |
11840 | if (err) { | |
11841 | IPW_ERROR("failed to register network device\n"); | |
a613bffd | 11842 | goto out_remove_sysfs; |
43f66a6c | 11843 | } |
48a84770 | 11844 | |
d685b8c2 ZY |
11845 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
11846 | if (rtap_iface) { | |
11847 | err = ipw_prom_alloc(priv); | |
11848 | if (err) { | |
11849 | IPW_ERROR("Failed to register promiscuous network " | |
11850 | "device (error %d).\n", err); | |
11851 | unregister_netdev(priv->net_dev); | |
11852 | goto out_remove_sysfs; | |
11853 | } | |
11854 | } | |
11855 | #endif | |
11856 | ||
48a84770 HBA |
11857 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " |
11858 | "channels, %d 802.11a channels)\n", | |
11859 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, | |
11860 | priv->ieee->geo.a_channels); | |
11861 | ||
43f66a6c JK |
11862 | return 0; |
11863 | ||
a613bffd | 11864 | out_remove_sysfs: |
43f66a6c | 11865 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
0edd5b44 | 11866 | out_release_irq: |
43f66a6c | 11867 | free_irq(pdev->irq, priv); |
0edd5b44 | 11868 | out_destroy_workqueue: |
43f66a6c JK |
11869 | destroy_workqueue(priv->workqueue); |
11870 | priv->workqueue = NULL; | |
0edd5b44 | 11871 | out_iounmap: |
43f66a6c | 11872 | iounmap(priv->hw_base); |
0edd5b44 | 11873 | out_pci_release_regions: |
43f66a6c | 11874 | pci_release_regions(pdev); |
0edd5b44 | 11875 | out_pci_disable_device: |
43f66a6c JK |
11876 | pci_disable_device(pdev); |
11877 | pci_set_drvdata(pdev, NULL); | |
0edd5b44 | 11878 | out_free_ieee80211: |
a3caa99e | 11879 | free_ieee80211(priv->net_dev, 0); |
0edd5b44 | 11880 | out: |
43f66a6c JK |
11881 | return err; |
11882 | } | |
11883 | ||
2ef19e63 | 11884 | static void __devexit ipw_pci_remove(struct pci_dev *pdev) |
43f66a6c JK |
11885 | { |
11886 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
afbf30a2 JK |
11887 | struct list_head *p, *q; |
11888 | int i; | |
b095c381 | 11889 | |
43f66a6c JK |
11890 | if (!priv) |
11891 | return; | |
11892 | ||
4644151b | 11893 | mutex_lock(&priv->mutex); |
43f66a6c | 11894 | |
afbf30a2 | 11895 | priv->status |= STATUS_EXIT_PENDING; |
43f66a6c | 11896 | ipw_down(priv); |
43f66a6c JK |
11897 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
11898 | ||
4644151b | 11899 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
11900 | |
11901 | unregister_netdev(priv->net_dev); | |
11902 | ||
11903 | if (priv->rxq) { | |
11904 | ipw_rx_queue_free(priv, priv->rxq); | |
11905 | priv->rxq = NULL; | |
11906 | } | |
11907 | ipw_tx_queue_free(priv); | |
11908 | ||
f6c5cb7c JK |
11909 | if (priv->cmdlog) { |
11910 | kfree(priv->cmdlog); | |
11911 | priv->cmdlog = NULL; | |
11912 | } | |
43f66a6c JK |
11913 | /* ipw_down will ensure that there is no more pending work |
11914 | * in the workqueue's, so we can safely remove them now. */ | |
a613bffd JK |
11915 | cancel_delayed_work(&priv->adhoc_check); |
11916 | cancel_delayed_work(&priv->gather_stats); | |
11917 | cancel_delayed_work(&priv->request_scan); | |
ea177305 DW |
11918 | cancel_delayed_work(&priv->request_direct_scan); |
11919 | cancel_delayed_work(&priv->request_passive_scan); | |
0b531676 | 11920 | cancel_delayed_work(&priv->scan_event); |
a613bffd JK |
11921 | cancel_delayed_work(&priv->rf_kill); |
11922 | cancel_delayed_work(&priv->scan_check); | |
11923 | destroy_workqueue(priv->workqueue); | |
11924 | priv->workqueue = NULL; | |
43f66a6c | 11925 | |
afbf30a2 JK |
11926 | /* Free MAC hash list for ADHOC */ |
11927 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { | |
11928 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { | |
afbf30a2 | 11929 | list_del(p); |
489f4458 | 11930 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
afbf30a2 JK |
11931 | } |
11932 | } | |
11933 | ||
8f760780 JJ |
11934 | kfree(priv->error); |
11935 | priv->error = NULL; | |
43f66a6c | 11936 | |
d685b8c2 ZY |
11937 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
11938 | ipw_prom_free(priv); | |
11939 | #endif | |
11940 | ||
43f66a6c JK |
11941 | free_irq(pdev->irq, priv); |
11942 | iounmap(priv->hw_base); | |
11943 | pci_release_regions(pdev); | |
11944 | pci_disable_device(pdev); | |
11945 | pci_set_drvdata(pdev, NULL); | |
a3caa99e JL |
11946 | /* wiphy_unregister needs to be here, before free_ieee80211 */ |
11947 | wiphy_unregister(priv->ieee->wdev.wiphy); | |
11948 | kfree(priv->ieee->a_band.channels); | |
11949 | kfree(priv->ieee->bg_band.channels); | |
11950 | free_ieee80211(priv->net_dev, 0); | |
afbf30a2 | 11951 | free_firmware(); |
43f66a6c JK |
11952 | } |
11953 | ||
43f66a6c | 11954 | #ifdef CONFIG_PM |
583a4e88 | 11955 | static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
43f66a6c JK |
11956 | { |
11957 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
11958 | struct net_device *dev = priv->net_dev; | |
11959 | ||
11960 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); | |
11961 | ||
0edd5b44 | 11962 | /* Take down the device; powers it off, etc. */ |
43f66a6c JK |
11963 | ipw_down(priv); |
11964 | ||
11965 | /* Remove the PRESENT state of the device */ | |
11966 | netif_device_detach(dev); | |
11967 | ||
43f66a6c | 11968 | pci_save_state(pdev); |
43f66a6c | 11969 | pci_disable_device(pdev); |
583a4e88 | 11970 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
bf79451e | 11971 | |
c3d72b96 DW |
11972 | priv->suspend_at = get_seconds(); |
11973 | ||
43f66a6c JK |
11974 | return 0; |
11975 | } | |
11976 | ||
11977 | static int ipw_pci_resume(struct pci_dev *pdev) | |
11978 | { | |
11979 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
11980 | struct net_device *dev = priv->net_dev; | |
02e0e5e9 | 11981 | int err; |
43f66a6c | 11982 | u32 val; |
bf79451e | 11983 | |
43f66a6c JK |
11984 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
11985 | ||
ea2b26e0 | 11986 | pci_set_power_state(pdev, PCI_D0); |
02e0e5e9 JL |
11987 | err = pci_enable_device(pdev); |
11988 | if (err) { | |
11989 | printk(KERN_ERR "%s: pci_enable_device failed on resume\n", | |
11990 | dev->name); | |
11991 | return err; | |
11992 | } | |
43f66a6c | 11993 | pci_restore_state(pdev); |
ea2b26e0 | 11994 | |
43f66a6c JK |
11995 | /* |
11996 | * Suspend/Resume resets the PCI configuration space, so we have to | |
11997 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries | |
11998 | * from interfering with C3 CPU state. pci_restore_state won't help | |
11999 | * here since it only restores the first 64 bytes pci config header. | |
12000 | */ | |
bf79451e JG |
12001 | pci_read_config_dword(pdev, 0x40, &val); |
12002 | if ((val & 0x0000ff00) != 0) | |
43f66a6c JK |
12003 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
12004 | ||
12005 | /* Set the device back into the PRESENT state; this will also wake | |
12006 | * the queue of needed */ | |
12007 | netif_device_attach(dev); | |
12008 | ||
c3d72b96 DW |
12009 | priv->suspend_time = get_seconds() - priv->suspend_at; |
12010 | ||
43f66a6c JK |
12011 | /* Bring the device back up */ |
12012 | queue_work(priv->workqueue, &priv->up); | |
bf79451e | 12013 | |
43f66a6c JK |
12014 | return 0; |
12015 | } | |
12016 | #endif | |
12017 | ||
c8c22c94 ZY |
12018 | static void ipw_pci_shutdown(struct pci_dev *pdev) |
12019 | { | |
12020 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
12021 | ||
12022 | /* Take down the device; powers it off, etc. */ | |
12023 | ipw_down(priv); | |
12024 | ||
12025 | pci_disable_device(pdev); | |
12026 | } | |
12027 | ||
43f66a6c JK |
12028 | /* driver initialization stuff */ |
12029 | static struct pci_driver ipw_driver = { | |
12030 | .name = DRV_NAME, | |
12031 | .id_table = card_ids, | |
12032 | .probe = ipw_pci_probe, | |
12033 | .remove = __devexit_p(ipw_pci_remove), | |
12034 | #ifdef CONFIG_PM | |
12035 | .suspend = ipw_pci_suspend, | |
12036 | .resume = ipw_pci_resume, | |
12037 | #endif | |
c8c22c94 | 12038 | .shutdown = ipw_pci_shutdown, |
43f66a6c JK |
12039 | }; |
12040 | ||
12041 | static int __init ipw_init(void) | |
12042 | { | |
12043 | int ret; | |
12044 | ||
12045 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); | |
12046 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); | |
12047 | ||
29917620 | 12048 | ret = pci_register_driver(&ipw_driver); |
43f66a6c JK |
12049 | if (ret) { |
12050 | IPW_ERROR("Unable to initialize PCI module\n"); | |
12051 | return ret; | |
12052 | } | |
12053 | ||
0edd5b44 | 12054 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
43f66a6c JK |
12055 | if (ret) { |
12056 | IPW_ERROR("Unable to create driver sysfs file\n"); | |
12057 | pci_unregister_driver(&ipw_driver); | |
12058 | return ret; | |
12059 | } | |
12060 | ||
12061 | return ret; | |
12062 | } | |
12063 | ||
12064 | static void __exit ipw_exit(void) | |
12065 | { | |
12066 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); | |
12067 | pci_unregister_driver(&ipw_driver); | |
12068 | } | |
12069 | ||
12070 | module_param(disable, int, 0444); | |
12071 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); | |
12072 | ||
12073 | module_param(associate, int, 0444); | |
5c7f9b73 | 12074 | MODULE_PARM_DESC(associate, "auto associate when scanning (default off)"); |
43f66a6c JK |
12075 | |
12076 | module_param(auto_create, int, 0444); | |
12077 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); | |
12078 | ||
21f8a73f | 12079 | module_param_named(led, led_support, int, 0444); |
61a2d07d | 12080 | MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)"); |
a613bffd | 12081 | |
43f66a6c JK |
12082 | module_param(debug, int, 0444); |
12083 | MODULE_PARM_DESC(debug, "debug output mask"); | |
12084 | ||
21f8a73f | 12085 | module_param_named(channel, default_channel, int, 0444); |
bf79451e | 12086 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
43f66a6c | 12087 | |
d685b8c2 ZY |
12088 | #ifdef CONFIG_IPW2200_PROMISCUOUS |
12089 | module_param(rtap_iface, int, 0444); | |
12090 | MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)"); | |
12091 | #endif | |
12092 | ||
e43e3c1e | 12093 | #ifdef CONFIG_IPW2200_QOS |
b095c381 JK |
12094 | module_param(qos_enable, int, 0444); |
12095 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); | |
12096 | ||
12097 | module_param(qos_burst_enable, int, 0444); | |
12098 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); | |
12099 | ||
12100 | module_param(qos_no_ack_mask, int, 0444); | |
12101 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); | |
43f66a6c | 12102 | |
b095c381 JK |
12103 | module_param(burst_duration_CCK, int, 0444); |
12104 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); | |
12105 | ||
12106 | module_param(burst_duration_OFDM, int, 0444); | |
12107 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); | |
e43e3c1e | 12108 | #endif /* CONFIG_IPW2200_QOS */ |
b095c381 JK |
12109 | |
12110 | #ifdef CONFIG_IPW2200_MONITOR | |
21f8a73f | 12111 | module_param_named(mode, network_mode, int, 0444); |
43f66a6c JK |
12112 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); |
12113 | #else | |
21f8a73f | 12114 | module_param_named(mode, network_mode, int, 0444); |
43f66a6c JK |
12115 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); |
12116 | #endif | |
12117 | ||
810dabd4 ZY |
12118 | module_param(bt_coexist, int, 0444); |
12119 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); | |
12120 | ||
b095c381 | 12121 | module_param(hwcrypto, int, 0444); |
bde37d03 | 12122 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
b095c381 | 12123 | |
f6c5cb7c JK |
12124 | module_param(cmdlog, int, 0444); |
12125 | MODULE_PARM_DESC(cmdlog, | |
12126 | "allocate a ring buffer for logging firmware commands"); | |
12127 | ||
4bfdb91d ZY |
12128 | module_param(roaming, int, 0444); |
12129 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); | |
12130 | ||
d2b83e12 ZY |
12131 | module_param(antenna, int, 0444); |
12132 | MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)"); | |
12133 | ||
43f66a6c JK |
12134 | module_exit(ipw_exit); |
12135 | module_init(ipw_init); |