]>
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 JK |
27 | Contact Information: |
28 | James P. Ketrenos <ipw2100-admin@linux.intel.com> | |
29 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
30 | ||
31 | ******************************************************************************/ | |
32 | ||
33 | #include "ipw2200.h" | |
733482e4 | 34 | #include <linux/version.h> |
43f66a6c | 35 | |
7c567894 | 36 | #define IPW2200_VERSION "git-1.1.1" |
43f66a6c | 37 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" |
171e7b2f | 38 | #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation" |
43f66a6c JK |
39 | #define DRV_VERSION IPW2200_VERSION |
40 | ||
b095c381 JK |
41 | #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1) |
42 | ||
43f66a6c JK |
43 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
44 | MODULE_VERSION(DRV_VERSION); | |
45 | MODULE_AUTHOR(DRV_COPYRIGHT); | |
46 | MODULE_LICENSE("GPL"); | |
47 | ||
f6c5cb7c | 48 | static int cmdlog = 0; |
43f66a6c JK |
49 | static int debug = 0; |
50 | static int channel = 0; | |
43f66a6c JK |
51 | static int mode = 0; |
52 | ||
53 | static u32 ipw_debug_level; | |
54 | static int associate = 1; | |
55 | static int auto_create = 1; | |
a613bffd | 56 | static int led = 0; |
43f66a6c | 57 | static int disable = 0; |
810dabd4 | 58 | static int bt_coexist = 0; |
bde37d03 | 59 | static int hwcrypto = 0; |
4bfdb91d | 60 | static int roaming = 1; |
43f66a6c JK |
61 | static const char ipw_modes[] = { |
62 | 'a', 'b', 'g', '?' | |
63 | }; | |
64 | ||
b095c381 JK |
65 | #ifdef CONFIG_IPW_QOS |
66 | static int qos_enable = 0; | |
67 | static int qos_burst_enable = 0; | |
68 | static int qos_no_ack_mask = 0; | |
69 | static int burst_duration_CCK = 0; | |
70 | static int burst_duration_OFDM = 0; | |
71 | ||
72 | static struct ieee80211_qos_parameters def_qos_parameters_OFDM = { | |
73 | {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM, | |
74 | QOS_TX3_CW_MIN_OFDM}, | |
75 | {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM, | |
76 | QOS_TX3_CW_MAX_OFDM}, | |
77 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, | |
78 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, | |
79 | {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM, | |
80 | QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM} | |
81 | }; | |
82 | ||
83 | static struct ieee80211_qos_parameters def_qos_parameters_CCK = { | |
84 | {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK, | |
85 | QOS_TX3_CW_MIN_CCK}, | |
86 | {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK, | |
87 | QOS_TX3_CW_MAX_CCK}, | |
88 | {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS}, | |
89 | {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM}, | |
90 | {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK, | |
91 | QOS_TX3_TXOP_LIMIT_CCK} | |
92 | }; | |
93 | ||
94 | static struct ieee80211_qos_parameters def_parameters_OFDM = { | |
95 | {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM, | |
96 | DEF_TX3_CW_MIN_OFDM}, | |
97 | {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM, | |
98 | DEF_TX3_CW_MAX_OFDM}, | |
99 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, | |
100 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, | |
101 | {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM, | |
102 | DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM} | |
103 | }; | |
104 | ||
105 | static struct ieee80211_qos_parameters def_parameters_CCK = { | |
106 | {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK, | |
107 | DEF_TX3_CW_MIN_CCK}, | |
108 | {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK, | |
109 | DEF_TX3_CW_MAX_CCK}, | |
110 | {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS}, | |
111 | {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM}, | |
112 | {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK, | |
113 | DEF_TX3_TXOP_LIMIT_CCK} | |
114 | }; | |
115 | ||
116 | static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 }; | |
117 | ||
118 | static int from_priority_to_tx_queue[] = { | |
119 | IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1, | |
120 | IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4 | |
121 | }; | |
122 | ||
123 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv); | |
124 | ||
125 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters | |
126 | *qos_param); | |
127 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element | |
128 | *qos_param); | |
129 | #endif /* CONFIG_IPW_QOS */ | |
130 | ||
97a78ca9 | 131 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev); |
b095c381 | 132 | static void ipw_remove_current_network(struct ipw_priv *priv); |
43f66a6c | 133 | static void ipw_rx(struct ipw_priv *priv); |
bf79451e | 134 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
43f66a6c JK |
135 | struct clx2_tx_queue *txq, int qindex); |
136 | static int ipw_queue_reset(struct ipw_priv *priv); | |
137 | ||
138 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, | |
139 | int len, int sync); | |
140 | ||
141 | static void ipw_tx_queue_free(struct ipw_priv *); | |
142 | ||
143 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); | |
144 | static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); | |
145 | static void ipw_rx_queue_replenish(void *); | |
43f66a6c | 146 | static int ipw_up(struct ipw_priv *); |
c848d0af | 147 | static void ipw_bg_up(void *); |
43f66a6c | 148 | static void ipw_down(struct ipw_priv *); |
c848d0af | 149 | static void ipw_bg_down(void *); |
43f66a6c | 150 | static int ipw_config(struct ipw_priv *); |
0edd5b44 JG |
151 | static int init_supported_rates(struct ipw_priv *priv, |
152 | struct ipw_supported_rates *prates); | |
b095c381 JK |
153 | static void ipw_set_hwcrypto_keys(struct ipw_priv *); |
154 | static void ipw_send_wep_keys(struct ipw_priv *, int); | |
43f66a6c | 155 | |
f6c5cb7c JK |
156 | static int snprint_line(char *buf, size_t count, |
157 | const u8 * data, u32 len, u32 ofs) | |
43f66a6c JK |
158 | { |
159 | int out, i, j, l; | |
160 | char c; | |
bf79451e | 161 | |
43f66a6c JK |
162 | out = snprintf(buf, count, "%08X", ofs); |
163 | ||
164 | for (l = 0, i = 0; i < 2; i++) { | |
165 | out += snprintf(buf + out, count - out, " "); | |
bf79451e JG |
166 | for (j = 0; j < 8 && l < len; j++, l++) |
167 | out += snprintf(buf + out, count - out, "%02X ", | |
43f66a6c JK |
168 | data[(i * 8 + j)]); |
169 | for (; j < 8; j++) | |
170 | out += snprintf(buf + out, count - out, " "); | |
171 | } | |
bf79451e | 172 | |
43f66a6c JK |
173 | out += snprintf(buf + out, count - out, " "); |
174 | for (l = 0, i = 0; i < 2; i++) { | |
175 | out += snprintf(buf + out, count - out, " "); | |
176 | for (j = 0; j < 8 && l < len; j++, l++) { | |
177 | c = data[(i * 8 + j)]; | |
178 | if (!isascii(c) || !isprint(c)) | |
179 | c = '.'; | |
bf79451e | 180 | |
43f66a6c JK |
181 | out += snprintf(buf + out, count - out, "%c", c); |
182 | } | |
183 | ||
184 | for (; j < 8; j++) | |
185 | out += snprintf(buf + out, count - out, " "); | |
186 | } | |
bf79451e | 187 | |
f6c5cb7c | 188 | return out; |
43f66a6c JK |
189 | } |
190 | ||
0edd5b44 | 191 | static void printk_buf(int level, const u8 * data, u32 len) |
43f66a6c JK |
192 | { |
193 | char line[81]; | |
194 | u32 ofs = 0; | |
195 | if (!(ipw_debug_level & level)) | |
196 | return; | |
197 | ||
198 | while (len) { | |
f6c5cb7c JK |
199 | snprint_line(line, sizeof(line), &data[ofs], |
200 | min(len, 16U), ofs); | |
201 | printk(KERN_DEBUG "%s\n", line); | |
43f66a6c JK |
202 | ofs += 16; |
203 | len -= min(len, 16U); | |
204 | } | |
205 | } | |
206 | ||
f6c5cb7c JK |
207 | static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len) |
208 | { | |
209 | size_t out = size; | |
210 | u32 ofs = 0; | |
211 | int total = 0; | |
212 | ||
213 | while (size && len) { | |
214 | out = snprint_line(output, size, &data[ofs], | |
215 | min_t(size_t, len, 16U), ofs); | |
216 | ||
217 | ofs += 16; | |
218 | output += out; | |
219 | size -= out; | |
220 | len -= min_t(size_t, len, 16U); | |
221 | total += out; | |
222 | } | |
223 | return total; | |
224 | } | |
225 | ||
c8fe6679 | 226 | /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
227 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); |
228 | #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) | |
229 | ||
c8fe6679 | 230 | /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
231 | static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg); |
232 | #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b) | |
233 | ||
c8fe6679 | 234 | /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
235 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value); |
236 | static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c) | |
237 | { | |
0edd5b44 JG |
238 | IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__, |
239 | __LINE__, (u32) (b), (u32) (c)); | |
43f66a6c JK |
240 | _ipw_write_reg8(a, b, c); |
241 | } | |
242 | ||
c8fe6679 | 243 | /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
244 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value); |
245 | static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c) | |
246 | { | |
0edd5b44 JG |
247 | IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__, |
248 | __LINE__, (u32) (b), (u32) (c)); | |
43f66a6c JK |
249 | _ipw_write_reg16(a, b, c); |
250 | } | |
251 | ||
c8fe6679 | 252 | /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */ |
43f66a6c JK |
253 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value); |
254 | static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c) | |
255 | { | |
0edd5b44 JG |
256 | IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__, |
257 | __LINE__, (u32) (b), (u32) (c)); | |
43f66a6c JK |
258 | _ipw_write_reg32(a, b, c); |
259 | } | |
260 | ||
c8fe6679 | 261 | /* 8-bit direct write (low 4K) */ |
43f66a6c | 262 | #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs)) |
c8fe6679 ZY |
263 | |
264 | /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ | |
43f66a6c JK |
265 | #define ipw_write8(ipw, ofs, val) \ |
266 | IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ | |
267 | _ipw_write8(ipw, ofs, val) | |
268 | ||
c8fe6679 | 269 | /* 16-bit direct write (low 4K) */ |
43f66a6c | 270 | #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs)) |
c8fe6679 ZY |
271 | |
272 | /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ | |
43f66a6c JK |
273 | #define ipw_write16(ipw, ofs, val) \ |
274 | IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ | |
275 | _ipw_write16(ipw, ofs, val) | |
276 | ||
c8fe6679 | 277 | /* 32-bit direct write (low 4K) */ |
43f66a6c | 278 | #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs)) |
c8fe6679 ZY |
279 | |
280 | /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */ | |
43f66a6c JK |
281 | #define ipw_write32(ipw, ofs, val) \ |
282 | IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \ | |
283 | _ipw_write32(ipw, ofs, val) | |
284 | ||
c8fe6679 | 285 | /* 8-bit direct read (low 4K) */ |
43f66a6c | 286 | #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs)) |
c8fe6679 ZY |
287 | |
288 | /* 8-bit direct read (low 4K), with debug wrapper */ | |
0edd5b44 JG |
289 | static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
290 | { | |
291 | IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs)); | |
43f66a6c JK |
292 | return _ipw_read8(ipw, ofs); |
293 | } | |
0edd5b44 | 294 | |
c8fe6679 | 295 | /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
43f66a6c JK |
296 | #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs) |
297 | ||
c8fe6679 | 298 | /* 16-bit direct read (low 4K) */ |
43f66a6c | 299 | #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs)) |
c8fe6679 ZY |
300 | |
301 | /* 16-bit direct read (low 4K), with debug wrapper */ | |
0edd5b44 JG |
302 | static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
303 | { | |
304 | IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs)); | |
43f66a6c JK |
305 | return _ipw_read16(ipw, ofs); |
306 | } | |
0edd5b44 | 307 | |
c8fe6679 | 308 | /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
43f66a6c JK |
309 | #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs) |
310 | ||
c8fe6679 | 311 | /* 32-bit direct read (low 4K) */ |
43f66a6c | 312 | #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs)) |
c8fe6679 ZY |
313 | |
314 | /* 32-bit direct read (low 4K), with debug wrapper */ | |
0edd5b44 JG |
315 | static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs) |
316 | { | |
317 | IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs)); | |
43f66a6c JK |
318 | return _ipw_read32(ipw, ofs); |
319 | } | |
0edd5b44 | 320 | |
c8fe6679 | 321 | /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */ |
43f66a6c JK |
322 | #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs) |
323 | ||
c8fe6679 | 324 | /* multi-byte read (above 4K), with debug wrapper */ |
43f66a6c | 325 | static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); |
f6c5cb7c JK |
326 | static inline void __ipw_read_indirect(const char *f, int l, |
327 | struct ipw_priv *a, u32 b, u8 * c, int d) | |
328 | { | |
329 | IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b), | |
330 | d); | |
331 | _ipw_read_indirect(a, b, c, d); | |
332 | } | |
333 | ||
c8fe6679 | 334 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
f6c5cb7c | 335 | #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d) |
43f66a6c | 336 | |
c8fe6679 | 337 | /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */ |
0edd5b44 JG |
338 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, |
339 | int num); | |
43f66a6c JK |
340 | #define ipw_write_indirect(a, b, c, d) \ |
341 | IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \ | |
afbf30a2 | 342 | _ipw_write_indirect(a, b, c, d) |
43f66a6c | 343 | |
c8fe6679 | 344 | /* 32-bit indirect write (above 4K) */ |
0edd5b44 | 345 | static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value) |
43f66a6c | 346 | { |
0edd5b44 | 347 | IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value); |
b095c381 JK |
348 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
349 | _ipw_write32(priv, IPW_INDIRECT_DATA, value); | |
43f66a6c JK |
350 | } |
351 | ||
c8fe6679 | 352 | /* 8-bit indirect write (above 4K) */ |
43f66a6c JK |
353 | static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) |
354 | { | |
2638bc39 | 355 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
c8fe6679 ZY |
356 | u32 dif_len = reg - aligned_addr; |
357 | ||
43f66a6c | 358 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
c8fe6679 ZY |
359 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
360 | _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value); | |
43f66a6c JK |
361 | } |
362 | ||
c8fe6679 | 363 | /* 16-bit indirect write (above 4K) */ |
0edd5b44 | 364 | static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value) |
43f66a6c | 365 | { |
2638bc39 | 366 | u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
c8fe6679 ZY |
367 | u32 dif_len = (reg - aligned_addr) & (~0x1ul); |
368 | ||
43f66a6c | 369 | IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); |
c8fe6679 ZY |
370 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
371 | _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value); | |
43f66a6c JK |
372 | } |
373 | ||
c8fe6679 | 374 | /* 8-bit indirect read (above 4K) */ |
43f66a6c JK |
375 | static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) |
376 | { | |
377 | u32 word; | |
b095c381 | 378 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK); |
43f66a6c | 379 | IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); |
b095c381 | 380 | word = _ipw_read32(priv, IPW_INDIRECT_DATA); |
0edd5b44 | 381 | return (word >> ((reg & 0x3) * 8)) & 0xff; |
43f66a6c JK |
382 | } |
383 | ||
c8fe6679 | 384 | /* 32-bit indirect read (above 4K) */ |
43f66a6c JK |
385 | static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg) |
386 | { | |
387 | u32 value; | |
388 | ||
389 | IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); | |
390 | ||
b095c381 JK |
391 | _ipw_write32(priv, IPW_INDIRECT_ADDR, reg); |
392 | value = _ipw_read32(priv, IPW_INDIRECT_DATA); | |
43f66a6c JK |
393 | IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); |
394 | return value; | |
395 | } | |
396 | ||
c8fe6679 ZY |
397 | /* General purpose, no alignment requirement, iterative (multi-byte) read, */ |
398 | /* for area above 1st 4K of SRAM/reg space */ | |
43f66a6c JK |
399 | static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
400 | int num) | |
401 | { | |
2638bc39 | 402 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
43f66a6c | 403 | u32 dif_len = addr - aligned_addr; |
43f66a6c | 404 | u32 i; |
bf79451e | 405 | |
43f66a6c JK |
406 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
407 | ||
ea2b26e0 JK |
408 | if (num <= 0) { |
409 | return; | |
410 | } | |
411 | ||
c8fe6679 | 412 | /* Read the first dword (or portion) byte by byte */ |
43f66a6c | 413 | if (unlikely(dif_len)) { |
b095c381 | 414 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
43f66a6c | 415 | /* Start reading at aligned_addr + dif_len */ |
ea2b26e0 | 416 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--) |
b095c381 | 417 | *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i); |
43f66a6c JK |
418 | aligned_addr += 4; |
419 | } | |
420 | ||
c8fe6679 | 421 | /* Read all of the middle dwords as dwords, with auto-increment */ |
b095c381 | 422 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
ea2b26e0 | 423 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
b095c381 | 424 | *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA); |
bf79451e | 425 | |
c8fe6679 | 426 | /* Read the last dword (or portion) byte by byte */ |
ea2b26e0 | 427 | if (unlikely(num)) { |
b095c381 | 428 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
ea2b26e0 | 429 | for (i = 0; num > 0; i++, num--) |
b095c381 | 430 | *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i); |
ea2b26e0 | 431 | } |
43f66a6c JK |
432 | } |
433 | ||
c8fe6679 ZY |
434 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
435 | /* for area above 1st 4K of SRAM/reg space */ | |
0edd5b44 | 436 | static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, |
43f66a6c JK |
437 | int num) |
438 | { | |
2638bc39 | 439 | u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */ |
43f66a6c | 440 | u32 dif_len = addr - aligned_addr; |
43f66a6c | 441 | u32 i; |
bf79451e | 442 | |
43f66a6c | 443 | IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); |
bf79451e | 444 | |
ea2b26e0 JK |
445 | if (num <= 0) { |
446 | return; | |
447 | } | |
448 | ||
c8fe6679 | 449 | /* Write the first dword (or portion) byte by byte */ |
43f66a6c | 450 | if (unlikely(dif_len)) { |
b095c381 | 451 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
c8fe6679 | 452 | /* Start writing at aligned_addr + dif_len */ |
ea2b26e0 | 453 | for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++) |
b095c381 | 454 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
43f66a6c JK |
455 | aligned_addr += 4; |
456 | } | |
bf79451e | 457 | |
c8fe6679 | 458 | /* Write all of the middle dwords as dwords, with auto-increment */ |
b095c381 | 459 | _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr); |
ea2b26e0 | 460 | for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4) |
b095c381 | 461 | _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf); |
bf79451e | 462 | |
c8fe6679 | 463 | /* Write the last dword (or portion) byte by byte */ |
ea2b26e0 | 464 | if (unlikely(num)) { |
b095c381 | 465 | _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr); |
ea2b26e0 | 466 | for (i = 0; num > 0; i++, num--, buf++) |
b095c381 | 467 | _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf); |
ea2b26e0 | 468 | } |
43f66a6c JK |
469 | } |
470 | ||
c8fe6679 ZY |
471 | /* General purpose, no alignment requirement, iterative (multi-byte) write, */ |
472 | /* for 1st 4K of SRAM/regs space */ | |
bf79451e | 473 | static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf, |
43f66a6c JK |
474 | int num) |
475 | { | |
476 | memcpy_toio((priv->hw_base + addr), buf, num); | |
477 | } | |
478 | ||
c8fe6679 | 479 | /* Set bit(s) in low 4K of SRAM/regs */ |
43f66a6c JK |
480 | static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
481 | { | |
482 | ipw_write32(priv, reg, ipw_read32(priv, reg) | mask); | |
483 | } | |
484 | ||
c8fe6679 | 485 | /* Clear bit(s) in low 4K of SRAM/regs */ |
43f66a6c JK |
486 | static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask) |
487 | { | |
488 | ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask); | |
489 | } | |
490 | ||
491 | static inline void ipw_enable_interrupts(struct ipw_priv *priv) | |
492 | { | |
493 | if (priv->status & STATUS_INT_ENABLED) | |
494 | return; | |
495 | priv->status |= STATUS_INT_ENABLED; | |
b095c381 | 496 | ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL); |
43f66a6c JK |
497 | } |
498 | ||
499 | static inline void ipw_disable_interrupts(struct ipw_priv *priv) | |
500 | { | |
501 | if (!(priv->status & STATUS_INT_ENABLED)) | |
502 | return; | |
503 | priv->status &= ~STATUS_INT_ENABLED; | |
b095c381 | 504 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
43f66a6c JK |
505 | } |
506 | ||
0f52bf90 | 507 | #ifdef CONFIG_IPW2200_DEBUG |
43f66a6c JK |
508 | static char *ipw_error_desc(u32 val) |
509 | { | |
510 | switch (val) { | |
bf79451e | 511 | case IPW_FW_ERROR_OK: |
43f66a6c | 512 | return "ERROR_OK"; |
bf79451e | 513 | case IPW_FW_ERROR_FAIL: |
43f66a6c | 514 | return "ERROR_FAIL"; |
bf79451e | 515 | case IPW_FW_ERROR_MEMORY_UNDERFLOW: |
43f66a6c | 516 | return "MEMORY_UNDERFLOW"; |
bf79451e | 517 | case IPW_FW_ERROR_MEMORY_OVERFLOW: |
43f66a6c | 518 | return "MEMORY_OVERFLOW"; |
bf79451e | 519 | case IPW_FW_ERROR_BAD_PARAM: |
b095c381 | 520 | return "BAD_PARAM"; |
bf79451e | 521 | case IPW_FW_ERROR_BAD_CHECKSUM: |
b095c381 | 522 | return "BAD_CHECKSUM"; |
bf79451e | 523 | case IPW_FW_ERROR_NMI_INTERRUPT: |
b095c381 | 524 | return "NMI_INTERRUPT"; |
bf79451e | 525 | case IPW_FW_ERROR_BAD_DATABASE: |
b095c381 | 526 | return "BAD_DATABASE"; |
bf79451e | 527 | case IPW_FW_ERROR_ALLOC_FAIL: |
b095c381 | 528 | return "ALLOC_FAIL"; |
bf79451e | 529 | case IPW_FW_ERROR_DMA_UNDERRUN: |
b095c381 | 530 | return "DMA_UNDERRUN"; |
bf79451e | 531 | case IPW_FW_ERROR_DMA_STATUS: |
b095c381 JK |
532 | return "DMA_STATUS"; |
533 | case IPW_FW_ERROR_DINO_ERROR: | |
534 | return "DINO_ERROR"; | |
535 | case IPW_FW_ERROR_EEPROM_ERROR: | |
536 | return "EEPROM_ERROR"; | |
bf79451e | 537 | case IPW_FW_ERROR_SYSASSERT: |
b095c381 | 538 | return "SYSASSERT"; |
bf79451e | 539 | case IPW_FW_ERROR_FATAL_ERROR: |
b095c381 | 540 | return "FATAL_ERROR"; |
bf79451e | 541 | default: |
b095c381 | 542 | return "UNKNOWN_ERROR"; |
43f66a6c JK |
543 | } |
544 | } | |
545 | ||
b39860c6 JK |
546 | static void ipw_dump_error_log(struct ipw_priv *priv, |
547 | struct ipw_fw_error *error) | |
43f66a6c | 548 | { |
b39860c6 | 549 | u32 i; |
bf79451e | 550 | |
b39860c6 JK |
551 | if (!error) { |
552 | IPW_ERROR("Error allocating and capturing error log. " | |
553 | "Nothing to dump.\n"); | |
554 | return; | |
43f66a6c JK |
555 | } |
556 | ||
b39860c6 JK |
557 | IPW_ERROR("Start IPW Error Log Dump:\n"); |
558 | IPW_ERROR("Status: 0x%08X, Config: %08X\n", | |
559 | error->status, error->config); | |
43f66a6c | 560 | |
b39860c6 | 561 | for (i = 0; i < error->elem_len; i++) |
0edd5b44 | 562 | IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", |
b39860c6 JK |
563 | ipw_error_desc(error->elem[i].desc), |
564 | error->elem[i].time, | |
565 | error->elem[i].blink1, | |
566 | error->elem[i].blink2, | |
567 | error->elem[i].link1, | |
568 | error->elem[i].link2, error->elem[i].data); | |
569 | for (i = 0; i < error->log_len; i++) | |
570 | IPW_ERROR("%i\t0x%08x\t%i\n", | |
571 | error->log[i].time, | |
286568ab | 572 | error->log[i].data, error->log[i].event); |
43f66a6c | 573 | } |
43f66a6c | 574 | #endif |
43f66a6c | 575 | |
c848d0af | 576 | static inline int ipw_is_init(struct ipw_priv *priv) |
43f66a6c | 577 | { |
c848d0af | 578 | return (priv->status & STATUS_INIT) ? 1 : 0; |
43f66a6c JK |
579 | } |
580 | ||
0edd5b44 | 581 | static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len) |
43f66a6c JK |
582 | { |
583 | u32 addr, field_info, field_len, field_count, total_len; | |
584 | ||
585 | IPW_DEBUG_ORD("ordinal = %i\n", ord); | |
586 | ||
587 | if (!priv || !val || !len) { | |
588 | IPW_DEBUG_ORD("Invalid argument\n"); | |
589 | return -EINVAL; | |
590 | } | |
bf79451e | 591 | |
43f66a6c JK |
592 | /* verify device ordinal tables have been initialized */ |
593 | if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) { | |
594 | IPW_DEBUG_ORD("Access ordinals before initialization\n"); | |
595 | return -EINVAL; | |
596 | } | |
597 | ||
598 | switch (IPW_ORD_TABLE_ID_MASK & ord) { | |
599 | case IPW_ORD_TABLE_0_MASK: | |
600 | /* | |
601 | * TABLE 0: Direct access to a table of 32 bit values | |
602 | * | |
bf79451e | 603 | * This is a very simple table with the data directly |
43f66a6c JK |
604 | * read from the table |
605 | */ | |
606 | ||
607 | /* remove the table id from the ordinal */ | |
608 | ord &= IPW_ORD_TABLE_VALUE_MASK; | |
609 | ||
610 | /* boundary check */ | |
611 | if (ord > priv->table0_len) { | |
612 | IPW_DEBUG_ORD("ordinal value (%i) longer then " | |
613 | "max (%i)\n", ord, priv->table0_len); | |
614 | return -EINVAL; | |
615 | } | |
616 | ||
617 | /* verify we have enough room to store the value */ | |
618 | if (*len < sizeof(u32)) { | |
619 | IPW_DEBUG_ORD("ordinal buffer length too small, " | |
aaa4d308 | 620 | "need %zd\n", sizeof(u32)); |
43f66a6c JK |
621 | return -EINVAL; |
622 | } | |
623 | ||
624 | IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n", | |
0edd5b44 | 625 | ord, priv->table0_addr + (ord << 2)); |
43f66a6c JK |
626 | |
627 | *len = sizeof(u32); | |
628 | ord <<= 2; | |
0edd5b44 | 629 | *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord); |
43f66a6c JK |
630 | break; |
631 | ||
632 | case IPW_ORD_TABLE_1_MASK: | |
633 | /* | |
634 | * TABLE 1: Indirect access to a table of 32 bit values | |
bf79451e JG |
635 | * |
636 | * This is a fairly large table of u32 values each | |
43f66a6c JK |
637 | * representing starting addr for the data (which is |
638 | * also a u32) | |
639 | */ | |
640 | ||
641 | /* remove the table id from the ordinal */ | |
642 | ord &= IPW_ORD_TABLE_VALUE_MASK; | |
bf79451e | 643 | |
43f66a6c JK |
644 | /* boundary check */ |
645 | if (ord > priv->table1_len) { | |
646 | IPW_DEBUG_ORD("ordinal value too long\n"); | |
647 | return -EINVAL; | |
648 | } | |
649 | ||
650 | /* verify we have enough room to store the value */ | |
651 | if (*len < sizeof(u32)) { | |
652 | IPW_DEBUG_ORD("ordinal buffer length too small, " | |
aaa4d308 | 653 | "need %zd\n", sizeof(u32)); |
43f66a6c JK |
654 | return -EINVAL; |
655 | } | |
656 | ||
0edd5b44 JG |
657 | *((u32 *) val) = |
658 | ipw_read_reg32(priv, (priv->table1_addr + (ord << 2))); | |
43f66a6c JK |
659 | *len = sizeof(u32); |
660 | break; | |
661 | ||
662 | case IPW_ORD_TABLE_2_MASK: | |
663 | /* | |
664 | * TABLE 2: Indirect access to a table of variable sized values | |
665 | * | |
666 | * This table consist of six values, each containing | |
667 | * - dword containing the starting offset of the data | |
668 | * - dword containing the lengh in the first 16bits | |
669 | * and the count in the second 16bits | |
670 | */ | |
671 | ||
672 | /* remove the table id from the ordinal */ | |
673 | ord &= IPW_ORD_TABLE_VALUE_MASK; | |
674 | ||
675 | /* boundary check */ | |
676 | if (ord > priv->table2_len) { | |
677 | IPW_DEBUG_ORD("ordinal value too long\n"); | |
678 | return -EINVAL; | |
679 | } | |
680 | ||
681 | /* get the address of statistic */ | |
682 | addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3)); | |
bf79451e JG |
683 | |
684 | /* get the second DW of statistics ; | |
43f66a6c | 685 | * two 16-bit words - first is length, second is count */ |
0edd5b44 JG |
686 | field_info = |
687 | ipw_read_reg32(priv, | |
688 | priv->table2_addr + (ord << 3) + | |
689 | sizeof(u32)); | |
bf79451e | 690 | |
43f66a6c | 691 | /* get each entry length */ |
0edd5b44 | 692 | field_len = *((u16 *) & field_info); |
bf79451e | 693 | |
43f66a6c | 694 | /* get number of entries */ |
0edd5b44 | 695 | field_count = *(((u16 *) & field_info) + 1); |
bf79451e | 696 | |
43f66a6c JK |
697 | /* abort if not enought memory */ |
698 | total_len = field_len * field_count; | |
699 | if (total_len > *len) { | |
700 | *len = total_len; | |
701 | return -EINVAL; | |
702 | } | |
bf79451e | 703 | |
43f66a6c JK |
704 | *len = total_len; |
705 | if (!total_len) | |
706 | return 0; | |
707 | ||
708 | IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, " | |
bf79451e | 709 | "field_info = 0x%08x\n", |
43f66a6c JK |
710 | addr, total_len, field_info); |
711 | ipw_read_indirect(priv, addr, val, total_len); | |
712 | break; | |
713 | ||
714 | default: | |
715 | IPW_DEBUG_ORD("Invalid ordinal!\n"); | |
716 | return -EINVAL; | |
717 | ||
718 | } | |
719 | ||
43f66a6c JK |
720 | return 0; |
721 | } | |
722 | ||
723 | static void ipw_init_ordinals(struct ipw_priv *priv) | |
724 | { | |
725 | priv->table0_addr = IPW_ORDINALS_TABLE_LOWER; | |
bf79451e | 726 | priv->table0_len = ipw_read32(priv, priv->table0_addr); |
43f66a6c JK |
727 | |
728 | IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n", | |
729 | priv->table0_addr, priv->table0_len); | |
730 | ||
731 | priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1); | |
732 | priv->table1_len = ipw_read_reg32(priv, priv->table1_addr); | |
733 | ||
734 | IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n", | |
735 | priv->table1_addr, priv->table1_len); | |
736 | ||
737 | priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2); | |
738 | priv->table2_len = ipw_read_reg32(priv, priv->table2_addr); | |
0edd5b44 | 739 | priv->table2_len &= 0x0000ffff; /* use first two bytes */ |
43f66a6c JK |
740 | |
741 | IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n", | |
742 | priv->table2_addr, priv->table2_len); | |
743 | ||
744 | } | |
745 | ||
a73e22b2 | 746 | static u32 ipw_register_toggle(u32 reg) |
a613bffd | 747 | { |
b095c381 JK |
748 | reg &= ~IPW_START_STANDBY; |
749 | if (reg & IPW_GATE_ODMA) | |
750 | reg &= ~IPW_GATE_ODMA; | |
751 | if (reg & IPW_GATE_IDMA) | |
752 | reg &= ~IPW_GATE_IDMA; | |
753 | if (reg & IPW_GATE_ADMA) | |
754 | reg &= ~IPW_GATE_ADMA; | |
a613bffd JK |
755 | return reg; |
756 | } | |
757 | ||
758 | /* | |
759 | * LED behavior: | |
760 | * - On radio ON, turn on any LEDs that require to be on during start | |
761 | * - On initialization, start unassociated blink | |
762 | * - On association, disable unassociated blink | |
763 | * - On disassociation, start unassociated blink | |
764 | * - On radio OFF, turn off any LEDs started during radio on | |
765 | * | |
766 | */ | |
ede6111c ZY |
767 | #define LD_TIME_LINK_ON msecs_to_jiffies(300) |
768 | #define LD_TIME_LINK_OFF msecs_to_jiffies(2700) | |
769 | #define LD_TIME_ACT_ON msecs_to_jiffies(250) | |
a613bffd | 770 | |
a73e22b2 | 771 | static void ipw_led_link_on(struct ipw_priv *priv) |
a613bffd JK |
772 | { |
773 | unsigned long flags; | |
774 | u32 led; | |
775 | ||
776 | /* If configured to not use LEDs, or nic_type is 1, | |
777 | * then we don't toggle a LINK led */ | |
778 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) | |
779 | return; | |
780 | ||
781 | spin_lock_irqsave(&priv->lock, flags); | |
782 | ||
783 | if (!(priv->status & STATUS_RF_KILL_MASK) && | |
784 | !(priv->status & STATUS_LED_LINK_ON)) { | |
785 | IPW_DEBUG_LED("Link LED On\n"); | |
b095c381 | 786 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
787 | led |= priv->led_association_on; |
788 | ||
789 | led = ipw_register_toggle(led); | |
790 | ||
791 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 792 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
793 | |
794 | priv->status |= STATUS_LED_LINK_ON; | |
795 | ||
796 | /* If we aren't associated, schedule turning the LED off */ | |
797 | if (!(priv->status & STATUS_ASSOCIATED)) | |
798 | queue_delayed_work(priv->workqueue, | |
799 | &priv->led_link_off, | |
800 | LD_TIME_LINK_ON); | |
801 | } | |
802 | ||
803 | spin_unlock_irqrestore(&priv->lock, flags); | |
804 | } | |
805 | ||
c848d0af JK |
806 | static void ipw_bg_led_link_on(void *data) |
807 | { | |
808 | struct ipw_priv *priv = data; | |
4644151b | 809 | mutex_lock(&priv->mutex); |
c848d0af | 810 | ipw_led_link_on(data); |
4644151b | 811 | mutex_unlock(&priv->mutex); |
c848d0af JK |
812 | } |
813 | ||
a73e22b2 | 814 | static void ipw_led_link_off(struct ipw_priv *priv) |
a613bffd JK |
815 | { |
816 | unsigned long flags; | |
817 | u32 led; | |
818 | ||
819 | /* If configured not to use LEDs, or nic type is 1, | |
820 | * then we don't goggle the LINK led. */ | |
821 | if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1) | |
822 | return; | |
823 | ||
824 | spin_lock_irqsave(&priv->lock, flags); | |
825 | ||
826 | if (priv->status & STATUS_LED_LINK_ON) { | |
b095c381 | 827 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
828 | led &= priv->led_association_off; |
829 | led = ipw_register_toggle(led); | |
830 | ||
831 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 832 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
833 | |
834 | IPW_DEBUG_LED("Link LED Off\n"); | |
835 | ||
836 | priv->status &= ~STATUS_LED_LINK_ON; | |
837 | ||
838 | /* If we aren't associated and the radio is on, schedule | |
839 | * turning the LED on (blink while unassociated) */ | |
840 | if (!(priv->status & STATUS_RF_KILL_MASK) && | |
841 | !(priv->status & STATUS_ASSOCIATED)) | |
842 | queue_delayed_work(priv->workqueue, &priv->led_link_on, | |
843 | LD_TIME_LINK_OFF); | |
844 | ||
845 | } | |
846 | ||
847 | spin_unlock_irqrestore(&priv->lock, flags); | |
848 | } | |
849 | ||
c848d0af JK |
850 | static void ipw_bg_led_link_off(void *data) |
851 | { | |
852 | struct ipw_priv *priv = data; | |
4644151b | 853 | mutex_lock(&priv->mutex); |
c848d0af | 854 | ipw_led_link_off(data); |
4644151b | 855 | mutex_unlock(&priv->mutex); |
c848d0af JK |
856 | } |
857 | ||
858119e1 | 858 | static void __ipw_led_activity_on(struct ipw_priv *priv) |
a613bffd | 859 | { |
a613bffd JK |
860 | u32 led; |
861 | ||
862 | if (priv->config & CFG_NO_LED) | |
863 | return; | |
864 | ||
b095c381 | 865 | if (priv->status & STATUS_RF_KILL_MASK) |
a613bffd | 866 | return; |
a613bffd JK |
867 | |
868 | if (!(priv->status & STATUS_LED_ACT_ON)) { | |
b095c381 | 869 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
870 | led |= priv->led_activity_on; |
871 | ||
872 | led = ipw_register_toggle(led); | |
873 | ||
874 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 875 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
876 | |
877 | IPW_DEBUG_LED("Activity LED On\n"); | |
878 | ||
879 | priv->status |= STATUS_LED_ACT_ON; | |
880 | ||
c848d0af | 881 | cancel_delayed_work(&priv->led_act_off); |
a613bffd JK |
882 | queue_delayed_work(priv->workqueue, &priv->led_act_off, |
883 | LD_TIME_ACT_ON); | |
884 | } else { | |
885 | /* Reschedule LED off for full time period */ | |
886 | cancel_delayed_work(&priv->led_act_off); | |
887 | queue_delayed_work(priv->workqueue, &priv->led_act_off, | |
888 | LD_TIME_ACT_ON); | |
889 | } | |
b095c381 | 890 | } |
a613bffd | 891 | |
a73e22b2 | 892 | #if 0 |
b095c381 JK |
893 | void ipw_led_activity_on(struct ipw_priv *priv) |
894 | { | |
895 | unsigned long flags; | |
896 | spin_lock_irqsave(&priv->lock, flags); | |
897 | __ipw_led_activity_on(priv); | |
a613bffd JK |
898 | spin_unlock_irqrestore(&priv->lock, flags); |
899 | } | |
a73e22b2 | 900 | #endif /* 0 */ |
a613bffd | 901 | |
a73e22b2 | 902 | static void ipw_led_activity_off(struct ipw_priv *priv) |
a613bffd JK |
903 | { |
904 | unsigned long flags; | |
905 | u32 led; | |
906 | ||
907 | if (priv->config & CFG_NO_LED) | |
908 | return; | |
909 | ||
910 | spin_lock_irqsave(&priv->lock, flags); | |
911 | ||
912 | if (priv->status & STATUS_LED_ACT_ON) { | |
b095c381 | 913 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
914 | led &= priv->led_activity_off; |
915 | ||
916 | led = ipw_register_toggle(led); | |
917 | ||
918 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 919 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
920 | |
921 | IPW_DEBUG_LED("Activity LED Off\n"); | |
922 | ||
923 | priv->status &= ~STATUS_LED_ACT_ON; | |
924 | } | |
925 | ||
926 | spin_unlock_irqrestore(&priv->lock, flags); | |
927 | } | |
928 | ||
c848d0af JK |
929 | static void ipw_bg_led_activity_off(void *data) |
930 | { | |
931 | struct ipw_priv *priv = data; | |
4644151b | 932 | mutex_lock(&priv->mutex); |
c848d0af | 933 | ipw_led_activity_off(data); |
4644151b | 934 | mutex_unlock(&priv->mutex); |
c848d0af JK |
935 | } |
936 | ||
a73e22b2 | 937 | static void ipw_led_band_on(struct ipw_priv *priv) |
a613bffd JK |
938 | { |
939 | unsigned long flags; | |
940 | u32 led; | |
941 | ||
942 | /* Only nic type 1 supports mode LEDs */ | |
c848d0af JK |
943 | if (priv->config & CFG_NO_LED || |
944 | priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network) | |
a613bffd JK |
945 | return; |
946 | ||
947 | spin_lock_irqsave(&priv->lock, flags); | |
948 | ||
b095c381 | 949 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
950 | if (priv->assoc_network->mode == IEEE_A) { |
951 | led |= priv->led_ofdm_on; | |
952 | led &= priv->led_association_off; | |
953 | IPW_DEBUG_LED("Mode LED On: 802.11a\n"); | |
954 | } else if (priv->assoc_network->mode == IEEE_G) { | |
955 | led |= priv->led_ofdm_on; | |
956 | led |= priv->led_association_on; | |
957 | IPW_DEBUG_LED("Mode LED On: 802.11g\n"); | |
958 | } else { | |
959 | led &= priv->led_ofdm_off; | |
960 | led |= priv->led_association_on; | |
961 | IPW_DEBUG_LED("Mode LED On: 802.11b\n"); | |
962 | } | |
963 | ||
964 | led = ipw_register_toggle(led); | |
965 | ||
966 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 967 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
968 | |
969 | spin_unlock_irqrestore(&priv->lock, flags); | |
970 | } | |
971 | ||
a73e22b2 | 972 | static void ipw_led_band_off(struct ipw_priv *priv) |
a613bffd JK |
973 | { |
974 | unsigned long flags; | |
975 | u32 led; | |
976 | ||
977 | /* Only nic type 1 supports mode LEDs */ | |
978 | if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1) | |
979 | return; | |
980 | ||
981 | spin_lock_irqsave(&priv->lock, flags); | |
982 | ||
b095c381 | 983 | led = ipw_read_reg32(priv, IPW_EVENT_REG); |
a613bffd JK |
984 | led &= priv->led_ofdm_off; |
985 | led &= priv->led_association_off; | |
986 | ||
987 | led = ipw_register_toggle(led); | |
988 | ||
989 | IPW_DEBUG_LED("Reg: 0x%08X\n", led); | |
b095c381 | 990 | ipw_write_reg32(priv, IPW_EVENT_REG, led); |
a613bffd JK |
991 | |
992 | spin_unlock_irqrestore(&priv->lock, flags); | |
993 | } | |
994 | ||
a73e22b2 | 995 | static void ipw_led_radio_on(struct ipw_priv *priv) |
a613bffd JK |
996 | { |
997 | ipw_led_link_on(priv); | |
998 | } | |
999 | ||
a73e22b2 | 1000 | static void ipw_led_radio_off(struct ipw_priv *priv) |
a613bffd JK |
1001 | { |
1002 | ipw_led_activity_off(priv); | |
1003 | ipw_led_link_off(priv); | |
1004 | } | |
1005 | ||
a73e22b2 | 1006 | static void ipw_led_link_up(struct ipw_priv *priv) |
a613bffd JK |
1007 | { |
1008 | /* Set the Link Led on for all nic types */ | |
1009 | ipw_led_link_on(priv); | |
1010 | } | |
1011 | ||
a73e22b2 | 1012 | static void ipw_led_link_down(struct ipw_priv *priv) |
a613bffd JK |
1013 | { |
1014 | ipw_led_activity_off(priv); | |
1015 | ipw_led_link_off(priv); | |
1016 | ||
1017 | if (priv->status & STATUS_RF_KILL_MASK) | |
1018 | ipw_led_radio_off(priv); | |
1019 | } | |
1020 | ||
a73e22b2 | 1021 | static void ipw_led_init(struct ipw_priv *priv) |
a613bffd JK |
1022 | { |
1023 | priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE]; | |
1024 | ||
1025 | /* Set the default PINs for the link and activity leds */ | |
b095c381 JK |
1026 | priv->led_activity_on = IPW_ACTIVITY_LED; |
1027 | priv->led_activity_off = ~(IPW_ACTIVITY_LED); | |
a613bffd | 1028 | |
b095c381 JK |
1029 | priv->led_association_on = IPW_ASSOCIATED_LED; |
1030 | priv->led_association_off = ~(IPW_ASSOCIATED_LED); | |
a613bffd JK |
1031 | |
1032 | /* Set the default PINs for the OFDM leds */ | |
b095c381 JK |
1033 | priv->led_ofdm_on = IPW_OFDM_LED; |
1034 | priv->led_ofdm_off = ~(IPW_OFDM_LED); | |
a613bffd JK |
1035 | |
1036 | switch (priv->nic_type) { | |
1037 | case EEPROM_NIC_TYPE_1: | |
1038 | /* In this NIC type, the LEDs are reversed.... */ | |
b095c381 JK |
1039 | priv->led_activity_on = IPW_ASSOCIATED_LED; |
1040 | priv->led_activity_off = ~(IPW_ASSOCIATED_LED); | |
1041 | priv->led_association_on = IPW_ACTIVITY_LED; | |
1042 | priv->led_association_off = ~(IPW_ACTIVITY_LED); | |
a613bffd JK |
1043 | |
1044 | if (!(priv->config & CFG_NO_LED)) | |
1045 | ipw_led_band_on(priv); | |
1046 | ||
1047 | /* And we don't blink link LEDs for this nic, so | |
1048 | * just return here */ | |
1049 | return; | |
1050 | ||
1051 | case EEPROM_NIC_TYPE_3: | |
1052 | case EEPROM_NIC_TYPE_2: | |
1053 | case EEPROM_NIC_TYPE_4: | |
1054 | case EEPROM_NIC_TYPE_0: | |
1055 | break; | |
1056 | ||
1057 | default: | |
1058 | IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n", | |
1059 | priv->nic_type); | |
1060 | priv->nic_type = EEPROM_NIC_TYPE_0; | |
1061 | break; | |
1062 | } | |
1063 | ||
1064 | if (!(priv->config & CFG_NO_LED)) { | |
1065 | if (priv->status & STATUS_ASSOCIATED) | |
1066 | ipw_led_link_on(priv); | |
1067 | else | |
1068 | ipw_led_link_off(priv); | |
1069 | } | |
1070 | } | |
1071 | ||
a73e22b2 | 1072 | static void ipw_led_shutdown(struct ipw_priv *priv) |
a613bffd | 1073 | { |
a613bffd JK |
1074 | ipw_led_activity_off(priv); |
1075 | ipw_led_link_off(priv); | |
1076 | ipw_led_band_off(priv); | |
afbf30a2 JK |
1077 | cancel_delayed_work(&priv->led_link_on); |
1078 | cancel_delayed_work(&priv->led_link_off); | |
1079 | cancel_delayed_work(&priv->led_act_off); | |
a613bffd JK |
1080 | } |
1081 | ||
43f66a6c JK |
1082 | /* |
1083 | * The following adds a new attribute to the sysfs representation | |
1084 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) | |
1085 | * used for controling the debug level. | |
bf79451e | 1086 | * |
43f66a6c JK |
1087 | * See the level definitions in ipw for details. |
1088 | */ | |
1089 | static ssize_t show_debug_level(struct device_driver *d, char *buf) | |
1090 | { | |
1091 | return sprintf(buf, "0x%08X\n", ipw_debug_level); | |
1092 | } | |
a613bffd JK |
1093 | |
1094 | static ssize_t store_debug_level(struct device_driver *d, const char *buf, | |
1095 | size_t count) | |
43f66a6c JK |
1096 | { |
1097 | char *p = (char *)buf; | |
1098 | u32 val; | |
1099 | ||
1100 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | |
1101 | p++; | |
1102 | if (p[0] == 'x' || p[0] == 'X') | |
1103 | p++; | |
1104 | val = simple_strtoul(p, &p, 16); | |
1105 | } else | |
1106 | val = simple_strtoul(p, &p, 10); | |
bf79451e JG |
1107 | if (p == buf) |
1108 | printk(KERN_INFO DRV_NAME | |
43f66a6c JK |
1109 | ": %s is not in hex or decimal form.\n", buf); |
1110 | else | |
1111 | ipw_debug_level = val; | |
1112 | ||
1113 | return strnlen(buf, count); | |
1114 | } | |
1115 | ||
bf79451e | 1116 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
43f66a6c JK |
1117 | show_debug_level, store_debug_level); |
1118 | ||
b39860c6 | 1119 | static inline u32 ipw_get_event_log_len(struct ipw_priv *priv) |
43f66a6c | 1120 | { |
c8fe6679 | 1121 | /* length = 1st dword in log */ |
b39860c6 | 1122 | return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG)); |
43f66a6c | 1123 | } |
0edd5b44 | 1124 | |
b39860c6 JK |
1125 | static void ipw_capture_event_log(struct ipw_priv *priv, |
1126 | u32 log_len, struct ipw_event *log) | |
43f66a6c | 1127 | { |
b39860c6 | 1128 | u32 base; |
0edd5b44 | 1129 | |
b39860c6 JK |
1130 | if (log_len) { |
1131 | base = ipw_read32(priv, IPW_EVENT_LOG); | |
1132 | ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32), | |
1133 | (u8 *) log, sizeof(*log) * log_len); | |
1134 | } | |
1135 | } | |
43f66a6c | 1136 | |
b39860c6 | 1137 | static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv) |
43f66a6c | 1138 | { |
b39860c6 JK |
1139 | struct ipw_fw_error *error; |
1140 | u32 log_len = ipw_get_event_log_len(priv); | |
1141 | u32 base = ipw_read32(priv, IPW_ERROR_LOG); | |
1142 | u32 elem_len = ipw_read_reg32(priv, base); | |
43f66a6c | 1143 | |
b39860c6 JK |
1144 | error = kmalloc(sizeof(*error) + |
1145 | sizeof(*error->elem) * elem_len + | |
1146 | sizeof(*error->log) * log_len, GFP_ATOMIC); | |
1147 | if (!error) { | |
1148 | IPW_ERROR("Memory allocation for firmware error log " | |
1149 | "failed.\n"); | |
1150 | return NULL; | |
43f66a6c | 1151 | } |
f6c5cb7c | 1152 | error->jiffies = jiffies; |
b39860c6 JK |
1153 | error->status = priv->status; |
1154 | error->config = priv->config; | |
1155 | error->elem_len = elem_len; | |
1156 | error->log_len = log_len; | |
1157 | error->elem = (struct ipw_error_elem *)error->payload; | |
3b26b110 | 1158 | error->log = (struct ipw_event *)(error->elem + elem_len); |
b39860c6 JK |
1159 | |
1160 | ipw_capture_event_log(priv, log_len, error->log); | |
bf79451e | 1161 | |
b39860c6 JK |
1162 | if (elem_len) |
1163 | ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem, | |
1164 | sizeof(*error->elem) * elem_len); | |
1165 | ||
1166 | return error; | |
43f66a6c | 1167 | } |
0edd5b44 | 1168 | |
b39860c6 JK |
1169 | static void ipw_free_error_log(struct ipw_fw_error *error) |
1170 | { | |
1171 | if (error) | |
1172 | kfree(error); | |
1173 | } | |
43f66a6c | 1174 | |
b39860c6 JK |
1175 | static ssize_t show_event_log(struct device *d, |
1176 | struct device_attribute *attr, char *buf) | |
43f66a6c | 1177 | { |
b39860c6 JK |
1178 | struct ipw_priv *priv = dev_get_drvdata(d); |
1179 | u32 log_len = ipw_get_event_log_len(priv); | |
1180 | struct ipw_event log[log_len]; | |
1181 | u32 len = 0, i; | |
43f66a6c | 1182 | |
b39860c6 | 1183 | ipw_capture_event_log(priv, log_len, log); |
43f66a6c | 1184 | |
b39860c6 JK |
1185 | len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len); |
1186 | for (i = 0; i < log_len; i++) | |
1187 | len += snprintf(buf + len, PAGE_SIZE - len, | |
1188 | "\n%08X%08X%08X", | |
1189 | log[i].time, log[i].event, log[i].data); | |
1190 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
1191 | return len; | |
43f66a6c | 1192 | } |
0edd5b44 | 1193 | |
b39860c6 | 1194 | static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL); |
43f66a6c | 1195 | |
b39860c6 JK |
1196 | static ssize_t show_error(struct device *d, |
1197 | struct device_attribute *attr, char *buf) | |
43f66a6c | 1198 | { |
b39860c6 JK |
1199 | struct ipw_priv *priv = dev_get_drvdata(d); |
1200 | u32 len = 0, i; | |
1201 | if (!priv->error) | |
1202 | return 0; | |
1203 | len += snprintf(buf + len, PAGE_SIZE - len, | |
f6c5cb7c JK |
1204 | "%08lX%08X%08X%08X", |
1205 | priv->error->jiffies, | |
b39860c6 JK |
1206 | priv->error->status, |
1207 | priv->error->config, priv->error->elem_len); | |
1208 | for (i = 0; i < priv->error->elem_len; i++) | |
1209 | len += snprintf(buf + len, PAGE_SIZE - len, | |
1210 | "\n%08X%08X%08X%08X%08X%08X%08X", | |
1211 | priv->error->elem[i].time, | |
1212 | priv->error->elem[i].desc, | |
1213 | priv->error->elem[i].blink1, | |
1214 | priv->error->elem[i].blink2, | |
1215 | priv->error->elem[i].link1, | |
1216 | priv->error->elem[i].link2, | |
1217 | priv->error->elem[i].data); | |
1218 | ||
1219 | len += snprintf(buf + len, PAGE_SIZE - len, | |
1220 | "\n%08X", priv->error->log_len); | |
1221 | for (i = 0; i < priv->error->log_len; i++) | |
1222 | len += snprintf(buf + len, PAGE_SIZE - len, | |
1223 | "\n%08X%08X%08X", | |
1224 | priv->error->log[i].time, | |
1225 | priv->error->log[i].event, | |
1226 | priv->error->log[i].data); | |
1227 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
1228 | return len; | |
1229 | } | |
1230 | ||
1231 | static ssize_t clear_error(struct device *d, | |
1232 | struct device_attribute *attr, | |
1233 | const char *buf, size_t count) | |
1234 | { | |
1235 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1236 | if (priv->error) { | |
1237 | ipw_free_error_log(priv->error); | |
1238 | priv->error = NULL; | |
1239 | } | |
1240 | return count; | |
1241 | } | |
43f66a6c | 1242 | |
b39860c6 | 1243 | static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error); |
43f66a6c | 1244 | |
f6c5cb7c JK |
1245 | static ssize_t show_cmd_log(struct device *d, |
1246 | struct device_attribute *attr, char *buf) | |
1247 | { | |
1248 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1249 | u32 len = 0, i; | |
1250 | if (!priv->cmdlog) | |
1251 | return 0; | |
1252 | for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len; | |
1253 | (i != priv->cmdlog_pos) && (PAGE_SIZE - len); | |
1254 | i = (i + 1) % priv->cmdlog_len) { | |
1255 | len += | |
1256 | snprintf(buf + len, PAGE_SIZE - len, | |
1257 | "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies, | |
1258 | priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd, | |
1259 | priv->cmdlog[i].cmd.len); | |
1260 | len += | |
1261 | snprintk_buf(buf + len, PAGE_SIZE - len, | |
1262 | (u8 *) priv->cmdlog[i].cmd.param, | |
1263 | priv->cmdlog[i].cmd.len); | |
1264 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
1265 | } | |
1266 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
1267 | return len; | |
43f66a6c | 1268 | } |
0edd5b44 | 1269 | |
f6c5cb7c | 1270 | static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL); |
43f66a6c | 1271 | |
a613bffd JK |
1272 | static ssize_t show_scan_age(struct device *d, struct device_attribute *attr, |
1273 | char *buf) | |
43f66a6c | 1274 | { |
a613bffd JK |
1275 | struct ipw_priv *priv = dev_get_drvdata(d); |
1276 | return sprintf(buf, "%d\n", priv->ieee->scan_age); | |
1277 | } | |
1278 | ||
1279 | static ssize_t store_scan_age(struct device *d, struct device_attribute *attr, | |
1280 | const char *buf, size_t count) | |
1281 | { | |
1282 | struct ipw_priv *priv = dev_get_drvdata(d); | |
0f52bf90 | 1283 | #ifdef CONFIG_IPW2200_DEBUG |
a613bffd | 1284 | struct net_device *dev = priv->net_dev; |
c848d0af | 1285 | #endif |
a613bffd JK |
1286 | char buffer[] = "00000000"; |
1287 | unsigned long len = | |
1288 | (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1; | |
1289 | unsigned long val; | |
1290 | char *p = buffer; | |
1291 | ||
1292 | IPW_DEBUG_INFO("enter\n"); | |
1293 | ||
1294 | strncpy(buffer, buf, len); | |
1295 | buffer[len] = 0; | |
1296 | ||
1297 | if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') { | |
1298 | p++; | |
1299 | if (p[0] == 'x' || p[0] == 'X') | |
1300 | p++; | |
1301 | val = simple_strtoul(p, &p, 16); | |
1302 | } else | |
1303 | val = simple_strtoul(p, &p, 10); | |
1304 | if (p == buffer) { | |
1305 | IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name); | |
1306 | } else { | |
1307 | priv->ieee->scan_age = val; | |
1308 | IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age); | |
1309 | } | |
1310 | ||
1311 | IPW_DEBUG_INFO("exit\n"); | |
1312 | return len; | |
1313 | } | |
1314 | ||
1315 | static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age); | |
1316 | ||
1317 | static ssize_t show_led(struct device *d, struct device_attribute *attr, | |
1318 | char *buf) | |
1319 | { | |
1320 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1321 | return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1); | |
1322 | } | |
1323 | ||
1324 | static ssize_t store_led(struct device *d, struct device_attribute *attr, | |
1325 | const char *buf, size_t count) | |
1326 | { | |
1327 | struct ipw_priv *priv = dev_get_drvdata(d); | |
1328 | ||
1329 | IPW_DEBUG_INFO("enter\n"); | |
1330 | ||
1331 | if (count == 0) | |
1332 | return 0; | |
1333 | ||
1334 | if (*buf == 0) { | |
1335 | IPW_DEBUG_LED("Disabling LED control.\n"); | |
1336 | priv->config |= CFG_NO_LED; | |
1337 | ipw_led_shutdown(priv); | |
1338 | } else { | |
1339 | IPW_DEBUG_LED("Enabling LED control.\n"); | |
1340 | priv->config &= ~CFG_NO_LED; | |
1341 | ipw_led_init(priv); | |
1342 | } | |
1343 | ||
1344 | IPW_DEBUG_INFO("exit\n"); | |
1345 | return count; | |
1346 | } | |
1347 | ||
1348 | static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led); | |
1349 | ||
ad3fee56 | 1350 | static ssize_t show_status(struct device *d, |
0edd5b44 | 1351 | struct device_attribute *attr, char *buf) |
43f66a6c | 1352 | { |
ad3fee56 | 1353 | struct ipw_priv *p = d->driver_data; |
43f66a6c JK |
1354 | return sprintf(buf, "0x%08x\n", (int)p->status); |
1355 | } | |
0edd5b44 | 1356 | |
43f66a6c JK |
1357 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
1358 | ||
ad3fee56 AM |
1359 | static ssize_t show_cfg(struct device *d, struct device_attribute *attr, |
1360 | char *buf) | |
43f66a6c | 1361 | { |
ad3fee56 | 1362 | struct ipw_priv *p = d->driver_data; |
43f66a6c JK |
1363 | return sprintf(buf, "0x%08x\n", (int)p->config); |
1364 | } | |
0edd5b44 | 1365 | |
43f66a6c JK |
1366 | static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); |
1367 | ||
ad3fee56 | 1368 | static ssize_t show_nic_type(struct device *d, |
0edd5b44 | 1369 | struct device_attribute *attr, char *buf) |
43f66a6c | 1370 | { |
a613bffd JK |
1371 | struct ipw_priv *priv = d->driver_data; |
1372 | return sprintf(buf, "TYPE: %d\n", priv->nic_type); | |
43f66a6c | 1373 | } |
0edd5b44 | 1374 | |
43f66a6c JK |
1375 | static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); |
1376 | ||
ad3fee56 | 1377 | static ssize_t show_ucode_version(struct device *d, |
0edd5b44 | 1378 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1379 | { |
1380 | u32 len = sizeof(u32), tmp = 0; | |
ad3fee56 | 1381 | struct ipw_priv *p = d->driver_data; |
43f66a6c | 1382 | |
0edd5b44 | 1383 | if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len)) |
43f66a6c JK |
1384 | return 0; |
1385 | ||
1386 | return sprintf(buf, "0x%08x\n", tmp); | |
1387 | } | |
0edd5b44 JG |
1388 | |
1389 | static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL); | |
43f66a6c | 1390 | |
ad3fee56 AM |
1391 | static ssize_t show_rtc(struct device *d, struct device_attribute *attr, |
1392 | char *buf) | |
43f66a6c JK |
1393 | { |
1394 | u32 len = sizeof(u32), tmp = 0; | |
ad3fee56 | 1395 | struct ipw_priv *p = d->driver_data; |
43f66a6c | 1396 | |
0edd5b44 | 1397 | if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len)) |
43f66a6c JK |
1398 | return 0; |
1399 | ||
1400 | return sprintf(buf, "0x%08x\n", tmp); | |
1401 | } | |
0edd5b44 JG |
1402 | |
1403 | static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL); | |
43f66a6c JK |
1404 | |
1405 | /* | |
1406 | * Add a device attribute to view/control the delay between eeprom | |
1407 | * operations. | |
1408 | */ | |
ad3fee56 | 1409 | static ssize_t show_eeprom_delay(struct device *d, |
0edd5b44 | 1410 | struct device_attribute *attr, char *buf) |
43f66a6c | 1411 | { |
0edd5b44 | 1412 | int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay; |
43f66a6c JK |
1413 | return sprintf(buf, "%i\n", n); |
1414 | } | |
ad3fee56 | 1415 | static ssize_t store_eeprom_delay(struct device *d, |
0edd5b44 JG |
1416 | struct device_attribute *attr, |
1417 | const char *buf, size_t count) | |
43f66a6c | 1418 | { |
ad3fee56 | 1419 | struct ipw_priv *p = d->driver_data; |
43f66a6c JK |
1420 | sscanf(buf, "%i", &p->eeprom_delay); |
1421 | return strnlen(buf, count); | |
1422 | } | |
0edd5b44 JG |
1423 | |
1424 | static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO, | |
1425 | show_eeprom_delay, store_eeprom_delay); | |
43f66a6c | 1426 | |
ad3fee56 | 1427 | static ssize_t show_command_event_reg(struct device *d, |
0edd5b44 | 1428 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1429 | { |
1430 | u32 reg = 0; | |
ad3fee56 | 1431 | struct ipw_priv *p = d->driver_data; |
43f66a6c | 1432 | |
b095c381 | 1433 | reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT); |
43f66a6c JK |
1434 | return sprintf(buf, "0x%08x\n", reg); |
1435 | } | |
ad3fee56 | 1436 | static ssize_t store_command_event_reg(struct device *d, |
0edd5b44 JG |
1437 | struct device_attribute *attr, |
1438 | const char *buf, size_t count) | |
43f66a6c JK |
1439 | { |
1440 | u32 reg; | |
ad3fee56 | 1441 | struct ipw_priv *p = d->driver_data; |
43f66a6c JK |
1442 | |
1443 | sscanf(buf, "%x", ®); | |
b095c381 | 1444 | ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg); |
43f66a6c JK |
1445 | return strnlen(buf, count); |
1446 | } | |
0edd5b44 JG |
1447 | |
1448 | static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO, | |
1449 | show_command_event_reg, store_command_event_reg); | |
43f66a6c | 1450 | |
ad3fee56 | 1451 | static ssize_t show_mem_gpio_reg(struct device *d, |
0edd5b44 | 1452 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1453 | { |
1454 | u32 reg = 0; | |
ad3fee56 | 1455 | struct ipw_priv *p = d->driver_data; |
43f66a6c JK |
1456 | |
1457 | reg = ipw_read_reg32(p, 0x301100); | |
1458 | return sprintf(buf, "0x%08x\n", reg); | |
1459 | } | |
ad3fee56 | 1460 | static ssize_t store_mem_gpio_reg(struct device *d, |
0edd5b44 JG |
1461 | struct device_attribute *attr, |
1462 | const char *buf, size_t count) | |
43f66a6c JK |
1463 | { |
1464 | u32 reg; | |
ad3fee56 | 1465 | struct ipw_priv *p = d->driver_data; |
43f66a6c JK |
1466 | |
1467 | sscanf(buf, "%x", ®); | |
1468 | ipw_write_reg32(p, 0x301100, reg); | |
1469 | return strnlen(buf, count); | |
1470 | } | |
0edd5b44 JG |
1471 | |
1472 | static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO, | |
1473 | show_mem_gpio_reg, store_mem_gpio_reg); | |
43f66a6c | 1474 | |
ad3fee56 | 1475 | static ssize_t show_indirect_dword(struct device *d, |
0edd5b44 | 1476 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1477 | { |
1478 | u32 reg = 0; | |
ad3fee56 | 1479 | struct ipw_priv *priv = d->driver_data; |
afbf30a2 | 1480 | |
bf79451e | 1481 | if (priv->status & STATUS_INDIRECT_DWORD) |
43f66a6c | 1482 | reg = ipw_read_reg32(priv, priv->indirect_dword); |
bf79451e | 1483 | else |
43f66a6c | 1484 | reg = 0; |
bf79451e | 1485 | |
43f66a6c JK |
1486 | return sprintf(buf, "0x%08x\n", reg); |
1487 | } | |
ad3fee56 | 1488 | static ssize_t store_indirect_dword(struct device *d, |
0edd5b44 JG |
1489 | struct device_attribute *attr, |
1490 | const char *buf, size_t count) | |
43f66a6c | 1491 | { |
ad3fee56 | 1492 | struct ipw_priv *priv = d->driver_data; |
43f66a6c JK |
1493 | |
1494 | sscanf(buf, "%x", &priv->indirect_dword); | |
1495 | priv->status |= STATUS_INDIRECT_DWORD; | |
1496 | return strnlen(buf, count); | |
1497 | } | |
0edd5b44 JG |
1498 | |
1499 | static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO, | |
1500 | show_indirect_dword, store_indirect_dword); | |
43f66a6c | 1501 | |
ad3fee56 | 1502 | static ssize_t show_indirect_byte(struct device *d, |
0edd5b44 | 1503 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1504 | { |
1505 | u8 reg = 0; | |
ad3fee56 | 1506 | struct ipw_priv *priv = d->driver_data; |
afbf30a2 | 1507 | |
bf79451e | 1508 | if (priv->status & STATUS_INDIRECT_BYTE) |
43f66a6c | 1509 | reg = ipw_read_reg8(priv, priv->indirect_byte); |
bf79451e | 1510 | else |
43f66a6c JK |
1511 | reg = 0; |
1512 | ||
1513 | return sprintf(buf, "0x%02x\n", reg); | |
1514 | } | |
ad3fee56 | 1515 | static ssize_t store_indirect_byte(struct device *d, |
0edd5b44 JG |
1516 | struct device_attribute *attr, |
1517 | const char *buf, size_t count) | |
43f66a6c | 1518 | { |
ad3fee56 | 1519 | struct ipw_priv *priv = d->driver_data; |
43f66a6c JK |
1520 | |
1521 | sscanf(buf, "%x", &priv->indirect_byte); | |
1522 | priv->status |= STATUS_INDIRECT_BYTE; | |
1523 | return strnlen(buf, count); | |
1524 | } | |
0edd5b44 JG |
1525 | |
1526 | static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO, | |
43f66a6c JK |
1527 | show_indirect_byte, store_indirect_byte); |
1528 | ||
ad3fee56 | 1529 | static ssize_t show_direct_dword(struct device *d, |
0edd5b44 | 1530 | struct device_attribute *attr, char *buf) |
43f66a6c JK |
1531 | { |
1532 | u32 reg = 0; | |
ad3fee56 | 1533 | struct ipw_priv *priv = d->driver_data; |
43f66a6c | 1534 | |
bf79451e | 1535 | if (priv->status & STATUS_DIRECT_DWORD) |
43f66a6c | 1536 | reg = ipw_read32(priv, priv->direct_dword); |
bf79451e | 1537 | else |
43f66a6c JK |
1538 | reg = 0; |
1539 | ||
1540 | return sprintf(buf, "0x%08x\n", reg); | |
1541 | } | |
ad3fee56 | 1542 | static ssize_t store_direct_dword(struct device *d, |
0edd5b44 JG |
1543 | struct device_attribute *attr, |
1544 | const char *buf, size_t count) | |
43f66a6c | 1545 | { |
ad3fee56 | 1546 | struct ipw_priv *priv = d->driver_data; |
43f66a6c JK |
1547 | |
1548 | sscanf(buf, "%x", &priv->direct_dword); | |
1549 | priv->status |= STATUS_DIRECT_DWORD; | |
1550 | return strnlen(buf, count); | |
1551 | } | |
43f66a6c | 1552 | |
0edd5b44 JG |
1553 | static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO, |
1554 | show_direct_dword, store_direct_dword); | |
43f66a6c | 1555 | |
858119e1 | 1556 | static int rf_kill_active(struct ipw_priv *priv) |
43f66a6c JK |
1557 | { |
1558 | if (0 == (ipw_read32(priv, 0x30) & 0x10000)) | |
1559 | priv->status |= STATUS_RF_KILL_HW; | |
1560 | else | |
1561 | priv->status &= ~STATUS_RF_KILL_HW; | |
1562 | ||
1563 | return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0; | |
1564 | } | |
1565 | ||
ad3fee56 | 1566 | static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, |
0edd5b44 | 1567 | char *buf) |
43f66a6c JK |
1568 | { |
1569 | /* 0 - RF kill not enabled | |
bf79451e | 1570 | 1 - SW based RF kill active (sysfs) |
43f66a6c JK |
1571 | 2 - HW based RF kill active |
1572 | 3 - Both HW and SW baed RF kill active */ | |
ad3fee56 | 1573 | struct ipw_priv *priv = d->driver_data; |
43f66a6c | 1574 | int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) | |
0edd5b44 | 1575 | (rf_kill_active(priv) ? 0x2 : 0x0); |
43f66a6c JK |
1576 | return sprintf(buf, "%i\n", val); |
1577 | } | |
1578 | ||
1579 | static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) | |
1580 | { | |
bf79451e | 1581 | if ((disable_radio ? 1 : 0) == |
ea2b26e0 | 1582 | ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0)) |
0edd5b44 | 1583 | return 0; |
43f66a6c JK |
1584 | |
1585 | IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", | |
1586 | disable_radio ? "OFF" : "ON"); | |
1587 | ||
1588 | if (disable_radio) { | |
1589 | priv->status |= STATUS_RF_KILL_SW; | |
1590 | ||
a613bffd | 1591 | if (priv->workqueue) |
43f66a6c | 1592 | cancel_delayed_work(&priv->request_scan); |
43f66a6c JK |
1593 | queue_work(priv->workqueue, &priv->down); |
1594 | } else { | |
1595 | priv->status &= ~STATUS_RF_KILL_SW; | |
1596 | if (rf_kill_active(priv)) { | |
1597 | IPW_DEBUG_RF_KILL("Can not turn radio back on - " | |
1598 | "disabled by HW switch\n"); | |
1599 | /* Make sure the RF_KILL check timer is running */ | |
1600 | cancel_delayed_work(&priv->rf_kill); | |
bf79451e | 1601 | queue_delayed_work(priv->workqueue, &priv->rf_kill, |
43f66a6c | 1602 | 2 * HZ); |
bf79451e | 1603 | } else |
43f66a6c JK |
1604 | queue_work(priv->workqueue, &priv->up); |
1605 | } | |
1606 | ||
1607 | return 1; | |
1608 | } | |
1609 | ||
0edd5b44 JG |
1610 | static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, |
1611 | const char *buf, size_t count) | |
43f66a6c | 1612 | { |
ad3fee56 | 1613 | struct ipw_priv *priv = d->driver_data; |
bf79451e | 1614 | |
43f66a6c JK |
1615 | ipw_radio_kill_sw(priv, buf[0] == '1'); |
1616 | ||
1617 | return count; | |
1618 | } | |
0edd5b44 JG |
1619 | |
1620 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); | |
43f66a6c | 1621 | |
b095c381 JK |
1622 | static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr, |
1623 | char *buf) | |
1624 | { | |
1625 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; | |
1626 | int pos = 0, len = 0; | |
1627 | if (priv->config & CFG_SPEED_SCAN) { | |
1628 | while (priv->speed_scan[pos] != 0) | |
1629 | len += sprintf(&buf[len], "%d ", | |
1630 | priv->speed_scan[pos++]); | |
1631 | return len + sprintf(&buf[len], "\n"); | |
1632 | } | |
1633 | ||
1634 | return sprintf(buf, "0\n"); | |
1635 | } | |
1636 | ||
1637 | static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr, | |
1638 | const char *buf, size_t count) | |
1639 | { | |
1640 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; | |
1641 | int channel, pos = 0; | |
1642 | const char *p = buf; | |
1643 | ||
1644 | /* list of space separated channels to scan, optionally ending with 0 */ | |
1645 | while ((channel = simple_strtol(p, NULL, 0))) { | |
1646 | if (pos == MAX_SPEED_SCAN - 1) { | |
1647 | priv->speed_scan[pos] = 0; | |
1648 | break; | |
1649 | } | |
1650 | ||
1867b117 | 1651 | if (ieee80211_is_valid_channel(priv->ieee, channel)) |
b095c381 JK |
1652 | priv->speed_scan[pos++] = channel; |
1653 | else | |
1654 | IPW_WARNING("Skipping invalid channel request: %d\n", | |
1655 | channel); | |
1656 | p = strchr(p, ' '); | |
1657 | if (!p) | |
1658 | break; | |
1659 | while (*p == ' ' || *p == '\t') | |
1660 | p++; | |
1661 | } | |
1662 | ||
1663 | if (pos == 0) | |
1664 | priv->config &= ~CFG_SPEED_SCAN; | |
1665 | else { | |
1666 | priv->speed_scan_pos = 0; | |
1667 | priv->config |= CFG_SPEED_SCAN; | |
1668 | } | |
1669 | ||
1670 | return count; | |
1671 | } | |
1672 | ||
1673 | static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan, | |
1674 | store_speed_scan); | |
1675 | ||
1676 | static ssize_t show_net_stats(struct device *d, struct device_attribute *attr, | |
1677 | char *buf) | |
1678 | { | |
1679 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; | |
1680 | return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0'); | |
1681 | } | |
1682 | ||
1683 | static ssize_t store_net_stats(struct device *d, struct device_attribute *attr, | |
1684 | const char *buf, size_t count) | |
1685 | { | |
1686 | struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; | |
1687 | if (buf[0] == '1') | |
1688 | priv->config |= CFG_NET_STATS; | |
1689 | else | |
1690 | priv->config &= ~CFG_NET_STATS; | |
1691 | ||
1692 | return count; | |
1693 | } | |
1694 | ||
afbf30a2 JK |
1695 | static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, |
1696 | show_net_stats, store_net_stats); | |
b095c381 | 1697 | |
ea2b26e0 JK |
1698 | static void notify_wx_assoc_event(struct ipw_priv *priv) |
1699 | { | |
1700 | union iwreq_data wrqu; | |
1701 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1702 | if (priv->status & STATUS_ASSOCIATED) | |
1703 | memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); | |
1704 | else | |
1705 | memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); | |
1706 | wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); | |
1707 | } | |
1708 | ||
43f66a6c JK |
1709 | static void ipw_irq_tasklet(struct ipw_priv *priv) |
1710 | { | |
1711 | u32 inta, inta_mask, handled = 0; | |
1712 | unsigned long flags; | |
1713 | int rc = 0; | |
1714 | ||
1715 | spin_lock_irqsave(&priv->lock, flags); | |
1716 | ||
b095c381 JK |
1717 | inta = ipw_read32(priv, IPW_INTA_RW); |
1718 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); | |
1719 | inta &= (IPW_INTA_MASK_ALL & inta_mask); | |
43f66a6c JK |
1720 | |
1721 | /* Add any cached INTA values that need to be handled */ | |
1722 | inta |= priv->isr_inta; | |
1723 | ||
1724 | /* handle all the justifications for the interrupt */ | |
b095c381 | 1725 | if (inta & IPW_INTA_BIT_RX_TRANSFER) { |
43f66a6c | 1726 | ipw_rx(priv); |
b095c381 | 1727 | handled |= IPW_INTA_BIT_RX_TRANSFER; |
43f66a6c JK |
1728 | } |
1729 | ||
b095c381 | 1730 | if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) { |
43f66a6c | 1731 | IPW_DEBUG_HC("Command completed.\n"); |
0edd5b44 | 1732 | rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); |
43f66a6c JK |
1733 | priv->status &= ~STATUS_HCMD_ACTIVE; |
1734 | wake_up_interruptible(&priv->wait_command_queue); | |
b095c381 | 1735 | handled |= IPW_INTA_BIT_TX_CMD_QUEUE; |
43f66a6c JK |
1736 | } |
1737 | ||
b095c381 | 1738 | if (inta & IPW_INTA_BIT_TX_QUEUE_1) { |
43f66a6c | 1739 | IPW_DEBUG_TX("TX_QUEUE_1\n"); |
0edd5b44 | 1740 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); |
b095c381 | 1741 | handled |= IPW_INTA_BIT_TX_QUEUE_1; |
43f66a6c JK |
1742 | } |
1743 | ||
b095c381 | 1744 | if (inta & IPW_INTA_BIT_TX_QUEUE_2) { |
43f66a6c | 1745 | IPW_DEBUG_TX("TX_QUEUE_2\n"); |
0edd5b44 | 1746 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); |
b095c381 | 1747 | handled |= IPW_INTA_BIT_TX_QUEUE_2; |
43f66a6c JK |
1748 | } |
1749 | ||
b095c381 | 1750 | if (inta & IPW_INTA_BIT_TX_QUEUE_3) { |
43f66a6c | 1751 | IPW_DEBUG_TX("TX_QUEUE_3\n"); |
0edd5b44 | 1752 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); |
b095c381 | 1753 | handled |= IPW_INTA_BIT_TX_QUEUE_3; |
43f66a6c JK |
1754 | } |
1755 | ||
b095c381 | 1756 | if (inta & IPW_INTA_BIT_TX_QUEUE_4) { |
43f66a6c | 1757 | IPW_DEBUG_TX("TX_QUEUE_4\n"); |
0edd5b44 | 1758 | rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); |
b095c381 | 1759 | handled |= IPW_INTA_BIT_TX_QUEUE_4; |
43f66a6c JK |
1760 | } |
1761 | ||
b095c381 | 1762 | if (inta & IPW_INTA_BIT_STATUS_CHANGE) { |
43f66a6c | 1763 | IPW_WARNING("STATUS_CHANGE\n"); |
b095c381 | 1764 | handled |= IPW_INTA_BIT_STATUS_CHANGE; |
43f66a6c JK |
1765 | } |
1766 | ||
b095c381 | 1767 | if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) { |
43f66a6c | 1768 | IPW_WARNING("TX_PERIOD_EXPIRED\n"); |
b095c381 | 1769 | handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED; |
43f66a6c JK |
1770 | } |
1771 | ||
b095c381 | 1772 | if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { |
43f66a6c | 1773 | IPW_WARNING("HOST_CMD_DONE\n"); |
b095c381 | 1774 | handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; |
43f66a6c JK |
1775 | } |
1776 | ||
b095c381 | 1777 | if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) { |
43f66a6c | 1778 | IPW_WARNING("FW_INITIALIZATION_DONE\n"); |
b095c381 | 1779 | handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE; |
43f66a6c JK |
1780 | } |
1781 | ||
b095c381 | 1782 | if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { |
43f66a6c | 1783 | IPW_WARNING("PHY_OFF_DONE\n"); |
b095c381 | 1784 | handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; |
43f66a6c JK |
1785 | } |
1786 | ||
b095c381 | 1787 | if (inta & IPW_INTA_BIT_RF_KILL_DONE) { |
43f66a6c JK |
1788 | IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); |
1789 | priv->status |= STATUS_RF_KILL_HW; | |
1790 | wake_up_interruptible(&priv->wait_command_queue); | |
ea2b26e0 | 1791 | priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING); |
43f66a6c | 1792 | cancel_delayed_work(&priv->request_scan); |
a613bffd | 1793 | schedule_work(&priv->link_down); |
43f66a6c | 1794 | queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); |
b095c381 | 1795 | handled |= IPW_INTA_BIT_RF_KILL_DONE; |
43f66a6c | 1796 | } |
bf79451e | 1797 | |
b095c381 | 1798 | if (inta & IPW_INTA_BIT_FATAL_ERROR) { |
1d1b09eb | 1799 | IPW_WARNING("Firmware error detected. Restarting.\n"); |
b39860c6 | 1800 | if (priv->error) { |
1d1b09eb | 1801 | IPW_DEBUG_FW("Sysfs 'error' log already exists.\n"); |
0f52bf90 | 1802 | #ifdef CONFIG_IPW2200_DEBUG |
b39860c6 JK |
1803 | if (ipw_debug_level & IPW_DL_FW_ERRORS) { |
1804 | struct ipw_fw_error *error = | |
1805 | ipw_alloc_error_log(priv); | |
1806 | ipw_dump_error_log(priv, error); | |
1807 | if (error) | |
1808 | ipw_free_error_log(error); | |
1809 | } | |
1810 | #endif | |
1811 | } else { | |
1812 | priv->error = ipw_alloc_error_log(priv); | |
1813 | if (priv->error) | |
1d1b09eb | 1814 | IPW_DEBUG_FW("Sysfs 'error' log captured.\n"); |
b39860c6 | 1815 | else |
1d1b09eb ZY |
1816 | IPW_DEBUG_FW("Error allocating sysfs 'error' " |
1817 | "log.\n"); | |
0f52bf90 | 1818 | #ifdef CONFIG_IPW2200_DEBUG |
b39860c6 JK |
1819 | if (ipw_debug_level & IPW_DL_FW_ERRORS) |
1820 | ipw_dump_error_log(priv, priv->error); | |
43f66a6c | 1821 | #endif |
b39860c6 JK |
1822 | } |
1823 | ||
b095c381 JK |
1824 | /* XXX: If hardware encryption is for WPA/WPA2, |
1825 | * we have to notify the supplicant. */ | |
1826 | if (priv->ieee->sec.encrypt) { | |
1827 | priv->status &= ~STATUS_ASSOCIATED; | |
1828 | notify_wx_assoc_event(priv); | |
1829 | } | |
1830 | ||
1831 | /* Keep the restart process from trying to send host | |
1832 | * commands by clearing the INIT status bit */ | |
1833 | priv->status &= ~STATUS_INIT; | |
afbf30a2 JK |
1834 | |
1835 | /* Cancel currently queued command. */ | |
1836 | priv->status &= ~STATUS_HCMD_ACTIVE; | |
1837 | wake_up_interruptible(&priv->wait_command_queue); | |
1838 | ||
43f66a6c | 1839 | queue_work(priv->workqueue, &priv->adapter_restart); |
b095c381 | 1840 | handled |= IPW_INTA_BIT_FATAL_ERROR; |
43f66a6c JK |
1841 | } |
1842 | ||
b095c381 | 1843 | if (inta & IPW_INTA_BIT_PARITY_ERROR) { |
43f66a6c | 1844 | IPW_ERROR("Parity error\n"); |
b095c381 | 1845 | handled |= IPW_INTA_BIT_PARITY_ERROR; |
43f66a6c JK |
1846 | } |
1847 | ||
1848 | if (handled != inta) { | |
0edd5b44 | 1849 | IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
43f66a6c JK |
1850 | } |
1851 | ||
1852 | /* enable all interrupts */ | |
1853 | ipw_enable_interrupts(priv); | |
1854 | ||
1855 | spin_unlock_irqrestore(&priv->lock, flags); | |
1856 | } | |
bf79451e | 1857 | |
43f66a6c JK |
1858 | #define IPW_CMD(x) case IPW_CMD_ ## x : return #x |
1859 | static char *get_cmd_string(u8 cmd) | |
1860 | { | |
1861 | switch (cmd) { | |
1862 | IPW_CMD(HOST_COMPLETE); | |
bf79451e JG |
1863 | IPW_CMD(POWER_DOWN); |
1864 | IPW_CMD(SYSTEM_CONFIG); | |
1865 | IPW_CMD(MULTICAST_ADDRESS); | |
1866 | IPW_CMD(SSID); | |
1867 | IPW_CMD(ADAPTER_ADDRESS); | |
1868 | IPW_CMD(PORT_TYPE); | |
1869 | IPW_CMD(RTS_THRESHOLD); | |
1870 | IPW_CMD(FRAG_THRESHOLD); | |
1871 | IPW_CMD(POWER_MODE); | |
1872 | IPW_CMD(WEP_KEY); | |
1873 | IPW_CMD(TGI_TX_KEY); | |
1874 | IPW_CMD(SCAN_REQUEST); | |
1875 | IPW_CMD(SCAN_REQUEST_EXT); | |
1876 | IPW_CMD(ASSOCIATE); | |
1877 | IPW_CMD(SUPPORTED_RATES); | |
1878 | IPW_CMD(SCAN_ABORT); | |
1879 | IPW_CMD(TX_FLUSH); | |
1880 | IPW_CMD(QOS_PARAMETERS); | |
1881 | IPW_CMD(DINO_CONFIG); | |
1882 | IPW_CMD(RSN_CAPABILITIES); | |
1883 | IPW_CMD(RX_KEY); | |
1884 | IPW_CMD(CARD_DISABLE); | |
1885 | IPW_CMD(SEED_NUMBER); | |
1886 | IPW_CMD(TX_POWER); | |
1887 | IPW_CMD(COUNTRY_INFO); | |
1888 | IPW_CMD(AIRONET_INFO); | |
1889 | IPW_CMD(AP_TX_POWER); | |
1890 | IPW_CMD(CCKM_INFO); | |
1891 | IPW_CMD(CCX_VER_INFO); | |
1892 | IPW_CMD(SET_CALIBRATION); | |
1893 | IPW_CMD(SENSITIVITY_CALIB); | |
1894 | IPW_CMD(RETRY_LIMIT); | |
1895 | IPW_CMD(IPW_PRE_POWER_DOWN); | |
1896 | IPW_CMD(VAP_BEACON_TEMPLATE); | |
1897 | IPW_CMD(VAP_DTIM_PERIOD); | |
1898 | IPW_CMD(EXT_SUPPORTED_RATES); | |
1899 | IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT); | |
1900 | IPW_CMD(VAP_QUIET_INTERVALS); | |
1901 | IPW_CMD(VAP_CHANNEL_SWITCH); | |
1902 | IPW_CMD(VAP_MANDATORY_CHANNELS); | |
1903 | IPW_CMD(VAP_CELL_PWR_LIMIT); | |
1904 | IPW_CMD(VAP_CF_PARAM_SET); | |
1905 | IPW_CMD(VAP_SET_BEACONING_STATE); | |
1906 | IPW_CMD(MEASUREMENT); | |
1907 | IPW_CMD(POWER_CAPABILITY); | |
1908 | IPW_CMD(SUPPORTED_CHANNELS); | |
1909 | IPW_CMD(TPC_REPORT); | |
1910 | IPW_CMD(WME_INFO); | |
1911 | IPW_CMD(PRODUCTION_COMMAND); | |
1912 | default: | |
43f66a6c JK |
1913 | return "UNKNOWN"; |
1914 | } | |
1915 | } | |
43f66a6c JK |
1916 | |
1917 | #define HOST_COMPLETE_TIMEOUT HZ | |
0a7bcf26 ZY |
1918 | |
1919 | static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd) | |
43f66a6c JK |
1920 | { |
1921 | int rc = 0; | |
a613bffd | 1922 | unsigned long flags; |
43f66a6c | 1923 | |
a613bffd | 1924 | spin_lock_irqsave(&priv->lock, flags); |
43f66a6c | 1925 | if (priv->status & STATUS_HCMD_ACTIVE) { |
9ddf84f6 JK |
1926 | IPW_ERROR("Failed to send %s: Already sending a command.\n", |
1927 | get_cmd_string(cmd->cmd)); | |
a613bffd | 1928 | spin_unlock_irqrestore(&priv->lock, flags); |
9ddf84f6 | 1929 | return -EAGAIN; |
43f66a6c JK |
1930 | } |
1931 | ||
1932 | priv->status |= STATUS_HCMD_ACTIVE; | |
bf79451e | 1933 | |
f6c5cb7c JK |
1934 | if (priv->cmdlog) { |
1935 | priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies; | |
1936 | priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd; | |
1937 | priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len; | |
1938 | memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param, | |
1939 | cmd->len); | |
1940 | priv->cmdlog[priv->cmdlog_pos].retcode = -1; | |
1941 | } | |
1942 | ||
b095c381 JK |
1943 | IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n", |
1944 | get_cmd_string(cmd->cmd), cmd->cmd, cmd->len, | |
1945 | priv->status); | |
f516dbcd ZY |
1946 | |
1947 | #ifndef DEBUG_CMD_WEP_KEY | |
1948 | if (cmd->cmd == IPW_CMD_WEP_KEY) | |
1949 | IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n"); | |
1950 | else | |
1951 | #endif | |
1952 | printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); | |
1953 | ||
0a7bcf26 | 1954 | rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0); |
a613bffd JK |
1955 | if (rc) { |
1956 | priv->status &= ~STATUS_HCMD_ACTIVE; | |
9ddf84f6 JK |
1957 | IPW_ERROR("Failed to send %s: Reason %d\n", |
1958 | get_cmd_string(cmd->cmd), rc); | |
a613bffd | 1959 | spin_unlock_irqrestore(&priv->lock, flags); |
f6c5cb7c | 1960 | goto exit; |
a613bffd JK |
1961 | } |
1962 | spin_unlock_irqrestore(&priv->lock, flags); | |
43f66a6c | 1963 | |
0edd5b44 JG |
1964 | rc = wait_event_interruptible_timeout(priv->wait_command_queue, |
1965 | !(priv-> | |
1966 | status & STATUS_HCMD_ACTIVE), | |
1967 | HOST_COMPLETE_TIMEOUT); | |
43f66a6c | 1968 | if (rc == 0) { |
a613bffd JK |
1969 | spin_lock_irqsave(&priv->lock, flags); |
1970 | if (priv->status & STATUS_HCMD_ACTIVE) { | |
9ddf84f6 JK |
1971 | IPW_ERROR("Failed to send %s: Command timed out.\n", |
1972 | get_cmd_string(cmd->cmd)); | |
a613bffd JK |
1973 | priv->status &= ~STATUS_HCMD_ACTIVE; |
1974 | spin_unlock_irqrestore(&priv->lock, flags); | |
f6c5cb7c JK |
1975 | rc = -EIO; |
1976 | goto exit; | |
a613bffd JK |
1977 | } |
1978 | spin_unlock_irqrestore(&priv->lock, flags); | |
3b9990cb JK |
1979 | } else |
1980 | rc = 0; | |
a613bffd | 1981 | |
b095c381 | 1982 | if (priv->status & STATUS_RF_KILL_HW) { |
9ddf84f6 JK |
1983 | IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n", |
1984 | get_cmd_string(cmd->cmd)); | |
f6c5cb7c JK |
1985 | rc = -EIO; |
1986 | goto exit; | |
43f66a6c JK |
1987 | } |
1988 | ||
2638bc39 | 1989 | exit: |
f6c5cb7c JK |
1990 | if (priv->cmdlog) { |
1991 | priv->cmdlog[priv->cmdlog_pos++].retcode = rc; | |
1992 | priv->cmdlog_pos %= priv->cmdlog_len; | |
1993 | } | |
1994 | return rc; | |
43f66a6c JK |
1995 | } |
1996 | ||
0a7bcf26 ZY |
1997 | static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command) |
1998 | { | |
1999 | struct host_cmd cmd = { | |
2000 | .cmd = command, | |
2001 | }; | |
2002 | ||
2003 | return __ipw_send_cmd(priv, &cmd); | |
2004 | } | |
2005 | ||
2006 | static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len, | |
2007 | void *data) | |
43f66a6c JK |
2008 | { |
2009 | struct host_cmd cmd = { | |
0a7bcf26 ZY |
2010 | .cmd = command, |
2011 | .len = len, | |
2012 | .param = data, | |
43f66a6c JK |
2013 | }; |
2014 | ||
0a7bcf26 ZY |
2015 | return __ipw_send_cmd(priv, &cmd); |
2016 | } | |
2017 | ||
2018 | static int ipw_send_host_complete(struct ipw_priv *priv) | |
2019 | { | |
43f66a6c JK |
2020 | if (!priv) { |
2021 | IPW_ERROR("Invalid args\n"); | |
2022 | return -1; | |
2023 | } | |
2024 | ||
0a7bcf26 | 2025 | return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE); |
43f66a6c JK |
2026 | } |
2027 | ||
bf79451e | 2028 | static int ipw_send_system_config(struct ipw_priv *priv, |
43f66a6c JK |
2029 | struct ipw_sys_config *config) |
2030 | { | |
43f66a6c JK |
2031 | if (!priv || !config) { |
2032 | IPW_ERROR("Invalid args\n"); | |
2033 | return -1; | |
2034 | } | |
2035 | ||
0a7bcf26 | 2036 | return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, sizeof(*config), |
2638bc39 | 2037 | config); |
43f66a6c JK |
2038 | } |
2039 | ||
0edd5b44 | 2040 | static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len) |
43f66a6c | 2041 | { |
43f66a6c JK |
2042 | if (!priv || !ssid) { |
2043 | IPW_ERROR("Invalid args\n"); | |
2044 | return -1; | |
2045 | } | |
2046 | ||
0a7bcf26 | 2047 | return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE), |
2638bc39 | 2048 | ssid); |
43f66a6c JK |
2049 | } |
2050 | ||
0edd5b44 | 2051 | static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) |
43f66a6c | 2052 | { |
43f66a6c JK |
2053 | if (!priv || !mac) { |
2054 | IPW_ERROR("Invalid args\n"); | |
2055 | return -1; | |
2056 | } | |
2057 | ||
2058 | IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n", | |
2059 | priv->net_dev->name, MAC_ARG(mac)); | |
2060 | ||
2638bc39 | 2061 | return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac); |
43f66a6c JK |
2062 | } |
2063 | ||
a613bffd JK |
2064 | /* |
2065 | * NOTE: This must be executed from our workqueue as it results in udelay | |
2066 | * being called which may corrupt the keyboard if executed on default | |
2067 | * workqueue | |
2068 | */ | |
43f66a6c JK |
2069 | static void ipw_adapter_restart(void *adapter) |
2070 | { | |
2071 | struct ipw_priv *priv = adapter; | |
2072 | ||
2073 | if (priv->status & STATUS_RF_KILL_MASK) | |
2074 | return; | |
2075 | ||
2076 | ipw_down(priv); | |
b095c381 JK |
2077 | |
2078 | if (priv->assoc_network && | |
2079 | (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS)) | |
2080 | ipw_remove_current_network(priv); | |
2081 | ||
43f66a6c JK |
2082 | if (ipw_up(priv)) { |
2083 | IPW_ERROR("Failed to up device\n"); | |
2084 | return; | |
2085 | } | |
2086 | } | |
2087 | ||
c848d0af JK |
2088 | static void ipw_bg_adapter_restart(void *data) |
2089 | { | |
2090 | struct ipw_priv *priv = data; | |
4644151b | 2091 | mutex_lock(&priv->mutex); |
c848d0af | 2092 | ipw_adapter_restart(data); |
4644151b | 2093 | mutex_unlock(&priv->mutex); |
c848d0af JK |
2094 | } |
2095 | ||
43f66a6c JK |
2096 | #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) |
2097 | ||
2098 | static void ipw_scan_check(void *data) | |
2099 | { | |
2100 | struct ipw_priv *priv = data; | |
2101 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { | |
2102 | IPW_DEBUG_SCAN("Scan completion watchdog resetting " | |
c7b6a674 ZY |
2103 | "adapter after (%dms).\n", |
2104 | jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG)); | |
a613bffd | 2105 | queue_work(priv->workqueue, &priv->adapter_restart); |
43f66a6c JK |
2106 | } |
2107 | } | |
2108 | ||
c848d0af JK |
2109 | static void ipw_bg_scan_check(void *data) |
2110 | { | |
2111 | struct ipw_priv *priv = data; | |
4644151b | 2112 | mutex_lock(&priv->mutex); |
c848d0af | 2113 | ipw_scan_check(data); |
4644151b | 2114 | mutex_unlock(&priv->mutex); |
c848d0af JK |
2115 | } |
2116 | ||
43f66a6c JK |
2117 | static int ipw_send_scan_request_ext(struct ipw_priv *priv, |
2118 | struct ipw_scan_request_ext *request) | |
2119 | { | |
0a7bcf26 | 2120 | return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT, |
2638bc39 | 2121 | sizeof(*request), request); |
43f66a6c JK |
2122 | } |
2123 | ||
2124 | static int ipw_send_scan_abort(struct ipw_priv *priv) | |
2125 | { | |
43f66a6c JK |
2126 | if (!priv) { |
2127 | IPW_ERROR("Invalid args\n"); | |
2128 | return -1; | |
2129 | } | |
2130 | ||
0a7bcf26 | 2131 | return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT); |
43f66a6c JK |
2132 | } |
2133 | ||
2134 | static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) | |
2135 | { | |
0a7bcf26 ZY |
2136 | struct ipw_sensitivity_calib calib = { |
2137 | .beacon_rssi_raw = sens, | |
43f66a6c | 2138 | }; |
0a7bcf26 ZY |
2139 | |
2140 | return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib), | |
2638bc39 | 2141 | &calib); |
43f66a6c JK |
2142 | } |
2143 | ||
2144 | static int ipw_send_associate(struct ipw_priv *priv, | |
2145 | struct ipw_associate *associate) | |
2146 | { | |
a613bffd | 2147 | struct ipw_associate tmp_associate; |
0a7bcf26 ZY |
2148 | |
2149 | if (!priv || !associate) { | |
2150 | IPW_ERROR("Invalid args\n"); | |
2151 | return -1; | |
2152 | } | |
2153 | ||
a613bffd JK |
2154 | memcpy(&tmp_associate, associate, sizeof(*associate)); |
2155 | tmp_associate.policy_support = | |
2156 | cpu_to_le16(tmp_associate.policy_support); | |
2157 | tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw); | |
2158 | tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw); | |
2159 | tmp_associate.capability = cpu_to_le16(tmp_associate.capability); | |
2160 | tmp_associate.listen_interval = | |
2161 | cpu_to_le16(tmp_associate.listen_interval); | |
2162 | tmp_associate.beacon_interval = | |
2163 | cpu_to_le16(tmp_associate.beacon_interval); | |
2164 | tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window); | |
2165 | ||
0a7bcf26 | 2166 | return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate), |
2638bc39 | 2167 | &tmp_associate); |
43f66a6c JK |
2168 | } |
2169 | ||
2170 | static int ipw_send_supported_rates(struct ipw_priv *priv, | |
2171 | struct ipw_supported_rates *rates) | |
2172 | { | |
43f66a6c JK |
2173 | if (!priv || !rates) { |
2174 | IPW_ERROR("Invalid args\n"); | |
2175 | return -1; | |
2176 | } | |
2177 | ||
0a7bcf26 | 2178 | return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates), |
2638bc39 | 2179 | rates); |
43f66a6c JK |
2180 | } |
2181 | ||
2182 | static int ipw_set_random_seed(struct ipw_priv *priv) | |
2183 | { | |
0a7bcf26 | 2184 | u32 val; |
43f66a6c JK |
2185 | |
2186 | if (!priv) { | |
2187 | IPW_ERROR("Invalid args\n"); | |
2188 | return -1; | |
2189 | } | |
2190 | ||
0a7bcf26 | 2191 | get_random_bytes(&val, sizeof(val)); |
43f66a6c | 2192 | |
0a7bcf26 | 2193 | return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val); |
43f66a6c JK |
2194 | } |
2195 | ||
43f66a6c JK |
2196 | static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) |
2197 | { | |
43f66a6c JK |
2198 | if (!priv) { |
2199 | IPW_ERROR("Invalid args\n"); | |
2200 | return -1; | |
2201 | } | |
2202 | ||
0a7bcf26 | 2203 | return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off), |
2638bc39 | 2204 | &phy_off); |
43f66a6c | 2205 | } |
43f66a6c | 2206 | |
0edd5b44 | 2207 | static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power) |
43f66a6c | 2208 | { |
43f66a6c JK |
2209 | if (!priv || !power) { |
2210 | IPW_ERROR("Invalid args\n"); | |
2211 | return -1; | |
2212 | } | |
2213 | ||
2638bc39 | 2214 | return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power); |
43f66a6c JK |
2215 | } |
2216 | ||
6de9f7f2 ZY |
2217 | static int ipw_set_tx_power(struct ipw_priv *priv) |
2218 | { | |
1867b117 | 2219 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
6de9f7f2 ZY |
2220 | struct ipw_tx_power tx_power; |
2221 | s8 max_power; | |
2222 | int i; | |
2223 | ||
2224 | memset(&tx_power, 0, sizeof(tx_power)); | |
2225 | ||
2226 | /* configure device for 'G' band */ | |
2227 | tx_power.ieee_mode = IPW_G_MODE; | |
2228 | tx_power.num_channels = geo->bg_channels; | |
2229 | for (i = 0; i < geo->bg_channels; i++) { | |
2230 | max_power = geo->bg[i].max_power; | |
2231 | tx_power.channels_tx_power[i].channel_number = | |
2232 | geo->bg[i].channel; | |
2233 | tx_power.channels_tx_power[i].tx_power = max_power ? | |
2234 | min(max_power, priv->tx_power) : priv->tx_power; | |
43f66a6c | 2235 | } |
6de9f7f2 ZY |
2236 | if (ipw_send_tx_power(priv, &tx_power)) |
2237 | return -EIO; | |
2238 | ||
2239 | /* configure device to also handle 'B' band */ | |
2240 | tx_power.ieee_mode = IPW_B_MODE; | |
2241 | if (ipw_send_tx_power(priv, &tx_power)) | |
2242 | return -EIO; | |
bf79451e | 2243 | |
6de9f7f2 ZY |
2244 | /* configure device to also handle 'A' band */ |
2245 | if (priv->ieee->abg_true) { | |
2246 | tx_power.ieee_mode = IPW_A_MODE; | |
2247 | tx_power.num_channels = geo->a_channels; | |
2248 | for (i = 0; i < tx_power.num_channels; i++) { | |
2249 | max_power = geo->a[i].max_power; | |
2250 | tx_power.channels_tx_power[i].channel_number = | |
2251 | geo->a[i].channel; | |
2252 | tx_power.channels_tx_power[i].tx_power = max_power ? | |
2253 | min(max_power, priv->tx_power) : priv->tx_power; | |
2254 | } | |
2255 | if (ipw_send_tx_power(priv, &tx_power)) | |
2256 | return -EIO; | |
2257 | } | |
43f66a6c JK |
2258 | return 0; |
2259 | } | |
2260 | ||
2261 | static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts) | |
2262 | { | |
2263 | struct ipw_rts_threshold rts_threshold = { | |
2264 | .rts_threshold = rts, | |
2265 | }; | |
43f66a6c JK |
2266 | |
2267 | if (!priv) { | |
2268 | IPW_ERROR("Invalid args\n"); | |
2269 | return -1; | |
2270 | } | |
2271 | ||
0a7bcf26 ZY |
2272 | return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD, |
2273 | sizeof(rts_threshold), &rts_threshold); | |
43f66a6c JK |
2274 | } |
2275 | ||
2276 | static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) | |
2277 | { | |
2278 | struct ipw_frag_threshold frag_threshold = { | |
2279 | .frag_threshold = frag, | |
2280 | }; | |
43f66a6c JK |
2281 | |
2282 | if (!priv) { | |
2283 | IPW_ERROR("Invalid args\n"); | |
2284 | return -1; | |
2285 | } | |
2286 | ||
0a7bcf26 ZY |
2287 | return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD, |
2288 | sizeof(frag_threshold), &frag_threshold); | |
43f66a6c JK |
2289 | } |
2290 | ||
2291 | static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) | |
2292 | { | |
0a7bcf26 | 2293 | u32 param; |
43f66a6c JK |
2294 | |
2295 | if (!priv) { | |
2296 | IPW_ERROR("Invalid args\n"); | |
2297 | return -1; | |
2298 | } | |
bf79451e | 2299 | |
43f66a6c JK |
2300 | /* If on battery, set to 3, if AC set to CAM, else user |
2301 | * level */ | |
2302 | switch (mode) { | |
2303 | case IPW_POWER_BATTERY: | |
0a7bcf26 | 2304 | param = IPW_POWER_INDEX_3; |
43f66a6c JK |
2305 | break; |
2306 | case IPW_POWER_AC: | |
0a7bcf26 | 2307 | param = IPW_POWER_MODE_CAM; |
43f66a6c JK |
2308 | break; |
2309 | default: | |
0a7bcf26 | 2310 | param = mode; |
43f66a6c JK |
2311 | break; |
2312 | } | |
2313 | ||
0a7bcf26 | 2314 | return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param), |
2638bc39 | 2315 | ¶m); |
43f66a6c JK |
2316 | } |
2317 | ||
afbf30a2 JK |
2318 | static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit) |
2319 | { | |
2320 | struct ipw_retry_limit retry_limit = { | |
2321 | .short_retry_limit = slimit, | |
2322 | .long_retry_limit = llimit | |
2323 | }; | |
afbf30a2 JK |
2324 | |
2325 | if (!priv) { | |
2326 | IPW_ERROR("Invalid args\n"); | |
2327 | return -1; | |
2328 | } | |
2329 | ||
0a7bcf26 | 2330 | return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit), |
2638bc39 | 2331 | &retry_limit); |
afbf30a2 JK |
2332 | } |
2333 | ||
43f66a6c JK |
2334 | /* |
2335 | * The IPW device contains a Microwire compatible EEPROM that stores | |
2336 | * various data like the MAC address. Usually the firmware has exclusive | |
2337 | * access to the eeprom, but during device initialization (before the | |
2338 | * device driver has sent the HostComplete command to the firmware) the | |
2339 | * device driver has read access to the EEPROM by way of indirect addressing | |
2340 | * through a couple of memory mapped registers. | |
2341 | * | |
2342 | * The following is a simplified implementation for pulling data out of the | |
2343 | * the eeprom, along with some helper functions to find information in | |
2344 | * the per device private data's copy of the eeprom. | |
2345 | * | |
2346 | * NOTE: To better understand how these functions work (i.e what is a chip | |
2347 | * select and why do have to keep driving the eeprom clock?), read | |
2348 | * just about any data sheet for a Microwire compatible EEPROM. | |
2349 | */ | |
2350 | ||
2351 | /* write a 32 bit value into the indirect accessor register */ | |
2352 | static inline void eeprom_write_reg(struct ipw_priv *p, u32 data) | |
2353 | { | |
2354 | ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data); | |
bf79451e | 2355 | |
43f66a6c JK |
2356 | /* the eeprom requires some time to complete the operation */ |
2357 | udelay(p->eeprom_delay); | |
2358 | ||
2359 | return; | |
2360 | } | |
2361 | ||
2362 | /* perform a chip select operation */ | |
858119e1 | 2363 | static void eeprom_cs(struct ipw_priv *priv) |
43f66a6c | 2364 | { |
0edd5b44 JG |
2365 | eeprom_write_reg(priv, 0); |
2366 | eeprom_write_reg(priv, EEPROM_BIT_CS); | |
2367 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); | |
2368 | eeprom_write_reg(priv, EEPROM_BIT_CS); | |
43f66a6c JK |
2369 | } |
2370 | ||
2371 | /* perform a chip select operation */ | |
858119e1 | 2372 | static void eeprom_disable_cs(struct ipw_priv *priv) |
43f66a6c | 2373 | { |
0edd5b44 JG |
2374 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
2375 | eeprom_write_reg(priv, 0); | |
2376 | eeprom_write_reg(priv, EEPROM_BIT_SK); | |
43f66a6c JK |
2377 | } |
2378 | ||
2379 | /* push a single bit down to the eeprom */ | |
0edd5b44 | 2380 | static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit) |
43f66a6c | 2381 | { |
0edd5b44 JG |
2382 | int d = (bit ? EEPROM_BIT_DI : 0); |
2383 | eeprom_write_reg(p, EEPROM_BIT_CS | d); | |
2384 | eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK); | |
43f66a6c JK |
2385 | } |
2386 | ||
2387 | /* push an opcode followed by an address down to the eeprom */ | |
0edd5b44 | 2388 | static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr) |
43f66a6c JK |
2389 | { |
2390 | int i; | |
2391 | ||
2392 | eeprom_cs(priv); | |
0edd5b44 JG |
2393 | eeprom_write_bit(priv, 1); |
2394 | eeprom_write_bit(priv, op & 2); | |
2395 | eeprom_write_bit(priv, op & 1); | |
2396 | for (i = 7; i >= 0; i--) { | |
2397 | eeprom_write_bit(priv, addr & (1 << i)); | |
43f66a6c JK |
2398 | } |
2399 | } | |
2400 | ||
2401 | /* pull 16 bits off the eeprom, one bit at a time */ | |
0edd5b44 | 2402 | static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr) |
43f66a6c JK |
2403 | { |
2404 | int i; | |
0edd5b44 | 2405 | u16 r = 0; |
bf79451e | 2406 | |
43f66a6c | 2407 | /* Send READ Opcode */ |
0edd5b44 | 2408 | eeprom_op(priv, EEPROM_CMD_READ, addr); |
43f66a6c JK |
2409 | |
2410 | /* Send dummy bit */ | |
0edd5b44 | 2411 | eeprom_write_reg(priv, EEPROM_BIT_CS); |
43f66a6c JK |
2412 | |
2413 | /* Read the byte off the eeprom one bit at a time */ | |
0edd5b44 | 2414 | for (i = 0; i < 16; i++) { |
43f66a6c | 2415 | u32 data = 0; |
0edd5b44 JG |
2416 | eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK); |
2417 | eeprom_write_reg(priv, EEPROM_BIT_CS); | |
2418 | data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS); | |
2419 | r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0); | |
43f66a6c | 2420 | } |
bf79451e | 2421 | |
43f66a6c | 2422 | /* Send another dummy bit */ |
0edd5b44 | 2423 | eeprom_write_reg(priv, 0); |
43f66a6c | 2424 | eeprom_disable_cs(priv); |
bf79451e | 2425 | |
43f66a6c JK |
2426 | return r; |
2427 | } | |
2428 | ||
2429 | /* helper function for pulling the mac address out of the private */ | |
2430 | /* data's copy of the eeprom data */ | |
0edd5b44 | 2431 | static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) |
43f66a6c | 2432 | { |
afbf30a2 | 2433 | memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); |
43f66a6c JK |
2434 | } |
2435 | ||
2436 | /* | |
2437 | * Either the device driver (i.e. the host) or the firmware can | |
2438 | * load eeprom data into the designated region in SRAM. If neither | |
2439 | * happens then the FW will shutdown with a fatal error. | |
2440 | * | |
2441 | * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE | |
2442 | * bit needs region of shared SRAM needs to be non-zero. | |
2443 | */ | |
2444 | static void ipw_eeprom_init_sram(struct ipw_priv *priv) | |
2445 | { | |
2446 | int i; | |
0edd5b44 | 2447 | u16 *eeprom = (u16 *) priv->eeprom; |
bf79451e | 2448 | |
43f66a6c JK |
2449 | IPW_DEBUG_TRACE(">>\n"); |
2450 | ||
2451 | /* read entire contents of eeprom into private buffer */ | |
0edd5b44 | 2452 | for (i = 0; i < 128; i++) |
a613bffd | 2453 | eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i)); |
43f66a6c | 2454 | |
bf79451e JG |
2455 | /* |
2456 | If the data looks correct, then copy it to our private | |
43f66a6c | 2457 | copy. Otherwise let the firmware know to perform the operation |
c7b6a674 | 2458 | on its own. |
0edd5b44 | 2459 | */ |
386093ef | 2460 | if (priv->eeprom[EEPROM_VERSION] != 0) { |
43f66a6c JK |
2461 | IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); |
2462 | ||
2463 | /* write the eeprom data to sram */ | |
b095c381 | 2464 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
0edd5b44 | 2465 | ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); |
43f66a6c JK |
2466 | |
2467 | /* Do not load eeprom data on fatal error or suspend */ | |
2468 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); | |
2469 | } else { | |
2470 | IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n"); | |
2471 | ||
2472 | /* Load eeprom data on fatal error or suspend */ | |
2473 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1); | |
2474 | } | |
2475 | ||
2476 | IPW_DEBUG_TRACE("<<\n"); | |
2477 | } | |
2478 | ||
858119e1 | 2479 | static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count) |
43f66a6c JK |
2480 | { |
2481 | count >>= 2; | |
0edd5b44 JG |
2482 | if (!count) |
2483 | return; | |
b095c381 | 2484 | _ipw_write32(priv, IPW_AUTOINC_ADDR, start); |
bf79451e | 2485 | while (count--) |
b095c381 | 2486 | _ipw_write32(priv, IPW_AUTOINC_DATA, 0); |
43f66a6c JK |
2487 | } |
2488 | ||
2489 | static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) | |
2490 | { | |
b095c381 | 2491 | ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL, |
bf79451e | 2492 | CB_NUMBER_OF_ELEMENTS_SMALL * |
43f66a6c JK |
2493 | sizeof(struct command_block)); |
2494 | } | |
2495 | ||
2496 | static int ipw_fw_dma_enable(struct ipw_priv *priv) | |
0edd5b44 | 2497 | { /* start dma engine but no transfers yet */ |
43f66a6c JK |
2498 | |
2499 | IPW_DEBUG_FW(">> : \n"); | |
bf79451e | 2500 | |
43f66a6c JK |
2501 | /* Start the dma */ |
2502 | ipw_fw_dma_reset_command_blocks(priv); | |
bf79451e | 2503 | |
43f66a6c | 2504 | /* Write CB base address */ |
b095c381 | 2505 | ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL); |
43f66a6c JK |
2506 | |
2507 | IPW_DEBUG_FW("<< : \n"); | |
2508 | return 0; | |
2509 | } | |
2510 | ||
2511 | static void ipw_fw_dma_abort(struct ipw_priv *priv) | |
2512 | { | |
2513 | u32 control = 0; | |
2514 | ||
2515 | IPW_DEBUG_FW(">> :\n"); | |
bf79451e JG |
2516 | |
2517 | //set the Stop and Abort bit | |
43f66a6c | 2518 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; |
b095c381 | 2519 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
43f66a6c | 2520 | priv->sram_desc.last_cb_index = 0; |
bf79451e | 2521 | |
43f66a6c JK |
2522 | IPW_DEBUG_FW("<< \n"); |
2523 | } | |
2524 | ||
0edd5b44 JG |
2525 | static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index, |
2526 | struct command_block *cb) | |
43f66a6c | 2527 | { |
0edd5b44 | 2528 | u32 address = |
b095c381 | 2529 | IPW_SHARED_SRAM_DMA_CONTROL + |
0edd5b44 | 2530 | (sizeof(struct command_block) * index); |
43f66a6c JK |
2531 | IPW_DEBUG_FW(">> :\n"); |
2532 | ||
0edd5b44 JG |
2533 | ipw_write_indirect(priv, address, (u8 *) cb, |
2534 | (int)sizeof(struct command_block)); | |
43f66a6c JK |
2535 | |
2536 | IPW_DEBUG_FW("<< :\n"); | |
2537 | return 0; | |
2538 | ||
2539 | } | |
2540 | ||
2541 | static int ipw_fw_dma_kick(struct ipw_priv *priv) | |
2542 | { | |
2543 | u32 control = 0; | |
0edd5b44 | 2544 | u32 index = 0; |
43f66a6c JK |
2545 | |
2546 | IPW_DEBUG_FW(">> :\n"); | |
bf79451e | 2547 | |
43f66a6c | 2548 | for (index = 0; index < priv->sram_desc.last_cb_index; index++) |
0edd5b44 JG |
2549 | ipw_fw_dma_write_command_block(priv, index, |
2550 | &priv->sram_desc.cb_list[index]); | |
43f66a6c JK |
2551 | |
2552 | /* Enable the DMA in the CSR register */ | |
b095c381 JK |
2553 | ipw_clear_bit(priv, IPW_RESET_REG, |
2554 | IPW_RESET_REG_MASTER_DISABLED | | |
2555 | IPW_RESET_REG_STOP_MASTER); | |
bf79451e | 2556 | |
0edd5b44 | 2557 | /* Set the Start bit. */ |
43f66a6c | 2558 | control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; |
b095c381 | 2559 | ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control); |
43f66a6c JK |
2560 | |
2561 | IPW_DEBUG_FW("<< :\n"); | |
2562 | return 0; | |
2563 | } | |
2564 | ||
2565 | static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv) | |
2566 | { | |
2567 | u32 address; | |
0edd5b44 JG |
2568 | u32 register_value = 0; |
2569 | u32 cb_fields_address = 0; | |
43f66a6c JK |
2570 | |
2571 | IPW_DEBUG_FW(">> :\n"); | |
b095c381 | 2572 | address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
0edd5b44 | 2573 | IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); |
43f66a6c JK |
2574 | |
2575 | /* Read the DMA Controlor register */ | |
b095c381 JK |
2576 | register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL); |
2577 | IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value); | |
43f66a6c | 2578 | |
0edd5b44 | 2579 | /* Print the CB values */ |
43f66a6c JK |
2580 | cb_fields_address = address; |
2581 | register_value = ipw_read_reg32(priv, cb_fields_address); | |
0edd5b44 | 2582 | IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value); |
43f66a6c JK |
2583 | |
2584 | cb_fields_address += sizeof(u32); | |
2585 | register_value = ipw_read_reg32(priv, cb_fields_address); | |
0edd5b44 | 2586 | IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value); |
43f66a6c JK |
2587 | |
2588 | cb_fields_address += sizeof(u32); | |
2589 | register_value = ipw_read_reg32(priv, cb_fields_address); | |
2590 | IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n", | |
2591 | register_value); | |
2592 | ||
2593 | cb_fields_address += sizeof(u32); | |
2594 | register_value = ipw_read_reg32(priv, cb_fields_address); | |
0edd5b44 | 2595 | IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value); |
43f66a6c JK |
2596 | |
2597 | IPW_DEBUG_FW(">> :\n"); | |
2598 | } | |
2599 | ||
2600 | static int ipw_fw_dma_command_block_index(struct ipw_priv *priv) | |
2601 | { | |
2602 | u32 current_cb_address = 0; | |
2603 | u32 current_cb_index = 0; | |
2604 | ||
2605 | IPW_DEBUG_FW("<< :\n"); | |
b095c381 | 2606 | current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB); |
bf79451e | 2607 | |
b095c381 | 2608 | current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) / |
0edd5b44 | 2609 | sizeof(struct command_block); |
bf79451e | 2610 | |
43f66a6c | 2611 | IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n", |
0edd5b44 | 2612 | current_cb_index, current_cb_address); |
43f66a6c JK |
2613 | |
2614 | IPW_DEBUG_FW(">> :\n"); | |
2615 | return current_cb_index; | |
2616 | ||
2617 | } | |
2618 | ||
2619 | static int ipw_fw_dma_add_command_block(struct ipw_priv *priv, | |
2620 | u32 src_address, | |
2621 | u32 dest_address, | |
2622 | u32 length, | |
0edd5b44 | 2623 | int interrupt_enabled, int is_last) |
43f66a6c JK |
2624 | { |
2625 | ||
bf79451e | 2626 | u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC | |
0edd5b44 JG |
2627 | CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG | |
2628 | CB_DEST_SIZE_LONG; | |
43f66a6c | 2629 | struct command_block *cb; |
0edd5b44 | 2630 | u32 last_cb_element = 0; |
43f66a6c JK |
2631 | |
2632 | IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n", | |
2633 | src_address, dest_address, length); | |
2634 | ||
2635 | if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL) | |
2636 | return -1; | |
2637 | ||
2638 | last_cb_element = priv->sram_desc.last_cb_index; | |
2639 | cb = &priv->sram_desc.cb_list[last_cb_element]; | |
2640 | priv->sram_desc.last_cb_index++; | |
2641 | ||
2642 | /* Calculate the new CB control word */ | |
0edd5b44 | 2643 | if (interrupt_enabled) |
43f66a6c JK |
2644 | control |= CB_INT_ENABLED; |
2645 | ||
2646 | if (is_last) | |
2647 | control |= CB_LAST_VALID; | |
bf79451e | 2648 | |
43f66a6c JK |
2649 | control |= length; |
2650 | ||
2651 | /* Calculate the CB Element's checksum value */ | |
0edd5b44 | 2652 | cb->status = control ^ src_address ^ dest_address; |
43f66a6c JK |
2653 | |
2654 | /* Copy the Source and Destination addresses */ | |
2655 | cb->dest_addr = dest_address; | |
2656 | cb->source_addr = src_address; | |
2657 | ||
2658 | /* Copy the Control Word last */ | |
2659 | cb->control = control; | |
2660 | ||
2661 | return 0; | |
2662 | } | |
2663 | ||
2664 | static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, | |
0edd5b44 | 2665 | u32 src_phys, u32 dest_address, u32 length) |
43f66a6c JK |
2666 | { |
2667 | u32 bytes_left = length; | |
0edd5b44 JG |
2668 | u32 src_offset = 0; |
2669 | u32 dest_offset = 0; | |
43f66a6c JK |
2670 | int status = 0; |
2671 | IPW_DEBUG_FW(">> \n"); | |
2672 | IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n", | |
2673 | src_phys, dest_address, length); | |
2674 | while (bytes_left > CB_MAX_LENGTH) { | |
0edd5b44 JG |
2675 | status = ipw_fw_dma_add_command_block(priv, |
2676 | src_phys + src_offset, | |
2677 | dest_address + | |
2678 | dest_offset, | |
2679 | CB_MAX_LENGTH, 0, 0); | |
43f66a6c JK |
2680 | if (status) { |
2681 | IPW_DEBUG_FW_INFO(": Failed\n"); | |
2682 | return -1; | |
bf79451e | 2683 | } else |
43f66a6c JK |
2684 | IPW_DEBUG_FW_INFO(": Added new cb\n"); |
2685 | ||
2686 | src_offset += CB_MAX_LENGTH; | |
2687 | dest_offset += CB_MAX_LENGTH; | |
2688 | bytes_left -= CB_MAX_LENGTH; | |
2689 | } | |
2690 | ||
2691 | /* add the buffer tail */ | |
2692 | if (bytes_left > 0) { | |
0edd5b44 JG |
2693 | status = |
2694 | ipw_fw_dma_add_command_block(priv, src_phys + src_offset, | |
2695 | dest_address + dest_offset, | |
2696 | bytes_left, 0, 0); | |
43f66a6c JK |
2697 | if (status) { |
2698 | IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n"); | |
2699 | return -1; | |
bf79451e | 2700 | } else |
0edd5b44 JG |
2701 | IPW_DEBUG_FW_INFO |
2702 | (": Adding new cb - the buffer tail\n"); | |
43f66a6c | 2703 | } |
bf79451e | 2704 | |
43f66a6c JK |
2705 | IPW_DEBUG_FW("<< \n"); |
2706 | return 0; | |
2707 | } | |
2708 | ||
2709 | static int ipw_fw_dma_wait(struct ipw_priv *priv) | |
2710 | { | |
397ae121 | 2711 | u32 current_index = 0, previous_index; |
43f66a6c JK |
2712 | u32 watchdog = 0; |
2713 | ||
2714 | IPW_DEBUG_FW(">> : \n"); | |
2715 | ||
2716 | current_index = ipw_fw_dma_command_block_index(priv); | |
397ae121 | 2717 | IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n", |
0edd5b44 | 2718 | (int)priv->sram_desc.last_cb_index); |
43f66a6c JK |
2719 | |
2720 | while (current_index < priv->sram_desc.last_cb_index) { | |
2721 | udelay(50); | |
397ae121 | 2722 | previous_index = current_index; |
43f66a6c JK |
2723 | current_index = ipw_fw_dma_command_block_index(priv); |
2724 | ||
397ae121 ZY |
2725 | if (previous_index < current_index) { |
2726 | watchdog = 0; | |
2727 | continue; | |
2728 | } | |
2729 | if (++watchdog > 400) { | |
43f66a6c JK |
2730 | IPW_DEBUG_FW_INFO("Timeout\n"); |
2731 | ipw_fw_dma_dump_command_block(priv); | |
2732 | ipw_fw_dma_abort(priv); | |
2733 | return -1; | |
2734 | } | |
2735 | } | |
2736 | ||
2737 | ipw_fw_dma_abort(priv); | |
2738 | ||
0edd5b44 | 2739 | /*Disable the DMA in the CSR register */ |
b095c381 JK |
2740 | ipw_set_bit(priv, IPW_RESET_REG, |
2741 | IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER); | |
43f66a6c JK |
2742 | |
2743 | IPW_DEBUG_FW("<< dmaWaitSync \n"); | |
2744 | return 0; | |
2745 | } | |
2746 | ||
bf79451e | 2747 | static void ipw_remove_current_network(struct ipw_priv *priv) |
43f66a6c JK |
2748 | { |
2749 | struct list_head *element, *safe; | |
bf79451e | 2750 | struct ieee80211_network *network = NULL; |
a613bffd JK |
2751 | unsigned long flags; |
2752 | ||
2753 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
43f66a6c JK |
2754 | list_for_each_safe(element, safe, &priv->ieee->network_list) { |
2755 | network = list_entry(element, struct ieee80211_network, list); | |
2756 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { | |
2757 | list_del(element); | |
bf79451e | 2758 | list_add_tail(&network->list, |
43f66a6c JK |
2759 | &priv->ieee->network_free_list); |
2760 | } | |
2761 | } | |
a613bffd | 2762 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
43f66a6c JK |
2763 | } |
2764 | ||
2765 | /** | |
bf79451e | 2766 | * Check that card is still alive. |
43f66a6c JK |
2767 | * Reads debug register from domain0. |
2768 | * If card is present, pre-defined value should | |
2769 | * be found there. | |
bf79451e | 2770 | * |
43f66a6c JK |
2771 | * @param priv |
2772 | * @return 1 if card is present, 0 otherwise | |
2773 | */ | |
2774 | static inline int ipw_alive(struct ipw_priv *priv) | |
2775 | { | |
2776 | return ipw_read32(priv, 0x90) == 0xd55555d5; | |
2777 | } | |
2778 | ||
c7b6a674 | 2779 | /* timeout in msec, attempted in 10-msec quanta */ |
858119e1 | 2780 | static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask, |
43f66a6c JK |
2781 | int timeout) |
2782 | { | |
2783 | int i = 0; | |
2784 | ||
2785 | do { | |
bf79451e | 2786 | if ((ipw_read32(priv, addr) & mask) == mask) |
43f66a6c JK |
2787 | return i; |
2788 | mdelay(10); | |
2789 | i += 10; | |
2790 | } while (i < timeout); | |
bf79451e | 2791 | |
43f66a6c JK |
2792 | return -ETIME; |
2793 | } | |
2794 | ||
bf79451e | 2795 | /* These functions load the firmware and micro code for the operation of |
43f66a6c JK |
2796 | * the ipw hardware. It assumes the buffer has all the bits for the |
2797 | * image and the caller is handling the memory allocation and clean up. | |
2798 | */ | |
2799 | ||
0edd5b44 | 2800 | static int ipw_stop_master(struct ipw_priv *priv) |
43f66a6c JK |
2801 | { |
2802 | int rc; | |
bf79451e | 2803 | |
43f66a6c JK |
2804 | IPW_DEBUG_TRACE(">> \n"); |
2805 | /* stop master. typical delay - 0 */ | |
b095c381 | 2806 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
43f66a6c | 2807 | |
c7b6a674 | 2808 | /* timeout is in msec, polled in 10-msec quanta */ |
b095c381 JK |
2809 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
2810 | IPW_RESET_REG_MASTER_DISABLED, 100); | |
43f66a6c | 2811 | if (rc < 0) { |
c7b6a674 | 2812 | IPW_ERROR("wait for stop master failed after 100ms\n"); |
43f66a6c JK |
2813 | return -1; |
2814 | } | |
2815 | ||
2816 | IPW_DEBUG_INFO("stop master %dms\n", rc); | |
2817 | ||
2818 | return rc; | |
2819 | } | |
2820 | ||
2821 | static void ipw_arc_release(struct ipw_priv *priv) | |
2822 | { | |
2823 | IPW_DEBUG_TRACE(">> \n"); | |
2824 | mdelay(5); | |
2825 | ||
b095c381 | 2826 | ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
43f66a6c JK |
2827 | |
2828 | /* no one knows timing, for safety add some delay */ | |
2829 | mdelay(5); | |
2830 | } | |
2831 | ||
43f66a6c JK |
2832 | struct fw_chunk { |
2833 | u32 address; | |
2834 | u32 length; | |
2835 | }; | |
2836 | ||
0edd5b44 | 2837 | static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len) |
43f66a6c JK |
2838 | { |
2839 | int rc = 0, i, addr; | |
2840 | u8 cr = 0; | |
2841 | u16 *image; | |
2842 | ||
0edd5b44 | 2843 | image = (u16 *) data; |
bf79451e | 2844 | |
43f66a6c JK |
2845 | IPW_DEBUG_TRACE(">> \n"); |
2846 | ||
2847 | rc = ipw_stop_master(priv); | |
2848 | ||
2849 | if (rc < 0) | |
2850 | return rc; | |
bf79451e | 2851 | |
0edd5b44 | 2852 | // spin_lock_irqsave(&priv->lock, flags); |
bf79451e | 2853 | |
b095c381 JK |
2854 | for (addr = IPW_SHARED_LOWER_BOUND; |
2855 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { | |
43f66a6c JK |
2856 | ipw_write32(priv, addr, 0); |
2857 | } | |
2858 | ||
2859 | /* no ucode (yet) */ | |
2860 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); | |
2861 | /* destroy DMA queues */ | |
2862 | /* reset sequence */ | |
2863 | ||
b095c381 | 2864 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON); |
43f66a6c | 2865 | ipw_arc_release(priv); |
b095c381 | 2866 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF); |
43f66a6c JK |
2867 | mdelay(1); |
2868 | ||
2869 | /* reset PHY */ | |
b095c381 | 2870 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
43f66a6c | 2871 | mdelay(1); |
bf79451e | 2872 | |
b095c381 | 2873 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
43f66a6c | 2874 | mdelay(1); |
bf79451e | 2875 | |
43f66a6c | 2876 | /* enable ucode store */ |
c8fe6679 ZY |
2877 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
2878 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); | |
43f66a6c JK |
2879 | mdelay(1); |
2880 | ||
2881 | /* write ucode */ | |
2882 | /** | |
2883 | * @bug | |
2884 | * Do NOT set indirect address register once and then | |
2885 | * store data to indirect data register in the loop. | |
2886 | * It seems very reasonable, but in this case DINO do not | |
2887 | * accept ucode. It is essential to set address each time. | |
2888 | */ | |
2889 | /* load new ipw uCode */ | |
2890 | for (i = 0; i < len / 2; i++) | |
b095c381 | 2891 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
a613bffd | 2892 | cpu_to_le16(image[i])); |
43f66a6c | 2893 | |
43f66a6c | 2894 | /* enable DINO */ |
b095c381 JK |
2895 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
2896 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); | |
43f66a6c | 2897 | |
0edd5b44 | 2898 | /* this is where the igx / win driver deveates from the VAP driver. */ |
43f66a6c JK |
2899 | |
2900 | /* wait for alive response */ | |
2901 | for (i = 0; i < 100; i++) { | |
2902 | /* poll for incoming data */ | |
b095c381 | 2903 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
43f66a6c JK |
2904 | if (cr & DINO_RXFIFO_DATA) |
2905 | break; | |
2906 | mdelay(1); | |
2907 | } | |
2908 | ||
2909 | if (cr & DINO_RXFIFO_DATA) { | |
2910 | /* alive_command_responce size is NOT multiple of 4 */ | |
2911 | u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; | |
bf79451e JG |
2912 | |
2913 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) | |
43f66a6c | 2914 | response_buffer[i] = |
a613bffd | 2915 | le32_to_cpu(ipw_read_reg32(priv, |
b095c381 | 2916 | IPW_BASEBAND_RX_FIFO_READ)); |
43f66a6c JK |
2917 | memcpy(&priv->dino_alive, response_buffer, |
2918 | sizeof(priv->dino_alive)); | |
2919 | if (priv->dino_alive.alive_command == 1 | |
2920 | && priv->dino_alive.ucode_valid == 1) { | |
2921 | rc = 0; | |
0edd5b44 JG |
2922 | IPW_DEBUG_INFO |
2923 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " | |
2924 | "of %02d/%02d/%02d %02d:%02d\n", | |
2925 | priv->dino_alive.software_revision, | |
2926 | priv->dino_alive.software_revision, | |
2927 | priv->dino_alive.device_identifier, | |
2928 | priv->dino_alive.device_identifier, | |
2929 | priv->dino_alive.time_stamp[0], | |
2930 | priv->dino_alive.time_stamp[1], | |
2931 | priv->dino_alive.time_stamp[2], | |
2932 | priv->dino_alive.time_stamp[3], | |
2933 | priv->dino_alive.time_stamp[4]); | |
43f66a6c JK |
2934 | } else { |
2935 | IPW_DEBUG_INFO("Microcode is not alive\n"); | |
2936 | rc = -EINVAL; | |
2937 | } | |
2938 | } else { | |
2939 | IPW_DEBUG_INFO("No alive response from DINO\n"); | |
2940 | rc = -ETIME; | |
2941 | } | |
2942 | ||
2943 | /* disable DINO, otherwise for some reason | |
2944 | firmware have problem getting alive resp. */ | |
b095c381 | 2945 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
43f66a6c | 2946 | |
0edd5b44 | 2947 | // spin_unlock_irqrestore(&priv->lock, flags); |
43f66a6c JK |
2948 | |
2949 | return rc; | |
2950 | } | |
2951 | ||
0edd5b44 | 2952 | static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len) |
43f66a6c JK |
2953 | { |
2954 | int rc = -1; | |
2955 | int offset = 0; | |
2956 | struct fw_chunk *chunk; | |
2957 | dma_addr_t shared_phys; | |
2958 | u8 *shared_virt; | |
2959 | ||
2960 | IPW_DEBUG_TRACE("<< : \n"); | |
2961 | shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys); | |
2962 | ||
2963 | if (!shared_virt) | |
2964 | return -ENOMEM; | |
2965 | ||
2966 | memmove(shared_virt, data, len); | |
2967 | ||
2968 | /* Start the Dma */ | |
2969 | rc = ipw_fw_dma_enable(priv); | |
2970 | ||
2971 | if (priv->sram_desc.last_cb_index > 0) { | |
2972 | /* the DMA is already ready this would be a bug. */ | |
2973 | BUG(); | |
2974 | goto out; | |
2975 | } | |
2976 | ||
2977 | do { | |
2978 | chunk = (struct fw_chunk *)(data + offset); | |
2979 | offset += sizeof(struct fw_chunk); | |
2980 | /* build DMA packet and queue up for sending */ | |
bf79451e | 2981 | /* dma to chunk->address, the chunk->length bytes from data + |
43f66a6c JK |
2982 | * offeset*/ |
2983 | /* Dma loading */ | |
2984 | rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, | |
a613bffd JK |
2985 | le32_to_cpu(chunk->address), |
2986 | le32_to_cpu(chunk->length)); | |
43f66a6c JK |
2987 | if (rc) { |
2988 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); | |
2989 | goto out; | |
2990 | } | |
bf79451e | 2991 | |
a613bffd | 2992 | offset += le32_to_cpu(chunk->length); |
43f66a6c JK |
2993 | } while (offset < len); |
2994 | ||
0edd5b44 | 2995 | /* Run the DMA and wait for the answer */ |
43f66a6c JK |
2996 | rc = ipw_fw_dma_kick(priv); |
2997 | if (rc) { | |
2998 | IPW_ERROR("dmaKick Failed\n"); | |
2999 | goto out; | |
3000 | } | |
3001 | ||
3002 | rc = ipw_fw_dma_wait(priv); | |
3003 | if (rc) { | |
3004 | IPW_ERROR("dmaWaitSync Failed\n"); | |
3005 | goto out; | |
3006 | } | |
0edd5b44 JG |
3007 | out: |
3008 | pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys); | |
43f66a6c JK |
3009 | return rc; |
3010 | } | |
3011 | ||
3012 | /* stop nic */ | |
3013 | static int ipw_stop_nic(struct ipw_priv *priv) | |
3014 | { | |
3015 | int rc = 0; | |
3016 | ||
0edd5b44 | 3017 | /* stop */ |
b095c381 | 3018 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
bf79451e | 3019 | |
b095c381 JK |
3020 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
3021 | IPW_RESET_REG_MASTER_DISABLED, 500); | |
43f66a6c | 3022 | if (rc < 0) { |
c7b6a674 | 3023 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
43f66a6c | 3024 | return rc; |
bf79451e | 3025 | } |
43f66a6c | 3026 | |
b095c381 | 3027 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
bf79451e | 3028 | |
43f66a6c JK |
3029 | return rc; |
3030 | } | |
3031 | ||
3032 | static void ipw_start_nic(struct ipw_priv *priv) | |
3033 | { | |
3034 | IPW_DEBUG_TRACE(">>\n"); | |
3035 | ||
0edd5b44 | 3036 | /* prvHwStartNic release ARC */ |
b095c381 JK |
3037 | ipw_clear_bit(priv, IPW_RESET_REG, |
3038 | IPW_RESET_REG_MASTER_DISABLED | | |
3039 | IPW_RESET_REG_STOP_MASTER | | |
43f66a6c | 3040 | CBD_RESET_REG_PRINCETON_RESET); |
bf79451e | 3041 | |
43f66a6c | 3042 | /* enable power management */ |
b095c381 JK |
3043 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
3044 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); | |
43f66a6c JK |
3045 | |
3046 | IPW_DEBUG_TRACE("<<\n"); | |
3047 | } | |
bf79451e | 3048 | |
43f66a6c JK |
3049 | static int ipw_init_nic(struct ipw_priv *priv) |
3050 | { | |
3051 | int rc; | |
3052 | ||
3053 | IPW_DEBUG_TRACE(">>\n"); | |
bf79451e | 3054 | /* reset */ |
43f66a6c JK |
3055 | /*prvHwInitNic */ |
3056 | /* set "initialization complete" bit to move adapter to D0 state */ | |
b095c381 | 3057 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); |
43f66a6c JK |
3058 | |
3059 | /* low-level PLL activation */ | |
b095c381 JK |
3060 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
3061 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); | |
43f66a6c JK |
3062 | |
3063 | /* wait for clock stabilization */ | |
b095c381 JK |
3064 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
3065 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); | |
0edd5b44 | 3066 | if (rc < 0) |
43f66a6c JK |
3067 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
3068 | ||
3069 | /* assert SW reset */ | |
b095c381 | 3070 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
43f66a6c JK |
3071 | |
3072 | udelay(10); | |
3073 | ||
3074 | /* set "initialization complete" bit to move adapter to D0 state */ | |
b095c381 | 3075 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); |
43f66a6c JK |
3076 | |
3077 | IPW_DEBUG_TRACE(">>\n"); | |
3078 | return 0; | |
3079 | } | |
3080 | ||
bf79451e | 3081 | /* Call this function from process context, it will sleep in request_firmware. |
43f66a6c JK |
3082 | * Probe is an ok place to call this from. |
3083 | */ | |
3084 | static int ipw_reset_nic(struct ipw_priv *priv) | |
3085 | { | |
3086 | int rc = 0; | |
a613bffd | 3087 | unsigned long flags; |
43f66a6c JK |
3088 | |
3089 | IPW_DEBUG_TRACE(">>\n"); | |
bf79451e | 3090 | |
43f66a6c | 3091 | rc = ipw_init_nic(priv); |
bf79451e | 3092 | |
a613bffd | 3093 | spin_lock_irqsave(&priv->lock, flags); |
43f66a6c JK |
3094 | /* Clear the 'host command active' bit... */ |
3095 | priv->status &= ~STATUS_HCMD_ACTIVE; | |
3096 | wake_up_interruptible(&priv->wait_command_queue); | |
afbf30a2 JK |
3097 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
3098 | wake_up_interruptible(&priv->wait_state); | |
a613bffd | 3099 | spin_unlock_irqrestore(&priv->lock, flags); |
43f66a6c JK |
3100 | |
3101 | IPW_DEBUG_TRACE("<<\n"); | |
3102 | return rc; | |
bf79451e | 3103 | } |
43f66a6c | 3104 | |
9006ea75 JK |
3105 | |
3106 | struct ipw_fw { | |
3107 | u32 ver; | |
3108 | u32 boot_size; | |
3109 | u32 ucode_size; | |
3110 | u32 fw_size; | |
3111 | u8 data[0]; | |
3112 | }; | |
3113 | ||
bf79451e | 3114 | static int ipw_get_fw(struct ipw_priv *priv, |
9006ea75 | 3115 | const struct firmware **raw, const char *name) |
43f66a6c | 3116 | { |
9006ea75 | 3117 | struct ipw_fw *fw; |
43f66a6c JK |
3118 | int rc; |
3119 | ||
3120 | /* ask firmware_class module to get the boot firmware off disk */ | |
9006ea75 | 3121 | rc = request_firmware(raw, name, &priv->pci_dev->dev); |
43f66a6c | 3122 | if (rc < 0) { |
9006ea75 | 3123 | IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc); |
43f66a6c | 3124 | return rc; |
bf79451e | 3125 | } |
43f66a6c | 3126 | |
9006ea75 JK |
3127 | if ((*raw)->size < sizeof(*fw)) { |
3128 | IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size); | |
3129 | return -EINVAL; | |
3130 | } | |
3131 | ||
3132 | fw = (void *)(*raw)->data; | |
3133 | ||
3134 | if ((*raw)->size < sizeof(*fw) + | |
3135 | fw->boot_size + fw->ucode_size + fw->fw_size) { | |
3136 | IPW_ERROR("%s is too small or corrupt (%zd)\n", | |
3137 | name, (*raw)->size); | |
43f66a6c JK |
3138 | return -EINVAL; |
3139 | } | |
3140 | ||
9006ea75 | 3141 | IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n", |
43f66a6c | 3142 | name, |
9006ea75 JK |
3143 | le32_to_cpu(fw->ver) >> 16, |
3144 | le32_to_cpu(fw->ver) & 0xff, | |
3145 | (*raw)->size - sizeof(*fw)); | |
43f66a6c JK |
3146 | return 0; |
3147 | } | |
3148 | ||
b095c381 | 3149 | #define IPW_RX_BUF_SIZE (3000) |
43f66a6c | 3150 | |
858119e1 | 3151 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
43f66a6c JK |
3152 | struct ipw_rx_queue *rxq) |
3153 | { | |
3154 | unsigned long flags; | |
3155 | int i; | |
3156 | ||
3157 | spin_lock_irqsave(&rxq->lock, flags); | |
3158 | ||
3159 | INIT_LIST_HEAD(&rxq->rx_free); | |
3160 | INIT_LIST_HEAD(&rxq->rx_used); | |
3161 | ||
3162 | /* Fill the rx_used queue with _all_ of the Rx buffers */ | |
3163 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { | |
3164 | /* In the reset function, these buffers may have been allocated | |
3165 | * to an SKB, so we need to unmap and free potential storage */ | |
3166 | if (rxq->pool[i].skb != NULL) { | |
3167 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, | |
b095c381 | 3168 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
43f66a6c | 3169 | dev_kfree_skb(rxq->pool[i].skb); |
a613bffd | 3170 | rxq->pool[i].skb = NULL; |
43f66a6c JK |
3171 | } |
3172 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); | |
3173 | } | |
bf79451e | 3174 | |
43f66a6c JK |
3175 | /* Set us so that we have processed and used all buffers, but have |
3176 | * not restocked the Rx queue with fresh buffers */ | |
3177 | rxq->read = rxq->write = 0; | |
3178 | rxq->processed = RX_QUEUE_SIZE - 1; | |
3179 | rxq->free_count = 0; | |
3180 | spin_unlock_irqrestore(&rxq->lock, flags); | |
3181 | } | |
3182 | ||
3183 | #ifdef CONFIG_PM | |
3184 | static int fw_loaded = 0; | |
9006ea75 | 3185 | static const struct firmware *raw = NULL; |
afbf30a2 JK |
3186 | |
3187 | static void free_firmware(void) | |
3188 | { | |
3189 | if (fw_loaded) { | |
9006ea75 JK |
3190 | release_firmware(raw); |
3191 | raw = NULL; | |
afbf30a2 JK |
3192 | fw_loaded = 0; |
3193 | } | |
3194 | } | |
3195 | #else | |
3196 | #define free_firmware() do {} while (0) | |
43f66a6c JK |
3197 | #endif |
3198 | ||
3199 | static int ipw_load(struct ipw_priv *priv) | |
3200 | { | |
3201 | #ifndef CONFIG_PM | |
9006ea75 | 3202 | const struct firmware *raw = NULL; |
43f66a6c | 3203 | #endif |
9006ea75 JK |
3204 | struct ipw_fw *fw; |
3205 | u8 *boot_img, *ucode_img, *fw_img; | |
3206 | u8 *name = NULL; | |
43f66a6c JK |
3207 | int rc = 0, retries = 3; |
3208 | ||
397ae121 ZY |
3209 | switch (priv->ieee->iw_mode) { |
3210 | case IW_MODE_ADHOC: | |
9006ea75 | 3211 | name = "ipw2200-ibss.fw"; |
397ae121 | 3212 | break; |
b095c381 | 3213 | #ifdef CONFIG_IPW2200_MONITOR |
397ae121 | 3214 | case IW_MODE_MONITOR: |
9006ea75 | 3215 | name = "ipw2200-sniffer.fw"; |
397ae121 | 3216 | break; |
43f66a6c | 3217 | #endif |
397ae121 | 3218 | case IW_MODE_INFRA: |
9006ea75 | 3219 | name = "ipw2200-bss.fw"; |
397ae121 | 3220 | break; |
9006ea75 JK |
3221 | } |
3222 | ||
3223 | if (!name) { | |
397ae121 | 3224 | rc = -EINVAL; |
9006ea75 JK |
3225 | goto error; |
3226 | } | |
3227 | ||
3228 | #ifdef CONFIG_PM | |
3229 | if (!fw_loaded) { | |
3230 | #endif | |
3231 | rc = ipw_get_fw(priv, &raw, name); | |
3232 | if (rc < 0) | |
3233 | goto error; | |
3234 | #ifdef CONFIG_PM | |
43f66a6c | 3235 | } |
9006ea75 JK |
3236 | #endif |
3237 | ||
3238 | fw = (void *)raw->data; | |
3239 | boot_img = &fw->data[0]; | |
3240 | ucode_img = &fw->data[fw->boot_size]; | |
3241 | fw_img = &fw->data[fw->boot_size + fw->ucode_size]; | |
397ae121 ZY |
3242 | |
3243 | if (rc < 0) | |
3244 | goto error; | |
43f66a6c JK |
3245 | |
3246 | if (!priv->rxq) | |
3247 | priv->rxq = ipw_rx_queue_alloc(priv); | |
3248 | else | |
3249 | ipw_rx_queue_reset(priv, priv->rxq); | |
3250 | if (!priv->rxq) { | |
3251 | IPW_ERROR("Unable to initialize Rx queue\n"); | |
3252 | goto error; | |
3253 | } | |
3254 | ||
0edd5b44 | 3255 | retry: |
43f66a6c | 3256 | /* Ensure interrupts are disabled */ |
b095c381 | 3257 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
43f66a6c JK |
3258 | priv->status &= ~STATUS_INT_ENABLED; |
3259 | ||
3260 | /* ack pending interrupts */ | |
b095c381 | 3261 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
bf79451e | 3262 | |
43f66a6c JK |
3263 | ipw_stop_nic(priv); |
3264 | ||
3265 | rc = ipw_reset_nic(priv); | |
397ae121 | 3266 | if (rc < 0) { |
43f66a6c JK |
3267 | IPW_ERROR("Unable to reset NIC\n"); |
3268 | goto error; | |
3269 | } | |
3270 | ||
b095c381 JK |
3271 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
3272 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); | |
43f66a6c JK |
3273 | |
3274 | /* DMA the initial boot firmware into the device */ | |
9006ea75 | 3275 | rc = ipw_load_firmware(priv, boot_img, fw->boot_size); |
43f66a6c | 3276 | if (rc < 0) { |
a4f6bbb3 | 3277 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
43f66a6c JK |
3278 | goto error; |
3279 | } | |
3280 | ||
3281 | /* kick start the device */ | |
3282 | ipw_start_nic(priv); | |
3283 | ||
c7b6a674 | 3284 | /* wait for the device to finish its initial startup sequence */ |
b095c381 JK |
3285 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
3286 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); | |
43f66a6c JK |
3287 | if (rc < 0) { |
3288 | IPW_ERROR("device failed to boot initial fw image\n"); | |
3289 | goto error; | |
3290 | } | |
3291 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); | |
3292 | ||
bf79451e | 3293 | /* ack fw init done interrupt */ |
b095c381 | 3294 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
43f66a6c JK |
3295 | |
3296 | /* DMA the ucode into the device */ | |
9006ea75 | 3297 | rc = ipw_load_ucode(priv, ucode_img, fw->ucode_size); |
43f66a6c | 3298 | if (rc < 0) { |
a4f6bbb3 | 3299 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
43f66a6c JK |
3300 | goto error; |
3301 | } | |
bf79451e | 3302 | |
43f66a6c JK |
3303 | /* stop nic */ |
3304 | ipw_stop_nic(priv); | |
3305 | ||
3306 | /* DMA bss firmware into the device */ | |
9006ea75 | 3307 | rc = ipw_load_firmware(priv, fw_img, fw->fw_size); |
0edd5b44 | 3308 | if (rc < 0) { |
a4f6bbb3 | 3309 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
43f66a6c JK |
3310 | goto error; |
3311 | } | |
397ae121 ZY |
3312 | #ifdef CONFIG_PM |
3313 | fw_loaded = 1; | |
3314 | #endif | |
3315 | ||
43f66a6c JK |
3316 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
3317 | ||
3318 | rc = ipw_queue_reset(priv); | |
397ae121 | 3319 | if (rc < 0) { |
43f66a6c JK |
3320 | IPW_ERROR("Unable to initialize queues\n"); |
3321 | goto error; | |
3322 | } | |
3323 | ||
3324 | /* Ensure interrupts are disabled */ | |
b095c381 | 3325 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
c848d0af | 3326 | /* ack pending interrupts */ |
b095c381 | 3327 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
bf79451e | 3328 | |
43f66a6c JK |
3329 | /* kick start the device */ |
3330 | ipw_start_nic(priv); | |
3331 | ||
b095c381 | 3332 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
43f66a6c JK |
3333 | if (retries > 0) { |
3334 | IPW_WARNING("Parity error. Retrying init.\n"); | |
3335 | retries--; | |
3336 | goto retry; | |
3337 | } | |
3338 | ||
3339 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); | |
3340 | rc = -EIO; | |
3341 | goto error; | |
3342 | } | |
3343 | ||
3344 | /* wait for the device */ | |
b095c381 JK |
3345 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
3346 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); | |
43f66a6c | 3347 | if (rc < 0) { |
c7b6a674 | 3348 | IPW_ERROR("device failed to start within 500ms\n"); |
43f66a6c JK |
3349 | goto error; |
3350 | } | |
3351 | IPW_DEBUG_INFO("device response after %dms\n", rc); | |
3352 | ||
3353 | /* ack fw init done interrupt */ | |
b095c381 | 3354 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
43f66a6c JK |
3355 | |
3356 | /* read eeprom data and initialize the eeprom region of sram */ | |
3357 | priv->eeprom_delay = 1; | |
bf79451e | 3358 | ipw_eeprom_init_sram(priv); |
43f66a6c JK |
3359 | |
3360 | /* enable interrupts */ | |
3361 | ipw_enable_interrupts(priv); | |
3362 | ||
3363 | /* Ensure our queue has valid packets */ | |
3364 | ipw_rx_queue_replenish(priv); | |
3365 | ||
b095c381 | 3366 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
43f66a6c JK |
3367 | |
3368 | /* ack pending interrupts */ | |
b095c381 | 3369 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
43f66a6c JK |
3370 | |
3371 | #ifndef CONFIG_PM | |
9006ea75 | 3372 | release_firmware(raw); |
43f66a6c JK |
3373 | #endif |
3374 | return 0; | |
3375 | ||
0edd5b44 | 3376 | error: |
43f66a6c JK |
3377 | if (priv->rxq) { |
3378 | ipw_rx_queue_free(priv, priv->rxq); | |
3379 | priv->rxq = NULL; | |
3380 | } | |
3381 | ipw_tx_queue_free(priv); | |
9006ea75 JK |
3382 | if (raw) |
3383 | release_firmware(raw); | |
43f66a6c JK |
3384 | #ifdef CONFIG_PM |
3385 | fw_loaded = 0; | |
9006ea75 | 3386 | raw = NULL; |
43f66a6c JK |
3387 | #endif |
3388 | ||
3389 | return rc; | |
3390 | } | |
3391 | ||
bf79451e | 3392 | /** |
43f66a6c JK |
3393 | * DMA services |
3394 | * | |
3395 | * Theory of operation | |
3396 | * | |
3397 | * A queue is a circular buffers with 'Read' and 'Write' pointers. | |
3398 | * 2 empty entries always kept in the buffer to protect from overflow. | |
3399 | * | |
3400 | * For Tx queue, there are low mark and high mark limits. If, after queuing | |
bf79451e JG |
3401 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
3402 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, | |
43f66a6c JK |
3403 | * Tx queue resumed. |
3404 | * | |
3405 | * The IPW operates with six queues, one receive queue in the device's | |
3406 | * sram, one transmit queue for sending commands to the device firmware, | |
bf79451e | 3407 | * and four transmit queues for data. |
43f66a6c | 3408 | * |
bf79451e | 3409 | * The four transmit queues allow for performing quality of service (qos) |
43f66a6c | 3410 | * transmissions as per the 802.11 protocol. Currently Linux does not |
bf79451e | 3411 | * provide a mechanism to the user for utilizing prioritized queues, so |
43f66a6c JK |
3412 | * we only utilize the first data transmit queue (queue1). |
3413 | */ | |
3414 | ||
3415 | /** | |
3416 | * Driver allocates buffers of this size for Rx | |
3417 | */ | |
3418 | ||
3419 | static inline int ipw_queue_space(const struct clx2_queue *q) | |
3420 | { | |
3421 | int s = q->last_used - q->first_empty; | |
3422 | if (s <= 0) | |
3423 | s += q->n_bd; | |
3424 | s -= 2; /* keep some reserve to not confuse empty and full situations */ | |
3425 | if (s < 0) | |
3426 | s = 0; | |
3427 | return s; | |
3428 | } | |
3429 | ||
3430 | static inline int ipw_queue_inc_wrap(int index, int n_bd) | |
3431 | { | |
3432 | return (++index == n_bd) ? 0 : index; | |
3433 | } | |
3434 | ||
3435 | /** | |
3436 | * Initialize common DMA queue structure | |
bf79451e | 3437 | * |
43f66a6c JK |
3438 | * @param q queue to init |
3439 | * @param count Number of BD's to allocate. Should be power of 2 | |
3440 | * @param read_register Address for 'read' register | |
3441 | * (not offset within BAR, full address) | |
3442 | * @param write_register Address for 'write' register | |
3443 | * (not offset within BAR, full address) | |
3444 | * @param base_register Address for 'base' register | |
3445 | * (not offset within BAR, full address) | |
3446 | * @param size Address for 'size' register | |
3447 | * (not offset within BAR, full address) | |
3448 | */ | |
bf79451e | 3449 | static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q, |
0edd5b44 | 3450 | int count, u32 read, u32 write, u32 base, u32 size) |
43f66a6c JK |
3451 | { |
3452 | q->n_bd = count; | |
3453 | ||
3454 | q->low_mark = q->n_bd / 4; | |
3455 | if (q->low_mark < 4) | |
3456 | q->low_mark = 4; | |
3457 | ||
3458 | q->high_mark = q->n_bd / 8; | |
3459 | if (q->high_mark < 2) | |
3460 | q->high_mark = 2; | |
3461 | ||
3462 | q->first_empty = q->last_used = 0; | |
3463 | q->reg_r = read; | |
3464 | q->reg_w = write; | |
3465 | ||
3466 | ipw_write32(priv, base, q->dma_addr); | |
3467 | ipw_write32(priv, size, count); | |
3468 | ipw_write32(priv, read, 0); | |
3469 | ipw_write32(priv, write, 0); | |
3470 | ||
3471 | _ipw_read32(priv, 0x90); | |
3472 | } | |
3473 | ||
bf79451e | 3474 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
43f66a6c | 3475 | struct clx2_tx_queue *q, |
0edd5b44 | 3476 | int count, u32 read, u32 write, u32 base, u32 size) |
43f66a6c JK |
3477 | { |
3478 | struct pci_dev *dev = priv->pci_dev; | |
3479 | ||
3480 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); | |
3481 | if (!q->txb) { | |
3482 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); | |
3483 | return -ENOMEM; | |
3484 | } | |
3485 | ||
0edd5b44 JG |
3486 | q->bd = |
3487 | pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr); | |
43f66a6c | 3488 | if (!q->bd) { |
aaa4d308 | 3489 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
0edd5b44 | 3490 | sizeof(q->bd[0]) * count); |
43f66a6c JK |
3491 | kfree(q->txb); |
3492 | q->txb = NULL; | |
3493 | return -ENOMEM; | |
3494 | } | |
3495 | ||
3496 | ipw_queue_init(priv, &q->q, count, read, write, base, size); | |
3497 | return 0; | |
3498 | } | |
3499 | ||
3500 | /** | |
3501 | * Free one TFD, those at index [txq->q.last_used]. | |
3502 | * Do NOT advance any indexes | |
bf79451e | 3503 | * |
43f66a6c JK |
3504 | * @param dev |
3505 | * @param txq | |
3506 | */ | |
3507 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, | |
3508 | struct clx2_tx_queue *txq) | |
3509 | { | |
3510 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; | |
3511 | struct pci_dev *dev = priv->pci_dev; | |
3512 | int i; | |
bf79451e | 3513 | |
43f66a6c JK |
3514 | /* classify bd */ |
3515 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) | |
3516 | /* nothing to cleanup after for host commands */ | |
3517 | return; | |
3518 | ||
3519 | /* sanity check */ | |
a613bffd JK |
3520 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
3521 | IPW_ERROR("Too many chunks: %i\n", | |
3522 | le32_to_cpu(bd->u.data.num_chunks)); | |
43f66a6c JK |
3523 | /** @todo issue fatal error, it is quite serious situation */ |
3524 | return; | |
3525 | } | |
3526 | ||
3527 | /* unmap chunks if any */ | |
a613bffd JK |
3528 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
3529 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), | |
3530 | le16_to_cpu(bd->u.data.chunk_len[i]), | |
3531 | PCI_DMA_TODEVICE); | |
43f66a6c JK |
3532 | if (txq->txb[txq->q.last_used]) { |
3533 | ieee80211_txb_free(txq->txb[txq->q.last_used]); | |
3534 | txq->txb[txq->q.last_used] = NULL; | |
3535 | } | |
3536 | } | |
3537 | } | |
3538 | ||
3539 | /** | |
3540 | * Deallocate DMA queue. | |
bf79451e | 3541 | * |
43f66a6c JK |
3542 | * Empty queue by removing and destroying all BD's. |
3543 | * Free all buffers. | |
bf79451e | 3544 | * |
43f66a6c JK |
3545 | * @param dev |
3546 | * @param q | |
3547 | */ | |
0edd5b44 | 3548 | static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq) |
43f66a6c JK |
3549 | { |
3550 | struct clx2_queue *q = &txq->q; | |
3551 | struct pci_dev *dev = priv->pci_dev; | |
3552 | ||
bf79451e JG |
3553 | if (q->n_bd == 0) |
3554 | return; | |
43f66a6c JK |
3555 | |
3556 | /* first, empty all BD's */ | |
3557 | for (; q->first_empty != q->last_used; | |
3558 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { | |
3559 | ipw_queue_tx_free_tfd(priv, txq); | |
3560 | } | |
bf79451e | 3561 | |
43f66a6c | 3562 | /* free buffers belonging to queue itself */ |
0edd5b44 | 3563 | pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd, |
43f66a6c JK |
3564 | q->dma_addr); |
3565 | kfree(txq->txb); | |
3566 | ||
3567 | /* 0 fill whole structure */ | |
3568 | memset(txq, 0, sizeof(*txq)); | |
3569 | } | |
3570 | ||
43f66a6c JK |
3571 | /** |
3572 | * Destroy all DMA queues and structures | |
bf79451e | 3573 | * |
43f66a6c JK |
3574 | * @param priv |
3575 | */ | |
3576 | static void ipw_tx_queue_free(struct ipw_priv *priv) | |
3577 | { | |
3578 | /* Tx CMD queue */ | |
3579 | ipw_queue_tx_free(priv, &priv->txq_cmd); | |
3580 | ||
3581 | /* Tx queues */ | |
3582 | ipw_queue_tx_free(priv, &priv->txq[0]); | |
3583 | ipw_queue_tx_free(priv, &priv->txq[1]); | |
3584 | ipw_queue_tx_free(priv, &priv->txq[2]); | |
3585 | ipw_queue_tx_free(priv, &priv->txq[3]); | |
3586 | } | |
3587 | ||
858119e1 | 3588 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
43f66a6c JK |
3589 | { |
3590 | /* First 3 bytes are manufacturer */ | |
3591 | bssid[0] = priv->mac_addr[0]; | |
3592 | bssid[1] = priv->mac_addr[1]; | |
3593 | bssid[2] = priv->mac_addr[2]; | |
3594 | ||
3595 | /* Last bytes are random */ | |
0edd5b44 | 3596 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
43f66a6c | 3597 | |
0edd5b44 JG |
3598 | bssid[0] &= 0xfe; /* clear multicast bit */ |
3599 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ | |
43f66a6c JK |
3600 | } |
3601 | ||
858119e1 | 3602 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
43f66a6c JK |
3603 | { |
3604 | struct ipw_station_entry entry; | |
3605 | int i; | |
3606 | ||
3607 | for (i = 0; i < priv->num_stations; i++) { | |
3608 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { | |
3609 | /* Another node is active in network */ | |
3610 | priv->missed_adhoc_beacons = 0; | |
3611 | if (!(priv->config & CFG_STATIC_CHANNEL)) | |
3612 | /* when other nodes drop out, we drop out */ | |
3613 | priv->config &= ~CFG_ADHOC_PERSIST; | |
3614 | ||
3615 | return i; | |
3616 | } | |
3617 | } | |
3618 | ||
3619 | if (i == MAX_STATIONS) | |
3620 | return IPW_INVALID_STATION; | |
3621 | ||
3622 | IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid)); | |
3623 | ||
3624 | entry.reserved = 0; | |
3625 | entry.support_mode = 0; | |
3626 | memcpy(entry.mac_addr, bssid, ETH_ALEN); | |
3627 | memcpy(priv->stations[i], bssid, ETH_ALEN); | |
3628 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), | |
0edd5b44 | 3629 | &entry, sizeof(entry)); |
43f66a6c JK |
3630 | priv->num_stations++; |
3631 | ||
3632 | return i; | |
3633 | } | |
3634 | ||
858119e1 | 3635 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
43f66a6c JK |
3636 | { |
3637 | int i; | |
3638 | ||
bf79451e JG |
3639 | for (i = 0; i < priv->num_stations; i++) |
3640 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) | |
43f66a6c JK |
3641 | return i; |
3642 | ||
3643 | return IPW_INVALID_STATION; | |
3644 | } | |
3645 | ||
3646 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) | |
3647 | { | |
3648 | int err; | |
3649 | ||
7b99659f HL |
3650 | if (priv->status & STATUS_ASSOCIATING) { |
3651 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); | |
3652 | queue_work(priv->workqueue, &priv->disassociate); | |
3653 | return; | |
3654 | } | |
3655 | ||
3656 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
43f66a6c JK |
3657 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
3658 | return; | |
3659 | } | |
3660 | ||
3661 | IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " " | |
3662 | "on channel %d.\n", | |
bf79451e | 3663 | MAC_ARG(priv->assoc_request.bssid), |
43f66a6c JK |
3664 | priv->assoc_request.channel); |
3665 | ||
3666 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); | |
3667 | priv->status |= STATUS_DISASSOCIATING; | |
3668 | ||
3669 | if (quiet) | |
3670 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; | |
3671 | else | |
3672 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; | |
e6324726 | 3673 | |
43f66a6c JK |
3674 | err = ipw_send_associate(priv, &priv->assoc_request); |
3675 | if (err) { | |
3676 | IPW_DEBUG_HC("Attempt to send [dis]associate command " | |
3677 | "failed.\n"); | |
3678 | return; | |
3679 | } | |
3680 | ||
3681 | } | |
3682 | ||
c848d0af | 3683 | static int ipw_disassociate(void *data) |
43f66a6c | 3684 | { |
c848d0af JK |
3685 | struct ipw_priv *priv = data; |
3686 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) | |
3687 | return 0; | |
43f66a6c | 3688 | ipw_send_disassociate(data, 0); |
c848d0af | 3689 | return 1; |
43f66a6c JK |
3690 | } |
3691 | ||
c848d0af | 3692 | static void ipw_bg_disassociate(void *data) |
43f66a6c | 3693 | { |
c848d0af | 3694 | struct ipw_priv *priv = data; |
4644151b | 3695 | mutex_lock(&priv->mutex); |
c848d0af | 3696 | ipw_disassociate(data); |
4644151b | 3697 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
3698 | } |
3699 | ||
d8bad6df ZY |
3700 | static void ipw_system_config(void *data) |
3701 | { | |
3702 | struct ipw_priv *priv = data; | |
3703 | ipw_send_system_config(priv, &priv->sys_config); | |
43f66a6c JK |
3704 | } |
3705 | ||
3706 | struct ipw_status_code { | |
3707 | u16 status; | |
3708 | const char *reason; | |
3709 | }; | |
3710 | ||
3711 | static const struct ipw_status_code ipw_status_codes[] = { | |
3712 | {0x00, "Successful"}, | |
3713 | {0x01, "Unspecified failure"}, | |
3714 | {0x0A, "Cannot support all requested capabilities in the " | |
3715 | "Capability information field"}, | |
3716 | {0x0B, "Reassociation denied due to inability to confirm that " | |
3717 | "association exists"}, | |
3718 | {0x0C, "Association denied due to reason outside the scope of this " | |
3719 | "standard"}, | |
0edd5b44 JG |
3720 | {0x0D, |
3721 | "Responding station does not support the specified authentication " | |
43f66a6c | 3722 | "algorithm"}, |
0edd5b44 JG |
3723 | {0x0E, |
3724 | "Received an Authentication frame with authentication sequence " | |
43f66a6c JK |
3725 | "transaction sequence number out of expected sequence"}, |
3726 | {0x0F, "Authentication rejected because of challenge failure"}, | |
3727 | {0x10, "Authentication rejected due to timeout waiting for next " | |
3728 | "frame in sequence"}, | |
3729 | {0x11, "Association denied because AP is unable to handle additional " | |
3730 | "associated stations"}, | |
0edd5b44 JG |
3731 | {0x12, |
3732 | "Association denied due to requesting station not supporting all " | |
43f66a6c | 3733 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
0edd5b44 JG |
3734 | {0x13, |
3735 | "Association denied due to requesting station not supporting " | |
43f66a6c | 3736 | "short preamble operation"}, |
0edd5b44 JG |
3737 | {0x14, |
3738 | "Association denied due to requesting station not supporting " | |
43f66a6c | 3739 | "PBCC encoding"}, |
0edd5b44 JG |
3740 | {0x15, |
3741 | "Association denied due to requesting station not supporting " | |
43f66a6c | 3742 | "channel agility"}, |
0edd5b44 JG |
3743 | {0x19, |
3744 | "Association denied due to requesting station not supporting " | |
43f66a6c | 3745 | "short slot operation"}, |
0edd5b44 JG |
3746 | {0x1A, |
3747 | "Association denied due to requesting station not supporting " | |
43f66a6c JK |
3748 | "DSSS-OFDM operation"}, |
3749 | {0x28, "Invalid Information Element"}, | |
3750 | {0x29, "Group Cipher is not valid"}, | |
3751 | {0x2A, "Pairwise Cipher is not valid"}, | |
3752 | {0x2B, "AKMP is not valid"}, | |
3753 | {0x2C, "Unsupported RSN IE version"}, | |
3754 | {0x2D, "Invalid RSN IE Capabilities"}, | |
3755 | {0x2E, "Cipher suite is rejected per security policy"}, | |
3756 | }; | |
3757 | ||
0f52bf90 | 3758 | #ifdef CONFIG_IPW2200_DEBUG |
bf79451e | 3759 | static const char *ipw_get_status_code(u16 status) |
43f66a6c JK |
3760 | { |
3761 | int i; | |
bf79451e | 3762 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
ea2b26e0 | 3763 | if (ipw_status_codes[i].status == (status & 0xff)) |
43f66a6c JK |
3764 | return ipw_status_codes[i].reason; |
3765 | return "Unknown status value."; | |
3766 | } | |
3767 | #endif | |
3768 | ||
3769 | static void inline average_init(struct average *avg) | |
3770 | { | |
3771 | memset(avg, 0, sizeof(*avg)); | |
3772 | } | |
3773 | ||
858119e1 | 3774 | static void average_add(struct average *avg, s16 val) |
43f66a6c JK |
3775 | { |
3776 | avg->sum -= avg->entries[avg->pos]; | |
3777 | avg->sum += val; | |
3778 | avg->entries[avg->pos++] = val; | |
3779 | if (unlikely(avg->pos == AVG_ENTRIES)) { | |
3780 | avg->init = 1; | |
3781 | avg->pos = 0; | |
3782 | } | |
3783 | } | |
3784 | ||
858119e1 | 3785 | static s16 average_value(struct average *avg) |
43f66a6c JK |
3786 | { |
3787 | if (!unlikely(avg->init)) { | |
3788 | if (avg->pos) | |
3789 | return avg->sum / avg->pos; | |
3790 | return 0; | |
3791 | } | |
3792 | ||
3793 | return avg->sum / AVG_ENTRIES; | |
3794 | } | |
3795 | ||
3796 | static void ipw_reset_stats(struct ipw_priv *priv) | |
3797 | { | |
3798 | u32 len = sizeof(u32); | |
3799 | ||
3800 | priv->quality = 0; | |
3801 | ||
3802 | average_init(&priv->average_missed_beacons); | |
3803 | average_init(&priv->average_rssi); | |
3804 | average_init(&priv->average_noise); | |
3805 | ||
3806 | priv->last_rate = 0; | |
3807 | priv->last_missed_beacons = 0; | |
3808 | priv->last_rx_packets = 0; | |
3809 | priv->last_tx_packets = 0; | |
3810 | priv->last_tx_failures = 0; | |
bf79451e | 3811 | |
43f66a6c JK |
3812 | /* Firmware managed, reset only when NIC is restarted, so we have to |
3813 | * normalize on the current value */ | |
bf79451e | 3814 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
43f66a6c | 3815 | &priv->last_rx_err, &len); |
bf79451e | 3816 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
43f66a6c JK |
3817 | &priv->last_tx_failures, &len); |
3818 | ||
3819 | /* Driver managed, reset with each association */ | |
3820 | priv->missed_adhoc_beacons = 0; | |
3821 | priv->missed_beacons = 0; | |
3822 | priv->tx_packets = 0; | |
3823 | priv->rx_packets = 0; | |
3824 | ||
3825 | } | |
3826 | ||
858119e1 | 3827 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
43f66a6c JK |
3828 | { |
3829 | u32 i = 0x80000000; | |
3830 | u32 mask = priv->rates_mask; | |
3831 | /* If currently associated in B mode, restrict the maximum | |
3832 | * rate match to B rates */ | |
3833 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) | |
3834 | mask &= IEEE80211_CCK_RATES_MASK; | |
3835 | ||
3836 | /* TODO: Verify that the rate is supported by the current rates | |
3837 | * list. */ | |
3838 | ||
0edd5b44 JG |
3839 | while (i && !(mask & i)) |
3840 | i >>= 1; | |
43f66a6c | 3841 | switch (i) { |
ea2b26e0 JK |
3842 | case IEEE80211_CCK_RATE_1MB_MASK: |
3843 | return 1000000; | |
3844 | case IEEE80211_CCK_RATE_2MB_MASK: | |
3845 | return 2000000; | |
3846 | case IEEE80211_CCK_RATE_5MB_MASK: | |
3847 | return 5500000; | |
3848 | case IEEE80211_OFDM_RATE_6MB_MASK: | |
3849 | return 6000000; | |
3850 | case IEEE80211_OFDM_RATE_9MB_MASK: | |
3851 | return 9000000; | |
3852 | case IEEE80211_CCK_RATE_11MB_MASK: | |
3853 | return 11000000; | |
3854 | case IEEE80211_OFDM_RATE_12MB_MASK: | |
3855 | return 12000000; | |
3856 | case IEEE80211_OFDM_RATE_18MB_MASK: | |
3857 | return 18000000; | |
3858 | case IEEE80211_OFDM_RATE_24MB_MASK: | |
3859 | return 24000000; | |
3860 | case IEEE80211_OFDM_RATE_36MB_MASK: | |
3861 | return 36000000; | |
3862 | case IEEE80211_OFDM_RATE_48MB_MASK: | |
3863 | return 48000000; | |
3864 | case IEEE80211_OFDM_RATE_54MB_MASK: | |
3865 | return 54000000; | |
43f66a6c JK |
3866 | } |
3867 | ||
bf79451e | 3868 | if (priv->ieee->mode == IEEE_B) |
43f66a6c JK |
3869 | return 11000000; |
3870 | else | |
3871 | return 54000000; | |
3872 | } | |
3873 | ||
3874 | static u32 ipw_get_current_rate(struct ipw_priv *priv) | |
3875 | { | |
3876 | u32 rate, len = sizeof(rate); | |
3877 | int err; | |
3878 | ||
bf79451e | 3879 | if (!(priv->status & STATUS_ASSOCIATED)) |
43f66a6c JK |
3880 | return 0; |
3881 | ||
3882 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { | |
bf79451e | 3883 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
43f66a6c JK |
3884 | &len); |
3885 | if (err) { | |
3886 | IPW_DEBUG_INFO("failed querying ordinals.\n"); | |
3887 | return 0; | |
3888 | } | |
bf79451e | 3889 | } else |
43f66a6c JK |
3890 | return ipw_get_max_rate(priv); |
3891 | ||
3892 | switch (rate) { | |
ea2b26e0 JK |
3893 | case IPW_TX_RATE_1MB: |
3894 | return 1000000; | |
3895 | case IPW_TX_RATE_2MB: | |
3896 | return 2000000; | |
3897 | case IPW_TX_RATE_5MB: | |
3898 | return 5500000; | |
3899 | case IPW_TX_RATE_6MB: | |
3900 | return 6000000; | |
3901 | case IPW_TX_RATE_9MB: | |
3902 | return 9000000; | |
3903 | case IPW_TX_RATE_11MB: | |
3904 | return 11000000; | |
3905 | case IPW_TX_RATE_12MB: | |
3906 | return 12000000; | |
3907 | case IPW_TX_RATE_18MB: | |
3908 | return 18000000; | |
3909 | case IPW_TX_RATE_24MB: | |
3910 | return 24000000; | |
3911 | case IPW_TX_RATE_36MB: | |
3912 | return 36000000; | |
3913 | case IPW_TX_RATE_48MB: | |
3914 | return 48000000; | |
3915 | case IPW_TX_RATE_54MB: | |
3916 | return 54000000; | |
43f66a6c JK |
3917 | } |
3918 | ||
3919 | return 0; | |
3920 | } | |
3921 | ||
43f66a6c JK |
3922 | #define IPW_STATS_INTERVAL (2 * HZ) |
3923 | static void ipw_gather_stats(struct ipw_priv *priv) | |
3924 | { | |
3925 | u32 rx_err, rx_err_delta, rx_packets_delta; | |
3926 | u32 tx_failures, tx_failures_delta, tx_packets_delta; | |
3927 | u32 missed_beacons_percent, missed_beacons_delta; | |
3928 | u32 quality = 0; | |
3929 | u32 len = sizeof(u32); | |
3930 | s16 rssi; | |
bf79451e | 3931 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
0edd5b44 | 3932 | rate_quality; |
ea2b26e0 | 3933 | u32 max_rate; |
43f66a6c JK |
3934 | |
3935 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
3936 | priv->quality = 0; | |
3937 | return; | |
3938 | } | |
3939 | ||
3940 | /* Update the statistics */ | |
bf79451e | 3941 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
43f66a6c | 3942 | &priv->missed_beacons, &len); |
0edd5b44 | 3943 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
43f66a6c JK |
3944 | priv->last_missed_beacons = priv->missed_beacons; |
3945 | if (priv->assoc_request.beacon_interval) { | |
3946 | missed_beacons_percent = missed_beacons_delta * | |
0edd5b44 JG |
3947 | (HZ * priv->assoc_request.beacon_interval) / |
3948 | (IPW_STATS_INTERVAL * 10); | |
43f66a6c JK |
3949 | } else { |
3950 | missed_beacons_percent = 0; | |
3951 | } | |
3952 | average_add(&priv->average_missed_beacons, missed_beacons_percent); | |
3953 | ||
3954 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); | |
3955 | rx_err_delta = rx_err - priv->last_rx_err; | |
3956 | priv->last_rx_err = rx_err; | |
3957 | ||
3958 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); | |
3959 | tx_failures_delta = tx_failures - priv->last_tx_failures; | |
3960 | priv->last_tx_failures = tx_failures; | |
3961 | ||
3962 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; | |
3963 | priv->last_rx_packets = priv->rx_packets; | |
3964 | ||
3965 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; | |
3966 | priv->last_tx_packets = priv->tx_packets; | |
3967 | ||
3968 | /* Calculate quality based on the following: | |
bf79451e | 3969 | * |
43f66a6c JK |
3970 | * Missed beacon: 100% = 0, 0% = 70% missed |
3971 | * Rate: 60% = 1Mbs, 100% = Max | |
3972 | * Rx and Tx errors represent a straight % of total Rx/Tx | |
3973 | * RSSI: 100% = > -50, 0% = < -80 | |
3974 | * Rx errors: 100% = 0, 0% = 50% missed | |
bf79451e | 3975 | * |
43f66a6c JK |
3976 | * The lowest computed quality is used. |
3977 | * | |
3978 | */ | |
3979 | #define BEACON_THRESHOLD 5 | |
3980 | beacon_quality = 100 - missed_beacons_percent; | |
3981 | if (beacon_quality < BEACON_THRESHOLD) | |
3982 | beacon_quality = 0; | |
3983 | else | |
bf79451e | 3984 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
0edd5b44 | 3985 | (100 - BEACON_THRESHOLD); |
bf79451e | 3986 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
43f66a6c | 3987 | beacon_quality, missed_beacons_percent); |
bf79451e | 3988 | |
43f66a6c | 3989 | priv->last_rate = ipw_get_current_rate(priv); |
ea2b26e0 JK |
3990 | max_rate = ipw_get_max_rate(priv); |
3991 | rate_quality = priv->last_rate * 40 / max_rate + 60; | |
43f66a6c JK |
3992 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
3993 | rate_quality, priv->last_rate / 1000000); | |
bf79451e | 3994 | |
0edd5b44 | 3995 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
bf79451e | 3996 | rx_quality = 100 - (rx_err_delta * 100) / |
0edd5b44 | 3997 | (rx_packets_delta + rx_err_delta); |
43f66a6c JK |
3998 | else |
3999 | rx_quality = 100; | |
4000 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", | |
4001 | rx_quality, rx_err_delta, rx_packets_delta); | |
bf79451e | 4002 | |
0edd5b44 | 4003 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
bf79451e | 4004 | tx_quality = 100 - (tx_failures_delta * 100) / |
0edd5b44 | 4005 | (tx_packets_delta + tx_failures_delta); |
43f66a6c JK |
4006 | else |
4007 | tx_quality = 100; | |
4008 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", | |
4009 | tx_quality, tx_failures_delta, tx_packets_delta); | |
bf79451e | 4010 | |
43f66a6c | 4011 | rssi = average_value(&priv->average_rssi); |
c848d0af JK |
4012 | signal_quality = |
4013 | (100 * | |
4014 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * | |
4015 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - | |
4016 | (priv->ieee->perfect_rssi - rssi) * | |
4017 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + | |
4018 | 62 * (priv->ieee->perfect_rssi - rssi))) / | |
4019 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * | |
4020 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); | |
4021 | if (signal_quality > 100) | |
43f66a6c | 4022 | signal_quality = 100; |
c848d0af | 4023 | else if (signal_quality < 1) |
43f66a6c | 4024 | signal_quality = 0; |
ea2b26e0 | 4025 | |
43f66a6c JK |
4026 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
4027 | signal_quality, rssi); | |
bf79451e JG |
4028 | |
4029 | quality = min(beacon_quality, | |
43f66a6c JK |
4030 | min(rate_quality, |
4031 | min(tx_quality, min(rx_quality, signal_quality)))); | |
4032 | if (quality == beacon_quality) | |
0edd5b44 JG |
4033 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
4034 | quality); | |
43f66a6c | 4035 | if (quality == rate_quality) |
0edd5b44 JG |
4036 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
4037 | quality); | |
43f66a6c | 4038 | if (quality == tx_quality) |
0edd5b44 JG |
4039 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
4040 | quality); | |
43f66a6c | 4041 | if (quality == rx_quality) |
0edd5b44 JG |
4042 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
4043 | quality); | |
43f66a6c | 4044 | if (quality == signal_quality) |
0edd5b44 JG |
4045 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
4046 | quality); | |
43f66a6c JK |
4047 | |
4048 | priv->quality = quality; | |
bf79451e JG |
4049 | |
4050 | queue_delayed_work(priv->workqueue, &priv->gather_stats, | |
43f66a6c JK |
4051 | IPW_STATS_INTERVAL); |
4052 | } | |
4053 | ||
c848d0af JK |
4054 | static void ipw_bg_gather_stats(void *data) |
4055 | { | |
4056 | struct ipw_priv *priv = data; | |
4644151b | 4057 | mutex_lock(&priv->mutex); |
c848d0af | 4058 | ipw_gather_stats(data); |
4644151b | 4059 | mutex_unlock(&priv->mutex); |
c848d0af JK |
4060 | } |
4061 | ||
e7582561 BC |
4062 | /* Missed beacon behavior: |
4063 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. | |
4064 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. | |
4065 | * Above disassociate threshold, give up and stop scanning. | |
4066 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ | |
858119e1 | 4067 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
ea2b26e0 JK |
4068 | int missed_count) |
4069 | { | |
4070 | priv->notif_missed_beacons = missed_count; | |
4071 | ||
afbf30a2 | 4072 | if (missed_count > priv->disassociate_threshold && |
ea2b26e0 JK |
4073 | priv->status & STATUS_ASSOCIATED) { |
4074 | /* If associated and we've hit the missed | |
4075 | * beacon threshold, disassociate, turn | |
4076 | * off roaming, and abort any active scans */ | |
4077 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | | |
afbf30a2 | 4078 | IPW_DL_STATE | IPW_DL_ASSOC, |
ea2b26e0 JK |
4079 | "Missed beacon: %d - disassociate\n", missed_count); |
4080 | priv->status &= ~STATUS_ROAMING; | |
a613bffd JK |
4081 | if (priv->status & STATUS_SCANNING) { |
4082 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | | |
4083 | IPW_DL_STATE, | |
4084 | "Aborting scan with missed beacon.\n"); | |
ea2b26e0 | 4085 | queue_work(priv->workqueue, &priv->abort_scan); |
a613bffd JK |
4086 | } |
4087 | ||
ea2b26e0 JK |
4088 | queue_work(priv->workqueue, &priv->disassociate); |
4089 | return; | |
4090 | } | |
4091 | ||
4092 | if (priv->status & STATUS_ROAMING) { | |
4093 | /* If we are currently roaming, then just | |
4094 | * print a debug statement... */ | |
4095 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | |
4096 | "Missed beacon: %d - roam in progress\n", | |
4097 | missed_count); | |
4098 | return; | |
4099 | } | |
4100 | ||
4bfdb91d ZY |
4101 | if (roaming && |
4102 | (missed_count > priv->roaming_threshold && | |
4103 | missed_count <= priv->disassociate_threshold)) { | |
ea2b26e0 | 4104 | /* If we are not already roaming, set the ROAM |
e7582561 BC |
4105 | * bit in the status and kick off a scan. |
4106 | * This can happen several times before we reach | |
4107 | * disassociate_threshold. */ | |
ea2b26e0 JK |
4108 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
4109 | "Missed beacon: %d - initiate " | |
4110 | "roaming\n", missed_count); | |
4111 | if (!(priv->status & STATUS_ROAMING)) { | |
4112 | priv->status |= STATUS_ROAMING; | |
4113 | if (!(priv->status & STATUS_SCANNING)) | |
4114 | queue_work(priv->workqueue, | |
4115 | &priv->request_scan); | |
4116 | } | |
4117 | return; | |
4118 | } | |
4119 | ||
4120 | if (priv->status & STATUS_SCANNING) { | |
4121 | /* Stop scan to keep fw from getting | |
4122 | * stuck (only if we aren't roaming -- | |
4123 | * otherwise we'll never scan more than 2 or 3 | |
4124 | * channels..) */ | |
b095c381 JK |
4125 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
4126 | "Aborting scan with missed beacon.\n"); | |
ea2b26e0 JK |
4127 | queue_work(priv->workqueue, &priv->abort_scan); |
4128 | } | |
4129 | ||
4130 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); | |
ea2b26e0 JK |
4131 | } |
4132 | ||
43f66a6c JK |
4133 | /** |
4134 | * Handle host notification packet. | |
4135 | * Called from interrupt routine | |
4136 | */ | |
858119e1 | 4137 | static void ipw_rx_notification(struct ipw_priv *priv, |
43f66a6c JK |
4138 | struct ipw_rx_notification *notif) |
4139 | { | |
a613bffd JK |
4140 | notif->size = le16_to_cpu(notif->size); |
4141 | ||
0edd5b44 | 4142 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size); |
bf79451e | 4143 | |
43f66a6c | 4144 | switch (notif->subtype) { |
0edd5b44 JG |
4145 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
4146 | struct notif_association *assoc = ¬if->u.assoc; | |
4147 | ||
4148 | switch (assoc->state) { | |
4149 | case CMAS_ASSOCIATED:{ | |
4150 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4151 | IPW_DL_ASSOC, | |
4152 | "associated: '%s' " MAC_FMT | |
4153 | " \n", | |
4154 | escape_essid(priv->essid, | |
4155 | priv->essid_len), | |
4156 | MAC_ARG(priv->bssid)); | |
4157 | ||
4158 | switch (priv->ieee->iw_mode) { | |
4159 | case IW_MODE_INFRA: | |
4160 | memcpy(priv->ieee->bssid, | |
4161 | priv->bssid, ETH_ALEN); | |
4162 | break; | |
4163 | ||
4164 | case IW_MODE_ADHOC: | |
4165 | memcpy(priv->ieee->bssid, | |
4166 | priv->bssid, ETH_ALEN); | |
4167 | ||
4168 | /* clear out the station table */ | |
4169 | priv->num_stations = 0; | |
4170 | ||
4171 | IPW_DEBUG_ASSOC | |
4172 | ("queueing adhoc check\n"); | |
4173 | queue_delayed_work(priv-> | |
4174 | workqueue, | |
4175 | &priv-> | |
4176 | adhoc_check, | |
4177 | priv-> | |
4178 | assoc_request. | |
4179 | beacon_interval); | |
4180 | break; | |
4181 | } | |
4182 | ||
4183 | priv->status &= ~STATUS_ASSOCIATING; | |
4184 | priv->status |= STATUS_ASSOCIATED; | |
d8bad6df ZY |
4185 | queue_work(priv->workqueue, |
4186 | &priv->system_config); | |
0edd5b44 | 4187 | |
b095c381 | 4188 | #ifdef CONFIG_IPW_QOS |
afbf30a2 JK |
4189 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
4190 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl)) | |
4191 | if ((priv->status & STATUS_AUTH) && | |
4192 | (IPW_GET_PACKET_STYPE(¬if->u.raw) | |
4193 | == IEEE80211_STYPE_ASSOC_RESP)) { | |
b095c381 JK |
4194 | if ((sizeof |
4195 | (struct | |
2b184d5b | 4196 | ieee80211_assoc_response) |
b095c381 JK |
4197 | <= notif->size) |
4198 | && (notif->size <= 2314)) { | |
4199 | struct | |
4200 | ieee80211_rx_stats | |
4201 | stats = { | |
4202 | .len = | |
4203 | notif-> | |
4204 | size - 1, | |
4205 | }; | |
4206 | ||
4207 | IPW_DEBUG_QOS | |
4208 | ("QoS Associate " | |
4209 | "size %d\n", | |
4210 | notif->size); | |
4211 | ieee80211_rx_mgt(priv-> | |
4212 | ieee, | |
4213 | (struct | |
2b184d5b | 4214 | ieee80211_hdr_4addr |
b095c381 JK |
4215 | *) |
4216 | ¬if->u.raw, &stats); | |
4217 | } | |
0edd5b44 | 4218 | } |
b095c381 | 4219 | #endif |
0edd5b44 | 4220 | |
a613bffd | 4221 | schedule_work(&priv->link_up); |
43f66a6c | 4222 | |
0edd5b44 JG |
4223 | break; |
4224 | } | |
bf79451e | 4225 | |
0edd5b44 JG |
4226 | case CMAS_AUTHENTICATED:{ |
4227 | if (priv-> | |
4228 | status & (STATUS_ASSOCIATED | | |
4229 | STATUS_AUTH)) { | |
0f52bf90 | 4230 | #ifdef CONFIG_IPW2200_DEBUG |
0edd5b44 JG |
4231 | struct notif_authenticate *auth |
4232 | = ¬if->u.auth; | |
4233 | IPW_DEBUG(IPW_DL_NOTIF | | |
4234 | IPW_DL_STATE | | |
4235 | IPW_DL_ASSOC, | |
4236 | "deauthenticated: '%s' " | |
4237 | MAC_FMT | |
4238 | ": (0x%04X) - %s \n", | |
4239 | escape_essid(priv-> | |
4240 | essid, | |
4241 | priv-> | |
4242 | essid_len), | |
4243 | MAC_ARG(priv->bssid), | |
4244 | ntohs(auth->status), | |
4245 | ipw_get_status_code | |
4246 | (ntohs | |
4247 | (auth->status))); | |
43f66a6c JK |
4248 | #endif |
4249 | ||
0edd5b44 JG |
4250 | priv->status &= |
4251 | ~(STATUS_ASSOCIATING | | |
4252 | STATUS_AUTH | | |
4253 | STATUS_ASSOCIATED); | |
4254 | ||
a613bffd | 4255 | schedule_work(&priv->link_down); |
0edd5b44 JG |
4256 | break; |
4257 | } | |
4258 | ||
4259 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4260 | IPW_DL_ASSOC, | |
4261 | "authenticated: '%s' " MAC_FMT | |
4262 | "\n", | |
4263 | escape_essid(priv->essid, | |
4264 | priv->essid_len), | |
4265 | MAC_ARG(priv->bssid)); | |
4266 | break; | |
4267 | } | |
4268 | ||
4269 | case CMAS_INIT:{ | |
ea2b26e0 JK |
4270 | if (priv->status & STATUS_AUTH) { |
4271 | struct | |
4272 | ieee80211_assoc_response | |
4273 | *resp; | |
4274 | resp = | |
4275 | (struct | |
4276 | ieee80211_assoc_response | |
4277 | *)¬if->u.raw; | |
4278 | IPW_DEBUG(IPW_DL_NOTIF | | |
4279 | IPW_DL_STATE | | |
4280 | IPW_DL_ASSOC, | |
4281 | "association failed (0x%04X): %s\n", | |
4282 | ntohs(resp->status), | |
4283 | ipw_get_status_code | |
4284 | (ntohs | |
4285 | (resp->status))); | |
4286 | } | |
4287 | ||
0edd5b44 JG |
4288 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
4289 | IPW_DL_ASSOC, | |
4290 | "disassociated: '%s' " MAC_FMT | |
4291 | " \n", | |
4292 | escape_essid(priv->essid, | |
4293 | priv->essid_len), | |
4294 | MAC_ARG(priv->bssid)); | |
4295 | ||
4296 | priv->status &= | |
4297 | ~(STATUS_DISASSOCIATING | | |
4298 | STATUS_ASSOCIATING | | |
4299 | STATUS_ASSOCIATED | STATUS_AUTH); | |
b095c381 JK |
4300 | if (priv->assoc_network |
4301 | && (priv->assoc_network-> | |
4302 | capability & | |
4303 | WLAN_CAPABILITY_IBSS)) | |
4304 | ipw_remove_current_network | |
4305 | (priv); | |
0edd5b44 | 4306 | |
a613bffd | 4307 | schedule_work(&priv->link_down); |
0edd5b44 | 4308 | |
0edd5b44 JG |
4309 | break; |
4310 | } | |
43f66a6c | 4311 | |
b095c381 JK |
4312 | case CMAS_RX_ASSOC_RESP: |
4313 | break; | |
4314 | ||
0edd5b44 JG |
4315 | default: |
4316 | IPW_ERROR("assoc: unknown (%d)\n", | |
4317 | assoc->state); | |
43f66a6c | 4318 | break; |
bf79451e | 4319 | } |
43f66a6c | 4320 | |
43f66a6c JK |
4321 | break; |
4322 | } | |
bf79451e | 4323 | |
0edd5b44 JG |
4324 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
4325 | struct notif_authenticate *auth = ¬if->u.auth; | |
4326 | switch (auth->state) { | |
4327 | case CMAS_AUTHENTICATED: | |
4328 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | |
4329 | "authenticated: '%s' " MAC_FMT " \n", | |
4330 | escape_essid(priv->essid, | |
4331 | priv->essid_len), | |
4332 | MAC_ARG(priv->bssid)); | |
4333 | priv->status |= STATUS_AUTH; | |
4334 | break; | |
43f66a6c | 4335 | |
0edd5b44 JG |
4336 | case CMAS_INIT: |
4337 | if (priv->status & STATUS_AUTH) { | |
4338 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4339 | IPW_DL_ASSOC, | |
4340 | "authentication failed (0x%04X): %s\n", | |
4341 | ntohs(auth->status), | |
4342 | ipw_get_status_code(ntohs | |
4343 | (auth-> | |
4344 | status))); | |
4345 | } | |
4346 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4347 | IPW_DL_ASSOC, | |
4348 | "deauthenticated: '%s' " MAC_FMT "\n", | |
4349 | escape_essid(priv->essid, | |
4350 | priv->essid_len), | |
4351 | MAC_ARG(priv->bssid)); | |
bf79451e | 4352 | |
0edd5b44 JG |
4353 | priv->status &= ~(STATUS_ASSOCIATING | |
4354 | STATUS_AUTH | | |
4355 | STATUS_ASSOCIATED); | |
43f66a6c | 4356 | |
a613bffd | 4357 | schedule_work(&priv->link_down); |
0edd5b44 | 4358 | break; |
43f66a6c | 4359 | |
0edd5b44 JG |
4360 | case CMAS_TX_AUTH_SEQ_1: |
4361 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4362 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); | |
4363 | break; | |
4364 | case CMAS_RX_AUTH_SEQ_2: | |
4365 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4366 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); | |
4367 | break; | |
4368 | case CMAS_AUTH_SEQ_1_PASS: | |
4369 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4370 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); | |
4371 | break; | |
4372 | case CMAS_AUTH_SEQ_1_FAIL: | |
4373 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4374 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); | |
4375 | break; | |
4376 | case CMAS_TX_AUTH_SEQ_3: | |
4377 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4378 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); | |
4379 | break; | |
4380 | case CMAS_RX_AUTH_SEQ_4: | |
4381 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4382 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); | |
4383 | break; | |
4384 | case CMAS_AUTH_SEQ_2_PASS: | |
4385 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4386 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); | |
4387 | break; | |
4388 | case CMAS_AUTH_SEQ_2_FAIL: | |
4389 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4390 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); | |
4391 | break; | |
4392 | case CMAS_TX_ASSOC: | |
4393 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4394 | IPW_DL_ASSOC, "TX_ASSOC\n"); | |
4395 | break; | |
4396 | case CMAS_RX_ASSOC_RESP: | |
4397 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4398 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); | |
b095c381 | 4399 | |
0edd5b44 JG |
4400 | break; |
4401 | case CMAS_ASSOCIATED: | |
4402 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4403 | IPW_DL_ASSOC, "ASSOCIATED\n"); | |
4404 | break; | |
4405 | default: | |
4406 | IPW_DEBUG_NOTIF("auth: failure - %d\n", | |
4407 | auth->state); | |
4408 | break; | |
43f66a6c | 4409 | } |
43f66a6c JK |
4410 | break; |
4411 | } | |
4412 | ||
0edd5b44 JG |
4413 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
4414 | struct notif_channel_result *x = | |
4415 | ¬if->u.channel_result; | |
43f66a6c | 4416 | |
0edd5b44 JG |
4417 | if (notif->size == sizeof(*x)) { |
4418 | IPW_DEBUG_SCAN("Scan result for channel %d\n", | |
4419 | x->channel_num); | |
4420 | } else { | |
4421 | IPW_DEBUG_SCAN("Scan result of wrong size %d " | |
4422 | "(should be %zd)\n", | |
4423 | notif->size, sizeof(*x)); | |
bf79451e | 4424 | } |
43f66a6c JK |
4425 | break; |
4426 | } | |
43f66a6c | 4427 | |
0edd5b44 JG |
4428 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
4429 | struct notif_scan_complete *x = ¬if->u.scan_complete; | |
4430 | if (notif->size == sizeof(*x)) { | |
4431 | IPW_DEBUG_SCAN | |
4432 | ("Scan completed: type %d, %d channels, " | |
4433 | "%d status\n", x->scan_type, | |
4434 | x->num_channels, x->status); | |
4435 | } else { | |
4436 | IPW_ERROR("Scan completed of wrong size %d " | |
4437 | "(should be %zd)\n", | |
4438 | notif->size, sizeof(*x)); | |
4439 | } | |
43f66a6c | 4440 | |
0edd5b44 JG |
4441 | priv->status &= |
4442 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); | |
4443 | ||
a0e04ab3 | 4444 | wake_up_interruptible(&priv->wait_state); |
0edd5b44 JG |
4445 | cancel_delayed_work(&priv->scan_check); |
4446 | ||
b095c381 JK |
4447 | if (priv->status & STATUS_EXIT_PENDING) |
4448 | break; | |
4449 | ||
4450 | priv->ieee->scans++; | |
4451 | ||
4452 | #ifdef CONFIG_IPW2200_MONITOR | |
4453 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | |
afbf30a2 | 4454 | priv->status |= STATUS_SCAN_FORCED; |
b095c381 JK |
4455 | queue_work(priv->workqueue, |
4456 | &priv->request_scan); | |
4457 | break; | |
4458 | } | |
afbf30a2 | 4459 | priv->status &= ~STATUS_SCAN_FORCED; |
b095c381 JK |
4460 | #endif /* CONFIG_IPW2200_MONITOR */ |
4461 | ||
0edd5b44 JG |
4462 | if (!(priv->status & (STATUS_ASSOCIATED | |
4463 | STATUS_ASSOCIATING | | |
4464 | STATUS_ROAMING | | |
4465 | STATUS_DISASSOCIATING))) | |
4466 | queue_work(priv->workqueue, &priv->associate); | |
4467 | else if (priv->status & STATUS_ROAMING) { | |
e7582561 BC |
4468 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
4469 | /* If a scan completed and we are in roam mode, then | |
4470 | * the scan that completed was the one requested as a | |
4471 | * result of entering roam... so, schedule the | |
4472 | * roam work */ | |
4473 | queue_work(priv->workqueue, | |
4474 | &priv->roam); | |
4475 | else | |
4476 | /* Don't schedule if we aborted the scan */ | |
4477 | priv->status &= ~STATUS_ROAMING; | |
0edd5b44 JG |
4478 | } else if (priv->status & STATUS_SCAN_PENDING) |
4479 | queue_work(priv->workqueue, | |
4480 | &priv->request_scan); | |
a613bffd JK |
4481 | else if (priv->config & CFG_BACKGROUND_SCAN |
4482 | && priv->status & STATUS_ASSOCIATED) | |
4483 | queue_delayed_work(priv->workqueue, | |
4484 | &priv->request_scan, HZ); | |
0edd5b44 | 4485 | break; |
43f66a6c | 4486 | } |
43f66a6c | 4487 | |
0edd5b44 JG |
4488 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
4489 | struct notif_frag_length *x = ¬if->u.frag_len; | |
43f66a6c | 4490 | |
a613bffd JK |
4491 | if (notif->size == sizeof(*x)) |
4492 | IPW_ERROR("Frag length: %d\n", | |
4493 | le16_to_cpu(x->frag_length)); | |
4494 | else | |
0edd5b44 JG |
4495 | IPW_ERROR("Frag length of wrong size %d " |
4496 | "(should be %zd)\n", | |
4497 | notif->size, sizeof(*x)); | |
0edd5b44 | 4498 | break; |
43f66a6c | 4499 | } |
43f66a6c | 4500 | |
0edd5b44 JG |
4501 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
4502 | struct notif_link_deterioration *x = | |
4503 | ¬if->u.link_deterioration; | |
afbf30a2 | 4504 | |
0edd5b44 JG |
4505 | if (notif->size == sizeof(*x)) { |
4506 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | |
12977154 BC |
4507 | "link deterioration: type %d, cnt %d\n", |
4508 | x->silence_notification_type, | |
4509 | x->silence_count); | |
0edd5b44 JG |
4510 | memcpy(&priv->last_link_deterioration, x, |
4511 | sizeof(*x)); | |
4512 | } else { | |
4513 | IPW_ERROR("Link Deterioration of wrong size %d " | |
4514 | "(should be %zd)\n", | |
4515 | notif->size, sizeof(*x)); | |
4516 | } | |
43f66a6c JK |
4517 | break; |
4518 | } | |
4519 | ||
0edd5b44 JG |
4520 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
4521 | IPW_ERROR("Dino config\n"); | |
4522 | if (priv->hcmd | |
a613bffd | 4523 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
0edd5b44 | 4524 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
a613bffd | 4525 | |
0edd5b44 JG |
4526 | break; |
4527 | } | |
43f66a6c | 4528 | |
0edd5b44 JG |
4529 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
4530 | struct notif_beacon_state *x = ¬if->u.beacon_state; | |
4531 | if (notif->size != sizeof(*x)) { | |
4532 | IPW_ERROR | |
4533 | ("Beacon state of wrong size %d (should " | |
4534 | "be %zd)\n", notif->size, sizeof(*x)); | |
4535 | break; | |
43f66a6c JK |
4536 | } |
4537 | ||
a613bffd JK |
4538 | if (le32_to_cpu(x->state) == |
4539 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) | |
4540 | ipw_handle_missed_beacon(priv, | |
4541 | le32_to_cpu(x-> | |
4542 | number)); | |
43f66a6c | 4543 | |
0edd5b44 JG |
4544 | break; |
4545 | } | |
43f66a6c | 4546 | |
0edd5b44 JG |
4547 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
4548 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; | |
4549 | if (notif->size == sizeof(*x)) { | |
4550 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " | |
4551 | "0x%02x station %d\n", | |
4552 | x->key_state, x->security_type, | |
4553 | x->station_index); | |
4554 | break; | |
4555 | } | |
43f66a6c | 4556 | |
0edd5b44 JG |
4557 | IPW_ERROR |
4558 | ("TGi Tx Key of wrong size %d (should be %zd)\n", | |
4559 | notif->size, sizeof(*x)); | |
43f66a6c | 4560 | break; |
bf79451e | 4561 | } |
43f66a6c | 4562 | |
0edd5b44 JG |
4563 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
4564 | struct notif_calibration *x = ¬if->u.calibration; | |
43f66a6c | 4565 | |
0edd5b44 JG |
4566 | if (notif->size == sizeof(*x)) { |
4567 | memcpy(&priv->calib, x, sizeof(*x)); | |
4568 | IPW_DEBUG_INFO("TODO: Calibration\n"); | |
4569 | break; | |
4570 | } | |
43f66a6c | 4571 | |
0edd5b44 JG |
4572 | IPW_ERROR |
4573 | ("Calibration of wrong size %d (should be %zd)\n", | |
4574 | notif->size, sizeof(*x)); | |
43f66a6c | 4575 | break; |
bf79451e JG |
4576 | } |
4577 | ||
0edd5b44 JG |
4578 | case HOST_NOTIFICATION_NOISE_STATS:{ |
4579 | if (notif->size == sizeof(u32)) { | |
4580 | priv->last_noise = | |
a613bffd JK |
4581 | (u8) (le32_to_cpu(notif->u.noise.value) & |
4582 | 0xff); | |
0edd5b44 JG |
4583 | average_add(&priv->average_noise, |
4584 | priv->last_noise); | |
4585 | break; | |
4586 | } | |
43f66a6c | 4587 | |
0edd5b44 JG |
4588 | IPW_ERROR |
4589 | ("Noise stat is wrong size %d (should be %zd)\n", | |
4590 | notif->size, sizeof(u32)); | |
43f66a6c JK |
4591 | break; |
4592 | } | |
4593 | ||
43f66a6c | 4594 | default: |
1dd31b6c ZY |
4595 | IPW_DEBUG_NOTIF("Unknown notification: " |
4596 | "subtype=%d,flags=0x%2x,size=%d\n", | |
4597 | notif->subtype, notif->flags, notif->size); | |
43f66a6c JK |
4598 | } |
4599 | } | |
4600 | ||
4601 | /** | |
4602 | * Destroys all DMA structures and initialise them again | |
bf79451e | 4603 | * |
43f66a6c JK |
4604 | * @param priv |
4605 | * @return error code | |
4606 | */ | |
4607 | static int ipw_queue_reset(struct ipw_priv *priv) | |
4608 | { | |
4609 | int rc = 0; | |
4610 | /** @todo customize queue sizes */ | |
4611 | int nTx = 64, nTxCmd = 8; | |
4612 | ipw_tx_queue_free(priv); | |
4613 | /* Tx CMD queue */ | |
4614 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, | |
b095c381 JK |
4615 | IPW_TX_CMD_QUEUE_READ_INDEX, |
4616 | IPW_TX_CMD_QUEUE_WRITE_INDEX, | |
4617 | IPW_TX_CMD_QUEUE_BD_BASE, | |
4618 | IPW_TX_CMD_QUEUE_BD_SIZE); | |
43f66a6c JK |
4619 | if (rc) { |
4620 | IPW_ERROR("Tx Cmd queue init failed\n"); | |
4621 | goto error; | |
4622 | } | |
4623 | /* Tx queue(s) */ | |
4624 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, | |
b095c381 JK |
4625 | IPW_TX_QUEUE_0_READ_INDEX, |
4626 | IPW_TX_QUEUE_0_WRITE_INDEX, | |
4627 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); | |
43f66a6c JK |
4628 | if (rc) { |
4629 | IPW_ERROR("Tx 0 queue init failed\n"); | |
4630 | goto error; | |
4631 | } | |
4632 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, | |
b095c381 JK |
4633 | IPW_TX_QUEUE_1_READ_INDEX, |
4634 | IPW_TX_QUEUE_1_WRITE_INDEX, | |
4635 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); | |
43f66a6c JK |
4636 | if (rc) { |
4637 | IPW_ERROR("Tx 1 queue init failed\n"); | |
4638 | goto error; | |
4639 | } | |
4640 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, | |
b095c381 JK |
4641 | IPW_TX_QUEUE_2_READ_INDEX, |
4642 | IPW_TX_QUEUE_2_WRITE_INDEX, | |
4643 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); | |
43f66a6c JK |
4644 | if (rc) { |
4645 | IPW_ERROR("Tx 2 queue init failed\n"); | |
4646 | goto error; | |
4647 | } | |
4648 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, | |
b095c381 JK |
4649 | IPW_TX_QUEUE_3_READ_INDEX, |
4650 | IPW_TX_QUEUE_3_WRITE_INDEX, | |
4651 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); | |
43f66a6c JK |
4652 | if (rc) { |
4653 | IPW_ERROR("Tx 3 queue init failed\n"); | |
4654 | goto error; | |
4655 | } | |
4656 | /* statistics */ | |
4657 | priv->rx_bufs_min = 0; | |
4658 | priv->rx_pend_max = 0; | |
4659 | return rc; | |
4660 | ||
0edd5b44 | 4661 | error: |
43f66a6c JK |
4662 | ipw_tx_queue_free(priv); |
4663 | return rc; | |
4664 | } | |
4665 | ||
4666 | /** | |
4667 | * Reclaim Tx queue entries no more used by NIC. | |
bf79451e | 4668 | * |
43f66a6c JK |
4669 | * When FW adwances 'R' index, all entries between old and |
4670 | * new 'R' index need to be reclaimed. As result, some free space | |
4671 | * forms. If there is enough free space (> low mark), wake Tx queue. | |
bf79451e | 4672 | * |
43f66a6c JK |
4673 | * @note Need to protect against garbage in 'R' index |
4674 | * @param priv | |
4675 | * @param txq | |
4676 | * @param qindex | |
4677 | * @return Number of used entries remains in the queue | |
4678 | */ | |
bf79451e | 4679 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
43f66a6c JK |
4680 | struct clx2_tx_queue *txq, int qindex) |
4681 | { | |
4682 | u32 hw_tail; | |
4683 | int used; | |
4684 | struct clx2_queue *q = &txq->q; | |
4685 | ||
4686 | hw_tail = ipw_read32(priv, q->reg_r); | |
4687 | if (hw_tail >= q->n_bd) { | |
4688 | IPW_ERROR | |
0edd5b44 JG |
4689 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
4690 | hw_tail, q->n_bd); | |
43f66a6c JK |
4691 | goto done; |
4692 | } | |
4693 | for (; q->last_used != hw_tail; | |
4694 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { | |
4695 | ipw_queue_tx_free_tfd(priv, txq); | |
4696 | priv->tx_packets++; | |
4697 | } | |
0edd5b44 | 4698 | done: |
9ddf84f6 JK |
4699 | if ((ipw_queue_space(q) > q->low_mark) && |
4700 | (qindex >= 0) && | |
4701 | (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev)) | |
4702 | netif_wake_queue(priv->net_dev); | |
43f66a6c JK |
4703 | used = q->first_empty - q->last_used; |
4704 | if (used < 0) | |
4705 | used += q->n_bd; | |
4706 | ||
4707 | return used; | |
4708 | } | |
4709 | ||
4710 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, | |
4711 | int len, int sync) | |
4712 | { | |
4713 | struct clx2_tx_queue *txq = &priv->txq_cmd; | |
4714 | struct clx2_queue *q = &txq->q; | |
4715 | struct tfd_frame *tfd; | |
4716 | ||
4717 | if (ipw_queue_space(q) < (sync ? 1 : 2)) { | |
4718 | IPW_ERROR("No space for Tx\n"); | |
4719 | return -EBUSY; | |
4720 | } | |
4721 | ||
4722 | tfd = &txq->bd[q->first_empty]; | |
4723 | txq->txb[q->first_empty] = NULL; | |
4724 | ||
4725 | memset(tfd, 0, sizeof(*tfd)); | |
4726 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; | |
4727 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; | |
4728 | priv->hcmd_seq++; | |
4729 | tfd->u.cmd.index = hcmd; | |
4730 | tfd->u.cmd.length = len; | |
4731 | memcpy(tfd->u.cmd.payload, buf, len); | |
4732 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); | |
4733 | ipw_write32(priv, q->reg_w, q->first_empty); | |
4734 | _ipw_read32(priv, 0x90); | |
4735 | ||
4736 | return 0; | |
4737 | } | |
4738 | ||
bf79451e | 4739 | /* |
43f66a6c JK |
4740 | * Rx theory of operation |
4741 | * | |
4742 | * The host allocates 32 DMA target addresses and passes the host address | |
b095c381 | 4743 | * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
43f66a6c JK |
4744 | * 0 to 31 |
4745 | * | |
4746 | * Rx Queue Indexes | |
4747 | * The host/firmware share two index registers for managing the Rx buffers. | |
4748 | * | |
bf79451e JG |
4749 | * The READ index maps to the first position that the firmware may be writing |
4750 | * to -- the driver can read up to (but not including) this position and get | |
4751 | * good data. | |
43f66a6c JK |
4752 | * The READ index is managed by the firmware once the card is enabled. |
4753 | * | |
4754 | * The WRITE index maps to the last position the driver has read from -- the | |
4755 | * position preceding WRITE is the last slot the firmware can place a packet. | |
4756 | * | |
4757 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if | |
bf79451e | 4758 | * WRITE = READ. |
43f66a6c | 4759 | * |
bf79451e | 4760 | * During initialization the host sets up the READ queue position to the first |
43f66a6c JK |
4761 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
4762 | * | |
4763 | * When the firmware places a packet in a buffer it will advance the READ index | |
4764 | * and fire the RX interrupt. The driver can then query the READ index and | |
4765 | * process as many packets as possible, moving the WRITE index forward as it | |
4766 | * resets the Rx queue buffers with new memory. | |
bf79451e | 4767 | * |
43f66a6c | 4768 | * The management in the driver is as follows: |
bf79451e | 4769 | * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When |
43f66a6c | 4770 | * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled |
bf79451e | 4771 | * to replensish the ipw->rxq->rx_free. |
43f66a6c JK |
4772 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
4773 | * ipw->rxq is replenished and the READ INDEX is updated (updating the | |
4774 | * 'processed' and 'read' driver indexes as well) | |
4775 | * + A received packet is processed and handed to the kernel network stack, | |
4776 | * detached from the ipw->rxq. The driver 'processed' index is updated. | |
4777 | * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free | |
bf79451e JG |
4778 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
4779 | * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there | |
43f66a6c JK |
4780 | * were enough free buffers and RX_STALLED is set it is cleared. |
4781 | * | |
4782 | * | |
4783 | * Driver sequence: | |
4784 | * | |
bf79451e | 4785 | * ipw_rx_queue_alloc() Allocates rx_free |
43f66a6c JK |
4786 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
4787 | * ipw_rx_queue_restock | |
4788 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx | |
4789 | * queue, updates firmware pointers, and updates | |
4790 | * the WRITE index. If insufficient rx_free buffers | |
4791 | * are available, schedules ipw_rx_queue_replenish | |
4792 | * | |
4793 | * -- enable interrupts -- | |
4794 | * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the | |
bf79451e | 4795 | * READ INDEX, detaching the SKB from the pool. |
43f66a6c JK |
4796 | * Moves the packet buffer from queue to rx_used. |
4797 | * Calls ipw_rx_queue_restock to refill any empty | |
4798 | * slots. | |
4799 | * ... | |
4800 | * | |
4801 | */ | |
4802 | ||
bf79451e | 4803 | /* |
43f66a6c JK |
4804 | * If there are slots in the RX queue that need to be restocked, |
4805 | * and we have free pre-allocated buffers, fill the ranks as much | |
4806 | * as we can pulling from rx_free. | |
4807 | * | |
4808 | * This moves the 'write' index forward to catch up with 'processed', and | |
4809 | * also updates the memory address in the firmware to reference the new | |
4810 | * target buffer. | |
4811 | */ | |
4812 | static void ipw_rx_queue_restock(struct ipw_priv *priv) | |
4813 | { | |
4814 | struct ipw_rx_queue *rxq = priv->rxq; | |
4815 | struct list_head *element; | |
4816 | struct ipw_rx_mem_buffer *rxb; | |
4817 | unsigned long flags; | |
4818 | int write; | |
4819 | ||
4820 | spin_lock_irqsave(&rxq->lock, flags); | |
4821 | write = rxq->write; | |
4822 | while ((rxq->write != rxq->processed) && (rxq->free_count)) { | |
4823 | element = rxq->rx_free.next; | |
4824 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); | |
4825 | list_del(element); | |
4826 | ||
b095c381 | 4827 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
43f66a6c JK |
4828 | rxb->dma_addr); |
4829 | rxq->queue[rxq->write] = rxb; | |
4830 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; | |
4831 | rxq->free_count--; | |
4832 | } | |
4833 | spin_unlock_irqrestore(&rxq->lock, flags); | |
4834 | ||
bf79451e | 4835 | /* If the pre-allocated buffer pool is dropping low, schedule to |
43f66a6c JK |
4836 | * refill it */ |
4837 | if (rxq->free_count <= RX_LOW_WATERMARK) | |
4838 | queue_work(priv->workqueue, &priv->rx_replenish); | |
4839 | ||
4840 | /* If we've added more space for the firmware to place data, tell it */ | |
bf79451e | 4841 | if (write != rxq->write) |
b095c381 | 4842 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
43f66a6c JK |
4843 | } |
4844 | ||
4845 | /* | |
4846 | * Move all used packet from rx_used to rx_free, allocating a new SKB for each. | |
bf79451e JG |
4847 | * Also restock the Rx queue via ipw_rx_queue_restock. |
4848 | * | |
43f66a6c JK |
4849 | * This is called as a scheduled work item (except for during intialization) |
4850 | */ | |
4851 | static void ipw_rx_queue_replenish(void *data) | |
4852 | { | |
4853 | struct ipw_priv *priv = data; | |
4854 | struct ipw_rx_queue *rxq = priv->rxq; | |
4855 | struct list_head *element; | |
4856 | struct ipw_rx_mem_buffer *rxb; | |
4857 | unsigned long flags; | |
4858 | ||
4859 | spin_lock_irqsave(&rxq->lock, flags); | |
4860 | while (!list_empty(&rxq->rx_used)) { | |
4861 | element = rxq->rx_used.next; | |
4862 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); | |
b095c381 | 4863 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
43f66a6c JK |
4864 | if (!rxb->skb) { |
4865 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", | |
4866 | priv->net_dev->name); | |
4867 | /* We don't reschedule replenish work here -- we will | |
4868 | * call the restock method and if it still needs | |
4869 | * more buffers it will schedule replenish */ | |
4870 | break; | |
4871 | } | |
4872 | list_del(element); | |
bf79451e | 4873 | |
43f66a6c | 4874 | rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data; |
0edd5b44 JG |
4875 | rxb->dma_addr = |
4876 | pci_map_single(priv->pci_dev, rxb->skb->data, | |
b095c381 | 4877 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
bf79451e | 4878 | |
43f66a6c JK |
4879 | list_add_tail(&rxb->list, &rxq->rx_free); |
4880 | rxq->free_count++; | |
4881 | } | |
4882 | spin_unlock_irqrestore(&rxq->lock, flags); | |
4883 | ||
4884 | ipw_rx_queue_restock(priv); | |
4885 | } | |
4886 | ||
c848d0af JK |
4887 | static void ipw_bg_rx_queue_replenish(void *data) |
4888 | { | |
4889 | struct ipw_priv *priv = data; | |
4644151b | 4890 | mutex_lock(&priv->mutex); |
c848d0af | 4891 | ipw_rx_queue_replenish(data); |
4644151b | 4892 | mutex_unlock(&priv->mutex); |
c848d0af JK |
4893 | } |
4894 | ||
43f66a6c | 4895 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
c7b6a674 | 4896 | * If an SKB has been detached, the POOL needs to have its SKB set to NULL |
bf79451e | 4897 | * This free routine walks the list of POOL entries and if SKB is set to |
43f66a6c JK |
4898 | * non NULL it is unmapped and freed |
4899 | */ | |
0edd5b44 | 4900 | static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq) |
43f66a6c JK |
4901 | { |
4902 | int i; | |
4903 | ||
4904 | if (!rxq) | |
4905 | return; | |
bf79451e | 4906 | |
43f66a6c JK |
4907 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
4908 | if (rxq->pool[i].skb != NULL) { | |
4909 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, | |
b095c381 | 4910 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
43f66a6c JK |
4911 | dev_kfree_skb(rxq->pool[i].skb); |
4912 | } | |
4913 | } | |
4914 | ||
4915 | kfree(rxq); | |
4916 | } | |
4917 | ||
4918 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) | |
4919 | { | |
4920 | struct ipw_rx_queue *rxq; | |
4921 | int i; | |
4922 | ||
c75f4742 | 4923 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
ad18b0ea PI |
4924 | if (unlikely(!rxq)) { |
4925 | IPW_ERROR("memory allocation failed\n"); | |
4926 | return NULL; | |
4927 | } | |
43f66a6c JK |
4928 | spin_lock_init(&rxq->lock); |
4929 | INIT_LIST_HEAD(&rxq->rx_free); | |
4930 | INIT_LIST_HEAD(&rxq->rx_used); | |
4931 | ||
4932 | /* Fill the rx_used queue with _all_ of the Rx buffers */ | |
bf79451e | 4933 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
43f66a6c JK |
4934 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
4935 | ||
4936 | /* Set us so that we have processed and used all buffers, but have | |
4937 | * not restocked the Rx queue with fresh buffers */ | |
4938 | rxq->read = rxq->write = 0; | |
4939 | rxq->processed = RX_QUEUE_SIZE - 1; | |
4940 | rxq->free_count = 0; | |
4941 | ||
4942 | return rxq; | |
4943 | } | |
4944 | ||
4945 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) | |
4946 | { | |
4947 | rate &= ~IEEE80211_BASIC_RATE_MASK; | |
4948 | if (ieee_mode == IEEE_A) { | |
4949 | switch (rate) { | |
bf79451e JG |
4950 | case IEEE80211_OFDM_RATE_6MB: |
4951 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? | |
0edd5b44 | 4952 | 1 : 0; |
bf79451e JG |
4953 | case IEEE80211_OFDM_RATE_9MB: |
4954 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? | |
0edd5b44 | 4955 | 1 : 0; |
bf79451e | 4956 | case IEEE80211_OFDM_RATE_12MB: |
0edd5b44 JG |
4957 | return priv-> |
4958 | rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; | |
bf79451e | 4959 | case IEEE80211_OFDM_RATE_18MB: |
0edd5b44 JG |
4960 | return priv-> |
4961 | rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; | |
bf79451e | 4962 | case IEEE80211_OFDM_RATE_24MB: |
0edd5b44 JG |
4963 | return priv-> |
4964 | rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; | |
bf79451e | 4965 | case IEEE80211_OFDM_RATE_36MB: |
0edd5b44 JG |
4966 | return priv-> |
4967 | rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; | |
bf79451e | 4968 | case IEEE80211_OFDM_RATE_48MB: |
0edd5b44 JG |
4969 | return priv-> |
4970 | rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; | |
bf79451e | 4971 | case IEEE80211_OFDM_RATE_54MB: |
0edd5b44 JG |
4972 | return priv-> |
4973 | rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; | |
43f66a6c JK |
4974 | default: |
4975 | return 0; | |
4976 | } | |
4977 | } | |
bf79451e | 4978 | |
43f66a6c JK |
4979 | /* B and G mixed */ |
4980 | switch (rate) { | |
bf79451e | 4981 | case IEEE80211_CCK_RATE_1MB: |
43f66a6c | 4982 | return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0; |
bf79451e | 4983 | case IEEE80211_CCK_RATE_2MB: |
43f66a6c | 4984 | return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0; |
bf79451e | 4985 | case IEEE80211_CCK_RATE_5MB: |
43f66a6c | 4986 | return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0; |
bf79451e | 4987 | case IEEE80211_CCK_RATE_11MB: |
43f66a6c JK |
4988 | return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0; |
4989 | } | |
4990 | ||
4991 | /* If we are limited to B modulations, bail at this point */ | |
4992 | if (ieee_mode == IEEE_B) | |
4993 | return 0; | |
4994 | ||
4995 | /* G */ | |
4996 | switch (rate) { | |
bf79451e | 4997 | case IEEE80211_OFDM_RATE_6MB: |
43f66a6c | 4998 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0; |
bf79451e | 4999 | case IEEE80211_OFDM_RATE_9MB: |
43f66a6c | 5000 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0; |
bf79451e | 5001 | case IEEE80211_OFDM_RATE_12MB: |
43f66a6c | 5002 | return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
bf79451e | 5003 | case IEEE80211_OFDM_RATE_18MB: |
43f66a6c | 5004 | return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
bf79451e | 5005 | case IEEE80211_OFDM_RATE_24MB: |
43f66a6c | 5006 | return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
bf79451e | 5007 | case IEEE80211_OFDM_RATE_36MB: |
43f66a6c | 5008 | return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
bf79451e | 5009 | case IEEE80211_OFDM_RATE_48MB: |
43f66a6c | 5010 | return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
bf79451e | 5011 | case IEEE80211_OFDM_RATE_54MB: |
43f66a6c JK |
5012 | return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
5013 | } | |
5014 | ||
5015 | return 0; | |
5016 | } | |
5017 | ||
bf79451e | 5018 | static int ipw_compatible_rates(struct ipw_priv *priv, |
43f66a6c JK |
5019 | const struct ieee80211_network *network, |
5020 | struct ipw_supported_rates *rates) | |
5021 | { | |
5022 | int num_rates, i; | |
5023 | ||
5024 | memset(rates, 0, sizeof(*rates)); | |
0edd5b44 | 5025 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
43f66a6c JK |
5026 | rates->num_rates = 0; |
5027 | for (i = 0; i < num_rates; i++) { | |
a613bffd JK |
5028 | if (!ipw_is_rate_in_mask(priv, network->mode, |
5029 | network->rates[i])) { | |
5030 | ||
ea2b26e0 | 5031 | if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) { |
a613bffd JK |
5032 | IPW_DEBUG_SCAN("Adding masked mandatory " |
5033 | "rate %02X\n", | |
5034 | network->rates[i]); | |
5035 | rates->supported_rates[rates->num_rates++] = | |
5036 | network->rates[i]; | |
5037 | continue; | |
ea2b26e0 JK |
5038 | } |
5039 | ||
43f66a6c JK |
5040 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
5041 | network->rates[i], priv->rates_mask); | |
5042 | continue; | |
5043 | } | |
bf79451e | 5044 | |
43f66a6c JK |
5045 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
5046 | } | |
5047 | ||
a613bffd JK |
5048 | num_rates = min(network->rates_ex_len, |
5049 | (u8) (IPW_MAX_RATES - num_rates)); | |
43f66a6c | 5050 | for (i = 0; i < num_rates; i++) { |
a613bffd JK |
5051 | if (!ipw_is_rate_in_mask(priv, network->mode, |
5052 | network->rates_ex[i])) { | |
ea2b26e0 | 5053 | if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) { |
a613bffd JK |
5054 | IPW_DEBUG_SCAN("Adding masked mandatory " |
5055 | "rate %02X\n", | |
5056 | network->rates_ex[i]); | |
5057 | rates->supported_rates[rates->num_rates++] = | |
5058 | network->rates[i]; | |
5059 | continue; | |
ea2b26e0 JK |
5060 | } |
5061 | ||
43f66a6c JK |
5062 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
5063 | network->rates_ex[i], priv->rates_mask); | |
5064 | continue; | |
5065 | } | |
bf79451e | 5066 | |
0edd5b44 JG |
5067 | rates->supported_rates[rates->num_rates++] = |
5068 | network->rates_ex[i]; | |
43f66a6c JK |
5069 | } |
5070 | ||
ea2b26e0 | 5071 | return 1; |
43f66a6c JK |
5072 | } |
5073 | ||
858119e1 | 5074 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
43f66a6c JK |
5075 | const struct ipw_supported_rates *src) |
5076 | { | |
5077 | u8 i; | |
5078 | for (i = 0; i < src->num_rates; i++) | |
5079 | dest->supported_rates[i] = src->supported_rates[i]; | |
5080 | dest->num_rates = src->num_rates; | |
5081 | } | |
5082 | ||
5083 | /* TODO: Look at sniffed packets in the air to determine if the basic rate | |
5084 | * mask should ever be used -- right now all callers to add the scan rates are | |
5085 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ | |
5086 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, | |
0edd5b44 | 5087 | u8 modulation, u32 rate_mask) |
43f66a6c | 5088 | { |
bf79451e | 5089 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
0edd5b44 | 5090 | IEEE80211_BASIC_RATE_MASK : 0; |
bf79451e | 5091 | |
43f66a6c | 5092 | if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK) |
bf79451e | 5093 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5094 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; |
43f66a6c JK |
5095 | |
5096 | if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK) | |
bf79451e | 5097 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5098 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; |
43f66a6c JK |
5099 | |
5100 | if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK) | |
bf79451e | 5101 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5102 | IEEE80211_CCK_RATE_5MB; |
43f66a6c JK |
5103 | |
5104 | if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) | |
bf79451e | 5105 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5106 | IEEE80211_CCK_RATE_11MB; |
43f66a6c JK |
5107 | } |
5108 | ||
5109 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, | |
0edd5b44 | 5110 | u8 modulation, u32 rate_mask) |
43f66a6c | 5111 | { |
bf79451e | 5112 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
0edd5b44 | 5113 | IEEE80211_BASIC_RATE_MASK : 0; |
43f66a6c JK |
5114 | |
5115 | if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) | |
bf79451e | 5116 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5117 | IEEE80211_OFDM_RATE_6MB; |
43f66a6c JK |
5118 | |
5119 | if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) | |
bf79451e | 5120 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5121 | IEEE80211_OFDM_RATE_9MB; |
43f66a6c JK |
5122 | |
5123 | if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) | |
bf79451e | 5124 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5125 | IEEE80211_OFDM_RATE_12MB; |
43f66a6c JK |
5126 | |
5127 | if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) | |
bf79451e | 5128 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5129 | IEEE80211_OFDM_RATE_18MB; |
43f66a6c JK |
5130 | |
5131 | if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) | |
bf79451e | 5132 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5133 | IEEE80211_OFDM_RATE_24MB; |
43f66a6c JK |
5134 | |
5135 | if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) | |
bf79451e | 5136 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5137 | IEEE80211_OFDM_RATE_36MB; |
43f66a6c JK |
5138 | |
5139 | if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) | |
bf79451e | 5140 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5141 | IEEE80211_OFDM_RATE_48MB; |
43f66a6c JK |
5142 | |
5143 | if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) | |
bf79451e | 5144 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5145 | IEEE80211_OFDM_RATE_54MB; |
43f66a6c JK |
5146 | } |
5147 | ||
5148 | struct ipw_network_match { | |
5149 | struct ieee80211_network *network; | |
5150 | struct ipw_supported_rates rates; | |
5151 | }; | |
5152 | ||
c848d0af JK |
5153 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
5154 | struct ipw_network_match *match, | |
5155 | struct ieee80211_network *network, | |
5156 | int roaming) | |
43f66a6c JK |
5157 | { |
5158 | struct ipw_supported_rates rates; | |
5159 | ||
5160 | /* Verify that this network's capability is compatible with the | |
5161 | * current mode (AdHoc or Infrastructure) */ | |
c848d0af | 5162 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
43f66a6c | 5163 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
c848d0af | 5164 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to " |
bf79451e | 5165 | "capability mismatch.\n", |
43f66a6c JK |
5166 | escape_essid(network->ssid, network->ssid_len), |
5167 | MAC_ARG(network->bssid)); | |
5168 | return 0; | |
5169 | } | |
5170 | ||
5171 | /* If we do not have an ESSID for this AP, we can not associate with | |
5172 | * it */ | |
5173 | if (network->flags & NETWORK_EMPTY_ESSID) { | |
c848d0af | 5174 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5175 | "because of hidden ESSID.\n", |
5176 | escape_essid(network->ssid, network->ssid_len), | |
5177 | MAC_ARG(network->bssid)); | |
5178 | return 0; | |
5179 | } | |
bf79451e | 5180 | |
43f66a6c JK |
5181 | if (unlikely(roaming)) { |
5182 | /* If we are roaming, then ensure check if this is a valid | |
5183 | * network to try and roam to */ | |
5184 | if ((network->ssid_len != match->network->ssid_len) || | |
bf79451e | 5185 | memcmp(network->ssid, match->network->ssid, |
43f66a6c | 5186 | network->ssid_len)) { |
c848d0af | 5187 | IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded " |
43f66a6c | 5188 | "because of non-network ESSID.\n", |
bf79451e | 5189 | escape_essid(network->ssid, |
43f66a6c JK |
5190 | network->ssid_len), |
5191 | MAC_ARG(network->bssid)); | |
5192 | return 0; | |
5193 | } | |
5194 | } else { | |
bf79451e JG |
5195 | /* If an ESSID has been configured then compare the broadcast |
5196 | * ESSID to ours */ | |
5197 | if ((priv->config & CFG_STATIC_ESSID) && | |
43f66a6c | 5198 | ((network->ssid_len != priv->essid_len) || |
bf79451e | 5199 | memcmp(network->ssid, priv->essid, |
43f66a6c JK |
5200 | min(network->ssid_len, priv->essid_len)))) { |
5201 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | |
afbf30a2 | 5202 | |
0edd5b44 JG |
5203 | strncpy(escaped, |
5204 | escape_essid(network->ssid, network->ssid_len), | |
43f66a6c | 5205 | sizeof(escaped)); |
c848d0af | 5206 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
bf79451e | 5207 | "because of ESSID mismatch: '%s'.\n", |
43f66a6c | 5208 | escaped, MAC_ARG(network->bssid), |
0edd5b44 JG |
5209 | escape_essid(priv->essid, |
5210 | priv->essid_len)); | |
43f66a6c JK |
5211 | return 0; |
5212 | } | |
5213 | } | |
5214 | ||
5215 | /* If the old network rate is better than this one, don't bother | |
5216 | * testing everything else. */ | |
c848d0af JK |
5217 | |
5218 | if (network->time_stamp[0] < match->network->time_stamp[0]) { | |
afbf30a2 JK |
5219 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
5220 | "current network.\n", | |
43f66a6c | 5221 | escape_essid(match->network->ssid, |
afbf30a2 | 5222 | match->network->ssid_len)); |
43f66a6c | 5223 | return 0; |
c848d0af | 5224 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
afbf30a2 JK |
5225 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
5226 | "current network.\n", | |
5227 | escape_essid(match->network->ssid, | |
5228 | match->network->ssid_len)); | |
43f66a6c JK |
5229 | return 0; |
5230 | } | |
5231 | ||
5232 | /* Now go through and see if the requested network is valid... */ | |
bf79451e | 5233 | if (priv->ieee->scan_age != 0 && |
c848d0af JK |
5234 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
5235 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " | |
c7b6a674 | 5236 | "because of age: %ums.\n", |
43f66a6c JK |
5237 | escape_essid(network->ssid, network->ssid_len), |
5238 | MAC_ARG(network->bssid), | |
2638bc39 ZY |
5239 | jiffies_to_msecs(jiffies - |
5240 | network->last_scanned)); | |
43f66a6c | 5241 | return 0; |
bf79451e | 5242 | } |
43f66a6c | 5243 | |
bf79451e | 5244 | if ((priv->config & CFG_STATIC_CHANNEL) && |
43f66a6c | 5245 | (network->channel != priv->channel)) { |
c848d0af | 5246 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5247 | "because of channel mismatch: %d != %d.\n", |
5248 | escape_essid(network->ssid, network->ssid_len), | |
5249 | MAC_ARG(network->bssid), | |
5250 | network->channel, priv->channel); | |
5251 | return 0; | |
5252 | } | |
bf79451e | 5253 | |
43f66a6c | 5254 | /* Verify privacy compatability */ |
bf79451e | 5255 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
43f66a6c | 5256 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
c848d0af | 5257 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5258 | "because of privacy mismatch: %s != %s.\n", |
5259 | escape_essid(network->ssid, network->ssid_len), | |
5260 | MAC_ARG(network->bssid), | |
afbf30a2 JK |
5261 | priv-> |
5262 | capability & CAP_PRIVACY_ON ? "on" : "off", | |
5263 | network-> | |
5264 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : | |
5265 | "off"); | |
43f66a6c JK |
5266 | return 0; |
5267 | } | |
bf79451e | 5268 | |
c848d0af JK |
5269 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
5270 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " | |
5271 | "because of the same BSSID match: " MAC_FMT | |
5272 | ".\n", escape_essid(network->ssid, | |
5273 | network->ssid_len), | |
0edd5b44 | 5274 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
43f66a6c JK |
5275 | return 0; |
5276 | } | |
bf79451e | 5277 | |
43f66a6c JK |
5278 | /* Filter out any incompatible freq / mode combinations */ |
5279 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { | |
c848d0af | 5280 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5281 | "because of invalid frequency/mode " |
5282 | "combination.\n", | |
5283 | escape_essid(network->ssid, network->ssid_len), | |
5284 | MAC_ARG(network->bssid)); | |
5285 | return 0; | |
5286 | } | |
bf79451e | 5287 | |
c848d0af JK |
5288 | /* Ensure that the rates supported by the driver are compatible with |
5289 | * this AP, including verification of basic rates (mandatory) */ | |
5290 | if (!ipw_compatible_rates(priv, network, &rates)) { | |
5291 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " | |
5292 | "because configured rate mask excludes " | |
5293 | "AP mandatory rate.\n", | |
5294 | escape_essid(network->ssid, network->ssid_len), | |
5295 | MAC_ARG(network->bssid)); | |
5296 | return 0; | |
5297 | } | |
5298 | ||
43f66a6c | 5299 | if (rates.num_rates == 0) { |
c848d0af | 5300 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5301 | "because of no compatible rates.\n", |
5302 | escape_essid(network->ssid, network->ssid_len), | |
5303 | MAC_ARG(network->bssid)); | |
5304 | return 0; | |
5305 | } | |
bf79451e | 5306 | |
43f66a6c JK |
5307 | /* TODO: Perform any further minimal comparititive tests. We do not |
5308 | * want to put too much policy logic here; intelligent scan selection | |
5309 | * should occur within a generic IEEE 802.11 user space tool. */ | |
5310 | ||
5311 | /* Set up 'new' AP to this network */ | |
5312 | ipw_copy_rates(&match->rates, &rates); | |
5313 | match->network = network; | |
c848d0af | 5314 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n", |
43f66a6c JK |
5315 | escape_essid(network->ssid, network->ssid_len), |
5316 | MAC_ARG(network->bssid)); | |
5317 | ||
5318 | return 1; | |
5319 | } | |
5320 | ||
c848d0af | 5321 | static void ipw_merge_adhoc_network(void *data) |
43f66a6c | 5322 | { |
c848d0af JK |
5323 | struct ipw_priv *priv = data; |
5324 | struct ieee80211_network *network = NULL; | |
5325 | struct ipw_network_match match = { | |
5326 | .network = priv->assoc_network | |
5327 | }; | |
5328 | ||
afbf30a2 JK |
5329 | if ((priv->status & STATUS_ASSOCIATED) && |
5330 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { | |
c848d0af JK |
5331 | /* First pass through ROAM process -- look for a better |
5332 | * network */ | |
5333 | unsigned long flags; | |
5334 | ||
5335 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
5336 | list_for_each_entry(network, &priv->ieee->network_list, list) { | |
5337 | if (network != priv->assoc_network) | |
5338 | ipw_find_adhoc_network(priv, &match, network, | |
5339 | 1); | |
5340 | } | |
5341 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
5342 | ||
5343 | if (match.network == priv->assoc_network) { | |
5344 | IPW_DEBUG_MERGE("No better ADHOC in this network to " | |
5345 | "merge to.\n"); | |
5346 | return; | |
5347 | } | |
5348 | ||
4644151b | 5349 | mutex_lock(&priv->mutex); |
c848d0af JK |
5350 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
5351 | IPW_DEBUG_MERGE("remove network %s\n", | |
5352 | escape_essid(priv->essid, | |
5353 | priv->essid_len)); | |
5354 | ipw_remove_current_network(priv); | |
43f66a6c | 5355 | } |
c848d0af JK |
5356 | |
5357 | ipw_disassociate(priv); | |
5358 | priv->assoc_network = match.network; | |
4644151b | 5359 | mutex_unlock(&priv->mutex); |
c848d0af | 5360 | return; |
43f66a6c | 5361 | } |
c848d0af | 5362 | } |
43f66a6c | 5363 | |
0edd5b44 JG |
5364 | static int ipw_best_network(struct ipw_priv *priv, |
5365 | struct ipw_network_match *match, | |
5366 | struct ieee80211_network *network, int roaming) | |
43f66a6c JK |
5367 | { |
5368 | struct ipw_supported_rates rates; | |
5369 | ||
5370 | /* Verify that this network's capability is compatible with the | |
5371 | * current mode (AdHoc or Infrastructure) */ | |
5372 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && | |
2474385e | 5373 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
43f66a6c JK |
5374 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
5375 | !(network->capability & WLAN_CAPABILITY_IBSS))) { | |
5376 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to " | |
bf79451e | 5377 | "capability mismatch.\n", |
43f66a6c JK |
5378 | escape_essid(network->ssid, network->ssid_len), |
5379 | MAC_ARG(network->bssid)); | |
5380 | return 0; | |
5381 | } | |
5382 | ||
5383 | /* If we do not have an ESSID for this AP, we can not associate with | |
5384 | * it */ | |
5385 | if (network->flags & NETWORK_EMPTY_ESSID) { | |
5386 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5387 | "because of hidden ESSID.\n", | |
5388 | escape_essid(network->ssid, network->ssid_len), | |
5389 | MAC_ARG(network->bssid)); | |
5390 | return 0; | |
5391 | } | |
bf79451e | 5392 | |
43f66a6c JK |
5393 | if (unlikely(roaming)) { |
5394 | /* If we are roaming, then ensure check if this is a valid | |
5395 | * network to try and roam to */ | |
5396 | if ((network->ssid_len != match->network->ssid_len) || | |
bf79451e | 5397 | memcmp(network->ssid, match->network->ssid, |
43f66a6c JK |
5398 | network->ssid_len)) { |
5399 | IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded " | |
5400 | "because of non-network ESSID.\n", | |
bf79451e | 5401 | escape_essid(network->ssid, |
43f66a6c JK |
5402 | network->ssid_len), |
5403 | MAC_ARG(network->bssid)); | |
5404 | return 0; | |
5405 | } | |
5406 | } else { | |
bf79451e JG |
5407 | /* If an ESSID has been configured then compare the broadcast |
5408 | * ESSID to ours */ | |
5409 | if ((priv->config & CFG_STATIC_ESSID) && | |
43f66a6c | 5410 | ((network->ssid_len != priv->essid_len) || |
bf79451e | 5411 | memcmp(network->ssid, priv->essid, |
43f66a6c JK |
5412 | min(network->ssid_len, priv->essid_len)))) { |
5413 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | |
0edd5b44 JG |
5414 | strncpy(escaped, |
5415 | escape_essid(network->ssid, network->ssid_len), | |
43f66a6c JK |
5416 | sizeof(escaped)); |
5417 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
bf79451e | 5418 | "because of ESSID mismatch: '%s'.\n", |
43f66a6c | 5419 | escaped, MAC_ARG(network->bssid), |
0edd5b44 JG |
5420 | escape_essid(priv->essid, |
5421 | priv->essid_len)); | |
43f66a6c JK |
5422 | return 0; |
5423 | } | |
5424 | } | |
5425 | ||
5426 | /* If the old network rate is better than this one, don't bother | |
5427 | * testing everything else. */ | |
0edd5b44 | 5428 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
43f66a6c | 5429 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
bf79451e JG |
5430 | strncpy(escaped, |
5431 | escape_essid(network->ssid, network->ssid_len), | |
43f66a6c JK |
5432 | sizeof(escaped)); |
5433 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because " | |
5434 | "'%s (" MAC_FMT ")' has a stronger signal.\n", | |
5435 | escaped, MAC_ARG(network->bssid), | |
5436 | escape_essid(match->network->ssid, | |
5437 | match->network->ssid_len), | |
5438 | MAC_ARG(match->network->bssid)); | |
5439 | return 0; | |
5440 | } | |
bf79451e | 5441 | |
43f66a6c JK |
5442 | /* If this network has already had an association attempt within the |
5443 | * last 3 seconds, do not try and associate again... */ | |
5444 | if (network->last_associate && | |
ea2b26e0 | 5445 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
43f66a6c | 5446 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
c7b6a674 | 5447 | "because of storming (%ums since last " |
43f66a6c JK |
5448 | "assoc attempt).\n", |
5449 | escape_essid(network->ssid, network->ssid_len), | |
5450 | MAC_ARG(network->bssid), | |
2638bc39 ZY |
5451 | jiffies_to_msecs(jiffies - |
5452 | network->last_associate)); | |
43f66a6c JK |
5453 | return 0; |
5454 | } | |
5455 | ||
5456 | /* Now go through and see if the requested network is valid... */ | |
bf79451e | 5457 | if (priv->ieee->scan_age != 0 && |
ea2b26e0 | 5458 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
43f66a6c | 5459 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
c7b6a674 | 5460 | "because of age: %ums.\n", |
43f66a6c JK |
5461 | escape_essid(network->ssid, network->ssid_len), |
5462 | MAC_ARG(network->bssid), | |
2638bc39 ZY |
5463 | jiffies_to_msecs(jiffies - |
5464 | network->last_scanned)); | |
43f66a6c | 5465 | return 0; |
bf79451e | 5466 | } |
43f66a6c | 5467 | |
bf79451e | 5468 | if ((priv->config & CFG_STATIC_CHANNEL) && |
43f66a6c JK |
5469 | (network->channel != priv->channel)) { |
5470 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5471 | "because of channel mismatch: %d != %d.\n", | |
5472 | escape_essid(network->ssid, network->ssid_len), | |
5473 | MAC_ARG(network->bssid), | |
5474 | network->channel, priv->channel); | |
5475 | return 0; | |
5476 | } | |
bf79451e | 5477 | |
43f66a6c | 5478 | /* Verify privacy compatability */ |
bf79451e | 5479 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
43f66a6c JK |
5480 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
5481 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5482 | "because of privacy mismatch: %s != %s.\n", | |
5483 | escape_essid(network->ssid, network->ssid_len), | |
5484 | MAC_ARG(network->bssid), | |
bf79451e | 5485 | priv->capability & CAP_PRIVACY_ON ? "on" : |
43f66a6c | 5486 | "off", |
bf79451e | 5487 | network->capability & |
0edd5b44 | 5488 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
43f66a6c JK |
5489 | return 0; |
5490 | } | |
bf79451e JG |
5491 | |
5492 | if ((priv->config & CFG_STATIC_BSSID) && | |
43f66a6c JK |
5493 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
5494 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5495 | "because of BSSID mismatch: " MAC_FMT ".\n", | |
5496 | escape_essid(network->ssid, network->ssid_len), | |
0edd5b44 | 5497 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
43f66a6c JK |
5498 | return 0; |
5499 | } | |
bf79451e | 5500 | |
43f66a6c JK |
5501 | /* Filter out any incompatible freq / mode combinations */ |
5502 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { | |
5503 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5504 | "because of invalid frequency/mode " | |
5505 | "combination.\n", | |
5506 | escape_essid(network->ssid, network->ssid_len), | |
5507 | MAC_ARG(network->bssid)); | |
5508 | return 0; | |
5509 | } | |
bf79451e | 5510 | |
1fe0adb4 | 5511 | /* Filter out invalid channel in current GEO */ |
1867b117 | 5512 | if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) { |
1fe0adb4 LH |
5513 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
5514 | "because of invalid channel in current GEO\n", | |
5515 | escape_essid(network->ssid, network->ssid_len), | |
5516 | MAC_ARG(network->bssid)); | |
5517 | return 0; | |
5518 | } | |
5519 | ||
ea2b26e0 JK |
5520 | /* Ensure that the rates supported by the driver are compatible with |
5521 | * this AP, including verification of basic rates (mandatory) */ | |
5522 | if (!ipw_compatible_rates(priv, network, &rates)) { | |
5523 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5524 | "because configured rate mask excludes " | |
5525 | "AP mandatory rate.\n", | |
5526 | escape_essid(network->ssid, network->ssid_len), | |
5527 | MAC_ARG(network->bssid)); | |
5528 | return 0; | |
5529 | } | |
5530 | ||
43f66a6c JK |
5531 | if (rates.num_rates == 0) { |
5532 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5533 | "because of no compatible rates.\n", | |
5534 | escape_essid(network->ssid, network->ssid_len), | |
5535 | MAC_ARG(network->bssid)); | |
5536 | return 0; | |
5537 | } | |
bf79451e | 5538 | |
43f66a6c JK |
5539 | /* TODO: Perform any further minimal comparititive tests. We do not |
5540 | * want to put too much policy logic here; intelligent scan selection | |
5541 | * should occur within a generic IEEE 802.11 user space tool. */ | |
5542 | ||
5543 | /* Set up 'new' AP to this network */ | |
5544 | ipw_copy_rates(&match->rates, &rates); | |
5545 | match->network = network; | |
5546 | ||
5547 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n", | |
5548 | escape_essid(network->ssid, network->ssid_len), | |
5549 | MAC_ARG(network->bssid)); | |
5550 | ||
5551 | return 1; | |
5552 | } | |
5553 | ||
bf79451e | 5554 | static void ipw_adhoc_create(struct ipw_priv *priv, |
0edd5b44 | 5555 | struct ieee80211_network *network) |
43f66a6c | 5556 | { |
1867b117 | 5557 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
afbf30a2 JK |
5558 | int i; |
5559 | ||
43f66a6c JK |
5560 | /* |
5561 | * For the purposes of scanning, we can set our wireless mode | |
5562 | * to trigger scans across combinations of bands, but when it | |
5563 | * comes to creating a new ad-hoc network, we have tell the FW | |
5564 | * exactly which band to use. | |
5565 | * | |
bf79451e | 5566 | * We also have the possibility of an invalid channel for the |
43f66a6c JK |
5567 | * chossen band. Attempting to create a new ad-hoc network |
5568 | * with an invalid channel for wireless mode will trigger a | |
5569 | * FW fatal error. | |
afbf30a2 | 5570 | * |
43f66a6c | 5571 | */ |
1867b117 | 5572 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
afbf30a2 JK |
5573 | case IEEE80211_52GHZ_BAND: |
5574 | network->mode = IEEE_A; | |
1867b117 | 5575 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
afbf30a2 JK |
5576 | if (i == -1) |
5577 | BUG(); | |
5578 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { | |
5579 | IPW_WARNING("Overriding invalid channel\n"); | |
5580 | priv->channel = geo->a[0].channel; | |
5581 | } | |
5582 | break; | |
5583 | ||
5584 | case IEEE80211_24GHZ_BAND: | |
5585 | if (priv->ieee->mode & IEEE_G) | |
5586 | network->mode = IEEE_G; | |
5587 | else | |
5588 | network->mode = IEEE_B; | |
1867b117 | 5589 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
1fe0adb4 LH |
5590 | if (i == -1) |
5591 | BUG(); | |
5592 | if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) { | |
5593 | IPW_WARNING("Overriding invalid channel\n"); | |
5594 | priv->channel = geo->bg[0].channel; | |
5595 | } | |
afbf30a2 JK |
5596 | break; |
5597 | ||
5598 | default: | |
43f66a6c JK |
5599 | IPW_WARNING("Overriding invalid channel\n"); |
5600 | if (priv->ieee->mode & IEEE_A) { | |
5601 | network->mode = IEEE_A; | |
b095c381 | 5602 | priv->channel = geo->a[0].channel; |
43f66a6c JK |
5603 | } else if (priv->ieee->mode & IEEE_G) { |
5604 | network->mode = IEEE_G; | |
b095c381 | 5605 | priv->channel = geo->bg[0].channel; |
43f66a6c JK |
5606 | } else { |
5607 | network->mode = IEEE_B; | |
b095c381 | 5608 | priv->channel = geo->bg[0].channel; |
43f66a6c | 5609 | } |
afbf30a2 JK |
5610 | break; |
5611 | } | |
43f66a6c JK |
5612 | |
5613 | network->channel = priv->channel; | |
5614 | priv->config |= CFG_ADHOC_PERSIST; | |
5615 | ipw_create_bssid(priv, network->bssid); | |
5616 | network->ssid_len = priv->essid_len; | |
5617 | memcpy(network->ssid, priv->essid, priv->essid_len); | |
5618 | memset(&network->stats, 0, sizeof(network->stats)); | |
5619 | network->capability = WLAN_CAPABILITY_IBSS; | |
ea2b26e0 JK |
5620 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
5621 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; | |
43f66a6c JK |
5622 | if (priv->capability & CAP_PRIVACY_ON) |
5623 | network->capability |= WLAN_CAPABILITY_PRIVACY; | |
5624 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); | |
0edd5b44 | 5625 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
43f66a6c | 5626 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
bf79451e | 5627 | memcpy(network->rates_ex, |
43f66a6c JK |
5628 | &priv->rates.supported_rates[network->rates_len], |
5629 | network->rates_ex_len); | |
5630 | network->last_scanned = 0; | |
5631 | network->flags = 0; | |
5632 | network->last_associate = 0; | |
5633 | network->time_stamp[0] = 0; | |
5634 | network->time_stamp[1] = 0; | |
0edd5b44 JG |
5635 | network->beacon_interval = 100; /* Default */ |
5636 | network->listen_interval = 10; /* Default */ | |
5637 | network->atim_window = 0; /* Default */ | |
43f66a6c JK |
5638 | network->wpa_ie_len = 0; |
5639 | network->rsn_ie_len = 0; | |
43f66a6c JK |
5640 | } |
5641 | ||
b095c381 JK |
5642 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
5643 | { | |
0a7bcf26 | 5644 | struct ipw_tgi_tx_key key; |
b095c381 JK |
5645 | |
5646 | if (!(priv->ieee->sec.flags & (1 << index))) | |
5647 | return; | |
5648 | ||
0a7bcf26 ZY |
5649 | key.key_id = index; |
5650 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); | |
5651 | key.security_type = type; | |
5652 | key.station_index = 0; /* always 0 for BSS */ | |
5653 | key.flags = 0; | |
b095c381 | 5654 | /* 0 for new key; previous value of counter (after fatal error) */ |
0a7bcf26 ZY |
5655 | key.tx_counter[0] = 0; |
5656 | key.tx_counter[1] = 0; | |
b095c381 | 5657 | |
0a7bcf26 | 5658 | ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key); |
b095c381 JK |
5659 | } |
5660 | ||
5661 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) | |
43f66a6c | 5662 | { |
0a7bcf26 | 5663 | struct ipw_wep_key key; |
43f66a6c | 5664 | int i; |
43f66a6c | 5665 | |
0a7bcf26 ZY |
5666 | key.cmd_id = DINO_CMD_WEP_KEY; |
5667 | key.seq_num = 0; | |
43f66a6c | 5668 | |
b095c381 JK |
5669 | /* Note: AES keys cannot be set for multiple times. |
5670 | * Only set it at the first time. */ | |
bf79451e | 5671 | for (i = 0; i < 4; i++) { |
0a7bcf26 | 5672 | key.key_index = i | type; |
b095c381 | 5673 | if (!(priv->ieee->sec.flags & (1 << i))) { |
0a7bcf26 | 5674 | key.key_size = 0; |
b095c381 | 5675 | continue; |
43f66a6c JK |
5676 | } |
5677 | ||
0a7bcf26 ZY |
5678 | key.key_size = priv->ieee->sec.key_sizes[i]; |
5679 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); | |
b095c381 | 5680 | |
0a7bcf26 | 5681 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
bf79451e | 5682 | } |
43f66a6c JK |
5683 | } |
5684 | ||
1fbfea54 | 5685 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
43f66a6c | 5686 | { |
1fbfea54 | 5687 | if (priv->ieee->host_encrypt) |
43f66a6c | 5688 | return; |
43f66a6c | 5689 | |
1fbfea54 ZY |
5690 | switch (level) { |
5691 | case SEC_LEVEL_3: | |
5692 | priv->sys_config.disable_unicast_decryption = 0; | |
5693 | priv->ieee->host_decrypt = 0; | |
5694 | break; | |
5695 | case SEC_LEVEL_2: | |
5696 | priv->sys_config.disable_unicast_decryption = 1; | |
5697 | priv->ieee->host_decrypt = 1; | |
5698 | break; | |
5699 | case SEC_LEVEL_1: | |
5700 | priv->sys_config.disable_unicast_decryption = 0; | |
5701 | priv->ieee->host_decrypt = 0; | |
5702 | break; | |
5703 | case SEC_LEVEL_0: | |
5704 | priv->sys_config.disable_unicast_decryption = 1; | |
5705 | break; | |
5706 | default: | |
5707 | break; | |
5708 | } | |
5709 | } | |
5710 | ||
5711 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) | |
5712 | { | |
5713 | if (priv->ieee->host_encrypt) | |
5714 | return; | |
5715 | ||
5716 | switch (level) { | |
5717 | case SEC_LEVEL_3: | |
5718 | priv->sys_config.disable_multicast_decryption = 0; | |
5719 | break; | |
5720 | case SEC_LEVEL_2: | |
5721 | priv->sys_config.disable_multicast_decryption = 1; | |
5722 | break; | |
5723 | case SEC_LEVEL_1: | |
5724 | priv->sys_config.disable_multicast_decryption = 0; | |
5725 | break; | |
5726 | case SEC_LEVEL_0: | |
5727 | priv->sys_config.disable_multicast_decryption = 1; | |
5728 | break; | |
5729 | default: | |
5730 | break; | |
5731 | } | |
5732 | } | |
5733 | ||
b095c381 JK |
5734 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
5735 | { | |
5736 | switch (priv->ieee->sec.level) { | |
5737 | case SEC_LEVEL_3: | |
d8bad6df ZY |
5738 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
5739 | ipw_send_tgi_tx_key(priv, | |
5740 | DCT_FLAG_EXT_SECURITY_CCM, | |
5741 | priv->ieee->sec.active_key); | |
afbf30a2 | 5742 | |
567deaf6 HL |
5743 | if (!priv->ieee->host_mc_decrypt) |
5744 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); | |
b095c381 JK |
5745 | break; |
5746 | case SEC_LEVEL_2: | |
d8bad6df ZY |
5747 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
5748 | ipw_send_tgi_tx_key(priv, | |
5749 | DCT_FLAG_EXT_SECURITY_TKIP, | |
5750 | priv->ieee->sec.active_key); | |
b095c381 JK |
5751 | break; |
5752 | case SEC_LEVEL_1: | |
5753 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); | |
29cb843e HL |
5754 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
5755 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); | |
b095c381 JK |
5756 | break; |
5757 | case SEC_LEVEL_0: | |
5758 | default: | |
5759 | break; | |
5760 | } | |
5761 | } | |
5762 | ||
43f66a6c JK |
5763 | static void ipw_adhoc_check(void *data) |
5764 | { | |
5765 | struct ipw_priv *priv = data; | |
bf79451e | 5766 | |
afbf30a2 | 5767 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
43f66a6c | 5768 | !(priv->config & CFG_ADHOC_PERSIST)) { |
afbf30a2 JK |
5769 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
5770 | IPW_DL_STATE | IPW_DL_ASSOC, | |
5771 | "Missed beacon: %d - disassociate\n", | |
5772 | priv->missed_adhoc_beacons); | |
43f66a6c JK |
5773 | ipw_remove_current_network(priv); |
5774 | ipw_disassociate(priv); | |
5775 | return; | |
5776 | } | |
5777 | ||
bf79451e | 5778 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
43f66a6c JK |
5779 | priv->assoc_request.beacon_interval); |
5780 | } | |
5781 | ||
c848d0af JK |
5782 | static void ipw_bg_adhoc_check(void *data) |
5783 | { | |
5784 | struct ipw_priv *priv = data; | |
4644151b | 5785 | mutex_lock(&priv->mutex); |
c848d0af | 5786 | ipw_adhoc_check(data); |
4644151b | 5787 | mutex_unlock(&priv->mutex); |
c848d0af JK |
5788 | } |
5789 | ||
0f52bf90 | 5790 | #ifdef CONFIG_IPW2200_DEBUG |
43f66a6c JK |
5791 | static void ipw_debug_config(struct ipw_priv *priv) |
5792 | { | |
5793 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " | |
5794 | "[CFG 0x%08X]\n", priv->config); | |
5795 | if (priv->config & CFG_STATIC_CHANNEL) | |
0edd5b44 | 5796 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
43f66a6c JK |
5797 | else |
5798 | IPW_DEBUG_INFO("Channel unlocked.\n"); | |
5799 | if (priv->config & CFG_STATIC_ESSID) | |
bf79451e | 5800 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
0edd5b44 | 5801 | escape_essid(priv->essid, priv->essid_len)); |
43f66a6c JK |
5802 | else |
5803 | IPW_DEBUG_INFO("ESSID unlocked.\n"); | |
5804 | if (priv->config & CFG_STATIC_BSSID) | |
ea2b26e0 JK |
5805 | IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n", |
5806 | MAC_ARG(priv->bssid)); | |
43f66a6c JK |
5807 | else |
5808 | IPW_DEBUG_INFO("BSSID unlocked.\n"); | |
5809 | if (priv->capability & CAP_PRIVACY_ON) | |
5810 | IPW_DEBUG_INFO("PRIVACY on\n"); | |
5811 | else | |
5812 | IPW_DEBUG_INFO("PRIVACY off\n"); | |
5813 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); | |
5814 | } | |
5815 | #else | |
8d45ff7d | 5816 | #define ipw_debug_config(x) do {} while (0) |
43f66a6c JK |
5817 | #endif |
5818 | ||
858119e1 | 5819 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
43f66a6c JK |
5820 | { |
5821 | /* TODO: Verify that this works... */ | |
5822 | struct ipw_fixed_rate fr = { | |
5823 | .tx_rates = priv->rates_mask | |
5824 | }; | |
5825 | u32 reg; | |
5826 | u16 mask = 0; | |
5827 | ||
bf79451e | 5828 | /* Identify 'current FW band' and match it with the fixed |
43f66a6c | 5829 | * Tx rates */ |
bf79451e | 5830 | |
43f66a6c | 5831 | switch (priv->ieee->freq_band) { |
0edd5b44 | 5832 | case IEEE80211_52GHZ_BAND: /* A only */ |
43f66a6c JK |
5833 | /* IEEE_A */ |
5834 | if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { | |
5835 | /* Invalid fixed rate mask */ | |
ea2b26e0 JK |
5836 | IPW_DEBUG_WX |
5837 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | |
43f66a6c JK |
5838 | fr.tx_rates = 0; |
5839 | break; | |
5840 | } | |
bf79451e | 5841 | |
43f66a6c JK |
5842 | fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; |
5843 | break; | |
5844 | ||
0edd5b44 | 5845 | default: /* 2.4Ghz or Mixed */ |
43f66a6c | 5846 | /* IEEE_B */ |
b095c381 | 5847 | if (mode == IEEE_B) { |
43f66a6c JK |
5848 | if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { |
5849 | /* Invalid fixed rate mask */ | |
ea2b26e0 JK |
5850 | IPW_DEBUG_WX |
5851 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | |
43f66a6c JK |
5852 | fr.tx_rates = 0; |
5853 | } | |
5854 | break; | |
bf79451e | 5855 | } |
43f66a6c JK |
5856 | |
5857 | /* IEEE_G */ | |
5858 | if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | | |
5859 | IEEE80211_OFDM_RATES_MASK)) { | |
5860 | /* Invalid fixed rate mask */ | |
ea2b26e0 JK |
5861 | IPW_DEBUG_WX |
5862 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | |
43f66a6c JK |
5863 | fr.tx_rates = 0; |
5864 | break; | |
5865 | } | |
bf79451e | 5866 | |
43f66a6c JK |
5867 | if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) { |
5868 | mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1); | |
5869 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK; | |
5870 | } | |
bf79451e | 5871 | |
43f66a6c JK |
5872 | if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) { |
5873 | mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1); | |
5874 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK; | |
5875 | } | |
bf79451e | 5876 | |
43f66a6c JK |
5877 | if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) { |
5878 | mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1); | |
5879 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK; | |
5880 | } | |
bf79451e | 5881 | |
43f66a6c JK |
5882 | fr.tx_rates |= mask; |
5883 | break; | |
5884 | } | |
5885 | ||
5886 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); | |
0edd5b44 | 5887 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
43f66a6c JK |
5888 | } |
5889 | ||
ea2b26e0 | 5890 | static void ipw_abort_scan(struct ipw_priv *priv) |
43f66a6c JK |
5891 | { |
5892 | int err; | |
5893 | ||
ea2b26e0 JK |
5894 | if (priv->status & STATUS_SCAN_ABORTING) { |
5895 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); | |
5896 | return; | |
5897 | } | |
5898 | priv->status |= STATUS_SCAN_ABORTING; | |
43f66a6c | 5899 | |
ea2b26e0 JK |
5900 | err = ipw_send_scan_abort(priv); |
5901 | if (err) | |
5902 | IPW_DEBUG_HC("Request to abort scan failed.\n"); | |
5903 | } | |
5904 | ||
afbf30a2 JK |
5905 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
5906 | struct ipw_scan_request_ext *scan, | |
5907 | int scan_type) | |
ea2b26e0 | 5908 | { |
ea2b26e0 | 5909 | int channel_index = 0; |
b095c381 | 5910 | const struct ieee80211_geo *geo; |
afbf30a2 | 5911 | int i; |
b095c381 | 5912 | |
1867b117 | 5913 | geo = ieee80211_get_geo(priv->ieee); |
43f66a6c | 5914 | |
afbf30a2 JK |
5915 | if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { |
5916 | int start = channel_index; | |
5917 | for (i = 0; i < geo->a_channels; i++) { | |
5918 | if ((priv->status & STATUS_ASSOCIATED) && | |
5919 | geo->a[i].channel == priv->channel) | |
5920 | continue; | |
5921 | channel_index++; | |
5922 | scan->channels_list[channel_index] = geo->a[i].channel; | |
1fe0adb4 LH |
5923 | ipw_set_scan_type(scan, channel_index, |
5924 | geo->a[i]. | |
5925 | flags & IEEE80211_CH_PASSIVE_ONLY ? | |
5926 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : | |
5927 | scan_type); | |
afbf30a2 JK |
5928 | } |
5929 | ||
5930 | if (start != channel_index) { | |
5931 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | | |
5932 | (channel_index - start); | |
5933 | channel_index++; | |
5934 | } | |
5935 | } | |
5936 | ||
5937 | if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { | |
5938 | int start = channel_index; | |
5939 | if (priv->config & CFG_SPEED_SCAN) { | |
1fe0adb4 | 5940 | int index; |
afbf30a2 JK |
5941 | u8 channels[IEEE80211_24GHZ_CHANNELS] = { |
5942 | /* nop out the list */ | |
5943 | [0] = 0 | |
5944 | }; | |
5945 | ||
5946 | u8 channel; | |
5947 | while (channel_index < IPW_SCAN_CHANNELS) { | |
5948 | channel = | |
5949 | priv->speed_scan[priv->speed_scan_pos]; | |
5950 | if (channel == 0) { | |
5951 | priv->speed_scan_pos = 0; | |
5952 | channel = priv->speed_scan[0]; | |
5953 | } | |
5954 | if ((priv->status & STATUS_ASSOCIATED) && | |
5955 | channel == priv->channel) { | |
5956 | priv->speed_scan_pos++; | |
5957 | continue; | |
5958 | } | |
5959 | ||
5960 | /* If this channel has already been | |
5961 | * added in scan, break from loop | |
5962 | * and this will be the first channel | |
5963 | * in the next scan. | |
5964 | */ | |
5965 | if (channels[channel - 1] != 0) | |
5966 | break; | |
5967 | ||
5968 | channels[channel - 1] = 1; | |
5969 | priv->speed_scan_pos++; | |
5970 | channel_index++; | |
5971 | scan->channels_list[channel_index] = channel; | |
1fe0adb4 | 5972 | index = |
1867b117 | 5973 | ieee80211_channel_to_index(priv->ieee, channel); |
afbf30a2 | 5974 | ipw_set_scan_type(scan, channel_index, |
1fe0adb4 LH |
5975 | geo->bg[index]. |
5976 | flags & | |
5977 | IEEE80211_CH_PASSIVE_ONLY ? | |
5978 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN | |
5979 | : scan_type); | |
afbf30a2 JK |
5980 | } |
5981 | } else { | |
5982 | for (i = 0; i < geo->bg_channels; i++) { | |
5983 | if ((priv->status & STATUS_ASSOCIATED) && | |
5984 | geo->bg[i].channel == priv->channel) | |
5985 | continue; | |
5986 | channel_index++; | |
5987 | scan->channels_list[channel_index] = | |
5988 | geo->bg[i].channel; | |
5989 | ipw_set_scan_type(scan, channel_index, | |
1fe0adb4 LH |
5990 | geo->bg[i]. |
5991 | flags & | |
5992 | IEEE80211_CH_PASSIVE_ONLY ? | |
5993 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN | |
5994 | : scan_type); | |
afbf30a2 JK |
5995 | } |
5996 | } | |
5997 | ||
5998 | if (start != channel_index) { | |
5999 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | | |
6000 | (channel_index - start); | |
6001 | } | |
6002 | } | |
6003 | } | |
6004 | ||
6005 | static int ipw_request_scan(struct ipw_priv *priv) | |
6006 | { | |
6007 | struct ipw_scan_request_ext scan; | |
6008 | int err = 0, scan_type; | |
6009 | ||
6010 | if (!(priv->status & STATUS_INIT) || | |
6011 | (priv->status & STATUS_EXIT_PENDING)) | |
6012 | return 0; | |
6013 | ||
4644151b | 6014 | mutex_lock(&priv->mutex); |
afbf30a2 | 6015 | |
ea2b26e0 | 6016 | if (priv->status & STATUS_SCANNING) { |
a613bffd | 6017 | IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n"); |
ea2b26e0 | 6018 | priv->status |= STATUS_SCAN_PENDING; |
b095c381 | 6019 | goto done; |
ea2b26e0 | 6020 | } |
43f66a6c | 6021 | |
afbf30a2 JK |
6022 | if (!(priv->status & STATUS_SCAN_FORCED) && |
6023 | priv->status & STATUS_SCAN_ABORTING) { | |
ea2b26e0 JK |
6024 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
6025 | priv->status |= STATUS_SCAN_PENDING; | |
b095c381 | 6026 | goto done; |
43f66a6c JK |
6027 | } |
6028 | ||
ea2b26e0 JK |
6029 | if (priv->status & STATUS_RF_KILL_MASK) { |
6030 | IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n"); | |
6031 | priv->status |= STATUS_SCAN_PENDING; | |
b095c381 | 6032 | goto done; |
ea2b26e0 | 6033 | } |
43f66a6c | 6034 | |
ea2b26e0 | 6035 | memset(&scan, 0, sizeof(scan)); |
43f66a6c | 6036 | |
b095c381 JK |
6037 | if (priv->config & CFG_SPEED_SCAN) |
6038 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | |
6039 | cpu_to_le16(30); | |
6040 | else | |
6041 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | |
6042 | cpu_to_le16(20); | |
6043 | ||
a613bffd JK |
6044 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
6045 | cpu_to_le16(20); | |
1fe0adb4 | 6046 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120); |
43f66a6c | 6047 | |
a613bffd | 6048 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
43f66a6c | 6049 | |
b095c381 | 6050 | #ifdef CONFIG_IPW2200_MONITOR |
ea2b26e0 | 6051 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
afbf30a2 | 6052 | u8 channel; |
b095c381 | 6053 | u8 band = 0; |
43f66a6c | 6054 | |
1867b117 | 6055 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
b095c381 | 6056 | case IEEE80211_52GHZ_BAND: |
ea2b26e0 | 6057 | band = (u8) (IPW_A_MODE << 6) | 1; |
b095c381 JK |
6058 | channel = priv->channel; |
6059 | break; | |
ea2b26e0 | 6060 | |
b095c381 | 6061 | case IEEE80211_24GHZ_BAND: |
ea2b26e0 | 6062 | band = (u8) (IPW_B_MODE << 6) | 1; |
b095c381 JK |
6063 | channel = priv->channel; |
6064 | break; | |
ea2b26e0 | 6065 | |
b095c381 | 6066 | default: |
ea2b26e0 JK |
6067 | band = (u8) (IPW_B_MODE << 6) | 1; |
6068 | channel = 9; | |
b095c381 | 6069 | break; |
ea2b26e0 JK |
6070 | } |
6071 | ||
b095c381 JK |
6072 | scan.channels_list[0] = band; |
6073 | scan.channels_list[1] = channel; | |
6074 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); | |
ea2b26e0 | 6075 | |
b095c381 JK |
6076 | /* NOTE: The card will sit on this channel for this time |
6077 | * period. Scan aborts are timing sensitive and frequently | |
6078 | * result in firmware restarts. As such, it is best to | |
6079 | * set a small dwell_time here and just keep re-issuing | |
6080 | * scans. Otherwise fast channel hopping will not actually | |
6081 | * hop channels. | |
6082 | * | |
6083 | * TODO: Move SPEED SCAN support to all modes and bands */ | |
a613bffd JK |
6084 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
6085 | cpu_to_le16(2000); | |
43f66a6c | 6086 | } else { |
b095c381 JK |
6087 | #endif /* CONFIG_IPW2200_MONITOR */ |
6088 | /* If we are roaming, then make this a directed scan for the | |
6089 | * current network. Otherwise, ensure that every other scan | |
6090 | * is a fast channel hop scan */ | |
6091 | if ((priv->status & STATUS_ROAMING) | |
6092 | || (!(priv->status & STATUS_ASSOCIATED) | |
6093 | && (priv->config & CFG_STATIC_ESSID) | |
6094 | && (le32_to_cpu(scan.full_scan_index) % 2))) { | |
ea2b26e0 JK |
6095 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
6096 | if (err) { | |
b095c381 JK |
6097 | IPW_DEBUG_HC("Attempt to send SSID command " |
6098 | "failed.\n"); | |
6099 | goto done; | |
ea2b26e0 | 6100 | } |
43f66a6c | 6101 | |
ea2b26e0 | 6102 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
afbf30a2 | 6103 | } else |
ea2b26e0 | 6104 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
ea2b26e0 | 6105 | |
afbf30a2 | 6106 | ipw_add_scan_channels(priv, &scan, scan_type); |
b095c381 | 6107 | #ifdef CONFIG_IPW2200_MONITOR |
43f66a6c | 6108 | } |
ea2b26e0 | 6109 | #endif |
bf79451e | 6110 | |
ea2b26e0 | 6111 | err = ipw_send_scan_request_ext(priv, &scan); |
43f66a6c | 6112 | if (err) { |
ea2b26e0 | 6113 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
b095c381 | 6114 | goto done; |
43f66a6c JK |
6115 | } |
6116 | ||
ea2b26e0 JK |
6117 | priv->status |= STATUS_SCANNING; |
6118 | priv->status &= ~STATUS_SCAN_PENDING; | |
afbf30a2 JK |
6119 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
6120 | IPW_SCAN_CHECK_WATCHDOG); | |
b095c381 | 6121 | done: |
4644151b | 6122 | mutex_unlock(&priv->mutex); |
b095c381 | 6123 | return err; |
c848d0af JK |
6124 | } |
6125 | ||
6126 | static void ipw_bg_abort_scan(void *data) | |
6127 | { | |
6128 | struct ipw_priv *priv = data; | |
4644151b | 6129 | mutex_lock(&priv->mutex); |
c848d0af | 6130 | ipw_abort_scan(data); |
4644151b | 6131 | mutex_unlock(&priv->mutex); |
c848d0af JK |
6132 | } |
6133 | ||
ea2b26e0 JK |
6134 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
6135 | { | |
b095c381 JK |
6136 | /* This is called when wpa_supplicant loads and closes the driver |
6137 | * interface. */ | |
cdd1fa1e | 6138 | priv->ieee->wpa_enabled = value; |
b095c381 | 6139 | return 0; |
ea2b26e0 JK |
6140 | } |
6141 | ||
ea2b26e0 JK |
6142 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
6143 | { | |
6144 | struct ieee80211_device *ieee = priv->ieee; | |
6145 | struct ieee80211_security sec = { | |
6146 | .flags = SEC_AUTH_MODE, | |
6147 | }; | |
6148 | int ret = 0; | |
6149 | ||
afbf30a2 | 6150 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
ea2b26e0 JK |
6151 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
6152 | ieee->open_wep = 0; | |
afbf30a2 | 6153 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
ea2b26e0 JK |
6154 | sec.auth_mode = WLAN_AUTH_OPEN; |
6155 | ieee->open_wep = 1; | |
3e234b4e ZY |
6156 | } else if (value & IW_AUTH_ALG_LEAP) { |
6157 | sec.auth_mode = WLAN_AUTH_LEAP; | |
6158 | ieee->open_wep = 1; | |
afbf30a2 JK |
6159 | } else |
6160 | return -EINVAL; | |
ea2b26e0 JK |
6161 | |
6162 | if (ieee->set_security) | |
6163 | ieee->set_security(ieee->dev, &sec); | |
6164 | else | |
6165 | ret = -EOPNOTSUPP; | |
6166 | ||
6167 | return ret; | |
6168 | } | |
6169 | ||
a73e22b2 AB |
6170 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
6171 | int wpa_ie_len) | |
afbf30a2 JK |
6172 | { |
6173 | /* make sure WPA is enabled */ | |
6174 | ipw_wpa_enable(priv, 1); | |
6175 | ||
6176 | ipw_disassociate(priv); | |
6177 | } | |
6178 | ||
6179 | static int ipw_set_rsn_capa(struct ipw_priv *priv, | |
6180 | char *capabilities, int length) | |
6181 | { | |
afbf30a2 JK |
6182 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
6183 | ||
0a7bcf26 | 6184 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
2638bc39 | 6185 | capabilities); |
afbf30a2 JK |
6186 | } |
6187 | ||
b095c381 | 6188 | /* |
afbf30a2 JK |
6189 | * WE-18 support |
6190 | */ | |
6191 | ||
6192 | /* SIOCSIWGENIE */ | |
6193 | static int ipw_wx_set_genie(struct net_device *dev, | |
6194 | struct iw_request_info *info, | |
6195 | union iwreq_data *wrqu, char *extra) | |
ea2b26e0 | 6196 | { |
afbf30a2 JK |
6197 | struct ipw_priv *priv = ieee80211_priv(dev); |
6198 | struct ieee80211_device *ieee = priv->ieee; | |
6199 | u8 *buf; | |
6200 | int err = 0; | |
ea2b26e0 | 6201 | |
afbf30a2 JK |
6202 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
6203 | (wrqu->data.length && extra == NULL)) | |
6204 | return -EINVAL; | |
ea2b26e0 | 6205 | |
4644151b | 6206 | //mutex_lock(&priv->mutex); |
afbf30a2 JK |
6207 | |
6208 | //if (!ieee->wpa_enabled) { | |
6209 | // err = -EOPNOTSUPP; | |
6210 | // goto out; | |
6211 | //} | |
6212 | ||
6213 | if (wrqu->data.length) { | |
6214 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); | |
6215 | if (buf == NULL) { | |
6216 | err = -ENOMEM; | |
6217 | goto out; | |
6218 | } | |
6219 | ||
6220 | memcpy(buf, extra, wrqu->data.length); | |
6221 | kfree(ieee->wpa_ie); | |
6222 | ieee->wpa_ie = buf; | |
6223 | ieee->wpa_ie_len = wrqu->data.length; | |
b095c381 | 6224 | } else { |
afbf30a2 JK |
6225 | kfree(ieee->wpa_ie); |
6226 | ieee->wpa_ie = NULL; | |
6227 | ieee->wpa_ie_len = 0; | |
ea2b26e0 | 6228 | } |
afbf30a2 JK |
6229 | |
6230 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); | |
6231 | out: | |
4644151b | 6232 | //mutex_unlock(&priv->mutex); |
afbf30a2 JK |
6233 | return err; |
6234 | } | |
6235 | ||
6236 | /* SIOCGIWGENIE */ | |
6237 | static int ipw_wx_get_genie(struct net_device *dev, | |
6238 | struct iw_request_info *info, | |
6239 | union iwreq_data *wrqu, char *extra) | |
6240 | { | |
6241 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6242 | struct ieee80211_device *ieee = priv->ieee; | |
6243 | int err = 0; | |
6244 | ||
4644151b | 6245 | //mutex_lock(&priv->mutex); |
afbf30a2 JK |
6246 | |
6247 | //if (!ieee->wpa_enabled) { | |
6248 | // err = -EOPNOTSUPP; | |
6249 | // goto out; | |
6250 | //} | |
6251 | ||
6252 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { | |
6253 | wrqu->data.length = 0; | |
6254 | goto out; | |
6255 | } | |
6256 | ||
6257 | if (wrqu->data.length < ieee->wpa_ie_len) { | |
6258 | err = -E2BIG; | |
6259 | goto out; | |
6260 | } | |
6261 | ||
6262 | wrqu->data.length = ieee->wpa_ie_len; | |
6263 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); | |
6264 | ||
6265 | out: | |
4644151b | 6266 | //mutex_unlock(&priv->mutex); |
afbf30a2 JK |
6267 | return err; |
6268 | } | |
6269 | ||
1fbfea54 ZY |
6270 | static int wext_cipher2level(int cipher) |
6271 | { | |
6272 | switch (cipher) { | |
6273 | case IW_AUTH_CIPHER_NONE: | |
6274 | return SEC_LEVEL_0; | |
6275 | case IW_AUTH_CIPHER_WEP40: | |
6276 | case IW_AUTH_CIPHER_WEP104: | |
6277 | return SEC_LEVEL_1; | |
6278 | case IW_AUTH_CIPHER_TKIP: | |
6279 | return SEC_LEVEL_2; | |
6280 | case IW_AUTH_CIPHER_CCMP: | |
6281 | return SEC_LEVEL_3; | |
6282 | default: | |
6283 | return -1; | |
6284 | } | |
6285 | } | |
6286 | ||
afbf30a2 JK |
6287 | /* SIOCSIWAUTH */ |
6288 | static int ipw_wx_set_auth(struct net_device *dev, | |
6289 | struct iw_request_info *info, | |
6290 | union iwreq_data *wrqu, char *extra) | |
6291 | { | |
6292 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6293 | struct ieee80211_device *ieee = priv->ieee; | |
6294 | struct iw_param *param = &wrqu->param; | |
6295 | struct ieee80211_crypt_data *crypt; | |
6296 | unsigned long flags; | |
6297 | int ret = 0; | |
6298 | ||
6299 | switch (param->flags & IW_AUTH_INDEX) { | |
6300 | case IW_AUTH_WPA_VERSION: | |
1fbfea54 | 6301 | break; |
afbf30a2 | 6302 | case IW_AUTH_CIPHER_PAIRWISE: |
1fbfea54 ZY |
6303 | ipw_set_hw_decrypt_unicast(priv, |
6304 | wext_cipher2level(param->value)); | |
6305 | break; | |
afbf30a2 | 6306 | case IW_AUTH_CIPHER_GROUP: |
1fbfea54 ZY |
6307 | ipw_set_hw_decrypt_multicast(priv, |
6308 | wext_cipher2level(param->value)); | |
6309 | break; | |
afbf30a2 JK |
6310 | case IW_AUTH_KEY_MGMT: |
6311 | /* | |
6312 | * ipw2200 does not use these parameters | |
6313 | */ | |
6314 | break; | |
6315 | ||
6316 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
6317 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; | |
991d1cc5 | 6318 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
afbf30a2 | 6319 | break; |
afbf30a2 JK |
6320 | |
6321 | flags = crypt->ops->get_flags(crypt->priv); | |
6322 | ||
6323 | if (param->value) | |
6324 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | |
6325 | else | |
6326 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | |
6327 | ||
6328 | crypt->ops->set_flags(flags, crypt->priv); | |
6329 | ||
6330 | break; | |
6331 | ||
6332 | case IW_AUTH_DROP_UNENCRYPTED:{ | |
6333 | /* HACK: | |
6334 | * | |
6335 | * wpa_supplicant calls set_wpa_enabled when the driver | |
6336 | * is loaded and unloaded, regardless of if WPA is being | |
6337 | * used. No other calls are made which can be used to | |
6338 | * determine if encryption will be used or not prior to | |
6339 | * association being expected. If encryption is not being | |
6340 | * used, drop_unencrypted is set to false, else true -- we | |
6341 | * can use this to determine if the CAP_PRIVACY_ON bit should | |
6342 | * be set. | |
6343 | */ | |
6344 | struct ieee80211_security sec = { | |
6345 | .flags = SEC_ENABLED, | |
6346 | .enabled = param->value, | |
6347 | }; | |
6348 | priv->ieee->drop_unencrypted = param->value; | |
6349 | /* We only change SEC_LEVEL for open mode. Others | |
6350 | * are set by ipw_wpa_set_encryption. | |
6351 | */ | |
6352 | if (!param->value) { | |
6353 | sec.flags |= SEC_LEVEL; | |
6354 | sec.level = SEC_LEVEL_0; | |
6355 | } else { | |
6356 | sec.flags |= SEC_LEVEL; | |
6357 | sec.level = SEC_LEVEL_1; | |
6358 | } | |
6359 | if (priv->ieee->set_security) | |
6360 | priv->ieee->set_security(priv->ieee->dev, &sec); | |
6361 | break; | |
6362 | } | |
6363 | ||
6364 | case IW_AUTH_80211_AUTH_ALG: | |
6365 | ret = ipw_wpa_set_auth_algs(priv, param->value); | |
6366 | break; | |
6367 | ||
6368 | case IW_AUTH_WPA_ENABLED: | |
6369 | ret = ipw_wpa_enable(priv, param->value); | |
6370 | break; | |
6371 | ||
6372 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
6373 | ieee->ieee802_1x = param->value; | |
6374 | break; | |
6375 | ||
6376 | //case IW_AUTH_ROAMING_CONTROL: | |
6377 | case IW_AUTH_PRIVACY_INVOKED: | |
6378 | ieee->privacy_invoked = param->value; | |
6379 | break; | |
6380 | ||
6381 | default: | |
6382 | return -EOPNOTSUPP; | |
6383 | } | |
6384 | return ret; | |
6385 | } | |
6386 | ||
6387 | /* SIOCGIWAUTH */ | |
6388 | static int ipw_wx_get_auth(struct net_device *dev, | |
6389 | struct iw_request_info *info, | |
6390 | union iwreq_data *wrqu, char *extra) | |
6391 | { | |
6392 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6393 | struct ieee80211_device *ieee = priv->ieee; | |
6394 | struct ieee80211_crypt_data *crypt; | |
6395 | struct iw_param *param = &wrqu->param; | |
6396 | int ret = 0; | |
6397 | ||
6398 | switch (param->flags & IW_AUTH_INDEX) { | |
6399 | case IW_AUTH_WPA_VERSION: | |
6400 | case IW_AUTH_CIPHER_PAIRWISE: | |
6401 | case IW_AUTH_CIPHER_GROUP: | |
6402 | case IW_AUTH_KEY_MGMT: | |
6403 | /* | |
6404 | * wpa_supplicant will control these internally | |
6405 | */ | |
6406 | ret = -EOPNOTSUPP; | |
6407 | break; | |
6408 | ||
6409 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
6410 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; | |
991d1cc5 | 6411 | if (!crypt || !crypt->ops->get_flags) |
afbf30a2 | 6412 | break; |
afbf30a2 JK |
6413 | |
6414 | param->value = (crypt->ops->get_flags(crypt->priv) & | |
6415 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; | |
6416 | ||
6417 | break; | |
6418 | ||
6419 | case IW_AUTH_DROP_UNENCRYPTED: | |
6420 | param->value = ieee->drop_unencrypted; | |
6421 | break; | |
6422 | ||
6423 | case IW_AUTH_80211_AUTH_ALG: | |
6424 | param->value = ieee->sec.auth_mode; | |
6425 | break; | |
6426 | ||
6427 | case IW_AUTH_WPA_ENABLED: | |
6428 | param->value = ieee->wpa_enabled; | |
6429 | break; | |
6430 | ||
6431 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
6432 | param->value = ieee->ieee802_1x; | |
6433 | break; | |
6434 | ||
6435 | case IW_AUTH_ROAMING_CONTROL: | |
6436 | case IW_AUTH_PRIVACY_INVOKED: | |
6437 | param->value = ieee->privacy_invoked; | |
6438 | break; | |
6439 | ||
6440 | default: | |
6441 | return -EOPNOTSUPP; | |
6442 | } | |
6443 | return 0; | |
6444 | } | |
6445 | ||
6446 | /* SIOCSIWENCODEEXT */ | |
6447 | static int ipw_wx_set_encodeext(struct net_device *dev, | |
6448 | struct iw_request_info *info, | |
6449 | union iwreq_data *wrqu, char *extra) | |
6450 | { | |
6451 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6452 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
6453 | ||
6454 | if (hwcrypto) { | |
afbf30a2 | 6455 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
567deaf6 HL |
6456 | /* IPW HW can't build TKIP MIC, |
6457 | host decryption still needed */ | |
6458 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) | |
6459 | priv->ieee->host_mc_decrypt = 1; | |
6460 | else { | |
6461 | priv->ieee->host_encrypt = 0; | |
6462 | priv->ieee->host_encrypt_msdu = 1; | |
6463 | priv->ieee->host_decrypt = 1; | |
6464 | } | |
afbf30a2 JK |
6465 | } else { |
6466 | priv->ieee->host_encrypt = 0; | |
6467 | priv->ieee->host_encrypt_msdu = 0; | |
6468 | priv->ieee->host_decrypt = 0; | |
567deaf6 | 6469 | priv->ieee->host_mc_decrypt = 0; |
afbf30a2 JK |
6470 | } |
6471 | } | |
6472 | ||
6473 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); | |
6474 | } | |
6475 | ||
6476 | /* SIOCGIWENCODEEXT */ | |
6477 | static int ipw_wx_get_encodeext(struct net_device *dev, | |
6478 | struct iw_request_info *info, | |
6479 | union iwreq_data *wrqu, char *extra) | |
6480 | { | |
6481 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6482 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); | |
6483 | } | |
6484 | ||
6485 | /* SIOCSIWMLME */ | |
6486 | static int ipw_wx_set_mlme(struct net_device *dev, | |
6487 | struct iw_request_info *info, | |
6488 | union iwreq_data *wrqu, char *extra) | |
6489 | { | |
6490 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6491 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | |
6492 | u16 reason; | |
6493 | ||
6494 | reason = cpu_to_le16(mlme->reason_code); | |
6495 | ||
6496 | switch (mlme->cmd) { | |
6497 | case IW_MLME_DEAUTH: | |
6498 | // silently ignore | |
6499 | break; | |
6500 | ||
6501 | case IW_MLME_DISASSOC: | |
6502 | ipw_disassociate(priv); | |
6503 | break; | |
6504 | ||
6505 | default: | |
6506 | return -EOPNOTSUPP; | |
6507 | } | |
6508 | return 0; | |
6509 | } | |
afbf30a2 JK |
6510 | |
6511 | #ifdef CONFIG_IPW_QOS | |
6512 | ||
6513 | /* QoS */ | |
6514 | /* | |
6515 | * get the modulation type of the current network or | |
6516 | * the card current mode | |
6517 | */ | |
53d0bcf8 | 6518 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
afbf30a2 JK |
6519 | { |
6520 | u8 mode = 0; | |
6521 | ||
6522 | if (priv->status & STATUS_ASSOCIATED) { | |
6523 | unsigned long flags; | |
6524 | ||
6525 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
6526 | mode = priv->assoc_network->mode; | |
6527 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
6528 | } else { | |
6529 | mode = priv->ieee->mode; | |
6530 | } | |
6531 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); | |
6532 | return mode; | |
b095c381 | 6533 | } |
ea2b26e0 | 6534 | |
b095c381 JK |
6535 | /* |
6536 | * Handle management frame beacon and probe response | |
6537 | */ | |
3b9990cb JK |
6538 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
6539 | int active_network, | |
6540 | struct ieee80211_network *network) | |
b095c381 JK |
6541 | { |
6542 | u32 size = sizeof(struct ieee80211_qos_parameters); | |
6543 | ||
afbf30a2 | 6544 | if (network->capability & WLAN_CAPABILITY_IBSS) |
b095c381 JK |
6545 | network->qos_data.active = network->qos_data.supported; |
6546 | ||
6547 | if (network->flags & NETWORK_HAS_QOS_MASK) { | |
afbf30a2 JK |
6548 | if (active_network && |
6549 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) | |
b095c381 JK |
6550 | network->qos_data.active = network->qos_data.supported; |
6551 | ||
6552 | if ((network->qos_data.active == 1) && (active_network == 1) && | |
6553 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && | |
6554 | (network->qos_data.old_param_count != | |
6555 | network->qos_data.param_count)) { | |
6556 | network->qos_data.old_param_count = | |
6557 | network->qos_data.param_count; | |
6558 | schedule_work(&priv->qos_activate); | |
afbf30a2 JK |
6559 | IPW_DEBUG_QOS("QoS parameters change call " |
6560 | "qos_activate\n"); | |
b095c381 | 6561 | } |
ea2b26e0 | 6562 | } else { |
afbf30a2 JK |
6563 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
6564 | memcpy(&network->qos_data.parameters, | |
b095c381 | 6565 | &def_parameters_CCK, size); |
afbf30a2 JK |
6566 | else |
6567 | memcpy(&network->qos_data.parameters, | |
b095c381 | 6568 | &def_parameters_OFDM, size); |
afbf30a2 | 6569 | |
b095c381 JK |
6570 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
6571 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); | |
6572 | schedule_work(&priv->qos_activate); | |
6573 | } | |
6574 | ||
6575 | network->qos_data.active = 0; | |
6576 | network->qos_data.supported = 0; | |
ea2b26e0 | 6577 | } |
afbf30a2 JK |
6578 | if ((priv->status & STATUS_ASSOCIATED) && |
6579 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { | |
6580 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) | |
6581 | if ((network->capability & WLAN_CAPABILITY_IBSS) && | |
6582 | !(network->flags & NETWORK_EMPTY_ESSID)) | |
b095c381 | 6583 | if ((network->ssid_len == |
afbf30a2 JK |
6584 | priv->assoc_network->ssid_len) && |
6585 | !memcmp(network->ssid, | |
6586 | priv->assoc_network->ssid, | |
6587 | network->ssid_len)) { | |
b095c381 JK |
6588 | queue_work(priv->workqueue, |
6589 | &priv->merge_networks); | |
6590 | } | |
b095c381 | 6591 | } |
ea2b26e0 | 6592 | |
b095c381 JK |
6593 | return 0; |
6594 | } | |
6595 | ||
6596 | /* | |
6597 | * This function set up the firmware to support QoS. It sends | |
6598 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO | |
6599 | */ | |
6600 | static int ipw_qos_activate(struct ipw_priv *priv, | |
6601 | struct ieee80211_qos_data *qos_network_data) | |
6602 | { | |
6603 | int err; | |
6604 | struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS]; | |
6605 | struct ieee80211_qos_parameters *active_one = NULL; | |
6606 | u32 size = sizeof(struct ieee80211_qos_parameters); | |
6607 | u32 burst_duration; | |
6608 | int i; | |
6609 | u8 type; | |
6610 | ||
6611 | type = ipw_qos_current_mode(priv); | |
6612 | ||
6613 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); | |
6614 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); | |
6615 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); | |
6616 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); | |
6617 | ||
6618 | if (qos_network_data == NULL) { | |
6619 | if (type == IEEE_B) { | |
6620 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); | |
6621 | active_one = &def_parameters_CCK; | |
6622 | } else | |
6623 | active_one = &def_parameters_OFDM; | |
6624 | ||
afbf30a2 | 6625 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
b095c381 JK |
6626 | burst_duration = ipw_qos_get_burst_duration(priv); |
6627 | for (i = 0; i < QOS_QUEUE_NUM; i++) | |
afbf30a2 JK |
6628 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
6629 | (u16) burst_duration; | |
6630 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
b095c381 JK |
6631 | if (type == IEEE_B) { |
6632 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", | |
6633 | type); | |
6634 | if (priv->qos_data.qos_enable == 0) | |
6635 | active_one = &def_parameters_CCK; | |
6636 | else | |
6637 | active_one = priv->qos_data.def_qos_parm_CCK; | |
6638 | } else { | |
6639 | if (priv->qos_data.qos_enable == 0) | |
6640 | active_one = &def_parameters_OFDM; | |
6641 | else | |
6642 | active_one = priv->qos_data.def_qos_parm_OFDM; | |
6643 | } | |
afbf30a2 | 6644 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
b095c381 JK |
6645 | } else { |
6646 | unsigned long flags; | |
6647 | int active; | |
6648 | ||
6649 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
6650 | active_one = &(qos_network_data->parameters); | |
6651 | qos_network_data->old_param_count = | |
6652 | qos_network_data->param_count; | |
afbf30a2 | 6653 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
b095c381 JK |
6654 | active = qos_network_data->supported; |
6655 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
6656 | ||
6657 | if (active == 0) { | |
6658 | burst_duration = ipw_qos_get_burst_duration(priv); | |
6659 | for (i = 0; i < QOS_QUEUE_NUM; i++) | |
6660 | qos_parameters[QOS_PARAM_SET_ACTIVE]. | |
6661 | tx_op_limit[i] = (u16) burst_duration; | |
6662 | } | |
6663 | } | |
6664 | ||
6665 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); | |
afbf30a2 JK |
6666 | err = ipw_send_qos_params_command(priv, |
6667 | (struct ieee80211_qos_parameters *) | |
6668 | &(qos_parameters[0])); | |
b095c381 JK |
6669 | if (err) |
6670 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); | |
6671 | ||
6672 | return err; | |
6673 | } | |
6674 | ||
6675 | /* | |
6676 | * send IPW_CMD_WME_INFO to the firmware | |
6677 | */ | |
6678 | static int ipw_qos_set_info_element(struct ipw_priv *priv) | |
6679 | { | |
6680 | int ret = 0; | |
6681 | struct ieee80211_qos_information_element qos_info; | |
6682 | ||
6683 | if (priv == NULL) | |
6684 | return -1; | |
6685 | ||
6686 | qos_info.elementID = QOS_ELEMENT_ID; | |
6687 | qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2; | |
6688 | ||
6689 | qos_info.version = QOS_VERSION_1; | |
6690 | qos_info.ac_info = 0; | |
6691 | ||
6692 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); | |
6693 | qos_info.qui_type = QOS_OUI_TYPE; | |
6694 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; | |
6695 | ||
6696 | ret = ipw_send_qos_info_command(priv, &qos_info); | |
6697 | if (ret != 0) { | |
6698 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); | |
6699 | } | |
6700 | return ret; | |
6701 | } | |
6702 | ||
6703 | /* | |
6704 | * Set the QoS parameter with the association request structure | |
6705 | */ | |
6706 | static int ipw_qos_association(struct ipw_priv *priv, | |
6707 | struct ieee80211_network *network) | |
6708 | { | |
6709 | int err = 0; | |
6710 | struct ieee80211_qos_data *qos_data = NULL; | |
6711 | struct ieee80211_qos_data ibss_data = { | |
6712 | .supported = 1, | |
6713 | .active = 1, | |
6714 | }; | |
6715 | ||
6716 | switch (priv->ieee->iw_mode) { | |
6717 | case IW_MODE_ADHOC: | |
6718 | if (!(network->capability & WLAN_CAPABILITY_IBSS)) | |
6719 | BUG(); | |
6720 | ||
6721 | qos_data = &ibss_data; | |
6722 | break; | |
6723 | ||
6724 | case IW_MODE_INFRA: | |
6725 | qos_data = &network->qos_data; | |
6726 | break; | |
6727 | ||
6728 | default: | |
6729 | BUG(); | |
6730 | break; | |
6731 | } | |
6732 | ||
6733 | err = ipw_qos_activate(priv, qos_data); | |
6734 | if (err) { | |
6735 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; | |
6736 | return err; | |
6737 | } | |
6738 | ||
6739 | if (priv->qos_data.qos_enable && qos_data->supported) { | |
6740 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); | |
6741 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; | |
6742 | return ipw_qos_set_info_element(priv); | |
6743 | } | |
6744 | ||
6745 | return 0; | |
6746 | } | |
6747 | ||
6748 | /* | |
6749 | * handling the beaconing responces. if we get different QoS setting | |
6750 | * of the network from the the associated setting adjust the QoS | |
6751 | * setting | |
6752 | */ | |
6753 | static int ipw_qos_association_resp(struct ipw_priv *priv, | |
6754 | struct ieee80211_network *network) | |
6755 | { | |
6756 | int ret = 0; | |
6757 | unsigned long flags; | |
6758 | u32 size = sizeof(struct ieee80211_qos_parameters); | |
6759 | int set_qos_param = 0; | |
6760 | ||
afbf30a2 JK |
6761 | if ((priv == NULL) || (network == NULL) || |
6762 | (priv->assoc_network == NULL)) | |
b095c381 JK |
6763 | return ret; |
6764 | ||
6765 | if (!(priv->status & STATUS_ASSOCIATED)) | |
6766 | return ret; | |
6767 | ||
afbf30a2 | 6768 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
b095c381 | 6769 | return ret; |
b095c381 JK |
6770 | |
6771 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
6772 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { | |
afbf30a2 | 6773 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
b095c381 JK |
6774 | sizeof(struct ieee80211_qos_data)); |
6775 | priv->assoc_network->qos_data.active = 1; | |
6776 | if ((network->qos_data.old_param_count != | |
6777 | network->qos_data.param_count)) { | |
6778 | set_qos_param = 1; | |
6779 | network->qos_data.old_param_count = | |
6780 | network->qos_data.param_count; | |
6781 | } | |
6782 | ||
6783 | } else { | |
afbf30a2 JK |
6784 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
6785 | memcpy(&priv->assoc_network->qos_data.parameters, | |
b095c381 | 6786 | &def_parameters_CCK, size); |
afbf30a2 JK |
6787 | else |
6788 | memcpy(&priv->assoc_network->qos_data.parameters, | |
b095c381 | 6789 | &def_parameters_OFDM, size); |
b095c381 JK |
6790 | priv->assoc_network->qos_data.active = 0; |
6791 | priv->assoc_network->qos_data.supported = 0; | |
6792 | set_qos_param = 1; | |
6793 | } | |
6794 | ||
6795 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
6796 | ||
6797 | if (set_qos_param == 1) | |
6798 | schedule_work(&priv->qos_activate); | |
6799 | ||
6800 | return ret; | |
6801 | } | |
6802 | ||
6803 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) | |
6804 | { | |
6805 | u32 ret = 0; | |
6806 | ||
6807 | if ((priv == NULL)) | |
6808 | return 0; | |
6809 | ||
afbf30a2 | 6810 | if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) |
b095c381 | 6811 | ret = priv->qos_data.burst_duration_CCK; |
afbf30a2 | 6812 | else |
b095c381 | 6813 | ret = priv->qos_data.burst_duration_OFDM; |
afbf30a2 | 6814 | |
b095c381 JK |
6815 | return ret; |
6816 | } | |
6817 | ||
6818 | /* | |
6819 | * Initialize the setting of QoS global | |
6820 | */ | |
6821 | static void ipw_qos_init(struct ipw_priv *priv, int enable, | |
6822 | int burst_enable, u32 burst_duration_CCK, | |
6823 | u32 burst_duration_OFDM) | |
6824 | { | |
6825 | priv->qos_data.qos_enable = enable; | |
6826 | ||
6827 | if (priv->qos_data.qos_enable) { | |
6828 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; | |
6829 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; | |
6830 | IPW_DEBUG_QOS("QoS is enabled\n"); | |
6831 | } else { | |
6832 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; | |
6833 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; | |
6834 | IPW_DEBUG_QOS("QoS is not enabled\n"); | |
6835 | } | |
6836 | ||
6837 | priv->qos_data.burst_enable = burst_enable; | |
6838 | ||
6839 | if (burst_enable) { | |
6840 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; | |
6841 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; | |
6842 | } else { | |
6843 | priv->qos_data.burst_duration_CCK = 0; | |
6844 | priv->qos_data.burst_duration_OFDM = 0; | |
6845 | } | |
6846 | } | |
6847 | ||
6848 | /* | |
6849 | * map the packet priority to the right TX Queue | |
6850 | */ | |
6851 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) | |
6852 | { | |
6853 | if (priority > 7 || !priv->qos_data.qos_enable) | |
6854 | priority = 0; | |
6855 | ||
6856 | return from_priority_to_tx_queue[priority] - 1; | |
6857 | } | |
6858 | ||
6859 | /* | |
6860 | * add QoS parameter to the TX command | |
6861 | */ | |
6862 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, | |
6863 | u16 priority, | |
6864 | struct tfd_data *tfd, u8 unicast) | |
6865 | { | |
6866 | int ret = 0; | |
6867 | int tx_queue_id = 0; | |
6868 | struct ieee80211_qos_data *qos_data = NULL; | |
6869 | int active, supported; | |
6870 | unsigned long flags; | |
6871 | ||
6872 | if (!(priv->status & STATUS_ASSOCIATED)) | |
6873 | return 0; | |
6874 | ||
6875 | qos_data = &priv->assoc_network->qos_data; | |
6876 | ||
6877 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
6878 | ||
6879 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
6880 | if (unicast == 0) | |
6881 | qos_data->active = 0; | |
6882 | else | |
6883 | qos_data->active = qos_data->supported; | |
6884 | } | |
6885 | ||
6886 | active = qos_data->active; | |
6887 | supported = qos_data->supported; | |
6888 | ||
6889 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
6890 | ||
afbf30a2 JK |
6891 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
6892 | "unicast %d\n", | |
6893 | priv->qos_data.qos_enable, active, supported, unicast); | |
b095c381 JK |
6894 | if (active && priv->qos_data.qos_enable) { |
6895 | ret = from_priority_to_tx_queue[priority]; | |
6896 | tx_queue_id = ret - 1; | |
6897 | IPW_DEBUG_QOS("QoS packet priority is %d \n", priority); | |
6898 | if (priority <= 7) { | |
6899 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; | |
6900 | tfd->tfd.tfd_26.mchdr.qos_ctrl = priority; | |
6901 | tfd->tfd.tfd_26.mchdr.frame_ctl |= | |
6902 | IEEE80211_STYPE_QOS_DATA; | |
6903 | ||
6904 | if (priv->qos_data.qos_no_ack_mask & | |
6905 | (1UL << tx_queue_id)) { | |
6906 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; | |
6907 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= | |
6908 | CTRL_QOS_NO_ACK; | |
6909 | } | |
6910 | } | |
6911 | } | |
6912 | ||
6913 | return ret; | |
6914 | } | |
6915 | ||
6916 | /* | |
6917 | * background support to run QoS activate functionality | |
6918 | */ | |
6919 | static void ipw_bg_qos_activate(void *data) | |
6920 | { | |
6921 | struct ipw_priv *priv = data; | |
6922 | ||
6923 | if (priv == NULL) | |
6924 | return; | |
6925 | ||
4644151b | 6926 | mutex_lock(&priv->mutex); |
b095c381 JK |
6927 | |
6928 | if (priv->status & STATUS_ASSOCIATED) | |
6929 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); | |
6930 | ||
4644151b | 6931 | mutex_unlock(&priv->mutex); |
b095c381 JK |
6932 | } |
6933 | ||
3b9990cb JK |
6934 | static int ipw_handle_probe_response(struct net_device *dev, |
6935 | struct ieee80211_probe_response *resp, | |
6936 | struct ieee80211_network *network) | |
b095c381 JK |
6937 | { |
6938 | struct ipw_priv *priv = ieee80211_priv(dev); | |
3b9990cb JK |
6939 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
6940 | (network == priv->assoc_network)); | |
43f66a6c | 6941 | |
3b9990cb | 6942 | ipw_qos_handle_probe_response(priv, active_network, network); |
43f66a6c | 6943 | |
3b9990cb JK |
6944 | return 0; |
6945 | } | |
43f66a6c | 6946 | |
3b9990cb JK |
6947 | static int ipw_handle_beacon(struct net_device *dev, |
6948 | struct ieee80211_beacon *resp, | |
6949 | struct ieee80211_network *network) | |
6950 | { | |
6951 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6952 | int active_network = ((priv->status & STATUS_ASSOCIATED) && | |
6953 | (network == priv->assoc_network)); | |
bf79451e | 6954 | |
3b9990cb | 6955 | ipw_qos_handle_probe_response(priv, active_network, network); |
bf79451e | 6956 | |
b095c381 JK |
6957 | return 0; |
6958 | } | |
bf79451e | 6959 | |
3b9990cb JK |
6960 | static int ipw_handle_assoc_response(struct net_device *dev, |
6961 | struct ieee80211_assoc_response *resp, | |
6962 | struct ieee80211_network *network) | |
6963 | { | |
6964 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6965 | ipw_qos_association_resp(priv, network); | |
6966 | return 0; | |
6967 | } | |
43f66a6c | 6968 | |
b095c381 JK |
6969 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
6970 | *qos_param) | |
6971 | { | |
4e22699f ZY |
6972 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
6973 | sizeof(*qos_param) * 3, qos_param); | |
b095c381 JK |
6974 | } |
6975 | ||
6976 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element | |
6977 | *qos_param) | |
6978 | { | |
4e22699f ZY |
6979 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
6980 | qos_param); | |
43f66a6c JK |
6981 | } |
6982 | ||
b095c381 JK |
6983 | #endif /* CONFIG_IPW_QOS */ |
6984 | ||
43f66a6c JK |
6985 | static int ipw_associate_network(struct ipw_priv *priv, |
6986 | struct ieee80211_network *network, | |
0edd5b44 | 6987 | struct ipw_supported_rates *rates, int roaming) |
43f66a6c JK |
6988 | { |
6989 | int err; | |
6990 | ||
6991 | if (priv->config & CFG_FIXED_RATE) | |
b095c381 | 6992 | ipw_set_fixed_rate(priv, network->mode); |
43f66a6c JK |
6993 | |
6994 | if (!(priv->config & CFG_STATIC_ESSID)) { | |
bf79451e | 6995 | priv->essid_len = min(network->ssid_len, |
0edd5b44 | 6996 | (u8) IW_ESSID_MAX_SIZE); |
43f66a6c JK |
6997 | memcpy(priv->essid, network->ssid, priv->essid_len); |
6998 | } | |
6999 | ||
7000 | network->last_associate = jiffies; | |
7001 | ||
7002 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); | |
7003 | priv->assoc_request.channel = network->channel; | |
3e234b4e ZY |
7004 | priv->assoc_request.auth_key = 0; |
7005 | ||
43f66a6c | 7006 | if ((priv->capability & CAP_PRIVACY_ON) && |
3e234b4e | 7007 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
43f66a6c | 7008 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
b095c381 JK |
7009 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
7010 | ||
1ba61e05 | 7011 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
b095c381 | 7012 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
3e234b4e ZY |
7013 | |
7014 | } else if ((priv->capability & CAP_PRIVACY_ON) && | |
7015 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) | |
7016 | priv->assoc_request.auth_type = AUTH_LEAP; | |
7017 | else | |
43f66a6c | 7018 | priv->assoc_request.auth_type = AUTH_OPEN; |
43f66a6c | 7019 | |
b095c381 | 7020 | if (priv->ieee->wpa_ie_len) { |
ea2b26e0 JK |
7021 | priv->assoc_request.policy_support = 0x02; /* RSN active */ |
7022 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, | |
7023 | priv->ieee->wpa_ie_len); | |
7024 | } | |
43f66a6c | 7025 | |
bf79451e JG |
7026 | /* |
7027 | * It is valid for our ieee device to support multiple modes, but | |
7028 | * when it comes to associating to a given network we have to choose | |
43f66a6c JK |
7029 | * just one mode. |
7030 | */ | |
7031 | if (network->mode & priv->ieee->mode & IEEE_A) | |
7032 | priv->assoc_request.ieee_mode = IPW_A_MODE; | |
7033 | else if (network->mode & priv->ieee->mode & IEEE_G) | |
7034 | priv->assoc_request.ieee_mode = IPW_G_MODE; | |
7035 | else if (network->mode & priv->ieee->mode & IEEE_B) | |
7036 | priv->assoc_request.ieee_mode = IPW_B_MODE; | |
7037 | ||
ea2b26e0 JK |
7038 | priv->assoc_request.capability = network->capability; |
7039 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) | |
7040 | && !(priv->config & CFG_PREAMBLE_LONG)) { | |
7041 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; | |
7042 | } else { | |
7043 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; | |
7044 | ||
7045 | /* Clear the short preamble if we won't be supporting it */ | |
7046 | priv->assoc_request.capability &= | |
7047 | ~WLAN_CAPABILITY_SHORT_PREAMBLE; | |
7048 | } | |
7049 | ||
afbf30a2 JK |
7050 | /* Clear capability bits that aren't used in Ad Hoc */ |
7051 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | |
7052 | priv->assoc_request.capability &= | |
7053 | ~WLAN_CAPABILITY_SHORT_SLOT_TIME; | |
7054 | ||
43f66a6c | 7055 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
ea2b26e0 | 7056 | "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n", |
43f66a6c | 7057 | roaming ? "Rea" : "A", |
bf79451e JG |
7058 | escape_essid(priv->essid, priv->essid_len), |
7059 | network->channel, | |
7060 | ipw_modes[priv->assoc_request.ieee_mode], | |
7061 | rates->num_rates, | |
ea2b26e0 JK |
7062 | (priv->assoc_request.preamble_length == |
7063 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", | |
7064 | network->capability & | |
7065 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", | |
43f66a6c | 7066 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
bf79451e JG |
7067 | priv->capability & CAP_PRIVACY_ON ? |
7068 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : | |
43f66a6c JK |
7069 | "(open)") : "", |
7070 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", | |
bf79451e | 7071 | priv->capability & CAP_PRIVACY_ON ? |
b095c381 | 7072 | '1' + priv->ieee->sec.active_key : '.', |
0edd5b44 | 7073 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
43f66a6c JK |
7074 | |
7075 | priv->assoc_request.beacon_interval = network->beacon_interval; | |
7076 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && | |
0edd5b44 | 7077 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
43f66a6c JK |
7078 | priv->assoc_request.assoc_type = HC_IBSS_START; |
7079 | priv->assoc_request.assoc_tsf_msw = 0; | |
7080 | priv->assoc_request.assoc_tsf_lsw = 0; | |
7081 | } else { | |
7082 | if (unlikely(roaming)) | |
7083 | priv->assoc_request.assoc_type = HC_REASSOCIATE; | |
7084 | else | |
7085 | priv->assoc_request.assoc_type = HC_ASSOCIATE; | |
7086 | priv->assoc_request.assoc_tsf_msw = network->time_stamp[1]; | |
7087 | priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0]; | |
7088 | } | |
7089 | ||
afbf30a2 | 7090 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
43f66a6c JK |
7091 | |
7092 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
7093 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); | |
7094 | priv->assoc_request.atim_window = network->atim_window; | |
7095 | } else { | |
afbf30a2 | 7096 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
43f66a6c JK |
7097 | priv->assoc_request.atim_window = 0; |
7098 | } | |
7099 | ||
43f66a6c | 7100 | priv->assoc_request.listen_interval = network->listen_interval; |
bf79451e | 7101 | |
43f66a6c JK |
7102 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
7103 | if (err) { | |
7104 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); | |
7105 | return err; | |
7106 | } | |
7107 | ||
7108 | rates->ieee_mode = priv->assoc_request.ieee_mode; | |
7109 | rates->purpose = IPW_RATE_CONNECT; | |
7110 | ipw_send_supported_rates(priv, rates); | |
bf79451e | 7111 | |
43f66a6c JK |
7112 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
7113 | priv->sys_config.dot11g_auto_detection = 1; | |
7114 | else | |
7115 | priv->sys_config.dot11g_auto_detection = 0; | |
c848d0af JK |
7116 | |
7117 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | |
7118 | priv->sys_config.answer_broadcast_ssid_probe = 1; | |
7119 | else | |
7120 | priv->sys_config.answer_broadcast_ssid_probe = 0; | |
7121 | ||
43f66a6c JK |
7122 | err = ipw_send_system_config(priv, &priv->sys_config); |
7123 | if (err) { | |
7124 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); | |
7125 | return err; | |
7126 | } | |
bf79451e | 7127 | |
43f66a6c | 7128 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
ea2b26e0 | 7129 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
43f66a6c JK |
7130 | if (err) { |
7131 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); | |
7132 | return err; | |
7133 | } | |
7134 | ||
7135 | /* | |
7136 | * If preemption is enabled, it is possible for the association | |
7137 | * to complete before we return from ipw_send_associate. Therefore | |
7138 | * we have to be sure and update our priviate data first. | |
7139 | */ | |
7140 | priv->channel = network->channel; | |
7141 | memcpy(priv->bssid, network->bssid, ETH_ALEN); | |
bf79451e | 7142 | priv->status |= STATUS_ASSOCIATING; |
43f66a6c JK |
7143 | priv->status &= ~STATUS_SECURITY_UPDATED; |
7144 | ||
7145 | priv->assoc_network = network; | |
7146 | ||
b095c381 JK |
7147 | #ifdef CONFIG_IPW_QOS |
7148 | ipw_qos_association(priv, network); | |
7149 | #endif | |
7150 | ||
43f66a6c JK |
7151 | err = ipw_send_associate(priv, &priv->assoc_request); |
7152 | if (err) { | |
7153 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); | |
7154 | return err; | |
7155 | } | |
bf79451e JG |
7156 | |
7157 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n", | |
43f66a6c JK |
7158 | escape_essid(priv->essid, priv->essid_len), |
7159 | MAC_ARG(priv->bssid)); | |
7160 | ||
7161 | return 0; | |
7162 | } | |
7163 | ||
7164 | static void ipw_roam(void *data) | |
7165 | { | |
7166 | struct ipw_priv *priv = data; | |
7167 | struct ieee80211_network *network = NULL; | |
7168 | struct ipw_network_match match = { | |
7169 | .network = priv->assoc_network | |
7170 | }; | |
7171 | ||
7172 | /* The roaming process is as follows: | |
bf79451e JG |
7173 | * |
7174 | * 1. Missed beacon threshold triggers the roaming process by | |
43f66a6c JK |
7175 | * setting the status ROAM bit and requesting a scan. |
7176 | * 2. When the scan completes, it schedules the ROAM work | |
7177 | * 3. The ROAM work looks at all of the known networks for one that | |
7178 | * is a better network than the currently associated. If none | |
7179 | * found, the ROAM process is over (ROAM bit cleared) | |
7180 | * 4. If a better network is found, a disassociation request is | |
7181 | * sent. | |
7182 | * 5. When the disassociation completes, the roam work is again | |
7183 | * scheduled. The second time through, the driver is no longer | |
7184 | * associated, and the newly selected network is sent an | |
bf79451e | 7185 | * association request. |
43f66a6c JK |
7186 | * 6. At this point ,the roaming process is complete and the ROAM |
7187 | * status bit is cleared. | |
7188 | */ | |
7189 | ||
7190 | /* If we are no longer associated, and the roaming bit is no longer | |
7191 | * set, then we are not actively roaming, so just return */ | |
7192 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) | |
7193 | return; | |
bf79451e | 7194 | |
43f66a6c | 7195 | if (priv->status & STATUS_ASSOCIATED) { |
bf79451e | 7196 | /* First pass through ROAM process -- look for a better |
43f66a6c | 7197 | * network */ |
a613bffd | 7198 | unsigned long flags; |
43f66a6c JK |
7199 | u8 rssi = priv->assoc_network->stats.rssi; |
7200 | priv->assoc_network->stats.rssi = -128; | |
a613bffd | 7201 | spin_lock_irqsave(&priv->ieee->lock, flags); |
43f66a6c JK |
7202 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
7203 | if (network != priv->assoc_network) | |
7204 | ipw_best_network(priv, &match, network, 1); | |
7205 | } | |
a613bffd | 7206 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
43f66a6c | 7207 | priv->assoc_network->stats.rssi = rssi; |
bf79451e | 7208 | |
43f66a6c JK |
7209 | if (match.network == priv->assoc_network) { |
7210 | IPW_DEBUG_ASSOC("No better APs in this network to " | |
7211 | "roam to.\n"); | |
7212 | priv->status &= ~STATUS_ROAMING; | |
7213 | ipw_debug_config(priv); | |
7214 | return; | |
7215 | } | |
bf79451e | 7216 | |
43f66a6c JK |
7217 | ipw_send_disassociate(priv, 1); |
7218 | priv->assoc_network = match.network; | |
7219 | ||
7220 | return; | |
bf79451e | 7221 | } |
43f66a6c JK |
7222 | |
7223 | /* Second pass through ROAM process -- request association */ | |
7224 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); | |
7225 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); | |
7226 | priv->status &= ~STATUS_ROAMING; | |
7227 | } | |
7228 | ||
c848d0af JK |
7229 | static void ipw_bg_roam(void *data) |
7230 | { | |
7231 | struct ipw_priv *priv = data; | |
4644151b | 7232 | mutex_lock(&priv->mutex); |
c848d0af | 7233 | ipw_roam(data); |
4644151b | 7234 | mutex_unlock(&priv->mutex); |
c848d0af JK |
7235 | } |
7236 | ||
7237 | static int ipw_associate(void *data) | |
43f66a6c JK |
7238 | { |
7239 | struct ipw_priv *priv = data; | |
7240 | ||
7241 | struct ieee80211_network *network = NULL; | |
7242 | struct ipw_network_match match = { | |
7243 | .network = NULL | |
7244 | }; | |
7245 | struct ipw_supported_rates *rates; | |
7246 | struct list_head *element; | |
a613bffd | 7247 | unsigned long flags; |
43f66a6c | 7248 | |
b095c381 JK |
7249 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
7250 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); | |
7251 | return 0; | |
7252 | } | |
7253 | ||
c848d0af | 7254 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
afbf30a2 JK |
7255 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
7256 | "progress)\n"); | |
c848d0af JK |
7257 | return 0; |
7258 | } | |
7259 | ||
e6324726 HL |
7260 | if (priv->status & STATUS_DISASSOCIATING) { |
7261 | IPW_DEBUG_ASSOC("Not attempting association (in " | |
7262 | "disassociating)\n "); | |
7263 | queue_work(priv->workqueue, &priv->associate); | |
7264 | return 0; | |
7265 | } | |
7266 | ||
c848d0af | 7267 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
afbf30a2 JK |
7268 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
7269 | "initialized)\n"); | |
c848d0af JK |
7270 | return 0; |
7271 | } | |
43f66a6c JK |
7272 | |
7273 | if (!(priv->config & CFG_ASSOCIATE) && | |
7274 | !(priv->config & (CFG_STATIC_ESSID | | |
0edd5b44 | 7275 | CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) { |
43f66a6c | 7276 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
c848d0af | 7277 | return 0; |
43f66a6c JK |
7278 | } |
7279 | ||
a613bffd JK |
7280 | /* Protect our use of the network_list */ |
7281 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
bf79451e | 7282 | list_for_each_entry(network, &priv->ieee->network_list, list) |
0edd5b44 | 7283 | ipw_best_network(priv, &match, network, 0); |
43f66a6c JK |
7284 | |
7285 | network = match.network; | |
7286 | rates = &match.rates; | |
7287 | ||
7288 | if (network == NULL && | |
7289 | priv->ieee->iw_mode == IW_MODE_ADHOC && | |
7290 | priv->config & CFG_ADHOC_CREATE && | |
7291 | priv->config & CFG_STATIC_ESSID && | |
a613bffd | 7292 | priv->config & CFG_STATIC_CHANNEL && |
43f66a6c JK |
7293 | !list_empty(&priv->ieee->network_free_list)) { |
7294 | element = priv->ieee->network_free_list.next; | |
0edd5b44 | 7295 | network = list_entry(element, struct ieee80211_network, list); |
43f66a6c JK |
7296 | ipw_adhoc_create(priv, network); |
7297 | rates = &priv->rates; | |
7298 | list_del(element); | |
7299 | list_add_tail(&network->list, &priv->ieee->network_list); | |
7300 | } | |
a613bffd | 7301 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
bf79451e | 7302 | |
43f66a6c JK |
7303 | /* If we reached the end of the list, then we don't have any valid |
7304 | * matching APs */ | |
7305 | if (!network) { | |
7306 | ipw_debug_config(priv); | |
7307 | ||
b095c381 JK |
7308 | if (!(priv->status & STATUS_SCANNING)) { |
7309 | if (!(priv->config & CFG_SPEED_SCAN)) | |
7310 | queue_delayed_work(priv->workqueue, | |
7311 | &priv->request_scan, | |
7312 | SCAN_INTERVAL); | |
7313 | else | |
7314 | queue_work(priv->workqueue, | |
7315 | &priv->request_scan); | |
7316 | } | |
bf79451e | 7317 | |
c848d0af | 7318 | return 0; |
43f66a6c JK |
7319 | } |
7320 | ||
7321 | ipw_associate_network(priv, network, rates, 0); | |
c848d0af JK |
7322 | |
7323 | return 1; | |
7324 | } | |
7325 | ||
7326 | static void ipw_bg_associate(void *data) | |
7327 | { | |
7328 | struct ipw_priv *priv = data; | |
4644151b | 7329 | mutex_lock(&priv->mutex); |
c848d0af | 7330 | ipw_associate(data); |
4644151b | 7331 | mutex_unlock(&priv->mutex); |
43f66a6c | 7332 | } |
bf79451e | 7333 | |
b095c381 JK |
7334 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
7335 | struct sk_buff *skb) | |
7336 | { | |
7337 | struct ieee80211_hdr *hdr; | |
7338 | u16 fc; | |
7339 | ||
7340 | hdr = (struct ieee80211_hdr *)skb->data; | |
7341 | fc = le16_to_cpu(hdr->frame_ctl); | |
7342 | if (!(fc & IEEE80211_FCTL_PROTECTED)) | |
7343 | return; | |
7344 | ||
7345 | fc &= ~IEEE80211_FCTL_PROTECTED; | |
7346 | hdr->frame_ctl = cpu_to_le16(fc); | |
7347 | switch (priv->ieee->sec.level) { | |
7348 | case SEC_LEVEL_3: | |
7349 | /* Remove CCMP HDR */ | |
7350 | memmove(skb->data + IEEE80211_3ADDR_LEN, | |
7351 | skb->data + IEEE80211_3ADDR_LEN + 8, | |
7352 | skb->len - IEEE80211_3ADDR_LEN - 8); | |
f4ff497d | 7353 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
b095c381 JK |
7354 | break; |
7355 | case SEC_LEVEL_2: | |
7356 | break; | |
7357 | case SEC_LEVEL_1: | |
7358 | /* Remove IV */ | |
7359 | memmove(skb->data + IEEE80211_3ADDR_LEN, | |
7360 | skb->data + IEEE80211_3ADDR_LEN + 4, | |
7361 | skb->len - IEEE80211_3ADDR_LEN - 4); | |
f4ff497d | 7362 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
b095c381 JK |
7363 | break; |
7364 | case SEC_LEVEL_0: | |
7365 | break; | |
7366 | default: | |
7367 | printk(KERN_ERR "Unknow security level %d\n", | |
7368 | priv->ieee->sec.level); | |
7369 | break; | |
7370 | } | |
43f66a6c | 7371 | } |
bf79451e | 7372 | |
b095c381 JK |
7373 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
7374 | struct ipw_rx_mem_buffer *rxb, | |
7375 | struct ieee80211_rx_stats *stats) | |
43f66a6c | 7376 | { |
567deaf6 | 7377 | struct ieee80211_hdr_4addr *hdr; |
43f66a6c JK |
7378 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
7379 | ||
7380 | /* We received data from the HW, so stop the watchdog */ | |
7381 | priv->net_dev->trans_start = jiffies; | |
7382 | ||
bf79451e | 7383 | /* We only process data packets if the |
43f66a6c | 7384 | * interface is open */ |
a613bffd | 7385 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
43f66a6c JK |
7386 | skb_tailroom(rxb->skb))) { |
7387 | priv->ieee->stats.rx_errors++; | |
7388 | priv->wstats.discard.misc++; | |
7389 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); | |
7390 | return; | |
7391 | } else if (unlikely(!netif_running(priv->net_dev))) { | |
7392 | priv->ieee->stats.rx_dropped++; | |
7393 | priv->wstats.discard.misc++; | |
7394 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | |
7395 | return; | |
7396 | } | |
7397 | ||
7398 | /* Advance skb->data to the start of the actual payload */ | |
aaa4d308 | 7399 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
43f66a6c JK |
7400 | |
7401 | /* Set the size of the skb to the size of the frame */ | |
a613bffd | 7402 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
43f66a6c JK |
7403 | |
7404 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); | |
7405 | ||
b095c381 | 7406 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
567deaf6 HL |
7407 | hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data; |
7408 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && | |
3c19065a | 7409 | (is_multicast_ether_addr(hdr->addr1) ? |
567deaf6 | 7410 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
b095c381 JK |
7411 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
7412 | ||
bf79451e | 7413 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
43f66a6c | 7414 | priv->ieee->stats.rx_errors++; |
a613bffd | 7415 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
43f66a6c | 7416 | rxb->skb = NULL; |
b095c381 | 7417 | __ipw_led_activity_on(priv); |
a613bffd | 7418 | } |
43f66a6c JK |
7419 | } |
7420 | ||
24a47dbd MK |
7421 | #ifdef CONFIG_IEEE80211_RADIOTAP |
7422 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, | |
7423 | struct ipw_rx_mem_buffer *rxb, | |
7424 | struct ieee80211_rx_stats *stats) | |
7425 | { | |
7426 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; | |
7427 | struct ipw_rx_frame *frame = &pkt->u.frame; | |
7428 | ||
7429 | /* initial pull of some data */ | |
7430 | u16 received_channel = frame->received_channel; | |
7431 | u8 antennaAndPhy = frame->antennaAndPhy; | |
7432 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ | |
7433 | u16 pktrate = frame->rate; | |
7434 | ||
7435 | /* Magic struct that slots into the radiotap header -- no reason | |
7436 | * to build this manually element by element, we can write it much | |
7437 | * more efficiently than we can parse it. ORDER MATTERS HERE */ | |
7438 | struct ipw_rt_hdr { | |
7439 | struct ieee80211_radiotap_header rt_hdr; | |
7440 | u8 rt_flags; /* radiotap packet flags */ | |
7441 | u8 rt_rate; /* rate in 500kb/s */ | |
7442 | u16 rt_channel; /* channel in mhz */ | |
7443 | u16 rt_chbitmask; /* channel bitfield */ | |
7444 | s8 rt_dbmsignal; /* signal in dbM, kluged to signed */ | |
7445 | u8 rt_antenna; /* antenna number */ | |
7446 | } *ipw_rt; | |
7447 | ||
7448 | short len = le16_to_cpu(pkt->u.frame.length); | |
7449 | ||
7450 | /* We received data from the HW, so stop the watchdog */ | |
7451 | priv->net_dev->trans_start = jiffies; | |
7452 | ||
7453 | /* We only process data packets if the | |
7454 | * interface is open */ | |
7455 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > | |
7456 | skb_tailroom(rxb->skb))) { | |
7457 | priv->ieee->stats.rx_errors++; | |
7458 | priv->wstats.discard.misc++; | |
7459 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); | |
7460 | return; | |
7461 | } else if (unlikely(!netif_running(priv->net_dev))) { | |
7462 | priv->ieee->stats.rx_dropped++; | |
7463 | priv->wstats.discard.misc++; | |
7464 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | |
7465 | return; | |
7466 | } | |
7467 | ||
7468 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use | |
7469 | * that now */ | |
7470 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { | |
7471 | /* FIXME: Should alloc bigger skb instead */ | |
7472 | priv->ieee->stats.rx_dropped++; | |
7473 | priv->wstats.discard.misc++; | |
7474 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); | |
7475 | return; | |
7476 | } | |
7477 | ||
7478 | /* copy the frame itself */ | |
7479 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), | |
7480 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); | |
7481 | ||
7482 | /* Zero the radiotap static buffer ... We only need to zero the bytes NOT | |
7483 | * part of our real header, saves a little time. | |
7484 | * | |
7485 | * No longer necessary since we fill in all our data. Purge before merging | |
7486 | * patch officially. | |
7487 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, | |
7488 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); | |
7489 | */ | |
7490 | ||
7491 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; | |
7492 | ||
7493 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; | |
7494 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ | |
7495 | ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */ | |
7496 | ||
7497 | /* Big bitfield of all the fields we provide in radiotap */ | |
7498 | ipw_rt->rt_hdr.it_present = | |
7499 | ((1 << IEEE80211_RADIOTAP_FLAGS) | | |
7500 | (1 << IEEE80211_RADIOTAP_RATE) | | |
7501 | (1 << IEEE80211_RADIOTAP_CHANNEL) | | |
7502 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | | |
7503 | (1 << IEEE80211_RADIOTAP_ANTENNA)); | |
7504 | ||
7505 | /* Zero the flags, we'll add to them as we go */ | |
7506 | ipw_rt->rt_flags = 0; | |
7507 | ||
7508 | /* Convert signal to DBM */ | |
7509 | ipw_rt->rt_dbmsignal = antsignal; | |
7510 | ||
7511 | /* Convert the channel data and set the flags */ | |
7512 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); | |
7513 | if (received_channel > 14) { /* 802.11a */ | |
7514 | ipw_rt->rt_chbitmask = | |
7515 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); | |
7516 | } else if (antennaAndPhy & 32) { /* 802.11b */ | |
7517 | ipw_rt->rt_chbitmask = | |
7518 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); | |
7519 | } else { /* 802.11g */ | |
7520 | ipw_rt->rt_chbitmask = | |
7521 | (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); | |
7522 | } | |
7523 | ||
7524 | /* set the rate in multiples of 500k/s */ | |
7525 | switch (pktrate) { | |
7526 | case IPW_TX_RATE_1MB: | |
7527 | ipw_rt->rt_rate = 2; | |
7528 | break; | |
7529 | case IPW_TX_RATE_2MB: | |
7530 | ipw_rt->rt_rate = 4; | |
7531 | break; | |
7532 | case IPW_TX_RATE_5MB: | |
7533 | ipw_rt->rt_rate = 10; | |
7534 | break; | |
7535 | case IPW_TX_RATE_6MB: | |
7536 | ipw_rt->rt_rate = 12; | |
7537 | break; | |
7538 | case IPW_TX_RATE_9MB: | |
7539 | ipw_rt->rt_rate = 18; | |
7540 | break; | |
7541 | case IPW_TX_RATE_11MB: | |
7542 | ipw_rt->rt_rate = 22; | |
7543 | break; | |
7544 | case IPW_TX_RATE_12MB: | |
7545 | ipw_rt->rt_rate = 24; | |
7546 | break; | |
7547 | case IPW_TX_RATE_18MB: | |
7548 | ipw_rt->rt_rate = 36; | |
7549 | break; | |
7550 | case IPW_TX_RATE_24MB: | |
7551 | ipw_rt->rt_rate = 48; | |
7552 | break; | |
7553 | case IPW_TX_RATE_36MB: | |
7554 | ipw_rt->rt_rate = 72; | |
7555 | break; | |
7556 | case IPW_TX_RATE_48MB: | |
7557 | ipw_rt->rt_rate = 96; | |
7558 | break; | |
7559 | case IPW_TX_RATE_54MB: | |
7560 | ipw_rt->rt_rate = 108; | |
7561 | break; | |
7562 | default: | |
7563 | ipw_rt->rt_rate = 0; | |
7564 | break; | |
7565 | } | |
7566 | ||
7567 | /* antenna number */ | |
7568 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ | |
7569 | ||
7570 | /* set the preamble flag if we have it */ | |
7571 | if ((antennaAndPhy & 64)) | |
7572 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; | |
7573 | ||
7574 | /* Set the size of the skb to the size of the frame */ | |
7575 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); | |
43f66a6c JK |
7576 | |
7577 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); | |
7578 | ||
bf79451e | 7579 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
43f66a6c | 7580 | priv->ieee->stats.rx_errors++; |
24a47dbd MK |
7581 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
7582 | rxb->skb = NULL; | |
7583 | /* no LED during capture */ | |
7584 | } | |
7585 | } | |
7586 | #endif | |
7587 | ||
858119e1 | 7588 | static int is_network_packet(struct ipw_priv *priv, |
ea2b26e0 JK |
7589 | struct ieee80211_hdr_4addr *header) |
7590 | { | |
7591 | /* Filter incoming packets to determine if they are targetted toward | |
7592 | * this network, discarding packets coming from ourselves */ | |
7593 | switch (priv->ieee->iw_mode) { | |
a613bffd | 7594 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
c848d0af JK |
7595 | /* packets from our adapter are dropped (echo) */ |
7596 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) | |
7597 | return 0; | |
7598 | ||
90700fd9 | 7599 | /* {broad,multi}cast packets to our BSSID go through */ |
3c19065a | 7600 | if (is_multicast_ether_addr(header->addr1)) |
ea2b26e0 | 7601 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
a613bffd JK |
7602 | |
7603 | /* packets to our adapter go through */ | |
7604 | return !memcmp(header->addr1, priv->net_dev->dev_addr, | |
7605 | ETH_ALEN); | |
a613bffd | 7606 | |
90700fd9 | 7607 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
c848d0af JK |
7608 | /* packets from our adapter are dropped (echo) */ |
7609 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) | |
7610 | return 0; | |
7611 | ||
90700fd9 | 7612 | /* {broad,multi}cast packets to our BSS go through */ |
3c19065a | 7613 | if (is_multicast_ether_addr(header->addr1)) |
a613bffd JK |
7614 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
7615 | ||
7616 | /* packets to our adapter go through */ | |
7617 | return !memcmp(header->addr1, priv->net_dev->dev_addr, | |
7618 | ETH_ALEN); | |
ea2b26e0 | 7619 | } |
a613bffd | 7620 | |
ea2b26e0 JK |
7621 | return 1; |
7622 | } | |
7623 | ||
afbf30a2 JK |
7624 | #define IPW_PACKET_RETRY_TIME HZ |
7625 | ||
858119e1 | 7626 | static int is_duplicate_packet(struct ipw_priv *priv, |
afbf30a2 JK |
7627 | struct ieee80211_hdr_4addr *header) |
7628 | { | |
afbf30a2 JK |
7629 | u16 sc = le16_to_cpu(header->seq_ctl); |
7630 | u16 seq = WLAN_GET_SEQ_SEQ(sc); | |
7631 | u16 frag = WLAN_GET_SEQ_FRAG(sc); | |
7632 | u16 *last_seq, *last_frag; | |
7633 | unsigned long *last_time; | |
7634 | ||
7635 | switch (priv->ieee->iw_mode) { | |
7636 | case IW_MODE_ADHOC: | |
7637 | { | |
7638 | struct list_head *p; | |
7639 | struct ipw_ibss_seq *entry = NULL; | |
7640 | u8 *mac = header->addr2; | |
7641 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; | |
7642 | ||
7643 | __list_for_each(p, &priv->ibss_mac_hash[index]) { | |
7644 | entry = | |
7645 | list_entry(p, struct ipw_ibss_seq, list); | |
7646 | if (!memcmp(entry->mac, mac, ETH_ALEN)) | |
7647 | break; | |
7648 | } | |
7649 | if (p == &priv->ibss_mac_hash[index]) { | |
7650 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); | |
7651 | if (!entry) { | |
7652 | IPW_ERROR | |
7653 | ("Cannot malloc new mac entry\n"); | |
7654 | return 0; | |
7655 | } | |
7656 | memcpy(entry->mac, mac, ETH_ALEN); | |
7657 | entry->seq_num = seq; | |
7658 | entry->frag_num = frag; | |
7659 | entry->packet_time = jiffies; | |
7660 | list_add(&entry->list, | |
7661 | &priv->ibss_mac_hash[index]); | |
7662 | return 0; | |
7663 | } | |
7664 | last_seq = &entry->seq_num; | |
7665 | last_frag = &entry->frag_num; | |
7666 | last_time = &entry->packet_time; | |
7667 | break; | |
7668 | } | |
7669 | case IW_MODE_INFRA: | |
7670 | last_seq = &priv->last_seq_num; | |
7671 | last_frag = &priv->last_frag_num; | |
7672 | last_time = &priv->last_packet_time; | |
7673 | break; | |
7674 | default: | |
7675 | return 0; | |
7676 | } | |
7677 | if ((*last_seq == seq) && | |
7678 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { | |
7679 | if (*last_frag == frag) | |
7680 | goto drop; | |
7681 | if (*last_frag + 1 != frag) | |
7682 | /* out-of-order fragment */ | |
7683 | goto drop; | |
afbf30a2 JK |
7684 | } else |
7685 | *last_seq = seq; | |
7686 | ||
f57ce7ce | 7687 | *last_frag = frag; |
afbf30a2 JK |
7688 | *last_time = jiffies; |
7689 | return 0; | |
7690 | ||
7691 | drop: | |
87b016cb ZY |
7692 | /* Comment this line now since we observed the card receives |
7693 | * duplicate packets but the FCTL_RETRY bit is not set in the | |
7694 | * IBSS mode with fragmentation enabled. | |
7695 | BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */ | |
afbf30a2 JK |
7696 | return 1; |
7697 | } | |
7698 | ||
b095c381 JK |
7699 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
7700 | struct ipw_rx_mem_buffer *rxb, | |
7701 | struct ieee80211_rx_stats *stats) | |
7702 | { | |
7703 | struct sk_buff *skb = rxb->skb; | |
7704 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; | |
7705 | struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *) | |
7706 | (skb->data + IPW_RX_FRAME_SIZE); | |
7707 | ||
7708 | ieee80211_rx_mgt(priv->ieee, header, stats); | |
7709 | ||
7710 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && | |
7711 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == | |
7712 | IEEE80211_STYPE_PROBE_RESP) || | |
7713 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == | |
7714 | IEEE80211_STYPE_BEACON))) { | |
7715 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) | |
7716 | ipw_add_station(priv, header->addr2); | |
7717 | } | |
7718 | ||
7719 | if (priv->config & CFG_NET_STATS) { | |
7720 | IPW_DEBUG_HC("sending stat packet\n"); | |
7721 | ||
7722 | /* Set the size of the skb to the size of the full | |
7723 | * ipw header and 802.11 frame */ | |
7724 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + | |
7725 | IPW_RX_FRAME_SIZE); | |
7726 | ||
7727 | /* Advance past the ipw packet header to the 802.11 frame */ | |
7728 | skb_pull(skb, IPW_RX_FRAME_SIZE); | |
7729 | ||
7730 | /* Push the ieee80211_rx_stats before the 802.11 frame */ | |
7731 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); | |
7732 | ||
7733 | skb->dev = priv->ieee->dev; | |
7734 | ||
7735 | /* Point raw at the ieee80211_stats */ | |
7736 | skb->mac.raw = skb->data; | |
7737 | ||
7738 | skb->pkt_type = PACKET_OTHERHOST; | |
7739 | skb->protocol = __constant_htons(ETH_P_80211_STATS); | |
7740 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); | |
7741 | netif_rx(skb); | |
43f66a6c | 7742 | rxb->skb = NULL; |
b095c381 | 7743 | } |
43f66a6c JK |
7744 | } |
7745 | ||
43f66a6c JK |
7746 | /* |
7747 | * Main entry function for recieving a packet with 80211 headers. This | |
7748 | * should be called when ever the FW has notified us that there is a new | |
7749 | * skb in the recieve queue. | |
7750 | */ | |
7751 | static void ipw_rx(struct ipw_priv *priv) | |
7752 | { | |
7753 | struct ipw_rx_mem_buffer *rxb; | |
7754 | struct ipw_rx_packet *pkt; | |
0dacca1f | 7755 | struct ieee80211_hdr_4addr *header; |
43f66a6c JK |
7756 | u32 r, w, i; |
7757 | u8 network_packet; | |
7758 | ||
b095c381 JK |
7759 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
7760 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); | |
43f66a6c JK |
7761 | i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE; |
7762 | ||
7763 | while (i != r) { | |
7764 | rxb = priv->rxq->queue[i]; | |
43f66a6c JK |
7765 | if (unlikely(rxb == NULL)) { |
7766 | printk(KERN_CRIT "Queue not allocated!\n"); | |
7767 | break; | |
7768 | } | |
43f66a6c JK |
7769 | priv->rxq->queue[i] = NULL; |
7770 | ||
7771 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, | |
b095c381 | 7772 | IPW_RX_BUF_SIZE, |
43f66a6c JK |
7773 | PCI_DMA_FROMDEVICE); |
7774 | ||
7775 | pkt = (struct ipw_rx_packet *)rxb->skb->data; | |
7776 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", | |
7777 | pkt->header.message_type, | |
0edd5b44 | 7778 | pkt->header.rx_seq_num, pkt->header.control_bits); |
43f66a6c JK |
7779 | |
7780 | switch (pkt->header.message_type) { | |
0edd5b44 JG |
7781 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
7782 | struct ieee80211_rx_stats stats = { | |
c848d0af JK |
7783 | .rssi = |
7784 | le16_to_cpu(pkt->u.frame.rssi_dbm) - | |
0edd5b44 | 7785 | IPW_RSSI_TO_DBM, |
c848d0af | 7786 | .signal = |
b191608a BM |
7787 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
7788 | IPW_RSSI_TO_DBM + 0x100, | |
c848d0af JK |
7789 | .noise = |
7790 | le16_to_cpu(pkt->u.frame.noise), | |
0edd5b44 JG |
7791 | .rate = pkt->u.frame.rate, |
7792 | .mac_time = jiffies, | |
7793 | .received_channel = | |
7794 | pkt->u.frame.received_channel, | |
7795 | .freq = | |
7796 | (pkt->u.frame. | |
7797 | control & (1 << 0)) ? | |
7798 | IEEE80211_24GHZ_BAND : | |
7799 | IEEE80211_52GHZ_BAND, | |
a613bffd | 7800 | .len = le16_to_cpu(pkt->u.frame.length), |
0edd5b44 JG |
7801 | }; |
7802 | ||
7803 | if (stats.rssi != 0) | |
7804 | stats.mask |= IEEE80211_STATMASK_RSSI; | |
7805 | if (stats.signal != 0) | |
7806 | stats.mask |= IEEE80211_STATMASK_SIGNAL; | |
c848d0af JK |
7807 | if (stats.noise != 0) |
7808 | stats.mask |= IEEE80211_STATMASK_NOISE; | |
0edd5b44 JG |
7809 | if (stats.rate != 0) |
7810 | stats.mask |= IEEE80211_STATMASK_RATE; | |
7811 | ||
7812 | priv->rx_packets++; | |
43f66a6c | 7813 | |
b095c381 | 7814 | #ifdef CONFIG_IPW2200_MONITOR |
0edd5b44 | 7815 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
24a47dbd MK |
7816 | #ifdef CONFIG_IEEE80211_RADIOTAP |
7817 | ipw_handle_data_packet_monitor(priv, | |
7818 | rxb, | |
7819 | &stats); | |
7820 | #else | |
0edd5b44 JG |
7821 | ipw_handle_data_packet(priv, rxb, |
7822 | &stats); | |
24a47dbd | 7823 | #endif |
0edd5b44 JG |
7824 | break; |
7825 | } | |
43f66a6c | 7826 | #endif |
bf79451e | 7827 | |
0edd5b44 | 7828 | header = |
0dacca1f JK |
7829 | (struct ieee80211_hdr_4addr *)(rxb->skb-> |
7830 | data + | |
7831 | IPW_RX_FRAME_SIZE); | |
43f66a6c JK |
7832 | /* TODO: Check Ad-Hoc dest/source and make sure |
7833 | * that we are actually parsing these packets | |
bf79451e | 7834 | * correctly -- we should probably use the |
43f66a6c JK |
7835 | * frame control of the packet and disregard |
7836 | * the current iw_mode */ | |
0edd5b44 | 7837 | |
ea2b26e0 JK |
7838 | network_packet = |
7839 | is_network_packet(priv, header); | |
0edd5b44 JG |
7840 | if (network_packet && priv->assoc_network) { |
7841 | priv->assoc_network->stats.rssi = | |
7842 | stats.rssi; | |
7843 | average_add(&priv->average_rssi, | |
7844 | stats.rssi); | |
7845 | priv->last_rx_rssi = stats.rssi; | |
7846 | } | |
7847 | ||
7848 | IPW_DEBUG_RX("Frame: len=%u\n", | |
a613bffd | 7849 | le16_to_cpu(pkt->u.frame.length)); |
0edd5b44 | 7850 | |
a613bffd | 7851 | if (le16_to_cpu(pkt->u.frame.length) < |
9d0be03a ZY |
7852 | ieee80211_get_hdrlen(le16_to_cpu( |
7853 | header->frame_ctl))) { | |
0edd5b44 JG |
7854 | IPW_DEBUG_DROP |
7855 | ("Received packet is too small. " | |
7856 | "Dropping.\n"); | |
7857 | priv->ieee->stats.rx_errors++; | |
7858 | priv->wstats.discard.misc++; | |
7859 | break; | |
7860 | } | |
7861 | ||
a613bffd JK |
7862 | switch (WLAN_FC_GET_TYPE |
7863 | (le16_to_cpu(header->frame_ctl))) { | |
b095c381 | 7864 | |
0edd5b44 | 7865 | case IEEE80211_FTYPE_MGMT: |
b095c381 JK |
7866 | ipw_handle_mgmt_packet(priv, rxb, |
7867 | &stats); | |
0edd5b44 JG |
7868 | break; |
7869 | ||
7870 | case IEEE80211_FTYPE_CTL: | |
7871 | break; | |
7872 | ||
7873 | case IEEE80211_FTYPE_DATA: | |
afbf30a2 JK |
7874 | if (unlikely(!network_packet || |
7875 | is_duplicate_packet(priv, | |
7876 | header))) | |
7877 | { | |
0edd5b44 JG |
7878 | IPW_DEBUG_DROP("Dropping: " |
7879 | MAC_FMT ", " | |
7880 | MAC_FMT ", " | |
7881 | MAC_FMT "\n", | |
7882 | MAC_ARG(header-> | |
7883 | addr1), | |
7884 | MAC_ARG(header-> | |
7885 | addr2), | |
7886 | MAC_ARG(header-> | |
7887 | addr3)); | |
b095c381 JK |
7888 | break; |
7889 | } | |
7890 | ||
7891 | ipw_handle_data_packet(priv, rxb, | |
7892 | &stats); | |
7893 | ||
0edd5b44 JG |
7894 | break; |
7895 | } | |
43f66a6c JK |
7896 | break; |
7897 | } | |
bf79451e | 7898 | |
0edd5b44 JG |
7899 | case RX_HOST_NOTIFICATION_TYPE:{ |
7900 | IPW_DEBUG_RX | |
7901 | ("Notification: subtype=%02X flags=%02X size=%d\n", | |
43f66a6c JK |
7902 | pkt->u.notification.subtype, |
7903 | pkt->u.notification.flags, | |
7904 | pkt->u.notification.size); | |
0edd5b44 JG |
7905 | ipw_rx_notification(priv, &pkt->u.notification); |
7906 | break; | |
7907 | } | |
43f66a6c JK |
7908 | |
7909 | default: | |
7910 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", | |
7911 | pkt->header.message_type); | |
7912 | break; | |
7913 | } | |
bf79451e JG |
7914 | |
7915 | /* For now we just don't re-use anything. We can tweak this | |
7916 | * later to try and re-use notification packets and SKBs that | |
43f66a6c JK |
7917 | * fail to Rx correctly */ |
7918 | if (rxb->skb != NULL) { | |
7919 | dev_kfree_skb_any(rxb->skb); | |
7920 | rxb->skb = NULL; | |
7921 | } | |
bf79451e | 7922 | |
43f66a6c | 7923 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
b095c381 | 7924 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
43f66a6c | 7925 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
bf79451e | 7926 | |
43f66a6c JK |
7927 | i = (i + 1) % RX_QUEUE_SIZE; |
7928 | } | |
7929 | ||
7930 | /* Backtrack one entry */ | |
7931 | priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1; | |
7932 | ||
7933 | ipw_rx_queue_restock(priv); | |
7934 | } | |
7935 | ||
afbf30a2 JK |
7936 | #define DEFAULT_RTS_THRESHOLD 2304U |
7937 | #define MIN_RTS_THRESHOLD 1U | |
7938 | #define MAX_RTS_THRESHOLD 2304U | |
7939 | #define DEFAULT_BEACON_INTERVAL 100U | |
7940 | #define DEFAULT_SHORT_RETRY_LIMIT 7U | |
7941 | #define DEFAULT_LONG_RETRY_LIMIT 4U | |
7942 | ||
d6d5b5c1 ZY |
7943 | /** |
7944 | * ipw_sw_reset | |
7945 | * @option: options to control different reset behaviour | |
7946 | * 0 = reset everything except the 'disable' module_param | |
7947 | * 1 = reset everything and print out driver info (for probe only) | |
7948 | * 2 = reset everything | |
7949 | */ | |
7950 | static int ipw_sw_reset(struct ipw_priv *priv, int option) | |
43f66a6c | 7951 | { |
afbf30a2 JK |
7952 | int band, modulation; |
7953 | int old_mode = priv->ieee->iw_mode; | |
43f66a6c | 7954 | |
afbf30a2 JK |
7955 | /* Initialize module parameter values here */ |
7956 | priv->config = 0; | |
43f66a6c | 7957 | |
afbf30a2 JK |
7958 | /* We default to disabling the LED code as right now it causes |
7959 | * too many systems to lock up... */ | |
7960 | if (!led) | |
7961 | priv->config |= CFG_NO_LED; | |
43f66a6c | 7962 | |
afbf30a2 JK |
7963 | if (associate) |
7964 | priv->config |= CFG_ASSOCIATE; | |
7965 | else | |
7966 | IPW_DEBUG_INFO("Auto associate disabled.\n"); | |
bf79451e | 7967 | |
afbf30a2 JK |
7968 | if (auto_create) |
7969 | priv->config |= CFG_ADHOC_CREATE; | |
7970 | else | |
7971 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); | |
43f66a6c | 7972 | |
17ed081d ZY |
7973 | priv->config &= ~CFG_STATIC_ESSID; |
7974 | priv->essid_len = 0; | |
7975 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); | |
7976 | ||
d6d5b5c1 | 7977 | if (disable && option) { |
afbf30a2 JK |
7978 | priv->status |= STATUS_RF_KILL_SW; |
7979 | IPW_DEBUG_INFO("Radio disabled.\n"); | |
43f66a6c | 7980 | } |
bf79451e | 7981 | |
afbf30a2 JK |
7982 | if (channel != 0) { |
7983 | priv->config |= CFG_STATIC_CHANNEL; | |
7984 | priv->channel = channel; | |
7985 | IPW_DEBUG_INFO("Bind to static channel %d\n", channel); | |
7986 | /* TODO: Validate that provided channel is in range */ | |
43f66a6c | 7987 | } |
afbf30a2 JK |
7988 | #ifdef CONFIG_IPW_QOS |
7989 | ipw_qos_init(priv, qos_enable, qos_burst_enable, | |
7990 | burst_duration_CCK, burst_duration_OFDM); | |
7991 | #endif /* CONFIG_IPW_QOS */ | |
43f66a6c | 7992 | |
afbf30a2 JK |
7993 | switch (mode) { |
7994 | case 1: | |
7995 | priv->ieee->iw_mode = IW_MODE_ADHOC; | |
7996 | priv->net_dev->type = ARPHRD_ETHER; | |
7997 | ||
7998 | break; | |
7999 | #ifdef CONFIG_IPW2200_MONITOR | |
8000 | case 2: | |
8001 | priv->ieee->iw_mode = IW_MODE_MONITOR; | |
24a47dbd MK |
8002 | #ifdef CONFIG_IEEE80211_RADIOTAP |
8003 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | |
8004 | #else | |
afbf30a2 | 8005 | priv->net_dev->type = ARPHRD_IEEE80211; |
24a47dbd | 8006 | #endif |
afbf30a2 JK |
8007 | break; |
8008 | #endif | |
8009 | default: | |
8010 | case 0: | |
8011 | priv->net_dev->type = ARPHRD_ETHER; | |
8012 | priv->ieee->iw_mode = IW_MODE_INFRA; | |
8013 | break; | |
43f66a6c JK |
8014 | } |
8015 | ||
afbf30a2 JK |
8016 | if (hwcrypto) { |
8017 | priv->ieee->host_encrypt = 0; | |
8018 | priv->ieee->host_encrypt_msdu = 0; | |
8019 | priv->ieee->host_decrypt = 0; | |
567deaf6 | 8020 | priv->ieee->host_mc_decrypt = 0; |
afbf30a2 JK |
8021 | } |
8022 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); | |
43f66a6c | 8023 | |
e402c937 ZY |
8024 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
8025 | priv->ieee->host_open_frag = 0; | |
bf79451e | 8026 | |
afbf30a2 JK |
8027 | if ((priv->pci_dev->device == 0x4223) || |
8028 | (priv->pci_dev->device == 0x4224)) { | |
e8c69e27 | 8029 | if (option == 1) |
afbf30a2 JK |
8030 | printk(KERN_INFO DRV_NAME |
8031 | ": Detected Intel PRO/Wireless 2915ABG Network " | |
8032 | "Connection\n"); | |
8033 | priv->ieee->abg_true = 1; | |
8034 | band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; | |
8035 | modulation = IEEE80211_OFDM_MODULATION | | |
8036 | IEEE80211_CCK_MODULATION; | |
8037 | priv->adapter = IPW_2915ABG; | |
8038 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; | |
43f66a6c | 8039 | } else { |
e8c69e27 | 8040 | if (option == 1) |
afbf30a2 JK |
8041 | printk(KERN_INFO DRV_NAME |
8042 | ": Detected Intel PRO/Wireless 2200BG Network " | |
8043 | "Connection\n"); | |
bf79451e | 8044 | |
afbf30a2 JK |
8045 | priv->ieee->abg_true = 0; |
8046 | band = IEEE80211_24GHZ_BAND; | |
8047 | modulation = IEEE80211_OFDM_MODULATION | | |
8048 | IEEE80211_CCK_MODULATION; | |
8049 | priv->adapter = IPW_2200BG; | |
8050 | priv->ieee->mode = IEEE_G | IEEE_B; | |
43f66a6c JK |
8051 | } |
8052 | ||
afbf30a2 JK |
8053 | priv->ieee->freq_band = band; |
8054 | priv->ieee->modulation = modulation; | |
43f66a6c | 8055 | |
afbf30a2 | 8056 | priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK; |
bf79451e | 8057 | |
afbf30a2 JK |
8058 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
8059 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; | |
43f66a6c | 8060 | |
afbf30a2 JK |
8061 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
8062 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; | |
8063 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; | |
43f66a6c | 8064 | |
afbf30a2 JK |
8065 | /* If power management is turned on, default to AC mode */ |
8066 | priv->power_mode = IPW_POWER_AC; | |
8067 | priv->tx_power = IPW_TX_POWER_DEFAULT; | |
8068 | ||
0ece35b5 | 8069 | return old_mode == priv->ieee->iw_mode; |
43f66a6c JK |
8070 | } |
8071 | ||
8072 | /* | |
8073 | * This file defines the Wireless Extension handlers. It does not | |
8074 | * define any methods of hardware manipulation and relies on the | |
8075 | * functions defined in ipw_main to provide the HW interaction. | |
bf79451e JG |
8076 | * |
8077 | * The exception to this is the use of the ipw_get_ordinal() | |
43f66a6c JK |
8078 | * function used to poll the hardware vs. making unecessary calls. |
8079 | * | |
8080 | */ | |
8081 | ||
bf79451e JG |
8082 | static int ipw_wx_get_name(struct net_device *dev, |
8083 | struct iw_request_info *info, | |
43f66a6c JK |
8084 | union iwreq_data *wrqu, char *extra) |
8085 | { | |
8086 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 8087 | mutex_lock(&priv->mutex); |
c848d0af | 8088 | if (priv->status & STATUS_RF_KILL_MASK) |
a613bffd | 8089 | strcpy(wrqu->name, "radio off"); |
c848d0af | 8090 | else if (!(priv->status & STATUS_ASSOCIATED)) |
43f66a6c | 8091 | strcpy(wrqu->name, "unassociated"); |
bf79451e | 8092 | else |
43f66a6c JK |
8093 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", |
8094 | ipw_modes[priv->assoc_request.ieee_mode]); | |
8095 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); | |
4644151b | 8096 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8097 | return 0; |
8098 | } | |
8099 | ||
8100 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) | |
8101 | { | |
8102 | if (channel == 0) { | |
8103 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); | |
8104 | priv->config &= ~CFG_STATIC_CHANNEL; | |
c848d0af JK |
8105 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
8106 | "parameters.\n"); | |
8107 | ipw_associate(priv); | |
43f66a6c JK |
8108 | return 0; |
8109 | } | |
8110 | ||
8111 | priv->config |= CFG_STATIC_CHANNEL; | |
8112 | ||
8113 | if (priv->channel == channel) { | |
0edd5b44 JG |
8114 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
8115 | channel); | |
43f66a6c JK |
8116 | return 0; |
8117 | } | |
8118 | ||
8119 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); | |
8120 | priv->channel = channel; | |
8121 | ||
b095c381 JK |
8122 | #ifdef CONFIG_IPW2200_MONITOR |
8123 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | |
afbf30a2 | 8124 | int i; |
b095c381 | 8125 | if (priv->status & STATUS_SCANNING) { |
afbf30a2 | 8126 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
b095c381 | 8127 | "channel change.\n"); |
afbf30a2 | 8128 | ipw_abort_scan(priv); |
b095c381 JK |
8129 | } |
8130 | ||
8131 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) | |
8132 | udelay(10); | |
8133 | ||
8134 | if (priv->status & STATUS_SCANNING) | |
8135 | IPW_DEBUG_SCAN("Still scanning...\n"); | |
8136 | else | |
8137 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", | |
8138 | 1000 - i); | |
8139 | ||
8140 | return 0; | |
43f66a6c | 8141 | } |
b095c381 JK |
8142 | #endif /* CONFIG_IPW2200_MONITOR */ |
8143 | ||
c848d0af JK |
8144 | /* Network configuration changed -- force [re]association */ |
8145 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); | |
8146 | if (!ipw_disassociate(priv)) | |
43f66a6c | 8147 | ipw_associate(priv); |
43f66a6c JK |
8148 | |
8149 | return 0; | |
8150 | } | |
8151 | ||
bf79451e JG |
8152 | static int ipw_wx_set_freq(struct net_device *dev, |
8153 | struct iw_request_info *info, | |
8154 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
8155 | { |
8156 | struct ipw_priv *priv = ieee80211_priv(dev); | |
1867b117 | 8157 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
43f66a6c | 8158 | struct iw_freq *fwrq = &wrqu->freq; |
afbf30a2 | 8159 | int ret = 0, i; |
1fe0adb4 LH |
8160 | u8 channel, flags; |
8161 | int band; | |
b095c381 JK |
8162 | |
8163 | if (fwrq->m == 0) { | |
8164 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); | |
4644151b | 8165 | mutex_lock(&priv->mutex); |
b095c381 | 8166 | ret = ipw_set_channel(priv, 0); |
4644151b | 8167 | mutex_unlock(&priv->mutex); |
b095c381 JK |
8168 | return ret; |
8169 | } | |
43f66a6c JK |
8170 | /* if setting by freq convert to channel */ |
8171 | if (fwrq->e == 1) { | |
1867b117 | 8172 | channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m); |
b095c381 JK |
8173 | if (channel == 0) |
8174 | return -EINVAL; | |
8175 | } else | |
8176 | channel = fwrq->m; | |
bf79451e | 8177 | |
1867b117 | 8178 | if (!(band = ieee80211_is_valid_channel(priv->ieee, channel))) |
b095c381 | 8179 | return -EINVAL; |
43f66a6c | 8180 | |
1fe0adb4 | 8181 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
1867b117 | 8182 | i = ieee80211_channel_to_index(priv->ieee, channel); |
afbf30a2 JK |
8183 | if (i == -1) |
8184 | return -EINVAL; | |
bf79451e | 8185 | |
1fe0adb4 LH |
8186 | flags = (band == IEEE80211_24GHZ_BAND) ? |
8187 | geo->bg[i].flags : geo->a[i].flags; | |
8188 | if (flags & IEEE80211_CH_PASSIVE_ONLY) { | |
afbf30a2 JK |
8189 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
8190 | return -EINVAL; | |
43f66a6c JK |
8191 | } |
8192 | } | |
bf79451e | 8193 | |
43f66a6c | 8194 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
4644151b | 8195 | mutex_lock(&priv->mutex); |
b095c381 | 8196 | ret = ipw_set_channel(priv, channel); |
4644151b | 8197 | mutex_unlock(&priv->mutex); |
c848d0af | 8198 | return ret; |
43f66a6c JK |
8199 | } |
8200 | ||
bf79451e JG |
8201 | static int ipw_wx_get_freq(struct net_device *dev, |
8202 | struct iw_request_info *info, | |
43f66a6c JK |
8203 | union iwreq_data *wrqu, char *extra) |
8204 | { | |
8205 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8206 | ||
8207 | wrqu->freq.e = 0; | |
8208 | ||
8209 | /* If we are associated, trying to associate, or have a statically | |
8210 | * configured CHANNEL then return that; otherwise return ANY */ | |
4644151b | 8211 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8212 | if (priv->config & CFG_STATIC_CHANNEL || |
8213 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) | |
8214 | wrqu->freq.m = priv->channel; | |
bf79451e | 8215 | else |
43f66a6c JK |
8216 | wrqu->freq.m = 0; |
8217 | ||
4644151b | 8218 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8219 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
8220 | return 0; | |
8221 | } | |
8222 | ||
bf79451e JG |
8223 | static int ipw_wx_set_mode(struct net_device *dev, |
8224 | struct iw_request_info *info, | |
43f66a6c JK |
8225 | union iwreq_data *wrqu, char *extra) |
8226 | { | |
8227 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8228 | int err = 0; | |
8229 | ||
8230 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); | |
8231 | ||
43f66a6c | 8232 | switch (wrqu->mode) { |
b095c381 | 8233 | #ifdef CONFIG_IPW2200_MONITOR |
43f66a6c JK |
8234 | case IW_MODE_MONITOR: |
8235 | #endif | |
8236 | case IW_MODE_ADHOC: | |
8237 | case IW_MODE_INFRA: | |
8238 | break; | |
8239 | case IW_MODE_AUTO: | |
8240 | wrqu->mode = IW_MODE_INFRA; | |
8241 | break; | |
8242 | default: | |
8243 | return -EINVAL; | |
8244 | } | |
b095c381 JK |
8245 | if (wrqu->mode == priv->ieee->iw_mode) |
8246 | return 0; | |
43f66a6c | 8247 | |
4644151b | 8248 | mutex_lock(&priv->mutex); |
43f66a6c | 8249 | |
afbf30a2 JK |
8250 | ipw_sw_reset(priv, 0); |
8251 | ||
b095c381 | 8252 | #ifdef CONFIG_IPW2200_MONITOR |
bf79451e | 8253 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
43f66a6c | 8254 | priv->net_dev->type = ARPHRD_ETHER; |
bf79451e JG |
8255 | |
8256 | if (wrqu->mode == IW_MODE_MONITOR) | |
24a47dbd MK |
8257 | #ifdef CONFIG_IEEE80211_RADIOTAP |
8258 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | |
8259 | #else | |
43f66a6c | 8260 | priv->net_dev->type = ARPHRD_IEEE80211; |
24a47dbd | 8261 | #endif |
b095c381 | 8262 | #endif /* CONFIG_IPW2200_MONITOR */ |
bf79451e | 8263 | |
bf79451e | 8264 | /* Free the existing firmware and reset the fw_loaded |
43f66a6c | 8265 | * flag so ipw_load() will bring in the new firmawre */ |
afbf30a2 | 8266 | free_firmware(); |
43f66a6c JK |
8267 | |
8268 | priv->ieee->iw_mode = wrqu->mode; | |
bf79451e | 8269 | |
c848d0af | 8270 | queue_work(priv->workqueue, &priv->adapter_restart); |
4644151b | 8271 | mutex_unlock(&priv->mutex); |
0edd5b44 | 8272 | return err; |
43f66a6c JK |
8273 | } |
8274 | ||
bf79451e | 8275 | static int ipw_wx_get_mode(struct net_device *dev, |
0edd5b44 JG |
8276 | struct iw_request_info *info, |
8277 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
8278 | { |
8279 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 8280 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8281 | wrqu->mode = priv->ieee->iw_mode; |
8282 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); | |
4644151b | 8283 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8284 | return 0; |
8285 | } | |
8286 | ||
43f66a6c JK |
8287 | /* Values are in microsecond */ |
8288 | static const s32 timeout_duration[] = { | |
8289 | 350000, | |
8290 | 250000, | |
8291 | 75000, | |
8292 | 37000, | |
8293 | 25000, | |
8294 | }; | |
8295 | ||
8296 | static const s32 period_duration[] = { | |
8297 | 400000, | |
8298 | 700000, | |
8299 | 1000000, | |
8300 | 1000000, | |
8301 | 1000000 | |
8302 | }; | |
8303 | ||
bf79451e JG |
8304 | static int ipw_wx_get_range(struct net_device *dev, |
8305 | struct iw_request_info *info, | |
43f66a6c JK |
8306 | union iwreq_data *wrqu, char *extra) |
8307 | { | |
8308 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8309 | struct iw_range *range = (struct iw_range *)extra; | |
1867b117 | 8310 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
b095c381 | 8311 | int i = 0, j; |
43f66a6c JK |
8312 | |
8313 | wrqu->data.length = sizeof(*range); | |
8314 | memset(range, 0, sizeof(*range)); | |
8315 | ||
8316 | /* 54Mbs == ~27 Mb/s real (802.11g) */ | |
bf79451e | 8317 | range->throughput = 27 * 1000 * 1000; |
43f66a6c JK |
8318 | |
8319 | range->max_qual.qual = 100; | |
8320 | /* TODO: Find real max RSSI and stick here */ | |
8321 | range->max_qual.level = 0; | |
b191608a | 8322 | range->max_qual.noise = 0; |
0edd5b44 | 8323 | range->max_qual.updated = 7; /* Updated all three */ |
43f66a6c JK |
8324 | |
8325 | range->avg_qual.qual = 70; | |
8326 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ | |
0edd5b44 | 8327 | range->avg_qual.level = 0; /* FIXME to real average level */ |
43f66a6c | 8328 | range->avg_qual.noise = 0; |
0edd5b44 | 8329 | range->avg_qual.updated = 7; /* Updated all three */ |
4644151b | 8330 | mutex_lock(&priv->mutex); |
0edd5b44 | 8331 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
43f66a6c | 8332 | |
bf79451e JG |
8333 | for (i = 0; i < range->num_bitrates; i++) |
8334 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * | |
0edd5b44 | 8335 | 500000; |
bf79451e | 8336 | |
43f66a6c JK |
8337 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
8338 | range->min_frag = MIN_FRAG_THRESHOLD; | |
8339 | range->max_frag = MAX_FRAG_THRESHOLD; | |
8340 | ||
8341 | range->encoding_size[0] = 5; | |
bf79451e | 8342 | range->encoding_size[1] = 13; |
43f66a6c JK |
8343 | range->num_encoding_sizes = 2; |
8344 | range->max_encoding_tokens = WEP_KEYS; | |
8345 | ||
8346 | /* Set the Wireless Extension versions */ | |
8347 | range->we_version_compiled = WIRELESS_EXT; | |
f1b50863 | 8348 | range->we_version_source = 18; |
43f66a6c | 8349 | |
b095c381 JK |
8350 | i = 0; |
8351 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { | |
e815de42 ZY |
8352 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) { |
8353 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && | |
8354 | (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY)) | |
8355 | continue; | |
8356 | ||
b095c381 JK |
8357 | range->freq[i].i = geo->bg[j].channel; |
8358 | range->freq[i].m = geo->bg[j].freq * 100000; | |
8359 | range->freq[i].e = 1; | |
e815de42 | 8360 | i++; |
b095c381 JK |
8361 | } |
8362 | } | |
43f66a6c | 8363 | |
b095c381 | 8364 | if (priv->ieee->mode & IEEE_A) { |
e815de42 ZY |
8365 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) { |
8366 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && | |
8367 | (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY)) | |
8368 | continue; | |
8369 | ||
b095c381 JK |
8370 | range->freq[i].i = geo->a[j].channel; |
8371 | range->freq[i].m = geo->a[j].freq * 100000; | |
8372 | range->freq[i].e = 1; | |
e815de42 | 8373 | i++; |
b095c381 | 8374 | } |
43f66a6c | 8375 | } |
b095c381 JK |
8376 | |
8377 | range->num_channels = i; | |
8378 | range->num_frequency = i; | |
8379 | ||
4644151b | 8380 | mutex_unlock(&priv->mutex); |
97a78ca9 BB |
8381 | |
8382 | /* Event capability (kernel + driver) */ | |
8383 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | | |
8384 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | | |
8385 | IW_EVENT_CAPA_MASK(SIOCGIWAP)); | |
8386 | range->event_capa[1] = IW_EVENT_CAPA_K_1; | |
43f66a6c | 8387 | |
f1b50863 DW |
8388 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
8389 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | |
8390 | ||
43f66a6c JK |
8391 | IPW_DEBUG_WX("GET Range\n"); |
8392 | return 0; | |
8393 | } | |
8394 | ||
bf79451e JG |
8395 | static int ipw_wx_set_wap(struct net_device *dev, |
8396 | struct iw_request_info *info, | |
43f66a6c JK |
8397 | union iwreq_data *wrqu, char *extra) |
8398 | { | |
8399 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8400 | ||
8401 | static const unsigned char any[] = { | |
8402 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
8403 | }; | |
8404 | static const unsigned char off[] = { | |
8405 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
8406 | }; | |
8407 | ||
bf79451e | 8408 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
43f66a6c | 8409 | return -EINVAL; |
4644151b | 8410 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8411 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
8412 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { | |
8413 | /* we disable mandatory BSSID association */ | |
8414 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); | |
8415 | priv->config &= ~CFG_STATIC_BSSID; | |
c848d0af JK |
8416 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
8417 | "parameters.\n"); | |
8418 | ipw_associate(priv); | |
4644151b | 8419 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8420 | return 0; |
8421 | } | |
8422 | ||
8423 | priv->config |= CFG_STATIC_BSSID; | |
8424 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { | |
8425 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); | |
4644151b | 8426 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8427 | return 0; |
8428 | } | |
8429 | ||
8430 | IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n", | |
8431 | MAC_ARG(wrqu->ap_addr.sa_data)); | |
8432 | ||
8433 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); | |
8434 | ||
c848d0af JK |
8435 | /* Network configuration changed -- force [re]association */ |
8436 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); | |
8437 | if (!ipw_disassociate(priv)) | |
43f66a6c | 8438 | ipw_associate(priv); |
43f66a6c | 8439 | |
4644151b | 8440 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8441 | return 0; |
8442 | } | |
8443 | ||
bf79451e JG |
8444 | static int ipw_wx_get_wap(struct net_device *dev, |
8445 | struct iw_request_info *info, | |
43f66a6c JK |
8446 | union iwreq_data *wrqu, char *extra) |
8447 | { | |
8448 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8449 | /* If we are associated, trying to associate, or have a statically | |
8450 | * configured BSSID then return that; otherwise return ANY */ | |
4644151b | 8451 | mutex_lock(&priv->mutex); |
bf79451e | 8452 | if (priv->config & CFG_STATIC_BSSID || |
43f66a6c JK |
8453 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
8454 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; | |
afbf30a2 | 8455 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
43f66a6c JK |
8456 | } else |
8457 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); | |
8458 | ||
8459 | IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", | |
8460 | MAC_ARG(wrqu->ap_addr.sa_data)); | |
4644151b | 8461 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8462 | return 0; |
8463 | } | |
8464 | ||
bf79451e JG |
8465 | static int ipw_wx_set_essid(struct net_device *dev, |
8466 | struct iw_request_info *info, | |
43f66a6c JK |
8467 | union iwreq_data *wrqu, char *extra) |
8468 | { | |
8469 | struct ipw_priv *priv = ieee80211_priv(dev); | |
0edd5b44 | 8470 | char *essid = ""; /* ANY */ |
43f66a6c | 8471 | int length = 0; |
4644151b | 8472 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8473 | if (wrqu->essid.flags && wrqu->essid.length) { |
8474 | length = wrqu->essid.length - 1; | |
8475 | essid = extra; | |
8476 | } | |
8477 | if (length == 0) { | |
8478 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); | |
afbf30a2 JK |
8479 | if ((priv->config & CFG_STATIC_ESSID) && |
8480 | !(priv->status & (STATUS_ASSOCIATED | | |
43f66a6c JK |
8481 | STATUS_ASSOCIATING))) { |
8482 | IPW_DEBUG_ASSOC("Attempting to associate with new " | |
8483 | "parameters.\n"); | |
afbf30a2 | 8484 | priv->config &= ~CFG_STATIC_ESSID; |
43f66a6c JK |
8485 | ipw_associate(priv); |
8486 | } | |
4644151b | 8487 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8488 | return 0; |
8489 | } | |
8490 | ||
8491 | length = min(length, IW_ESSID_MAX_SIZE); | |
8492 | ||
8493 | priv->config |= CFG_STATIC_ESSID; | |
8494 | ||
8495 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { | |
8496 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); | |
4644151b | 8497 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8498 | return 0; |
8499 | } | |
8500 | ||
8501 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length), | |
8502 | length); | |
8503 | ||
8504 | priv->essid_len = length; | |
8505 | memcpy(priv->essid, essid, priv->essid_len); | |
bf79451e | 8506 | |
c848d0af JK |
8507 | /* Network configuration changed -- force [re]association */ |
8508 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); | |
8509 | if (!ipw_disassociate(priv)) | |
43f66a6c | 8510 | ipw_associate(priv); |
43f66a6c | 8511 | |
4644151b | 8512 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8513 | return 0; |
8514 | } | |
8515 | ||
bf79451e JG |
8516 | static int ipw_wx_get_essid(struct net_device *dev, |
8517 | struct iw_request_info *info, | |
43f66a6c JK |
8518 | union iwreq_data *wrqu, char *extra) |
8519 | { | |
8520 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8521 | ||
8522 | /* If we are associated, trying to associate, or have a statically | |
8523 | * configured ESSID then return that; otherwise return ANY */ | |
4644151b | 8524 | mutex_lock(&priv->mutex); |
43f66a6c | 8525 | if (priv->config & CFG_STATIC_ESSID || |
bf79451e JG |
8526 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
8527 | IPW_DEBUG_WX("Getting essid: '%s'\n", | |
43f66a6c | 8528 | escape_essid(priv->essid, priv->essid_len)); |
bf79451e | 8529 | memcpy(extra, priv->essid, priv->essid_len); |
43f66a6c | 8530 | wrqu->essid.length = priv->essid_len; |
0edd5b44 | 8531 | wrqu->essid.flags = 1; /* active */ |
43f66a6c JK |
8532 | } else { |
8533 | IPW_DEBUG_WX("Getting essid: ANY\n"); | |
8534 | wrqu->essid.length = 0; | |
0edd5b44 | 8535 | wrqu->essid.flags = 0; /* active */ |
43f66a6c | 8536 | } |
4644151b | 8537 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8538 | return 0; |
8539 | } | |
8540 | ||
bf79451e JG |
8541 | static int ipw_wx_set_nick(struct net_device *dev, |
8542 | struct iw_request_info *info, | |
43f66a6c | 8543 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8544 | { |
43f66a6c JK |
8545 | struct ipw_priv *priv = ieee80211_priv(dev); |
8546 | ||
8547 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); | |
8548 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) | |
8549 | return -E2BIG; | |
4644151b | 8550 | mutex_lock(&priv->mutex); |
0edd5b44 | 8551 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
43f66a6c | 8552 | memset(priv->nick, 0, sizeof(priv->nick)); |
0edd5b44 | 8553 | memcpy(priv->nick, extra, wrqu->data.length); |
43f66a6c | 8554 | IPW_DEBUG_TRACE("<<\n"); |
4644151b | 8555 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8556 | return 0; |
8557 | ||
8558 | } | |
8559 | ||
bf79451e JG |
8560 | static int ipw_wx_get_nick(struct net_device *dev, |
8561 | struct iw_request_info *info, | |
43f66a6c | 8562 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8563 | { |
43f66a6c JK |
8564 | struct ipw_priv *priv = ieee80211_priv(dev); |
8565 | IPW_DEBUG_WX("Getting nick\n"); | |
4644151b | 8566 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8567 | wrqu->data.length = strlen(priv->nick) + 1; |
8568 | memcpy(extra, priv->nick, wrqu->data.length); | |
0edd5b44 | 8569 | wrqu->data.flags = 1; /* active */ |
4644151b | 8570 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8571 | return 0; |
8572 | } | |
8573 | ||
651be26f OH |
8574 | static int ipw_wx_set_sens(struct net_device *dev, |
8575 | struct iw_request_info *info, | |
8576 | union iwreq_data *wrqu, char *extra) | |
8577 | { | |
8578 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8579 | int err = 0; | |
8580 | ||
8581 | IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value); | |
8582 | IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value); | |
8583 | mutex_lock(&priv->mutex); | |
8584 | ||
8585 | if (wrqu->sens.fixed == 0) | |
8586 | { | |
8587 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; | |
8588 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; | |
8589 | goto out; | |
8590 | } | |
8591 | if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) || | |
8592 | (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) { | |
8593 | err = -EINVAL; | |
8594 | goto out; | |
8595 | } | |
8596 | ||
8597 | priv->roaming_threshold = wrqu->sens.value; | |
8598 | priv->disassociate_threshold = 3*wrqu->sens.value; | |
8599 | out: | |
8600 | mutex_unlock(&priv->mutex); | |
8601 | return err; | |
8602 | } | |
8603 | ||
8604 | static int ipw_wx_get_sens(struct net_device *dev, | |
8605 | struct iw_request_info *info, | |
8606 | union iwreq_data *wrqu, char *extra) | |
8607 | { | |
8608 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8609 | mutex_lock(&priv->mutex); | |
8610 | wrqu->sens.fixed = 1; | |
8611 | wrqu->sens.value = priv->roaming_threshold; | |
8612 | mutex_unlock(&priv->mutex); | |
8613 | ||
8614 | IPW_DEBUG_WX("GET roaming threshold -> %s %d \n", | |
8615 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); | |
8616 | ||
8617 | return 0; | |
8618 | } | |
8619 | ||
43f66a6c JK |
8620 | static int ipw_wx_set_rate(struct net_device *dev, |
8621 | struct iw_request_info *info, | |
8622 | union iwreq_data *wrqu, char *extra) | |
bf79451e | 8623 | { |
ea2b26e0 JK |
8624 | /* TODO: We should use semaphores or locks for access to priv */ |
8625 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8626 | u32 target_rate = wrqu->bitrate.value; | |
8627 | u32 fixed, mask; | |
8628 | ||
8629 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ | |
8630 | /* value = X, fixed = 1 means only rate X */ | |
8631 | /* value = X, fixed = 0 means all rates lower equal X */ | |
8632 | ||
8633 | if (target_rate == -1) { | |
8634 | fixed = 0; | |
8635 | mask = IEEE80211_DEFAULT_RATES_MASK; | |
8636 | /* Now we should reassociate */ | |
8637 | goto apply; | |
8638 | } | |
8639 | ||
8640 | mask = 0; | |
8641 | fixed = wrqu->bitrate.fixed; | |
8642 | ||
8643 | if (target_rate == 1000000 || !fixed) | |
8644 | mask |= IEEE80211_CCK_RATE_1MB_MASK; | |
8645 | if (target_rate == 1000000) | |
8646 | goto apply; | |
8647 | ||
8648 | if (target_rate == 2000000 || !fixed) | |
8649 | mask |= IEEE80211_CCK_RATE_2MB_MASK; | |
8650 | if (target_rate == 2000000) | |
8651 | goto apply; | |
8652 | ||
8653 | if (target_rate == 5500000 || !fixed) | |
8654 | mask |= IEEE80211_CCK_RATE_5MB_MASK; | |
8655 | if (target_rate == 5500000) | |
8656 | goto apply; | |
8657 | ||
8658 | if (target_rate == 6000000 || !fixed) | |
8659 | mask |= IEEE80211_OFDM_RATE_6MB_MASK; | |
8660 | if (target_rate == 6000000) | |
8661 | goto apply; | |
8662 | ||
8663 | if (target_rate == 9000000 || !fixed) | |
8664 | mask |= IEEE80211_OFDM_RATE_9MB_MASK; | |
8665 | if (target_rate == 9000000) | |
8666 | goto apply; | |
8667 | ||
8668 | if (target_rate == 11000000 || !fixed) | |
8669 | mask |= IEEE80211_CCK_RATE_11MB_MASK; | |
8670 | if (target_rate == 11000000) | |
8671 | goto apply; | |
8672 | ||
8673 | if (target_rate == 12000000 || !fixed) | |
8674 | mask |= IEEE80211_OFDM_RATE_12MB_MASK; | |
8675 | if (target_rate == 12000000) | |
8676 | goto apply; | |
8677 | ||
8678 | if (target_rate == 18000000 || !fixed) | |
8679 | mask |= IEEE80211_OFDM_RATE_18MB_MASK; | |
8680 | if (target_rate == 18000000) | |
8681 | goto apply; | |
8682 | ||
8683 | if (target_rate == 24000000 || !fixed) | |
8684 | mask |= IEEE80211_OFDM_RATE_24MB_MASK; | |
8685 | if (target_rate == 24000000) | |
8686 | goto apply; | |
8687 | ||
8688 | if (target_rate == 36000000 || !fixed) | |
8689 | mask |= IEEE80211_OFDM_RATE_36MB_MASK; | |
8690 | if (target_rate == 36000000) | |
8691 | goto apply; | |
8692 | ||
8693 | if (target_rate == 48000000 || !fixed) | |
8694 | mask |= IEEE80211_OFDM_RATE_48MB_MASK; | |
8695 | if (target_rate == 48000000) | |
8696 | goto apply; | |
8697 | ||
8698 | if (target_rate == 54000000 || !fixed) | |
8699 | mask |= IEEE80211_OFDM_RATE_54MB_MASK; | |
8700 | if (target_rate == 54000000) | |
8701 | goto apply; | |
8702 | ||
8703 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); | |
8704 | return -EINVAL; | |
8705 | ||
8706 | apply: | |
8707 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", | |
8708 | mask, fixed ? "fixed" : "sub-rates"); | |
4644151b | 8709 | mutex_lock(&priv->mutex); |
b095c381 | 8710 | if (mask == IEEE80211_DEFAULT_RATES_MASK) { |
ea2b26e0 | 8711 | priv->config &= ~CFG_FIXED_RATE; |
b095c381 JK |
8712 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
8713 | } else | |
ea2b26e0 JK |
8714 | priv->config |= CFG_FIXED_RATE; |
8715 | ||
c848d0af JK |
8716 | if (priv->rates_mask == mask) { |
8717 | IPW_DEBUG_WX("Mask set to current mask.\n"); | |
4644151b | 8718 | mutex_unlock(&priv->mutex); |
c848d0af | 8719 | return 0; |
ea2b26e0 JK |
8720 | } |
8721 | ||
c848d0af JK |
8722 | priv->rates_mask = mask; |
8723 | ||
8724 | /* Network configuration changed -- force [re]association */ | |
8725 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); | |
8726 | if (!ipw_disassociate(priv)) | |
8727 | ipw_associate(priv); | |
8728 | ||
4644151b | 8729 | mutex_unlock(&priv->mutex); |
ea2b26e0 | 8730 | return 0; |
43f66a6c JK |
8731 | } |
8732 | ||
bf79451e JG |
8733 | static int ipw_wx_get_rate(struct net_device *dev, |
8734 | struct iw_request_info *info, | |
43f66a6c | 8735 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8736 | { |
0edd5b44 | 8737 | struct ipw_priv *priv = ieee80211_priv(dev); |
4644151b | 8738 | mutex_lock(&priv->mutex); |
43f66a6c | 8739 | wrqu->bitrate.value = priv->last_rate; |
4644151b | 8740 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8741 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
8742 | return 0; | |
8743 | } | |
8744 | ||
bf79451e JG |
8745 | static int ipw_wx_set_rts(struct net_device *dev, |
8746 | struct iw_request_info *info, | |
43f66a6c | 8747 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8748 | { |
43f66a6c | 8749 | struct ipw_priv *priv = ieee80211_priv(dev); |
4644151b | 8750 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8751 | if (wrqu->rts.disabled) |
8752 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; | |
8753 | else { | |
8754 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || | |
c848d0af | 8755 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
4644151b | 8756 | mutex_unlock(&priv->mutex); |
43f66a6c | 8757 | return -EINVAL; |
c848d0af | 8758 | } |
43f66a6c JK |
8759 | priv->rts_threshold = wrqu->rts.value; |
8760 | } | |
8761 | ||
8762 | ipw_send_rts_threshold(priv, priv->rts_threshold); | |
4644151b | 8763 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8764 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
8765 | return 0; | |
8766 | } | |
8767 | ||
bf79451e JG |
8768 | static int ipw_wx_get_rts(struct net_device *dev, |
8769 | struct iw_request_info *info, | |
43f66a6c | 8770 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8771 | { |
43f66a6c | 8772 | struct ipw_priv *priv = ieee80211_priv(dev); |
4644151b | 8773 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8774 | wrqu->rts.value = priv->rts_threshold; |
8775 | wrqu->rts.fixed = 0; /* no auto select */ | |
0edd5b44 | 8776 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
4644151b | 8777 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8778 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
8779 | return 0; | |
8780 | } | |
8781 | ||
bf79451e JG |
8782 | static int ipw_wx_set_txpow(struct net_device *dev, |
8783 | struct iw_request_info *info, | |
43f66a6c | 8784 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8785 | { |
43f66a6c | 8786 | struct ipw_priv *priv = ieee80211_priv(dev); |
6de9f7f2 | 8787 | int err = 0; |
43f66a6c | 8788 | |
4644151b | 8789 | mutex_lock(&priv->mutex); |
c848d0af | 8790 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
6de9f7f2 ZY |
8791 | err = -EINPROGRESS; |
8792 | goto out; | |
43f66a6c | 8793 | } |
43f66a6c | 8794 | |
b095c381 JK |
8795 | if (!wrqu->power.fixed) |
8796 | wrqu->power.value = IPW_TX_POWER_DEFAULT; | |
8797 | ||
c848d0af | 8798 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
6de9f7f2 ZY |
8799 | err = -EINVAL; |
8800 | goto out; | |
c848d0af | 8801 | } |
43f66a6c | 8802 | |
b095c381 | 8803 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
afbf30a2 | 8804 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
6de9f7f2 ZY |
8805 | err = -EINVAL; |
8806 | goto out; | |
c848d0af | 8807 | } |
43f66a6c | 8808 | |
43f66a6c | 8809 | priv->tx_power = wrqu->power.value; |
6de9f7f2 ZY |
8810 | err = ipw_set_tx_power(priv); |
8811 | out: | |
4644151b | 8812 | mutex_unlock(&priv->mutex); |
6de9f7f2 | 8813 | return err; |
43f66a6c JK |
8814 | } |
8815 | ||
bf79451e JG |
8816 | static int ipw_wx_get_txpow(struct net_device *dev, |
8817 | struct iw_request_info *info, | |
43f66a6c | 8818 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8819 | { |
43f66a6c | 8820 | struct ipw_priv *priv = ieee80211_priv(dev); |
4644151b | 8821 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8822 | wrqu->power.value = priv->tx_power; |
8823 | wrqu->power.fixed = 1; | |
8824 | wrqu->power.flags = IW_TXPOW_DBM; | |
8825 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; | |
4644151b | 8826 | mutex_unlock(&priv->mutex); |
43f66a6c | 8827 | |
bf79451e | 8828 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
22501c8e | 8829 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
43f66a6c JK |
8830 | |
8831 | return 0; | |
8832 | } | |
8833 | ||
bf79451e | 8834 | static int ipw_wx_set_frag(struct net_device *dev, |
0edd5b44 JG |
8835 | struct iw_request_info *info, |
8836 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
8837 | { |
8838 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 8839 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8840 | if (wrqu->frag.disabled) |
8841 | priv->ieee->fts = DEFAULT_FTS; | |
8842 | else { | |
8843 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || | |
b095c381 | 8844 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
4644151b | 8845 | mutex_unlock(&priv->mutex); |
43f66a6c | 8846 | return -EINVAL; |
b095c381 | 8847 | } |
bf79451e | 8848 | |
43f66a6c JK |
8849 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
8850 | } | |
8851 | ||
8852 | ipw_send_frag_threshold(priv, wrqu->frag.value); | |
4644151b | 8853 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8854 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
8855 | return 0; | |
8856 | } | |
8857 | ||
bf79451e | 8858 | static int ipw_wx_get_frag(struct net_device *dev, |
0edd5b44 JG |
8859 | struct iw_request_info *info, |
8860 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
8861 | { |
8862 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 8863 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8864 | wrqu->frag.value = priv->ieee->fts; |
8865 | wrqu->frag.fixed = 0; /* no auto select */ | |
0edd5b44 | 8866 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
4644151b | 8867 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8868 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
8869 | ||
8870 | return 0; | |
8871 | } | |
8872 | ||
bf79451e JG |
8873 | static int ipw_wx_set_retry(struct net_device *dev, |
8874 | struct iw_request_info *info, | |
43f66a6c | 8875 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8876 | { |
afbf30a2 JK |
8877 | struct ipw_priv *priv = ieee80211_priv(dev); |
8878 | ||
8879 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) | |
8880 | return -EINVAL; | |
8881 | ||
8882 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) | |
8883 | return 0; | |
8884 | ||
8885 | if (wrqu->retry.value < 0 || wrqu->retry.value > 255) | |
8886 | return -EINVAL; | |
8887 | ||
4644151b | 8888 | mutex_lock(&priv->mutex); |
afbf30a2 JK |
8889 | if (wrqu->retry.flags & IW_RETRY_MIN) |
8890 | priv->short_retry_limit = (u8) wrqu->retry.value; | |
8891 | else if (wrqu->retry.flags & IW_RETRY_MAX) | |
8892 | priv->long_retry_limit = (u8) wrqu->retry.value; | |
8893 | else { | |
8894 | priv->short_retry_limit = (u8) wrqu->retry.value; | |
8895 | priv->long_retry_limit = (u8) wrqu->retry.value; | |
8896 | } | |
8897 | ||
8898 | ipw_send_retry_limit(priv, priv->short_retry_limit, | |
8899 | priv->long_retry_limit); | |
4644151b | 8900 | mutex_unlock(&priv->mutex); |
afbf30a2 JK |
8901 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
8902 | priv->short_retry_limit, priv->long_retry_limit); | |
8903 | return 0; | |
43f66a6c JK |
8904 | } |
8905 | ||
bf79451e JG |
8906 | static int ipw_wx_get_retry(struct net_device *dev, |
8907 | struct iw_request_info *info, | |
43f66a6c | 8908 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8909 | { |
afbf30a2 JK |
8910 | struct ipw_priv *priv = ieee80211_priv(dev); |
8911 | ||
4644151b | 8912 | mutex_lock(&priv->mutex); |
afbf30a2 JK |
8913 | wrqu->retry.disabled = 0; |
8914 | ||
8915 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { | |
4644151b | 8916 | mutex_unlock(&priv->mutex); |
afbf30a2 JK |
8917 | return -EINVAL; |
8918 | } | |
8919 | ||
8920 | if (wrqu->retry.flags & IW_RETRY_MAX) { | |
8921 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; | |
8922 | wrqu->retry.value = priv->long_retry_limit; | |
8923 | } else if (wrqu->retry.flags & IW_RETRY_MIN) { | |
8924 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; | |
8925 | wrqu->retry.value = priv->short_retry_limit; | |
8926 | } else { | |
8927 | wrqu->retry.flags = IW_RETRY_LIMIT; | |
8928 | wrqu->retry.value = priv->short_retry_limit; | |
8929 | } | |
4644151b | 8930 | mutex_unlock(&priv->mutex); |
afbf30a2 JK |
8931 | |
8932 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); | |
8933 | ||
8934 | return 0; | |
8935 | } | |
8936 | ||
afbf30a2 JK |
8937 | static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid, |
8938 | int essid_len) | |
8939 | { | |
8940 | struct ipw_scan_request_ext scan; | |
8941 | int err = 0, scan_type; | |
8942 | ||
efb3442c PE |
8943 | if (!(priv->status & STATUS_INIT) || |
8944 | (priv->status & STATUS_EXIT_PENDING)) | |
8945 | return 0; | |
8946 | ||
4644151b | 8947 | mutex_lock(&priv->mutex); |
afbf30a2 JK |
8948 | |
8949 | if (priv->status & STATUS_RF_KILL_MASK) { | |
8950 | IPW_DEBUG_HC("Aborting scan due to RF kill activation\n"); | |
8951 | priv->status |= STATUS_SCAN_PENDING; | |
8952 | goto done; | |
8953 | } | |
8954 | ||
8955 | IPW_DEBUG_HC("starting request direct scan!\n"); | |
8956 | ||
8957 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { | |
d834a41c OK |
8958 | /* We should not sleep here; otherwise we will block most |
8959 | * of the system (for instance, we hold rtnl_lock when we | |
8960 | * get here). | |
8961 | */ | |
8962 | err = -EAGAIN; | |
8963 | goto done; | |
afbf30a2 JK |
8964 | } |
8965 | memset(&scan, 0, sizeof(scan)); | |
8966 | ||
8967 | if (priv->config & CFG_SPEED_SCAN) | |
8968 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | |
8969 | cpu_to_le16(30); | |
8970 | else | |
8971 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | |
8972 | cpu_to_le16(20); | |
8973 | ||
8974 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = | |
8975 | cpu_to_le16(20); | |
1fe0adb4 | 8976 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120); |
afbf30a2 JK |
8977 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
8978 | ||
8979 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); | |
8980 | ||
8981 | err = ipw_send_ssid(priv, essid, essid_len); | |
8982 | if (err) { | |
8983 | IPW_DEBUG_HC("Attempt to send SSID command failed\n"); | |
8984 | goto done; | |
8985 | } | |
8986 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; | |
8987 | ||
8988 | ipw_add_scan_channels(priv, &scan, scan_type); | |
8989 | ||
8990 | err = ipw_send_scan_request_ext(priv, &scan); | |
8991 | if (err) { | |
8992 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); | |
8993 | goto done; | |
8994 | } | |
8995 | ||
8996 | priv->status |= STATUS_SCANNING; | |
8997 | ||
8998 | done: | |
4644151b | 8999 | mutex_unlock(&priv->mutex); |
afbf30a2 | 9000 | return err; |
43f66a6c JK |
9001 | } |
9002 | ||
bf79451e JG |
9003 | static int ipw_wx_set_scan(struct net_device *dev, |
9004 | struct iw_request_info *info, | |
43f66a6c JK |
9005 | union iwreq_data *wrqu, char *extra) |
9006 | { | |
9007 | struct ipw_priv *priv = ieee80211_priv(dev); | |
afbf30a2 JK |
9008 | struct iw_scan_req *req = NULL; |
9009 | if (wrqu->data.length | |
9010 | && wrqu->data.length == sizeof(struct iw_scan_req)) { | |
9011 | req = (struct iw_scan_req *)extra; | |
9012 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { | |
9013 | ipw_request_direct_scan(priv, req->essid, | |
9014 | req->essid_len); | |
9015 | return 0; | |
9016 | } | |
9017 | } | |
8935f39e | 9018 | |
43f66a6c | 9019 | IPW_DEBUG_WX("Start scan\n"); |
b095c381 JK |
9020 | |
9021 | queue_work(priv->workqueue, &priv->request_scan); | |
9022 | ||
43f66a6c JK |
9023 | return 0; |
9024 | } | |
9025 | ||
bf79451e JG |
9026 | static int ipw_wx_get_scan(struct net_device *dev, |
9027 | struct iw_request_info *info, | |
43f66a6c | 9028 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9029 | { |
43f66a6c JK |
9030 | struct ipw_priv *priv = ieee80211_priv(dev); |
9031 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); | |
9032 | } | |
9033 | ||
bf79451e | 9034 | static int ipw_wx_set_encode(struct net_device *dev, |
0edd5b44 JG |
9035 | struct iw_request_info *info, |
9036 | union iwreq_data *wrqu, char *key) | |
43f66a6c JK |
9037 | { |
9038 | struct ipw_priv *priv = ieee80211_priv(dev); | |
afbf30a2 | 9039 | int ret; |
caeff81b | 9040 | u32 cap = priv->capability; |
afbf30a2 | 9041 | |
4644151b | 9042 | mutex_lock(&priv->mutex); |
afbf30a2 | 9043 | ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); |
afbf30a2 | 9044 | |
caeff81b HL |
9045 | /* In IBSS mode, we need to notify the firmware to update |
9046 | * the beacon info after we changed the capability. */ | |
9047 | if (cap != priv->capability && | |
9048 | priv->ieee->iw_mode == IW_MODE_ADHOC && | |
9049 | priv->status & STATUS_ASSOCIATED) | |
9050 | ipw_disassociate(priv); | |
9051 | ||
4644151b | 9052 | mutex_unlock(&priv->mutex); |
afbf30a2 | 9053 | return ret; |
43f66a6c JK |
9054 | } |
9055 | ||
bf79451e | 9056 | static int ipw_wx_get_encode(struct net_device *dev, |
0edd5b44 JG |
9057 | struct iw_request_info *info, |
9058 | union iwreq_data *wrqu, char *key) | |
43f66a6c JK |
9059 | { |
9060 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9061 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); | |
9062 | } | |
9063 | ||
bf79451e | 9064 | static int ipw_wx_set_power(struct net_device *dev, |
0edd5b44 JG |
9065 | struct iw_request_info *info, |
9066 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
9067 | { |
9068 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9069 | int err; | |
4644151b | 9070 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9071 | if (wrqu->power.disabled) { |
9072 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | |
9073 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); | |
9074 | if (err) { | |
9075 | IPW_DEBUG_WX("failed setting power mode.\n"); | |
4644151b | 9076 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9077 | return err; |
9078 | } | |
43f66a6c | 9079 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
4644151b | 9080 | mutex_unlock(&priv->mutex); |
43f66a6c | 9081 | return 0; |
bf79451e | 9082 | } |
43f66a6c JK |
9083 | |
9084 | switch (wrqu->power.flags & IW_POWER_MODE) { | |
0edd5b44 JG |
9085 | case IW_POWER_ON: /* If not specified */ |
9086 | case IW_POWER_MODE: /* If set all mask */ | |
9087 | case IW_POWER_ALL_R: /* If explicitely state all */ | |
43f66a6c | 9088 | break; |
0edd5b44 | 9089 | default: /* Otherwise we don't support it */ |
43f66a6c JK |
9090 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
9091 | wrqu->power.flags); | |
4644151b | 9092 | mutex_unlock(&priv->mutex); |
bf79451e | 9093 | return -EOPNOTSUPP; |
43f66a6c | 9094 | } |
bf79451e | 9095 | |
43f66a6c JK |
9096 | /* If the user hasn't specified a power management mode yet, default |
9097 | * to BATTERY */ | |
0edd5b44 | 9098 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
43f66a6c | 9099 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
bf79451e | 9100 | else |
43f66a6c JK |
9101 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
9102 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); | |
9103 | if (err) { | |
9104 | IPW_DEBUG_WX("failed setting power mode.\n"); | |
4644151b | 9105 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9106 | return err; |
9107 | } | |
9108 | ||
0edd5b44 | 9109 | IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); |
4644151b | 9110 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9111 | return 0; |
9112 | } | |
9113 | ||
bf79451e | 9114 | static int ipw_wx_get_power(struct net_device *dev, |
0edd5b44 JG |
9115 | struct iw_request_info *info, |
9116 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
9117 | { |
9118 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 9119 | mutex_lock(&priv->mutex); |
a613bffd | 9120 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
43f66a6c | 9121 | wrqu->power.disabled = 1; |
a613bffd | 9122 | else |
43f66a6c | 9123 | wrqu->power.disabled = 0; |
43f66a6c | 9124 | |
4644151b | 9125 | mutex_unlock(&priv->mutex); |
43f66a6c | 9126 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
bf79451e | 9127 | |
43f66a6c JK |
9128 | return 0; |
9129 | } | |
9130 | ||
bf79451e | 9131 | static int ipw_wx_set_powermode(struct net_device *dev, |
0edd5b44 JG |
9132 | struct iw_request_info *info, |
9133 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
9134 | { |
9135 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9136 | int mode = *(int *)extra; | |
9137 | int err; | |
4644151b | 9138 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9139 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) { |
9140 | mode = IPW_POWER_AC; | |
9141 | priv->power_mode = mode; | |
9142 | } else { | |
9143 | priv->power_mode = IPW_POWER_ENABLED | mode; | |
9144 | } | |
bf79451e | 9145 | |
43f66a6c JK |
9146 | if (priv->power_mode != mode) { |
9147 | err = ipw_send_power_mode(priv, mode); | |
bf79451e | 9148 | |
43f66a6c JK |
9149 | if (err) { |
9150 | IPW_DEBUG_WX("failed setting power mode.\n"); | |
4644151b | 9151 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9152 | return err; |
9153 | } | |
9154 | } | |
4644151b | 9155 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9156 | return 0; |
9157 | } | |
9158 | ||
9159 | #define MAX_WX_STRING 80 | |
bf79451e | 9160 | static int ipw_wx_get_powermode(struct net_device *dev, |
0edd5b44 JG |
9161 | struct iw_request_info *info, |
9162 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
9163 | { |
9164 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9165 | int level = IPW_POWER_LEVEL(priv->power_mode); | |
9166 | char *p = extra; | |
9167 | ||
9168 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); | |
9169 | ||
9170 | switch (level) { | |
9171 | case IPW_POWER_AC: | |
9172 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); | |
9173 | break; | |
9174 | case IPW_POWER_BATTERY: | |
9175 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); | |
9176 | break; | |
9177 | default: | |
9178 | p += snprintf(p, MAX_WX_STRING - (p - extra), | |
bf79451e | 9179 | "(Timeout %dms, Period %dms)", |
43f66a6c JK |
9180 | timeout_duration[level - 1] / 1000, |
9181 | period_duration[level - 1] / 1000); | |
9182 | } | |
9183 | ||
9184 | if (!(priv->power_mode & IPW_POWER_ENABLED)) | |
0edd5b44 | 9185 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
43f66a6c JK |
9186 | |
9187 | wrqu->data.length = p - extra + 1; | |
9188 | ||
9189 | return 0; | |
9190 | } | |
9191 | ||
9192 | static int ipw_wx_set_wireless_mode(struct net_device *dev, | |
0edd5b44 JG |
9193 | struct iw_request_info *info, |
9194 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9195 | { |
0edd5b44 | 9196 | struct ipw_priv *priv = ieee80211_priv(dev); |
43f66a6c JK |
9197 | int mode = *(int *)extra; |
9198 | u8 band = 0, modulation = 0; | |
9199 | ||
9200 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { | |
0edd5b44 | 9201 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
43f66a6c JK |
9202 | return -EINVAL; |
9203 | } | |
4644151b | 9204 | mutex_lock(&priv->mutex); |
43f66a6c | 9205 | if (priv->adapter == IPW_2915ABG) { |
a33a1982 | 9206 | priv->ieee->abg_true = 1; |
43f66a6c JK |
9207 | if (mode & IEEE_A) { |
9208 | band |= IEEE80211_52GHZ_BAND; | |
9209 | modulation |= IEEE80211_OFDM_MODULATION; | |
9210 | } else | |
a33a1982 | 9211 | priv->ieee->abg_true = 0; |
43f66a6c JK |
9212 | } else { |
9213 | if (mode & IEEE_A) { | |
9214 | IPW_WARNING("Attempt to set 2200BG into " | |
9215 | "802.11a mode\n"); | |
4644151b | 9216 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9217 | return -EINVAL; |
9218 | } | |
9219 | ||
a33a1982 | 9220 | priv->ieee->abg_true = 0; |
43f66a6c JK |
9221 | } |
9222 | ||
9223 | if (mode & IEEE_B) { | |
9224 | band |= IEEE80211_24GHZ_BAND; | |
9225 | modulation |= IEEE80211_CCK_MODULATION; | |
9226 | } else | |
a33a1982 | 9227 | priv->ieee->abg_true = 0; |
bf79451e | 9228 | |
43f66a6c JK |
9229 | if (mode & IEEE_G) { |
9230 | band |= IEEE80211_24GHZ_BAND; | |
9231 | modulation |= IEEE80211_OFDM_MODULATION; | |
9232 | } else | |
a33a1982 | 9233 | priv->ieee->abg_true = 0; |
43f66a6c JK |
9234 | |
9235 | priv->ieee->mode = mode; | |
9236 | priv->ieee->freq_band = band; | |
9237 | priv->ieee->modulation = modulation; | |
0edd5b44 | 9238 | init_supported_rates(priv, &priv->rates); |
43f66a6c | 9239 | |
c848d0af JK |
9240 | /* Network configuration changed -- force [re]association */ |
9241 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); | |
9242 | if (!ipw_disassociate(priv)) { | |
43f66a6c | 9243 | ipw_send_supported_rates(priv, &priv->rates); |
c848d0af JK |
9244 | ipw_associate(priv); |
9245 | } | |
43f66a6c | 9246 | |
a613bffd JK |
9247 | /* Update the band LEDs */ |
9248 | ipw_led_band_on(priv); | |
43f66a6c | 9249 | |
bf79451e | 9250 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
43f66a6c | 9251 | mode & IEEE_A ? 'a' : '.', |
0edd5b44 | 9252 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
4644151b | 9253 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9254 | return 0; |
9255 | } | |
9256 | ||
9257 | static int ipw_wx_get_wireless_mode(struct net_device *dev, | |
0edd5b44 JG |
9258 | struct iw_request_info *info, |
9259 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9260 | { |
0edd5b44 | 9261 | struct ipw_priv *priv = ieee80211_priv(dev); |
4644151b | 9262 | mutex_lock(&priv->mutex); |
ea2b26e0 JK |
9263 | switch (priv->ieee->mode) { |
9264 | case IEEE_A: | |
43f66a6c JK |
9265 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
9266 | break; | |
ea2b26e0 JK |
9267 | case IEEE_B: |
9268 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); | |
9269 | break; | |
9270 | case IEEE_A | IEEE_B: | |
9271 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); | |
9272 | break; | |
9273 | case IEEE_G: | |
9274 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); | |
9275 | break; | |
9276 | case IEEE_A | IEEE_G: | |
9277 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); | |
9278 | break; | |
9279 | case IEEE_B | IEEE_G: | |
9280 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); | |
9281 | break; | |
9282 | case IEEE_A | IEEE_B | IEEE_G: | |
9283 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); | |
9284 | break; | |
9285 | default: | |
9286 | strncpy(extra, "unknown", MAX_WX_STRING); | |
43f66a6c | 9287 | break; |
bf79451e JG |
9288 | } |
9289 | ||
43f66a6c JK |
9290 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
9291 | ||
0edd5b44 | 9292 | wrqu->data.length = strlen(extra) + 1; |
4644151b | 9293 | mutex_unlock(&priv->mutex); |
b095c381 JK |
9294 | |
9295 | return 0; | |
9296 | } | |
9297 | ||
9298 | static int ipw_wx_set_preamble(struct net_device *dev, | |
9299 | struct iw_request_info *info, | |
9300 | union iwreq_data *wrqu, char *extra) | |
9301 | { | |
9302 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9303 | int mode = *(int *)extra; | |
4644151b | 9304 | mutex_lock(&priv->mutex); |
b095c381 JK |
9305 | /* Switching from SHORT -> LONG requires a disassociation */ |
9306 | if (mode == 1) { | |
9307 | if (!(priv->config & CFG_PREAMBLE_LONG)) { | |
9308 | priv->config |= CFG_PREAMBLE_LONG; | |
9309 | ||
9310 | /* Network configuration changed -- force [re]association */ | |
9311 | IPW_DEBUG_ASSOC | |
9312 | ("[re]association triggered due to preamble change.\n"); | |
9313 | if (!ipw_disassociate(priv)) | |
9314 | ipw_associate(priv); | |
9315 | } | |
9316 | goto done; | |
9317 | } | |
43f66a6c | 9318 | |
b095c381 JK |
9319 | if (mode == 0) { |
9320 | priv->config &= ~CFG_PREAMBLE_LONG; | |
9321 | goto done; | |
9322 | } | |
4644151b | 9323 | mutex_unlock(&priv->mutex); |
b095c381 JK |
9324 | return -EINVAL; |
9325 | ||
9326 | done: | |
4644151b | 9327 | mutex_unlock(&priv->mutex); |
b095c381 JK |
9328 | return 0; |
9329 | } | |
9330 | ||
9331 | static int ipw_wx_get_preamble(struct net_device *dev, | |
9332 | struct iw_request_info *info, | |
9333 | union iwreq_data *wrqu, char *extra) | |
9334 | { | |
9335 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 9336 | mutex_lock(&priv->mutex); |
b095c381 JK |
9337 | if (priv->config & CFG_PREAMBLE_LONG) |
9338 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); | |
9339 | else | |
9340 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); | |
4644151b | 9341 | mutex_unlock(&priv->mutex); |
0edd5b44 | 9342 | return 0; |
43f66a6c JK |
9343 | } |
9344 | ||
b095c381 JK |
9345 | #ifdef CONFIG_IPW2200_MONITOR |
9346 | static int ipw_wx_set_monitor(struct net_device *dev, | |
bf79451e | 9347 | struct iw_request_info *info, |
43f66a6c | 9348 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9349 | { |
43f66a6c JK |
9350 | struct ipw_priv *priv = ieee80211_priv(dev); |
9351 | int *parms = (int *)extra; | |
9352 | int enable = (parms[0] > 0); | |
4644151b | 9353 | mutex_lock(&priv->mutex); |
b095c381 | 9354 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
43f66a6c JK |
9355 | if (enable) { |
9356 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { | |
24a47dbd MK |
9357 | #ifdef CONFIG_IEEE80211_RADIOTAP |
9358 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | |
9359 | #else | |
43f66a6c | 9360 | priv->net_dev->type = ARPHRD_IEEE80211; |
24a47dbd | 9361 | #endif |
b095c381 | 9362 | queue_work(priv->workqueue, &priv->adapter_restart); |
43f66a6c | 9363 | } |
bf79451e | 9364 | |
43f66a6c JK |
9365 | ipw_set_channel(priv, parms[1]); |
9366 | } else { | |
b095c381 | 9367 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
4644151b | 9368 | mutex_unlock(&priv->mutex); |
43f66a6c | 9369 | return 0; |
b095c381 | 9370 | } |
43f66a6c | 9371 | priv->net_dev->type = ARPHRD_ETHER; |
b095c381 | 9372 | queue_work(priv->workqueue, &priv->adapter_restart); |
43f66a6c | 9373 | } |
4644151b | 9374 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9375 | return 0; |
9376 | } | |
9377 | ||
b095c381 JK |
9378 | #endif // CONFIG_IPW2200_MONITOR |
9379 | ||
bf79451e JG |
9380 | static int ipw_wx_reset(struct net_device *dev, |
9381 | struct iw_request_info *info, | |
43f66a6c | 9382 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9383 | { |
43f66a6c JK |
9384 | struct ipw_priv *priv = ieee80211_priv(dev); |
9385 | IPW_DEBUG_WX("RESET\n"); | |
b095c381 JK |
9386 | queue_work(priv->workqueue, &priv->adapter_restart); |
9387 | return 0; | |
9388 | } | |
9389 | ||
b095c381 JK |
9390 | static int ipw_wx_sw_reset(struct net_device *dev, |
9391 | struct iw_request_info *info, | |
9392 | union iwreq_data *wrqu, char *extra) | |
ea2b26e0 JK |
9393 | { |
9394 | struct ipw_priv *priv = ieee80211_priv(dev); | |
b095c381 JK |
9395 | union iwreq_data wrqu_sec = { |
9396 | .encoding = { | |
9397 | .flags = IW_ENCODE_DISABLED, | |
9398 | }, | |
9399 | }; | |
afbf30a2 | 9400 | int ret; |
c848d0af | 9401 | |
b095c381 | 9402 | IPW_DEBUG_WX("SW_RESET\n"); |
ea2b26e0 | 9403 | |
4644151b | 9404 | mutex_lock(&priv->mutex); |
ea2b26e0 | 9405 | |
d6d5b5c1 | 9406 | ret = ipw_sw_reset(priv, 2); |
afbf30a2 JK |
9407 | if (!ret) { |
9408 | free_firmware(); | |
9409 | ipw_adapter_restart(priv); | |
9410 | } | |
ea2b26e0 | 9411 | |
b095c381 JK |
9412 | /* The SW reset bit might have been toggled on by the 'disable' |
9413 | * module parameter, so take appropriate action */ | |
9414 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); | |
ea2b26e0 | 9415 | |
4644151b | 9416 | mutex_unlock(&priv->mutex); |
b095c381 | 9417 | ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
4644151b | 9418 | mutex_lock(&priv->mutex); |
bf79451e | 9419 | |
b095c381 JK |
9420 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
9421 | /* Configuration likely changed -- force [re]association */ | |
9422 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " | |
9423 | "reset.\n"); | |
9424 | if (!ipw_disassociate(priv)) | |
9425 | ipw_associate(priv); | |
43f66a6c | 9426 | } |
b095c381 | 9427 | |
4644151b | 9428 | mutex_unlock(&priv->mutex); |
43f66a6c | 9429 | |
43f66a6c JK |
9430 | return 0; |
9431 | } | |
43f66a6c JK |
9432 | |
9433 | /* Rebase the WE IOCTLs to zero for the handler array */ | |
9434 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] | |
0edd5b44 | 9435 | static iw_handler ipw_wx_handlers[] = { |
ea2b26e0 JK |
9436 | IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, |
9437 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, | |
9438 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, | |
9439 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, | |
9440 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, | |
651be26f OH |
9441 | IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens, |
9442 | IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens, | |
ea2b26e0 JK |
9443 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, |
9444 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, | |
9445 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, | |
9446 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, | |
9447 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, | |
9448 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, | |
9449 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, | |
9450 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, | |
9451 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, | |
9452 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, | |
9453 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, | |
9454 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, | |
9455 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, | |
9456 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, | |
9457 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, | |
9458 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, | |
9459 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, | |
9460 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, | |
9461 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, | |
9462 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, | |
9463 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, | |
9464 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, | |
9465 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, | |
a613bffd JK |
9466 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
9467 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, | |
9468 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, | |
9469 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, | |
afbf30a2 JK |
9470 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
9471 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, | |
9472 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, | |
9473 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, | |
9474 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, | |
9475 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, | |
9476 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, | |
43f66a6c JK |
9477 | }; |
9478 | ||
b095c381 JK |
9479 | enum { |
9480 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, | |
9481 | IPW_PRIV_GET_POWER, | |
9482 | IPW_PRIV_SET_MODE, | |
9483 | IPW_PRIV_GET_MODE, | |
9484 | IPW_PRIV_SET_PREAMBLE, | |
9485 | IPW_PRIV_GET_PREAMBLE, | |
9486 | IPW_PRIV_RESET, | |
9487 | IPW_PRIV_SW_RESET, | |
9488 | #ifdef CONFIG_IPW2200_MONITOR | |
9489 | IPW_PRIV_SET_MONITOR, | |
9490 | #endif | |
9491 | }; | |
43f66a6c | 9492 | |
bf79451e | 9493 | static struct iw_priv_args ipw_priv_args[] = { |
43f66a6c | 9494 | { |
0edd5b44 JG |
9495 | .cmd = IPW_PRIV_SET_POWER, |
9496 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
9497 | .name = "set_power"}, | |
43f66a6c | 9498 | { |
0edd5b44 JG |
9499 | .cmd = IPW_PRIV_GET_POWER, |
9500 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, | |
9501 | .name = "get_power"}, | |
43f66a6c | 9502 | { |
0edd5b44 JG |
9503 | .cmd = IPW_PRIV_SET_MODE, |
9504 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
9505 | .name = "set_mode"}, | |
43f66a6c | 9506 | { |
0edd5b44 JG |
9507 | .cmd = IPW_PRIV_GET_MODE, |
9508 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, | |
9509 | .name = "get_mode"}, | |
43f66a6c | 9510 | { |
ea2b26e0 JK |
9511 | .cmd = IPW_PRIV_SET_PREAMBLE, |
9512 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
9513 | .name = "set_preamble"}, | |
9514 | { | |
9515 | .cmd = IPW_PRIV_GET_PREAMBLE, | |
9516 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, | |
9517 | .name = "get_preamble"}, | |
43f66a6c | 9518 | { |
0edd5b44 JG |
9519 | IPW_PRIV_RESET, |
9520 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, | |
b095c381 JK |
9521 | { |
9522 | IPW_PRIV_SW_RESET, | |
9523 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, | |
9524 | #ifdef CONFIG_IPW2200_MONITOR | |
9525 | { | |
9526 | IPW_PRIV_SET_MONITOR, | |
9527 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, | |
9528 | #endif /* CONFIG_IPW2200_MONITOR */ | |
43f66a6c JK |
9529 | }; |
9530 | ||
9531 | static iw_handler ipw_priv_handler[] = { | |
9532 | ipw_wx_set_powermode, | |
9533 | ipw_wx_get_powermode, | |
9534 | ipw_wx_set_wireless_mode, | |
9535 | ipw_wx_get_wireless_mode, | |
ea2b26e0 JK |
9536 | ipw_wx_set_preamble, |
9537 | ipw_wx_get_preamble, | |
bf79451e | 9538 | ipw_wx_reset, |
b095c381 JK |
9539 | ipw_wx_sw_reset, |
9540 | #ifdef CONFIG_IPW2200_MONITOR | |
9541 | ipw_wx_set_monitor, | |
43f66a6c JK |
9542 | #endif |
9543 | }; | |
9544 | ||
0edd5b44 | 9545 | static struct iw_handler_def ipw_wx_handler_def = { |
ea2b26e0 JK |
9546 | .standard = ipw_wx_handlers, |
9547 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), | |
9548 | .num_private = ARRAY_SIZE(ipw_priv_handler), | |
9549 | .num_private_args = ARRAY_SIZE(ipw_priv_args), | |
9550 | .private = ipw_priv_handler, | |
9551 | .private_args = ipw_priv_args, | |
97a78ca9 | 9552 | .get_wireless_stats = ipw_get_wireless_stats, |
43f66a6c JK |
9553 | }; |
9554 | ||
43f66a6c JK |
9555 | /* |
9556 | * Get wireless statistics. | |
9557 | * Called by /proc/net/wireless | |
9558 | * Also called by SIOCGIWSTATS | |
9559 | */ | |
0edd5b44 | 9560 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
43f66a6c JK |
9561 | { |
9562 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9563 | struct iw_statistics *wstats; | |
bf79451e | 9564 | |
43f66a6c JK |
9565 | wstats = &priv->wstats; |
9566 | ||
ea2b26e0 | 9567 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
afbf30a2 | 9568 | * netdev->get_wireless_stats seems to be called before fw is |
43f66a6c JK |
9569 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
9570 | * and associated; if not associcated, the values are all meaningless | |
9571 | * anyway, so set them all to NULL and INVALID */ | |
9572 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
9573 | wstats->miss.beacon = 0; | |
9574 | wstats->discard.retries = 0; | |
9575 | wstats->qual.qual = 0; | |
9576 | wstats->qual.level = 0; | |
9577 | wstats->qual.noise = 0; | |
9578 | wstats->qual.updated = 7; | |
9579 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | | |
0edd5b44 | 9580 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
43f66a6c | 9581 | return wstats; |
bf79451e | 9582 | } |
43f66a6c JK |
9583 | |
9584 | wstats->qual.qual = priv->quality; | |
9585 | wstats->qual.level = average_value(&priv->average_rssi); | |
9586 | wstats->qual.noise = average_value(&priv->average_noise); | |
9587 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | | |
b191608a | 9588 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
43f66a6c JK |
9589 | |
9590 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); | |
9591 | wstats->discard.retries = priv->last_tx_failures; | |
9592 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; | |
bf79451e | 9593 | |
43f66a6c JK |
9594 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
9595 | goto fail_get_ordinal; | |
9596 | wstats->discard.retries += tx_retry; */ | |
bf79451e | 9597 | |
43f66a6c JK |
9598 | return wstats; |
9599 | } | |
9600 | ||
43f66a6c JK |
9601 | /* net device stuff */ |
9602 | ||
858119e1 | 9603 | static void init_sys_config(struct ipw_sys_config *sys_config) |
43f66a6c | 9604 | { |
0edd5b44 | 9605 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
810dabd4 | 9606 | sys_config->bt_coexistence = 0; |
43f66a6c JK |
9607 | sys_config->answer_broadcast_ssid_probe = 0; |
9608 | sys_config->accept_all_data_frames = 0; | |
9609 | sys_config->accept_non_directed_frames = 1; | |
9610 | sys_config->exclude_unicast_unencrypted = 0; | |
9611 | sys_config->disable_unicast_decryption = 1; | |
9612 | sys_config->exclude_multicast_unencrypted = 0; | |
9613 | sys_config->disable_multicast_decryption = 1; | |
71de1f3d | 9614 | sys_config->antenna_diversity = CFG_SYS_ANTENNA_SLOW_DIV; |
0edd5b44 | 9615 | sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */ |
43f66a6c | 9616 | sys_config->dot11g_auto_detection = 0; |
bf79451e | 9617 | sys_config->enable_cts_to_self = 0; |
43f66a6c | 9618 | sys_config->bt_coexist_collision_thr = 0; |
c848d0af | 9619 | sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256 |
12977154 | 9620 | sys_config->silence_threshold = 0x1e; |
43f66a6c JK |
9621 | } |
9622 | ||
9623 | static int ipw_net_open(struct net_device *dev) | |
9624 | { | |
9625 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9626 | IPW_DEBUG_INFO("dev->open\n"); | |
9627 | /* we should be verifying the device is ready to be opened */ | |
4644151b | 9628 | mutex_lock(&priv->mutex); |
bf79451e JG |
9629 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
9630 | (priv->status & STATUS_ASSOCIATED)) | |
43f66a6c | 9631 | netif_start_queue(dev); |
4644151b | 9632 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9633 | return 0; |
9634 | } | |
9635 | ||
9636 | static int ipw_net_stop(struct net_device *dev) | |
9637 | { | |
9638 | IPW_DEBUG_INFO("dev->close\n"); | |
9639 | netif_stop_queue(dev); | |
9640 | return 0; | |
9641 | } | |
9642 | ||
9643 | /* | |
9644 | todo: | |
9645 | ||
9646 | modify to send one tfd per fragment instead of using chunking. otherwise | |
9647 | we need to heavily modify the ieee80211_skb_to_txb. | |
9648 | */ | |
9649 | ||
858119e1 | 9650 | static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb, |
227d2dc1 | 9651 | int pri) |
43f66a6c | 9652 | { |
0dacca1f | 9653 | struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) |
0edd5b44 | 9654 | txb->fragments[0]->data; |
43f66a6c JK |
9655 | int i = 0; |
9656 | struct tfd_frame *tfd; | |
b095c381 JK |
9657 | #ifdef CONFIG_IPW_QOS |
9658 | int tx_id = ipw_get_tx_queue_number(priv, pri); | |
9659 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; | |
9660 | #else | |
43f66a6c | 9661 | struct clx2_tx_queue *txq = &priv->txq[0]; |
b095c381 | 9662 | #endif |
43f66a6c JK |
9663 | struct clx2_queue *q = &txq->q; |
9664 | u8 id, hdr_len, unicast; | |
9665 | u16 remaining_bytes; | |
c848d0af | 9666 | int fc; |
43f66a6c JK |
9667 | |
9668 | switch (priv->ieee->iw_mode) { | |
9669 | case IW_MODE_ADHOC: | |
9670 | hdr_len = IEEE80211_3ADDR_LEN; | |
3c19065a | 9671 | unicast = !is_multicast_ether_addr(hdr->addr1); |
43f66a6c JK |
9672 | id = ipw_find_station(priv, hdr->addr1); |
9673 | if (id == IPW_INVALID_STATION) { | |
9674 | id = ipw_add_station(priv, hdr->addr1); | |
9675 | if (id == IPW_INVALID_STATION) { | |
9676 | IPW_WARNING("Attempt to send data to " | |
bf79451e | 9677 | "invalid cell: " MAC_FMT "\n", |
43f66a6c JK |
9678 | MAC_ARG(hdr->addr1)); |
9679 | goto drop; | |
9680 | } | |
9681 | } | |
9682 | break; | |
9683 | ||
9684 | case IW_MODE_INFRA: | |
9685 | default: | |
3c19065a | 9686 | unicast = !is_multicast_ether_addr(hdr->addr3); |
43f66a6c JK |
9687 | hdr_len = IEEE80211_3ADDR_LEN; |
9688 | id = 0; | |
9689 | break; | |
9690 | } | |
9691 | ||
9692 | tfd = &txq->bd[q->first_empty]; | |
9693 | txq->txb[q->first_empty] = txb; | |
9694 | memset(tfd, 0, sizeof(*tfd)); | |
9695 | tfd->u.data.station_number = id; | |
9696 | ||
9697 | tfd->control_flags.message_type = TX_FRAME_TYPE; | |
9698 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; | |
9699 | ||
9700 | tfd->u.data.cmd_id = DINO_CMD_TX; | |
a613bffd | 9701 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
43f66a6c | 9702 | remaining_bytes = txb->payload_size; |
bf79451e | 9703 | |
43f66a6c | 9704 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
b095c381 | 9705 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
43f66a6c | 9706 | else |
b095c381 | 9707 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
43f66a6c | 9708 | |
ea2b26e0 JK |
9709 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
9710 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; | |
43f66a6c | 9711 | |
c848d0af JK |
9712 | fc = le16_to_cpu(hdr->frame_ctl); |
9713 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); | |
43f66a6c JK |
9714 | |
9715 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); | |
9716 | ||
b095c381 JK |
9717 | if (likely(unicast)) |
9718 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; | |
9719 | ||
9720 | if (txb->encrypted && !priv->ieee->host_encrypt) { | |
9721 | switch (priv->ieee->sec.level) { | |
9722 | case SEC_LEVEL_3: | |
9723 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | |
9724 | IEEE80211_FCTL_PROTECTED; | |
9725 | /* XXX: ACK flag must be set for CCMP even if it | |
9726 | * is a multicast/broadcast packet, because CCMP | |
9727 | * group communication encrypted by GTK is | |
9728 | * actually done by the AP. */ | |
9729 | if (!unicast) | |
9730 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; | |
9731 | ||
9732 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; | |
9733 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; | |
9734 | tfd->u.data.key_index = 0; | |
9735 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; | |
9736 | break; | |
9737 | case SEC_LEVEL_2: | |
9738 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | |
9739 | IEEE80211_FCTL_PROTECTED; | |
9740 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; | |
9741 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; | |
9742 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; | |
9743 | break; | |
9744 | case SEC_LEVEL_1: | |
9745 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | |
9746 | IEEE80211_FCTL_PROTECTED; | |
9747 | tfd->u.data.key_index = priv->ieee->tx_keyidx; | |
9748 | if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <= | |
9749 | 40) | |
9750 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; | |
9751 | else | |
9752 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; | |
9753 | break; | |
9754 | case SEC_LEVEL_0: | |
9755 | break; | |
9756 | default: | |
9757 | printk(KERN_ERR "Unknow security level %d\n", | |
9758 | priv->ieee->sec.level); | |
9759 | break; | |
9760 | } | |
9761 | } else | |
9762 | /* No hardware encryption */ | |
9763 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; | |
9764 | ||
9765 | #ifdef CONFIG_IPW_QOS | |
9766 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast); | |
9767 | #endif /* CONFIG_IPW_QOS */ | |
9768 | ||
43f66a6c | 9769 | /* payload */ |
a613bffd JK |
9770 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
9771 | txb->nr_frags)); | |
9772 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", | |
9773 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); | |
9774 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { | |
9775 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", | |
9776 | i, le32_to_cpu(tfd->u.data.num_chunks), | |
9777 | txb->fragments[i]->len - hdr_len); | |
bf79451e | 9778 | IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n", |
43f66a6c JK |
9779 | i, tfd->u.data.num_chunks, |
9780 | txb->fragments[i]->len - hdr_len); | |
bf79451e | 9781 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
43f66a6c JK |
9782 | txb->fragments[i]->len - hdr_len); |
9783 | ||
0edd5b44 | 9784 | tfd->u.data.chunk_ptr[i] = |
a613bffd JK |
9785 | cpu_to_le32(pci_map_single |
9786 | (priv->pci_dev, | |
9787 | txb->fragments[i]->data + hdr_len, | |
9788 | txb->fragments[i]->len - hdr_len, | |
9789 | PCI_DMA_TODEVICE)); | |
9790 | tfd->u.data.chunk_len[i] = | |
9791 | cpu_to_le16(txb->fragments[i]->len - hdr_len); | |
43f66a6c JK |
9792 | } |
9793 | ||
9794 | if (i != txb->nr_frags) { | |
9795 | struct sk_buff *skb; | |
9796 | u16 remaining_bytes = 0; | |
9797 | int j; | |
9798 | ||
9799 | for (j = i; j < txb->nr_frags; j++) | |
9800 | remaining_bytes += txb->fragments[j]->len - hdr_len; | |
9801 | ||
9802 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", | |
9803 | remaining_bytes); | |
9804 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); | |
9805 | if (skb != NULL) { | |
a613bffd | 9806 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
43f66a6c JK |
9807 | for (j = i; j < txb->nr_frags; j++) { |
9808 | int size = txb->fragments[j]->len - hdr_len; | |
afbf30a2 | 9809 | |
43f66a6c | 9810 | printk(KERN_INFO "Adding frag %d %d...\n", |
0edd5b44 | 9811 | j, size); |
43f66a6c | 9812 | memcpy(skb_put(skb, size), |
0edd5b44 | 9813 | txb->fragments[j]->data + hdr_len, size); |
43f66a6c JK |
9814 | } |
9815 | dev_kfree_skb_any(txb->fragments[i]); | |
9816 | txb->fragments[i] = skb; | |
0edd5b44 | 9817 | tfd->u.data.chunk_ptr[i] = |
a613bffd JK |
9818 | cpu_to_le32(pci_map_single |
9819 | (priv->pci_dev, skb->data, | |
9820 | tfd->u.data.chunk_len[i], | |
9821 | PCI_DMA_TODEVICE)); | |
9822 | ||
9823 | tfd->u.data.num_chunks = | |
9824 | cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) + | |
9825 | 1); | |
bf79451e | 9826 | } |
43f66a6c JK |
9827 | } |
9828 | ||
9829 | /* kick DMA */ | |
9830 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); | |
9831 | ipw_write32(priv, q->reg_w, q->first_empty); | |
9832 | ||
f697014a JK |
9833 | if (ipw_queue_space(q) < q->high_mark) |
9834 | netif_stop_queue(priv->net_dev); | |
9835 | ||
227d2dc1 | 9836 | return NETDEV_TX_OK; |
43f66a6c | 9837 | |
0edd5b44 | 9838 | drop: |
43f66a6c JK |
9839 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
9840 | ieee80211_txb_free(txb); | |
227d2dc1 JK |
9841 | return NETDEV_TX_OK; |
9842 | } | |
9843 | ||
9844 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) | |
9845 | { | |
9846 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9847 | #ifdef CONFIG_IPW_QOS | |
9848 | int tx_id = ipw_get_tx_queue_number(priv, pri); | |
9849 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; | |
9850 | #else | |
9851 | struct clx2_tx_queue *txq = &priv->txq[0]; | |
9852 | #endif /* CONFIG_IPW_QOS */ | |
9853 | ||
9854 | if (ipw_queue_space(&txq->q) < txq->q.high_mark) | |
9855 | return 1; | |
9856 | ||
9857 | return 0; | |
43f66a6c JK |
9858 | } |
9859 | ||
9860 | static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, | |
c8d42d1a | 9861 | struct net_device *dev, int pri) |
43f66a6c JK |
9862 | { |
9863 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9864 | unsigned long flags; | |
227d2dc1 | 9865 | int ret; |
43f66a6c JK |
9866 | |
9867 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); | |
43f66a6c JK |
9868 | spin_lock_irqsave(&priv->lock, flags); |
9869 | ||
9870 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
9871 | IPW_DEBUG_INFO("Tx attempt while not associated.\n"); | |
9872 | priv->ieee->stats.tx_carrier_errors++; | |
9873 | netif_stop_queue(dev); | |
9874 | goto fail_unlock; | |
9875 | } | |
9876 | ||
227d2dc1 JK |
9877 | ret = ipw_tx_skb(priv, txb, pri); |
9878 | if (ret == NETDEV_TX_OK) | |
9879 | __ipw_led_activity_on(priv); | |
43f66a6c | 9880 | spin_unlock_irqrestore(&priv->lock, flags); |
43f66a6c | 9881 | |
227d2dc1 | 9882 | return ret; |
43f66a6c | 9883 | |
0edd5b44 | 9884 | fail_unlock: |
43f66a6c JK |
9885 | spin_unlock_irqrestore(&priv->lock, flags); |
9886 | return 1; | |
9887 | } | |
9888 | ||
9889 | static struct net_device_stats *ipw_net_get_stats(struct net_device *dev) | |
9890 | { | |
9891 | struct ipw_priv *priv = ieee80211_priv(dev); | |
bf79451e | 9892 | |
43f66a6c JK |
9893 | priv->ieee->stats.tx_packets = priv->tx_packets; |
9894 | priv->ieee->stats.rx_packets = priv->rx_packets; | |
9895 | return &priv->ieee->stats; | |
9896 | } | |
9897 | ||
9898 | static void ipw_net_set_multicast_list(struct net_device *dev) | |
9899 | { | |
9900 | ||
9901 | } | |
9902 | ||
9903 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) | |
9904 | { | |
9905 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9906 | struct sockaddr *addr = p; | |
9907 | if (!is_valid_ether_addr(addr->sa_data)) | |
9908 | return -EADDRNOTAVAIL; | |
4644151b | 9909 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9910 | priv->config |= CFG_CUSTOM_MAC; |
9911 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); | |
9912 | printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n", | |
9913 | priv->net_dev->name, MAC_ARG(priv->mac_addr)); | |
a613bffd | 9914 | queue_work(priv->workqueue, &priv->adapter_restart); |
4644151b | 9915 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9916 | return 0; |
9917 | } | |
9918 | ||
bf79451e | 9919 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
43f66a6c JK |
9920 | struct ethtool_drvinfo *info) |
9921 | { | |
9922 | struct ipw_priv *p = ieee80211_priv(dev); | |
9923 | char vers[64]; | |
9924 | char date[32]; | |
9925 | u32 len; | |
9926 | ||
9927 | strcpy(info->driver, DRV_NAME); | |
9928 | strcpy(info->version, DRV_VERSION); | |
9929 | ||
9930 | len = sizeof(vers); | |
9931 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); | |
9932 | len = sizeof(date); | |
9933 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); | |
9934 | ||
0edd5b44 | 9935 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
43f66a6c JK |
9936 | vers, date); |
9937 | strcpy(info->bus_info, pci_name(p->pci_dev)); | |
b095c381 | 9938 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
43f66a6c JK |
9939 | } |
9940 | ||
9941 | static u32 ipw_ethtool_get_link(struct net_device *dev) | |
9942 | { | |
9943 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9944 | return (priv->status & STATUS_ASSOCIATED) != 0; | |
9945 | } | |
9946 | ||
9947 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) | |
9948 | { | |
b095c381 | 9949 | return IPW_EEPROM_IMAGE_SIZE; |
43f66a6c JK |
9950 | } |
9951 | ||
9952 | static int ipw_ethtool_get_eeprom(struct net_device *dev, | |
0edd5b44 | 9953 | struct ethtool_eeprom *eeprom, u8 * bytes) |
43f66a6c JK |
9954 | { |
9955 | struct ipw_priv *p = ieee80211_priv(dev); | |
9956 | ||
b095c381 | 9957 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
43f66a6c | 9958 | return -EINVAL; |
4644151b | 9959 | mutex_lock(&p->mutex); |
afbf30a2 | 9960 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
4644151b | 9961 | mutex_unlock(&p->mutex); |
43f66a6c JK |
9962 | return 0; |
9963 | } | |
9964 | ||
9965 | static int ipw_ethtool_set_eeprom(struct net_device *dev, | |
0edd5b44 | 9966 | struct ethtool_eeprom *eeprom, u8 * bytes) |
43f66a6c JK |
9967 | { |
9968 | struct ipw_priv *p = ieee80211_priv(dev); | |
9969 | int i; | |
9970 | ||
b095c381 | 9971 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
43f66a6c | 9972 | return -EINVAL; |
4644151b | 9973 | mutex_lock(&p->mutex); |
afbf30a2 | 9974 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
71e585fc AB |
9975 | for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++) |
9976 | ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]); | |
4644151b | 9977 | mutex_unlock(&p->mutex); |
43f66a6c JK |
9978 | return 0; |
9979 | } | |
9980 | ||
9981 | static struct ethtool_ops ipw_ethtool_ops = { | |
ea2b26e0 JK |
9982 | .get_link = ipw_ethtool_get_link, |
9983 | .get_drvinfo = ipw_ethtool_get_drvinfo, | |
9984 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, | |
9985 | .get_eeprom = ipw_ethtool_get_eeprom, | |
9986 | .set_eeprom = ipw_ethtool_set_eeprom, | |
43f66a6c JK |
9987 | }; |
9988 | ||
9989 | static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) | |
9990 | { | |
9991 | struct ipw_priv *priv = data; | |
9992 | u32 inta, inta_mask; | |
bf79451e | 9993 | |
43f66a6c JK |
9994 | if (!priv) |
9995 | return IRQ_NONE; | |
9996 | ||
9997 | spin_lock(&priv->lock); | |
9998 | ||
9999 | if (!(priv->status & STATUS_INT_ENABLED)) { | |
10000 | /* Shared IRQ */ | |
10001 | goto none; | |
10002 | } | |
10003 | ||
b095c381 JK |
10004 | inta = ipw_read32(priv, IPW_INTA_RW); |
10005 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); | |
bf79451e | 10006 | |
43f66a6c JK |
10007 | if (inta == 0xFFFFFFFF) { |
10008 | /* Hardware disappeared */ | |
10009 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); | |
10010 | goto none; | |
10011 | } | |
10012 | ||
b095c381 | 10013 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
43f66a6c JK |
10014 | /* Shared interrupt */ |
10015 | goto none; | |
10016 | } | |
10017 | ||
10018 | /* tell the device to stop sending interrupts */ | |
10019 | ipw_disable_interrupts(priv); | |
bf79451e | 10020 | |
43f66a6c | 10021 | /* ack current interrupts */ |
b095c381 JK |
10022 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
10023 | ipw_write32(priv, IPW_INTA_RW, inta); | |
bf79451e | 10024 | |
43f66a6c JK |
10025 | /* Cache INTA value for our tasklet */ |
10026 | priv->isr_inta = inta; | |
10027 | ||
10028 | tasklet_schedule(&priv->irq_tasklet); | |
10029 | ||
0edd5b44 | 10030 | spin_unlock(&priv->lock); |
43f66a6c JK |
10031 | |
10032 | return IRQ_HANDLED; | |
0edd5b44 | 10033 | none: |
43f66a6c JK |
10034 | spin_unlock(&priv->lock); |
10035 | return IRQ_NONE; | |
10036 | } | |
10037 | ||
10038 | static void ipw_rf_kill(void *adapter) | |
10039 | { | |
10040 | struct ipw_priv *priv = adapter; | |
10041 | unsigned long flags; | |
bf79451e | 10042 | |
43f66a6c JK |
10043 | spin_lock_irqsave(&priv->lock, flags); |
10044 | ||
10045 | if (rf_kill_active(priv)) { | |
10046 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); | |
10047 | if (priv->workqueue) | |
10048 | queue_delayed_work(priv->workqueue, | |
10049 | &priv->rf_kill, 2 * HZ); | |
10050 | goto exit_unlock; | |
10051 | } | |
10052 | ||
10053 | /* RF Kill is now disabled, so bring the device back up */ | |
10054 | ||
10055 | if (!(priv->status & STATUS_RF_KILL_MASK)) { | |
10056 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " | |
10057 | "device\n"); | |
10058 | ||
10059 | /* we can not do an adapter restart while inside an irq lock */ | |
10060 | queue_work(priv->workqueue, &priv->adapter_restart); | |
bf79451e | 10061 | } else |
43f66a6c JK |
10062 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
10063 | "enabled\n"); | |
10064 | ||
0edd5b44 | 10065 | exit_unlock: |
43f66a6c JK |
10066 | spin_unlock_irqrestore(&priv->lock, flags); |
10067 | } | |
10068 | ||
c848d0af JK |
10069 | static void ipw_bg_rf_kill(void *data) |
10070 | { | |
10071 | struct ipw_priv *priv = data; | |
4644151b | 10072 | mutex_lock(&priv->mutex); |
c848d0af | 10073 | ipw_rf_kill(data); |
4644151b | 10074 | mutex_unlock(&priv->mutex); |
c848d0af JK |
10075 | } |
10076 | ||
a73e22b2 | 10077 | static void ipw_link_up(struct ipw_priv *priv) |
a613bffd | 10078 | { |
afbf30a2 JK |
10079 | priv->last_seq_num = -1; |
10080 | priv->last_frag_num = -1; | |
10081 | priv->last_packet_time = 0; | |
10082 | ||
a613bffd JK |
10083 | netif_carrier_on(priv->net_dev); |
10084 | if (netif_queue_stopped(priv->net_dev)) { | |
10085 | IPW_DEBUG_NOTIF("waking queue\n"); | |
10086 | netif_wake_queue(priv->net_dev); | |
10087 | } else { | |
10088 | IPW_DEBUG_NOTIF("starting queue\n"); | |
10089 | netif_start_queue(priv->net_dev); | |
10090 | } | |
10091 | ||
c848d0af | 10092 | cancel_delayed_work(&priv->request_scan); |
a613bffd JK |
10093 | ipw_reset_stats(priv); |
10094 | /* Ensure the rate is updated immediately */ | |
10095 | priv->last_rate = ipw_get_current_rate(priv); | |
10096 | ipw_gather_stats(priv); | |
10097 | ipw_led_link_up(priv); | |
10098 | notify_wx_assoc_event(priv); | |
10099 | ||
10100 | if (priv->config & CFG_BACKGROUND_SCAN) | |
10101 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); | |
10102 | } | |
10103 | ||
c848d0af JK |
10104 | static void ipw_bg_link_up(void *data) |
10105 | { | |
10106 | struct ipw_priv *priv = data; | |
4644151b | 10107 | mutex_lock(&priv->mutex); |
c848d0af | 10108 | ipw_link_up(data); |
4644151b | 10109 | mutex_unlock(&priv->mutex); |
c848d0af JK |
10110 | } |
10111 | ||
a73e22b2 | 10112 | static void ipw_link_down(struct ipw_priv *priv) |
a613bffd JK |
10113 | { |
10114 | ipw_led_link_down(priv); | |
10115 | netif_carrier_off(priv->net_dev); | |
10116 | netif_stop_queue(priv->net_dev); | |
10117 | notify_wx_assoc_event(priv); | |
10118 | ||
10119 | /* Cancel any queued work ... */ | |
10120 | cancel_delayed_work(&priv->request_scan); | |
10121 | cancel_delayed_work(&priv->adhoc_check); | |
10122 | cancel_delayed_work(&priv->gather_stats); | |
10123 | ||
10124 | ipw_reset_stats(priv); | |
10125 | ||
afbf30a2 JK |
10126 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
10127 | /* Queue up another scan... */ | |
10128 | queue_work(priv->workqueue, &priv->request_scan); | |
10129 | } | |
a613bffd JK |
10130 | } |
10131 | ||
c848d0af JK |
10132 | static void ipw_bg_link_down(void *data) |
10133 | { | |
10134 | struct ipw_priv *priv = data; | |
4644151b | 10135 | mutex_lock(&priv->mutex); |
c848d0af | 10136 | ipw_link_down(data); |
4644151b | 10137 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10138 | } |
10139 | ||
10140 | static int ipw_setup_deferred_work(struct ipw_priv *priv) | |
10141 | { | |
10142 | int ret = 0; | |
10143 | ||
43f66a6c | 10144 | priv->workqueue = create_workqueue(DRV_NAME); |
43f66a6c | 10145 | init_waitqueue_head(&priv->wait_command_queue); |
afbf30a2 | 10146 | init_waitqueue_head(&priv->wait_state); |
43f66a6c | 10147 | |
c848d0af JK |
10148 | INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv); |
10149 | INIT_WORK(&priv->associate, ipw_bg_associate, priv); | |
10150 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv); | |
d8bad6df | 10151 | INIT_WORK(&priv->system_config, ipw_system_config, priv); |
c848d0af JK |
10152 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv); |
10153 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv); | |
10154 | INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv); | |
10155 | INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv); | |
10156 | INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv); | |
bf79451e | 10157 | INIT_WORK(&priv->request_scan, |
43f66a6c | 10158 | (void (*)(void *))ipw_request_scan, priv); |
bf79451e | 10159 | INIT_WORK(&priv->gather_stats, |
c848d0af JK |
10160 | (void (*)(void *))ipw_bg_gather_stats, priv); |
10161 | INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv); | |
10162 | INIT_WORK(&priv->roam, ipw_bg_roam, priv); | |
10163 | INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv); | |
10164 | INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv); | |
10165 | INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv); | |
10166 | INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on, | |
10167 | priv); | |
10168 | INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off, | |
a613bffd | 10169 | priv); |
c848d0af | 10170 | INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off, |
a613bffd | 10171 | priv); |
c848d0af JK |
10172 | INIT_WORK(&priv->merge_networks, |
10173 | (void (*)(void *))ipw_merge_adhoc_network, priv); | |
43f66a6c | 10174 | |
b095c381 JK |
10175 | #ifdef CONFIG_IPW_QOS |
10176 | INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate, | |
10177 | priv); | |
10178 | #endif /* CONFIG_IPW_QOS */ | |
43f66a6c JK |
10179 | |
10180 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) | |
10181 | ipw_irq_tasklet, (unsigned long)priv); | |
10182 | ||
10183 | return ret; | |
10184 | } | |
10185 | ||
43f66a6c JK |
10186 | static void shim__set_security(struct net_device *dev, |
10187 | struct ieee80211_security *sec) | |
10188 | { | |
10189 | struct ipw_priv *priv = ieee80211_priv(dev); | |
10190 | int i; | |
bf79451e | 10191 | for (i = 0; i < 4; i++) { |
43f66a6c | 10192 | if (sec->flags & (1 << i)) { |
afbf30a2 | 10193 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
b095c381 | 10194 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
43f66a6c | 10195 | if (sec->key_sizes[i] == 0) |
b095c381 JK |
10196 | priv->ieee->sec.flags &= ~(1 << i); |
10197 | else { | |
10198 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], | |
43f66a6c | 10199 | sec->key_sizes[i]); |
b095c381 JK |
10200 | priv->ieee->sec.flags |= (1 << i); |
10201 | } | |
43f66a6c | 10202 | priv->status |= STATUS_SECURITY_UPDATED; |
b095c381 JK |
10203 | } else if (sec->level != SEC_LEVEL_1) |
10204 | priv->ieee->sec.flags &= ~(1 << i); | |
43f66a6c JK |
10205 | } |
10206 | ||
b095c381 | 10207 | if (sec->flags & SEC_ACTIVE_KEY) { |
43f66a6c | 10208 | if (sec->active_key <= 3) { |
b095c381 JK |
10209 | priv->ieee->sec.active_key = sec->active_key; |
10210 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; | |
bf79451e | 10211 | } else |
b095c381 | 10212 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
43f66a6c | 10213 | priv->status |= STATUS_SECURITY_UPDATED; |
b095c381 JK |
10214 | } else |
10215 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; | |
43f66a6c JK |
10216 | |
10217 | if ((sec->flags & SEC_AUTH_MODE) && | |
b095c381 JK |
10218 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
10219 | priv->ieee->sec.auth_mode = sec->auth_mode; | |
10220 | priv->ieee->sec.flags |= SEC_AUTH_MODE; | |
43f66a6c JK |
10221 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
10222 | priv->capability |= CAP_SHARED_KEY; | |
10223 | else | |
10224 | priv->capability &= ~CAP_SHARED_KEY; | |
10225 | priv->status |= STATUS_SECURITY_UPDATED; | |
10226 | } | |
bf79451e | 10227 | |
b095c381 JK |
10228 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
10229 | priv->ieee->sec.flags |= SEC_ENABLED; | |
10230 | priv->ieee->sec.enabled = sec->enabled; | |
43f66a6c | 10231 | priv->status |= STATUS_SECURITY_UPDATED; |
bf79451e | 10232 | if (sec->enabled) |
43f66a6c JK |
10233 | priv->capability |= CAP_PRIVACY_ON; |
10234 | else | |
10235 | priv->capability &= ~CAP_PRIVACY_ON; | |
10236 | } | |
bf79451e | 10237 | |
afbf30a2 JK |
10238 | if (sec->flags & SEC_ENCRYPT) |
10239 | priv->ieee->sec.encrypt = sec->encrypt; | |
bf79451e | 10240 | |
b095c381 JK |
10241 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
10242 | priv->ieee->sec.level = sec->level; | |
10243 | priv->ieee->sec.flags |= SEC_LEVEL; | |
43f66a6c JK |
10244 | priv->status |= STATUS_SECURITY_UPDATED; |
10245 | } | |
10246 | ||
1fbfea54 ZY |
10247 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
10248 | ipw_set_hwcrypto_keys(priv); | |
10249 | ||
bf79451e JG |
10250 | /* To match current functionality of ipw2100 (which works well w/ |
10251 | * various supplicants, we don't force a disassociate if the | |
43f66a6c JK |
10252 | * privacy capability changes ... */ |
10253 | #if 0 | |
10254 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && | |
bf79451e | 10255 | (((priv->assoc_request.capability & |
43f66a6c | 10256 | WLAN_CAPABILITY_PRIVACY) && !sec->enabled) || |
bf79451e | 10257 | (!(priv->assoc_request.capability & |
0edd5b44 | 10258 | WLAN_CAPABILITY_PRIVACY) && sec->enabled))) { |
43f66a6c JK |
10259 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
10260 | "change.\n"); | |
10261 | ipw_disassociate(priv); | |
10262 | } | |
10263 | #endif | |
10264 | } | |
10265 | ||
bf79451e | 10266 | static int init_supported_rates(struct ipw_priv *priv, |
43f66a6c JK |
10267 | struct ipw_supported_rates *rates) |
10268 | { | |
10269 | /* TODO: Mask out rates based on priv->rates_mask */ | |
10270 | ||
10271 | memset(rates, 0, sizeof(*rates)); | |
0edd5b44 | 10272 | /* configure supported rates */ |
43f66a6c JK |
10273 | switch (priv->ieee->freq_band) { |
10274 | case IEEE80211_52GHZ_BAND: | |
10275 | rates->ieee_mode = IPW_A_MODE; | |
10276 | rates->purpose = IPW_RATE_CAPABILITIES; | |
10277 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, | |
10278 | IEEE80211_OFDM_DEFAULT_RATES_MASK); | |
10279 | break; | |
10280 | ||
0edd5b44 | 10281 | default: /* Mixed or 2.4Ghz */ |
43f66a6c JK |
10282 | rates->ieee_mode = IPW_G_MODE; |
10283 | rates->purpose = IPW_RATE_CAPABILITIES; | |
10284 | ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, | |
10285 | IEEE80211_CCK_DEFAULT_RATES_MASK); | |
10286 | if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) { | |
10287 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, | |
10288 | IEEE80211_OFDM_DEFAULT_RATES_MASK); | |
10289 | } | |
10290 | break; | |
10291 | } | |
10292 | ||
10293 | return 0; | |
10294 | } | |
10295 | ||
bf79451e | 10296 | static int ipw_config(struct ipw_priv *priv) |
43f66a6c | 10297 | { |
43f66a6c JK |
10298 | /* This is only called from ipw_up, which resets/reloads the firmware |
10299 | so, we don't need to first disable the card before we configure | |
10300 | it */ | |
6de9f7f2 | 10301 | if (ipw_set_tx_power(priv)) |
43f66a6c JK |
10302 | goto error; |
10303 | ||
10304 | /* initialize adapter address */ | |
10305 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) | |
10306 | goto error; | |
10307 | ||
10308 | /* set basic system config settings */ | |
10309 | init_sys_config(&priv->sys_config); | |
810dabd4 ZY |
10310 | |
10311 | /* Support Bluetooth if we have BT h/w on board, and user wants to. | |
10312 | * Does not support BT priority yet (don't abort or defer our Tx) */ | |
10313 | if (bt_coexist) { | |
2638bc39 | 10314 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
810dabd4 ZY |
10315 | |
10316 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) | |
10317 | priv->sys_config.bt_coexistence | |
2638bc39 | 10318 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
810dabd4 ZY |
10319 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
10320 | priv->sys_config.bt_coexistence | |
2638bc39 | 10321 | |= CFG_BT_COEXISTENCE_OOB; |
810dabd4 ZY |
10322 | } |
10323 | ||
c848d0af JK |
10324 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
10325 | priv->sys_config.answer_broadcast_ssid_probe = 1; | |
10326 | else | |
10327 | priv->sys_config.answer_broadcast_ssid_probe = 0; | |
10328 | ||
43f66a6c JK |
10329 | if (ipw_send_system_config(priv, &priv->sys_config)) |
10330 | goto error; | |
10331 | ||
0edd5b44 JG |
10332 | init_supported_rates(priv, &priv->rates); |
10333 | if (ipw_send_supported_rates(priv, &priv->rates)) | |
43f66a6c JK |
10334 | goto error; |
10335 | ||
10336 | /* Set request-to-send threshold */ | |
10337 | if (priv->rts_threshold) { | |
10338 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) | |
10339 | goto error; | |
10340 | } | |
b095c381 JK |
10341 | #ifdef CONFIG_IPW_QOS |
10342 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); | |
10343 | ipw_qos_activate(priv, NULL); | |
10344 | #endif /* CONFIG_IPW_QOS */ | |
43f66a6c JK |
10345 | |
10346 | if (ipw_set_random_seed(priv)) | |
10347 | goto error; | |
bf79451e | 10348 | |
43f66a6c JK |
10349 | /* final state transition to the RUN state */ |
10350 | if (ipw_send_host_complete(priv)) | |
10351 | goto error; | |
10352 | ||
e666619e JK |
10353 | priv->status |= STATUS_INIT; |
10354 | ||
10355 | ipw_led_init(priv); | |
10356 | ipw_led_radio_on(priv); | |
10357 | priv->notif_missed_beacons = 0; | |
10358 | ||
10359 | /* Set hardware WEP key if it is configured. */ | |
10360 | if ((priv->capability & CAP_PRIVACY_ON) && | |
10361 | (priv->ieee->sec.level == SEC_LEVEL_1) && | |
10362 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) | |
10363 | ipw_set_hwcrypto_keys(priv); | |
43f66a6c JK |
10364 | |
10365 | return 0; | |
bf79451e | 10366 | |
0edd5b44 | 10367 | error: |
43f66a6c JK |
10368 | return -EIO; |
10369 | } | |
10370 | ||
4f36f808 JK |
10371 | /* |
10372 | * NOTE: | |
10373 | * | |
10374 | * These tables have been tested in conjunction with the | |
10375 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. | |
10376 | * | |
10377 | * Altering this values, using it on other hardware, or in geographies | |
10378 | * not intended for resale of the above mentioned Intel adapters has | |
10379 | * not been tested. | |
10380 | * | |
48a84770 HBA |
10381 | * Remember to update the table in README.ipw2200 when changing this |
10382 | * table. | |
10383 | * | |
4f36f808 JK |
10384 | */ |
10385 | static const struct ieee80211_geo ipw_geos[] = { | |
10386 | { /* Restricted */ | |
10387 | "---", | |
10388 | .bg_channels = 11, | |
10389 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10390 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10391 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10392 | {2457, 10}, {2462, 11}}, | |
10393 | }, | |
10394 | ||
10395 | { /* Custom US/Canada */ | |
10396 | "ZZF", | |
10397 | .bg_channels = 11, | |
10398 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10399 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10400 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10401 | {2457, 10}, {2462, 11}}, | |
10402 | .a_channels = 8, | |
10403 | .a = {{5180, 36}, | |
10404 | {5200, 40}, | |
10405 | {5220, 44}, | |
10406 | {5240, 48}, | |
10407 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10408 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10409 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10410 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}}, | |
10411 | }, | |
10412 | ||
10413 | { /* Rest of World */ | |
10414 | "ZZD", | |
10415 | .bg_channels = 13, | |
10416 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10417 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10418 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10419 | {2457, 10}, {2462, 11}, {2467, 12}, | |
10420 | {2472, 13}}, | |
10421 | }, | |
10422 | ||
10423 | { /* Custom USA & Europe & High */ | |
10424 | "ZZA", | |
10425 | .bg_channels = 11, | |
10426 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10427 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10428 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10429 | {2457, 10}, {2462, 11}}, | |
10430 | .a_channels = 13, | |
10431 | .a = {{5180, 36}, | |
10432 | {5200, 40}, | |
10433 | {5220, 44}, | |
10434 | {5240, 48}, | |
10435 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10436 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10437 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10438 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10439 | {5745, 149}, | |
10440 | {5765, 153}, | |
10441 | {5785, 157}, | |
10442 | {5805, 161}, | |
10443 | {5825, 165}}, | |
10444 | }, | |
10445 | ||
10446 | { /* Custom NA & Europe */ | |
10447 | "ZZB", | |
10448 | .bg_channels = 11, | |
10449 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10450 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10451 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10452 | {2457, 10}, {2462, 11}}, | |
10453 | .a_channels = 13, | |
10454 | .a = {{5180, 36}, | |
10455 | {5200, 40}, | |
10456 | {5220, 44}, | |
10457 | {5240, 48}, | |
10458 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10459 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10460 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10461 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10462 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, | |
10463 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, | |
10464 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, | |
10465 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, | |
10466 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, | |
10467 | }, | |
10468 | ||
10469 | { /* Custom Japan */ | |
10470 | "ZZC", | |
10471 | .bg_channels = 11, | |
10472 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10473 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10474 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10475 | {2457, 10}, {2462, 11}}, | |
10476 | .a_channels = 4, | |
10477 | .a = {{5170, 34}, {5190, 38}, | |
10478 | {5210, 42}, {5230, 46}}, | |
10479 | }, | |
10480 | ||
10481 | { /* Custom */ | |
10482 | "ZZM", | |
10483 | .bg_channels = 11, | |
10484 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10485 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10486 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10487 | {2457, 10}, {2462, 11}}, | |
10488 | }, | |
10489 | ||
10490 | { /* Europe */ | |
10491 | "ZZE", | |
10492 | .bg_channels = 13, | |
10493 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10494 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10495 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10496 | {2457, 10}, {2462, 11}, {2467, 12}, | |
10497 | {2472, 13}}, | |
10498 | .a_channels = 19, | |
10499 | .a = {{5180, 36}, | |
10500 | {5200, 40}, | |
10501 | {5220, 44}, | |
10502 | {5240, 48}, | |
10503 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10504 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10505 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10506 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10507 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, | |
10508 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, | |
10509 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, | |
10510 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, | |
10511 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, | |
10512 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, | |
10513 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, | |
10514 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, | |
10515 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, | |
10516 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, | |
10517 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}}, | |
10518 | }, | |
10519 | ||
10520 | { /* Custom Japan */ | |
10521 | "ZZJ", | |
10522 | .bg_channels = 14, | |
10523 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10524 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10525 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10526 | {2457, 10}, {2462, 11}, {2467, 12}, | |
10527 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}}, | |
10528 | .a_channels = 4, | |
10529 | .a = {{5170, 34}, {5190, 38}, | |
10530 | {5210, 42}, {5230, 46}}, | |
10531 | }, | |
10532 | ||
03520576 JK |
10533 | { /* Rest of World */ |
10534 | "ZZR", | |
10535 | .bg_channels = 14, | |
10536 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10537 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10538 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10539 | {2457, 10}, {2462, 11}, {2467, 12}, | |
10540 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY | | |
10541 | IEEE80211_CH_PASSIVE_ONLY}}, | |
10542 | }, | |
10543 | ||
4f36f808 JK |
10544 | { /* High Band */ |
10545 | "ZZH", | |
10546 | .bg_channels = 13, | |
10547 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10548 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10549 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10550 | {2457, 10}, {2462, 11}, | |
10551 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, | |
10552 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, | |
10553 | .a_channels = 4, | |
10554 | .a = {{5745, 149}, {5765, 153}, | |
10555 | {5785, 157}, {5805, 161}}, | |
10556 | }, | |
10557 | ||
10558 | { /* Custom Europe */ | |
10559 | "ZZG", | |
10560 | .bg_channels = 13, | |
10561 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10562 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10563 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10564 | {2457, 10}, {2462, 11}, | |
10565 | {2467, 12}, {2472, 13}}, | |
10566 | .a_channels = 4, | |
10567 | .a = {{5180, 36}, {5200, 40}, | |
10568 | {5220, 44}, {5240, 48}}, | |
10569 | }, | |
10570 | ||
10571 | { /* Europe */ | |
10572 | "ZZK", | |
10573 | .bg_channels = 13, | |
10574 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10575 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10576 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10577 | {2457, 10}, {2462, 11}, | |
10578 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, | |
10579 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, | |
10580 | .a_channels = 24, | |
10581 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, | |
10582 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, | |
10583 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, | |
10584 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, | |
10585 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10586 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10587 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10588 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10589 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, | |
10590 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, | |
10591 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, | |
10592 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, | |
10593 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, | |
10594 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, | |
10595 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, | |
10596 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, | |
10597 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, | |
10598 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, | |
10599 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}, | |
10600 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, | |
10601 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, | |
10602 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, | |
10603 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, | |
10604 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, | |
10605 | }, | |
10606 | ||
10607 | { /* Europe */ | |
10608 | "ZZL", | |
10609 | .bg_channels = 11, | |
10610 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10611 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10612 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10613 | {2457, 10}, {2462, 11}}, | |
10614 | .a_channels = 13, | |
10615 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, | |
10616 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, | |
10617 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, | |
10618 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, | |
10619 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10620 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10621 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10622 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10623 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, | |
10624 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, | |
10625 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, | |
10626 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, | |
10627 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, | |
10628 | } | |
afbf30a2 JK |
10629 | }; |
10630 | ||
43f66a6c JK |
10631 | #define MAX_HW_RESTARTS 5 |
10632 | static int ipw_up(struct ipw_priv *priv) | |
10633 | { | |
4f36f808 | 10634 | int rc, i, j; |
43f66a6c JK |
10635 | |
10636 | if (priv->status & STATUS_EXIT_PENDING) | |
10637 | return -EIO; | |
10638 | ||
f6c5cb7c JK |
10639 | if (cmdlog && !priv->cmdlog) { |
10640 | priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog, | |
10641 | GFP_KERNEL); | |
10642 | if (priv->cmdlog == NULL) { | |
10643 | IPW_ERROR("Error allocating %d command log entries.\n", | |
10644 | cmdlog); | |
10645 | } else { | |
10646 | memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog); | |
10647 | priv->cmdlog_len = cmdlog; | |
10648 | } | |
10649 | } | |
10650 | ||
0edd5b44 | 10651 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
bf79451e | 10652 | /* Load the microcode, firmware, and eeprom. |
43f66a6c JK |
10653 | * Also start the clocks. */ |
10654 | rc = ipw_load(priv); | |
10655 | if (rc) { | |
a4f6bbb3 | 10656 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
43f66a6c JK |
10657 | return rc; |
10658 | } | |
10659 | ||
10660 | ipw_init_ordinals(priv); | |
10661 | if (!(priv->config & CFG_CUSTOM_MAC)) | |
10662 | eeprom_parse_mac(priv, priv->mac_addr); | |
10663 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); | |
10664 | ||
4f36f808 JK |
10665 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
10666 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], | |
10667 | ipw_geos[j].name, 3)) | |
10668 | break; | |
10669 | } | |
03520576 JK |
10670 | if (j == ARRAY_SIZE(ipw_geos)) { |
10671 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", | |
10672 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], | |
10673 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], | |
10674 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); | |
4f36f808 | 10675 | j = 0; |
03520576 | 10676 | } |
1867b117 | 10677 | if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) { |
4f36f808 JK |
10678 | IPW_WARNING("Could not set geography."); |
10679 | return 0; | |
10680 | } | |
10681 | ||
b095c381 JK |
10682 | if (priv->status & STATUS_RF_KILL_SW) { |
10683 | IPW_WARNING("Radio disabled by module parameter.\n"); | |
10684 | return 0; | |
10685 | } else if (rf_kill_active(priv)) { | |
10686 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" | |
10687 | "Kill switch must be turned off for " | |
10688 | "wireless networking to work.\n"); | |
10689 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | |
10690 | 2 * HZ); | |
43f66a6c | 10691 | return 0; |
c848d0af | 10692 | } |
43f66a6c JK |
10693 | |
10694 | rc = ipw_config(priv); | |
10695 | if (!rc) { | |
10696 | IPW_DEBUG_INFO("Configured device on count %i\n", i); | |
e666619e JK |
10697 | |
10698 | /* If configure to try and auto-associate, kick | |
10699 | * off a scan. */ | |
10700 | queue_work(priv->workqueue, &priv->request_scan); | |
afbf30a2 | 10701 | |
43f66a6c | 10702 | return 0; |
43f66a6c | 10703 | } |
bf79451e | 10704 | |
c848d0af | 10705 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
43f66a6c JK |
10706 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
10707 | i, MAX_HW_RESTARTS); | |
10708 | ||
10709 | /* We had an error bringing up the hardware, so take it | |
10710 | * all the way back down so we can try again */ | |
10711 | ipw_down(priv); | |
10712 | } | |
10713 | ||
bf79451e | 10714 | /* tried to restart and config the device for as long as our |
43f66a6c | 10715 | * patience could withstand */ |
0edd5b44 | 10716 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
c848d0af | 10717 | |
43f66a6c JK |
10718 | return -EIO; |
10719 | } | |
10720 | ||
c848d0af JK |
10721 | static void ipw_bg_up(void *data) |
10722 | { | |
10723 | struct ipw_priv *priv = data; | |
4644151b | 10724 | mutex_lock(&priv->mutex); |
c848d0af | 10725 | ipw_up(data); |
4644151b | 10726 | mutex_unlock(&priv->mutex); |
c848d0af JK |
10727 | } |
10728 | ||
b095c381 | 10729 | static void ipw_deinit(struct ipw_priv *priv) |
43f66a6c | 10730 | { |
b095c381 JK |
10731 | int i; |
10732 | ||
10733 | if (priv->status & STATUS_SCANNING) { | |
10734 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); | |
10735 | ipw_abort_scan(priv); | |
10736 | } | |
10737 | ||
10738 | if (priv->status & STATUS_ASSOCIATED) { | |
10739 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); | |
10740 | ipw_disassociate(priv); | |
10741 | } | |
10742 | ||
10743 | ipw_led_shutdown(priv); | |
10744 | ||
10745 | /* Wait up to 1s for status to change to not scanning and not | |
10746 | * associated (disassociation can take a while for a ful 802.11 | |
10747 | * exchange */ | |
10748 | for (i = 1000; i && (priv->status & | |
10749 | (STATUS_DISASSOCIATING | | |
10750 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) | |
10751 | udelay(10); | |
10752 | ||
10753 | if (priv->status & (STATUS_DISASSOCIATING | | |
10754 | STATUS_ASSOCIATED | STATUS_SCANNING)) | |
10755 | IPW_DEBUG_INFO("Still associated or scanning...\n"); | |
10756 | else | |
10757 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); | |
10758 | ||
43f66a6c | 10759 | /* Attempt to disable the card */ |
43f66a6c | 10760 | ipw_send_card_disable(priv, 0); |
b095c381 JK |
10761 | |
10762 | priv->status &= ~STATUS_INIT; | |
10763 | } | |
10764 | ||
10765 | static void ipw_down(struct ipw_priv *priv) | |
10766 | { | |
10767 | int exit_pending = priv->status & STATUS_EXIT_PENDING; | |
10768 | ||
10769 | priv->status |= STATUS_EXIT_PENDING; | |
10770 | ||
10771 | if (ipw_is_init(priv)) | |
10772 | ipw_deinit(priv); | |
10773 | ||
10774 | /* Wipe out the EXIT_PENDING status bit if we are not actually | |
10775 | * exiting the module */ | |
10776 | if (!exit_pending) | |
10777 | priv->status &= ~STATUS_EXIT_PENDING; | |
43f66a6c JK |
10778 | |
10779 | /* tell the device to stop sending interrupts */ | |
10780 | ipw_disable_interrupts(priv); | |
10781 | ||
10782 | /* Clear all bits but the RF Kill */ | |
b095c381 | 10783 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
43f66a6c JK |
10784 | netif_carrier_off(priv->net_dev); |
10785 | netif_stop_queue(priv->net_dev); | |
10786 | ||
10787 | ipw_stop_nic(priv); | |
a613bffd JK |
10788 | |
10789 | ipw_led_radio_off(priv); | |
43f66a6c JK |
10790 | } |
10791 | ||
c848d0af JK |
10792 | static void ipw_bg_down(void *data) |
10793 | { | |
10794 | struct ipw_priv *priv = data; | |
4644151b | 10795 | mutex_lock(&priv->mutex); |
c848d0af | 10796 | ipw_down(data); |
4644151b | 10797 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10798 | } |
10799 | ||
10800 | /* Called by register_netdev() */ | |
10801 | static int ipw_net_init(struct net_device *dev) | |
10802 | { | |
10803 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 10804 | mutex_lock(&priv->mutex); |
43f66a6c | 10805 | |
c848d0af | 10806 | if (ipw_up(priv)) { |
4644151b | 10807 | mutex_unlock(&priv->mutex); |
43f66a6c | 10808 | return -EIO; |
c848d0af | 10809 | } |
43f66a6c | 10810 | |
4644151b | 10811 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10812 | return 0; |
10813 | } | |
10814 | ||
10815 | /* PCI driver stuff */ | |
10816 | static struct pci_device_id card_ids[] = { | |
10817 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, | |
10818 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, | |
10819 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, | |
10820 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, | |
10821 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, | |
10822 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, | |
10823 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, | |
10824 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, | |
10825 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, | |
10826 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, | |
10827 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, | |
10828 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, | |
10829 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, | |
10830 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, | |
10831 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, | |
10832 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, | |
10833 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, | |
10834 | {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | |
0edd5b44 | 10835 | {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ |
a613bffd | 10836 | {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ |
0edd5b44 JG |
10837 | {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
10838 | {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ | |
bf79451e | 10839 | |
43f66a6c JK |
10840 | /* required last entry */ |
10841 | {0,} | |
10842 | }; | |
10843 | ||
10844 | MODULE_DEVICE_TABLE(pci, card_ids); | |
10845 | ||
10846 | static struct attribute *ipw_sysfs_entries[] = { | |
10847 | &dev_attr_rf_kill.attr, | |
10848 | &dev_attr_direct_dword.attr, | |
10849 | &dev_attr_indirect_byte.attr, | |
10850 | &dev_attr_indirect_dword.attr, | |
10851 | &dev_attr_mem_gpio_reg.attr, | |
10852 | &dev_attr_command_event_reg.attr, | |
10853 | &dev_attr_nic_type.attr, | |
10854 | &dev_attr_status.attr, | |
10855 | &dev_attr_cfg.attr, | |
b39860c6 JK |
10856 | &dev_attr_error.attr, |
10857 | &dev_attr_event_log.attr, | |
f6c5cb7c | 10858 | &dev_attr_cmd_log.attr, |
43f66a6c JK |
10859 | &dev_attr_eeprom_delay.attr, |
10860 | &dev_attr_ucode_version.attr, | |
10861 | &dev_attr_rtc.attr, | |
a613bffd JK |
10862 | &dev_attr_scan_age.attr, |
10863 | &dev_attr_led.attr, | |
b095c381 JK |
10864 | &dev_attr_speed_scan.attr, |
10865 | &dev_attr_net_stats.attr, | |
43f66a6c JK |
10866 | NULL |
10867 | }; | |
10868 | ||
10869 | static struct attribute_group ipw_attribute_group = { | |
10870 | .name = NULL, /* put in device directory */ | |
0edd5b44 | 10871 | .attrs = ipw_sysfs_entries, |
43f66a6c JK |
10872 | }; |
10873 | ||
0edd5b44 | 10874 | static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
43f66a6c JK |
10875 | { |
10876 | int err = 0; | |
10877 | struct net_device *net_dev; | |
10878 | void __iomem *base; | |
10879 | u32 length, val; | |
10880 | struct ipw_priv *priv; | |
afbf30a2 | 10881 | int i; |
43f66a6c JK |
10882 | |
10883 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); | |
10884 | if (net_dev == NULL) { | |
10885 | err = -ENOMEM; | |
10886 | goto out; | |
10887 | } | |
10888 | ||
10889 | priv = ieee80211_priv(net_dev); | |
10890 | priv->ieee = netdev_priv(net_dev); | |
a613bffd | 10891 | |
43f66a6c JK |
10892 | priv->net_dev = net_dev; |
10893 | priv->pci_dev = pdev; | |
0f52bf90 | 10894 | #ifdef CONFIG_IPW2200_DEBUG |
43f66a6c JK |
10895 | ipw_debug_level = debug; |
10896 | #endif | |
10897 | spin_lock_init(&priv->lock); | |
afbf30a2 JK |
10898 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
10899 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); | |
43f66a6c | 10900 | |
4644151b | 10901 | mutex_init(&priv->mutex); |
43f66a6c JK |
10902 | if (pci_enable_device(pdev)) { |
10903 | err = -ENODEV; | |
10904 | goto out_free_ieee80211; | |
10905 | } | |
10906 | ||
10907 | pci_set_master(pdev); | |
10908 | ||
0e08b44e | 10909 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
bf79451e | 10910 | if (!err) |
0e08b44e | 10911 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
43f66a6c JK |
10912 | if (err) { |
10913 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); | |
10914 | goto out_pci_disable_device; | |
10915 | } | |
10916 | ||
10917 | pci_set_drvdata(pdev, priv); | |
10918 | ||
10919 | err = pci_request_regions(pdev, DRV_NAME); | |
bf79451e | 10920 | if (err) |
43f66a6c JK |
10921 | goto out_pci_disable_device; |
10922 | ||
bf79451e | 10923 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
43f66a6c | 10924 | * PCI Tx retries from interfering with C3 CPU state */ |
bf79451e JG |
10925 | pci_read_config_dword(pdev, 0x40, &val); |
10926 | if ((val & 0x0000ff00) != 0) | |
43f66a6c | 10927 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
bf79451e | 10928 | |
43f66a6c JK |
10929 | length = pci_resource_len(pdev, 0); |
10930 | priv->hw_len = length; | |
bf79451e | 10931 | |
43f66a6c JK |
10932 | base = ioremap_nocache(pci_resource_start(pdev, 0), length); |
10933 | if (!base) { | |
10934 | err = -ENODEV; | |
10935 | goto out_pci_release_regions; | |
10936 | } | |
10937 | ||
10938 | priv->hw_base = base; | |
10939 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); | |
10940 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); | |
10941 | ||
10942 | err = ipw_setup_deferred_work(priv); | |
10943 | if (err) { | |
10944 | IPW_ERROR("Unable to setup deferred work\n"); | |
10945 | goto out_iounmap; | |
10946 | } | |
10947 | ||
b095c381 | 10948 | ipw_sw_reset(priv, 1); |
43f66a6c | 10949 | |
0edd5b44 | 10950 | err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv); |
43f66a6c JK |
10951 | if (err) { |
10952 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); | |
10953 | goto out_destroy_workqueue; | |
10954 | } | |
10955 | ||
10956 | SET_MODULE_OWNER(net_dev); | |
10957 | SET_NETDEV_DEV(net_dev, &pdev->dev); | |
10958 | ||
4644151b | 10959 | mutex_lock(&priv->mutex); |
c848d0af | 10960 | |
43f66a6c JK |
10961 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
10962 | priv->ieee->set_security = shim__set_security; | |
227d2dc1 | 10963 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
43f66a6c | 10964 | |
b095c381 | 10965 | #ifdef CONFIG_IPW_QOS |
3b9990cb JK |
10966 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
10967 | priv->ieee->handle_beacon = ipw_handle_probe_response; | |
10968 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; | |
b095c381 JK |
10969 | #endif /* CONFIG_IPW_QOS */ |
10970 | ||
c848d0af JK |
10971 | priv->ieee->perfect_rssi = -20; |
10972 | priv->ieee->worst_rssi = -85; | |
43f66a6c JK |
10973 | |
10974 | net_dev->open = ipw_net_open; | |
10975 | net_dev->stop = ipw_net_stop; | |
10976 | net_dev->init = ipw_net_init; | |
10977 | net_dev->get_stats = ipw_net_get_stats; | |
10978 | net_dev->set_multicast_list = ipw_net_set_multicast_list; | |
10979 | net_dev->set_mac_address = ipw_net_set_mac_address; | |
97a78ca9 | 10980 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
97a78ca9 | 10981 | net_dev->wireless_data = &priv->wireless_data; |
43f66a6c JK |
10982 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
10983 | net_dev->ethtool_ops = &ipw_ethtool_ops; | |
10984 | net_dev->irq = pdev->irq; | |
0edd5b44 | 10985 | net_dev->base_addr = (unsigned long)priv->hw_base; |
43f66a6c JK |
10986 | net_dev->mem_start = pci_resource_start(pdev, 0); |
10987 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; | |
10988 | ||
10989 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); | |
10990 | if (err) { | |
10991 | IPW_ERROR("failed to create sysfs device attributes\n"); | |
4644151b | 10992 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10993 | goto out_release_irq; |
10994 | } | |
10995 | ||
4644151b | 10996 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10997 | err = register_netdev(net_dev); |
10998 | if (err) { | |
10999 | IPW_ERROR("failed to register network device\n"); | |
a613bffd | 11000 | goto out_remove_sysfs; |
43f66a6c | 11001 | } |
48a84770 HBA |
11002 | |
11003 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " | |
11004 | "channels, %d 802.11a channels)\n", | |
11005 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, | |
11006 | priv->ieee->geo.a_channels); | |
11007 | ||
43f66a6c JK |
11008 | return 0; |
11009 | ||
a613bffd | 11010 | out_remove_sysfs: |
43f66a6c | 11011 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
0edd5b44 | 11012 | out_release_irq: |
43f66a6c | 11013 | free_irq(pdev->irq, priv); |
0edd5b44 | 11014 | out_destroy_workqueue: |
43f66a6c JK |
11015 | destroy_workqueue(priv->workqueue); |
11016 | priv->workqueue = NULL; | |
0edd5b44 | 11017 | out_iounmap: |
43f66a6c | 11018 | iounmap(priv->hw_base); |
0edd5b44 | 11019 | out_pci_release_regions: |
43f66a6c | 11020 | pci_release_regions(pdev); |
0edd5b44 | 11021 | out_pci_disable_device: |
43f66a6c JK |
11022 | pci_disable_device(pdev); |
11023 | pci_set_drvdata(pdev, NULL); | |
0edd5b44 | 11024 | out_free_ieee80211: |
43f66a6c | 11025 | free_ieee80211(priv->net_dev); |
0edd5b44 | 11026 | out: |
43f66a6c JK |
11027 | return err; |
11028 | } | |
11029 | ||
11030 | static void ipw_pci_remove(struct pci_dev *pdev) | |
11031 | { | |
11032 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
afbf30a2 JK |
11033 | struct list_head *p, *q; |
11034 | int i; | |
b095c381 | 11035 | |
43f66a6c JK |
11036 | if (!priv) |
11037 | return; | |
11038 | ||
4644151b | 11039 | mutex_lock(&priv->mutex); |
43f66a6c | 11040 | |
afbf30a2 | 11041 | priv->status |= STATUS_EXIT_PENDING; |
43f66a6c | 11042 | ipw_down(priv); |
43f66a6c JK |
11043 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
11044 | ||
4644151b | 11045 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
11046 | |
11047 | unregister_netdev(priv->net_dev); | |
11048 | ||
11049 | if (priv->rxq) { | |
11050 | ipw_rx_queue_free(priv, priv->rxq); | |
11051 | priv->rxq = NULL; | |
11052 | } | |
11053 | ipw_tx_queue_free(priv); | |
11054 | ||
f6c5cb7c JK |
11055 | if (priv->cmdlog) { |
11056 | kfree(priv->cmdlog); | |
11057 | priv->cmdlog = NULL; | |
11058 | } | |
43f66a6c JK |
11059 | /* ipw_down will ensure that there is no more pending work |
11060 | * in the workqueue's, so we can safely remove them now. */ | |
a613bffd JK |
11061 | cancel_delayed_work(&priv->adhoc_check); |
11062 | cancel_delayed_work(&priv->gather_stats); | |
11063 | cancel_delayed_work(&priv->request_scan); | |
11064 | cancel_delayed_work(&priv->rf_kill); | |
11065 | cancel_delayed_work(&priv->scan_check); | |
11066 | destroy_workqueue(priv->workqueue); | |
11067 | priv->workqueue = NULL; | |
43f66a6c | 11068 | |
afbf30a2 JK |
11069 | /* Free MAC hash list for ADHOC */ |
11070 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { | |
11071 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { | |
afbf30a2 | 11072 | list_del(p); |
489f4458 | 11073 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
afbf30a2 JK |
11074 | } |
11075 | } | |
11076 | ||
b39860c6 JK |
11077 | if (priv->error) { |
11078 | ipw_free_error_log(priv->error); | |
11079 | priv->error = NULL; | |
43f66a6c JK |
11080 | } |
11081 | ||
11082 | free_irq(pdev->irq, priv); | |
11083 | iounmap(priv->hw_base); | |
11084 | pci_release_regions(pdev); | |
11085 | pci_disable_device(pdev); | |
11086 | pci_set_drvdata(pdev, NULL); | |
11087 | free_ieee80211(priv->net_dev); | |
afbf30a2 | 11088 | free_firmware(); |
43f66a6c JK |
11089 | } |
11090 | ||
43f66a6c | 11091 | #ifdef CONFIG_PM |
583a4e88 | 11092 | static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
43f66a6c JK |
11093 | { |
11094 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
11095 | struct net_device *dev = priv->net_dev; | |
11096 | ||
11097 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); | |
11098 | ||
0edd5b44 | 11099 | /* Take down the device; powers it off, etc. */ |
43f66a6c JK |
11100 | ipw_down(priv); |
11101 | ||
11102 | /* Remove the PRESENT state of the device */ | |
11103 | netif_device_detach(dev); | |
11104 | ||
43f66a6c | 11105 | pci_save_state(pdev); |
43f66a6c | 11106 | pci_disable_device(pdev); |
583a4e88 | 11107 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
bf79451e | 11108 | |
43f66a6c JK |
11109 | return 0; |
11110 | } | |
11111 | ||
11112 | static int ipw_pci_resume(struct pci_dev *pdev) | |
11113 | { | |
11114 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
11115 | struct net_device *dev = priv->net_dev; | |
11116 | u32 val; | |
bf79451e | 11117 | |
43f66a6c JK |
11118 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
11119 | ||
ea2b26e0 | 11120 | pci_set_power_state(pdev, PCI_D0); |
43f66a6c | 11121 | pci_enable_device(pdev); |
43f66a6c | 11122 | pci_restore_state(pdev); |
ea2b26e0 | 11123 | |
43f66a6c JK |
11124 | /* |
11125 | * Suspend/Resume resets the PCI configuration space, so we have to | |
11126 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries | |
11127 | * from interfering with C3 CPU state. pci_restore_state won't help | |
11128 | * here since it only restores the first 64 bytes pci config header. | |
11129 | */ | |
bf79451e JG |
11130 | pci_read_config_dword(pdev, 0x40, &val); |
11131 | if ((val & 0x0000ff00) != 0) | |
43f66a6c JK |
11132 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
11133 | ||
11134 | /* Set the device back into the PRESENT state; this will also wake | |
11135 | * the queue of needed */ | |
11136 | netif_device_attach(dev); | |
11137 | ||
11138 | /* Bring the device back up */ | |
11139 | queue_work(priv->workqueue, &priv->up); | |
bf79451e | 11140 | |
43f66a6c JK |
11141 | return 0; |
11142 | } | |
11143 | #endif | |
11144 | ||
11145 | /* driver initialization stuff */ | |
11146 | static struct pci_driver ipw_driver = { | |
11147 | .name = DRV_NAME, | |
11148 | .id_table = card_ids, | |
11149 | .probe = ipw_pci_probe, | |
11150 | .remove = __devexit_p(ipw_pci_remove), | |
11151 | #ifdef CONFIG_PM | |
11152 | .suspend = ipw_pci_suspend, | |
11153 | .resume = ipw_pci_resume, | |
11154 | #endif | |
11155 | }; | |
11156 | ||
11157 | static int __init ipw_init(void) | |
11158 | { | |
11159 | int ret; | |
11160 | ||
11161 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); | |
11162 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); | |
11163 | ||
11164 | ret = pci_module_init(&ipw_driver); | |
11165 | if (ret) { | |
11166 | IPW_ERROR("Unable to initialize PCI module\n"); | |
11167 | return ret; | |
11168 | } | |
11169 | ||
0edd5b44 | 11170 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
43f66a6c JK |
11171 | if (ret) { |
11172 | IPW_ERROR("Unable to create driver sysfs file\n"); | |
11173 | pci_unregister_driver(&ipw_driver); | |
11174 | return ret; | |
11175 | } | |
11176 | ||
11177 | return ret; | |
11178 | } | |
11179 | ||
11180 | static void __exit ipw_exit(void) | |
11181 | { | |
11182 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); | |
11183 | pci_unregister_driver(&ipw_driver); | |
11184 | } | |
11185 | ||
11186 | module_param(disable, int, 0444); | |
11187 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); | |
11188 | ||
11189 | module_param(associate, int, 0444); | |
11190 | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); | |
11191 | ||
11192 | module_param(auto_create, int, 0444); | |
11193 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); | |
11194 | ||
a613bffd | 11195 | module_param(led, int, 0444); |
c848d0af | 11196 | MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n"); |
a613bffd | 11197 | |
3e1555ba | 11198 | #ifdef CONFIG_IPW2200_DEBUG |
43f66a6c JK |
11199 | module_param(debug, int, 0444); |
11200 | MODULE_PARM_DESC(debug, "debug output mask"); | |
3e1555ba | 11201 | #endif |
43f66a6c JK |
11202 | |
11203 | module_param(channel, int, 0444); | |
bf79451e | 11204 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
43f66a6c | 11205 | |
b095c381 JK |
11206 | #ifdef CONFIG_IPW_QOS |
11207 | module_param(qos_enable, int, 0444); | |
11208 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); | |
11209 | ||
11210 | module_param(qos_burst_enable, int, 0444); | |
11211 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); | |
11212 | ||
11213 | module_param(qos_no_ack_mask, int, 0444); | |
11214 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); | |
43f66a6c | 11215 | |
b095c381 JK |
11216 | module_param(burst_duration_CCK, int, 0444); |
11217 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); | |
11218 | ||
11219 | module_param(burst_duration_OFDM, int, 0444); | |
11220 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); | |
11221 | #endif /* CONFIG_IPW_QOS */ | |
11222 | ||
11223 | #ifdef CONFIG_IPW2200_MONITOR | |
43f66a6c JK |
11224 | module_param(mode, int, 0444); |
11225 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); | |
11226 | #else | |
11227 | module_param(mode, int, 0444); | |
11228 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); | |
11229 | #endif | |
11230 | ||
810dabd4 ZY |
11231 | module_param(bt_coexist, int, 0444); |
11232 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); | |
11233 | ||
b095c381 | 11234 | module_param(hwcrypto, int, 0444); |
bde37d03 | 11235 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
b095c381 | 11236 | |
f6c5cb7c JK |
11237 | module_param(cmdlog, int, 0444); |
11238 | MODULE_PARM_DESC(cmdlog, | |
11239 | "allocate a ring buffer for logging firmware commands"); | |
11240 | ||
4bfdb91d ZY |
11241 | module_param(roaming, int, 0444); |
11242 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); | |
11243 | ||
43f66a6c JK |
11244 | module_exit(ipw_exit); |
11245 | module_init(ipw_init); |