Commit | Line | Data |
---|---|---|
43f66a6c | 1 | /****************************************************************************** |
bf79451e | 2 | |
afbf30a2 | 3 | Copyright(c) 2003 - 2005 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 | |
7c97eb3f | 36 | #define IPW2200_VERSION "git-1.0.10" |
43f66a6c | 37 | #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" |
2b184d5b | 38 | #define DRV_COPYRIGHT "Copyright(c) 2003-2005 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) { |
43f66a6c | 1799 | IPW_ERROR("Firmware error detected. Restarting.\n"); |
b39860c6 JK |
1800 | if (priv->error) { |
1801 | IPW_ERROR("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) | |
1814 | IPW_ERROR("Sysfs 'error' log captured.\n"); | |
1815 | else | |
1816 | IPW_ERROR("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 | ||
2832 | struct fw_header { | |
2833 | u32 version; | |
2834 | u32 mode; | |
2835 | }; | |
2836 | ||
2837 | struct fw_chunk { | |
2838 | u32 address; | |
2839 | u32 length; | |
2840 | }; | |
2841 | ||
2842 | #define IPW_FW_MAJOR_VERSION 2 | |
81715376 | 2843 | #define IPW_FW_MINOR_VERSION 4 |
43f66a6c JK |
2844 | |
2845 | #define IPW_FW_MINOR(x) ((x & 0xff) >> 8) | |
2846 | #define IPW_FW_MAJOR(x) (x & 0xff) | |
2847 | ||
afbf30a2 | 2848 | #define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION) |
43f66a6c JK |
2849 | |
2850 | #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \ | |
2851 | "." __stringify(IPW_FW_MINOR_VERSION) "-" | |
2852 | ||
2853 | #if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0 | |
2854 | #define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw" | |
2855 | #else | |
2856 | #define IPW_FW_NAME(x) "ipw2200_" x ".fw" | |
2857 | #endif | |
2858 | ||
0edd5b44 | 2859 | static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len) |
43f66a6c JK |
2860 | { |
2861 | int rc = 0, i, addr; | |
2862 | u8 cr = 0; | |
2863 | u16 *image; | |
2864 | ||
0edd5b44 | 2865 | image = (u16 *) data; |
bf79451e | 2866 | |
43f66a6c JK |
2867 | IPW_DEBUG_TRACE(">> \n"); |
2868 | ||
2869 | rc = ipw_stop_master(priv); | |
2870 | ||
2871 | if (rc < 0) | |
2872 | return rc; | |
bf79451e | 2873 | |
0edd5b44 | 2874 | // spin_lock_irqsave(&priv->lock, flags); |
bf79451e | 2875 | |
b095c381 JK |
2876 | for (addr = IPW_SHARED_LOWER_BOUND; |
2877 | addr < IPW_REGISTER_DOMAIN1_END; addr += 4) { | |
43f66a6c JK |
2878 | ipw_write32(priv, addr, 0); |
2879 | } | |
2880 | ||
2881 | /* no ucode (yet) */ | |
2882 | memset(&priv->dino_alive, 0, sizeof(priv->dino_alive)); | |
2883 | /* destroy DMA queues */ | |
2884 | /* reset sequence */ | |
2885 | ||
b095c381 | 2886 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON); |
43f66a6c | 2887 | ipw_arc_release(priv); |
b095c381 | 2888 | ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF); |
43f66a6c JK |
2889 | mdelay(1); |
2890 | ||
2891 | /* reset PHY */ | |
b095c381 | 2892 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN); |
43f66a6c | 2893 | mdelay(1); |
bf79451e | 2894 | |
b095c381 | 2895 | ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0); |
43f66a6c | 2896 | mdelay(1); |
bf79451e | 2897 | |
43f66a6c | 2898 | /* enable ucode store */ |
c8fe6679 ZY |
2899 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0); |
2900 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS); | |
43f66a6c JK |
2901 | mdelay(1); |
2902 | ||
2903 | /* write ucode */ | |
2904 | /** | |
2905 | * @bug | |
2906 | * Do NOT set indirect address register once and then | |
2907 | * store data to indirect data register in the loop. | |
2908 | * It seems very reasonable, but in this case DINO do not | |
2909 | * accept ucode. It is essential to set address each time. | |
2910 | */ | |
2911 | /* load new ipw uCode */ | |
2912 | for (i = 0; i < len / 2; i++) | |
b095c381 | 2913 | ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE, |
a613bffd | 2914 | cpu_to_le16(image[i])); |
43f66a6c | 2915 | |
43f66a6c | 2916 | /* enable DINO */ |
b095c381 JK |
2917 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
2918 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); | |
43f66a6c | 2919 | |
0edd5b44 | 2920 | /* this is where the igx / win driver deveates from the VAP driver. */ |
43f66a6c JK |
2921 | |
2922 | /* wait for alive response */ | |
2923 | for (i = 0; i < 100; i++) { | |
2924 | /* poll for incoming data */ | |
b095c381 | 2925 | cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS); |
43f66a6c JK |
2926 | if (cr & DINO_RXFIFO_DATA) |
2927 | break; | |
2928 | mdelay(1); | |
2929 | } | |
2930 | ||
2931 | if (cr & DINO_RXFIFO_DATA) { | |
2932 | /* alive_command_responce size is NOT multiple of 4 */ | |
2933 | u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4]; | |
bf79451e JG |
2934 | |
2935 | for (i = 0; i < ARRAY_SIZE(response_buffer); i++) | |
43f66a6c | 2936 | response_buffer[i] = |
a613bffd | 2937 | le32_to_cpu(ipw_read_reg32(priv, |
b095c381 | 2938 | IPW_BASEBAND_RX_FIFO_READ)); |
43f66a6c JK |
2939 | memcpy(&priv->dino_alive, response_buffer, |
2940 | sizeof(priv->dino_alive)); | |
2941 | if (priv->dino_alive.alive_command == 1 | |
2942 | && priv->dino_alive.ucode_valid == 1) { | |
2943 | rc = 0; | |
0edd5b44 JG |
2944 | IPW_DEBUG_INFO |
2945 | ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) " | |
2946 | "of %02d/%02d/%02d %02d:%02d\n", | |
2947 | priv->dino_alive.software_revision, | |
2948 | priv->dino_alive.software_revision, | |
2949 | priv->dino_alive.device_identifier, | |
2950 | priv->dino_alive.device_identifier, | |
2951 | priv->dino_alive.time_stamp[0], | |
2952 | priv->dino_alive.time_stamp[1], | |
2953 | priv->dino_alive.time_stamp[2], | |
2954 | priv->dino_alive.time_stamp[3], | |
2955 | priv->dino_alive.time_stamp[4]); | |
43f66a6c JK |
2956 | } else { |
2957 | IPW_DEBUG_INFO("Microcode is not alive\n"); | |
2958 | rc = -EINVAL; | |
2959 | } | |
2960 | } else { | |
2961 | IPW_DEBUG_INFO("No alive response from DINO\n"); | |
2962 | rc = -ETIME; | |
2963 | } | |
2964 | ||
2965 | /* disable DINO, otherwise for some reason | |
2966 | firmware have problem getting alive resp. */ | |
b095c381 | 2967 | ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0); |
43f66a6c | 2968 | |
0edd5b44 | 2969 | // spin_unlock_irqrestore(&priv->lock, flags); |
43f66a6c JK |
2970 | |
2971 | return rc; | |
2972 | } | |
2973 | ||
0edd5b44 | 2974 | static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len) |
43f66a6c JK |
2975 | { |
2976 | int rc = -1; | |
2977 | int offset = 0; | |
2978 | struct fw_chunk *chunk; | |
2979 | dma_addr_t shared_phys; | |
2980 | u8 *shared_virt; | |
2981 | ||
2982 | IPW_DEBUG_TRACE("<< : \n"); | |
2983 | shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys); | |
2984 | ||
2985 | if (!shared_virt) | |
2986 | return -ENOMEM; | |
2987 | ||
2988 | memmove(shared_virt, data, len); | |
2989 | ||
2990 | /* Start the Dma */ | |
2991 | rc = ipw_fw_dma_enable(priv); | |
2992 | ||
2993 | if (priv->sram_desc.last_cb_index > 0) { | |
2994 | /* the DMA is already ready this would be a bug. */ | |
2995 | BUG(); | |
2996 | goto out; | |
2997 | } | |
2998 | ||
2999 | do { | |
3000 | chunk = (struct fw_chunk *)(data + offset); | |
3001 | offset += sizeof(struct fw_chunk); | |
3002 | /* build DMA packet and queue up for sending */ | |
bf79451e | 3003 | /* dma to chunk->address, the chunk->length bytes from data + |
43f66a6c JK |
3004 | * offeset*/ |
3005 | /* Dma loading */ | |
3006 | rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, | |
a613bffd JK |
3007 | le32_to_cpu(chunk->address), |
3008 | le32_to_cpu(chunk->length)); | |
43f66a6c JK |
3009 | if (rc) { |
3010 | IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); | |
3011 | goto out; | |
3012 | } | |
bf79451e | 3013 | |
a613bffd | 3014 | offset += le32_to_cpu(chunk->length); |
43f66a6c JK |
3015 | } while (offset < len); |
3016 | ||
0edd5b44 | 3017 | /* Run the DMA and wait for the answer */ |
43f66a6c JK |
3018 | rc = ipw_fw_dma_kick(priv); |
3019 | if (rc) { | |
3020 | IPW_ERROR("dmaKick Failed\n"); | |
3021 | goto out; | |
3022 | } | |
3023 | ||
3024 | rc = ipw_fw_dma_wait(priv); | |
3025 | if (rc) { | |
3026 | IPW_ERROR("dmaWaitSync Failed\n"); | |
3027 | goto out; | |
3028 | } | |
0edd5b44 JG |
3029 | out: |
3030 | pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys); | |
43f66a6c JK |
3031 | return rc; |
3032 | } | |
3033 | ||
3034 | /* stop nic */ | |
3035 | static int ipw_stop_nic(struct ipw_priv *priv) | |
3036 | { | |
3037 | int rc = 0; | |
3038 | ||
0edd5b44 | 3039 | /* stop */ |
b095c381 | 3040 | ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER); |
bf79451e | 3041 | |
b095c381 JK |
3042 | rc = ipw_poll_bit(priv, IPW_RESET_REG, |
3043 | IPW_RESET_REG_MASTER_DISABLED, 500); | |
43f66a6c | 3044 | if (rc < 0) { |
c7b6a674 | 3045 | IPW_ERROR("wait for reg master disabled failed after 500ms\n"); |
43f66a6c | 3046 | return rc; |
bf79451e | 3047 | } |
43f66a6c | 3048 | |
b095c381 | 3049 | ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); |
bf79451e | 3050 | |
43f66a6c JK |
3051 | return rc; |
3052 | } | |
3053 | ||
3054 | static void ipw_start_nic(struct ipw_priv *priv) | |
3055 | { | |
3056 | IPW_DEBUG_TRACE(">>\n"); | |
3057 | ||
0edd5b44 | 3058 | /* prvHwStartNic release ARC */ |
b095c381 JK |
3059 | ipw_clear_bit(priv, IPW_RESET_REG, |
3060 | IPW_RESET_REG_MASTER_DISABLED | | |
3061 | IPW_RESET_REG_STOP_MASTER | | |
43f66a6c | 3062 | CBD_RESET_REG_PRINCETON_RESET); |
bf79451e | 3063 | |
43f66a6c | 3064 | /* enable power management */ |
b095c381 JK |
3065 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, |
3066 | IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); | |
43f66a6c JK |
3067 | |
3068 | IPW_DEBUG_TRACE("<<\n"); | |
3069 | } | |
bf79451e | 3070 | |
43f66a6c JK |
3071 | static int ipw_init_nic(struct ipw_priv *priv) |
3072 | { | |
3073 | int rc; | |
3074 | ||
3075 | IPW_DEBUG_TRACE(">>\n"); | |
bf79451e | 3076 | /* reset */ |
43f66a6c JK |
3077 | /*prvHwInitNic */ |
3078 | /* set "initialization complete" bit to move adapter to D0 state */ | |
b095c381 | 3079 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); |
43f66a6c JK |
3080 | |
3081 | /* low-level PLL activation */ | |
b095c381 JK |
3082 | ipw_write32(priv, IPW_READ_INT_REGISTER, |
3083 | IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER); | |
43f66a6c JK |
3084 | |
3085 | /* wait for clock stabilization */ | |
b095c381 JK |
3086 | rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW, |
3087 | IPW_GP_CNTRL_BIT_CLOCK_READY, 250); | |
0edd5b44 | 3088 | if (rc < 0) |
43f66a6c JK |
3089 | IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); |
3090 | ||
3091 | /* assert SW reset */ | |
b095c381 | 3092 | ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET); |
43f66a6c JK |
3093 | |
3094 | udelay(10); | |
3095 | ||
3096 | /* set "initialization complete" bit to move adapter to D0 state */ | |
b095c381 | 3097 | ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE); |
43f66a6c JK |
3098 | |
3099 | IPW_DEBUG_TRACE(">>\n"); | |
3100 | return 0; | |
3101 | } | |
3102 | ||
bf79451e | 3103 | /* Call this function from process context, it will sleep in request_firmware. |
43f66a6c JK |
3104 | * Probe is an ok place to call this from. |
3105 | */ | |
3106 | static int ipw_reset_nic(struct ipw_priv *priv) | |
3107 | { | |
3108 | int rc = 0; | |
a613bffd | 3109 | unsigned long flags; |
43f66a6c JK |
3110 | |
3111 | IPW_DEBUG_TRACE(">>\n"); | |
bf79451e | 3112 | |
43f66a6c | 3113 | rc = ipw_init_nic(priv); |
bf79451e | 3114 | |
a613bffd | 3115 | spin_lock_irqsave(&priv->lock, flags); |
43f66a6c JK |
3116 | /* Clear the 'host command active' bit... */ |
3117 | priv->status &= ~STATUS_HCMD_ACTIVE; | |
3118 | wake_up_interruptible(&priv->wait_command_queue); | |
afbf30a2 JK |
3119 | priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); |
3120 | wake_up_interruptible(&priv->wait_state); | |
a613bffd | 3121 | spin_unlock_irqrestore(&priv->lock, flags); |
43f66a6c JK |
3122 | |
3123 | IPW_DEBUG_TRACE("<<\n"); | |
3124 | return rc; | |
bf79451e | 3125 | } |
43f66a6c | 3126 | |
bf79451e | 3127 | static int ipw_get_fw(struct ipw_priv *priv, |
43f66a6c JK |
3128 | const struct firmware **fw, const char *name) |
3129 | { | |
3130 | struct fw_header *header; | |
3131 | int rc; | |
3132 | ||
3133 | /* ask firmware_class module to get the boot firmware off disk */ | |
3134 | rc = request_firmware(fw, name, &priv->pci_dev->dev); | |
3135 | if (rc < 0) { | |
3136 | IPW_ERROR("%s load failed: Reason %d\n", name, rc); | |
3137 | return rc; | |
bf79451e | 3138 | } |
43f66a6c JK |
3139 | |
3140 | header = (struct fw_header *)(*fw)->data; | |
a613bffd | 3141 | if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) { |
43f66a6c JK |
3142 | IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n", |
3143 | name, | |
a613bffd JK |
3144 | IPW_FW_MAJOR(le32_to_cpu(header->version)), |
3145 | IPW_FW_MAJOR_VERSION); | |
43f66a6c JK |
3146 | return -EINVAL; |
3147 | } | |
3148 | ||
aaa4d308 | 3149 | IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n", |
43f66a6c | 3150 | name, |
a613bffd JK |
3151 | IPW_FW_MAJOR(le32_to_cpu(header->version)), |
3152 | IPW_FW_MINOR(le32_to_cpu(header->version)), | |
43f66a6c JK |
3153 | (*fw)->size - sizeof(struct fw_header)); |
3154 | return 0; | |
3155 | } | |
3156 | ||
b095c381 | 3157 | #define IPW_RX_BUF_SIZE (3000) |
43f66a6c | 3158 | |
858119e1 | 3159 | static void ipw_rx_queue_reset(struct ipw_priv *priv, |
43f66a6c JK |
3160 | struct ipw_rx_queue *rxq) |
3161 | { | |
3162 | unsigned long flags; | |
3163 | int i; | |
3164 | ||
3165 | spin_lock_irqsave(&rxq->lock, flags); | |
3166 | ||
3167 | INIT_LIST_HEAD(&rxq->rx_free); | |
3168 | INIT_LIST_HEAD(&rxq->rx_used); | |
3169 | ||
3170 | /* Fill the rx_used queue with _all_ of the Rx buffers */ | |
3171 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { | |
3172 | /* In the reset function, these buffers may have been allocated | |
3173 | * to an SKB, so we need to unmap and free potential storage */ | |
3174 | if (rxq->pool[i].skb != NULL) { | |
3175 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, | |
b095c381 | 3176 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
43f66a6c | 3177 | dev_kfree_skb(rxq->pool[i].skb); |
a613bffd | 3178 | rxq->pool[i].skb = NULL; |
43f66a6c JK |
3179 | } |
3180 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); | |
3181 | } | |
bf79451e | 3182 | |
43f66a6c JK |
3183 | /* Set us so that we have processed and used all buffers, but have |
3184 | * not restocked the Rx queue with fresh buffers */ | |
3185 | rxq->read = rxq->write = 0; | |
3186 | rxq->processed = RX_QUEUE_SIZE - 1; | |
3187 | rxq->free_count = 0; | |
3188 | spin_unlock_irqrestore(&rxq->lock, flags); | |
3189 | } | |
3190 | ||
3191 | #ifdef CONFIG_PM | |
3192 | static int fw_loaded = 0; | |
3193 | static const struct firmware *bootfw = NULL; | |
3194 | static const struct firmware *firmware = NULL; | |
3195 | static const struct firmware *ucode = NULL; | |
afbf30a2 JK |
3196 | |
3197 | static void free_firmware(void) | |
3198 | { | |
3199 | if (fw_loaded) { | |
3200 | release_firmware(bootfw); | |
3201 | release_firmware(ucode); | |
3202 | release_firmware(firmware); | |
3203 | bootfw = ucode = firmware = NULL; | |
3204 | fw_loaded = 0; | |
3205 | } | |
3206 | } | |
3207 | #else | |
3208 | #define free_firmware() do {} while (0) | |
43f66a6c JK |
3209 | #endif |
3210 | ||
3211 | static int ipw_load(struct ipw_priv *priv) | |
3212 | { | |
3213 | #ifndef CONFIG_PM | |
3214 | const struct firmware *bootfw = NULL; | |
3215 | const struct firmware *firmware = NULL; | |
3216 | const struct firmware *ucode = NULL; | |
3217 | #endif | |
397ae121 ZY |
3218 | char *ucode_name; |
3219 | char *fw_name; | |
43f66a6c JK |
3220 | int rc = 0, retries = 3; |
3221 | ||
397ae121 ZY |
3222 | switch (priv->ieee->iw_mode) { |
3223 | case IW_MODE_ADHOC: | |
3224 | ucode_name = IPW_FW_NAME("ibss_ucode"); | |
3225 | fw_name = IPW_FW_NAME("ibss"); | |
3226 | break; | |
b095c381 | 3227 | #ifdef CONFIG_IPW2200_MONITOR |
397ae121 ZY |
3228 | case IW_MODE_MONITOR: |
3229 | ucode_name = IPW_FW_NAME("sniffer_ucode"); | |
3230 | fw_name = IPW_FW_NAME("sniffer"); | |
3231 | break; | |
43f66a6c | 3232 | #endif |
397ae121 ZY |
3233 | case IW_MODE_INFRA: |
3234 | ucode_name = IPW_FW_NAME("bss_ucode"); | |
3235 | fw_name = IPW_FW_NAME("bss"); | |
3236 | break; | |
3237 | default: | |
3238 | rc = -EINVAL; | |
43f66a6c | 3239 | } |
397ae121 ZY |
3240 | |
3241 | if (rc < 0) | |
3242 | goto error; | |
43f66a6c JK |
3243 | |
3244 | if (!priv->rxq) | |
3245 | priv->rxq = ipw_rx_queue_alloc(priv); | |
3246 | else | |
3247 | ipw_rx_queue_reset(priv, priv->rxq); | |
3248 | if (!priv->rxq) { | |
3249 | IPW_ERROR("Unable to initialize Rx queue\n"); | |
3250 | goto error; | |
3251 | } | |
3252 | ||
0edd5b44 | 3253 | retry: |
43f66a6c | 3254 | /* Ensure interrupts are disabled */ |
b095c381 | 3255 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
43f66a6c JK |
3256 | priv->status &= ~STATUS_INT_ENABLED; |
3257 | ||
3258 | /* ack pending interrupts */ | |
b095c381 | 3259 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
bf79451e | 3260 | |
43f66a6c JK |
3261 | ipw_stop_nic(priv); |
3262 | ||
3263 | rc = ipw_reset_nic(priv); | |
397ae121 | 3264 | if (rc < 0) { |
43f66a6c JK |
3265 | IPW_ERROR("Unable to reset NIC\n"); |
3266 | goto error; | |
3267 | } | |
3268 | ||
b095c381 JK |
3269 | ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND, |
3270 | IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND); | |
43f66a6c | 3271 | |
397ae121 ZY |
3272 | #ifdef CONFIG_PM |
3273 | if (!fw_loaded) { | |
3274 | #endif | |
3275 | rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot")); | |
3276 | if (rc < 0) | |
3277 | goto error; | |
3278 | #ifdef CONFIG_PM | |
3279 | } | |
3280 | #endif | |
43f66a6c | 3281 | /* DMA the initial boot firmware into the device */ |
bf79451e | 3282 | rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header), |
43f66a6c JK |
3283 | bootfw->size - sizeof(struct fw_header)); |
3284 | if (rc < 0) { | |
a4f6bbb3 | 3285 | IPW_ERROR("Unable to load boot firmware: %d\n", rc); |
43f66a6c JK |
3286 | goto error; |
3287 | } | |
3288 | ||
3289 | /* kick start the device */ | |
3290 | ipw_start_nic(priv); | |
3291 | ||
c7b6a674 | 3292 | /* wait for the device to finish its initial startup sequence */ |
b095c381 JK |
3293 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
3294 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); | |
43f66a6c JK |
3295 | if (rc < 0) { |
3296 | IPW_ERROR("device failed to boot initial fw image\n"); | |
3297 | goto error; | |
3298 | } | |
3299 | IPW_DEBUG_INFO("initial device response after %dms\n", rc); | |
3300 | ||
bf79451e | 3301 | /* ack fw init done interrupt */ |
b095c381 | 3302 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
43f66a6c | 3303 | |
397ae121 ZY |
3304 | #ifdef CONFIG_PM |
3305 | if (!fw_loaded) { | |
3306 | #endif | |
3307 | rc = ipw_get_fw(priv, &ucode, ucode_name); | |
3308 | if (rc < 0) | |
3309 | goto error; | |
3310 | #ifdef CONFIG_PM | |
3311 | } | |
3312 | #endif | |
2638bc39 | 3313 | |
43f66a6c | 3314 | /* DMA the ucode into the device */ |
bf79451e | 3315 | rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header), |
43f66a6c JK |
3316 | ucode->size - sizeof(struct fw_header)); |
3317 | if (rc < 0) { | |
a4f6bbb3 | 3318 | IPW_ERROR("Unable to load ucode: %d\n", rc); |
43f66a6c JK |
3319 | goto error; |
3320 | } | |
bf79451e | 3321 | |
43f66a6c JK |
3322 | /* stop nic */ |
3323 | ipw_stop_nic(priv); | |
3324 | ||
397ae121 ZY |
3325 | #ifdef CONFIG_PM |
3326 | if (!fw_loaded) { | |
3327 | #endif | |
3328 | rc = ipw_get_fw(priv, &firmware, fw_name); | |
3329 | if (rc < 0) | |
3330 | goto error; | |
3331 | #ifdef CONFIG_PM | |
3332 | } | |
3333 | #endif | |
3334 | ||
43f66a6c | 3335 | /* DMA bss firmware into the device */ |
bf79451e JG |
3336 | rc = ipw_load_firmware(priv, firmware->data + |
3337 | sizeof(struct fw_header), | |
43f66a6c | 3338 | firmware->size - sizeof(struct fw_header)); |
0edd5b44 | 3339 | if (rc < 0) { |
a4f6bbb3 | 3340 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
43f66a6c JK |
3341 | goto error; |
3342 | } | |
397ae121 ZY |
3343 | #ifdef CONFIG_PM |
3344 | fw_loaded = 1; | |
3345 | #endif | |
3346 | ||
43f66a6c JK |
3347 | ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0); |
3348 | ||
3349 | rc = ipw_queue_reset(priv); | |
397ae121 | 3350 | if (rc < 0) { |
43f66a6c JK |
3351 | IPW_ERROR("Unable to initialize queues\n"); |
3352 | goto error; | |
3353 | } | |
3354 | ||
3355 | /* Ensure interrupts are disabled */ | |
b095c381 | 3356 | ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL); |
c848d0af | 3357 | /* ack pending interrupts */ |
b095c381 | 3358 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
bf79451e | 3359 | |
43f66a6c JK |
3360 | /* kick start the device */ |
3361 | ipw_start_nic(priv); | |
3362 | ||
b095c381 | 3363 | if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) { |
43f66a6c JK |
3364 | if (retries > 0) { |
3365 | IPW_WARNING("Parity error. Retrying init.\n"); | |
3366 | retries--; | |
3367 | goto retry; | |
3368 | } | |
3369 | ||
3370 | IPW_ERROR("TODO: Handle parity error -- schedule restart?\n"); | |
3371 | rc = -EIO; | |
3372 | goto error; | |
3373 | } | |
3374 | ||
3375 | /* wait for the device */ | |
b095c381 JK |
3376 | rc = ipw_poll_bit(priv, IPW_INTA_RW, |
3377 | IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500); | |
43f66a6c | 3378 | if (rc < 0) { |
c7b6a674 | 3379 | IPW_ERROR("device failed to start within 500ms\n"); |
43f66a6c JK |
3380 | goto error; |
3381 | } | |
3382 | IPW_DEBUG_INFO("device response after %dms\n", rc); | |
3383 | ||
3384 | /* ack fw init done interrupt */ | |
b095c381 | 3385 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); |
43f66a6c JK |
3386 | |
3387 | /* read eeprom data and initialize the eeprom region of sram */ | |
3388 | priv->eeprom_delay = 1; | |
bf79451e | 3389 | ipw_eeprom_init_sram(priv); |
43f66a6c JK |
3390 | |
3391 | /* enable interrupts */ | |
3392 | ipw_enable_interrupts(priv); | |
3393 | ||
3394 | /* Ensure our queue has valid packets */ | |
3395 | ipw_rx_queue_replenish(priv); | |
3396 | ||
b095c381 | 3397 | ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read); |
43f66a6c JK |
3398 | |
3399 | /* ack pending interrupts */ | |
b095c381 | 3400 | ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL); |
43f66a6c JK |
3401 | |
3402 | #ifndef CONFIG_PM | |
3403 | release_firmware(bootfw); | |
3404 | release_firmware(ucode); | |
3405 | release_firmware(firmware); | |
3406 | #endif | |
3407 | return 0; | |
3408 | ||
0edd5b44 | 3409 | error: |
43f66a6c JK |
3410 | if (priv->rxq) { |
3411 | ipw_rx_queue_free(priv, priv->rxq); | |
3412 | priv->rxq = NULL; | |
3413 | } | |
3414 | ipw_tx_queue_free(priv); | |
3415 | if (bootfw) | |
3416 | release_firmware(bootfw); | |
3417 | if (ucode) | |
3418 | release_firmware(ucode); | |
3419 | if (firmware) | |
3420 | release_firmware(firmware); | |
3421 | #ifdef CONFIG_PM | |
3422 | fw_loaded = 0; | |
3423 | bootfw = ucode = firmware = NULL; | |
3424 | #endif | |
3425 | ||
3426 | return rc; | |
3427 | } | |
3428 | ||
bf79451e | 3429 | /** |
43f66a6c JK |
3430 | * DMA services |
3431 | * | |
3432 | * Theory of operation | |
3433 | * | |
3434 | * A queue is a circular buffers with 'Read' and 'Write' pointers. | |
3435 | * 2 empty entries always kept in the buffer to protect from overflow. | |
3436 | * | |
3437 | * For Tx queue, there are low mark and high mark limits. If, after queuing | |
bf79451e JG |
3438 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
3439 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, | |
43f66a6c JK |
3440 | * Tx queue resumed. |
3441 | * | |
3442 | * The IPW operates with six queues, one receive queue in the device's | |
3443 | * sram, one transmit queue for sending commands to the device firmware, | |
bf79451e | 3444 | * and four transmit queues for data. |
43f66a6c | 3445 | * |
bf79451e | 3446 | * The four transmit queues allow for performing quality of service (qos) |
43f66a6c | 3447 | * transmissions as per the 802.11 protocol. Currently Linux does not |
bf79451e | 3448 | * provide a mechanism to the user for utilizing prioritized queues, so |
43f66a6c JK |
3449 | * we only utilize the first data transmit queue (queue1). |
3450 | */ | |
3451 | ||
3452 | /** | |
3453 | * Driver allocates buffers of this size for Rx | |
3454 | */ | |
3455 | ||
3456 | static inline int ipw_queue_space(const struct clx2_queue *q) | |
3457 | { | |
3458 | int s = q->last_used - q->first_empty; | |
3459 | if (s <= 0) | |
3460 | s += q->n_bd; | |
3461 | s -= 2; /* keep some reserve to not confuse empty and full situations */ | |
3462 | if (s < 0) | |
3463 | s = 0; | |
3464 | return s; | |
3465 | } | |
3466 | ||
3467 | static inline int ipw_queue_inc_wrap(int index, int n_bd) | |
3468 | { | |
3469 | return (++index == n_bd) ? 0 : index; | |
3470 | } | |
3471 | ||
3472 | /** | |
3473 | * Initialize common DMA queue structure | |
bf79451e | 3474 | * |
43f66a6c JK |
3475 | * @param q queue to init |
3476 | * @param count Number of BD's to allocate. Should be power of 2 | |
3477 | * @param read_register Address for 'read' register | |
3478 | * (not offset within BAR, full address) | |
3479 | * @param write_register Address for 'write' register | |
3480 | * (not offset within BAR, full address) | |
3481 | * @param base_register Address for 'base' register | |
3482 | * (not offset within BAR, full address) | |
3483 | * @param size Address for 'size' register | |
3484 | * (not offset within BAR, full address) | |
3485 | */ | |
bf79451e | 3486 | static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q, |
0edd5b44 | 3487 | int count, u32 read, u32 write, u32 base, u32 size) |
43f66a6c JK |
3488 | { |
3489 | q->n_bd = count; | |
3490 | ||
3491 | q->low_mark = q->n_bd / 4; | |
3492 | if (q->low_mark < 4) | |
3493 | q->low_mark = 4; | |
3494 | ||
3495 | q->high_mark = q->n_bd / 8; | |
3496 | if (q->high_mark < 2) | |
3497 | q->high_mark = 2; | |
3498 | ||
3499 | q->first_empty = q->last_used = 0; | |
3500 | q->reg_r = read; | |
3501 | q->reg_w = write; | |
3502 | ||
3503 | ipw_write32(priv, base, q->dma_addr); | |
3504 | ipw_write32(priv, size, count); | |
3505 | ipw_write32(priv, read, 0); | |
3506 | ipw_write32(priv, write, 0); | |
3507 | ||
3508 | _ipw_read32(priv, 0x90); | |
3509 | } | |
3510 | ||
bf79451e | 3511 | static int ipw_queue_tx_init(struct ipw_priv *priv, |
43f66a6c | 3512 | struct clx2_tx_queue *q, |
0edd5b44 | 3513 | int count, u32 read, u32 write, u32 base, u32 size) |
43f66a6c JK |
3514 | { |
3515 | struct pci_dev *dev = priv->pci_dev; | |
3516 | ||
3517 | q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL); | |
3518 | if (!q->txb) { | |
3519 | IPW_ERROR("vmalloc for auxilary BD structures failed\n"); | |
3520 | return -ENOMEM; | |
3521 | } | |
3522 | ||
0edd5b44 JG |
3523 | q->bd = |
3524 | pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr); | |
43f66a6c | 3525 | if (!q->bd) { |
aaa4d308 | 3526 | IPW_ERROR("pci_alloc_consistent(%zd) failed\n", |
0edd5b44 | 3527 | sizeof(q->bd[0]) * count); |
43f66a6c JK |
3528 | kfree(q->txb); |
3529 | q->txb = NULL; | |
3530 | return -ENOMEM; | |
3531 | } | |
3532 | ||
3533 | ipw_queue_init(priv, &q->q, count, read, write, base, size); | |
3534 | return 0; | |
3535 | } | |
3536 | ||
3537 | /** | |
3538 | * Free one TFD, those at index [txq->q.last_used]. | |
3539 | * Do NOT advance any indexes | |
bf79451e | 3540 | * |
43f66a6c JK |
3541 | * @param dev |
3542 | * @param txq | |
3543 | */ | |
3544 | static void ipw_queue_tx_free_tfd(struct ipw_priv *priv, | |
3545 | struct clx2_tx_queue *txq) | |
3546 | { | |
3547 | struct tfd_frame *bd = &txq->bd[txq->q.last_used]; | |
3548 | struct pci_dev *dev = priv->pci_dev; | |
3549 | int i; | |
bf79451e | 3550 | |
43f66a6c JK |
3551 | /* classify bd */ |
3552 | if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE) | |
3553 | /* nothing to cleanup after for host commands */ | |
3554 | return; | |
3555 | ||
3556 | /* sanity check */ | |
a613bffd JK |
3557 | if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) { |
3558 | IPW_ERROR("Too many chunks: %i\n", | |
3559 | le32_to_cpu(bd->u.data.num_chunks)); | |
43f66a6c JK |
3560 | /** @todo issue fatal error, it is quite serious situation */ |
3561 | return; | |
3562 | } | |
3563 | ||
3564 | /* unmap chunks if any */ | |
a613bffd JK |
3565 | for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) { |
3566 | pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]), | |
3567 | le16_to_cpu(bd->u.data.chunk_len[i]), | |
3568 | PCI_DMA_TODEVICE); | |
43f66a6c JK |
3569 | if (txq->txb[txq->q.last_used]) { |
3570 | ieee80211_txb_free(txq->txb[txq->q.last_used]); | |
3571 | txq->txb[txq->q.last_used] = NULL; | |
3572 | } | |
3573 | } | |
3574 | } | |
3575 | ||
3576 | /** | |
3577 | * Deallocate DMA queue. | |
bf79451e | 3578 | * |
43f66a6c JK |
3579 | * Empty queue by removing and destroying all BD's. |
3580 | * Free all buffers. | |
bf79451e | 3581 | * |
43f66a6c JK |
3582 | * @param dev |
3583 | * @param q | |
3584 | */ | |
0edd5b44 | 3585 | static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq) |
43f66a6c JK |
3586 | { |
3587 | struct clx2_queue *q = &txq->q; | |
3588 | struct pci_dev *dev = priv->pci_dev; | |
3589 | ||
bf79451e JG |
3590 | if (q->n_bd == 0) |
3591 | return; | |
43f66a6c JK |
3592 | |
3593 | /* first, empty all BD's */ | |
3594 | for (; q->first_empty != q->last_used; | |
3595 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { | |
3596 | ipw_queue_tx_free_tfd(priv, txq); | |
3597 | } | |
bf79451e | 3598 | |
43f66a6c | 3599 | /* free buffers belonging to queue itself */ |
0edd5b44 | 3600 | pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd, |
43f66a6c JK |
3601 | q->dma_addr); |
3602 | kfree(txq->txb); | |
3603 | ||
3604 | /* 0 fill whole structure */ | |
3605 | memset(txq, 0, sizeof(*txq)); | |
3606 | } | |
3607 | ||
43f66a6c JK |
3608 | /** |
3609 | * Destroy all DMA queues and structures | |
bf79451e | 3610 | * |
43f66a6c JK |
3611 | * @param priv |
3612 | */ | |
3613 | static void ipw_tx_queue_free(struct ipw_priv *priv) | |
3614 | { | |
3615 | /* Tx CMD queue */ | |
3616 | ipw_queue_tx_free(priv, &priv->txq_cmd); | |
3617 | ||
3618 | /* Tx queues */ | |
3619 | ipw_queue_tx_free(priv, &priv->txq[0]); | |
3620 | ipw_queue_tx_free(priv, &priv->txq[1]); | |
3621 | ipw_queue_tx_free(priv, &priv->txq[2]); | |
3622 | ipw_queue_tx_free(priv, &priv->txq[3]); | |
3623 | } | |
3624 | ||
858119e1 | 3625 | static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) |
43f66a6c JK |
3626 | { |
3627 | /* First 3 bytes are manufacturer */ | |
3628 | bssid[0] = priv->mac_addr[0]; | |
3629 | bssid[1] = priv->mac_addr[1]; | |
3630 | bssid[2] = priv->mac_addr[2]; | |
3631 | ||
3632 | /* Last bytes are random */ | |
0edd5b44 | 3633 | get_random_bytes(&bssid[3], ETH_ALEN - 3); |
43f66a6c | 3634 | |
0edd5b44 JG |
3635 | bssid[0] &= 0xfe; /* clear multicast bit */ |
3636 | bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */ | |
43f66a6c JK |
3637 | } |
3638 | ||
858119e1 | 3639 | static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid) |
43f66a6c JK |
3640 | { |
3641 | struct ipw_station_entry entry; | |
3642 | int i; | |
3643 | ||
3644 | for (i = 0; i < priv->num_stations; i++) { | |
3645 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) { | |
3646 | /* Another node is active in network */ | |
3647 | priv->missed_adhoc_beacons = 0; | |
3648 | if (!(priv->config & CFG_STATIC_CHANNEL)) | |
3649 | /* when other nodes drop out, we drop out */ | |
3650 | priv->config &= ~CFG_ADHOC_PERSIST; | |
3651 | ||
3652 | return i; | |
3653 | } | |
3654 | } | |
3655 | ||
3656 | if (i == MAX_STATIONS) | |
3657 | return IPW_INVALID_STATION; | |
3658 | ||
3659 | IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid)); | |
3660 | ||
3661 | entry.reserved = 0; | |
3662 | entry.support_mode = 0; | |
3663 | memcpy(entry.mac_addr, bssid, ETH_ALEN); | |
3664 | memcpy(priv->stations[i], bssid, ETH_ALEN); | |
3665 | ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry), | |
0edd5b44 | 3666 | &entry, sizeof(entry)); |
43f66a6c JK |
3667 | priv->num_stations++; |
3668 | ||
3669 | return i; | |
3670 | } | |
3671 | ||
858119e1 | 3672 | static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid) |
43f66a6c JK |
3673 | { |
3674 | int i; | |
3675 | ||
bf79451e JG |
3676 | for (i = 0; i < priv->num_stations; i++) |
3677 | if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) | |
43f66a6c JK |
3678 | return i; |
3679 | ||
3680 | return IPW_INVALID_STATION; | |
3681 | } | |
3682 | ||
3683 | static void ipw_send_disassociate(struct ipw_priv *priv, int quiet) | |
3684 | { | |
3685 | int err; | |
3686 | ||
7b99659f HL |
3687 | if (priv->status & STATUS_ASSOCIATING) { |
3688 | IPW_DEBUG_ASSOC("Disassociating while associating.\n"); | |
3689 | queue_work(priv->workqueue, &priv->disassociate); | |
3690 | return; | |
3691 | } | |
3692 | ||
3693 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
43f66a6c JK |
3694 | IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); |
3695 | return; | |
3696 | } | |
3697 | ||
3698 | IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " " | |
3699 | "on channel %d.\n", | |
bf79451e | 3700 | MAC_ARG(priv->assoc_request.bssid), |
43f66a6c JK |
3701 | priv->assoc_request.channel); |
3702 | ||
3703 | priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED); | |
3704 | priv->status |= STATUS_DISASSOCIATING; | |
3705 | ||
3706 | if (quiet) | |
3707 | priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; | |
3708 | else | |
3709 | priv->assoc_request.assoc_type = HC_DISASSOCIATE; | |
e6324726 | 3710 | |
43f66a6c JK |
3711 | err = ipw_send_associate(priv, &priv->assoc_request); |
3712 | if (err) { | |
3713 | IPW_DEBUG_HC("Attempt to send [dis]associate command " | |
3714 | "failed.\n"); | |
3715 | return; | |
3716 | } | |
3717 | ||
3718 | } | |
3719 | ||
c848d0af | 3720 | static int ipw_disassociate(void *data) |
43f66a6c | 3721 | { |
c848d0af JK |
3722 | struct ipw_priv *priv = data; |
3723 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) | |
3724 | return 0; | |
43f66a6c | 3725 | ipw_send_disassociate(data, 0); |
c848d0af | 3726 | return 1; |
43f66a6c JK |
3727 | } |
3728 | ||
c848d0af | 3729 | static void ipw_bg_disassociate(void *data) |
43f66a6c | 3730 | { |
c848d0af | 3731 | struct ipw_priv *priv = data; |
4644151b | 3732 | mutex_lock(&priv->mutex); |
c848d0af | 3733 | ipw_disassociate(data); |
4644151b | 3734 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
3735 | } |
3736 | ||
d8bad6df ZY |
3737 | static void ipw_system_config(void *data) |
3738 | { | |
3739 | struct ipw_priv *priv = data; | |
3740 | ipw_send_system_config(priv, &priv->sys_config); | |
43f66a6c JK |
3741 | } |
3742 | ||
3743 | struct ipw_status_code { | |
3744 | u16 status; | |
3745 | const char *reason; | |
3746 | }; | |
3747 | ||
3748 | static const struct ipw_status_code ipw_status_codes[] = { | |
3749 | {0x00, "Successful"}, | |
3750 | {0x01, "Unspecified failure"}, | |
3751 | {0x0A, "Cannot support all requested capabilities in the " | |
3752 | "Capability information field"}, | |
3753 | {0x0B, "Reassociation denied due to inability to confirm that " | |
3754 | "association exists"}, | |
3755 | {0x0C, "Association denied due to reason outside the scope of this " | |
3756 | "standard"}, | |
0edd5b44 JG |
3757 | {0x0D, |
3758 | "Responding station does not support the specified authentication " | |
43f66a6c | 3759 | "algorithm"}, |
0edd5b44 JG |
3760 | {0x0E, |
3761 | "Received an Authentication frame with authentication sequence " | |
43f66a6c JK |
3762 | "transaction sequence number out of expected sequence"}, |
3763 | {0x0F, "Authentication rejected because of challenge failure"}, | |
3764 | {0x10, "Authentication rejected due to timeout waiting for next " | |
3765 | "frame in sequence"}, | |
3766 | {0x11, "Association denied because AP is unable to handle additional " | |
3767 | "associated stations"}, | |
0edd5b44 JG |
3768 | {0x12, |
3769 | "Association denied due to requesting station not supporting all " | |
43f66a6c | 3770 | "of the datarates in the BSSBasicServiceSet Parameter"}, |
0edd5b44 JG |
3771 | {0x13, |
3772 | "Association denied due to requesting station not supporting " | |
43f66a6c | 3773 | "short preamble operation"}, |
0edd5b44 JG |
3774 | {0x14, |
3775 | "Association denied due to requesting station not supporting " | |
43f66a6c | 3776 | "PBCC encoding"}, |
0edd5b44 JG |
3777 | {0x15, |
3778 | "Association denied due to requesting station not supporting " | |
43f66a6c | 3779 | "channel agility"}, |
0edd5b44 JG |
3780 | {0x19, |
3781 | "Association denied due to requesting station not supporting " | |
43f66a6c | 3782 | "short slot operation"}, |
0edd5b44 JG |
3783 | {0x1A, |
3784 | "Association denied due to requesting station not supporting " | |
43f66a6c JK |
3785 | "DSSS-OFDM operation"}, |
3786 | {0x28, "Invalid Information Element"}, | |
3787 | {0x29, "Group Cipher is not valid"}, | |
3788 | {0x2A, "Pairwise Cipher is not valid"}, | |
3789 | {0x2B, "AKMP is not valid"}, | |
3790 | {0x2C, "Unsupported RSN IE version"}, | |
3791 | {0x2D, "Invalid RSN IE Capabilities"}, | |
3792 | {0x2E, "Cipher suite is rejected per security policy"}, | |
3793 | }; | |
3794 | ||
0f52bf90 | 3795 | #ifdef CONFIG_IPW2200_DEBUG |
bf79451e | 3796 | static const char *ipw_get_status_code(u16 status) |
43f66a6c JK |
3797 | { |
3798 | int i; | |
bf79451e | 3799 | for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) |
ea2b26e0 | 3800 | if (ipw_status_codes[i].status == (status & 0xff)) |
43f66a6c JK |
3801 | return ipw_status_codes[i].reason; |
3802 | return "Unknown status value."; | |
3803 | } | |
3804 | #endif | |
3805 | ||
3806 | static void inline average_init(struct average *avg) | |
3807 | { | |
3808 | memset(avg, 0, sizeof(*avg)); | |
3809 | } | |
3810 | ||
858119e1 | 3811 | static void average_add(struct average *avg, s16 val) |
43f66a6c JK |
3812 | { |
3813 | avg->sum -= avg->entries[avg->pos]; | |
3814 | avg->sum += val; | |
3815 | avg->entries[avg->pos++] = val; | |
3816 | if (unlikely(avg->pos == AVG_ENTRIES)) { | |
3817 | avg->init = 1; | |
3818 | avg->pos = 0; | |
3819 | } | |
3820 | } | |
3821 | ||
858119e1 | 3822 | static s16 average_value(struct average *avg) |
43f66a6c JK |
3823 | { |
3824 | if (!unlikely(avg->init)) { | |
3825 | if (avg->pos) | |
3826 | return avg->sum / avg->pos; | |
3827 | return 0; | |
3828 | } | |
3829 | ||
3830 | return avg->sum / AVG_ENTRIES; | |
3831 | } | |
3832 | ||
3833 | static void ipw_reset_stats(struct ipw_priv *priv) | |
3834 | { | |
3835 | u32 len = sizeof(u32); | |
3836 | ||
3837 | priv->quality = 0; | |
3838 | ||
3839 | average_init(&priv->average_missed_beacons); | |
3840 | average_init(&priv->average_rssi); | |
3841 | average_init(&priv->average_noise); | |
3842 | ||
3843 | priv->last_rate = 0; | |
3844 | priv->last_missed_beacons = 0; | |
3845 | priv->last_rx_packets = 0; | |
3846 | priv->last_tx_packets = 0; | |
3847 | priv->last_tx_failures = 0; | |
bf79451e | 3848 | |
43f66a6c JK |
3849 | /* Firmware managed, reset only when NIC is restarted, so we have to |
3850 | * normalize on the current value */ | |
bf79451e | 3851 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, |
43f66a6c | 3852 | &priv->last_rx_err, &len); |
bf79451e | 3853 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, |
43f66a6c JK |
3854 | &priv->last_tx_failures, &len); |
3855 | ||
3856 | /* Driver managed, reset with each association */ | |
3857 | priv->missed_adhoc_beacons = 0; | |
3858 | priv->missed_beacons = 0; | |
3859 | priv->tx_packets = 0; | |
3860 | priv->rx_packets = 0; | |
3861 | ||
3862 | } | |
3863 | ||
858119e1 | 3864 | static u32 ipw_get_max_rate(struct ipw_priv *priv) |
43f66a6c JK |
3865 | { |
3866 | u32 i = 0x80000000; | |
3867 | u32 mask = priv->rates_mask; | |
3868 | /* If currently associated in B mode, restrict the maximum | |
3869 | * rate match to B rates */ | |
3870 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) | |
3871 | mask &= IEEE80211_CCK_RATES_MASK; | |
3872 | ||
3873 | /* TODO: Verify that the rate is supported by the current rates | |
3874 | * list. */ | |
3875 | ||
0edd5b44 JG |
3876 | while (i && !(mask & i)) |
3877 | i >>= 1; | |
43f66a6c | 3878 | switch (i) { |
ea2b26e0 JK |
3879 | case IEEE80211_CCK_RATE_1MB_MASK: |
3880 | return 1000000; | |
3881 | case IEEE80211_CCK_RATE_2MB_MASK: | |
3882 | return 2000000; | |
3883 | case IEEE80211_CCK_RATE_5MB_MASK: | |
3884 | return 5500000; | |
3885 | case IEEE80211_OFDM_RATE_6MB_MASK: | |
3886 | return 6000000; | |
3887 | case IEEE80211_OFDM_RATE_9MB_MASK: | |
3888 | return 9000000; | |
3889 | case IEEE80211_CCK_RATE_11MB_MASK: | |
3890 | return 11000000; | |
3891 | case IEEE80211_OFDM_RATE_12MB_MASK: | |
3892 | return 12000000; | |
3893 | case IEEE80211_OFDM_RATE_18MB_MASK: | |
3894 | return 18000000; | |
3895 | case IEEE80211_OFDM_RATE_24MB_MASK: | |
3896 | return 24000000; | |
3897 | case IEEE80211_OFDM_RATE_36MB_MASK: | |
3898 | return 36000000; | |
3899 | case IEEE80211_OFDM_RATE_48MB_MASK: | |
3900 | return 48000000; | |
3901 | case IEEE80211_OFDM_RATE_54MB_MASK: | |
3902 | return 54000000; | |
43f66a6c JK |
3903 | } |
3904 | ||
bf79451e | 3905 | if (priv->ieee->mode == IEEE_B) |
43f66a6c JK |
3906 | return 11000000; |
3907 | else | |
3908 | return 54000000; | |
3909 | } | |
3910 | ||
3911 | static u32 ipw_get_current_rate(struct ipw_priv *priv) | |
3912 | { | |
3913 | u32 rate, len = sizeof(rate); | |
3914 | int err; | |
3915 | ||
bf79451e | 3916 | if (!(priv->status & STATUS_ASSOCIATED)) |
43f66a6c JK |
3917 | return 0; |
3918 | ||
3919 | if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) { | |
bf79451e | 3920 | err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate, |
43f66a6c JK |
3921 | &len); |
3922 | if (err) { | |
3923 | IPW_DEBUG_INFO("failed querying ordinals.\n"); | |
3924 | return 0; | |
3925 | } | |
bf79451e | 3926 | } else |
43f66a6c JK |
3927 | return ipw_get_max_rate(priv); |
3928 | ||
3929 | switch (rate) { | |
ea2b26e0 JK |
3930 | case IPW_TX_RATE_1MB: |
3931 | return 1000000; | |
3932 | case IPW_TX_RATE_2MB: | |
3933 | return 2000000; | |
3934 | case IPW_TX_RATE_5MB: | |
3935 | return 5500000; | |
3936 | case IPW_TX_RATE_6MB: | |
3937 | return 6000000; | |
3938 | case IPW_TX_RATE_9MB: | |
3939 | return 9000000; | |
3940 | case IPW_TX_RATE_11MB: | |
3941 | return 11000000; | |
3942 | case IPW_TX_RATE_12MB: | |
3943 | return 12000000; | |
3944 | case IPW_TX_RATE_18MB: | |
3945 | return 18000000; | |
3946 | case IPW_TX_RATE_24MB: | |
3947 | return 24000000; | |
3948 | case IPW_TX_RATE_36MB: | |
3949 | return 36000000; | |
3950 | case IPW_TX_RATE_48MB: | |
3951 | return 48000000; | |
3952 | case IPW_TX_RATE_54MB: | |
3953 | return 54000000; | |
43f66a6c JK |
3954 | } |
3955 | ||
3956 | return 0; | |
3957 | } | |
3958 | ||
43f66a6c JK |
3959 | #define IPW_STATS_INTERVAL (2 * HZ) |
3960 | static void ipw_gather_stats(struct ipw_priv *priv) | |
3961 | { | |
3962 | u32 rx_err, rx_err_delta, rx_packets_delta; | |
3963 | u32 tx_failures, tx_failures_delta, tx_packets_delta; | |
3964 | u32 missed_beacons_percent, missed_beacons_delta; | |
3965 | u32 quality = 0; | |
3966 | u32 len = sizeof(u32); | |
3967 | s16 rssi; | |
bf79451e | 3968 | u32 beacon_quality, signal_quality, tx_quality, rx_quality, |
0edd5b44 | 3969 | rate_quality; |
ea2b26e0 | 3970 | u32 max_rate; |
43f66a6c JK |
3971 | |
3972 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
3973 | priv->quality = 0; | |
3974 | return; | |
3975 | } | |
3976 | ||
3977 | /* Update the statistics */ | |
bf79451e | 3978 | ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS, |
43f66a6c | 3979 | &priv->missed_beacons, &len); |
0edd5b44 | 3980 | missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons; |
43f66a6c JK |
3981 | priv->last_missed_beacons = priv->missed_beacons; |
3982 | if (priv->assoc_request.beacon_interval) { | |
3983 | missed_beacons_percent = missed_beacons_delta * | |
0edd5b44 JG |
3984 | (HZ * priv->assoc_request.beacon_interval) / |
3985 | (IPW_STATS_INTERVAL * 10); | |
43f66a6c JK |
3986 | } else { |
3987 | missed_beacons_percent = 0; | |
3988 | } | |
3989 | average_add(&priv->average_missed_beacons, missed_beacons_percent); | |
3990 | ||
3991 | ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len); | |
3992 | rx_err_delta = rx_err - priv->last_rx_err; | |
3993 | priv->last_rx_err = rx_err; | |
3994 | ||
3995 | ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len); | |
3996 | tx_failures_delta = tx_failures - priv->last_tx_failures; | |
3997 | priv->last_tx_failures = tx_failures; | |
3998 | ||
3999 | rx_packets_delta = priv->rx_packets - priv->last_rx_packets; | |
4000 | priv->last_rx_packets = priv->rx_packets; | |
4001 | ||
4002 | tx_packets_delta = priv->tx_packets - priv->last_tx_packets; | |
4003 | priv->last_tx_packets = priv->tx_packets; | |
4004 | ||
4005 | /* Calculate quality based on the following: | |
bf79451e | 4006 | * |
43f66a6c JK |
4007 | * Missed beacon: 100% = 0, 0% = 70% missed |
4008 | * Rate: 60% = 1Mbs, 100% = Max | |
4009 | * Rx and Tx errors represent a straight % of total Rx/Tx | |
4010 | * RSSI: 100% = > -50, 0% = < -80 | |
4011 | * Rx errors: 100% = 0, 0% = 50% missed | |
bf79451e | 4012 | * |
43f66a6c JK |
4013 | * The lowest computed quality is used. |
4014 | * | |
4015 | */ | |
4016 | #define BEACON_THRESHOLD 5 | |
4017 | beacon_quality = 100 - missed_beacons_percent; | |
4018 | if (beacon_quality < BEACON_THRESHOLD) | |
4019 | beacon_quality = 0; | |
4020 | else | |
bf79451e | 4021 | beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 / |
0edd5b44 | 4022 | (100 - BEACON_THRESHOLD); |
bf79451e | 4023 | IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n", |
43f66a6c | 4024 | beacon_quality, missed_beacons_percent); |
bf79451e | 4025 | |
43f66a6c | 4026 | priv->last_rate = ipw_get_current_rate(priv); |
ea2b26e0 JK |
4027 | max_rate = ipw_get_max_rate(priv); |
4028 | rate_quality = priv->last_rate * 40 / max_rate + 60; | |
43f66a6c JK |
4029 | IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", |
4030 | rate_quality, priv->last_rate / 1000000); | |
bf79451e | 4031 | |
0edd5b44 | 4032 | if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta) |
bf79451e | 4033 | rx_quality = 100 - (rx_err_delta * 100) / |
0edd5b44 | 4034 | (rx_packets_delta + rx_err_delta); |
43f66a6c JK |
4035 | else |
4036 | rx_quality = 100; | |
4037 | IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n", | |
4038 | rx_quality, rx_err_delta, rx_packets_delta); | |
bf79451e | 4039 | |
0edd5b44 | 4040 | if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta) |
bf79451e | 4041 | tx_quality = 100 - (tx_failures_delta * 100) / |
0edd5b44 | 4042 | (tx_packets_delta + tx_failures_delta); |
43f66a6c JK |
4043 | else |
4044 | tx_quality = 100; | |
4045 | IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n", | |
4046 | tx_quality, tx_failures_delta, tx_packets_delta); | |
bf79451e | 4047 | |
43f66a6c | 4048 | rssi = average_value(&priv->average_rssi); |
c848d0af JK |
4049 | signal_quality = |
4050 | (100 * | |
4051 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * | |
4052 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) - | |
4053 | (priv->ieee->perfect_rssi - rssi) * | |
4054 | (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) + | |
4055 | 62 * (priv->ieee->perfect_rssi - rssi))) / | |
4056 | ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) * | |
4057 | (priv->ieee->perfect_rssi - priv->ieee->worst_rssi)); | |
4058 | if (signal_quality > 100) | |
43f66a6c | 4059 | signal_quality = 100; |
c848d0af | 4060 | else if (signal_quality < 1) |
43f66a6c | 4061 | signal_quality = 0; |
ea2b26e0 | 4062 | |
43f66a6c JK |
4063 | IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", |
4064 | signal_quality, rssi); | |
bf79451e JG |
4065 | |
4066 | quality = min(beacon_quality, | |
43f66a6c JK |
4067 | min(rate_quality, |
4068 | min(tx_quality, min(rx_quality, signal_quality)))); | |
4069 | if (quality == beacon_quality) | |
0edd5b44 JG |
4070 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n", |
4071 | quality); | |
43f66a6c | 4072 | if (quality == rate_quality) |
0edd5b44 JG |
4073 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n", |
4074 | quality); | |
43f66a6c | 4075 | if (quality == tx_quality) |
0edd5b44 JG |
4076 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n", |
4077 | quality); | |
43f66a6c | 4078 | if (quality == rx_quality) |
0edd5b44 JG |
4079 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n", |
4080 | quality); | |
43f66a6c | 4081 | if (quality == signal_quality) |
0edd5b44 JG |
4082 | IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n", |
4083 | quality); | |
43f66a6c JK |
4084 | |
4085 | priv->quality = quality; | |
bf79451e JG |
4086 | |
4087 | queue_delayed_work(priv->workqueue, &priv->gather_stats, | |
43f66a6c JK |
4088 | IPW_STATS_INTERVAL); |
4089 | } | |
4090 | ||
c848d0af JK |
4091 | static void ipw_bg_gather_stats(void *data) |
4092 | { | |
4093 | struct ipw_priv *priv = data; | |
4644151b | 4094 | mutex_lock(&priv->mutex); |
c848d0af | 4095 | ipw_gather_stats(data); |
4644151b | 4096 | mutex_unlock(&priv->mutex); |
c848d0af JK |
4097 | } |
4098 | ||
e7582561 BC |
4099 | /* Missed beacon behavior: |
4100 | * 1st missed -> roaming_threshold, just wait, don't do any scan/roam. | |
4101 | * roaming_threshold -> disassociate_threshold, scan and roam for better signal. | |
4102 | * Above disassociate threshold, give up and stop scanning. | |
4103 | * Roaming is disabled if disassociate_threshold <= roaming_threshold */ | |
858119e1 | 4104 | static void ipw_handle_missed_beacon(struct ipw_priv *priv, |
ea2b26e0 JK |
4105 | int missed_count) |
4106 | { | |
4107 | priv->notif_missed_beacons = missed_count; | |
4108 | ||
afbf30a2 | 4109 | if (missed_count > priv->disassociate_threshold && |
ea2b26e0 JK |
4110 | priv->status & STATUS_ASSOCIATED) { |
4111 | /* If associated and we've hit the missed | |
4112 | * beacon threshold, disassociate, turn | |
4113 | * off roaming, and abort any active scans */ | |
4114 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | | |
afbf30a2 | 4115 | IPW_DL_STATE | IPW_DL_ASSOC, |
ea2b26e0 JK |
4116 | "Missed beacon: %d - disassociate\n", missed_count); |
4117 | priv->status &= ~STATUS_ROAMING; | |
a613bffd JK |
4118 | if (priv->status & STATUS_SCANNING) { |
4119 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | | |
4120 | IPW_DL_STATE, | |
4121 | "Aborting scan with missed beacon.\n"); | |
ea2b26e0 | 4122 | queue_work(priv->workqueue, &priv->abort_scan); |
a613bffd JK |
4123 | } |
4124 | ||
ea2b26e0 JK |
4125 | queue_work(priv->workqueue, &priv->disassociate); |
4126 | return; | |
4127 | } | |
4128 | ||
4129 | if (priv->status & STATUS_ROAMING) { | |
4130 | /* If we are currently roaming, then just | |
4131 | * print a debug statement... */ | |
4132 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | |
4133 | "Missed beacon: %d - roam in progress\n", | |
4134 | missed_count); | |
4135 | return; | |
4136 | } | |
4137 | ||
4bfdb91d ZY |
4138 | if (roaming && |
4139 | (missed_count > priv->roaming_threshold && | |
4140 | missed_count <= priv->disassociate_threshold)) { | |
ea2b26e0 | 4141 | /* If we are not already roaming, set the ROAM |
e7582561 BC |
4142 | * bit in the status and kick off a scan. |
4143 | * This can happen several times before we reach | |
4144 | * disassociate_threshold. */ | |
ea2b26e0 JK |
4145 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, |
4146 | "Missed beacon: %d - initiate " | |
4147 | "roaming\n", missed_count); | |
4148 | if (!(priv->status & STATUS_ROAMING)) { | |
4149 | priv->status |= STATUS_ROAMING; | |
4150 | if (!(priv->status & STATUS_SCANNING)) | |
4151 | queue_work(priv->workqueue, | |
4152 | &priv->request_scan); | |
4153 | } | |
4154 | return; | |
4155 | } | |
4156 | ||
4157 | if (priv->status & STATUS_SCANNING) { | |
4158 | /* Stop scan to keep fw from getting | |
4159 | * stuck (only if we aren't roaming -- | |
4160 | * otherwise we'll never scan more than 2 or 3 | |
4161 | * channels..) */ | |
b095c381 JK |
4162 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE, |
4163 | "Aborting scan with missed beacon.\n"); | |
ea2b26e0 JK |
4164 | queue_work(priv->workqueue, &priv->abort_scan); |
4165 | } | |
4166 | ||
4167 | IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count); | |
ea2b26e0 JK |
4168 | } |
4169 | ||
43f66a6c JK |
4170 | /** |
4171 | * Handle host notification packet. | |
4172 | * Called from interrupt routine | |
4173 | */ | |
858119e1 | 4174 | static void ipw_rx_notification(struct ipw_priv *priv, |
43f66a6c JK |
4175 | struct ipw_rx_notification *notif) |
4176 | { | |
a613bffd JK |
4177 | notif->size = le16_to_cpu(notif->size); |
4178 | ||
0edd5b44 | 4179 | IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size); |
bf79451e | 4180 | |
43f66a6c | 4181 | switch (notif->subtype) { |
0edd5b44 JG |
4182 | case HOST_NOTIFICATION_STATUS_ASSOCIATED:{ |
4183 | struct notif_association *assoc = ¬if->u.assoc; | |
4184 | ||
4185 | switch (assoc->state) { | |
4186 | case CMAS_ASSOCIATED:{ | |
4187 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4188 | IPW_DL_ASSOC, | |
4189 | "associated: '%s' " MAC_FMT | |
4190 | " \n", | |
4191 | escape_essid(priv->essid, | |
4192 | priv->essid_len), | |
4193 | MAC_ARG(priv->bssid)); | |
4194 | ||
4195 | switch (priv->ieee->iw_mode) { | |
4196 | case IW_MODE_INFRA: | |
4197 | memcpy(priv->ieee->bssid, | |
4198 | priv->bssid, ETH_ALEN); | |
4199 | break; | |
4200 | ||
4201 | case IW_MODE_ADHOC: | |
4202 | memcpy(priv->ieee->bssid, | |
4203 | priv->bssid, ETH_ALEN); | |
4204 | ||
4205 | /* clear out the station table */ | |
4206 | priv->num_stations = 0; | |
4207 | ||
4208 | IPW_DEBUG_ASSOC | |
4209 | ("queueing adhoc check\n"); | |
4210 | queue_delayed_work(priv-> | |
4211 | workqueue, | |
4212 | &priv-> | |
4213 | adhoc_check, | |
4214 | priv-> | |
4215 | assoc_request. | |
4216 | beacon_interval); | |
4217 | break; | |
4218 | } | |
4219 | ||
4220 | priv->status &= ~STATUS_ASSOCIATING; | |
4221 | priv->status |= STATUS_ASSOCIATED; | |
d8bad6df ZY |
4222 | queue_work(priv->workqueue, |
4223 | &priv->system_config); | |
0edd5b44 | 4224 | |
b095c381 | 4225 | #ifdef CONFIG_IPW_QOS |
afbf30a2 JK |
4226 | #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \ |
4227 | le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl)) | |
4228 | if ((priv->status & STATUS_AUTH) && | |
4229 | (IPW_GET_PACKET_STYPE(¬if->u.raw) | |
4230 | == IEEE80211_STYPE_ASSOC_RESP)) { | |
b095c381 JK |
4231 | if ((sizeof |
4232 | (struct | |
2b184d5b | 4233 | ieee80211_assoc_response) |
b095c381 JK |
4234 | <= notif->size) |
4235 | && (notif->size <= 2314)) { | |
4236 | struct | |
4237 | ieee80211_rx_stats | |
4238 | stats = { | |
4239 | .len = | |
4240 | notif-> | |
4241 | size - 1, | |
4242 | }; | |
4243 | ||
4244 | IPW_DEBUG_QOS | |
4245 | ("QoS Associate " | |
4246 | "size %d\n", | |
4247 | notif->size); | |
4248 | ieee80211_rx_mgt(priv-> | |
4249 | ieee, | |
4250 | (struct | |
2b184d5b | 4251 | ieee80211_hdr_4addr |
b095c381 JK |
4252 | *) |
4253 | ¬if->u.raw, &stats); | |
4254 | } | |
0edd5b44 | 4255 | } |
b095c381 | 4256 | #endif |
0edd5b44 | 4257 | |
a613bffd | 4258 | schedule_work(&priv->link_up); |
43f66a6c | 4259 | |
0edd5b44 JG |
4260 | break; |
4261 | } | |
bf79451e | 4262 | |
0edd5b44 JG |
4263 | case CMAS_AUTHENTICATED:{ |
4264 | if (priv-> | |
4265 | status & (STATUS_ASSOCIATED | | |
4266 | STATUS_AUTH)) { | |
0f52bf90 | 4267 | #ifdef CONFIG_IPW2200_DEBUG |
0edd5b44 JG |
4268 | struct notif_authenticate *auth |
4269 | = ¬if->u.auth; | |
4270 | IPW_DEBUG(IPW_DL_NOTIF | | |
4271 | IPW_DL_STATE | | |
4272 | IPW_DL_ASSOC, | |
4273 | "deauthenticated: '%s' " | |
4274 | MAC_FMT | |
4275 | ": (0x%04X) - %s \n", | |
4276 | escape_essid(priv-> | |
4277 | essid, | |
4278 | priv-> | |
4279 | essid_len), | |
4280 | MAC_ARG(priv->bssid), | |
4281 | ntohs(auth->status), | |
4282 | ipw_get_status_code | |
4283 | (ntohs | |
4284 | (auth->status))); | |
43f66a6c JK |
4285 | #endif |
4286 | ||
0edd5b44 JG |
4287 | priv->status &= |
4288 | ~(STATUS_ASSOCIATING | | |
4289 | STATUS_AUTH | | |
4290 | STATUS_ASSOCIATED); | |
4291 | ||
a613bffd | 4292 | schedule_work(&priv->link_down); |
0edd5b44 JG |
4293 | break; |
4294 | } | |
4295 | ||
4296 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4297 | IPW_DL_ASSOC, | |
4298 | "authenticated: '%s' " MAC_FMT | |
4299 | "\n", | |
4300 | escape_essid(priv->essid, | |
4301 | priv->essid_len), | |
4302 | MAC_ARG(priv->bssid)); | |
4303 | break; | |
4304 | } | |
4305 | ||
4306 | case CMAS_INIT:{ | |
ea2b26e0 JK |
4307 | if (priv->status & STATUS_AUTH) { |
4308 | struct | |
4309 | ieee80211_assoc_response | |
4310 | *resp; | |
4311 | resp = | |
4312 | (struct | |
4313 | ieee80211_assoc_response | |
4314 | *)¬if->u.raw; | |
4315 | IPW_DEBUG(IPW_DL_NOTIF | | |
4316 | IPW_DL_STATE | | |
4317 | IPW_DL_ASSOC, | |
4318 | "association failed (0x%04X): %s\n", | |
4319 | ntohs(resp->status), | |
4320 | ipw_get_status_code | |
4321 | (ntohs | |
4322 | (resp->status))); | |
4323 | } | |
4324 | ||
0edd5b44 JG |
4325 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | |
4326 | IPW_DL_ASSOC, | |
4327 | "disassociated: '%s' " MAC_FMT | |
4328 | " \n", | |
4329 | escape_essid(priv->essid, | |
4330 | priv->essid_len), | |
4331 | MAC_ARG(priv->bssid)); | |
4332 | ||
4333 | priv->status &= | |
4334 | ~(STATUS_DISASSOCIATING | | |
4335 | STATUS_ASSOCIATING | | |
4336 | STATUS_ASSOCIATED | STATUS_AUTH); | |
b095c381 JK |
4337 | if (priv->assoc_network |
4338 | && (priv->assoc_network-> | |
4339 | capability & | |
4340 | WLAN_CAPABILITY_IBSS)) | |
4341 | ipw_remove_current_network | |
4342 | (priv); | |
0edd5b44 | 4343 | |
a613bffd | 4344 | schedule_work(&priv->link_down); |
0edd5b44 | 4345 | |
0edd5b44 JG |
4346 | break; |
4347 | } | |
43f66a6c | 4348 | |
b095c381 JK |
4349 | case CMAS_RX_ASSOC_RESP: |
4350 | break; | |
4351 | ||
0edd5b44 JG |
4352 | default: |
4353 | IPW_ERROR("assoc: unknown (%d)\n", | |
4354 | assoc->state); | |
43f66a6c | 4355 | break; |
bf79451e | 4356 | } |
43f66a6c | 4357 | |
43f66a6c JK |
4358 | break; |
4359 | } | |
bf79451e | 4360 | |
0edd5b44 JG |
4361 | case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{ |
4362 | struct notif_authenticate *auth = ¬if->u.auth; | |
4363 | switch (auth->state) { | |
4364 | case CMAS_AUTHENTICATED: | |
4365 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | |
4366 | "authenticated: '%s' " MAC_FMT " \n", | |
4367 | escape_essid(priv->essid, | |
4368 | priv->essid_len), | |
4369 | MAC_ARG(priv->bssid)); | |
4370 | priv->status |= STATUS_AUTH; | |
4371 | break; | |
43f66a6c | 4372 | |
0edd5b44 JG |
4373 | case CMAS_INIT: |
4374 | if (priv->status & STATUS_AUTH) { | |
4375 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4376 | IPW_DL_ASSOC, | |
4377 | "authentication failed (0x%04X): %s\n", | |
4378 | ntohs(auth->status), | |
4379 | ipw_get_status_code(ntohs | |
4380 | (auth-> | |
4381 | status))); | |
4382 | } | |
4383 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4384 | IPW_DL_ASSOC, | |
4385 | "deauthenticated: '%s' " MAC_FMT "\n", | |
4386 | escape_essid(priv->essid, | |
4387 | priv->essid_len), | |
4388 | MAC_ARG(priv->bssid)); | |
bf79451e | 4389 | |
0edd5b44 JG |
4390 | priv->status &= ~(STATUS_ASSOCIATING | |
4391 | STATUS_AUTH | | |
4392 | STATUS_ASSOCIATED); | |
43f66a6c | 4393 | |
a613bffd | 4394 | schedule_work(&priv->link_down); |
0edd5b44 | 4395 | break; |
43f66a6c | 4396 | |
0edd5b44 JG |
4397 | case CMAS_TX_AUTH_SEQ_1: |
4398 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4399 | IPW_DL_ASSOC, "AUTH_SEQ_1\n"); | |
4400 | break; | |
4401 | case CMAS_RX_AUTH_SEQ_2: | |
4402 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4403 | IPW_DL_ASSOC, "AUTH_SEQ_2\n"); | |
4404 | break; | |
4405 | case CMAS_AUTH_SEQ_1_PASS: | |
4406 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4407 | IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n"); | |
4408 | break; | |
4409 | case CMAS_AUTH_SEQ_1_FAIL: | |
4410 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4411 | IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n"); | |
4412 | break; | |
4413 | case CMAS_TX_AUTH_SEQ_3: | |
4414 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4415 | IPW_DL_ASSOC, "AUTH_SEQ_3\n"); | |
4416 | break; | |
4417 | case CMAS_RX_AUTH_SEQ_4: | |
4418 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4419 | IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n"); | |
4420 | break; | |
4421 | case CMAS_AUTH_SEQ_2_PASS: | |
4422 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4423 | IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n"); | |
4424 | break; | |
4425 | case CMAS_AUTH_SEQ_2_FAIL: | |
4426 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4427 | IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n"); | |
4428 | break; | |
4429 | case CMAS_TX_ASSOC: | |
4430 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4431 | IPW_DL_ASSOC, "TX_ASSOC\n"); | |
4432 | break; | |
4433 | case CMAS_RX_ASSOC_RESP: | |
4434 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4435 | IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); | |
b095c381 | 4436 | |
0edd5b44 JG |
4437 | break; |
4438 | case CMAS_ASSOCIATED: | |
4439 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | | |
4440 | IPW_DL_ASSOC, "ASSOCIATED\n"); | |
4441 | break; | |
4442 | default: | |
4443 | IPW_DEBUG_NOTIF("auth: failure - %d\n", | |
4444 | auth->state); | |
4445 | break; | |
43f66a6c | 4446 | } |
43f66a6c JK |
4447 | break; |
4448 | } | |
4449 | ||
0edd5b44 JG |
4450 | case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{ |
4451 | struct notif_channel_result *x = | |
4452 | ¬if->u.channel_result; | |
43f66a6c | 4453 | |
0edd5b44 JG |
4454 | if (notif->size == sizeof(*x)) { |
4455 | IPW_DEBUG_SCAN("Scan result for channel %d\n", | |
4456 | x->channel_num); | |
4457 | } else { | |
4458 | IPW_DEBUG_SCAN("Scan result of wrong size %d " | |
4459 | "(should be %zd)\n", | |
4460 | notif->size, sizeof(*x)); | |
bf79451e | 4461 | } |
43f66a6c JK |
4462 | break; |
4463 | } | |
43f66a6c | 4464 | |
0edd5b44 JG |
4465 | case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{ |
4466 | struct notif_scan_complete *x = ¬if->u.scan_complete; | |
4467 | if (notif->size == sizeof(*x)) { | |
4468 | IPW_DEBUG_SCAN | |
4469 | ("Scan completed: type %d, %d channels, " | |
4470 | "%d status\n", x->scan_type, | |
4471 | x->num_channels, x->status); | |
4472 | } else { | |
4473 | IPW_ERROR("Scan completed of wrong size %d " | |
4474 | "(should be %zd)\n", | |
4475 | notif->size, sizeof(*x)); | |
4476 | } | |
43f66a6c | 4477 | |
0edd5b44 JG |
4478 | priv->status &= |
4479 | ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); | |
4480 | ||
a0e04ab3 | 4481 | wake_up_interruptible(&priv->wait_state); |
0edd5b44 JG |
4482 | cancel_delayed_work(&priv->scan_check); |
4483 | ||
b095c381 JK |
4484 | if (priv->status & STATUS_EXIT_PENDING) |
4485 | break; | |
4486 | ||
4487 | priv->ieee->scans++; | |
4488 | ||
4489 | #ifdef CONFIG_IPW2200_MONITOR | |
4490 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | |
afbf30a2 | 4491 | priv->status |= STATUS_SCAN_FORCED; |
b095c381 JK |
4492 | queue_work(priv->workqueue, |
4493 | &priv->request_scan); | |
4494 | break; | |
4495 | } | |
afbf30a2 | 4496 | priv->status &= ~STATUS_SCAN_FORCED; |
b095c381 JK |
4497 | #endif /* CONFIG_IPW2200_MONITOR */ |
4498 | ||
0edd5b44 JG |
4499 | if (!(priv->status & (STATUS_ASSOCIATED | |
4500 | STATUS_ASSOCIATING | | |
4501 | STATUS_ROAMING | | |
4502 | STATUS_DISASSOCIATING))) | |
4503 | queue_work(priv->workqueue, &priv->associate); | |
4504 | else if (priv->status & STATUS_ROAMING) { | |
e7582561 BC |
4505 | if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) |
4506 | /* If a scan completed and we are in roam mode, then | |
4507 | * the scan that completed was the one requested as a | |
4508 | * result of entering roam... so, schedule the | |
4509 | * roam work */ | |
4510 | queue_work(priv->workqueue, | |
4511 | &priv->roam); | |
4512 | else | |
4513 | /* Don't schedule if we aborted the scan */ | |
4514 | priv->status &= ~STATUS_ROAMING; | |
0edd5b44 JG |
4515 | } else if (priv->status & STATUS_SCAN_PENDING) |
4516 | queue_work(priv->workqueue, | |
4517 | &priv->request_scan); | |
a613bffd JK |
4518 | else if (priv->config & CFG_BACKGROUND_SCAN |
4519 | && priv->status & STATUS_ASSOCIATED) | |
4520 | queue_delayed_work(priv->workqueue, | |
4521 | &priv->request_scan, HZ); | |
0edd5b44 | 4522 | break; |
43f66a6c | 4523 | } |
43f66a6c | 4524 | |
0edd5b44 JG |
4525 | case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ |
4526 | struct notif_frag_length *x = ¬if->u.frag_len; | |
43f66a6c | 4527 | |
a613bffd JK |
4528 | if (notif->size == sizeof(*x)) |
4529 | IPW_ERROR("Frag length: %d\n", | |
4530 | le16_to_cpu(x->frag_length)); | |
4531 | else | |
0edd5b44 JG |
4532 | IPW_ERROR("Frag length of wrong size %d " |
4533 | "(should be %zd)\n", | |
4534 | notif->size, sizeof(*x)); | |
0edd5b44 | 4535 | break; |
43f66a6c | 4536 | } |
43f66a6c | 4537 | |
0edd5b44 JG |
4538 | case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ |
4539 | struct notif_link_deterioration *x = | |
4540 | ¬if->u.link_deterioration; | |
afbf30a2 | 4541 | |
0edd5b44 JG |
4542 | if (notif->size == sizeof(*x)) { |
4543 | IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, | |
4544 | "link deterioration: '%s' " MAC_FMT | |
4545 | " \n", escape_essid(priv->essid, | |
4546 | priv->essid_len), | |
4547 | MAC_ARG(priv->bssid)); | |
4548 | memcpy(&priv->last_link_deterioration, x, | |
4549 | sizeof(*x)); | |
4550 | } else { | |
4551 | IPW_ERROR("Link Deterioration of wrong size %d " | |
4552 | "(should be %zd)\n", | |
4553 | notif->size, sizeof(*x)); | |
4554 | } | |
43f66a6c JK |
4555 | break; |
4556 | } | |
4557 | ||
0edd5b44 JG |
4558 | case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ |
4559 | IPW_ERROR("Dino config\n"); | |
4560 | if (priv->hcmd | |
a613bffd | 4561 | && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG) |
0edd5b44 | 4562 | IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); |
a613bffd | 4563 | |
0edd5b44 JG |
4564 | break; |
4565 | } | |
43f66a6c | 4566 | |
0edd5b44 JG |
4567 | case HOST_NOTIFICATION_STATUS_BEACON_STATE:{ |
4568 | struct notif_beacon_state *x = ¬if->u.beacon_state; | |
4569 | if (notif->size != sizeof(*x)) { | |
4570 | IPW_ERROR | |
4571 | ("Beacon state of wrong size %d (should " | |
4572 | "be %zd)\n", notif->size, sizeof(*x)); | |
4573 | break; | |
43f66a6c JK |
4574 | } |
4575 | ||
a613bffd JK |
4576 | if (le32_to_cpu(x->state) == |
4577 | HOST_NOTIFICATION_STATUS_BEACON_MISSING) | |
4578 | ipw_handle_missed_beacon(priv, | |
4579 | le32_to_cpu(x-> | |
4580 | number)); | |
43f66a6c | 4581 | |
0edd5b44 JG |
4582 | break; |
4583 | } | |
43f66a6c | 4584 | |
0edd5b44 JG |
4585 | case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{ |
4586 | struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key; | |
4587 | if (notif->size == sizeof(*x)) { | |
4588 | IPW_ERROR("TGi Tx Key: state 0x%02x sec type " | |
4589 | "0x%02x station %d\n", | |
4590 | x->key_state, x->security_type, | |
4591 | x->station_index); | |
4592 | break; | |
4593 | } | |
43f66a6c | 4594 | |
0edd5b44 JG |
4595 | IPW_ERROR |
4596 | ("TGi Tx Key of wrong size %d (should be %zd)\n", | |
4597 | notif->size, sizeof(*x)); | |
43f66a6c | 4598 | break; |
bf79451e | 4599 | } |
43f66a6c | 4600 | |
0edd5b44 JG |
4601 | case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{ |
4602 | struct notif_calibration *x = ¬if->u.calibration; | |
43f66a6c | 4603 | |
0edd5b44 JG |
4604 | if (notif->size == sizeof(*x)) { |
4605 | memcpy(&priv->calib, x, sizeof(*x)); | |
4606 | IPW_DEBUG_INFO("TODO: Calibration\n"); | |
4607 | break; | |
4608 | } | |
43f66a6c | 4609 | |
0edd5b44 JG |
4610 | IPW_ERROR |
4611 | ("Calibration of wrong size %d (should be %zd)\n", | |
4612 | notif->size, sizeof(*x)); | |
43f66a6c | 4613 | break; |
bf79451e JG |
4614 | } |
4615 | ||
0edd5b44 JG |
4616 | case HOST_NOTIFICATION_NOISE_STATS:{ |
4617 | if (notif->size == sizeof(u32)) { | |
4618 | priv->last_noise = | |
a613bffd JK |
4619 | (u8) (le32_to_cpu(notif->u.noise.value) & |
4620 | 0xff); | |
0edd5b44 JG |
4621 | average_add(&priv->average_noise, |
4622 | priv->last_noise); | |
4623 | break; | |
4624 | } | |
43f66a6c | 4625 | |
0edd5b44 JG |
4626 | IPW_ERROR |
4627 | ("Noise stat is wrong size %d (should be %zd)\n", | |
4628 | notif->size, sizeof(u32)); | |
43f66a6c JK |
4629 | break; |
4630 | } | |
4631 | ||
43f66a6c | 4632 | default: |
1dd31b6c ZY |
4633 | IPW_DEBUG_NOTIF("Unknown notification: " |
4634 | "subtype=%d,flags=0x%2x,size=%d\n", | |
4635 | notif->subtype, notif->flags, notif->size); | |
43f66a6c JK |
4636 | } |
4637 | } | |
4638 | ||
4639 | /** | |
4640 | * Destroys all DMA structures and initialise them again | |
bf79451e | 4641 | * |
43f66a6c JK |
4642 | * @param priv |
4643 | * @return error code | |
4644 | */ | |
4645 | static int ipw_queue_reset(struct ipw_priv *priv) | |
4646 | { | |
4647 | int rc = 0; | |
4648 | /** @todo customize queue sizes */ | |
4649 | int nTx = 64, nTxCmd = 8; | |
4650 | ipw_tx_queue_free(priv); | |
4651 | /* Tx CMD queue */ | |
4652 | rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, | |
b095c381 JK |
4653 | IPW_TX_CMD_QUEUE_READ_INDEX, |
4654 | IPW_TX_CMD_QUEUE_WRITE_INDEX, | |
4655 | IPW_TX_CMD_QUEUE_BD_BASE, | |
4656 | IPW_TX_CMD_QUEUE_BD_SIZE); | |
43f66a6c JK |
4657 | if (rc) { |
4658 | IPW_ERROR("Tx Cmd queue init failed\n"); | |
4659 | goto error; | |
4660 | } | |
4661 | /* Tx queue(s) */ | |
4662 | rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, | |
b095c381 JK |
4663 | IPW_TX_QUEUE_0_READ_INDEX, |
4664 | IPW_TX_QUEUE_0_WRITE_INDEX, | |
4665 | IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE); | |
43f66a6c JK |
4666 | if (rc) { |
4667 | IPW_ERROR("Tx 0 queue init failed\n"); | |
4668 | goto error; | |
4669 | } | |
4670 | rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, | |
b095c381 JK |
4671 | IPW_TX_QUEUE_1_READ_INDEX, |
4672 | IPW_TX_QUEUE_1_WRITE_INDEX, | |
4673 | IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE); | |
43f66a6c JK |
4674 | if (rc) { |
4675 | IPW_ERROR("Tx 1 queue init failed\n"); | |
4676 | goto error; | |
4677 | } | |
4678 | rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, | |
b095c381 JK |
4679 | IPW_TX_QUEUE_2_READ_INDEX, |
4680 | IPW_TX_QUEUE_2_WRITE_INDEX, | |
4681 | IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE); | |
43f66a6c JK |
4682 | if (rc) { |
4683 | IPW_ERROR("Tx 2 queue init failed\n"); | |
4684 | goto error; | |
4685 | } | |
4686 | rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, | |
b095c381 JK |
4687 | IPW_TX_QUEUE_3_READ_INDEX, |
4688 | IPW_TX_QUEUE_3_WRITE_INDEX, | |
4689 | IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE); | |
43f66a6c JK |
4690 | if (rc) { |
4691 | IPW_ERROR("Tx 3 queue init failed\n"); | |
4692 | goto error; | |
4693 | } | |
4694 | /* statistics */ | |
4695 | priv->rx_bufs_min = 0; | |
4696 | priv->rx_pend_max = 0; | |
4697 | return rc; | |
4698 | ||
0edd5b44 | 4699 | error: |
43f66a6c JK |
4700 | ipw_tx_queue_free(priv); |
4701 | return rc; | |
4702 | } | |
4703 | ||
4704 | /** | |
4705 | * Reclaim Tx queue entries no more used by NIC. | |
bf79451e | 4706 | * |
43f66a6c JK |
4707 | * When FW adwances 'R' index, all entries between old and |
4708 | * new 'R' index need to be reclaimed. As result, some free space | |
4709 | * forms. If there is enough free space (> low mark), wake Tx queue. | |
bf79451e | 4710 | * |
43f66a6c JK |
4711 | * @note Need to protect against garbage in 'R' index |
4712 | * @param priv | |
4713 | * @param txq | |
4714 | * @param qindex | |
4715 | * @return Number of used entries remains in the queue | |
4716 | */ | |
bf79451e | 4717 | static int ipw_queue_tx_reclaim(struct ipw_priv *priv, |
43f66a6c JK |
4718 | struct clx2_tx_queue *txq, int qindex) |
4719 | { | |
4720 | u32 hw_tail; | |
4721 | int used; | |
4722 | struct clx2_queue *q = &txq->q; | |
4723 | ||
4724 | hw_tail = ipw_read32(priv, q->reg_r); | |
4725 | if (hw_tail >= q->n_bd) { | |
4726 | IPW_ERROR | |
0edd5b44 JG |
4727 | ("Read index for DMA queue (%d) is out of range [0-%d)\n", |
4728 | hw_tail, q->n_bd); | |
43f66a6c JK |
4729 | goto done; |
4730 | } | |
4731 | for (; q->last_used != hw_tail; | |
4732 | q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) { | |
4733 | ipw_queue_tx_free_tfd(priv, txq); | |
4734 | priv->tx_packets++; | |
4735 | } | |
0edd5b44 | 4736 | done: |
9ddf84f6 JK |
4737 | if ((ipw_queue_space(q) > q->low_mark) && |
4738 | (qindex >= 0) && | |
4739 | (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev)) | |
4740 | netif_wake_queue(priv->net_dev); | |
43f66a6c JK |
4741 | used = q->first_empty - q->last_used; |
4742 | if (used < 0) | |
4743 | used += q->n_bd; | |
4744 | ||
4745 | return used; | |
4746 | } | |
4747 | ||
4748 | static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf, | |
4749 | int len, int sync) | |
4750 | { | |
4751 | struct clx2_tx_queue *txq = &priv->txq_cmd; | |
4752 | struct clx2_queue *q = &txq->q; | |
4753 | struct tfd_frame *tfd; | |
4754 | ||
4755 | if (ipw_queue_space(q) < (sync ? 1 : 2)) { | |
4756 | IPW_ERROR("No space for Tx\n"); | |
4757 | return -EBUSY; | |
4758 | } | |
4759 | ||
4760 | tfd = &txq->bd[q->first_empty]; | |
4761 | txq->txb[q->first_empty] = NULL; | |
4762 | ||
4763 | memset(tfd, 0, sizeof(*tfd)); | |
4764 | tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE; | |
4765 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; | |
4766 | priv->hcmd_seq++; | |
4767 | tfd->u.cmd.index = hcmd; | |
4768 | tfd->u.cmd.length = len; | |
4769 | memcpy(tfd->u.cmd.payload, buf, len); | |
4770 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); | |
4771 | ipw_write32(priv, q->reg_w, q->first_empty); | |
4772 | _ipw_read32(priv, 0x90); | |
4773 | ||
4774 | return 0; | |
4775 | } | |
4776 | ||
bf79451e | 4777 | /* |
43f66a6c JK |
4778 | * Rx theory of operation |
4779 | * | |
4780 | * The host allocates 32 DMA target addresses and passes the host address | |
b095c381 | 4781 | * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
43f66a6c JK |
4782 | * 0 to 31 |
4783 | * | |
4784 | * Rx Queue Indexes | |
4785 | * The host/firmware share two index registers for managing the Rx buffers. | |
4786 | * | |
bf79451e JG |
4787 | * The READ index maps to the first position that the firmware may be writing |
4788 | * to -- the driver can read up to (but not including) this position and get | |
4789 | * good data. | |
43f66a6c JK |
4790 | * The READ index is managed by the firmware once the card is enabled. |
4791 | * | |
4792 | * The WRITE index maps to the last position the driver has read from -- the | |
4793 | * position preceding WRITE is the last slot the firmware can place a packet. | |
4794 | * | |
4795 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if | |
bf79451e | 4796 | * WRITE = READ. |
43f66a6c | 4797 | * |
bf79451e | 4798 | * During initialization the host sets up the READ queue position to the first |
43f66a6c JK |
4799 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
4800 | * | |
4801 | * When the firmware places a packet in a buffer it will advance the READ index | |
4802 | * and fire the RX interrupt. The driver can then query the READ index and | |
4803 | * process as many packets as possible, moving the WRITE index forward as it | |
4804 | * resets the Rx queue buffers with new memory. | |
bf79451e | 4805 | * |
43f66a6c | 4806 | * The management in the driver is as follows: |
bf79451e | 4807 | * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When |
43f66a6c | 4808 | * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled |
bf79451e | 4809 | * to replensish the ipw->rxq->rx_free. |
43f66a6c JK |
4810 | * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the |
4811 | * ipw->rxq is replenished and the READ INDEX is updated (updating the | |
4812 | * 'processed' and 'read' driver indexes as well) | |
4813 | * + A received packet is processed and handed to the kernel network stack, | |
4814 | * detached from the ipw->rxq. The driver 'processed' index is updated. | |
4815 | * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free | |
bf79451e JG |
4816 | * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ |
4817 | * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there | |
43f66a6c JK |
4818 | * were enough free buffers and RX_STALLED is set it is cleared. |
4819 | * | |
4820 | * | |
4821 | * Driver sequence: | |
4822 | * | |
bf79451e | 4823 | * ipw_rx_queue_alloc() Allocates rx_free |
43f66a6c JK |
4824 | * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls |
4825 | * ipw_rx_queue_restock | |
4826 | * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx | |
4827 | * queue, updates firmware pointers, and updates | |
4828 | * the WRITE index. If insufficient rx_free buffers | |
4829 | * are available, schedules ipw_rx_queue_replenish | |
4830 | * | |
4831 | * -- enable interrupts -- | |
4832 | * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the | |
bf79451e | 4833 | * READ INDEX, detaching the SKB from the pool. |
43f66a6c JK |
4834 | * Moves the packet buffer from queue to rx_used. |
4835 | * Calls ipw_rx_queue_restock to refill any empty | |
4836 | * slots. | |
4837 | * ... | |
4838 | * | |
4839 | */ | |
4840 | ||
bf79451e | 4841 | /* |
43f66a6c JK |
4842 | * If there are slots in the RX queue that need to be restocked, |
4843 | * and we have free pre-allocated buffers, fill the ranks as much | |
4844 | * as we can pulling from rx_free. | |
4845 | * | |
4846 | * This moves the 'write' index forward to catch up with 'processed', and | |
4847 | * also updates the memory address in the firmware to reference the new | |
4848 | * target buffer. | |
4849 | */ | |
4850 | static void ipw_rx_queue_restock(struct ipw_priv *priv) | |
4851 | { | |
4852 | struct ipw_rx_queue *rxq = priv->rxq; | |
4853 | struct list_head *element; | |
4854 | struct ipw_rx_mem_buffer *rxb; | |
4855 | unsigned long flags; | |
4856 | int write; | |
4857 | ||
4858 | spin_lock_irqsave(&rxq->lock, flags); | |
4859 | write = rxq->write; | |
4860 | while ((rxq->write != rxq->processed) && (rxq->free_count)) { | |
4861 | element = rxq->rx_free.next; | |
4862 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); | |
4863 | list_del(element); | |
4864 | ||
b095c381 | 4865 | ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, |
43f66a6c JK |
4866 | rxb->dma_addr); |
4867 | rxq->queue[rxq->write] = rxb; | |
4868 | rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; | |
4869 | rxq->free_count--; | |
4870 | } | |
4871 | spin_unlock_irqrestore(&rxq->lock, flags); | |
4872 | ||
bf79451e | 4873 | /* If the pre-allocated buffer pool is dropping low, schedule to |
43f66a6c JK |
4874 | * refill it */ |
4875 | if (rxq->free_count <= RX_LOW_WATERMARK) | |
4876 | queue_work(priv->workqueue, &priv->rx_replenish); | |
4877 | ||
4878 | /* If we've added more space for the firmware to place data, tell it */ | |
bf79451e | 4879 | if (write != rxq->write) |
b095c381 | 4880 | ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write); |
43f66a6c JK |
4881 | } |
4882 | ||
4883 | /* | |
4884 | * Move all used packet from rx_used to rx_free, allocating a new SKB for each. | |
bf79451e JG |
4885 | * Also restock the Rx queue via ipw_rx_queue_restock. |
4886 | * | |
43f66a6c JK |
4887 | * This is called as a scheduled work item (except for during intialization) |
4888 | */ | |
4889 | static void ipw_rx_queue_replenish(void *data) | |
4890 | { | |
4891 | struct ipw_priv *priv = data; | |
4892 | struct ipw_rx_queue *rxq = priv->rxq; | |
4893 | struct list_head *element; | |
4894 | struct ipw_rx_mem_buffer *rxb; | |
4895 | unsigned long flags; | |
4896 | ||
4897 | spin_lock_irqsave(&rxq->lock, flags); | |
4898 | while (!list_empty(&rxq->rx_used)) { | |
4899 | element = rxq->rx_used.next; | |
4900 | rxb = list_entry(element, struct ipw_rx_mem_buffer, list); | |
b095c381 | 4901 | rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC); |
43f66a6c JK |
4902 | if (!rxb->skb) { |
4903 | printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", | |
4904 | priv->net_dev->name); | |
4905 | /* We don't reschedule replenish work here -- we will | |
4906 | * call the restock method and if it still needs | |
4907 | * more buffers it will schedule replenish */ | |
4908 | break; | |
4909 | } | |
4910 | list_del(element); | |
bf79451e | 4911 | |
43f66a6c | 4912 | rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data; |
0edd5b44 JG |
4913 | rxb->dma_addr = |
4914 | pci_map_single(priv->pci_dev, rxb->skb->data, | |
b095c381 | 4915 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
bf79451e | 4916 | |
43f66a6c JK |
4917 | list_add_tail(&rxb->list, &rxq->rx_free); |
4918 | rxq->free_count++; | |
4919 | } | |
4920 | spin_unlock_irqrestore(&rxq->lock, flags); | |
4921 | ||
4922 | ipw_rx_queue_restock(priv); | |
4923 | } | |
4924 | ||
c848d0af JK |
4925 | static void ipw_bg_rx_queue_replenish(void *data) |
4926 | { | |
4927 | struct ipw_priv *priv = data; | |
4644151b | 4928 | mutex_lock(&priv->mutex); |
c848d0af | 4929 | ipw_rx_queue_replenish(data); |
4644151b | 4930 | mutex_unlock(&priv->mutex); |
c848d0af JK |
4931 | } |
4932 | ||
43f66a6c | 4933 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
c7b6a674 | 4934 | * If an SKB has been detached, the POOL needs to have its SKB set to NULL |
bf79451e | 4935 | * This free routine walks the list of POOL entries and if SKB is set to |
43f66a6c JK |
4936 | * non NULL it is unmapped and freed |
4937 | */ | |
0edd5b44 | 4938 | static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq) |
43f66a6c JK |
4939 | { |
4940 | int i; | |
4941 | ||
4942 | if (!rxq) | |
4943 | return; | |
bf79451e | 4944 | |
43f66a6c JK |
4945 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
4946 | if (rxq->pool[i].skb != NULL) { | |
4947 | pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, | |
b095c381 | 4948 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
43f66a6c JK |
4949 | dev_kfree_skb(rxq->pool[i].skb); |
4950 | } | |
4951 | } | |
4952 | ||
4953 | kfree(rxq); | |
4954 | } | |
4955 | ||
4956 | static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv) | |
4957 | { | |
4958 | struct ipw_rx_queue *rxq; | |
4959 | int i; | |
4960 | ||
c75f4742 | 4961 | rxq = kzalloc(sizeof(*rxq), GFP_KERNEL); |
ad18b0ea PI |
4962 | if (unlikely(!rxq)) { |
4963 | IPW_ERROR("memory allocation failed\n"); | |
4964 | return NULL; | |
4965 | } | |
43f66a6c JK |
4966 | spin_lock_init(&rxq->lock); |
4967 | INIT_LIST_HEAD(&rxq->rx_free); | |
4968 | INIT_LIST_HEAD(&rxq->rx_used); | |
4969 | ||
4970 | /* Fill the rx_used queue with _all_ of the Rx buffers */ | |
bf79451e | 4971 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
43f66a6c JK |
4972 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
4973 | ||
4974 | /* Set us so that we have processed and used all buffers, but have | |
4975 | * not restocked the Rx queue with fresh buffers */ | |
4976 | rxq->read = rxq->write = 0; | |
4977 | rxq->processed = RX_QUEUE_SIZE - 1; | |
4978 | rxq->free_count = 0; | |
4979 | ||
4980 | return rxq; | |
4981 | } | |
4982 | ||
4983 | static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate) | |
4984 | { | |
4985 | rate &= ~IEEE80211_BASIC_RATE_MASK; | |
4986 | if (ieee_mode == IEEE_A) { | |
4987 | switch (rate) { | |
bf79451e JG |
4988 | case IEEE80211_OFDM_RATE_6MB: |
4989 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? | |
0edd5b44 | 4990 | 1 : 0; |
bf79451e JG |
4991 | case IEEE80211_OFDM_RATE_9MB: |
4992 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? | |
0edd5b44 | 4993 | 1 : 0; |
bf79451e | 4994 | case IEEE80211_OFDM_RATE_12MB: |
0edd5b44 JG |
4995 | return priv-> |
4996 | rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; | |
bf79451e | 4997 | case IEEE80211_OFDM_RATE_18MB: |
0edd5b44 JG |
4998 | return priv-> |
4999 | rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; | |
bf79451e | 5000 | case IEEE80211_OFDM_RATE_24MB: |
0edd5b44 JG |
5001 | return priv-> |
5002 | rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; | |
bf79451e | 5003 | case IEEE80211_OFDM_RATE_36MB: |
0edd5b44 JG |
5004 | return priv-> |
5005 | rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; | |
bf79451e | 5006 | case IEEE80211_OFDM_RATE_48MB: |
0edd5b44 JG |
5007 | return priv-> |
5008 | rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; | |
bf79451e | 5009 | case IEEE80211_OFDM_RATE_54MB: |
0edd5b44 JG |
5010 | return priv-> |
5011 | rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; | |
43f66a6c JK |
5012 | default: |
5013 | return 0; | |
5014 | } | |
5015 | } | |
bf79451e | 5016 | |
43f66a6c JK |
5017 | /* B and G mixed */ |
5018 | switch (rate) { | |
bf79451e | 5019 | case IEEE80211_CCK_RATE_1MB: |
43f66a6c | 5020 | return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0; |
bf79451e | 5021 | case IEEE80211_CCK_RATE_2MB: |
43f66a6c | 5022 | return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0; |
bf79451e | 5023 | case IEEE80211_CCK_RATE_5MB: |
43f66a6c | 5024 | return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0; |
bf79451e | 5025 | case IEEE80211_CCK_RATE_11MB: |
43f66a6c JK |
5026 | return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0; |
5027 | } | |
5028 | ||
5029 | /* If we are limited to B modulations, bail at this point */ | |
5030 | if (ieee_mode == IEEE_B) | |
5031 | return 0; | |
5032 | ||
5033 | /* G */ | |
5034 | switch (rate) { | |
bf79451e | 5035 | case IEEE80211_OFDM_RATE_6MB: |
43f66a6c | 5036 | return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0; |
bf79451e | 5037 | case IEEE80211_OFDM_RATE_9MB: |
43f66a6c | 5038 | return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0; |
bf79451e | 5039 | case IEEE80211_OFDM_RATE_12MB: |
43f66a6c | 5040 | return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0; |
bf79451e | 5041 | case IEEE80211_OFDM_RATE_18MB: |
43f66a6c | 5042 | return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0; |
bf79451e | 5043 | case IEEE80211_OFDM_RATE_24MB: |
43f66a6c | 5044 | return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0; |
bf79451e | 5045 | case IEEE80211_OFDM_RATE_36MB: |
43f66a6c | 5046 | return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0; |
bf79451e | 5047 | case IEEE80211_OFDM_RATE_48MB: |
43f66a6c | 5048 | return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0; |
bf79451e | 5049 | case IEEE80211_OFDM_RATE_54MB: |
43f66a6c JK |
5050 | return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0; |
5051 | } | |
5052 | ||
5053 | return 0; | |
5054 | } | |
5055 | ||
bf79451e | 5056 | static int ipw_compatible_rates(struct ipw_priv *priv, |
43f66a6c JK |
5057 | const struct ieee80211_network *network, |
5058 | struct ipw_supported_rates *rates) | |
5059 | { | |
5060 | int num_rates, i; | |
5061 | ||
5062 | memset(rates, 0, sizeof(*rates)); | |
0edd5b44 | 5063 | num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); |
43f66a6c JK |
5064 | rates->num_rates = 0; |
5065 | for (i = 0; i < num_rates; i++) { | |
a613bffd JK |
5066 | if (!ipw_is_rate_in_mask(priv, network->mode, |
5067 | network->rates[i])) { | |
5068 | ||
ea2b26e0 | 5069 | if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) { |
a613bffd JK |
5070 | IPW_DEBUG_SCAN("Adding masked mandatory " |
5071 | "rate %02X\n", | |
5072 | network->rates[i]); | |
5073 | rates->supported_rates[rates->num_rates++] = | |
5074 | network->rates[i]; | |
5075 | continue; | |
ea2b26e0 JK |
5076 | } |
5077 | ||
43f66a6c JK |
5078 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
5079 | network->rates[i], priv->rates_mask); | |
5080 | continue; | |
5081 | } | |
bf79451e | 5082 | |
43f66a6c JK |
5083 | rates->supported_rates[rates->num_rates++] = network->rates[i]; |
5084 | } | |
5085 | ||
a613bffd JK |
5086 | num_rates = min(network->rates_ex_len, |
5087 | (u8) (IPW_MAX_RATES - num_rates)); | |
43f66a6c | 5088 | for (i = 0; i < num_rates; i++) { |
a613bffd JK |
5089 | if (!ipw_is_rate_in_mask(priv, network->mode, |
5090 | network->rates_ex[i])) { | |
ea2b26e0 | 5091 | if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) { |
a613bffd JK |
5092 | IPW_DEBUG_SCAN("Adding masked mandatory " |
5093 | "rate %02X\n", | |
5094 | network->rates_ex[i]); | |
5095 | rates->supported_rates[rates->num_rates++] = | |
5096 | network->rates[i]; | |
5097 | continue; | |
ea2b26e0 JK |
5098 | } |
5099 | ||
43f66a6c JK |
5100 | IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", |
5101 | network->rates_ex[i], priv->rates_mask); | |
5102 | continue; | |
5103 | } | |
bf79451e | 5104 | |
0edd5b44 JG |
5105 | rates->supported_rates[rates->num_rates++] = |
5106 | network->rates_ex[i]; | |
43f66a6c JK |
5107 | } |
5108 | ||
ea2b26e0 | 5109 | return 1; |
43f66a6c JK |
5110 | } |
5111 | ||
858119e1 | 5112 | static void ipw_copy_rates(struct ipw_supported_rates *dest, |
43f66a6c JK |
5113 | const struct ipw_supported_rates *src) |
5114 | { | |
5115 | u8 i; | |
5116 | for (i = 0; i < src->num_rates; i++) | |
5117 | dest->supported_rates[i] = src->supported_rates[i]; | |
5118 | dest->num_rates = src->num_rates; | |
5119 | } | |
5120 | ||
5121 | /* TODO: Look at sniffed packets in the air to determine if the basic rate | |
5122 | * mask should ever be used -- right now all callers to add the scan rates are | |
5123 | * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */ | |
5124 | static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates, | |
0edd5b44 | 5125 | u8 modulation, u32 rate_mask) |
43f66a6c | 5126 | { |
bf79451e | 5127 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
0edd5b44 | 5128 | IEEE80211_BASIC_RATE_MASK : 0; |
bf79451e | 5129 | |
43f66a6c | 5130 | if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK) |
bf79451e | 5131 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5132 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB; |
43f66a6c JK |
5133 | |
5134 | if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK) | |
bf79451e | 5135 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5136 | IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB; |
43f66a6c JK |
5137 | |
5138 | if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK) | |
bf79451e | 5139 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5140 | IEEE80211_CCK_RATE_5MB; |
43f66a6c JK |
5141 | |
5142 | if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK) | |
bf79451e | 5143 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5144 | IEEE80211_CCK_RATE_11MB; |
43f66a6c JK |
5145 | } |
5146 | ||
5147 | static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates, | |
0edd5b44 | 5148 | u8 modulation, u32 rate_mask) |
43f66a6c | 5149 | { |
bf79451e | 5150 | u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ? |
0edd5b44 | 5151 | IEEE80211_BASIC_RATE_MASK : 0; |
43f66a6c JK |
5152 | |
5153 | if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK) | |
bf79451e | 5154 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5155 | IEEE80211_OFDM_RATE_6MB; |
43f66a6c JK |
5156 | |
5157 | if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK) | |
bf79451e | 5158 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5159 | IEEE80211_OFDM_RATE_9MB; |
43f66a6c JK |
5160 | |
5161 | if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK) | |
bf79451e | 5162 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5163 | IEEE80211_OFDM_RATE_12MB; |
43f66a6c JK |
5164 | |
5165 | if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK) | |
bf79451e | 5166 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5167 | IEEE80211_OFDM_RATE_18MB; |
43f66a6c JK |
5168 | |
5169 | if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK) | |
bf79451e | 5170 | rates->supported_rates[rates->num_rates++] = basic_mask | |
0edd5b44 | 5171 | IEEE80211_OFDM_RATE_24MB; |
43f66a6c JK |
5172 | |
5173 | if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK) | |
bf79451e | 5174 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5175 | IEEE80211_OFDM_RATE_36MB; |
43f66a6c JK |
5176 | |
5177 | if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK) | |
bf79451e | 5178 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5179 | IEEE80211_OFDM_RATE_48MB; |
43f66a6c JK |
5180 | |
5181 | if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK) | |
bf79451e | 5182 | rates->supported_rates[rates->num_rates++] = |
0edd5b44 | 5183 | IEEE80211_OFDM_RATE_54MB; |
43f66a6c JK |
5184 | } |
5185 | ||
5186 | struct ipw_network_match { | |
5187 | struct ieee80211_network *network; | |
5188 | struct ipw_supported_rates rates; | |
5189 | }; | |
5190 | ||
c848d0af JK |
5191 | static int ipw_find_adhoc_network(struct ipw_priv *priv, |
5192 | struct ipw_network_match *match, | |
5193 | struct ieee80211_network *network, | |
5194 | int roaming) | |
43f66a6c JK |
5195 | { |
5196 | struct ipw_supported_rates rates; | |
5197 | ||
5198 | /* Verify that this network's capability is compatible with the | |
5199 | * current mode (AdHoc or Infrastructure) */ | |
c848d0af | 5200 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC && |
43f66a6c | 5201 | !(network->capability & WLAN_CAPABILITY_IBSS))) { |
c848d0af | 5202 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to " |
bf79451e | 5203 | "capability mismatch.\n", |
43f66a6c JK |
5204 | escape_essid(network->ssid, network->ssid_len), |
5205 | MAC_ARG(network->bssid)); | |
5206 | return 0; | |
5207 | } | |
5208 | ||
5209 | /* If we do not have an ESSID for this AP, we can not associate with | |
5210 | * it */ | |
5211 | if (network->flags & NETWORK_EMPTY_ESSID) { | |
c848d0af | 5212 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5213 | "because of hidden ESSID.\n", |
5214 | escape_essid(network->ssid, network->ssid_len), | |
5215 | MAC_ARG(network->bssid)); | |
5216 | return 0; | |
5217 | } | |
bf79451e | 5218 | |
43f66a6c JK |
5219 | if (unlikely(roaming)) { |
5220 | /* If we are roaming, then ensure check if this is a valid | |
5221 | * network to try and roam to */ | |
5222 | if ((network->ssid_len != match->network->ssid_len) || | |
bf79451e | 5223 | memcmp(network->ssid, match->network->ssid, |
43f66a6c | 5224 | network->ssid_len)) { |
c848d0af | 5225 | IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded " |
43f66a6c | 5226 | "because of non-network ESSID.\n", |
bf79451e | 5227 | escape_essid(network->ssid, |
43f66a6c JK |
5228 | network->ssid_len), |
5229 | MAC_ARG(network->bssid)); | |
5230 | return 0; | |
5231 | } | |
5232 | } else { | |
bf79451e JG |
5233 | /* If an ESSID has been configured then compare the broadcast |
5234 | * ESSID to ours */ | |
5235 | if ((priv->config & CFG_STATIC_ESSID) && | |
43f66a6c | 5236 | ((network->ssid_len != priv->essid_len) || |
bf79451e | 5237 | memcmp(network->ssid, priv->essid, |
43f66a6c JK |
5238 | min(network->ssid_len, priv->essid_len)))) { |
5239 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | |
afbf30a2 | 5240 | |
0edd5b44 JG |
5241 | strncpy(escaped, |
5242 | escape_essid(network->ssid, network->ssid_len), | |
43f66a6c | 5243 | sizeof(escaped)); |
c848d0af | 5244 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
bf79451e | 5245 | "because of ESSID mismatch: '%s'.\n", |
43f66a6c | 5246 | escaped, MAC_ARG(network->bssid), |
0edd5b44 JG |
5247 | escape_essid(priv->essid, |
5248 | priv->essid_len)); | |
43f66a6c JK |
5249 | return 0; |
5250 | } | |
5251 | } | |
5252 | ||
5253 | /* If the old network rate is better than this one, don't bother | |
5254 | * testing everything else. */ | |
c848d0af JK |
5255 | |
5256 | if (network->time_stamp[0] < match->network->time_stamp[0]) { | |
afbf30a2 JK |
5257 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
5258 | "current network.\n", | |
43f66a6c | 5259 | escape_essid(match->network->ssid, |
afbf30a2 | 5260 | match->network->ssid_len)); |
43f66a6c | 5261 | return 0; |
c848d0af | 5262 | } else if (network->time_stamp[1] < match->network->time_stamp[1]) { |
afbf30a2 JK |
5263 | IPW_DEBUG_MERGE("Network '%s excluded because newer than " |
5264 | "current network.\n", | |
5265 | escape_essid(match->network->ssid, | |
5266 | match->network->ssid_len)); | |
43f66a6c JK |
5267 | return 0; |
5268 | } | |
5269 | ||
5270 | /* Now go through and see if the requested network is valid... */ | |
bf79451e | 5271 | if (priv->ieee->scan_age != 0 && |
c848d0af JK |
5272 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
5273 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " | |
c7b6a674 | 5274 | "because of age: %ums.\n", |
43f66a6c JK |
5275 | escape_essid(network->ssid, network->ssid_len), |
5276 | MAC_ARG(network->bssid), | |
2638bc39 ZY |
5277 | jiffies_to_msecs(jiffies - |
5278 | network->last_scanned)); | |
43f66a6c | 5279 | return 0; |
bf79451e | 5280 | } |
43f66a6c | 5281 | |
bf79451e | 5282 | if ((priv->config & CFG_STATIC_CHANNEL) && |
43f66a6c | 5283 | (network->channel != priv->channel)) { |
c848d0af | 5284 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5285 | "because of channel mismatch: %d != %d.\n", |
5286 | escape_essid(network->ssid, network->ssid_len), | |
5287 | MAC_ARG(network->bssid), | |
5288 | network->channel, priv->channel); | |
5289 | return 0; | |
5290 | } | |
bf79451e | 5291 | |
43f66a6c | 5292 | /* Verify privacy compatability */ |
bf79451e | 5293 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
43f66a6c | 5294 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
c848d0af | 5295 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5296 | "because of privacy mismatch: %s != %s.\n", |
5297 | escape_essid(network->ssid, network->ssid_len), | |
5298 | MAC_ARG(network->bssid), | |
afbf30a2 JK |
5299 | priv-> |
5300 | capability & CAP_PRIVACY_ON ? "on" : "off", | |
5301 | network-> | |
5302 | capability & WLAN_CAPABILITY_PRIVACY ? "on" : | |
5303 | "off"); | |
43f66a6c JK |
5304 | return 0; |
5305 | } | |
bf79451e | 5306 | |
c848d0af JK |
5307 | if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
5308 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " | |
5309 | "because of the same BSSID match: " MAC_FMT | |
5310 | ".\n", escape_essid(network->ssid, | |
5311 | network->ssid_len), | |
0edd5b44 | 5312 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
43f66a6c JK |
5313 | return 0; |
5314 | } | |
bf79451e | 5315 | |
43f66a6c JK |
5316 | /* Filter out any incompatible freq / mode combinations */ |
5317 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { | |
c848d0af | 5318 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5319 | "because of invalid frequency/mode " |
5320 | "combination.\n", | |
5321 | escape_essid(network->ssid, network->ssid_len), | |
5322 | MAC_ARG(network->bssid)); | |
5323 | return 0; | |
5324 | } | |
bf79451e | 5325 | |
c848d0af JK |
5326 | /* Ensure that the rates supported by the driver are compatible with |
5327 | * this AP, including verification of basic rates (mandatory) */ | |
5328 | if (!ipw_compatible_rates(priv, network, &rates)) { | |
5329 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " | |
5330 | "because configured rate mask excludes " | |
5331 | "AP mandatory rate.\n", | |
5332 | escape_essid(network->ssid, network->ssid_len), | |
5333 | MAC_ARG(network->bssid)); | |
5334 | return 0; | |
5335 | } | |
5336 | ||
43f66a6c | 5337 | if (rates.num_rates == 0) { |
c848d0af | 5338 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded " |
43f66a6c JK |
5339 | "because of no compatible rates.\n", |
5340 | escape_essid(network->ssid, network->ssid_len), | |
5341 | MAC_ARG(network->bssid)); | |
5342 | return 0; | |
5343 | } | |
bf79451e | 5344 | |
43f66a6c JK |
5345 | /* TODO: Perform any further minimal comparititive tests. We do not |
5346 | * want to put too much policy logic here; intelligent scan selection | |
5347 | * should occur within a generic IEEE 802.11 user space tool. */ | |
5348 | ||
5349 | /* Set up 'new' AP to this network */ | |
5350 | ipw_copy_rates(&match->rates, &rates); | |
5351 | match->network = network; | |
c848d0af | 5352 | IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n", |
43f66a6c JK |
5353 | escape_essid(network->ssid, network->ssid_len), |
5354 | MAC_ARG(network->bssid)); | |
5355 | ||
5356 | return 1; | |
5357 | } | |
5358 | ||
c848d0af | 5359 | static void ipw_merge_adhoc_network(void *data) |
43f66a6c | 5360 | { |
c848d0af JK |
5361 | struct ipw_priv *priv = data; |
5362 | struct ieee80211_network *network = NULL; | |
5363 | struct ipw_network_match match = { | |
5364 | .network = priv->assoc_network | |
5365 | }; | |
5366 | ||
afbf30a2 JK |
5367 | if ((priv->status & STATUS_ASSOCIATED) && |
5368 | (priv->ieee->iw_mode == IW_MODE_ADHOC)) { | |
c848d0af JK |
5369 | /* First pass through ROAM process -- look for a better |
5370 | * network */ | |
5371 | unsigned long flags; | |
5372 | ||
5373 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
5374 | list_for_each_entry(network, &priv->ieee->network_list, list) { | |
5375 | if (network != priv->assoc_network) | |
5376 | ipw_find_adhoc_network(priv, &match, network, | |
5377 | 1); | |
5378 | } | |
5379 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
5380 | ||
5381 | if (match.network == priv->assoc_network) { | |
5382 | IPW_DEBUG_MERGE("No better ADHOC in this network to " | |
5383 | "merge to.\n"); | |
5384 | return; | |
5385 | } | |
5386 | ||
4644151b | 5387 | mutex_lock(&priv->mutex); |
c848d0af JK |
5388 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) { |
5389 | IPW_DEBUG_MERGE("remove network %s\n", | |
5390 | escape_essid(priv->essid, | |
5391 | priv->essid_len)); | |
5392 | ipw_remove_current_network(priv); | |
43f66a6c | 5393 | } |
c848d0af JK |
5394 | |
5395 | ipw_disassociate(priv); | |
5396 | priv->assoc_network = match.network; | |
4644151b | 5397 | mutex_unlock(&priv->mutex); |
c848d0af | 5398 | return; |
43f66a6c | 5399 | } |
c848d0af | 5400 | } |
43f66a6c | 5401 | |
0edd5b44 JG |
5402 | static int ipw_best_network(struct ipw_priv *priv, |
5403 | struct ipw_network_match *match, | |
5404 | struct ieee80211_network *network, int roaming) | |
43f66a6c JK |
5405 | { |
5406 | struct ipw_supported_rates rates; | |
5407 | ||
5408 | /* Verify that this network's capability is compatible with the | |
5409 | * current mode (AdHoc or Infrastructure) */ | |
5410 | if ((priv->ieee->iw_mode == IW_MODE_INFRA && | |
2474385e | 5411 | !(network->capability & WLAN_CAPABILITY_ESS)) || |
43f66a6c JK |
5412 | (priv->ieee->iw_mode == IW_MODE_ADHOC && |
5413 | !(network->capability & WLAN_CAPABILITY_IBSS))) { | |
5414 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to " | |
bf79451e | 5415 | "capability mismatch.\n", |
43f66a6c JK |
5416 | escape_essid(network->ssid, network->ssid_len), |
5417 | MAC_ARG(network->bssid)); | |
5418 | return 0; | |
5419 | } | |
5420 | ||
5421 | /* If we do not have an ESSID for this AP, we can not associate with | |
5422 | * it */ | |
5423 | if (network->flags & NETWORK_EMPTY_ESSID) { | |
5424 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5425 | "because of hidden ESSID.\n", | |
5426 | escape_essid(network->ssid, network->ssid_len), | |
5427 | MAC_ARG(network->bssid)); | |
5428 | return 0; | |
5429 | } | |
bf79451e | 5430 | |
43f66a6c JK |
5431 | if (unlikely(roaming)) { |
5432 | /* If we are roaming, then ensure check if this is a valid | |
5433 | * network to try and roam to */ | |
5434 | if ((network->ssid_len != match->network->ssid_len) || | |
bf79451e | 5435 | memcmp(network->ssid, match->network->ssid, |
43f66a6c JK |
5436 | network->ssid_len)) { |
5437 | IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded " | |
5438 | "because of non-network ESSID.\n", | |
bf79451e | 5439 | escape_essid(network->ssid, |
43f66a6c JK |
5440 | network->ssid_len), |
5441 | MAC_ARG(network->bssid)); | |
5442 | return 0; | |
5443 | } | |
5444 | } else { | |
bf79451e JG |
5445 | /* If an ESSID has been configured then compare the broadcast |
5446 | * ESSID to ours */ | |
5447 | if ((priv->config & CFG_STATIC_ESSID) && | |
43f66a6c | 5448 | ((network->ssid_len != priv->essid_len) || |
bf79451e | 5449 | memcmp(network->ssid, priv->essid, |
43f66a6c JK |
5450 | min(network->ssid_len, priv->essid_len)))) { |
5451 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | |
0edd5b44 JG |
5452 | strncpy(escaped, |
5453 | escape_essid(network->ssid, network->ssid_len), | |
43f66a6c JK |
5454 | sizeof(escaped)); |
5455 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
bf79451e | 5456 | "because of ESSID mismatch: '%s'.\n", |
43f66a6c | 5457 | escaped, MAC_ARG(network->bssid), |
0edd5b44 JG |
5458 | escape_essid(priv->essid, |
5459 | priv->essid_len)); | |
43f66a6c JK |
5460 | return 0; |
5461 | } | |
5462 | } | |
5463 | ||
5464 | /* If the old network rate is better than this one, don't bother | |
5465 | * testing everything else. */ | |
0edd5b44 | 5466 | if (match->network && match->network->stats.rssi > network->stats.rssi) { |
43f66a6c | 5467 | char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
bf79451e JG |
5468 | strncpy(escaped, |
5469 | escape_essid(network->ssid, network->ssid_len), | |
43f66a6c JK |
5470 | sizeof(escaped)); |
5471 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because " | |
5472 | "'%s (" MAC_FMT ")' has a stronger signal.\n", | |
5473 | escaped, MAC_ARG(network->bssid), | |
5474 | escape_essid(match->network->ssid, | |
5475 | match->network->ssid_len), | |
5476 | MAC_ARG(match->network->bssid)); | |
5477 | return 0; | |
5478 | } | |
bf79451e | 5479 | |
43f66a6c JK |
5480 | /* If this network has already had an association attempt within the |
5481 | * last 3 seconds, do not try and associate again... */ | |
5482 | if (network->last_associate && | |
ea2b26e0 | 5483 | time_after(network->last_associate + (HZ * 3UL), jiffies)) { |
43f66a6c | 5484 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
c7b6a674 | 5485 | "because of storming (%ums since last " |
43f66a6c JK |
5486 | "assoc attempt).\n", |
5487 | escape_essid(network->ssid, network->ssid_len), | |
5488 | MAC_ARG(network->bssid), | |
2638bc39 ZY |
5489 | jiffies_to_msecs(jiffies - |
5490 | network->last_associate)); | |
43f66a6c JK |
5491 | return 0; |
5492 | } | |
5493 | ||
5494 | /* Now go through and see if the requested network is valid... */ | |
bf79451e | 5495 | if (priv->ieee->scan_age != 0 && |
ea2b26e0 | 5496 | time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) { |
43f66a6c | 5497 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
c7b6a674 | 5498 | "because of age: %ums.\n", |
43f66a6c JK |
5499 | escape_essid(network->ssid, network->ssid_len), |
5500 | MAC_ARG(network->bssid), | |
2638bc39 ZY |
5501 | jiffies_to_msecs(jiffies - |
5502 | network->last_scanned)); | |
43f66a6c | 5503 | return 0; |
bf79451e | 5504 | } |
43f66a6c | 5505 | |
bf79451e | 5506 | if ((priv->config & CFG_STATIC_CHANNEL) && |
43f66a6c JK |
5507 | (network->channel != priv->channel)) { |
5508 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5509 | "because of channel mismatch: %d != %d.\n", | |
5510 | escape_essid(network->ssid, network->ssid_len), | |
5511 | MAC_ARG(network->bssid), | |
5512 | network->channel, priv->channel); | |
5513 | return 0; | |
5514 | } | |
bf79451e | 5515 | |
43f66a6c | 5516 | /* Verify privacy compatability */ |
bf79451e | 5517 | if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) != |
43f66a6c JK |
5518 | ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) { |
5519 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5520 | "because of privacy mismatch: %s != %s.\n", | |
5521 | escape_essid(network->ssid, network->ssid_len), | |
5522 | MAC_ARG(network->bssid), | |
bf79451e | 5523 | priv->capability & CAP_PRIVACY_ON ? "on" : |
43f66a6c | 5524 | "off", |
bf79451e | 5525 | network->capability & |
0edd5b44 | 5526 | WLAN_CAPABILITY_PRIVACY ? "on" : "off"); |
43f66a6c JK |
5527 | return 0; |
5528 | } | |
bf79451e JG |
5529 | |
5530 | if ((priv->config & CFG_STATIC_BSSID) && | |
43f66a6c JK |
5531 | memcmp(network->bssid, priv->bssid, ETH_ALEN)) { |
5532 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5533 | "because of BSSID mismatch: " MAC_FMT ".\n", | |
5534 | escape_essid(network->ssid, network->ssid_len), | |
0edd5b44 | 5535 | MAC_ARG(network->bssid), MAC_ARG(priv->bssid)); |
43f66a6c JK |
5536 | return 0; |
5537 | } | |
bf79451e | 5538 | |
43f66a6c JK |
5539 | /* Filter out any incompatible freq / mode combinations */ |
5540 | if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) { | |
5541 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5542 | "because of invalid frequency/mode " | |
5543 | "combination.\n", | |
5544 | escape_essid(network->ssid, network->ssid_len), | |
5545 | MAC_ARG(network->bssid)); | |
5546 | return 0; | |
5547 | } | |
bf79451e | 5548 | |
1fe0adb4 | 5549 | /* Filter out invalid channel in current GEO */ |
1867b117 | 5550 | if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) { |
1fe0adb4 LH |
5551 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " |
5552 | "because of invalid channel in current GEO\n", | |
5553 | escape_essid(network->ssid, network->ssid_len), | |
5554 | MAC_ARG(network->bssid)); | |
5555 | return 0; | |
5556 | } | |
5557 | ||
ea2b26e0 JK |
5558 | /* Ensure that the rates supported by the driver are compatible with |
5559 | * this AP, including verification of basic rates (mandatory) */ | |
5560 | if (!ipw_compatible_rates(priv, network, &rates)) { | |
5561 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5562 | "because configured rate mask excludes " | |
5563 | "AP mandatory rate.\n", | |
5564 | escape_essid(network->ssid, network->ssid_len), | |
5565 | MAC_ARG(network->bssid)); | |
5566 | return 0; | |
5567 | } | |
5568 | ||
43f66a6c JK |
5569 | if (rates.num_rates == 0) { |
5570 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " | |
5571 | "because of no compatible rates.\n", | |
5572 | escape_essid(network->ssid, network->ssid_len), | |
5573 | MAC_ARG(network->bssid)); | |
5574 | return 0; | |
5575 | } | |
bf79451e | 5576 | |
43f66a6c JK |
5577 | /* TODO: Perform any further minimal comparititive tests. We do not |
5578 | * want to put too much policy logic here; intelligent scan selection | |
5579 | * should occur within a generic IEEE 802.11 user space tool. */ | |
5580 | ||
5581 | /* Set up 'new' AP to this network */ | |
5582 | ipw_copy_rates(&match->rates, &rates); | |
5583 | match->network = network; | |
5584 | ||
5585 | IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n", | |
5586 | escape_essid(network->ssid, network->ssid_len), | |
5587 | MAC_ARG(network->bssid)); | |
5588 | ||
5589 | return 1; | |
5590 | } | |
5591 | ||
bf79451e | 5592 | static void ipw_adhoc_create(struct ipw_priv *priv, |
0edd5b44 | 5593 | struct ieee80211_network *network) |
43f66a6c | 5594 | { |
1867b117 | 5595 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
afbf30a2 JK |
5596 | int i; |
5597 | ||
43f66a6c JK |
5598 | /* |
5599 | * For the purposes of scanning, we can set our wireless mode | |
5600 | * to trigger scans across combinations of bands, but when it | |
5601 | * comes to creating a new ad-hoc network, we have tell the FW | |
5602 | * exactly which band to use. | |
5603 | * | |
bf79451e | 5604 | * We also have the possibility of an invalid channel for the |
43f66a6c JK |
5605 | * chossen band. Attempting to create a new ad-hoc network |
5606 | * with an invalid channel for wireless mode will trigger a | |
5607 | * FW fatal error. | |
afbf30a2 | 5608 | * |
43f66a6c | 5609 | */ |
1867b117 | 5610 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
afbf30a2 JK |
5611 | case IEEE80211_52GHZ_BAND: |
5612 | network->mode = IEEE_A; | |
1867b117 | 5613 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
afbf30a2 JK |
5614 | if (i == -1) |
5615 | BUG(); | |
5616 | if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { | |
5617 | IPW_WARNING("Overriding invalid channel\n"); | |
5618 | priv->channel = geo->a[0].channel; | |
5619 | } | |
5620 | break; | |
5621 | ||
5622 | case IEEE80211_24GHZ_BAND: | |
5623 | if (priv->ieee->mode & IEEE_G) | |
5624 | network->mode = IEEE_G; | |
5625 | else | |
5626 | network->mode = IEEE_B; | |
1867b117 | 5627 | i = ieee80211_channel_to_index(priv->ieee, priv->channel); |
1fe0adb4 LH |
5628 | if (i == -1) |
5629 | BUG(); | |
5630 | if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) { | |
5631 | IPW_WARNING("Overriding invalid channel\n"); | |
5632 | priv->channel = geo->bg[0].channel; | |
5633 | } | |
afbf30a2 JK |
5634 | break; |
5635 | ||
5636 | default: | |
43f66a6c JK |
5637 | IPW_WARNING("Overriding invalid channel\n"); |
5638 | if (priv->ieee->mode & IEEE_A) { | |
5639 | network->mode = IEEE_A; | |
b095c381 | 5640 | priv->channel = geo->a[0].channel; |
43f66a6c JK |
5641 | } else if (priv->ieee->mode & IEEE_G) { |
5642 | network->mode = IEEE_G; | |
b095c381 | 5643 | priv->channel = geo->bg[0].channel; |
43f66a6c JK |
5644 | } else { |
5645 | network->mode = IEEE_B; | |
b095c381 | 5646 | priv->channel = geo->bg[0].channel; |
43f66a6c | 5647 | } |
afbf30a2 JK |
5648 | break; |
5649 | } | |
43f66a6c JK |
5650 | |
5651 | network->channel = priv->channel; | |
5652 | priv->config |= CFG_ADHOC_PERSIST; | |
5653 | ipw_create_bssid(priv, network->bssid); | |
5654 | network->ssid_len = priv->essid_len; | |
5655 | memcpy(network->ssid, priv->essid, priv->essid_len); | |
5656 | memset(&network->stats, 0, sizeof(network->stats)); | |
5657 | network->capability = WLAN_CAPABILITY_IBSS; | |
ea2b26e0 JK |
5658 | if (!(priv->config & CFG_PREAMBLE_LONG)) |
5659 | network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE; | |
43f66a6c JK |
5660 | if (priv->capability & CAP_PRIVACY_ON) |
5661 | network->capability |= WLAN_CAPABILITY_PRIVACY; | |
5662 | network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); | |
0edd5b44 | 5663 | memcpy(network->rates, priv->rates.supported_rates, network->rates_len); |
43f66a6c | 5664 | network->rates_ex_len = priv->rates.num_rates - network->rates_len; |
bf79451e | 5665 | memcpy(network->rates_ex, |
43f66a6c JK |
5666 | &priv->rates.supported_rates[network->rates_len], |
5667 | network->rates_ex_len); | |
5668 | network->last_scanned = 0; | |
5669 | network->flags = 0; | |
5670 | network->last_associate = 0; | |
5671 | network->time_stamp[0] = 0; | |
5672 | network->time_stamp[1] = 0; | |
0edd5b44 JG |
5673 | network->beacon_interval = 100; /* Default */ |
5674 | network->listen_interval = 10; /* Default */ | |
5675 | network->atim_window = 0; /* Default */ | |
43f66a6c JK |
5676 | network->wpa_ie_len = 0; |
5677 | network->rsn_ie_len = 0; | |
43f66a6c JK |
5678 | } |
5679 | ||
b095c381 JK |
5680 | static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index) |
5681 | { | |
0a7bcf26 | 5682 | struct ipw_tgi_tx_key key; |
b095c381 JK |
5683 | |
5684 | if (!(priv->ieee->sec.flags & (1 << index))) | |
5685 | return; | |
5686 | ||
0a7bcf26 ZY |
5687 | key.key_id = index; |
5688 | memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH); | |
5689 | key.security_type = type; | |
5690 | key.station_index = 0; /* always 0 for BSS */ | |
5691 | key.flags = 0; | |
b095c381 | 5692 | /* 0 for new key; previous value of counter (after fatal error) */ |
0a7bcf26 ZY |
5693 | key.tx_counter[0] = 0; |
5694 | key.tx_counter[1] = 0; | |
b095c381 | 5695 | |
0a7bcf26 | 5696 | ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key); |
b095c381 JK |
5697 | } |
5698 | ||
5699 | static void ipw_send_wep_keys(struct ipw_priv *priv, int type) | |
43f66a6c | 5700 | { |
0a7bcf26 | 5701 | struct ipw_wep_key key; |
43f66a6c | 5702 | int i; |
43f66a6c | 5703 | |
0a7bcf26 ZY |
5704 | key.cmd_id = DINO_CMD_WEP_KEY; |
5705 | key.seq_num = 0; | |
43f66a6c | 5706 | |
b095c381 JK |
5707 | /* Note: AES keys cannot be set for multiple times. |
5708 | * Only set it at the first time. */ | |
bf79451e | 5709 | for (i = 0; i < 4; i++) { |
0a7bcf26 | 5710 | key.key_index = i | type; |
b095c381 | 5711 | if (!(priv->ieee->sec.flags & (1 << i))) { |
0a7bcf26 | 5712 | key.key_size = 0; |
b095c381 | 5713 | continue; |
43f66a6c JK |
5714 | } |
5715 | ||
0a7bcf26 ZY |
5716 | key.key_size = priv->ieee->sec.key_sizes[i]; |
5717 | memcpy(key.key, priv->ieee->sec.keys[i], key.key_size); | |
b095c381 | 5718 | |
0a7bcf26 | 5719 | ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key); |
bf79451e | 5720 | } |
43f66a6c JK |
5721 | } |
5722 | ||
1fbfea54 | 5723 | static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level) |
43f66a6c | 5724 | { |
1fbfea54 | 5725 | if (priv->ieee->host_encrypt) |
43f66a6c | 5726 | return; |
43f66a6c | 5727 | |
1fbfea54 ZY |
5728 | switch (level) { |
5729 | case SEC_LEVEL_3: | |
5730 | priv->sys_config.disable_unicast_decryption = 0; | |
5731 | priv->ieee->host_decrypt = 0; | |
5732 | break; | |
5733 | case SEC_LEVEL_2: | |
5734 | priv->sys_config.disable_unicast_decryption = 1; | |
5735 | priv->ieee->host_decrypt = 1; | |
5736 | break; | |
5737 | case SEC_LEVEL_1: | |
5738 | priv->sys_config.disable_unicast_decryption = 0; | |
5739 | priv->ieee->host_decrypt = 0; | |
5740 | break; | |
5741 | case SEC_LEVEL_0: | |
5742 | priv->sys_config.disable_unicast_decryption = 1; | |
5743 | break; | |
5744 | default: | |
5745 | break; | |
5746 | } | |
5747 | } | |
5748 | ||
5749 | static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level) | |
5750 | { | |
5751 | if (priv->ieee->host_encrypt) | |
5752 | return; | |
5753 | ||
5754 | switch (level) { | |
5755 | case SEC_LEVEL_3: | |
5756 | priv->sys_config.disable_multicast_decryption = 0; | |
5757 | break; | |
5758 | case SEC_LEVEL_2: | |
5759 | priv->sys_config.disable_multicast_decryption = 1; | |
5760 | break; | |
5761 | case SEC_LEVEL_1: | |
5762 | priv->sys_config.disable_multicast_decryption = 0; | |
5763 | break; | |
5764 | case SEC_LEVEL_0: | |
5765 | priv->sys_config.disable_multicast_decryption = 1; | |
5766 | break; | |
5767 | default: | |
5768 | break; | |
5769 | } | |
5770 | } | |
5771 | ||
b095c381 JK |
5772 | static void ipw_set_hwcrypto_keys(struct ipw_priv *priv) |
5773 | { | |
5774 | switch (priv->ieee->sec.level) { | |
5775 | case SEC_LEVEL_3: | |
d8bad6df ZY |
5776 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
5777 | ipw_send_tgi_tx_key(priv, | |
5778 | DCT_FLAG_EXT_SECURITY_CCM, | |
5779 | priv->ieee->sec.active_key); | |
afbf30a2 | 5780 | |
567deaf6 HL |
5781 | if (!priv->ieee->host_mc_decrypt) |
5782 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM); | |
b095c381 JK |
5783 | break; |
5784 | case SEC_LEVEL_2: | |
d8bad6df ZY |
5785 | if (priv->ieee->sec.flags & SEC_ACTIVE_KEY) |
5786 | ipw_send_tgi_tx_key(priv, | |
5787 | DCT_FLAG_EXT_SECURITY_TKIP, | |
5788 | priv->ieee->sec.active_key); | |
b095c381 JK |
5789 | break; |
5790 | case SEC_LEVEL_1: | |
5791 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); | |
29cb843e HL |
5792 | ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level); |
5793 | ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level); | |
b095c381 JK |
5794 | break; |
5795 | case SEC_LEVEL_0: | |
5796 | default: | |
5797 | break; | |
5798 | } | |
5799 | } | |
5800 | ||
43f66a6c JK |
5801 | static void ipw_adhoc_check(void *data) |
5802 | { | |
5803 | struct ipw_priv *priv = data; | |
bf79451e | 5804 | |
afbf30a2 | 5805 | if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold && |
43f66a6c | 5806 | !(priv->config & CFG_ADHOC_PERSIST)) { |
afbf30a2 JK |
5807 | IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | |
5808 | IPW_DL_STATE | IPW_DL_ASSOC, | |
5809 | "Missed beacon: %d - disassociate\n", | |
5810 | priv->missed_adhoc_beacons); | |
43f66a6c JK |
5811 | ipw_remove_current_network(priv); |
5812 | ipw_disassociate(priv); | |
5813 | return; | |
5814 | } | |
5815 | ||
bf79451e | 5816 | queue_delayed_work(priv->workqueue, &priv->adhoc_check, |
43f66a6c JK |
5817 | priv->assoc_request.beacon_interval); |
5818 | } | |
5819 | ||
c848d0af JK |
5820 | static void ipw_bg_adhoc_check(void *data) |
5821 | { | |
5822 | struct ipw_priv *priv = data; | |
4644151b | 5823 | mutex_lock(&priv->mutex); |
c848d0af | 5824 | ipw_adhoc_check(data); |
4644151b | 5825 | mutex_unlock(&priv->mutex); |
c848d0af JK |
5826 | } |
5827 | ||
0f52bf90 | 5828 | #ifdef CONFIG_IPW2200_DEBUG |
43f66a6c JK |
5829 | static void ipw_debug_config(struct ipw_priv *priv) |
5830 | { | |
5831 | IPW_DEBUG_INFO("Scan completed, no valid APs matched " | |
5832 | "[CFG 0x%08X]\n", priv->config); | |
5833 | if (priv->config & CFG_STATIC_CHANNEL) | |
0edd5b44 | 5834 | IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel); |
43f66a6c JK |
5835 | else |
5836 | IPW_DEBUG_INFO("Channel unlocked.\n"); | |
5837 | if (priv->config & CFG_STATIC_ESSID) | |
bf79451e | 5838 | IPW_DEBUG_INFO("ESSID locked to '%s'\n", |
0edd5b44 | 5839 | escape_essid(priv->essid, priv->essid_len)); |
43f66a6c JK |
5840 | else |
5841 | IPW_DEBUG_INFO("ESSID unlocked.\n"); | |
5842 | if (priv->config & CFG_STATIC_BSSID) | |
ea2b26e0 JK |
5843 | IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n", |
5844 | MAC_ARG(priv->bssid)); | |
43f66a6c JK |
5845 | else |
5846 | IPW_DEBUG_INFO("BSSID unlocked.\n"); | |
5847 | if (priv->capability & CAP_PRIVACY_ON) | |
5848 | IPW_DEBUG_INFO("PRIVACY on\n"); | |
5849 | else | |
5850 | IPW_DEBUG_INFO("PRIVACY off\n"); | |
5851 | IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask); | |
5852 | } | |
5853 | #else | |
8d45ff7d | 5854 | #define ipw_debug_config(x) do {} while (0) |
43f66a6c JK |
5855 | #endif |
5856 | ||
858119e1 | 5857 | static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode) |
43f66a6c JK |
5858 | { |
5859 | /* TODO: Verify that this works... */ | |
5860 | struct ipw_fixed_rate fr = { | |
5861 | .tx_rates = priv->rates_mask | |
5862 | }; | |
5863 | u32 reg; | |
5864 | u16 mask = 0; | |
5865 | ||
bf79451e | 5866 | /* Identify 'current FW band' and match it with the fixed |
43f66a6c | 5867 | * Tx rates */ |
bf79451e | 5868 | |
43f66a6c | 5869 | switch (priv->ieee->freq_band) { |
0edd5b44 | 5870 | case IEEE80211_52GHZ_BAND: /* A only */ |
43f66a6c JK |
5871 | /* IEEE_A */ |
5872 | if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { | |
5873 | /* Invalid fixed rate mask */ | |
ea2b26e0 JK |
5874 | IPW_DEBUG_WX |
5875 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | |
43f66a6c JK |
5876 | fr.tx_rates = 0; |
5877 | break; | |
5878 | } | |
bf79451e | 5879 | |
43f66a6c JK |
5880 | fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A; |
5881 | break; | |
5882 | ||
0edd5b44 | 5883 | default: /* 2.4Ghz or Mixed */ |
43f66a6c | 5884 | /* IEEE_B */ |
b095c381 | 5885 | if (mode == IEEE_B) { |
43f66a6c JK |
5886 | if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { |
5887 | /* Invalid fixed rate mask */ | |
ea2b26e0 JK |
5888 | IPW_DEBUG_WX |
5889 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | |
43f66a6c JK |
5890 | fr.tx_rates = 0; |
5891 | } | |
5892 | break; | |
bf79451e | 5893 | } |
43f66a6c JK |
5894 | |
5895 | /* IEEE_G */ | |
5896 | if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | | |
5897 | IEEE80211_OFDM_RATES_MASK)) { | |
5898 | /* Invalid fixed rate mask */ | |
ea2b26e0 JK |
5899 | IPW_DEBUG_WX |
5900 | ("invalid fixed rate mask in ipw_set_fixed_rate\n"); | |
43f66a6c JK |
5901 | fr.tx_rates = 0; |
5902 | break; | |
5903 | } | |
bf79451e | 5904 | |
43f66a6c JK |
5905 | if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) { |
5906 | mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1); | |
5907 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK; | |
5908 | } | |
bf79451e | 5909 | |
43f66a6c JK |
5910 | if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) { |
5911 | mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1); | |
5912 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK; | |
5913 | } | |
bf79451e | 5914 | |
43f66a6c JK |
5915 | if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) { |
5916 | mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1); | |
5917 | fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK; | |
5918 | } | |
bf79451e | 5919 | |
43f66a6c JK |
5920 | fr.tx_rates |= mask; |
5921 | break; | |
5922 | } | |
5923 | ||
5924 | reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE); | |
0edd5b44 | 5925 | ipw_write_reg32(priv, reg, *(u32 *) & fr); |
43f66a6c JK |
5926 | } |
5927 | ||
ea2b26e0 | 5928 | static void ipw_abort_scan(struct ipw_priv *priv) |
43f66a6c JK |
5929 | { |
5930 | int err; | |
5931 | ||
ea2b26e0 JK |
5932 | if (priv->status & STATUS_SCAN_ABORTING) { |
5933 | IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); | |
5934 | return; | |
5935 | } | |
5936 | priv->status |= STATUS_SCAN_ABORTING; | |
43f66a6c | 5937 | |
ea2b26e0 JK |
5938 | err = ipw_send_scan_abort(priv); |
5939 | if (err) | |
5940 | IPW_DEBUG_HC("Request to abort scan failed.\n"); | |
5941 | } | |
5942 | ||
afbf30a2 JK |
5943 | static void ipw_add_scan_channels(struct ipw_priv *priv, |
5944 | struct ipw_scan_request_ext *scan, | |
5945 | int scan_type) | |
ea2b26e0 | 5946 | { |
ea2b26e0 | 5947 | int channel_index = 0; |
b095c381 | 5948 | const struct ieee80211_geo *geo; |
afbf30a2 | 5949 | int i; |
b095c381 | 5950 | |
1867b117 | 5951 | geo = ieee80211_get_geo(priv->ieee); |
43f66a6c | 5952 | |
afbf30a2 JK |
5953 | if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { |
5954 | int start = channel_index; | |
5955 | for (i = 0; i < geo->a_channels; i++) { | |
5956 | if ((priv->status & STATUS_ASSOCIATED) && | |
5957 | geo->a[i].channel == priv->channel) | |
5958 | continue; | |
5959 | channel_index++; | |
5960 | scan->channels_list[channel_index] = geo->a[i].channel; | |
1fe0adb4 LH |
5961 | ipw_set_scan_type(scan, channel_index, |
5962 | geo->a[i]. | |
5963 | flags & IEEE80211_CH_PASSIVE_ONLY ? | |
5964 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN : | |
5965 | scan_type); | |
afbf30a2 JK |
5966 | } |
5967 | ||
5968 | if (start != channel_index) { | |
5969 | scan->channels_list[start] = (u8) (IPW_A_MODE << 6) | | |
5970 | (channel_index - start); | |
5971 | channel_index++; | |
5972 | } | |
5973 | } | |
5974 | ||
5975 | if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { | |
5976 | int start = channel_index; | |
5977 | if (priv->config & CFG_SPEED_SCAN) { | |
1fe0adb4 | 5978 | int index; |
afbf30a2 JK |
5979 | u8 channels[IEEE80211_24GHZ_CHANNELS] = { |
5980 | /* nop out the list */ | |
5981 | [0] = 0 | |
5982 | }; | |
5983 | ||
5984 | u8 channel; | |
5985 | while (channel_index < IPW_SCAN_CHANNELS) { | |
5986 | channel = | |
5987 | priv->speed_scan[priv->speed_scan_pos]; | |
5988 | if (channel == 0) { | |
5989 | priv->speed_scan_pos = 0; | |
5990 | channel = priv->speed_scan[0]; | |
5991 | } | |
5992 | if ((priv->status & STATUS_ASSOCIATED) && | |
5993 | channel == priv->channel) { | |
5994 | priv->speed_scan_pos++; | |
5995 | continue; | |
5996 | } | |
5997 | ||
5998 | /* If this channel has already been | |
5999 | * added in scan, break from loop | |
6000 | * and this will be the first channel | |
6001 | * in the next scan. | |
6002 | */ | |
6003 | if (channels[channel - 1] != 0) | |
6004 | break; | |
6005 | ||
6006 | channels[channel - 1] = 1; | |
6007 | priv->speed_scan_pos++; | |
6008 | channel_index++; | |
6009 | scan->channels_list[channel_index] = channel; | |
1fe0adb4 | 6010 | index = |
1867b117 | 6011 | ieee80211_channel_to_index(priv->ieee, channel); |
afbf30a2 | 6012 | ipw_set_scan_type(scan, channel_index, |
1fe0adb4 LH |
6013 | geo->bg[index]. |
6014 | flags & | |
6015 | IEEE80211_CH_PASSIVE_ONLY ? | |
6016 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN | |
6017 | : scan_type); | |
afbf30a2 JK |
6018 | } |
6019 | } else { | |
6020 | for (i = 0; i < geo->bg_channels; i++) { | |
6021 | if ((priv->status & STATUS_ASSOCIATED) && | |
6022 | geo->bg[i].channel == priv->channel) | |
6023 | continue; | |
6024 | channel_index++; | |
6025 | scan->channels_list[channel_index] = | |
6026 | geo->bg[i].channel; | |
6027 | ipw_set_scan_type(scan, channel_index, | |
1fe0adb4 LH |
6028 | geo->bg[i]. |
6029 | flags & | |
6030 | IEEE80211_CH_PASSIVE_ONLY ? | |
6031 | IPW_SCAN_PASSIVE_FULL_DWELL_SCAN | |
6032 | : scan_type); | |
afbf30a2 JK |
6033 | } |
6034 | } | |
6035 | ||
6036 | if (start != channel_index) { | |
6037 | scan->channels_list[start] = (u8) (IPW_B_MODE << 6) | | |
6038 | (channel_index - start); | |
6039 | } | |
6040 | } | |
6041 | } | |
6042 | ||
6043 | static int ipw_request_scan(struct ipw_priv *priv) | |
6044 | { | |
6045 | struct ipw_scan_request_ext scan; | |
6046 | int err = 0, scan_type; | |
6047 | ||
6048 | if (!(priv->status & STATUS_INIT) || | |
6049 | (priv->status & STATUS_EXIT_PENDING)) | |
6050 | return 0; | |
6051 | ||
4644151b | 6052 | mutex_lock(&priv->mutex); |
afbf30a2 | 6053 | |
ea2b26e0 | 6054 | if (priv->status & STATUS_SCANNING) { |
a613bffd | 6055 | IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n"); |
ea2b26e0 | 6056 | priv->status |= STATUS_SCAN_PENDING; |
b095c381 | 6057 | goto done; |
ea2b26e0 | 6058 | } |
43f66a6c | 6059 | |
afbf30a2 JK |
6060 | if (!(priv->status & STATUS_SCAN_FORCED) && |
6061 | priv->status & STATUS_SCAN_ABORTING) { | |
ea2b26e0 JK |
6062 | IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
6063 | priv->status |= STATUS_SCAN_PENDING; | |
b095c381 | 6064 | goto done; |
43f66a6c JK |
6065 | } |
6066 | ||
ea2b26e0 JK |
6067 | if (priv->status & STATUS_RF_KILL_MASK) { |
6068 | IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n"); | |
6069 | priv->status |= STATUS_SCAN_PENDING; | |
b095c381 | 6070 | goto done; |
ea2b26e0 | 6071 | } |
43f66a6c | 6072 | |
ea2b26e0 | 6073 | memset(&scan, 0, sizeof(scan)); |
43f66a6c | 6074 | |
b095c381 JK |
6075 | if (priv->config & CFG_SPEED_SCAN) |
6076 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | |
6077 | cpu_to_le16(30); | |
6078 | else | |
6079 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | |
6080 | cpu_to_le16(20); | |
6081 | ||
a613bffd JK |
6082 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = |
6083 | cpu_to_le16(20); | |
1fe0adb4 | 6084 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120); |
43f66a6c | 6085 | |
a613bffd | 6086 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); |
43f66a6c | 6087 | |
b095c381 | 6088 | #ifdef CONFIG_IPW2200_MONITOR |
ea2b26e0 | 6089 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
afbf30a2 | 6090 | u8 channel; |
b095c381 | 6091 | u8 band = 0; |
43f66a6c | 6092 | |
1867b117 | 6093 | switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) { |
b095c381 | 6094 | case IEEE80211_52GHZ_BAND: |
ea2b26e0 | 6095 | band = (u8) (IPW_A_MODE << 6) | 1; |
b095c381 JK |
6096 | channel = priv->channel; |
6097 | break; | |
ea2b26e0 | 6098 | |
b095c381 | 6099 | case IEEE80211_24GHZ_BAND: |
ea2b26e0 | 6100 | band = (u8) (IPW_B_MODE << 6) | 1; |
b095c381 JK |
6101 | channel = priv->channel; |
6102 | break; | |
ea2b26e0 | 6103 | |
b095c381 | 6104 | default: |
ea2b26e0 JK |
6105 | band = (u8) (IPW_B_MODE << 6) | 1; |
6106 | channel = 9; | |
b095c381 | 6107 | break; |
ea2b26e0 JK |
6108 | } |
6109 | ||
b095c381 JK |
6110 | scan.channels_list[0] = band; |
6111 | scan.channels_list[1] = channel; | |
6112 | ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN); | |
ea2b26e0 | 6113 | |
b095c381 JK |
6114 | /* NOTE: The card will sit on this channel for this time |
6115 | * period. Scan aborts are timing sensitive and frequently | |
6116 | * result in firmware restarts. As such, it is best to | |
6117 | * set a small dwell_time here and just keep re-issuing | |
6118 | * scans. Otherwise fast channel hopping will not actually | |
6119 | * hop channels. | |
6120 | * | |
6121 | * TODO: Move SPEED SCAN support to all modes and bands */ | |
a613bffd JK |
6122 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = |
6123 | cpu_to_le16(2000); | |
43f66a6c | 6124 | } else { |
b095c381 JK |
6125 | #endif /* CONFIG_IPW2200_MONITOR */ |
6126 | /* If we are roaming, then make this a directed scan for the | |
6127 | * current network. Otherwise, ensure that every other scan | |
6128 | * is a fast channel hop scan */ | |
6129 | if ((priv->status & STATUS_ROAMING) | |
6130 | || (!(priv->status & STATUS_ASSOCIATED) | |
6131 | && (priv->config & CFG_STATIC_ESSID) | |
6132 | && (le32_to_cpu(scan.full_scan_index) % 2))) { | |
ea2b26e0 JK |
6133 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
6134 | if (err) { | |
b095c381 JK |
6135 | IPW_DEBUG_HC("Attempt to send SSID command " |
6136 | "failed.\n"); | |
6137 | goto done; | |
ea2b26e0 | 6138 | } |
43f66a6c | 6139 | |
ea2b26e0 | 6140 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; |
afbf30a2 | 6141 | } else |
ea2b26e0 | 6142 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; |
ea2b26e0 | 6143 | |
afbf30a2 | 6144 | ipw_add_scan_channels(priv, &scan, scan_type); |
b095c381 | 6145 | #ifdef CONFIG_IPW2200_MONITOR |
43f66a6c | 6146 | } |
ea2b26e0 | 6147 | #endif |
bf79451e | 6148 | |
ea2b26e0 | 6149 | err = ipw_send_scan_request_ext(priv, &scan); |
43f66a6c | 6150 | if (err) { |
ea2b26e0 | 6151 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); |
b095c381 | 6152 | goto done; |
43f66a6c JK |
6153 | } |
6154 | ||
ea2b26e0 JK |
6155 | priv->status |= STATUS_SCANNING; |
6156 | priv->status &= ~STATUS_SCAN_PENDING; | |
afbf30a2 JK |
6157 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
6158 | IPW_SCAN_CHECK_WATCHDOG); | |
b095c381 | 6159 | done: |
4644151b | 6160 | mutex_unlock(&priv->mutex); |
b095c381 | 6161 | return err; |
c848d0af JK |
6162 | } |
6163 | ||
6164 | static void ipw_bg_abort_scan(void *data) | |
6165 | { | |
6166 | struct ipw_priv *priv = data; | |
4644151b | 6167 | mutex_lock(&priv->mutex); |
c848d0af | 6168 | ipw_abort_scan(data); |
4644151b | 6169 | mutex_unlock(&priv->mutex); |
c848d0af JK |
6170 | } |
6171 | ||
ea2b26e0 JK |
6172 | static int ipw_wpa_enable(struct ipw_priv *priv, int value) |
6173 | { | |
b095c381 JK |
6174 | /* This is called when wpa_supplicant loads and closes the driver |
6175 | * interface. */ | |
cdd1fa1e | 6176 | priv->ieee->wpa_enabled = value; |
b095c381 | 6177 | return 0; |
ea2b26e0 JK |
6178 | } |
6179 | ||
ea2b26e0 JK |
6180 | static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value) |
6181 | { | |
6182 | struct ieee80211_device *ieee = priv->ieee; | |
6183 | struct ieee80211_security sec = { | |
6184 | .flags = SEC_AUTH_MODE, | |
6185 | }; | |
6186 | int ret = 0; | |
6187 | ||
afbf30a2 | 6188 | if (value & IW_AUTH_ALG_SHARED_KEY) { |
ea2b26e0 JK |
6189 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
6190 | ieee->open_wep = 0; | |
afbf30a2 | 6191 | } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) { |
ea2b26e0 JK |
6192 | sec.auth_mode = WLAN_AUTH_OPEN; |
6193 | ieee->open_wep = 1; | |
3e234b4e ZY |
6194 | } else if (value & IW_AUTH_ALG_LEAP) { |
6195 | sec.auth_mode = WLAN_AUTH_LEAP; | |
6196 | ieee->open_wep = 1; | |
afbf30a2 JK |
6197 | } else |
6198 | return -EINVAL; | |
ea2b26e0 JK |
6199 | |
6200 | if (ieee->set_security) | |
6201 | ieee->set_security(ieee->dev, &sec); | |
6202 | else | |
6203 | ret = -EOPNOTSUPP; | |
6204 | ||
6205 | return ret; | |
6206 | } | |
6207 | ||
a73e22b2 AB |
6208 | static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, |
6209 | int wpa_ie_len) | |
afbf30a2 JK |
6210 | { |
6211 | /* make sure WPA is enabled */ | |
6212 | ipw_wpa_enable(priv, 1); | |
6213 | ||
6214 | ipw_disassociate(priv); | |
6215 | } | |
6216 | ||
6217 | static int ipw_set_rsn_capa(struct ipw_priv *priv, | |
6218 | char *capabilities, int length) | |
6219 | { | |
afbf30a2 JK |
6220 | IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n"); |
6221 | ||
0a7bcf26 | 6222 | return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length, |
2638bc39 | 6223 | capabilities); |
afbf30a2 JK |
6224 | } |
6225 | ||
b095c381 | 6226 | /* |
afbf30a2 JK |
6227 | * WE-18 support |
6228 | */ | |
6229 | ||
6230 | /* SIOCSIWGENIE */ | |
6231 | static int ipw_wx_set_genie(struct net_device *dev, | |
6232 | struct iw_request_info *info, | |
6233 | union iwreq_data *wrqu, char *extra) | |
ea2b26e0 | 6234 | { |
afbf30a2 JK |
6235 | struct ipw_priv *priv = ieee80211_priv(dev); |
6236 | struct ieee80211_device *ieee = priv->ieee; | |
6237 | u8 *buf; | |
6238 | int err = 0; | |
ea2b26e0 | 6239 | |
afbf30a2 JK |
6240 | if (wrqu->data.length > MAX_WPA_IE_LEN || |
6241 | (wrqu->data.length && extra == NULL)) | |
6242 | return -EINVAL; | |
ea2b26e0 | 6243 | |
4644151b | 6244 | //mutex_lock(&priv->mutex); |
afbf30a2 JK |
6245 | |
6246 | //if (!ieee->wpa_enabled) { | |
6247 | // err = -EOPNOTSUPP; | |
6248 | // goto out; | |
6249 | //} | |
6250 | ||
6251 | if (wrqu->data.length) { | |
6252 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); | |
6253 | if (buf == NULL) { | |
6254 | err = -ENOMEM; | |
6255 | goto out; | |
6256 | } | |
6257 | ||
6258 | memcpy(buf, extra, wrqu->data.length); | |
6259 | kfree(ieee->wpa_ie); | |
6260 | ieee->wpa_ie = buf; | |
6261 | ieee->wpa_ie_len = wrqu->data.length; | |
b095c381 | 6262 | } else { |
afbf30a2 JK |
6263 | kfree(ieee->wpa_ie); |
6264 | ieee->wpa_ie = NULL; | |
6265 | ieee->wpa_ie_len = 0; | |
ea2b26e0 | 6266 | } |
afbf30a2 JK |
6267 | |
6268 | ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len); | |
6269 | out: | |
4644151b | 6270 | //mutex_unlock(&priv->mutex); |
afbf30a2 JK |
6271 | return err; |
6272 | } | |
6273 | ||
6274 | /* SIOCGIWGENIE */ | |
6275 | static int ipw_wx_get_genie(struct net_device *dev, | |
6276 | struct iw_request_info *info, | |
6277 | union iwreq_data *wrqu, char *extra) | |
6278 | { | |
6279 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6280 | struct ieee80211_device *ieee = priv->ieee; | |
6281 | int err = 0; | |
6282 | ||
4644151b | 6283 | //mutex_lock(&priv->mutex); |
afbf30a2 JK |
6284 | |
6285 | //if (!ieee->wpa_enabled) { | |
6286 | // err = -EOPNOTSUPP; | |
6287 | // goto out; | |
6288 | //} | |
6289 | ||
6290 | if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) { | |
6291 | wrqu->data.length = 0; | |
6292 | goto out; | |
6293 | } | |
6294 | ||
6295 | if (wrqu->data.length < ieee->wpa_ie_len) { | |
6296 | err = -E2BIG; | |
6297 | goto out; | |
6298 | } | |
6299 | ||
6300 | wrqu->data.length = ieee->wpa_ie_len; | |
6301 | memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len); | |
6302 | ||
6303 | out: | |
4644151b | 6304 | //mutex_unlock(&priv->mutex); |
afbf30a2 JK |
6305 | return err; |
6306 | } | |
6307 | ||
1fbfea54 ZY |
6308 | static int wext_cipher2level(int cipher) |
6309 | { | |
6310 | switch (cipher) { | |
6311 | case IW_AUTH_CIPHER_NONE: | |
6312 | return SEC_LEVEL_0; | |
6313 | case IW_AUTH_CIPHER_WEP40: | |
6314 | case IW_AUTH_CIPHER_WEP104: | |
6315 | return SEC_LEVEL_1; | |
6316 | case IW_AUTH_CIPHER_TKIP: | |
6317 | return SEC_LEVEL_2; | |
6318 | case IW_AUTH_CIPHER_CCMP: | |
6319 | return SEC_LEVEL_3; | |
6320 | default: | |
6321 | return -1; | |
6322 | } | |
6323 | } | |
6324 | ||
afbf30a2 JK |
6325 | /* SIOCSIWAUTH */ |
6326 | static int ipw_wx_set_auth(struct net_device *dev, | |
6327 | struct iw_request_info *info, | |
6328 | union iwreq_data *wrqu, char *extra) | |
6329 | { | |
6330 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6331 | struct ieee80211_device *ieee = priv->ieee; | |
6332 | struct iw_param *param = &wrqu->param; | |
6333 | struct ieee80211_crypt_data *crypt; | |
6334 | unsigned long flags; | |
6335 | int ret = 0; | |
6336 | ||
6337 | switch (param->flags & IW_AUTH_INDEX) { | |
6338 | case IW_AUTH_WPA_VERSION: | |
1fbfea54 | 6339 | break; |
afbf30a2 | 6340 | case IW_AUTH_CIPHER_PAIRWISE: |
1fbfea54 ZY |
6341 | ipw_set_hw_decrypt_unicast(priv, |
6342 | wext_cipher2level(param->value)); | |
6343 | break; | |
afbf30a2 | 6344 | case IW_AUTH_CIPHER_GROUP: |
1fbfea54 ZY |
6345 | ipw_set_hw_decrypt_multicast(priv, |
6346 | wext_cipher2level(param->value)); | |
6347 | break; | |
afbf30a2 JK |
6348 | case IW_AUTH_KEY_MGMT: |
6349 | /* | |
6350 | * ipw2200 does not use these parameters | |
6351 | */ | |
6352 | break; | |
6353 | ||
6354 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
6355 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; | |
991d1cc5 | 6356 | if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) |
afbf30a2 | 6357 | break; |
afbf30a2 JK |
6358 | |
6359 | flags = crypt->ops->get_flags(crypt->priv); | |
6360 | ||
6361 | if (param->value) | |
6362 | flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | |
6363 | else | |
6364 | flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES; | |
6365 | ||
6366 | crypt->ops->set_flags(flags, crypt->priv); | |
6367 | ||
6368 | break; | |
6369 | ||
6370 | case IW_AUTH_DROP_UNENCRYPTED:{ | |
6371 | /* HACK: | |
6372 | * | |
6373 | * wpa_supplicant calls set_wpa_enabled when the driver | |
6374 | * is loaded and unloaded, regardless of if WPA is being | |
6375 | * used. No other calls are made which can be used to | |
6376 | * determine if encryption will be used or not prior to | |
6377 | * association being expected. If encryption is not being | |
6378 | * used, drop_unencrypted is set to false, else true -- we | |
6379 | * can use this to determine if the CAP_PRIVACY_ON bit should | |
6380 | * be set. | |
6381 | */ | |
6382 | struct ieee80211_security sec = { | |
6383 | .flags = SEC_ENABLED, | |
6384 | .enabled = param->value, | |
6385 | }; | |
6386 | priv->ieee->drop_unencrypted = param->value; | |
6387 | /* We only change SEC_LEVEL for open mode. Others | |
6388 | * are set by ipw_wpa_set_encryption. | |
6389 | */ | |
6390 | if (!param->value) { | |
6391 | sec.flags |= SEC_LEVEL; | |
6392 | sec.level = SEC_LEVEL_0; | |
6393 | } else { | |
6394 | sec.flags |= SEC_LEVEL; | |
6395 | sec.level = SEC_LEVEL_1; | |
6396 | } | |
6397 | if (priv->ieee->set_security) | |
6398 | priv->ieee->set_security(priv->ieee->dev, &sec); | |
6399 | break; | |
6400 | } | |
6401 | ||
6402 | case IW_AUTH_80211_AUTH_ALG: | |
6403 | ret = ipw_wpa_set_auth_algs(priv, param->value); | |
6404 | break; | |
6405 | ||
6406 | case IW_AUTH_WPA_ENABLED: | |
6407 | ret = ipw_wpa_enable(priv, param->value); | |
6408 | break; | |
6409 | ||
6410 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
6411 | ieee->ieee802_1x = param->value; | |
6412 | break; | |
6413 | ||
6414 | //case IW_AUTH_ROAMING_CONTROL: | |
6415 | case IW_AUTH_PRIVACY_INVOKED: | |
6416 | ieee->privacy_invoked = param->value; | |
6417 | break; | |
6418 | ||
6419 | default: | |
6420 | return -EOPNOTSUPP; | |
6421 | } | |
6422 | return ret; | |
6423 | } | |
6424 | ||
6425 | /* SIOCGIWAUTH */ | |
6426 | static int ipw_wx_get_auth(struct net_device *dev, | |
6427 | struct iw_request_info *info, | |
6428 | union iwreq_data *wrqu, char *extra) | |
6429 | { | |
6430 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6431 | struct ieee80211_device *ieee = priv->ieee; | |
6432 | struct ieee80211_crypt_data *crypt; | |
6433 | struct iw_param *param = &wrqu->param; | |
6434 | int ret = 0; | |
6435 | ||
6436 | switch (param->flags & IW_AUTH_INDEX) { | |
6437 | case IW_AUTH_WPA_VERSION: | |
6438 | case IW_AUTH_CIPHER_PAIRWISE: | |
6439 | case IW_AUTH_CIPHER_GROUP: | |
6440 | case IW_AUTH_KEY_MGMT: | |
6441 | /* | |
6442 | * wpa_supplicant will control these internally | |
6443 | */ | |
6444 | ret = -EOPNOTSUPP; | |
6445 | break; | |
6446 | ||
6447 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
6448 | crypt = priv->ieee->crypt[priv->ieee->tx_keyidx]; | |
991d1cc5 | 6449 | if (!crypt || !crypt->ops->get_flags) |
afbf30a2 | 6450 | break; |
afbf30a2 JK |
6451 | |
6452 | param->value = (crypt->ops->get_flags(crypt->priv) & | |
6453 | IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0; | |
6454 | ||
6455 | break; | |
6456 | ||
6457 | case IW_AUTH_DROP_UNENCRYPTED: | |
6458 | param->value = ieee->drop_unencrypted; | |
6459 | break; | |
6460 | ||
6461 | case IW_AUTH_80211_AUTH_ALG: | |
6462 | param->value = ieee->sec.auth_mode; | |
6463 | break; | |
6464 | ||
6465 | case IW_AUTH_WPA_ENABLED: | |
6466 | param->value = ieee->wpa_enabled; | |
6467 | break; | |
6468 | ||
6469 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
6470 | param->value = ieee->ieee802_1x; | |
6471 | break; | |
6472 | ||
6473 | case IW_AUTH_ROAMING_CONTROL: | |
6474 | case IW_AUTH_PRIVACY_INVOKED: | |
6475 | param->value = ieee->privacy_invoked; | |
6476 | break; | |
6477 | ||
6478 | default: | |
6479 | return -EOPNOTSUPP; | |
6480 | } | |
6481 | return 0; | |
6482 | } | |
6483 | ||
6484 | /* SIOCSIWENCODEEXT */ | |
6485 | static int ipw_wx_set_encodeext(struct net_device *dev, | |
6486 | struct iw_request_info *info, | |
6487 | union iwreq_data *wrqu, char *extra) | |
6488 | { | |
6489 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6490 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; | |
6491 | ||
6492 | if (hwcrypto) { | |
afbf30a2 | 6493 | if (ext->alg == IW_ENCODE_ALG_TKIP) { |
567deaf6 HL |
6494 | /* IPW HW can't build TKIP MIC, |
6495 | host decryption still needed */ | |
6496 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) | |
6497 | priv->ieee->host_mc_decrypt = 1; | |
6498 | else { | |
6499 | priv->ieee->host_encrypt = 0; | |
6500 | priv->ieee->host_encrypt_msdu = 1; | |
6501 | priv->ieee->host_decrypt = 1; | |
6502 | } | |
afbf30a2 JK |
6503 | } else { |
6504 | priv->ieee->host_encrypt = 0; | |
6505 | priv->ieee->host_encrypt_msdu = 0; | |
6506 | priv->ieee->host_decrypt = 0; | |
567deaf6 | 6507 | priv->ieee->host_mc_decrypt = 0; |
afbf30a2 JK |
6508 | } |
6509 | } | |
6510 | ||
6511 | return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra); | |
6512 | } | |
6513 | ||
6514 | /* SIOCGIWENCODEEXT */ | |
6515 | static int ipw_wx_get_encodeext(struct net_device *dev, | |
6516 | struct iw_request_info *info, | |
6517 | union iwreq_data *wrqu, char *extra) | |
6518 | { | |
6519 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6520 | return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra); | |
6521 | } | |
6522 | ||
6523 | /* SIOCSIWMLME */ | |
6524 | static int ipw_wx_set_mlme(struct net_device *dev, | |
6525 | struct iw_request_info *info, | |
6526 | union iwreq_data *wrqu, char *extra) | |
6527 | { | |
6528 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6529 | struct iw_mlme *mlme = (struct iw_mlme *)extra; | |
6530 | u16 reason; | |
6531 | ||
6532 | reason = cpu_to_le16(mlme->reason_code); | |
6533 | ||
6534 | switch (mlme->cmd) { | |
6535 | case IW_MLME_DEAUTH: | |
6536 | // silently ignore | |
6537 | break; | |
6538 | ||
6539 | case IW_MLME_DISASSOC: | |
6540 | ipw_disassociate(priv); | |
6541 | break; | |
6542 | ||
6543 | default: | |
6544 | return -EOPNOTSUPP; | |
6545 | } | |
6546 | return 0; | |
6547 | } | |
afbf30a2 JK |
6548 | |
6549 | #ifdef CONFIG_IPW_QOS | |
6550 | ||
6551 | /* QoS */ | |
6552 | /* | |
6553 | * get the modulation type of the current network or | |
6554 | * the card current mode | |
6555 | */ | |
53d0bcf8 | 6556 | static u8 ipw_qos_current_mode(struct ipw_priv * priv) |
afbf30a2 JK |
6557 | { |
6558 | u8 mode = 0; | |
6559 | ||
6560 | if (priv->status & STATUS_ASSOCIATED) { | |
6561 | unsigned long flags; | |
6562 | ||
6563 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
6564 | mode = priv->assoc_network->mode; | |
6565 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
6566 | } else { | |
6567 | mode = priv->ieee->mode; | |
6568 | } | |
6569 | IPW_DEBUG_QOS("QoS network/card mode %d \n", mode); | |
6570 | return mode; | |
b095c381 | 6571 | } |
ea2b26e0 | 6572 | |
b095c381 JK |
6573 | /* |
6574 | * Handle management frame beacon and probe response | |
6575 | */ | |
3b9990cb JK |
6576 | static int ipw_qos_handle_probe_response(struct ipw_priv *priv, |
6577 | int active_network, | |
6578 | struct ieee80211_network *network) | |
b095c381 JK |
6579 | { |
6580 | u32 size = sizeof(struct ieee80211_qos_parameters); | |
6581 | ||
afbf30a2 | 6582 | if (network->capability & WLAN_CAPABILITY_IBSS) |
b095c381 JK |
6583 | network->qos_data.active = network->qos_data.supported; |
6584 | ||
6585 | if (network->flags & NETWORK_HAS_QOS_MASK) { | |
afbf30a2 JK |
6586 | if (active_network && |
6587 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) | |
b095c381 JK |
6588 | network->qos_data.active = network->qos_data.supported; |
6589 | ||
6590 | if ((network->qos_data.active == 1) && (active_network == 1) && | |
6591 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && | |
6592 | (network->qos_data.old_param_count != | |
6593 | network->qos_data.param_count)) { | |
6594 | network->qos_data.old_param_count = | |
6595 | network->qos_data.param_count; | |
6596 | schedule_work(&priv->qos_activate); | |
afbf30a2 JK |
6597 | IPW_DEBUG_QOS("QoS parameters change call " |
6598 | "qos_activate\n"); | |
b095c381 | 6599 | } |
ea2b26e0 | 6600 | } else { |
afbf30a2 JK |
6601 | if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) |
6602 | memcpy(&network->qos_data.parameters, | |
b095c381 | 6603 | &def_parameters_CCK, size); |
afbf30a2 JK |
6604 | else |
6605 | memcpy(&network->qos_data.parameters, | |
b095c381 | 6606 | &def_parameters_OFDM, size); |
afbf30a2 | 6607 | |
b095c381 JK |
6608 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
6609 | IPW_DEBUG_QOS("QoS was disabled call qos_activate \n"); | |
6610 | schedule_work(&priv->qos_activate); | |
6611 | } | |
6612 | ||
6613 | network->qos_data.active = 0; | |
6614 | network->qos_data.supported = 0; | |
ea2b26e0 | 6615 | } |
afbf30a2 JK |
6616 | if ((priv->status & STATUS_ASSOCIATED) && |
6617 | (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) { | |
6618 | if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) | |
6619 | if ((network->capability & WLAN_CAPABILITY_IBSS) && | |
6620 | !(network->flags & NETWORK_EMPTY_ESSID)) | |
b095c381 | 6621 | if ((network->ssid_len == |
afbf30a2 JK |
6622 | priv->assoc_network->ssid_len) && |
6623 | !memcmp(network->ssid, | |
6624 | priv->assoc_network->ssid, | |
6625 | network->ssid_len)) { | |
b095c381 JK |
6626 | queue_work(priv->workqueue, |
6627 | &priv->merge_networks); | |
6628 | } | |
b095c381 | 6629 | } |
ea2b26e0 | 6630 | |
b095c381 JK |
6631 | return 0; |
6632 | } | |
6633 | ||
6634 | /* | |
6635 | * This function set up the firmware to support QoS. It sends | |
6636 | * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO | |
6637 | */ | |
6638 | static int ipw_qos_activate(struct ipw_priv *priv, | |
6639 | struct ieee80211_qos_data *qos_network_data) | |
6640 | { | |
6641 | int err; | |
6642 | struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS]; | |
6643 | struct ieee80211_qos_parameters *active_one = NULL; | |
6644 | u32 size = sizeof(struct ieee80211_qos_parameters); | |
6645 | u32 burst_duration; | |
6646 | int i; | |
6647 | u8 type; | |
6648 | ||
6649 | type = ipw_qos_current_mode(priv); | |
6650 | ||
6651 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]); | |
6652 | memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size); | |
6653 | active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]); | |
6654 | memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size); | |
6655 | ||
6656 | if (qos_network_data == NULL) { | |
6657 | if (type == IEEE_B) { | |
6658 | IPW_DEBUG_QOS("QoS activate network mode %d\n", type); | |
6659 | active_one = &def_parameters_CCK; | |
6660 | } else | |
6661 | active_one = &def_parameters_OFDM; | |
6662 | ||
afbf30a2 | 6663 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
b095c381 JK |
6664 | burst_duration = ipw_qos_get_burst_duration(priv); |
6665 | for (i = 0; i < QOS_QUEUE_NUM; i++) | |
afbf30a2 JK |
6666 | qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] = |
6667 | (u16) burst_duration; | |
6668 | } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
b095c381 JK |
6669 | if (type == IEEE_B) { |
6670 | IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n", | |
6671 | type); | |
6672 | if (priv->qos_data.qos_enable == 0) | |
6673 | active_one = &def_parameters_CCK; | |
6674 | else | |
6675 | active_one = priv->qos_data.def_qos_parm_CCK; | |
6676 | } else { | |
6677 | if (priv->qos_data.qos_enable == 0) | |
6678 | active_one = &def_parameters_OFDM; | |
6679 | else | |
6680 | active_one = priv->qos_data.def_qos_parm_OFDM; | |
6681 | } | |
afbf30a2 | 6682 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
b095c381 JK |
6683 | } else { |
6684 | unsigned long flags; | |
6685 | int active; | |
6686 | ||
6687 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
6688 | active_one = &(qos_network_data->parameters); | |
6689 | qos_network_data->old_param_count = | |
6690 | qos_network_data->param_count; | |
afbf30a2 | 6691 | memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size); |
b095c381 JK |
6692 | active = qos_network_data->supported; |
6693 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
6694 | ||
6695 | if (active == 0) { | |
6696 | burst_duration = ipw_qos_get_burst_duration(priv); | |
6697 | for (i = 0; i < QOS_QUEUE_NUM; i++) | |
6698 | qos_parameters[QOS_PARAM_SET_ACTIVE]. | |
6699 | tx_op_limit[i] = (u16) burst_duration; | |
6700 | } | |
6701 | } | |
6702 | ||
6703 | IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n"); | |
afbf30a2 JK |
6704 | err = ipw_send_qos_params_command(priv, |
6705 | (struct ieee80211_qos_parameters *) | |
6706 | &(qos_parameters[0])); | |
b095c381 JK |
6707 | if (err) |
6708 | IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n"); | |
6709 | ||
6710 | return err; | |
6711 | } | |
6712 | ||
6713 | /* | |
6714 | * send IPW_CMD_WME_INFO to the firmware | |
6715 | */ | |
6716 | static int ipw_qos_set_info_element(struct ipw_priv *priv) | |
6717 | { | |
6718 | int ret = 0; | |
6719 | struct ieee80211_qos_information_element qos_info; | |
6720 | ||
6721 | if (priv == NULL) | |
6722 | return -1; | |
6723 | ||
6724 | qos_info.elementID = QOS_ELEMENT_ID; | |
6725 | qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2; | |
6726 | ||
6727 | qos_info.version = QOS_VERSION_1; | |
6728 | qos_info.ac_info = 0; | |
6729 | ||
6730 | memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN); | |
6731 | qos_info.qui_type = QOS_OUI_TYPE; | |
6732 | qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE; | |
6733 | ||
6734 | ret = ipw_send_qos_info_command(priv, &qos_info); | |
6735 | if (ret != 0) { | |
6736 | IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n"); | |
6737 | } | |
6738 | return ret; | |
6739 | } | |
6740 | ||
6741 | /* | |
6742 | * Set the QoS parameter with the association request structure | |
6743 | */ | |
6744 | static int ipw_qos_association(struct ipw_priv *priv, | |
6745 | struct ieee80211_network *network) | |
6746 | { | |
6747 | int err = 0; | |
6748 | struct ieee80211_qos_data *qos_data = NULL; | |
6749 | struct ieee80211_qos_data ibss_data = { | |
6750 | .supported = 1, | |
6751 | .active = 1, | |
6752 | }; | |
6753 | ||
6754 | switch (priv->ieee->iw_mode) { | |
6755 | case IW_MODE_ADHOC: | |
6756 | if (!(network->capability & WLAN_CAPABILITY_IBSS)) | |
6757 | BUG(); | |
6758 | ||
6759 | qos_data = &ibss_data; | |
6760 | break; | |
6761 | ||
6762 | case IW_MODE_INFRA: | |
6763 | qos_data = &network->qos_data; | |
6764 | break; | |
6765 | ||
6766 | default: | |
6767 | BUG(); | |
6768 | break; | |
6769 | } | |
6770 | ||
6771 | err = ipw_qos_activate(priv, qos_data); | |
6772 | if (err) { | |
6773 | priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC; | |
6774 | return err; | |
6775 | } | |
6776 | ||
6777 | if (priv->qos_data.qos_enable && qos_data->supported) { | |
6778 | IPW_DEBUG_QOS("QoS will be enabled for this association\n"); | |
6779 | priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC; | |
6780 | return ipw_qos_set_info_element(priv); | |
6781 | } | |
6782 | ||
6783 | return 0; | |
6784 | } | |
6785 | ||
6786 | /* | |
6787 | * handling the beaconing responces. if we get different QoS setting | |
6788 | * of the network from the the associated setting adjust the QoS | |
6789 | * setting | |
6790 | */ | |
6791 | static int ipw_qos_association_resp(struct ipw_priv *priv, | |
6792 | struct ieee80211_network *network) | |
6793 | { | |
6794 | int ret = 0; | |
6795 | unsigned long flags; | |
6796 | u32 size = sizeof(struct ieee80211_qos_parameters); | |
6797 | int set_qos_param = 0; | |
6798 | ||
afbf30a2 JK |
6799 | if ((priv == NULL) || (network == NULL) || |
6800 | (priv->assoc_network == NULL)) | |
b095c381 JK |
6801 | return ret; |
6802 | ||
6803 | if (!(priv->status & STATUS_ASSOCIATED)) | |
6804 | return ret; | |
6805 | ||
afbf30a2 | 6806 | if ((priv->ieee->iw_mode != IW_MODE_INFRA)) |
b095c381 | 6807 | return ret; |
b095c381 JK |
6808 | |
6809 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
6810 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { | |
afbf30a2 | 6811 | memcpy(&priv->assoc_network->qos_data, &network->qos_data, |
b095c381 JK |
6812 | sizeof(struct ieee80211_qos_data)); |
6813 | priv->assoc_network->qos_data.active = 1; | |
6814 | if ((network->qos_data.old_param_count != | |
6815 | network->qos_data.param_count)) { | |
6816 | set_qos_param = 1; | |
6817 | network->qos_data.old_param_count = | |
6818 | network->qos_data.param_count; | |
6819 | } | |
6820 | ||
6821 | } else { | |
afbf30a2 JK |
6822 | if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) |
6823 | memcpy(&priv->assoc_network->qos_data.parameters, | |
b095c381 | 6824 | &def_parameters_CCK, size); |
afbf30a2 JK |
6825 | else |
6826 | memcpy(&priv->assoc_network->qos_data.parameters, | |
b095c381 | 6827 | &def_parameters_OFDM, size); |
b095c381 JK |
6828 | priv->assoc_network->qos_data.active = 0; |
6829 | priv->assoc_network->qos_data.supported = 0; | |
6830 | set_qos_param = 1; | |
6831 | } | |
6832 | ||
6833 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
6834 | ||
6835 | if (set_qos_param == 1) | |
6836 | schedule_work(&priv->qos_activate); | |
6837 | ||
6838 | return ret; | |
6839 | } | |
6840 | ||
6841 | static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv) | |
6842 | { | |
6843 | u32 ret = 0; | |
6844 | ||
6845 | if ((priv == NULL)) | |
6846 | return 0; | |
6847 | ||
afbf30a2 | 6848 | if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) |
b095c381 | 6849 | ret = priv->qos_data.burst_duration_CCK; |
afbf30a2 | 6850 | else |
b095c381 | 6851 | ret = priv->qos_data.burst_duration_OFDM; |
afbf30a2 | 6852 | |
b095c381 JK |
6853 | return ret; |
6854 | } | |
6855 | ||
6856 | /* | |
6857 | * Initialize the setting of QoS global | |
6858 | */ | |
6859 | static void ipw_qos_init(struct ipw_priv *priv, int enable, | |
6860 | int burst_enable, u32 burst_duration_CCK, | |
6861 | u32 burst_duration_OFDM) | |
6862 | { | |
6863 | priv->qos_data.qos_enable = enable; | |
6864 | ||
6865 | if (priv->qos_data.qos_enable) { | |
6866 | priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK; | |
6867 | priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM; | |
6868 | IPW_DEBUG_QOS("QoS is enabled\n"); | |
6869 | } else { | |
6870 | priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK; | |
6871 | priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM; | |
6872 | IPW_DEBUG_QOS("QoS is not enabled\n"); | |
6873 | } | |
6874 | ||
6875 | priv->qos_data.burst_enable = burst_enable; | |
6876 | ||
6877 | if (burst_enable) { | |
6878 | priv->qos_data.burst_duration_CCK = burst_duration_CCK; | |
6879 | priv->qos_data.burst_duration_OFDM = burst_duration_OFDM; | |
6880 | } else { | |
6881 | priv->qos_data.burst_duration_CCK = 0; | |
6882 | priv->qos_data.burst_duration_OFDM = 0; | |
6883 | } | |
6884 | } | |
6885 | ||
6886 | /* | |
6887 | * map the packet priority to the right TX Queue | |
6888 | */ | |
6889 | static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority) | |
6890 | { | |
6891 | if (priority > 7 || !priv->qos_data.qos_enable) | |
6892 | priority = 0; | |
6893 | ||
6894 | return from_priority_to_tx_queue[priority] - 1; | |
6895 | } | |
6896 | ||
6897 | /* | |
6898 | * add QoS parameter to the TX command | |
6899 | */ | |
6900 | static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv, | |
6901 | u16 priority, | |
6902 | struct tfd_data *tfd, u8 unicast) | |
6903 | { | |
6904 | int ret = 0; | |
6905 | int tx_queue_id = 0; | |
6906 | struct ieee80211_qos_data *qos_data = NULL; | |
6907 | int active, supported; | |
6908 | unsigned long flags; | |
6909 | ||
6910 | if (!(priv->status & STATUS_ASSOCIATED)) | |
6911 | return 0; | |
6912 | ||
6913 | qos_data = &priv->assoc_network->qos_data; | |
6914 | ||
6915 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
6916 | ||
6917 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
6918 | if (unicast == 0) | |
6919 | qos_data->active = 0; | |
6920 | else | |
6921 | qos_data->active = qos_data->supported; | |
6922 | } | |
6923 | ||
6924 | active = qos_data->active; | |
6925 | supported = qos_data->supported; | |
6926 | ||
6927 | spin_unlock_irqrestore(&priv->ieee->lock, flags); | |
6928 | ||
afbf30a2 JK |
6929 | IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d " |
6930 | "unicast %d\n", | |
6931 | priv->qos_data.qos_enable, active, supported, unicast); | |
b095c381 JK |
6932 | if (active && priv->qos_data.qos_enable) { |
6933 | ret = from_priority_to_tx_queue[priority]; | |
6934 | tx_queue_id = ret - 1; | |
6935 | IPW_DEBUG_QOS("QoS packet priority is %d \n", priority); | |
6936 | if (priority <= 7) { | |
6937 | tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED; | |
6938 | tfd->tfd.tfd_26.mchdr.qos_ctrl = priority; | |
6939 | tfd->tfd.tfd_26.mchdr.frame_ctl |= | |
6940 | IEEE80211_STYPE_QOS_DATA; | |
6941 | ||
6942 | if (priv->qos_data.qos_no_ack_mask & | |
6943 | (1UL << tx_queue_id)) { | |
6944 | tfd->tx_flags &= ~DCT_FLAG_ACK_REQD; | |
6945 | tfd->tfd.tfd_26.mchdr.qos_ctrl |= | |
6946 | CTRL_QOS_NO_ACK; | |
6947 | } | |
6948 | } | |
6949 | } | |
6950 | ||
6951 | return ret; | |
6952 | } | |
6953 | ||
6954 | /* | |
6955 | * background support to run QoS activate functionality | |
6956 | */ | |
6957 | static void ipw_bg_qos_activate(void *data) | |
6958 | { | |
6959 | struct ipw_priv *priv = data; | |
6960 | ||
6961 | if (priv == NULL) | |
6962 | return; | |
6963 | ||
4644151b | 6964 | mutex_lock(&priv->mutex); |
b095c381 JK |
6965 | |
6966 | if (priv->status & STATUS_ASSOCIATED) | |
6967 | ipw_qos_activate(priv, &(priv->assoc_network->qos_data)); | |
6968 | ||
4644151b | 6969 | mutex_unlock(&priv->mutex); |
b095c381 JK |
6970 | } |
6971 | ||
3b9990cb JK |
6972 | static int ipw_handle_probe_response(struct net_device *dev, |
6973 | struct ieee80211_probe_response *resp, | |
6974 | struct ieee80211_network *network) | |
b095c381 JK |
6975 | { |
6976 | struct ipw_priv *priv = ieee80211_priv(dev); | |
3b9990cb JK |
6977 | int active_network = ((priv->status & STATUS_ASSOCIATED) && |
6978 | (network == priv->assoc_network)); | |
43f66a6c | 6979 | |
3b9990cb | 6980 | ipw_qos_handle_probe_response(priv, active_network, network); |
43f66a6c | 6981 | |
3b9990cb JK |
6982 | return 0; |
6983 | } | |
43f66a6c | 6984 | |
3b9990cb JK |
6985 | static int ipw_handle_beacon(struct net_device *dev, |
6986 | struct ieee80211_beacon *resp, | |
6987 | struct ieee80211_network *network) | |
6988 | { | |
6989 | struct ipw_priv *priv = ieee80211_priv(dev); | |
6990 | int active_network = ((priv->status & STATUS_ASSOCIATED) && | |
6991 | (network == priv->assoc_network)); | |
bf79451e | 6992 | |
3b9990cb | 6993 | ipw_qos_handle_probe_response(priv, active_network, network); |
bf79451e | 6994 | |
b095c381 JK |
6995 | return 0; |
6996 | } | |
bf79451e | 6997 | |
3b9990cb JK |
6998 | static int ipw_handle_assoc_response(struct net_device *dev, |
6999 | struct ieee80211_assoc_response *resp, | |
7000 | struct ieee80211_network *network) | |
7001 | { | |
7002 | struct ipw_priv *priv = ieee80211_priv(dev); | |
7003 | ipw_qos_association_resp(priv, network); | |
7004 | return 0; | |
7005 | } | |
43f66a6c | 7006 | |
b095c381 JK |
7007 | static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters |
7008 | *qos_param) | |
7009 | { | |
4e22699f ZY |
7010 | return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS, |
7011 | sizeof(*qos_param) * 3, qos_param); | |
b095c381 JK |
7012 | } |
7013 | ||
7014 | static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element | |
7015 | *qos_param) | |
7016 | { | |
4e22699f ZY |
7017 | return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param), |
7018 | qos_param); | |
43f66a6c JK |
7019 | } |
7020 | ||
b095c381 JK |
7021 | #endif /* CONFIG_IPW_QOS */ |
7022 | ||
43f66a6c JK |
7023 | static int ipw_associate_network(struct ipw_priv *priv, |
7024 | struct ieee80211_network *network, | |
0edd5b44 | 7025 | struct ipw_supported_rates *rates, int roaming) |
43f66a6c JK |
7026 | { |
7027 | int err; | |
7028 | ||
7029 | if (priv->config & CFG_FIXED_RATE) | |
b095c381 | 7030 | ipw_set_fixed_rate(priv, network->mode); |
43f66a6c JK |
7031 | |
7032 | if (!(priv->config & CFG_STATIC_ESSID)) { | |
bf79451e | 7033 | priv->essid_len = min(network->ssid_len, |
0edd5b44 | 7034 | (u8) IW_ESSID_MAX_SIZE); |
43f66a6c JK |
7035 | memcpy(priv->essid, network->ssid, priv->essid_len); |
7036 | } | |
7037 | ||
7038 | network->last_associate = jiffies; | |
7039 | ||
7040 | memset(&priv->assoc_request, 0, sizeof(priv->assoc_request)); | |
7041 | priv->assoc_request.channel = network->channel; | |
3e234b4e ZY |
7042 | priv->assoc_request.auth_key = 0; |
7043 | ||
43f66a6c | 7044 | if ((priv->capability & CAP_PRIVACY_ON) && |
3e234b4e | 7045 | (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) { |
43f66a6c | 7046 | priv->assoc_request.auth_type = AUTH_SHARED_KEY; |
b095c381 JK |
7047 | priv->assoc_request.auth_key = priv->ieee->sec.active_key; |
7048 | ||
1ba61e05 | 7049 | if (priv->ieee->sec.level == SEC_LEVEL_1) |
b095c381 | 7050 | ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP); |
3e234b4e ZY |
7051 | |
7052 | } else if ((priv->capability & CAP_PRIVACY_ON) && | |
7053 | (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)) | |
7054 | priv->assoc_request.auth_type = AUTH_LEAP; | |
7055 | else | |
43f66a6c | 7056 | priv->assoc_request.auth_type = AUTH_OPEN; |
43f66a6c | 7057 | |
b095c381 | 7058 | if (priv->ieee->wpa_ie_len) { |
ea2b26e0 JK |
7059 | priv->assoc_request.policy_support = 0x02; /* RSN active */ |
7060 | ipw_set_rsn_capa(priv, priv->ieee->wpa_ie, | |
7061 | priv->ieee->wpa_ie_len); | |
7062 | } | |
43f66a6c | 7063 | |
bf79451e JG |
7064 | /* |
7065 | * It is valid for our ieee device to support multiple modes, but | |
7066 | * when it comes to associating to a given network we have to choose | |
43f66a6c JK |
7067 | * just one mode. |
7068 | */ | |
7069 | if (network->mode & priv->ieee->mode & IEEE_A) | |
7070 | priv->assoc_request.ieee_mode = IPW_A_MODE; | |
7071 | else if (network->mode & priv->ieee->mode & IEEE_G) | |
7072 | priv->assoc_request.ieee_mode = IPW_G_MODE; | |
7073 | else if (network->mode & priv->ieee->mode & IEEE_B) | |
7074 | priv->assoc_request.ieee_mode = IPW_B_MODE; | |
7075 | ||
ea2b26e0 JK |
7076 | priv->assoc_request.capability = network->capability; |
7077 | if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) | |
7078 | && !(priv->config & CFG_PREAMBLE_LONG)) { | |
7079 | priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE; | |
7080 | } else { | |
7081 | priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE; | |
7082 | ||
7083 | /* Clear the short preamble if we won't be supporting it */ | |
7084 | priv->assoc_request.capability &= | |
7085 | ~WLAN_CAPABILITY_SHORT_PREAMBLE; | |
7086 | } | |
7087 | ||
afbf30a2 JK |
7088 | /* Clear capability bits that aren't used in Ad Hoc */ |
7089 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | |
7090 | priv->assoc_request.capability &= | |
7091 | ~WLAN_CAPABILITY_SHORT_SLOT_TIME; | |
7092 | ||
43f66a6c | 7093 | IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " |
ea2b26e0 | 7094 | "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n", |
43f66a6c | 7095 | roaming ? "Rea" : "A", |
bf79451e JG |
7096 | escape_essid(priv->essid, priv->essid_len), |
7097 | network->channel, | |
7098 | ipw_modes[priv->assoc_request.ieee_mode], | |
7099 | rates->num_rates, | |
ea2b26e0 JK |
7100 | (priv->assoc_request.preamble_length == |
7101 | DCT_FLAG_LONG_PREAMBLE) ? "long" : "short", | |
7102 | network->capability & | |
7103 | WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long", | |
43f66a6c | 7104 | priv->capability & CAP_PRIVACY_ON ? "on " : "off", |
bf79451e JG |
7105 | priv->capability & CAP_PRIVACY_ON ? |
7106 | (priv->capability & CAP_SHARED_KEY ? "(shared)" : | |
43f66a6c JK |
7107 | "(open)") : "", |
7108 | priv->capability & CAP_PRIVACY_ON ? " key=" : "", | |
bf79451e | 7109 | priv->capability & CAP_PRIVACY_ON ? |
b095c381 | 7110 | '1' + priv->ieee->sec.active_key : '.', |
0edd5b44 | 7111 | priv->capability & CAP_PRIVACY_ON ? '.' : ' '); |
43f66a6c JK |
7112 | |
7113 | priv->assoc_request.beacon_interval = network->beacon_interval; | |
7114 | if ((priv->ieee->iw_mode == IW_MODE_ADHOC) && | |
0edd5b44 | 7115 | (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) { |
43f66a6c JK |
7116 | priv->assoc_request.assoc_type = HC_IBSS_START; |
7117 | priv->assoc_request.assoc_tsf_msw = 0; | |
7118 | priv->assoc_request.assoc_tsf_lsw = 0; | |
7119 | } else { | |
7120 | if (unlikely(roaming)) | |
7121 | priv->assoc_request.assoc_type = HC_REASSOCIATE; | |
7122 | else | |
7123 | priv->assoc_request.assoc_type = HC_ASSOCIATE; | |
7124 | priv->assoc_request.assoc_tsf_msw = network->time_stamp[1]; | |
7125 | priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0]; | |
7126 | } | |
7127 | ||
afbf30a2 | 7128 | memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN); |
43f66a6c JK |
7129 | |
7130 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { | |
7131 | memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); | |
7132 | priv->assoc_request.atim_window = network->atim_window; | |
7133 | } else { | |
afbf30a2 | 7134 | memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN); |
43f66a6c JK |
7135 | priv->assoc_request.atim_window = 0; |
7136 | } | |
7137 | ||
43f66a6c | 7138 | priv->assoc_request.listen_interval = network->listen_interval; |
bf79451e | 7139 | |
43f66a6c JK |
7140 | err = ipw_send_ssid(priv, priv->essid, priv->essid_len); |
7141 | if (err) { | |
7142 | IPW_DEBUG_HC("Attempt to send SSID command failed.\n"); | |
7143 | return err; | |
7144 | } | |
7145 | ||
7146 | rates->ieee_mode = priv->assoc_request.ieee_mode; | |
7147 | rates->purpose = IPW_RATE_CONNECT; | |
7148 | ipw_send_supported_rates(priv, rates); | |
bf79451e | 7149 | |
43f66a6c JK |
7150 | if (priv->assoc_request.ieee_mode == IPW_G_MODE) |
7151 | priv->sys_config.dot11g_auto_detection = 1; | |
7152 | else | |
7153 | priv->sys_config.dot11g_auto_detection = 0; | |
c848d0af JK |
7154 | |
7155 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) | |
7156 | priv->sys_config.answer_broadcast_ssid_probe = 1; | |
7157 | else | |
7158 | priv->sys_config.answer_broadcast_ssid_probe = 0; | |
7159 | ||
43f66a6c JK |
7160 | err = ipw_send_system_config(priv, &priv->sys_config); |
7161 | if (err) { | |
7162 | IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); | |
7163 | return err; | |
7164 | } | |
bf79451e | 7165 | |
43f66a6c | 7166 | IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); |
ea2b26e0 | 7167 | err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM); |
43f66a6c JK |
7168 | if (err) { |
7169 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); | |
7170 | return err; | |
7171 | } | |
7172 | ||
7173 | /* | |
7174 | * If preemption is enabled, it is possible for the association | |
7175 | * to complete before we return from ipw_send_associate. Therefore | |
7176 | * we have to be sure and update our priviate data first. | |
7177 | */ | |
7178 | priv->channel = network->channel; | |
7179 | memcpy(priv->bssid, network->bssid, ETH_ALEN); | |
bf79451e | 7180 | priv->status |= STATUS_ASSOCIATING; |
43f66a6c JK |
7181 | priv->status &= ~STATUS_SECURITY_UPDATED; |
7182 | ||
7183 | priv->assoc_network = network; | |
7184 | ||
b095c381 JK |
7185 | #ifdef CONFIG_IPW_QOS |
7186 | ipw_qos_association(priv, network); | |
7187 | #endif | |
7188 | ||
43f66a6c JK |
7189 | err = ipw_send_associate(priv, &priv->assoc_request); |
7190 | if (err) { | |
7191 | IPW_DEBUG_HC("Attempt to send associate command failed.\n"); | |
7192 | return err; | |
7193 | } | |
bf79451e JG |
7194 | |
7195 | IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n", | |
43f66a6c JK |
7196 | escape_essid(priv->essid, priv->essid_len), |
7197 | MAC_ARG(priv->bssid)); | |
7198 | ||
7199 | return 0; | |
7200 | } | |
7201 | ||
7202 | static void ipw_roam(void *data) | |
7203 | { | |
7204 | struct ipw_priv *priv = data; | |
7205 | struct ieee80211_network *network = NULL; | |
7206 | struct ipw_network_match match = { | |
7207 | .network = priv->assoc_network | |
7208 | }; | |
7209 | ||
7210 | /* The roaming process is as follows: | |
bf79451e JG |
7211 | * |
7212 | * 1. Missed beacon threshold triggers the roaming process by | |
43f66a6c JK |
7213 | * setting the status ROAM bit and requesting a scan. |
7214 | * 2. When the scan completes, it schedules the ROAM work | |
7215 | * 3. The ROAM work looks at all of the known networks for one that | |
7216 | * is a better network than the currently associated. If none | |
7217 | * found, the ROAM process is over (ROAM bit cleared) | |
7218 | * 4. If a better network is found, a disassociation request is | |
7219 | * sent. | |
7220 | * 5. When the disassociation completes, the roam work is again | |
7221 | * scheduled. The second time through, the driver is no longer | |
7222 | * associated, and the newly selected network is sent an | |
bf79451e | 7223 | * association request. |
43f66a6c JK |
7224 | * 6. At this point ,the roaming process is complete and the ROAM |
7225 | * status bit is cleared. | |
7226 | */ | |
7227 | ||
7228 | /* If we are no longer associated, and the roaming bit is no longer | |
7229 | * set, then we are not actively roaming, so just return */ | |
7230 | if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING))) | |
7231 | return; | |
bf79451e | 7232 | |
43f66a6c | 7233 | if (priv->status & STATUS_ASSOCIATED) { |
bf79451e | 7234 | /* First pass through ROAM process -- look for a better |
43f66a6c | 7235 | * network */ |
a613bffd | 7236 | unsigned long flags; |
43f66a6c JK |
7237 | u8 rssi = priv->assoc_network->stats.rssi; |
7238 | priv->assoc_network->stats.rssi = -128; | |
a613bffd | 7239 | spin_lock_irqsave(&priv->ieee->lock, flags); |
43f66a6c JK |
7240 | list_for_each_entry(network, &priv->ieee->network_list, list) { |
7241 | if (network != priv->assoc_network) | |
7242 | ipw_best_network(priv, &match, network, 1); | |
7243 | } | |
a613bffd | 7244 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
43f66a6c | 7245 | priv->assoc_network->stats.rssi = rssi; |
bf79451e | 7246 | |
43f66a6c JK |
7247 | if (match.network == priv->assoc_network) { |
7248 | IPW_DEBUG_ASSOC("No better APs in this network to " | |
7249 | "roam to.\n"); | |
7250 | priv->status &= ~STATUS_ROAMING; | |
7251 | ipw_debug_config(priv); | |
7252 | return; | |
7253 | } | |
bf79451e | 7254 | |
43f66a6c JK |
7255 | ipw_send_disassociate(priv, 1); |
7256 | priv->assoc_network = match.network; | |
7257 | ||
7258 | return; | |
bf79451e | 7259 | } |
43f66a6c JK |
7260 | |
7261 | /* Second pass through ROAM process -- request association */ | |
7262 | ipw_compatible_rates(priv, priv->assoc_network, &match.rates); | |
7263 | ipw_associate_network(priv, priv->assoc_network, &match.rates, 1); | |
7264 | priv->status &= ~STATUS_ROAMING; | |
7265 | } | |
7266 | ||
c848d0af JK |
7267 | static void ipw_bg_roam(void *data) |
7268 | { | |
7269 | struct ipw_priv *priv = data; | |
4644151b | 7270 | mutex_lock(&priv->mutex); |
c848d0af | 7271 | ipw_roam(data); |
4644151b | 7272 | mutex_unlock(&priv->mutex); |
c848d0af JK |
7273 | } |
7274 | ||
7275 | static int ipw_associate(void *data) | |
43f66a6c JK |
7276 | { |
7277 | struct ipw_priv *priv = data; | |
7278 | ||
7279 | struct ieee80211_network *network = NULL; | |
7280 | struct ipw_network_match match = { | |
7281 | .network = NULL | |
7282 | }; | |
7283 | struct ipw_supported_rates *rates; | |
7284 | struct list_head *element; | |
a613bffd | 7285 | unsigned long flags; |
43f66a6c | 7286 | |
b095c381 JK |
7287 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
7288 | IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n"); | |
7289 | return 0; | |
7290 | } | |
7291 | ||
c848d0af | 7292 | if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
afbf30a2 JK |
7293 | IPW_DEBUG_ASSOC("Not attempting association (already in " |
7294 | "progress)\n"); | |
c848d0af JK |
7295 | return 0; |
7296 | } | |
7297 | ||
e6324726 HL |
7298 | if (priv->status & STATUS_DISASSOCIATING) { |
7299 | IPW_DEBUG_ASSOC("Not attempting association (in " | |
7300 | "disassociating)\n "); | |
7301 | queue_work(priv->workqueue, &priv->associate); | |
7302 | return 0; | |
7303 | } | |
7304 | ||
c848d0af | 7305 | if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) { |
afbf30a2 JK |
7306 | IPW_DEBUG_ASSOC("Not attempting association (scanning or not " |
7307 | "initialized)\n"); | |
c848d0af JK |
7308 | return 0; |
7309 | } | |
43f66a6c JK |
7310 | |
7311 | if (!(priv->config & CFG_ASSOCIATE) && | |
7312 | !(priv->config & (CFG_STATIC_ESSID | | |
0edd5b44 | 7313 | CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) { |
43f66a6c | 7314 | IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); |
c848d0af | 7315 | return 0; |
43f66a6c JK |
7316 | } |
7317 | ||
a613bffd JK |
7318 | /* Protect our use of the network_list */ |
7319 | spin_lock_irqsave(&priv->ieee->lock, flags); | |
bf79451e | 7320 | list_for_each_entry(network, &priv->ieee->network_list, list) |
0edd5b44 | 7321 | ipw_best_network(priv, &match, network, 0); |
43f66a6c JK |
7322 | |
7323 | network = match.network; | |
7324 | rates = &match.rates; | |
7325 | ||
7326 | if (network == NULL && | |
7327 | priv->ieee->iw_mode == IW_MODE_ADHOC && | |
7328 | priv->config & CFG_ADHOC_CREATE && | |
7329 | priv->config & CFG_STATIC_ESSID && | |
a613bffd | 7330 | priv->config & CFG_STATIC_CHANNEL && |
43f66a6c JK |
7331 | !list_empty(&priv->ieee->network_free_list)) { |
7332 | element = priv->ieee->network_free_list.next; | |
0edd5b44 | 7333 | network = list_entry(element, struct ieee80211_network, list); |
43f66a6c JK |
7334 | ipw_adhoc_create(priv, network); |
7335 | rates = &priv->rates; | |
7336 | list_del(element); | |
7337 | list_add_tail(&network->list, &priv->ieee->network_list); | |
7338 | } | |
a613bffd | 7339 | spin_unlock_irqrestore(&priv->ieee->lock, flags); |
bf79451e | 7340 | |
43f66a6c JK |
7341 | /* If we reached the end of the list, then we don't have any valid |
7342 | * matching APs */ | |
7343 | if (!network) { | |
7344 | ipw_debug_config(priv); | |
7345 | ||
b095c381 JK |
7346 | if (!(priv->status & STATUS_SCANNING)) { |
7347 | if (!(priv->config & CFG_SPEED_SCAN)) | |
7348 | queue_delayed_work(priv->workqueue, | |
7349 | &priv->request_scan, | |
7350 | SCAN_INTERVAL); | |
7351 | else | |
7352 | queue_work(priv->workqueue, | |
7353 | &priv->request_scan); | |
7354 | } | |
bf79451e | 7355 | |
c848d0af | 7356 | return 0; |
43f66a6c JK |
7357 | } |
7358 | ||
7359 | ipw_associate_network(priv, network, rates, 0); | |
c848d0af JK |
7360 | |
7361 | return 1; | |
7362 | } | |
7363 | ||
7364 | static void ipw_bg_associate(void *data) | |
7365 | { | |
7366 | struct ipw_priv *priv = data; | |
4644151b | 7367 | mutex_lock(&priv->mutex); |
c848d0af | 7368 | ipw_associate(data); |
4644151b | 7369 | mutex_unlock(&priv->mutex); |
43f66a6c | 7370 | } |
bf79451e | 7371 | |
b095c381 JK |
7372 | static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv, |
7373 | struct sk_buff *skb) | |
7374 | { | |
7375 | struct ieee80211_hdr *hdr; | |
7376 | u16 fc; | |
7377 | ||
7378 | hdr = (struct ieee80211_hdr *)skb->data; | |
7379 | fc = le16_to_cpu(hdr->frame_ctl); | |
7380 | if (!(fc & IEEE80211_FCTL_PROTECTED)) | |
7381 | return; | |
7382 | ||
7383 | fc &= ~IEEE80211_FCTL_PROTECTED; | |
7384 | hdr->frame_ctl = cpu_to_le16(fc); | |
7385 | switch (priv->ieee->sec.level) { | |
7386 | case SEC_LEVEL_3: | |
7387 | /* Remove CCMP HDR */ | |
7388 | memmove(skb->data + IEEE80211_3ADDR_LEN, | |
7389 | skb->data + IEEE80211_3ADDR_LEN + 8, | |
7390 | skb->len - IEEE80211_3ADDR_LEN - 8); | |
f4ff497d | 7391 | skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */ |
b095c381 JK |
7392 | break; |
7393 | case SEC_LEVEL_2: | |
7394 | break; | |
7395 | case SEC_LEVEL_1: | |
7396 | /* Remove IV */ | |
7397 | memmove(skb->data + IEEE80211_3ADDR_LEN, | |
7398 | skb->data + IEEE80211_3ADDR_LEN + 4, | |
7399 | skb->len - IEEE80211_3ADDR_LEN - 4); | |
f4ff497d | 7400 | skb_trim(skb, skb->len - 8); /* IV + ICV */ |
b095c381 JK |
7401 | break; |
7402 | case SEC_LEVEL_0: | |
7403 | break; | |
7404 | default: | |
7405 | printk(KERN_ERR "Unknow security level %d\n", | |
7406 | priv->ieee->sec.level); | |
7407 | break; | |
7408 | } | |
43f66a6c | 7409 | } |
bf79451e | 7410 | |
b095c381 JK |
7411 | static void ipw_handle_data_packet(struct ipw_priv *priv, |
7412 | struct ipw_rx_mem_buffer *rxb, | |
7413 | struct ieee80211_rx_stats *stats) | |
43f66a6c | 7414 | { |
567deaf6 | 7415 | struct ieee80211_hdr_4addr *hdr; |
43f66a6c JK |
7416 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; |
7417 | ||
7418 | /* We received data from the HW, so stop the watchdog */ | |
7419 | priv->net_dev->trans_start = jiffies; | |
7420 | ||
bf79451e | 7421 | /* We only process data packets if the |
43f66a6c | 7422 | * interface is open */ |
a613bffd | 7423 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > |
43f66a6c JK |
7424 | skb_tailroom(rxb->skb))) { |
7425 | priv->ieee->stats.rx_errors++; | |
7426 | priv->wstats.discard.misc++; | |
7427 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); | |
7428 | return; | |
7429 | } else if (unlikely(!netif_running(priv->net_dev))) { | |
7430 | priv->ieee->stats.rx_dropped++; | |
7431 | priv->wstats.discard.misc++; | |
7432 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | |
7433 | return; | |
7434 | } | |
7435 | ||
7436 | /* Advance skb->data to the start of the actual payload */ | |
aaa4d308 | 7437 | skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); |
43f66a6c JK |
7438 | |
7439 | /* Set the size of the skb to the size of the frame */ | |
a613bffd | 7440 | skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length)); |
43f66a6c JK |
7441 | |
7442 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); | |
7443 | ||
b095c381 | 7444 | /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */ |
567deaf6 HL |
7445 | hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data; |
7446 | if (priv->ieee->iw_mode != IW_MODE_MONITOR && | |
3c19065a | 7447 | (is_multicast_ether_addr(hdr->addr1) ? |
567deaf6 | 7448 | !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt)) |
b095c381 JK |
7449 | ipw_rebuild_decrypted_skb(priv, rxb->skb); |
7450 | ||
bf79451e | 7451 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
43f66a6c | 7452 | priv->ieee->stats.rx_errors++; |
a613bffd | 7453 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
43f66a6c | 7454 | rxb->skb = NULL; |
b095c381 | 7455 | __ipw_led_activity_on(priv); |
a613bffd | 7456 | } |
43f66a6c JK |
7457 | } |
7458 | ||
24a47dbd MK |
7459 | #ifdef CONFIG_IEEE80211_RADIOTAP |
7460 | static void ipw_handle_data_packet_monitor(struct ipw_priv *priv, | |
7461 | struct ipw_rx_mem_buffer *rxb, | |
7462 | struct ieee80211_rx_stats *stats) | |
7463 | { | |
7464 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; | |
7465 | struct ipw_rx_frame *frame = &pkt->u.frame; | |
7466 | ||
7467 | /* initial pull of some data */ | |
7468 | u16 received_channel = frame->received_channel; | |
7469 | u8 antennaAndPhy = frame->antennaAndPhy; | |
7470 | s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */ | |
7471 | u16 pktrate = frame->rate; | |
7472 | ||
7473 | /* Magic struct that slots into the radiotap header -- no reason | |
7474 | * to build this manually element by element, we can write it much | |
7475 | * more efficiently than we can parse it. ORDER MATTERS HERE */ | |
7476 | struct ipw_rt_hdr { | |
7477 | struct ieee80211_radiotap_header rt_hdr; | |
7478 | u8 rt_flags; /* radiotap packet flags */ | |
7479 | u8 rt_rate; /* rate in 500kb/s */ | |
7480 | u16 rt_channel; /* channel in mhz */ | |
7481 | u16 rt_chbitmask; /* channel bitfield */ | |
7482 | s8 rt_dbmsignal; /* signal in dbM, kluged to signed */ | |
7483 | u8 rt_antenna; /* antenna number */ | |
7484 | } *ipw_rt; | |
7485 | ||
7486 | short len = le16_to_cpu(pkt->u.frame.length); | |
7487 | ||
7488 | /* We received data from the HW, so stop the watchdog */ | |
7489 | priv->net_dev->trans_start = jiffies; | |
7490 | ||
7491 | /* We only process data packets if the | |
7492 | * interface is open */ | |
7493 | if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) > | |
7494 | skb_tailroom(rxb->skb))) { | |
7495 | priv->ieee->stats.rx_errors++; | |
7496 | priv->wstats.discard.misc++; | |
7497 | IPW_DEBUG_DROP("Corruption detected! Oh no!\n"); | |
7498 | return; | |
7499 | } else if (unlikely(!netif_running(priv->net_dev))) { | |
7500 | priv->ieee->stats.rx_dropped++; | |
7501 | priv->wstats.discard.misc++; | |
7502 | IPW_DEBUG_DROP("Dropping packet while interface is not up.\n"); | |
7503 | return; | |
7504 | } | |
7505 | ||
7506 | /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use | |
7507 | * that now */ | |
7508 | if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) { | |
7509 | /* FIXME: Should alloc bigger skb instead */ | |
7510 | priv->ieee->stats.rx_dropped++; | |
7511 | priv->wstats.discard.misc++; | |
7512 | IPW_DEBUG_DROP("Dropping too large packet in monitor\n"); | |
7513 | return; | |
7514 | } | |
7515 | ||
7516 | /* copy the frame itself */ | |
7517 | memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr), | |
7518 | rxb->skb->data + IPW_RX_FRAME_SIZE, len); | |
7519 | ||
7520 | /* Zero the radiotap static buffer ... We only need to zero the bytes NOT | |
7521 | * part of our real header, saves a little time. | |
7522 | * | |
7523 | * No longer necessary since we fill in all our data. Purge before merging | |
7524 | * patch officially. | |
7525 | * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0, | |
7526 | * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr)); | |
7527 | */ | |
7528 | ||
7529 | ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data; | |
7530 | ||
7531 | ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; | |
7532 | ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */ | |
7533 | ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */ | |
7534 | ||
7535 | /* Big bitfield of all the fields we provide in radiotap */ | |
7536 | ipw_rt->rt_hdr.it_present = | |
7537 | ((1 << IEEE80211_RADIOTAP_FLAGS) | | |
7538 | (1 << IEEE80211_RADIOTAP_RATE) | | |
7539 | (1 << IEEE80211_RADIOTAP_CHANNEL) | | |
7540 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | | |
7541 | (1 << IEEE80211_RADIOTAP_ANTENNA)); | |
7542 | ||
7543 | /* Zero the flags, we'll add to them as we go */ | |
7544 | ipw_rt->rt_flags = 0; | |
7545 | ||
7546 | /* Convert signal to DBM */ | |
7547 | ipw_rt->rt_dbmsignal = antsignal; | |
7548 | ||
7549 | /* Convert the channel data and set the flags */ | |
7550 | ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel)); | |
7551 | if (received_channel > 14) { /* 802.11a */ | |
7552 | ipw_rt->rt_chbitmask = | |
7553 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); | |
7554 | } else if (antennaAndPhy & 32) { /* 802.11b */ | |
7555 | ipw_rt->rt_chbitmask = | |
7556 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); | |
7557 | } else { /* 802.11g */ | |
7558 | ipw_rt->rt_chbitmask = | |
7559 | (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ); | |
7560 | } | |
7561 | ||
7562 | /* set the rate in multiples of 500k/s */ | |
7563 | switch (pktrate) { | |
7564 | case IPW_TX_RATE_1MB: | |
7565 | ipw_rt->rt_rate = 2; | |
7566 | break; | |
7567 | case IPW_TX_RATE_2MB: | |
7568 | ipw_rt->rt_rate = 4; | |
7569 | break; | |
7570 | case IPW_TX_RATE_5MB: | |
7571 | ipw_rt->rt_rate = 10; | |
7572 | break; | |
7573 | case IPW_TX_RATE_6MB: | |
7574 | ipw_rt->rt_rate = 12; | |
7575 | break; | |
7576 | case IPW_TX_RATE_9MB: | |
7577 | ipw_rt->rt_rate = 18; | |
7578 | break; | |
7579 | case IPW_TX_RATE_11MB: | |
7580 | ipw_rt->rt_rate = 22; | |
7581 | break; | |
7582 | case IPW_TX_RATE_12MB: | |
7583 | ipw_rt->rt_rate = 24; | |
7584 | break; | |
7585 | case IPW_TX_RATE_18MB: | |
7586 | ipw_rt->rt_rate = 36; | |
7587 | break; | |
7588 | case IPW_TX_RATE_24MB: | |
7589 | ipw_rt->rt_rate = 48; | |
7590 | break; | |
7591 | case IPW_TX_RATE_36MB: | |
7592 | ipw_rt->rt_rate = 72; | |
7593 | break; | |
7594 | case IPW_TX_RATE_48MB: | |
7595 | ipw_rt->rt_rate = 96; | |
7596 | break; | |
7597 | case IPW_TX_RATE_54MB: | |
7598 | ipw_rt->rt_rate = 108; | |
7599 | break; | |
7600 | default: | |
7601 | ipw_rt->rt_rate = 0; | |
7602 | break; | |
7603 | } | |
7604 | ||
7605 | /* antenna number */ | |
7606 | ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */ | |
7607 | ||
7608 | /* set the preamble flag if we have it */ | |
7609 | if ((antennaAndPhy & 64)) | |
7610 | ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; | |
7611 | ||
7612 | /* Set the size of the skb to the size of the frame */ | |
7613 | skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr)); | |
43f66a6c JK |
7614 | |
7615 | IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); | |
7616 | ||
bf79451e | 7617 | if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) |
43f66a6c | 7618 | priv->ieee->stats.rx_errors++; |
24a47dbd MK |
7619 | else { /* ieee80211_rx succeeded, so it now owns the SKB */ |
7620 | rxb->skb = NULL; | |
7621 | /* no LED during capture */ | |
7622 | } | |
7623 | } | |
7624 | #endif | |
7625 | ||
858119e1 | 7626 | static int is_network_packet(struct ipw_priv *priv, |
ea2b26e0 JK |
7627 | struct ieee80211_hdr_4addr *header) |
7628 | { | |
7629 | /* Filter incoming packets to determine if they are targetted toward | |
7630 | * this network, discarding packets coming from ourselves */ | |
7631 | switch (priv->ieee->iw_mode) { | |
a613bffd | 7632 | case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */ |
c848d0af JK |
7633 | /* packets from our adapter are dropped (echo) */ |
7634 | if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN)) | |
7635 | return 0; | |
7636 | ||
90700fd9 | 7637 | /* {broad,multi}cast packets to our BSSID go through */ |
3c19065a | 7638 | if (is_multicast_ether_addr(header->addr1)) |
ea2b26e0 | 7639 | return !memcmp(header->addr3, priv->bssid, ETH_ALEN); |
a613bffd JK |
7640 | |
7641 | /* packets to our adapter go through */ | |
7642 | return !memcmp(header->addr1, priv->net_dev->dev_addr, | |
7643 | ETH_ALEN); | |
a613bffd | 7644 | |
90700fd9 | 7645 | case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */ |
c848d0af JK |
7646 | /* packets from our adapter are dropped (echo) */ |
7647 | if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN)) | |
7648 | return 0; | |
7649 | ||
90700fd9 | 7650 | /* {broad,multi}cast packets to our BSS go through */ |
3c19065a | 7651 | if (is_multicast_ether_addr(header->addr1)) |
a613bffd JK |
7652 | return !memcmp(header->addr2, priv->bssid, ETH_ALEN); |
7653 | ||
7654 | /* packets to our adapter go through */ | |
7655 | return !memcmp(header->addr1, priv->net_dev->dev_addr, | |
7656 | ETH_ALEN); | |
ea2b26e0 | 7657 | } |
a613bffd | 7658 | |
ea2b26e0 JK |
7659 | return 1; |
7660 | } | |
7661 | ||
afbf30a2 JK |
7662 | #define IPW_PACKET_RETRY_TIME HZ |
7663 | ||
858119e1 | 7664 | static int is_duplicate_packet(struct ipw_priv *priv, |
afbf30a2 JK |
7665 | struct ieee80211_hdr_4addr *header) |
7666 | { | |
afbf30a2 JK |
7667 | u16 sc = le16_to_cpu(header->seq_ctl); |
7668 | u16 seq = WLAN_GET_SEQ_SEQ(sc); | |
7669 | u16 frag = WLAN_GET_SEQ_FRAG(sc); | |
7670 | u16 *last_seq, *last_frag; | |
7671 | unsigned long *last_time; | |
7672 | ||
7673 | switch (priv->ieee->iw_mode) { | |
7674 | case IW_MODE_ADHOC: | |
7675 | { | |
7676 | struct list_head *p; | |
7677 | struct ipw_ibss_seq *entry = NULL; | |
7678 | u8 *mac = header->addr2; | |
7679 | int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; | |
7680 | ||
7681 | __list_for_each(p, &priv->ibss_mac_hash[index]) { | |
7682 | entry = | |
7683 | list_entry(p, struct ipw_ibss_seq, list); | |
7684 | if (!memcmp(entry->mac, mac, ETH_ALEN)) | |
7685 | break; | |
7686 | } | |
7687 | if (p == &priv->ibss_mac_hash[index]) { | |
7688 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); | |
7689 | if (!entry) { | |
7690 | IPW_ERROR | |
7691 | ("Cannot malloc new mac entry\n"); | |
7692 | return 0; | |
7693 | } | |
7694 | memcpy(entry->mac, mac, ETH_ALEN); | |
7695 | entry->seq_num = seq; | |
7696 | entry->frag_num = frag; | |
7697 | entry->packet_time = jiffies; | |
7698 | list_add(&entry->list, | |
7699 | &priv->ibss_mac_hash[index]); | |
7700 | return 0; | |
7701 | } | |
7702 | last_seq = &entry->seq_num; | |
7703 | last_frag = &entry->frag_num; | |
7704 | last_time = &entry->packet_time; | |
7705 | break; | |
7706 | } | |
7707 | case IW_MODE_INFRA: | |
7708 | last_seq = &priv->last_seq_num; | |
7709 | last_frag = &priv->last_frag_num; | |
7710 | last_time = &priv->last_packet_time; | |
7711 | break; | |
7712 | default: | |
7713 | return 0; | |
7714 | } | |
7715 | if ((*last_seq == seq) && | |
7716 | time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) { | |
7717 | if (*last_frag == frag) | |
7718 | goto drop; | |
7719 | if (*last_frag + 1 != frag) | |
7720 | /* out-of-order fragment */ | |
7721 | goto drop; | |
afbf30a2 JK |
7722 | } else |
7723 | *last_seq = seq; | |
7724 | ||
f57ce7ce | 7725 | *last_frag = frag; |
afbf30a2 JK |
7726 | *last_time = jiffies; |
7727 | return 0; | |
7728 | ||
7729 | drop: | |
87b016cb ZY |
7730 | /* Comment this line now since we observed the card receives |
7731 | * duplicate packets but the FCTL_RETRY bit is not set in the | |
7732 | * IBSS mode with fragmentation enabled. | |
7733 | BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */ | |
afbf30a2 JK |
7734 | return 1; |
7735 | } | |
7736 | ||
b095c381 JK |
7737 | static void ipw_handle_mgmt_packet(struct ipw_priv *priv, |
7738 | struct ipw_rx_mem_buffer *rxb, | |
7739 | struct ieee80211_rx_stats *stats) | |
7740 | { | |
7741 | struct sk_buff *skb = rxb->skb; | |
7742 | struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data; | |
7743 | struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *) | |
7744 | (skb->data + IPW_RX_FRAME_SIZE); | |
7745 | ||
7746 | ieee80211_rx_mgt(priv->ieee, header, stats); | |
7747 | ||
7748 | if (priv->ieee->iw_mode == IW_MODE_ADHOC && | |
7749 | ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == | |
7750 | IEEE80211_STYPE_PROBE_RESP) || | |
7751 | (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) == | |
7752 | IEEE80211_STYPE_BEACON))) { | |
7753 | if (!memcmp(header->addr3, priv->bssid, ETH_ALEN)) | |
7754 | ipw_add_station(priv, header->addr2); | |
7755 | } | |
7756 | ||
7757 | if (priv->config & CFG_NET_STATS) { | |
7758 | IPW_DEBUG_HC("sending stat packet\n"); | |
7759 | ||
7760 | /* Set the size of the skb to the size of the full | |
7761 | * ipw header and 802.11 frame */ | |
7762 | skb_put(skb, le16_to_cpu(pkt->u.frame.length) + | |
7763 | IPW_RX_FRAME_SIZE); | |
7764 | ||
7765 | /* Advance past the ipw packet header to the 802.11 frame */ | |
7766 | skb_pull(skb, IPW_RX_FRAME_SIZE); | |
7767 | ||
7768 | /* Push the ieee80211_rx_stats before the 802.11 frame */ | |
7769 | memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats)); | |
7770 | ||
7771 | skb->dev = priv->ieee->dev; | |
7772 | ||
7773 | /* Point raw at the ieee80211_stats */ | |
7774 | skb->mac.raw = skb->data; | |
7775 | ||
7776 | skb->pkt_type = PACKET_OTHERHOST; | |
7777 | skb->protocol = __constant_htons(ETH_P_80211_STATS); | |
7778 | memset(skb->cb, 0, sizeof(rxb->skb->cb)); | |
7779 | netif_rx(skb); | |
43f66a6c | 7780 | rxb->skb = NULL; |
b095c381 | 7781 | } |
43f66a6c JK |
7782 | } |
7783 | ||
43f66a6c JK |
7784 | /* |
7785 | * Main entry function for recieving a packet with 80211 headers. This | |
7786 | * should be called when ever the FW has notified us that there is a new | |
7787 | * skb in the recieve queue. | |
7788 | */ | |
7789 | static void ipw_rx(struct ipw_priv *priv) | |
7790 | { | |
7791 | struct ipw_rx_mem_buffer *rxb; | |
7792 | struct ipw_rx_packet *pkt; | |
0dacca1f | 7793 | struct ieee80211_hdr_4addr *header; |
43f66a6c JK |
7794 | u32 r, w, i; |
7795 | u8 network_packet; | |
7796 | ||
b095c381 JK |
7797 | r = ipw_read32(priv, IPW_RX_READ_INDEX); |
7798 | w = ipw_read32(priv, IPW_RX_WRITE_INDEX); | |
43f66a6c JK |
7799 | i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE; |
7800 | ||
7801 | while (i != r) { | |
7802 | rxb = priv->rxq->queue[i]; | |
43f66a6c JK |
7803 | if (unlikely(rxb == NULL)) { |
7804 | printk(KERN_CRIT "Queue not allocated!\n"); | |
7805 | break; | |
7806 | } | |
43f66a6c JK |
7807 | priv->rxq->queue[i] = NULL; |
7808 | ||
7809 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, | |
b095c381 | 7810 | IPW_RX_BUF_SIZE, |
43f66a6c JK |
7811 | PCI_DMA_FROMDEVICE); |
7812 | ||
7813 | pkt = (struct ipw_rx_packet *)rxb->skb->data; | |
7814 | IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n", | |
7815 | pkt->header.message_type, | |
0edd5b44 | 7816 | pkt->header.rx_seq_num, pkt->header.control_bits); |
43f66a6c JK |
7817 | |
7818 | switch (pkt->header.message_type) { | |
0edd5b44 JG |
7819 | case RX_FRAME_TYPE: /* 802.11 frame */ { |
7820 | struct ieee80211_rx_stats stats = { | |
c848d0af JK |
7821 | .rssi = |
7822 | le16_to_cpu(pkt->u.frame.rssi_dbm) - | |
0edd5b44 | 7823 | IPW_RSSI_TO_DBM, |
c848d0af | 7824 | .signal = |
b191608a BM |
7825 | le16_to_cpu(pkt->u.frame.rssi_dbm) - |
7826 | IPW_RSSI_TO_DBM + 0x100, | |
c848d0af JK |
7827 | .noise = |
7828 | le16_to_cpu(pkt->u.frame.noise), | |
0edd5b44 JG |
7829 | .rate = pkt->u.frame.rate, |
7830 | .mac_time = jiffies, | |
7831 | .received_channel = | |
7832 | pkt->u.frame.received_channel, | |
7833 | .freq = | |
7834 | (pkt->u.frame. | |
7835 | control & (1 << 0)) ? | |
7836 | IEEE80211_24GHZ_BAND : | |
7837 | IEEE80211_52GHZ_BAND, | |
a613bffd | 7838 | .len = le16_to_cpu(pkt->u.frame.length), |
0edd5b44 JG |
7839 | }; |
7840 | ||
7841 | if (stats.rssi != 0) | |
7842 | stats.mask |= IEEE80211_STATMASK_RSSI; | |
7843 | if (stats.signal != 0) | |
7844 | stats.mask |= IEEE80211_STATMASK_SIGNAL; | |
c848d0af JK |
7845 | if (stats.noise != 0) |
7846 | stats.mask |= IEEE80211_STATMASK_NOISE; | |
0edd5b44 JG |
7847 | if (stats.rate != 0) |
7848 | stats.mask |= IEEE80211_STATMASK_RATE; | |
7849 | ||
7850 | priv->rx_packets++; | |
43f66a6c | 7851 | |
b095c381 | 7852 | #ifdef CONFIG_IPW2200_MONITOR |
0edd5b44 | 7853 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { |
24a47dbd MK |
7854 | #ifdef CONFIG_IEEE80211_RADIOTAP |
7855 | ipw_handle_data_packet_monitor(priv, | |
7856 | rxb, | |
7857 | &stats); | |
7858 | #else | |
0edd5b44 JG |
7859 | ipw_handle_data_packet(priv, rxb, |
7860 | &stats); | |
24a47dbd | 7861 | #endif |
0edd5b44 JG |
7862 | break; |
7863 | } | |
43f66a6c | 7864 | #endif |
bf79451e | 7865 | |
0edd5b44 | 7866 | header = |
0dacca1f JK |
7867 | (struct ieee80211_hdr_4addr *)(rxb->skb-> |
7868 | data + | |
7869 | IPW_RX_FRAME_SIZE); | |
43f66a6c JK |
7870 | /* TODO: Check Ad-Hoc dest/source and make sure |
7871 | * that we are actually parsing these packets | |
bf79451e | 7872 | * correctly -- we should probably use the |
43f66a6c JK |
7873 | * frame control of the packet and disregard |
7874 | * the current iw_mode */ | |
0edd5b44 | 7875 | |
ea2b26e0 JK |
7876 | network_packet = |
7877 | is_network_packet(priv, header); | |
0edd5b44 JG |
7878 | if (network_packet && priv->assoc_network) { |
7879 | priv->assoc_network->stats.rssi = | |
7880 | stats.rssi; | |
7881 | average_add(&priv->average_rssi, | |
7882 | stats.rssi); | |
7883 | priv->last_rx_rssi = stats.rssi; | |
7884 | } | |
7885 | ||
7886 | IPW_DEBUG_RX("Frame: len=%u\n", | |
a613bffd | 7887 | le16_to_cpu(pkt->u.frame.length)); |
0edd5b44 | 7888 | |
a613bffd | 7889 | if (le16_to_cpu(pkt->u.frame.length) < |
9d0be03a ZY |
7890 | ieee80211_get_hdrlen(le16_to_cpu( |
7891 | header->frame_ctl))) { | |
0edd5b44 JG |
7892 | IPW_DEBUG_DROP |
7893 | ("Received packet is too small. " | |
7894 | "Dropping.\n"); | |
7895 | priv->ieee->stats.rx_errors++; | |
7896 | priv->wstats.discard.misc++; | |
7897 | break; | |
7898 | } | |
7899 | ||
a613bffd JK |
7900 | switch (WLAN_FC_GET_TYPE |
7901 | (le16_to_cpu(header->frame_ctl))) { | |
b095c381 | 7902 | |
0edd5b44 | 7903 | case IEEE80211_FTYPE_MGMT: |
b095c381 JK |
7904 | ipw_handle_mgmt_packet(priv, rxb, |
7905 | &stats); | |
0edd5b44 JG |
7906 | break; |
7907 | ||
7908 | case IEEE80211_FTYPE_CTL: | |
7909 | break; | |
7910 | ||
7911 | case IEEE80211_FTYPE_DATA: | |
afbf30a2 JK |
7912 | if (unlikely(!network_packet || |
7913 | is_duplicate_packet(priv, | |
7914 | header))) | |
7915 | { | |
0edd5b44 JG |
7916 | IPW_DEBUG_DROP("Dropping: " |
7917 | MAC_FMT ", " | |
7918 | MAC_FMT ", " | |
7919 | MAC_FMT "\n", | |
7920 | MAC_ARG(header-> | |
7921 | addr1), | |
7922 | MAC_ARG(header-> | |
7923 | addr2), | |
7924 | MAC_ARG(header-> | |
7925 | addr3)); | |
b095c381 JK |
7926 | break; |
7927 | } | |
7928 | ||
7929 | ipw_handle_data_packet(priv, rxb, | |
7930 | &stats); | |
7931 | ||
0edd5b44 JG |
7932 | break; |
7933 | } | |
43f66a6c JK |
7934 | break; |
7935 | } | |
bf79451e | 7936 | |
0edd5b44 JG |
7937 | case RX_HOST_NOTIFICATION_TYPE:{ |
7938 | IPW_DEBUG_RX | |
7939 | ("Notification: subtype=%02X flags=%02X size=%d\n", | |
43f66a6c JK |
7940 | pkt->u.notification.subtype, |
7941 | pkt->u.notification.flags, | |
7942 | pkt->u.notification.size); | |
0edd5b44 JG |
7943 | ipw_rx_notification(priv, &pkt->u.notification); |
7944 | break; | |
7945 | } | |
43f66a6c JK |
7946 | |
7947 | default: | |
7948 | IPW_DEBUG_RX("Bad Rx packet of type %d\n", | |
7949 | pkt->header.message_type); | |
7950 | break; | |
7951 | } | |
bf79451e JG |
7952 | |
7953 | /* For now we just don't re-use anything. We can tweak this | |
7954 | * later to try and re-use notification packets and SKBs that | |
43f66a6c JK |
7955 | * fail to Rx correctly */ |
7956 | if (rxb->skb != NULL) { | |
7957 | dev_kfree_skb_any(rxb->skb); | |
7958 | rxb->skb = NULL; | |
7959 | } | |
bf79451e | 7960 | |
43f66a6c | 7961 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
b095c381 | 7962 | IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
43f66a6c | 7963 | list_add_tail(&rxb->list, &priv->rxq->rx_used); |
bf79451e | 7964 | |
43f66a6c JK |
7965 | i = (i + 1) % RX_QUEUE_SIZE; |
7966 | } | |
7967 | ||
7968 | /* Backtrack one entry */ | |
7969 | priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1; | |
7970 | ||
7971 | ipw_rx_queue_restock(priv); | |
7972 | } | |
7973 | ||
afbf30a2 JK |
7974 | #define DEFAULT_RTS_THRESHOLD 2304U |
7975 | #define MIN_RTS_THRESHOLD 1U | |
7976 | #define MAX_RTS_THRESHOLD 2304U | |
7977 | #define DEFAULT_BEACON_INTERVAL 100U | |
7978 | #define DEFAULT_SHORT_RETRY_LIMIT 7U | |
7979 | #define DEFAULT_LONG_RETRY_LIMIT 4U | |
7980 | ||
7981 | static int ipw_sw_reset(struct ipw_priv *priv, int init) | |
43f66a6c | 7982 | { |
afbf30a2 JK |
7983 | int band, modulation; |
7984 | int old_mode = priv->ieee->iw_mode; | |
43f66a6c | 7985 | |
afbf30a2 JK |
7986 | /* Initialize module parameter values here */ |
7987 | priv->config = 0; | |
43f66a6c | 7988 | |
afbf30a2 JK |
7989 | /* We default to disabling the LED code as right now it causes |
7990 | * too many systems to lock up... */ | |
7991 | if (!led) | |
7992 | priv->config |= CFG_NO_LED; | |
43f66a6c | 7993 | |
afbf30a2 JK |
7994 | if (associate) |
7995 | priv->config |= CFG_ASSOCIATE; | |
7996 | else | |
7997 | IPW_DEBUG_INFO("Auto associate disabled.\n"); | |
bf79451e | 7998 | |
afbf30a2 JK |
7999 | if (auto_create) |
8000 | priv->config |= CFG_ADHOC_CREATE; | |
8001 | else | |
8002 | IPW_DEBUG_INFO("Auto adhoc creation disabled.\n"); | |
43f66a6c | 8003 | |
17ed081d ZY |
8004 | priv->config &= ~CFG_STATIC_ESSID; |
8005 | priv->essid_len = 0; | |
8006 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); | |
8007 | ||
afbf30a2 JK |
8008 | if (disable) { |
8009 | priv->status |= STATUS_RF_KILL_SW; | |
8010 | IPW_DEBUG_INFO("Radio disabled.\n"); | |
43f66a6c | 8011 | } |
bf79451e | 8012 | |
afbf30a2 JK |
8013 | if (channel != 0) { |
8014 | priv->config |= CFG_STATIC_CHANNEL; | |
8015 | priv->channel = channel; | |
8016 | IPW_DEBUG_INFO("Bind to static channel %d\n", channel); | |
8017 | /* TODO: Validate that provided channel is in range */ | |
43f66a6c | 8018 | } |
afbf30a2 JK |
8019 | #ifdef CONFIG_IPW_QOS |
8020 | ipw_qos_init(priv, qos_enable, qos_burst_enable, | |
8021 | burst_duration_CCK, burst_duration_OFDM); | |
8022 | #endif /* CONFIG_IPW_QOS */ | |
43f66a6c | 8023 | |
afbf30a2 JK |
8024 | switch (mode) { |
8025 | case 1: | |
8026 | priv->ieee->iw_mode = IW_MODE_ADHOC; | |
8027 | priv->net_dev->type = ARPHRD_ETHER; | |
8028 | ||
8029 | break; | |
8030 | #ifdef CONFIG_IPW2200_MONITOR | |
8031 | case 2: | |
8032 | priv->ieee->iw_mode = IW_MODE_MONITOR; | |
24a47dbd MK |
8033 | #ifdef CONFIG_IEEE80211_RADIOTAP |
8034 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | |
8035 | #else | |
afbf30a2 | 8036 | priv->net_dev->type = ARPHRD_IEEE80211; |
24a47dbd | 8037 | #endif |
afbf30a2 JK |
8038 | break; |
8039 | #endif | |
8040 | default: | |
8041 | case 0: | |
8042 | priv->net_dev->type = ARPHRD_ETHER; | |
8043 | priv->ieee->iw_mode = IW_MODE_INFRA; | |
8044 | break; | |
43f66a6c JK |
8045 | } |
8046 | ||
afbf30a2 JK |
8047 | if (hwcrypto) { |
8048 | priv->ieee->host_encrypt = 0; | |
8049 | priv->ieee->host_encrypt_msdu = 0; | |
8050 | priv->ieee->host_decrypt = 0; | |
567deaf6 | 8051 | priv->ieee->host_mc_decrypt = 0; |
afbf30a2 JK |
8052 | } |
8053 | IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off"); | |
43f66a6c | 8054 | |
e402c937 ZY |
8055 | /* IPW2200/2915 is abled to do hardware fragmentation. */ |
8056 | priv->ieee->host_open_frag = 0; | |
bf79451e | 8057 | |
afbf30a2 JK |
8058 | if ((priv->pci_dev->device == 0x4223) || |
8059 | (priv->pci_dev->device == 0x4224)) { | |
8060 | if (init) | |
8061 | printk(KERN_INFO DRV_NAME | |
8062 | ": Detected Intel PRO/Wireless 2915ABG Network " | |
8063 | "Connection\n"); | |
8064 | priv->ieee->abg_true = 1; | |
8065 | band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND; | |
8066 | modulation = IEEE80211_OFDM_MODULATION | | |
8067 | IEEE80211_CCK_MODULATION; | |
8068 | priv->adapter = IPW_2915ABG; | |
8069 | priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B; | |
43f66a6c | 8070 | } else { |
afbf30a2 JK |
8071 | if (init) |
8072 | printk(KERN_INFO DRV_NAME | |
8073 | ": Detected Intel PRO/Wireless 2200BG Network " | |
8074 | "Connection\n"); | |
bf79451e | 8075 | |
afbf30a2 JK |
8076 | priv->ieee->abg_true = 0; |
8077 | band = IEEE80211_24GHZ_BAND; | |
8078 | modulation = IEEE80211_OFDM_MODULATION | | |
8079 | IEEE80211_CCK_MODULATION; | |
8080 | priv->adapter = IPW_2200BG; | |
8081 | priv->ieee->mode = IEEE_G | IEEE_B; | |
43f66a6c JK |
8082 | } |
8083 | ||
afbf30a2 JK |
8084 | priv->ieee->freq_band = band; |
8085 | priv->ieee->modulation = modulation; | |
43f66a6c | 8086 | |
afbf30a2 | 8087 | priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK; |
bf79451e | 8088 | |
afbf30a2 JK |
8089 | priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT; |
8090 | priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT; | |
43f66a6c | 8091 | |
afbf30a2 JK |
8092 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; |
8093 | priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT; | |
8094 | priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT; | |
43f66a6c | 8095 | |
afbf30a2 JK |
8096 | /* If power management is turned on, default to AC mode */ |
8097 | priv->power_mode = IPW_POWER_AC; | |
8098 | priv->tx_power = IPW_TX_POWER_DEFAULT; | |
8099 | ||
0ece35b5 | 8100 | return old_mode == priv->ieee->iw_mode; |
43f66a6c JK |
8101 | } |
8102 | ||
8103 | /* | |
8104 | * This file defines the Wireless Extension handlers. It does not | |
8105 | * define any methods of hardware manipulation and relies on the | |
8106 | * functions defined in ipw_main to provide the HW interaction. | |
bf79451e JG |
8107 | * |
8108 | * The exception to this is the use of the ipw_get_ordinal() | |
43f66a6c JK |
8109 | * function used to poll the hardware vs. making unecessary calls. |
8110 | * | |
8111 | */ | |
8112 | ||
bf79451e JG |
8113 | static int ipw_wx_get_name(struct net_device *dev, |
8114 | struct iw_request_info *info, | |
43f66a6c JK |
8115 | union iwreq_data *wrqu, char *extra) |
8116 | { | |
8117 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 8118 | mutex_lock(&priv->mutex); |
c848d0af | 8119 | if (priv->status & STATUS_RF_KILL_MASK) |
a613bffd | 8120 | strcpy(wrqu->name, "radio off"); |
c848d0af | 8121 | else if (!(priv->status & STATUS_ASSOCIATED)) |
43f66a6c | 8122 | strcpy(wrqu->name, "unassociated"); |
bf79451e | 8123 | else |
43f66a6c JK |
8124 | snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", |
8125 | ipw_modes[priv->assoc_request.ieee_mode]); | |
8126 | IPW_DEBUG_WX("Name: %s\n", wrqu->name); | |
4644151b | 8127 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8128 | return 0; |
8129 | } | |
8130 | ||
8131 | static int ipw_set_channel(struct ipw_priv *priv, u8 channel) | |
8132 | { | |
8133 | if (channel == 0) { | |
8134 | IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); | |
8135 | priv->config &= ~CFG_STATIC_CHANNEL; | |
c848d0af JK |
8136 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
8137 | "parameters.\n"); | |
8138 | ipw_associate(priv); | |
43f66a6c JK |
8139 | return 0; |
8140 | } | |
8141 | ||
8142 | priv->config |= CFG_STATIC_CHANNEL; | |
8143 | ||
8144 | if (priv->channel == channel) { | |
0edd5b44 JG |
8145 | IPW_DEBUG_INFO("Request to set channel to current value (%d)\n", |
8146 | channel); | |
43f66a6c JK |
8147 | return 0; |
8148 | } | |
8149 | ||
8150 | IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); | |
8151 | priv->channel = channel; | |
8152 | ||
b095c381 JK |
8153 | #ifdef CONFIG_IPW2200_MONITOR |
8154 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) { | |
afbf30a2 | 8155 | int i; |
b095c381 | 8156 | if (priv->status & STATUS_SCANNING) { |
afbf30a2 | 8157 | IPW_DEBUG_SCAN("Scan abort triggered due to " |
b095c381 | 8158 | "channel change.\n"); |
afbf30a2 | 8159 | ipw_abort_scan(priv); |
b095c381 JK |
8160 | } |
8161 | ||
8162 | for (i = 1000; i && (priv->status & STATUS_SCANNING); i--) | |
8163 | udelay(10); | |
8164 | ||
8165 | if (priv->status & STATUS_SCANNING) | |
8166 | IPW_DEBUG_SCAN("Still scanning...\n"); | |
8167 | else | |
8168 | IPW_DEBUG_SCAN("Took %dms to abort current scan\n", | |
8169 | 1000 - i); | |
8170 | ||
8171 | return 0; | |
43f66a6c | 8172 | } |
b095c381 JK |
8173 | #endif /* CONFIG_IPW2200_MONITOR */ |
8174 | ||
c848d0af JK |
8175 | /* Network configuration changed -- force [re]association */ |
8176 | IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n"); | |
8177 | if (!ipw_disassociate(priv)) | |
43f66a6c | 8178 | ipw_associate(priv); |
43f66a6c JK |
8179 | |
8180 | return 0; | |
8181 | } | |
8182 | ||
bf79451e JG |
8183 | static int ipw_wx_set_freq(struct net_device *dev, |
8184 | struct iw_request_info *info, | |
8185 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
8186 | { |
8187 | struct ipw_priv *priv = ieee80211_priv(dev); | |
1867b117 | 8188 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
43f66a6c | 8189 | struct iw_freq *fwrq = &wrqu->freq; |
afbf30a2 | 8190 | int ret = 0, i; |
1fe0adb4 LH |
8191 | u8 channel, flags; |
8192 | int band; | |
b095c381 JK |
8193 | |
8194 | if (fwrq->m == 0) { | |
8195 | IPW_DEBUG_WX("SET Freq/Channel -> any\n"); | |
4644151b | 8196 | mutex_lock(&priv->mutex); |
b095c381 | 8197 | ret = ipw_set_channel(priv, 0); |
4644151b | 8198 | mutex_unlock(&priv->mutex); |
b095c381 JK |
8199 | return ret; |
8200 | } | |
43f66a6c JK |
8201 | /* if setting by freq convert to channel */ |
8202 | if (fwrq->e == 1) { | |
1867b117 | 8203 | channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m); |
b095c381 JK |
8204 | if (channel == 0) |
8205 | return -EINVAL; | |
8206 | } else | |
8207 | channel = fwrq->m; | |
bf79451e | 8208 | |
1867b117 | 8209 | if (!(band = ieee80211_is_valid_channel(priv->ieee, channel))) |
b095c381 | 8210 | return -EINVAL; |
43f66a6c | 8211 | |
1fe0adb4 | 8212 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) { |
1867b117 | 8213 | i = ieee80211_channel_to_index(priv->ieee, channel); |
afbf30a2 JK |
8214 | if (i == -1) |
8215 | return -EINVAL; | |
bf79451e | 8216 | |
1fe0adb4 LH |
8217 | flags = (band == IEEE80211_24GHZ_BAND) ? |
8218 | geo->bg[i].flags : geo->a[i].flags; | |
8219 | if (flags & IEEE80211_CH_PASSIVE_ONLY) { | |
afbf30a2 JK |
8220 | IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n"); |
8221 | return -EINVAL; | |
43f66a6c JK |
8222 | } |
8223 | } | |
bf79451e | 8224 | |
43f66a6c | 8225 | IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); |
4644151b | 8226 | mutex_lock(&priv->mutex); |
b095c381 | 8227 | ret = ipw_set_channel(priv, channel); |
4644151b | 8228 | mutex_unlock(&priv->mutex); |
c848d0af | 8229 | return ret; |
43f66a6c JK |
8230 | } |
8231 | ||
bf79451e JG |
8232 | static int ipw_wx_get_freq(struct net_device *dev, |
8233 | struct iw_request_info *info, | |
43f66a6c JK |
8234 | union iwreq_data *wrqu, char *extra) |
8235 | { | |
8236 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8237 | ||
8238 | wrqu->freq.e = 0; | |
8239 | ||
8240 | /* If we are associated, trying to associate, or have a statically | |
8241 | * configured CHANNEL then return that; otherwise return ANY */ | |
4644151b | 8242 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8243 | if (priv->config & CFG_STATIC_CHANNEL || |
8244 | priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) | |
8245 | wrqu->freq.m = priv->channel; | |
bf79451e | 8246 | else |
43f66a6c JK |
8247 | wrqu->freq.m = 0; |
8248 | ||
4644151b | 8249 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8250 | IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); |
8251 | return 0; | |
8252 | } | |
8253 | ||
bf79451e JG |
8254 | static int ipw_wx_set_mode(struct net_device *dev, |
8255 | struct iw_request_info *info, | |
43f66a6c JK |
8256 | union iwreq_data *wrqu, char *extra) |
8257 | { | |
8258 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8259 | int err = 0; | |
8260 | ||
8261 | IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); | |
8262 | ||
43f66a6c | 8263 | switch (wrqu->mode) { |
b095c381 | 8264 | #ifdef CONFIG_IPW2200_MONITOR |
43f66a6c JK |
8265 | case IW_MODE_MONITOR: |
8266 | #endif | |
8267 | case IW_MODE_ADHOC: | |
8268 | case IW_MODE_INFRA: | |
8269 | break; | |
8270 | case IW_MODE_AUTO: | |
8271 | wrqu->mode = IW_MODE_INFRA; | |
8272 | break; | |
8273 | default: | |
8274 | return -EINVAL; | |
8275 | } | |
b095c381 JK |
8276 | if (wrqu->mode == priv->ieee->iw_mode) |
8277 | return 0; | |
43f66a6c | 8278 | |
4644151b | 8279 | mutex_lock(&priv->mutex); |
43f66a6c | 8280 | |
afbf30a2 JK |
8281 | ipw_sw_reset(priv, 0); |
8282 | ||
b095c381 | 8283 | #ifdef CONFIG_IPW2200_MONITOR |
bf79451e | 8284 | if (priv->ieee->iw_mode == IW_MODE_MONITOR) |
43f66a6c | 8285 | priv->net_dev->type = ARPHRD_ETHER; |
bf79451e JG |
8286 | |
8287 | if (wrqu->mode == IW_MODE_MONITOR) | |
24a47dbd MK |
8288 | #ifdef CONFIG_IEEE80211_RADIOTAP |
8289 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | |
8290 | #else | |
43f66a6c | 8291 | priv->net_dev->type = ARPHRD_IEEE80211; |
24a47dbd | 8292 | #endif |
b095c381 | 8293 | #endif /* CONFIG_IPW2200_MONITOR */ |
bf79451e | 8294 | |
bf79451e | 8295 | /* Free the existing firmware and reset the fw_loaded |
43f66a6c | 8296 | * flag so ipw_load() will bring in the new firmawre */ |
afbf30a2 | 8297 | free_firmware(); |
43f66a6c JK |
8298 | |
8299 | priv->ieee->iw_mode = wrqu->mode; | |
bf79451e | 8300 | |
c848d0af | 8301 | queue_work(priv->workqueue, &priv->adapter_restart); |
4644151b | 8302 | mutex_unlock(&priv->mutex); |
0edd5b44 | 8303 | return err; |
43f66a6c JK |
8304 | } |
8305 | ||
bf79451e | 8306 | static int ipw_wx_get_mode(struct net_device *dev, |
0edd5b44 JG |
8307 | struct iw_request_info *info, |
8308 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
8309 | { |
8310 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 8311 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8312 | wrqu->mode = priv->ieee->iw_mode; |
8313 | IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); | |
4644151b | 8314 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8315 | return 0; |
8316 | } | |
8317 | ||
43f66a6c JK |
8318 | /* Values are in microsecond */ |
8319 | static const s32 timeout_duration[] = { | |
8320 | 350000, | |
8321 | 250000, | |
8322 | 75000, | |
8323 | 37000, | |
8324 | 25000, | |
8325 | }; | |
8326 | ||
8327 | static const s32 period_duration[] = { | |
8328 | 400000, | |
8329 | 700000, | |
8330 | 1000000, | |
8331 | 1000000, | |
8332 | 1000000 | |
8333 | }; | |
8334 | ||
bf79451e JG |
8335 | static int ipw_wx_get_range(struct net_device *dev, |
8336 | struct iw_request_info *info, | |
43f66a6c JK |
8337 | union iwreq_data *wrqu, char *extra) |
8338 | { | |
8339 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8340 | struct iw_range *range = (struct iw_range *)extra; | |
1867b117 | 8341 | const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee); |
b095c381 | 8342 | int i = 0, j; |
43f66a6c JK |
8343 | |
8344 | wrqu->data.length = sizeof(*range); | |
8345 | memset(range, 0, sizeof(*range)); | |
8346 | ||
8347 | /* 54Mbs == ~27 Mb/s real (802.11g) */ | |
bf79451e | 8348 | range->throughput = 27 * 1000 * 1000; |
43f66a6c JK |
8349 | |
8350 | range->max_qual.qual = 100; | |
8351 | /* TODO: Find real max RSSI and stick here */ | |
8352 | range->max_qual.level = 0; | |
b191608a | 8353 | range->max_qual.noise = 0; |
0edd5b44 | 8354 | range->max_qual.updated = 7; /* Updated all three */ |
43f66a6c JK |
8355 | |
8356 | range->avg_qual.qual = 70; | |
8357 | /* TODO: Find real 'good' to 'bad' threshol value for RSSI */ | |
0edd5b44 | 8358 | range->avg_qual.level = 0; /* FIXME to real average level */ |
43f66a6c | 8359 | range->avg_qual.noise = 0; |
0edd5b44 | 8360 | range->avg_qual.updated = 7; /* Updated all three */ |
4644151b | 8361 | mutex_lock(&priv->mutex); |
0edd5b44 | 8362 | range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); |
43f66a6c | 8363 | |
bf79451e JG |
8364 | for (i = 0; i < range->num_bitrates; i++) |
8365 | range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) * | |
0edd5b44 | 8366 | 500000; |
bf79451e | 8367 | |
43f66a6c JK |
8368 | range->max_rts = DEFAULT_RTS_THRESHOLD; |
8369 | range->min_frag = MIN_FRAG_THRESHOLD; | |
8370 | range->max_frag = MAX_FRAG_THRESHOLD; | |
8371 | ||
8372 | range->encoding_size[0] = 5; | |
bf79451e | 8373 | range->encoding_size[1] = 13; |
43f66a6c JK |
8374 | range->num_encoding_sizes = 2; |
8375 | range->max_encoding_tokens = WEP_KEYS; | |
8376 | ||
8377 | /* Set the Wireless Extension versions */ | |
8378 | range->we_version_compiled = WIRELESS_EXT; | |
f1b50863 | 8379 | range->we_version_source = 18; |
43f66a6c | 8380 | |
b095c381 JK |
8381 | i = 0; |
8382 | if (priv->ieee->mode & (IEEE_B | IEEE_G)) { | |
8383 | for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; | |
8384 | i++, j++) { | |
8385 | range->freq[i].i = geo->bg[j].channel; | |
8386 | range->freq[i].m = geo->bg[j].freq * 100000; | |
8387 | range->freq[i].e = 1; | |
8388 | } | |
8389 | } | |
43f66a6c | 8390 | |
b095c381 JK |
8391 | if (priv->ieee->mode & IEEE_A) { |
8392 | for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; | |
8393 | i++, j++) { | |
8394 | range->freq[i].i = geo->a[j].channel; | |
8395 | range->freq[i].m = geo->a[j].freq * 100000; | |
8396 | range->freq[i].e = 1; | |
8397 | } | |
43f66a6c | 8398 | } |
b095c381 JK |
8399 | |
8400 | range->num_channels = i; | |
8401 | range->num_frequency = i; | |
8402 | ||
4644151b | 8403 | mutex_unlock(&priv->mutex); |
97a78ca9 BB |
8404 | |
8405 | /* Event capability (kernel + driver) */ | |
8406 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | | |
8407 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | | |
8408 | IW_EVENT_CAPA_MASK(SIOCGIWAP)); | |
8409 | range->event_capa[1] = IW_EVENT_CAPA_K_1; | |
43f66a6c | 8410 | |
f1b50863 DW |
8411 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
8412 | IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; | |
8413 | ||
43f66a6c JK |
8414 | IPW_DEBUG_WX("GET Range\n"); |
8415 | return 0; | |
8416 | } | |
8417 | ||
bf79451e JG |
8418 | static int ipw_wx_set_wap(struct net_device *dev, |
8419 | struct iw_request_info *info, | |
43f66a6c JK |
8420 | union iwreq_data *wrqu, char *extra) |
8421 | { | |
8422 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8423 | ||
8424 | static const unsigned char any[] = { | |
8425 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff | |
8426 | }; | |
8427 | static const unsigned char off[] = { | |
8428 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | |
8429 | }; | |
8430 | ||
bf79451e | 8431 | if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) |
43f66a6c | 8432 | return -EINVAL; |
4644151b | 8433 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8434 | if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || |
8435 | !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { | |
8436 | /* we disable mandatory BSSID association */ | |
8437 | IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); | |
8438 | priv->config &= ~CFG_STATIC_BSSID; | |
c848d0af JK |
8439 | IPW_DEBUG_ASSOC("Attempting to associate with new " |
8440 | "parameters.\n"); | |
8441 | ipw_associate(priv); | |
4644151b | 8442 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8443 | return 0; |
8444 | } | |
8445 | ||
8446 | priv->config |= CFG_STATIC_BSSID; | |
8447 | if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { | |
8448 | IPW_DEBUG_WX("BSSID set to current BSSID.\n"); | |
4644151b | 8449 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8450 | return 0; |
8451 | } | |
8452 | ||
8453 | IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n", | |
8454 | MAC_ARG(wrqu->ap_addr.sa_data)); | |
8455 | ||
8456 | memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); | |
8457 | ||
c848d0af JK |
8458 | /* Network configuration changed -- force [re]association */ |
8459 | IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n"); | |
8460 | if (!ipw_disassociate(priv)) | |
43f66a6c | 8461 | ipw_associate(priv); |
43f66a6c | 8462 | |
4644151b | 8463 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8464 | return 0; |
8465 | } | |
8466 | ||
bf79451e JG |
8467 | static int ipw_wx_get_wap(struct net_device *dev, |
8468 | struct iw_request_info *info, | |
43f66a6c JK |
8469 | union iwreq_data *wrqu, char *extra) |
8470 | { | |
8471 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8472 | /* If we are associated, trying to associate, or have a statically | |
8473 | * configured BSSID then return that; otherwise return ANY */ | |
4644151b | 8474 | mutex_lock(&priv->mutex); |
bf79451e | 8475 | if (priv->config & CFG_STATIC_BSSID || |
43f66a6c JK |
8476 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
8477 | wrqu->ap_addr.sa_family = ARPHRD_ETHER; | |
afbf30a2 | 8478 | memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN); |
43f66a6c JK |
8479 | } else |
8480 | memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); | |
8481 | ||
8482 | IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", | |
8483 | MAC_ARG(wrqu->ap_addr.sa_data)); | |
4644151b | 8484 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8485 | return 0; |
8486 | } | |
8487 | ||
bf79451e JG |
8488 | static int ipw_wx_set_essid(struct net_device *dev, |
8489 | struct iw_request_info *info, | |
43f66a6c JK |
8490 | union iwreq_data *wrqu, char *extra) |
8491 | { | |
8492 | struct ipw_priv *priv = ieee80211_priv(dev); | |
0edd5b44 | 8493 | char *essid = ""; /* ANY */ |
43f66a6c | 8494 | int length = 0; |
4644151b | 8495 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8496 | if (wrqu->essid.flags && wrqu->essid.length) { |
8497 | length = wrqu->essid.length - 1; | |
8498 | essid = extra; | |
8499 | } | |
8500 | if (length == 0) { | |
8501 | IPW_DEBUG_WX("Setting ESSID to ANY\n"); | |
afbf30a2 JK |
8502 | if ((priv->config & CFG_STATIC_ESSID) && |
8503 | !(priv->status & (STATUS_ASSOCIATED | | |
43f66a6c JK |
8504 | STATUS_ASSOCIATING))) { |
8505 | IPW_DEBUG_ASSOC("Attempting to associate with new " | |
8506 | "parameters.\n"); | |
afbf30a2 | 8507 | priv->config &= ~CFG_STATIC_ESSID; |
43f66a6c JK |
8508 | ipw_associate(priv); |
8509 | } | |
4644151b | 8510 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8511 | return 0; |
8512 | } | |
8513 | ||
8514 | length = min(length, IW_ESSID_MAX_SIZE); | |
8515 | ||
8516 | priv->config |= CFG_STATIC_ESSID; | |
8517 | ||
8518 | if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { | |
8519 | IPW_DEBUG_WX("ESSID set to current ESSID.\n"); | |
4644151b | 8520 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8521 | return 0; |
8522 | } | |
8523 | ||
8524 | IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length), | |
8525 | length); | |
8526 | ||
8527 | priv->essid_len = length; | |
8528 | memcpy(priv->essid, essid, priv->essid_len); | |
bf79451e | 8529 | |
c848d0af JK |
8530 | /* Network configuration changed -- force [re]association */ |
8531 | IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n"); | |
8532 | if (!ipw_disassociate(priv)) | |
43f66a6c | 8533 | ipw_associate(priv); |
43f66a6c | 8534 | |
4644151b | 8535 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8536 | return 0; |
8537 | } | |
8538 | ||
bf79451e JG |
8539 | static int ipw_wx_get_essid(struct net_device *dev, |
8540 | struct iw_request_info *info, | |
43f66a6c JK |
8541 | union iwreq_data *wrqu, char *extra) |
8542 | { | |
8543 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8544 | ||
8545 | /* If we are associated, trying to associate, or have a statically | |
8546 | * configured ESSID then return that; otherwise return ANY */ | |
4644151b | 8547 | mutex_lock(&priv->mutex); |
43f66a6c | 8548 | if (priv->config & CFG_STATIC_ESSID || |
bf79451e JG |
8549 | priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { |
8550 | IPW_DEBUG_WX("Getting essid: '%s'\n", | |
43f66a6c | 8551 | escape_essid(priv->essid, priv->essid_len)); |
bf79451e | 8552 | memcpy(extra, priv->essid, priv->essid_len); |
43f66a6c | 8553 | wrqu->essid.length = priv->essid_len; |
0edd5b44 | 8554 | wrqu->essid.flags = 1; /* active */ |
43f66a6c JK |
8555 | } else { |
8556 | IPW_DEBUG_WX("Getting essid: ANY\n"); | |
8557 | wrqu->essid.length = 0; | |
0edd5b44 | 8558 | wrqu->essid.flags = 0; /* active */ |
43f66a6c | 8559 | } |
4644151b | 8560 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8561 | return 0; |
8562 | } | |
8563 | ||
bf79451e JG |
8564 | static int ipw_wx_set_nick(struct net_device *dev, |
8565 | struct iw_request_info *info, | |
43f66a6c | 8566 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8567 | { |
43f66a6c JK |
8568 | struct ipw_priv *priv = ieee80211_priv(dev); |
8569 | ||
8570 | IPW_DEBUG_WX("Setting nick to '%s'\n", extra); | |
8571 | if (wrqu->data.length > IW_ESSID_MAX_SIZE) | |
8572 | return -E2BIG; | |
4644151b | 8573 | mutex_lock(&priv->mutex); |
0edd5b44 | 8574 | wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); |
43f66a6c | 8575 | memset(priv->nick, 0, sizeof(priv->nick)); |
0edd5b44 | 8576 | memcpy(priv->nick, extra, wrqu->data.length); |
43f66a6c | 8577 | IPW_DEBUG_TRACE("<<\n"); |
4644151b | 8578 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8579 | return 0; |
8580 | ||
8581 | } | |
8582 | ||
bf79451e JG |
8583 | static int ipw_wx_get_nick(struct net_device *dev, |
8584 | struct iw_request_info *info, | |
43f66a6c | 8585 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8586 | { |
43f66a6c JK |
8587 | struct ipw_priv *priv = ieee80211_priv(dev); |
8588 | IPW_DEBUG_WX("Getting nick\n"); | |
4644151b | 8589 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8590 | wrqu->data.length = strlen(priv->nick) + 1; |
8591 | memcpy(extra, priv->nick, wrqu->data.length); | |
0edd5b44 | 8592 | wrqu->data.flags = 1; /* active */ |
4644151b | 8593 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8594 | return 0; |
8595 | } | |
8596 | ||
43f66a6c JK |
8597 | static int ipw_wx_set_rate(struct net_device *dev, |
8598 | struct iw_request_info *info, | |
8599 | union iwreq_data *wrqu, char *extra) | |
bf79451e | 8600 | { |
ea2b26e0 JK |
8601 | /* TODO: We should use semaphores or locks for access to priv */ |
8602 | struct ipw_priv *priv = ieee80211_priv(dev); | |
8603 | u32 target_rate = wrqu->bitrate.value; | |
8604 | u32 fixed, mask; | |
8605 | ||
8606 | /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */ | |
8607 | /* value = X, fixed = 1 means only rate X */ | |
8608 | /* value = X, fixed = 0 means all rates lower equal X */ | |
8609 | ||
8610 | if (target_rate == -1) { | |
8611 | fixed = 0; | |
8612 | mask = IEEE80211_DEFAULT_RATES_MASK; | |
8613 | /* Now we should reassociate */ | |
8614 | goto apply; | |
8615 | } | |
8616 | ||
8617 | mask = 0; | |
8618 | fixed = wrqu->bitrate.fixed; | |
8619 | ||
8620 | if (target_rate == 1000000 || !fixed) | |
8621 | mask |= IEEE80211_CCK_RATE_1MB_MASK; | |
8622 | if (target_rate == 1000000) | |
8623 | goto apply; | |
8624 | ||
8625 | if (target_rate == 2000000 || !fixed) | |
8626 | mask |= IEEE80211_CCK_RATE_2MB_MASK; | |
8627 | if (target_rate == 2000000) | |
8628 | goto apply; | |
8629 | ||
8630 | if (target_rate == 5500000 || !fixed) | |
8631 | mask |= IEEE80211_CCK_RATE_5MB_MASK; | |
8632 | if (target_rate == 5500000) | |
8633 | goto apply; | |
8634 | ||
8635 | if (target_rate == 6000000 || !fixed) | |
8636 | mask |= IEEE80211_OFDM_RATE_6MB_MASK; | |
8637 | if (target_rate == 6000000) | |
8638 | goto apply; | |
8639 | ||
8640 | if (target_rate == 9000000 || !fixed) | |
8641 | mask |= IEEE80211_OFDM_RATE_9MB_MASK; | |
8642 | if (target_rate == 9000000) | |
8643 | goto apply; | |
8644 | ||
8645 | if (target_rate == 11000000 || !fixed) | |
8646 | mask |= IEEE80211_CCK_RATE_11MB_MASK; | |
8647 | if (target_rate == 11000000) | |
8648 | goto apply; | |
8649 | ||
8650 | if (target_rate == 12000000 || !fixed) | |
8651 | mask |= IEEE80211_OFDM_RATE_12MB_MASK; | |
8652 | if (target_rate == 12000000) | |
8653 | goto apply; | |
8654 | ||
8655 | if (target_rate == 18000000 || !fixed) | |
8656 | mask |= IEEE80211_OFDM_RATE_18MB_MASK; | |
8657 | if (target_rate == 18000000) | |
8658 | goto apply; | |
8659 | ||
8660 | if (target_rate == 24000000 || !fixed) | |
8661 | mask |= IEEE80211_OFDM_RATE_24MB_MASK; | |
8662 | if (target_rate == 24000000) | |
8663 | goto apply; | |
8664 | ||
8665 | if (target_rate == 36000000 || !fixed) | |
8666 | mask |= IEEE80211_OFDM_RATE_36MB_MASK; | |
8667 | if (target_rate == 36000000) | |
8668 | goto apply; | |
8669 | ||
8670 | if (target_rate == 48000000 || !fixed) | |
8671 | mask |= IEEE80211_OFDM_RATE_48MB_MASK; | |
8672 | if (target_rate == 48000000) | |
8673 | goto apply; | |
8674 | ||
8675 | if (target_rate == 54000000 || !fixed) | |
8676 | mask |= IEEE80211_OFDM_RATE_54MB_MASK; | |
8677 | if (target_rate == 54000000) | |
8678 | goto apply; | |
8679 | ||
8680 | IPW_DEBUG_WX("invalid rate specified, returning error\n"); | |
8681 | return -EINVAL; | |
8682 | ||
8683 | apply: | |
8684 | IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n", | |
8685 | mask, fixed ? "fixed" : "sub-rates"); | |
4644151b | 8686 | mutex_lock(&priv->mutex); |
b095c381 | 8687 | if (mask == IEEE80211_DEFAULT_RATES_MASK) { |
ea2b26e0 | 8688 | priv->config &= ~CFG_FIXED_RATE; |
b095c381 JK |
8689 | ipw_set_fixed_rate(priv, priv->ieee->mode); |
8690 | } else | |
ea2b26e0 JK |
8691 | priv->config |= CFG_FIXED_RATE; |
8692 | ||
c848d0af JK |
8693 | if (priv->rates_mask == mask) { |
8694 | IPW_DEBUG_WX("Mask set to current mask.\n"); | |
4644151b | 8695 | mutex_unlock(&priv->mutex); |
c848d0af | 8696 | return 0; |
ea2b26e0 JK |
8697 | } |
8698 | ||
c848d0af JK |
8699 | priv->rates_mask = mask; |
8700 | ||
8701 | /* Network configuration changed -- force [re]association */ | |
8702 | IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n"); | |
8703 | if (!ipw_disassociate(priv)) | |
8704 | ipw_associate(priv); | |
8705 | ||
4644151b | 8706 | mutex_unlock(&priv->mutex); |
ea2b26e0 | 8707 | return 0; |
43f66a6c JK |
8708 | } |
8709 | ||
bf79451e JG |
8710 | static int ipw_wx_get_rate(struct net_device *dev, |
8711 | struct iw_request_info *info, | |
43f66a6c | 8712 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8713 | { |
0edd5b44 | 8714 | struct ipw_priv *priv = ieee80211_priv(dev); |
4644151b | 8715 | mutex_lock(&priv->mutex); |
43f66a6c | 8716 | wrqu->bitrate.value = priv->last_rate; |
4644151b | 8717 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8718 | IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); |
8719 | return 0; | |
8720 | } | |
8721 | ||
bf79451e JG |
8722 | static int ipw_wx_set_rts(struct net_device *dev, |
8723 | struct iw_request_info *info, | |
43f66a6c | 8724 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8725 | { |
43f66a6c | 8726 | struct ipw_priv *priv = ieee80211_priv(dev); |
4644151b | 8727 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8728 | if (wrqu->rts.disabled) |
8729 | priv->rts_threshold = DEFAULT_RTS_THRESHOLD; | |
8730 | else { | |
8731 | if (wrqu->rts.value < MIN_RTS_THRESHOLD || | |
c848d0af | 8732 | wrqu->rts.value > MAX_RTS_THRESHOLD) { |
4644151b | 8733 | mutex_unlock(&priv->mutex); |
43f66a6c | 8734 | return -EINVAL; |
c848d0af | 8735 | } |
43f66a6c JK |
8736 | priv->rts_threshold = wrqu->rts.value; |
8737 | } | |
8738 | ||
8739 | ipw_send_rts_threshold(priv, priv->rts_threshold); | |
4644151b | 8740 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8741 | IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); |
8742 | return 0; | |
8743 | } | |
8744 | ||
bf79451e JG |
8745 | static int ipw_wx_get_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 | wrqu->rts.value = priv->rts_threshold; |
8752 | wrqu->rts.fixed = 0; /* no auto select */ | |
0edd5b44 | 8753 | wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); |
4644151b | 8754 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8755 | IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); |
8756 | return 0; | |
8757 | } | |
8758 | ||
bf79451e JG |
8759 | static int ipw_wx_set_txpow(struct net_device *dev, |
8760 | struct iw_request_info *info, | |
43f66a6c | 8761 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8762 | { |
43f66a6c | 8763 | struct ipw_priv *priv = ieee80211_priv(dev); |
6de9f7f2 | 8764 | int err = 0; |
43f66a6c | 8765 | |
4644151b | 8766 | mutex_lock(&priv->mutex); |
c848d0af | 8767 | if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) { |
6de9f7f2 ZY |
8768 | err = -EINPROGRESS; |
8769 | goto out; | |
43f66a6c | 8770 | } |
43f66a6c | 8771 | |
b095c381 JK |
8772 | if (!wrqu->power.fixed) |
8773 | wrqu->power.value = IPW_TX_POWER_DEFAULT; | |
8774 | ||
c848d0af | 8775 | if (wrqu->power.flags != IW_TXPOW_DBM) { |
6de9f7f2 ZY |
8776 | err = -EINVAL; |
8777 | goto out; | |
c848d0af | 8778 | } |
43f66a6c | 8779 | |
b095c381 | 8780 | if ((wrqu->power.value > IPW_TX_POWER_MAX) || |
afbf30a2 | 8781 | (wrqu->power.value < IPW_TX_POWER_MIN)) { |
6de9f7f2 ZY |
8782 | err = -EINVAL; |
8783 | goto out; | |
c848d0af | 8784 | } |
43f66a6c | 8785 | |
43f66a6c | 8786 | priv->tx_power = wrqu->power.value; |
6de9f7f2 ZY |
8787 | err = ipw_set_tx_power(priv); |
8788 | out: | |
4644151b | 8789 | mutex_unlock(&priv->mutex); |
6de9f7f2 | 8790 | return err; |
43f66a6c JK |
8791 | } |
8792 | ||
bf79451e JG |
8793 | static int ipw_wx_get_txpow(struct net_device *dev, |
8794 | struct iw_request_info *info, | |
43f66a6c | 8795 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8796 | { |
43f66a6c | 8797 | struct ipw_priv *priv = ieee80211_priv(dev); |
4644151b | 8798 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8799 | wrqu->power.value = priv->tx_power; |
8800 | wrqu->power.fixed = 1; | |
8801 | wrqu->power.flags = IW_TXPOW_DBM; | |
8802 | wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; | |
4644151b | 8803 | mutex_unlock(&priv->mutex); |
43f66a6c | 8804 | |
bf79451e | 8805 | IPW_DEBUG_WX("GET TX Power -> %s %d \n", |
22501c8e | 8806 | wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value); |
43f66a6c JK |
8807 | |
8808 | return 0; | |
8809 | } | |
8810 | ||
bf79451e | 8811 | static int ipw_wx_set_frag(struct net_device *dev, |
0edd5b44 JG |
8812 | struct iw_request_info *info, |
8813 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
8814 | { |
8815 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 8816 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8817 | if (wrqu->frag.disabled) |
8818 | priv->ieee->fts = DEFAULT_FTS; | |
8819 | else { | |
8820 | if (wrqu->frag.value < MIN_FRAG_THRESHOLD || | |
b095c381 | 8821 | wrqu->frag.value > MAX_FRAG_THRESHOLD) { |
4644151b | 8822 | mutex_unlock(&priv->mutex); |
43f66a6c | 8823 | return -EINVAL; |
b095c381 | 8824 | } |
bf79451e | 8825 | |
43f66a6c JK |
8826 | priv->ieee->fts = wrqu->frag.value & ~0x1; |
8827 | } | |
8828 | ||
8829 | ipw_send_frag_threshold(priv, wrqu->frag.value); | |
4644151b | 8830 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8831 | IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); |
8832 | return 0; | |
8833 | } | |
8834 | ||
bf79451e | 8835 | static int ipw_wx_get_frag(struct net_device *dev, |
0edd5b44 JG |
8836 | struct iw_request_info *info, |
8837 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
8838 | { |
8839 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 8840 | mutex_lock(&priv->mutex); |
43f66a6c JK |
8841 | wrqu->frag.value = priv->ieee->fts; |
8842 | wrqu->frag.fixed = 0; /* no auto select */ | |
0edd5b44 | 8843 | wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); |
4644151b | 8844 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
8845 | IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); |
8846 | ||
8847 | return 0; | |
8848 | } | |
8849 | ||
bf79451e JG |
8850 | static int ipw_wx_set_retry(struct net_device *dev, |
8851 | struct iw_request_info *info, | |
43f66a6c | 8852 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8853 | { |
afbf30a2 JK |
8854 | struct ipw_priv *priv = ieee80211_priv(dev); |
8855 | ||
8856 | if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled) | |
8857 | return -EINVAL; | |
8858 | ||
8859 | if (!(wrqu->retry.flags & IW_RETRY_LIMIT)) | |
8860 | return 0; | |
8861 | ||
8862 | if (wrqu->retry.value < 0 || wrqu->retry.value > 255) | |
8863 | return -EINVAL; | |
8864 | ||
4644151b | 8865 | mutex_lock(&priv->mutex); |
afbf30a2 JK |
8866 | if (wrqu->retry.flags & IW_RETRY_MIN) |
8867 | priv->short_retry_limit = (u8) wrqu->retry.value; | |
8868 | else if (wrqu->retry.flags & IW_RETRY_MAX) | |
8869 | priv->long_retry_limit = (u8) wrqu->retry.value; | |
8870 | else { | |
8871 | priv->short_retry_limit = (u8) wrqu->retry.value; | |
8872 | priv->long_retry_limit = (u8) wrqu->retry.value; | |
8873 | } | |
8874 | ||
8875 | ipw_send_retry_limit(priv, priv->short_retry_limit, | |
8876 | priv->long_retry_limit); | |
4644151b | 8877 | mutex_unlock(&priv->mutex); |
afbf30a2 JK |
8878 | IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n", |
8879 | priv->short_retry_limit, priv->long_retry_limit); | |
8880 | return 0; | |
43f66a6c JK |
8881 | } |
8882 | ||
bf79451e JG |
8883 | static int ipw_wx_get_retry(struct net_device *dev, |
8884 | struct iw_request_info *info, | |
43f66a6c | 8885 | union iwreq_data *wrqu, char *extra) |
bf79451e | 8886 | { |
afbf30a2 JK |
8887 | struct ipw_priv *priv = ieee80211_priv(dev); |
8888 | ||
4644151b | 8889 | mutex_lock(&priv->mutex); |
afbf30a2 JK |
8890 | wrqu->retry.disabled = 0; |
8891 | ||
8892 | if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { | |
4644151b | 8893 | mutex_unlock(&priv->mutex); |
afbf30a2 JK |
8894 | return -EINVAL; |
8895 | } | |
8896 | ||
8897 | if (wrqu->retry.flags & IW_RETRY_MAX) { | |
8898 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX; | |
8899 | wrqu->retry.value = priv->long_retry_limit; | |
8900 | } else if (wrqu->retry.flags & IW_RETRY_MIN) { | |
8901 | wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN; | |
8902 | wrqu->retry.value = priv->short_retry_limit; | |
8903 | } else { | |
8904 | wrqu->retry.flags = IW_RETRY_LIMIT; | |
8905 | wrqu->retry.value = priv->short_retry_limit; | |
8906 | } | |
4644151b | 8907 | mutex_unlock(&priv->mutex); |
afbf30a2 JK |
8908 | |
8909 | IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value); | |
8910 | ||
8911 | return 0; | |
8912 | } | |
8913 | ||
afbf30a2 JK |
8914 | static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid, |
8915 | int essid_len) | |
8916 | { | |
8917 | struct ipw_scan_request_ext scan; | |
8918 | int err = 0, scan_type; | |
8919 | ||
efb3442c PE |
8920 | if (!(priv->status & STATUS_INIT) || |
8921 | (priv->status & STATUS_EXIT_PENDING)) | |
8922 | return 0; | |
8923 | ||
4644151b | 8924 | mutex_lock(&priv->mutex); |
afbf30a2 JK |
8925 | |
8926 | if (priv->status & STATUS_RF_KILL_MASK) { | |
8927 | IPW_DEBUG_HC("Aborting scan due to RF kill activation\n"); | |
8928 | priv->status |= STATUS_SCAN_PENDING; | |
8929 | goto done; | |
8930 | } | |
8931 | ||
8932 | IPW_DEBUG_HC("starting request direct scan!\n"); | |
8933 | ||
8934 | if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) { | |
d834a41c OK |
8935 | /* We should not sleep here; otherwise we will block most |
8936 | * of the system (for instance, we hold rtnl_lock when we | |
8937 | * get here). | |
8938 | */ | |
8939 | err = -EAGAIN; | |
8940 | goto done; | |
afbf30a2 JK |
8941 | } |
8942 | memset(&scan, 0, sizeof(scan)); | |
8943 | ||
8944 | if (priv->config & CFG_SPEED_SCAN) | |
8945 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | |
8946 | cpu_to_le16(30); | |
8947 | else | |
8948 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = | |
8949 | cpu_to_le16(20); | |
8950 | ||
8951 | scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = | |
8952 | cpu_to_le16(20); | |
1fe0adb4 | 8953 | scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120); |
afbf30a2 JK |
8954 | scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20); |
8955 | ||
8956 | scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee)); | |
8957 | ||
8958 | err = ipw_send_ssid(priv, essid, essid_len); | |
8959 | if (err) { | |
8960 | IPW_DEBUG_HC("Attempt to send SSID command failed\n"); | |
8961 | goto done; | |
8962 | } | |
8963 | scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; | |
8964 | ||
8965 | ipw_add_scan_channels(priv, &scan, scan_type); | |
8966 | ||
8967 | err = ipw_send_scan_request_ext(priv, &scan); | |
8968 | if (err) { | |
8969 | IPW_DEBUG_HC("Sending scan command failed: %08X\n", err); | |
8970 | goto done; | |
8971 | } | |
8972 | ||
8973 | priv->status |= STATUS_SCANNING; | |
8974 | ||
8975 | done: | |
4644151b | 8976 | mutex_unlock(&priv->mutex); |
afbf30a2 | 8977 | return err; |
43f66a6c JK |
8978 | } |
8979 | ||
bf79451e JG |
8980 | static int ipw_wx_set_scan(struct net_device *dev, |
8981 | struct iw_request_info *info, | |
43f66a6c JK |
8982 | union iwreq_data *wrqu, char *extra) |
8983 | { | |
8984 | struct ipw_priv *priv = ieee80211_priv(dev); | |
afbf30a2 JK |
8985 | struct iw_scan_req *req = NULL; |
8986 | if (wrqu->data.length | |
8987 | && wrqu->data.length == sizeof(struct iw_scan_req)) { | |
8988 | req = (struct iw_scan_req *)extra; | |
8989 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { | |
8990 | ipw_request_direct_scan(priv, req->essid, | |
8991 | req->essid_len); | |
8992 | return 0; | |
8993 | } | |
8994 | } | |
8935f39e | 8995 | |
43f66a6c | 8996 | IPW_DEBUG_WX("Start scan\n"); |
b095c381 JK |
8997 | |
8998 | queue_work(priv->workqueue, &priv->request_scan); | |
8999 | ||
43f66a6c JK |
9000 | return 0; |
9001 | } | |
9002 | ||
bf79451e JG |
9003 | static int ipw_wx_get_scan(struct net_device *dev, |
9004 | struct iw_request_info *info, | |
43f66a6c | 9005 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9006 | { |
43f66a6c JK |
9007 | struct ipw_priv *priv = ieee80211_priv(dev); |
9008 | return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra); | |
9009 | } | |
9010 | ||
bf79451e | 9011 | static int ipw_wx_set_encode(struct net_device *dev, |
0edd5b44 JG |
9012 | struct iw_request_info *info, |
9013 | union iwreq_data *wrqu, char *key) | |
43f66a6c JK |
9014 | { |
9015 | struct ipw_priv *priv = ieee80211_priv(dev); | |
afbf30a2 | 9016 | int ret; |
caeff81b | 9017 | u32 cap = priv->capability; |
afbf30a2 | 9018 | |
4644151b | 9019 | mutex_lock(&priv->mutex); |
afbf30a2 | 9020 | ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); |
afbf30a2 | 9021 | |
caeff81b HL |
9022 | /* In IBSS mode, we need to notify the firmware to update |
9023 | * the beacon info after we changed the capability. */ | |
9024 | if (cap != priv->capability && | |
9025 | priv->ieee->iw_mode == IW_MODE_ADHOC && | |
9026 | priv->status & STATUS_ASSOCIATED) | |
9027 | ipw_disassociate(priv); | |
9028 | ||
4644151b | 9029 | mutex_unlock(&priv->mutex); |
afbf30a2 | 9030 | return ret; |
43f66a6c JK |
9031 | } |
9032 | ||
bf79451e | 9033 | static int ipw_wx_get_encode(struct net_device *dev, |
0edd5b44 JG |
9034 | struct iw_request_info *info, |
9035 | union iwreq_data *wrqu, char *key) | |
43f66a6c JK |
9036 | { |
9037 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9038 | return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key); | |
9039 | } | |
9040 | ||
bf79451e | 9041 | static int ipw_wx_set_power(struct net_device *dev, |
0edd5b44 JG |
9042 | struct iw_request_info *info, |
9043 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
9044 | { |
9045 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9046 | int err; | |
4644151b | 9047 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9048 | if (wrqu->power.disabled) { |
9049 | priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); | |
9050 | err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); | |
9051 | if (err) { | |
9052 | IPW_DEBUG_WX("failed setting power mode.\n"); | |
4644151b | 9053 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9054 | return err; |
9055 | } | |
43f66a6c | 9056 | IPW_DEBUG_WX("SET Power Management Mode -> off\n"); |
4644151b | 9057 | mutex_unlock(&priv->mutex); |
43f66a6c | 9058 | return 0; |
bf79451e | 9059 | } |
43f66a6c JK |
9060 | |
9061 | switch (wrqu->power.flags & IW_POWER_MODE) { | |
0edd5b44 JG |
9062 | case IW_POWER_ON: /* If not specified */ |
9063 | case IW_POWER_MODE: /* If set all mask */ | |
9064 | case IW_POWER_ALL_R: /* If explicitely state all */ | |
43f66a6c | 9065 | break; |
0edd5b44 | 9066 | default: /* Otherwise we don't support it */ |
43f66a6c JK |
9067 | IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", |
9068 | wrqu->power.flags); | |
4644151b | 9069 | mutex_unlock(&priv->mutex); |
bf79451e | 9070 | return -EOPNOTSUPP; |
43f66a6c | 9071 | } |
bf79451e | 9072 | |
43f66a6c JK |
9073 | /* If the user hasn't specified a power management mode yet, default |
9074 | * to BATTERY */ | |
0edd5b44 | 9075 | if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC) |
43f66a6c | 9076 | priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY; |
bf79451e | 9077 | else |
43f66a6c JK |
9078 | priv->power_mode = IPW_POWER_ENABLED | priv->power_mode; |
9079 | err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); | |
9080 | if (err) { | |
9081 | IPW_DEBUG_WX("failed setting power mode.\n"); | |
4644151b | 9082 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9083 | return err; |
9084 | } | |
9085 | ||
0edd5b44 | 9086 | IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); |
4644151b | 9087 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9088 | return 0; |
9089 | } | |
9090 | ||
bf79451e | 9091 | static int ipw_wx_get_power(struct net_device *dev, |
0edd5b44 JG |
9092 | struct iw_request_info *info, |
9093 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
9094 | { |
9095 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 9096 | mutex_lock(&priv->mutex); |
a613bffd | 9097 | if (!(priv->power_mode & IPW_POWER_ENABLED)) |
43f66a6c | 9098 | wrqu->power.disabled = 1; |
a613bffd | 9099 | else |
43f66a6c | 9100 | wrqu->power.disabled = 0; |
43f66a6c | 9101 | |
4644151b | 9102 | mutex_unlock(&priv->mutex); |
43f66a6c | 9103 | IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); |
bf79451e | 9104 | |
43f66a6c JK |
9105 | return 0; |
9106 | } | |
9107 | ||
bf79451e | 9108 | static int ipw_wx_set_powermode(struct net_device *dev, |
0edd5b44 JG |
9109 | struct iw_request_info *info, |
9110 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
9111 | { |
9112 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9113 | int mode = *(int *)extra; | |
9114 | int err; | |
4644151b | 9115 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9116 | if ((mode < 1) || (mode > IPW_POWER_LIMIT)) { |
9117 | mode = IPW_POWER_AC; | |
9118 | priv->power_mode = mode; | |
9119 | } else { | |
9120 | priv->power_mode = IPW_POWER_ENABLED | mode; | |
9121 | } | |
bf79451e | 9122 | |
43f66a6c JK |
9123 | if (priv->power_mode != mode) { |
9124 | err = ipw_send_power_mode(priv, mode); | |
bf79451e | 9125 | |
43f66a6c JK |
9126 | if (err) { |
9127 | IPW_DEBUG_WX("failed setting power mode.\n"); | |
4644151b | 9128 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9129 | return err; |
9130 | } | |
9131 | } | |
4644151b | 9132 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9133 | return 0; |
9134 | } | |
9135 | ||
9136 | #define MAX_WX_STRING 80 | |
bf79451e | 9137 | static int ipw_wx_get_powermode(struct net_device *dev, |
0edd5b44 JG |
9138 | struct iw_request_info *info, |
9139 | union iwreq_data *wrqu, char *extra) | |
43f66a6c JK |
9140 | { |
9141 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9142 | int level = IPW_POWER_LEVEL(priv->power_mode); | |
9143 | char *p = extra; | |
9144 | ||
9145 | p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level); | |
9146 | ||
9147 | switch (level) { | |
9148 | case IPW_POWER_AC: | |
9149 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)"); | |
9150 | break; | |
9151 | case IPW_POWER_BATTERY: | |
9152 | p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)"); | |
9153 | break; | |
9154 | default: | |
9155 | p += snprintf(p, MAX_WX_STRING - (p - extra), | |
bf79451e | 9156 | "(Timeout %dms, Period %dms)", |
43f66a6c JK |
9157 | timeout_duration[level - 1] / 1000, |
9158 | period_duration[level - 1] / 1000); | |
9159 | } | |
9160 | ||
9161 | if (!(priv->power_mode & IPW_POWER_ENABLED)) | |
0edd5b44 | 9162 | p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF"); |
43f66a6c JK |
9163 | |
9164 | wrqu->data.length = p - extra + 1; | |
9165 | ||
9166 | return 0; | |
9167 | } | |
9168 | ||
9169 | static int ipw_wx_set_wireless_mode(struct net_device *dev, | |
0edd5b44 JG |
9170 | struct iw_request_info *info, |
9171 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9172 | { |
0edd5b44 | 9173 | struct ipw_priv *priv = ieee80211_priv(dev); |
43f66a6c JK |
9174 | int mode = *(int *)extra; |
9175 | u8 band = 0, modulation = 0; | |
9176 | ||
9177 | if (mode == 0 || mode & ~IEEE_MODE_MASK) { | |
0edd5b44 | 9178 | IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); |
43f66a6c JK |
9179 | return -EINVAL; |
9180 | } | |
4644151b | 9181 | mutex_lock(&priv->mutex); |
43f66a6c | 9182 | if (priv->adapter == IPW_2915ABG) { |
a33a1982 | 9183 | priv->ieee->abg_true = 1; |
43f66a6c JK |
9184 | if (mode & IEEE_A) { |
9185 | band |= IEEE80211_52GHZ_BAND; | |
9186 | modulation |= IEEE80211_OFDM_MODULATION; | |
9187 | } else | |
a33a1982 | 9188 | priv->ieee->abg_true = 0; |
43f66a6c JK |
9189 | } else { |
9190 | if (mode & IEEE_A) { | |
9191 | IPW_WARNING("Attempt to set 2200BG into " | |
9192 | "802.11a mode\n"); | |
4644151b | 9193 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9194 | return -EINVAL; |
9195 | } | |
9196 | ||
a33a1982 | 9197 | priv->ieee->abg_true = 0; |
43f66a6c JK |
9198 | } |
9199 | ||
9200 | if (mode & IEEE_B) { | |
9201 | band |= IEEE80211_24GHZ_BAND; | |
9202 | modulation |= IEEE80211_CCK_MODULATION; | |
9203 | } else | |
a33a1982 | 9204 | priv->ieee->abg_true = 0; |
bf79451e | 9205 | |
43f66a6c JK |
9206 | if (mode & IEEE_G) { |
9207 | band |= IEEE80211_24GHZ_BAND; | |
9208 | modulation |= IEEE80211_OFDM_MODULATION; | |
9209 | } else | |
a33a1982 | 9210 | priv->ieee->abg_true = 0; |
43f66a6c JK |
9211 | |
9212 | priv->ieee->mode = mode; | |
9213 | priv->ieee->freq_band = band; | |
9214 | priv->ieee->modulation = modulation; | |
0edd5b44 | 9215 | init_supported_rates(priv, &priv->rates); |
43f66a6c | 9216 | |
c848d0af JK |
9217 | /* Network configuration changed -- force [re]association */ |
9218 | IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n"); | |
9219 | if (!ipw_disassociate(priv)) { | |
43f66a6c | 9220 | ipw_send_supported_rates(priv, &priv->rates); |
c848d0af JK |
9221 | ipw_associate(priv); |
9222 | } | |
43f66a6c | 9223 | |
a613bffd JK |
9224 | /* Update the band LEDs */ |
9225 | ipw_led_band_on(priv); | |
43f66a6c | 9226 | |
bf79451e | 9227 | IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", |
43f66a6c | 9228 | mode & IEEE_A ? 'a' : '.', |
0edd5b44 | 9229 | mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); |
4644151b | 9230 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9231 | return 0; |
9232 | } | |
9233 | ||
9234 | static int ipw_wx_get_wireless_mode(struct net_device *dev, | |
0edd5b44 JG |
9235 | struct iw_request_info *info, |
9236 | union iwreq_data *wrqu, char *extra) | |
43f66a6c | 9237 | { |
0edd5b44 | 9238 | struct ipw_priv *priv = ieee80211_priv(dev); |
4644151b | 9239 | mutex_lock(&priv->mutex); |
ea2b26e0 JK |
9240 | switch (priv->ieee->mode) { |
9241 | case IEEE_A: | |
43f66a6c JK |
9242 | strncpy(extra, "802.11a (1)", MAX_WX_STRING); |
9243 | break; | |
ea2b26e0 JK |
9244 | case IEEE_B: |
9245 | strncpy(extra, "802.11b (2)", MAX_WX_STRING); | |
9246 | break; | |
9247 | case IEEE_A | IEEE_B: | |
9248 | strncpy(extra, "802.11ab (3)", MAX_WX_STRING); | |
9249 | break; | |
9250 | case IEEE_G: | |
9251 | strncpy(extra, "802.11g (4)", MAX_WX_STRING); | |
9252 | break; | |
9253 | case IEEE_A | IEEE_G: | |
9254 | strncpy(extra, "802.11ag (5)", MAX_WX_STRING); | |
9255 | break; | |
9256 | case IEEE_B | IEEE_G: | |
9257 | strncpy(extra, "802.11bg (6)", MAX_WX_STRING); | |
9258 | break; | |
9259 | case IEEE_A | IEEE_B | IEEE_G: | |
9260 | strncpy(extra, "802.11abg (7)", MAX_WX_STRING); | |
9261 | break; | |
9262 | default: | |
9263 | strncpy(extra, "unknown", MAX_WX_STRING); | |
43f66a6c | 9264 | break; |
bf79451e JG |
9265 | } |
9266 | ||
43f66a6c JK |
9267 | IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); |
9268 | ||
0edd5b44 | 9269 | wrqu->data.length = strlen(extra) + 1; |
4644151b | 9270 | mutex_unlock(&priv->mutex); |
b095c381 JK |
9271 | |
9272 | return 0; | |
9273 | } | |
9274 | ||
9275 | static int ipw_wx_set_preamble(struct net_device *dev, | |
9276 | struct iw_request_info *info, | |
9277 | union iwreq_data *wrqu, char *extra) | |
9278 | { | |
9279 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9280 | int mode = *(int *)extra; | |
4644151b | 9281 | mutex_lock(&priv->mutex); |
b095c381 JK |
9282 | /* Switching from SHORT -> LONG requires a disassociation */ |
9283 | if (mode == 1) { | |
9284 | if (!(priv->config & CFG_PREAMBLE_LONG)) { | |
9285 | priv->config |= CFG_PREAMBLE_LONG; | |
9286 | ||
9287 | /* Network configuration changed -- force [re]association */ | |
9288 | IPW_DEBUG_ASSOC | |
9289 | ("[re]association triggered due to preamble change.\n"); | |
9290 | if (!ipw_disassociate(priv)) | |
9291 | ipw_associate(priv); | |
9292 | } | |
9293 | goto done; | |
9294 | } | |
43f66a6c | 9295 | |
b095c381 JK |
9296 | if (mode == 0) { |
9297 | priv->config &= ~CFG_PREAMBLE_LONG; | |
9298 | goto done; | |
9299 | } | |
4644151b | 9300 | mutex_unlock(&priv->mutex); |
b095c381 JK |
9301 | return -EINVAL; |
9302 | ||
9303 | done: | |
4644151b | 9304 | mutex_unlock(&priv->mutex); |
b095c381 JK |
9305 | return 0; |
9306 | } | |
9307 | ||
9308 | static int ipw_wx_get_preamble(struct net_device *dev, | |
9309 | struct iw_request_info *info, | |
9310 | union iwreq_data *wrqu, char *extra) | |
9311 | { | |
9312 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 9313 | mutex_lock(&priv->mutex); |
b095c381 JK |
9314 | if (priv->config & CFG_PREAMBLE_LONG) |
9315 | snprintf(wrqu->name, IFNAMSIZ, "long (1)"); | |
9316 | else | |
9317 | snprintf(wrqu->name, IFNAMSIZ, "auto (0)"); | |
4644151b | 9318 | mutex_unlock(&priv->mutex); |
0edd5b44 | 9319 | return 0; |
43f66a6c JK |
9320 | } |
9321 | ||
b095c381 JK |
9322 | #ifdef CONFIG_IPW2200_MONITOR |
9323 | static int ipw_wx_set_monitor(struct net_device *dev, | |
bf79451e | 9324 | struct iw_request_info *info, |
43f66a6c | 9325 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9326 | { |
43f66a6c JK |
9327 | struct ipw_priv *priv = ieee80211_priv(dev); |
9328 | int *parms = (int *)extra; | |
9329 | int enable = (parms[0] > 0); | |
4644151b | 9330 | mutex_lock(&priv->mutex); |
b095c381 | 9331 | IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]); |
43f66a6c JK |
9332 | if (enable) { |
9333 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { | |
24a47dbd MK |
9334 | #ifdef CONFIG_IEEE80211_RADIOTAP |
9335 | priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP; | |
9336 | #else | |
43f66a6c | 9337 | priv->net_dev->type = ARPHRD_IEEE80211; |
24a47dbd | 9338 | #endif |
b095c381 | 9339 | queue_work(priv->workqueue, &priv->adapter_restart); |
43f66a6c | 9340 | } |
bf79451e | 9341 | |
43f66a6c JK |
9342 | ipw_set_channel(priv, parms[1]); |
9343 | } else { | |
b095c381 | 9344 | if (priv->ieee->iw_mode != IW_MODE_MONITOR) { |
4644151b | 9345 | mutex_unlock(&priv->mutex); |
43f66a6c | 9346 | return 0; |
b095c381 | 9347 | } |
43f66a6c | 9348 | priv->net_dev->type = ARPHRD_ETHER; |
b095c381 | 9349 | queue_work(priv->workqueue, &priv->adapter_restart); |
43f66a6c | 9350 | } |
4644151b | 9351 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9352 | return 0; |
9353 | } | |
9354 | ||
b095c381 JK |
9355 | #endif // CONFIG_IPW2200_MONITOR |
9356 | ||
bf79451e JG |
9357 | static int ipw_wx_reset(struct net_device *dev, |
9358 | struct iw_request_info *info, | |
43f66a6c | 9359 | union iwreq_data *wrqu, char *extra) |
bf79451e | 9360 | { |
43f66a6c JK |
9361 | struct ipw_priv *priv = ieee80211_priv(dev); |
9362 | IPW_DEBUG_WX("RESET\n"); | |
b095c381 JK |
9363 | queue_work(priv->workqueue, &priv->adapter_restart); |
9364 | return 0; | |
9365 | } | |
9366 | ||
b095c381 JK |
9367 | static int ipw_wx_sw_reset(struct net_device *dev, |
9368 | struct iw_request_info *info, | |
9369 | union iwreq_data *wrqu, char *extra) | |
ea2b26e0 JK |
9370 | { |
9371 | struct ipw_priv *priv = ieee80211_priv(dev); | |
b095c381 JK |
9372 | union iwreq_data wrqu_sec = { |
9373 | .encoding = { | |
9374 | .flags = IW_ENCODE_DISABLED, | |
9375 | }, | |
9376 | }; | |
afbf30a2 | 9377 | int ret; |
c848d0af | 9378 | |
b095c381 | 9379 | IPW_DEBUG_WX("SW_RESET\n"); |
ea2b26e0 | 9380 | |
4644151b | 9381 | mutex_lock(&priv->mutex); |
ea2b26e0 | 9382 | |
afbf30a2 JK |
9383 | ret = ipw_sw_reset(priv, 0); |
9384 | if (!ret) { | |
9385 | free_firmware(); | |
9386 | ipw_adapter_restart(priv); | |
9387 | } | |
ea2b26e0 | 9388 | |
b095c381 JK |
9389 | /* The SW reset bit might have been toggled on by the 'disable' |
9390 | * module parameter, so take appropriate action */ | |
9391 | ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW); | |
ea2b26e0 | 9392 | |
4644151b | 9393 | mutex_unlock(&priv->mutex); |
b095c381 | 9394 | ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL); |
4644151b | 9395 | mutex_lock(&priv->mutex); |
bf79451e | 9396 | |
b095c381 JK |
9397 | if (!(priv->status & STATUS_RF_KILL_MASK)) { |
9398 | /* Configuration likely changed -- force [re]association */ | |
9399 | IPW_DEBUG_ASSOC("[re]association triggered due to sw " | |
9400 | "reset.\n"); | |
9401 | if (!ipw_disassociate(priv)) | |
9402 | ipw_associate(priv); | |
43f66a6c | 9403 | } |
b095c381 | 9404 | |
4644151b | 9405 | mutex_unlock(&priv->mutex); |
43f66a6c | 9406 | |
43f66a6c JK |
9407 | return 0; |
9408 | } | |
43f66a6c JK |
9409 | |
9410 | /* Rebase the WE IOCTLs to zero for the handler array */ | |
9411 | #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] | |
0edd5b44 | 9412 | static iw_handler ipw_wx_handlers[] = { |
ea2b26e0 JK |
9413 | IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, |
9414 | IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, | |
9415 | IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, | |
9416 | IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, | |
9417 | IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, | |
9418 | IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, | |
9419 | IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, | |
9420 | IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, | |
9421 | IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, | |
9422 | IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, | |
9423 | IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, | |
9424 | IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, | |
9425 | IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, | |
9426 | IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, | |
9427 | IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, | |
9428 | IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, | |
9429 | IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, | |
9430 | IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, | |
9431 | IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, | |
9432 | IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, | |
9433 | IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, | |
9434 | IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, | |
9435 | IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, | |
9436 | IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, | |
9437 | IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, | |
9438 | IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, | |
9439 | IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, | |
9440 | IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, | |
a613bffd JK |
9441 | IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy, |
9442 | IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy, | |
9443 | IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy, | |
9444 | IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy, | |
afbf30a2 JK |
9445 | IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie, |
9446 | IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie, | |
9447 | IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme, | |
9448 | IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth, | |
9449 | IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth, | |
9450 | IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext, | |
9451 | IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext, | |
43f66a6c JK |
9452 | }; |
9453 | ||
b095c381 JK |
9454 | enum { |
9455 | IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV, | |
9456 | IPW_PRIV_GET_POWER, | |
9457 | IPW_PRIV_SET_MODE, | |
9458 | IPW_PRIV_GET_MODE, | |
9459 | IPW_PRIV_SET_PREAMBLE, | |
9460 | IPW_PRIV_GET_PREAMBLE, | |
9461 | IPW_PRIV_RESET, | |
9462 | IPW_PRIV_SW_RESET, | |
9463 | #ifdef CONFIG_IPW2200_MONITOR | |
9464 | IPW_PRIV_SET_MONITOR, | |
9465 | #endif | |
9466 | }; | |
43f66a6c | 9467 | |
bf79451e | 9468 | static struct iw_priv_args ipw_priv_args[] = { |
43f66a6c | 9469 | { |
0edd5b44 JG |
9470 | .cmd = IPW_PRIV_SET_POWER, |
9471 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
9472 | .name = "set_power"}, | |
43f66a6c | 9473 | { |
0edd5b44 JG |
9474 | .cmd = IPW_PRIV_GET_POWER, |
9475 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, | |
9476 | .name = "get_power"}, | |
43f66a6c | 9477 | { |
0edd5b44 JG |
9478 | .cmd = IPW_PRIV_SET_MODE, |
9479 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
9480 | .name = "set_mode"}, | |
43f66a6c | 9481 | { |
0edd5b44 JG |
9482 | .cmd = IPW_PRIV_GET_MODE, |
9483 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, | |
9484 | .name = "get_mode"}, | |
43f66a6c | 9485 | { |
ea2b26e0 JK |
9486 | .cmd = IPW_PRIV_SET_PREAMBLE, |
9487 | .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
9488 | .name = "set_preamble"}, | |
9489 | { | |
9490 | .cmd = IPW_PRIV_GET_PREAMBLE, | |
9491 | .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, | |
9492 | .name = "get_preamble"}, | |
43f66a6c | 9493 | { |
0edd5b44 JG |
9494 | IPW_PRIV_RESET, |
9495 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, | |
b095c381 JK |
9496 | { |
9497 | IPW_PRIV_SW_RESET, | |
9498 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"}, | |
9499 | #ifdef CONFIG_IPW2200_MONITOR | |
9500 | { | |
9501 | IPW_PRIV_SET_MONITOR, | |
9502 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, | |
9503 | #endif /* CONFIG_IPW2200_MONITOR */ | |
43f66a6c JK |
9504 | }; |
9505 | ||
9506 | static iw_handler ipw_priv_handler[] = { | |
9507 | ipw_wx_set_powermode, | |
9508 | ipw_wx_get_powermode, | |
9509 | ipw_wx_set_wireless_mode, | |
9510 | ipw_wx_get_wireless_mode, | |
ea2b26e0 JK |
9511 | ipw_wx_set_preamble, |
9512 | ipw_wx_get_preamble, | |
bf79451e | 9513 | ipw_wx_reset, |
b095c381 JK |
9514 | ipw_wx_sw_reset, |
9515 | #ifdef CONFIG_IPW2200_MONITOR | |
9516 | ipw_wx_set_monitor, | |
43f66a6c JK |
9517 | #endif |
9518 | }; | |
9519 | ||
0edd5b44 | 9520 | static struct iw_handler_def ipw_wx_handler_def = { |
ea2b26e0 JK |
9521 | .standard = ipw_wx_handlers, |
9522 | .num_standard = ARRAY_SIZE(ipw_wx_handlers), | |
9523 | .num_private = ARRAY_SIZE(ipw_priv_handler), | |
9524 | .num_private_args = ARRAY_SIZE(ipw_priv_args), | |
9525 | .private = ipw_priv_handler, | |
9526 | .private_args = ipw_priv_args, | |
97a78ca9 | 9527 | .get_wireless_stats = ipw_get_wireless_stats, |
43f66a6c JK |
9528 | }; |
9529 | ||
43f66a6c JK |
9530 | /* |
9531 | * Get wireless statistics. | |
9532 | * Called by /proc/net/wireless | |
9533 | * Also called by SIOCGIWSTATS | |
9534 | */ | |
0edd5b44 | 9535 | static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev) |
43f66a6c JK |
9536 | { |
9537 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9538 | struct iw_statistics *wstats; | |
bf79451e | 9539 | |
43f66a6c JK |
9540 | wstats = &priv->wstats; |
9541 | ||
ea2b26e0 | 9542 | /* if hw is disabled, then ipw_get_ordinal() can't be called. |
afbf30a2 | 9543 | * netdev->get_wireless_stats seems to be called before fw is |
43f66a6c JK |
9544 | * initialized. STATUS_ASSOCIATED will only be set if the hw is up |
9545 | * and associated; if not associcated, the values are all meaningless | |
9546 | * anyway, so set them all to NULL and INVALID */ | |
9547 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
9548 | wstats->miss.beacon = 0; | |
9549 | wstats->discard.retries = 0; | |
9550 | wstats->qual.qual = 0; | |
9551 | wstats->qual.level = 0; | |
9552 | wstats->qual.noise = 0; | |
9553 | wstats->qual.updated = 7; | |
9554 | wstats->qual.updated |= IW_QUAL_NOISE_INVALID | | |
0edd5b44 | 9555 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
43f66a6c | 9556 | return wstats; |
bf79451e | 9557 | } |
43f66a6c JK |
9558 | |
9559 | wstats->qual.qual = priv->quality; | |
9560 | wstats->qual.level = average_value(&priv->average_rssi); | |
9561 | wstats->qual.noise = average_value(&priv->average_noise); | |
9562 | wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | | |
b191608a | 9563 | IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM; |
43f66a6c JK |
9564 | |
9565 | wstats->miss.beacon = average_value(&priv->average_missed_beacons); | |
9566 | wstats->discard.retries = priv->last_tx_failures; | |
9567 | wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable; | |
bf79451e | 9568 | |
43f66a6c JK |
9569 | /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len)) |
9570 | goto fail_get_ordinal; | |
9571 | wstats->discard.retries += tx_retry; */ | |
bf79451e | 9572 | |
43f66a6c JK |
9573 | return wstats; |
9574 | } | |
9575 | ||
43f66a6c JK |
9576 | /* net device stuff */ |
9577 | ||
858119e1 | 9578 | static void init_sys_config(struct ipw_sys_config *sys_config) |
43f66a6c | 9579 | { |
0edd5b44 | 9580 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); |
810dabd4 | 9581 | sys_config->bt_coexistence = 0; |
43f66a6c JK |
9582 | sys_config->answer_broadcast_ssid_probe = 0; |
9583 | sys_config->accept_all_data_frames = 0; | |
9584 | sys_config->accept_non_directed_frames = 1; | |
9585 | sys_config->exclude_unicast_unencrypted = 0; | |
9586 | sys_config->disable_unicast_decryption = 1; | |
9587 | sys_config->exclude_multicast_unencrypted = 0; | |
9588 | sys_config->disable_multicast_decryption = 1; | |
9589 | sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH; | |
0edd5b44 | 9590 | sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */ |
43f66a6c | 9591 | sys_config->dot11g_auto_detection = 0; |
bf79451e | 9592 | sys_config->enable_cts_to_self = 0; |
43f66a6c | 9593 | sys_config->bt_coexist_collision_thr = 0; |
c848d0af | 9594 | sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256 |
43f66a6c JK |
9595 | } |
9596 | ||
9597 | static int ipw_net_open(struct net_device *dev) | |
9598 | { | |
9599 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9600 | IPW_DEBUG_INFO("dev->open\n"); | |
9601 | /* we should be verifying the device is ready to be opened */ | |
4644151b | 9602 | mutex_lock(&priv->mutex); |
bf79451e JG |
9603 | if (!(priv->status & STATUS_RF_KILL_MASK) && |
9604 | (priv->status & STATUS_ASSOCIATED)) | |
43f66a6c | 9605 | netif_start_queue(dev); |
4644151b | 9606 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9607 | return 0; |
9608 | } | |
9609 | ||
9610 | static int ipw_net_stop(struct net_device *dev) | |
9611 | { | |
9612 | IPW_DEBUG_INFO("dev->close\n"); | |
9613 | netif_stop_queue(dev); | |
9614 | return 0; | |
9615 | } | |
9616 | ||
9617 | /* | |
9618 | todo: | |
9619 | ||
9620 | modify to send one tfd per fragment instead of using chunking. otherwise | |
9621 | we need to heavily modify the ieee80211_skb_to_txb. | |
9622 | */ | |
9623 | ||
858119e1 | 9624 | static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb, |
227d2dc1 | 9625 | int pri) |
43f66a6c | 9626 | { |
0dacca1f | 9627 | struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) |
0edd5b44 | 9628 | txb->fragments[0]->data; |
43f66a6c JK |
9629 | int i = 0; |
9630 | struct tfd_frame *tfd; | |
b095c381 JK |
9631 | #ifdef CONFIG_IPW_QOS |
9632 | int tx_id = ipw_get_tx_queue_number(priv, pri); | |
9633 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; | |
9634 | #else | |
43f66a6c | 9635 | struct clx2_tx_queue *txq = &priv->txq[0]; |
b095c381 | 9636 | #endif |
43f66a6c JK |
9637 | struct clx2_queue *q = &txq->q; |
9638 | u8 id, hdr_len, unicast; | |
9639 | u16 remaining_bytes; | |
c848d0af | 9640 | int fc; |
43f66a6c JK |
9641 | |
9642 | switch (priv->ieee->iw_mode) { | |
9643 | case IW_MODE_ADHOC: | |
9644 | hdr_len = IEEE80211_3ADDR_LEN; | |
3c19065a | 9645 | unicast = !is_multicast_ether_addr(hdr->addr1); |
43f66a6c JK |
9646 | id = ipw_find_station(priv, hdr->addr1); |
9647 | if (id == IPW_INVALID_STATION) { | |
9648 | id = ipw_add_station(priv, hdr->addr1); | |
9649 | if (id == IPW_INVALID_STATION) { | |
9650 | IPW_WARNING("Attempt to send data to " | |
bf79451e | 9651 | "invalid cell: " MAC_FMT "\n", |
43f66a6c JK |
9652 | MAC_ARG(hdr->addr1)); |
9653 | goto drop; | |
9654 | } | |
9655 | } | |
9656 | break; | |
9657 | ||
9658 | case IW_MODE_INFRA: | |
9659 | default: | |
3c19065a | 9660 | unicast = !is_multicast_ether_addr(hdr->addr3); |
43f66a6c JK |
9661 | hdr_len = IEEE80211_3ADDR_LEN; |
9662 | id = 0; | |
9663 | break; | |
9664 | } | |
9665 | ||
9666 | tfd = &txq->bd[q->first_empty]; | |
9667 | txq->txb[q->first_empty] = txb; | |
9668 | memset(tfd, 0, sizeof(*tfd)); | |
9669 | tfd->u.data.station_number = id; | |
9670 | ||
9671 | tfd->control_flags.message_type = TX_FRAME_TYPE; | |
9672 | tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; | |
9673 | ||
9674 | tfd->u.data.cmd_id = DINO_CMD_TX; | |
a613bffd | 9675 | tfd->u.data.len = cpu_to_le16(txb->payload_size); |
43f66a6c | 9676 | remaining_bytes = txb->payload_size; |
bf79451e | 9677 | |
43f66a6c | 9678 | if (priv->assoc_request.ieee_mode == IPW_B_MODE) |
b095c381 | 9679 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK; |
43f66a6c | 9680 | else |
b095c381 | 9681 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM; |
43f66a6c | 9682 | |
ea2b26e0 JK |
9683 | if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE) |
9684 | tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE; | |
43f66a6c | 9685 | |
c848d0af JK |
9686 | fc = le16_to_cpu(hdr->frame_ctl); |
9687 | hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS); | |
43f66a6c JK |
9688 | |
9689 | memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); | |
9690 | ||
b095c381 JK |
9691 | if (likely(unicast)) |
9692 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; | |
9693 | ||
9694 | if (txb->encrypted && !priv->ieee->host_encrypt) { | |
9695 | switch (priv->ieee->sec.level) { | |
9696 | case SEC_LEVEL_3: | |
9697 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | |
9698 | IEEE80211_FCTL_PROTECTED; | |
9699 | /* XXX: ACK flag must be set for CCMP even if it | |
9700 | * is a multicast/broadcast packet, because CCMP | |
9701 | * group communication encrypted by GTK is | |
9702 | * actually done by the AP. */ | |
9703 | if (!unicast) | |
9704 | tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD; | |
9705 | ||
9706 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; | |
9707 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM; | |
9708 | tfd->u.data.key_index = 0; | |
9709 | tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE; | |
9710 | break; | |
9711 | case SEC_LEVEL_2: | |
9712 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | |
9713 | IEEE80211_FCTL_PROTECTED; | |
9714 | tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP; | |
9715 | tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP; | |
9716 | tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE; | |
9717 | break; | |
9718 | case SEC_LEVEL_1: | |
9719 | tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |= | |
9720 | IEEE80211_FCTL_PROTECTED; | |
9721 | tfd->u.data.key_index = priv->ieee->tx_keyidx; | |
9722 | if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <= | |
9723 | 40) | |
9724 | tfd->u.data.key_index |= DCT_WEP_KEY_64Bit; | |
9725 | else | |
9726 | tfd->u.data.key_index |= DCT_WEP_KEY_128Bit; | |
9727 | break; | |
9728 | case SEC_LEVEL_0: | |
9729 | break; | |
9730 | default: | |
9731 | printk(KERN_ERR "Unknow security level %d\n", | |
9732 | priv->ieee->sec.level); | |
9733 | break; | |
9734 | } | |
9735 | } else | |
9736 | /* No hardware encryption */ | |
9737 | tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP; | |
9738 | ||
9739 | #ifdef CONFIG_IPW_QOS | |
9740 | ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast); | |
9741 | #endif /* CONFIG_IPW_QOS */ | |
9742 | ||
43f66a6c | 9743 | /* payload */ |
a613bffd JK |
9744 | tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2), |
9745 | txb->nr_frags)); | |
9746 | IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n", | |
9747 | txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks)); | |
9748 | for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) { | |
9749 | IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n", | |
9750 | i, le32_to_cpu(tfd->u.data.num_chunks), | |
9751 | txb->fragments[i]->len - hdr_len); | |
bf79451e | 9752 | IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n", |
43f66a6c JK |
9753 | i, tfd->u.data.num_chunks, |
9754 | txb->fragments[i]->len - hdr_len); | |
bf79451e | 9755 | printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len, |
43f66a6c JK |
9756 | txb->fragments[i]->len - hdr_len); |
9757 | ||
0edd5b44 | 9758 | tfd->u.data.chunk_ptr[i] = |
a613bffd JK |
9759 | cpu_to_le32(pci_map_single |
9760 | (priv->pci_dev, | |
9761 | txb->fragments[i]->data + hdr_len, | |
9762 | txb->fragments[i]->len - hdr_len, | |
9763 | PCI_DMA_TODEVICE)); | |
9764 | tfd->u.data.chunk_len[i] = | |
9765 | cpu_to_le16(txb->fragments[i]->len - hdr_len); | |
43f66a6c JK |
9766 | } |
9767 | ||
9768 | if (i != txb->nr_frags) { | |
9769 | struct sk_buff *skb; | |
9770 | u16 remaining_bytes = 0; | |
9771 | int j; | |
9772 | ||
9773 | for (j = i; j < txb->nr_frags; j++) | |
9774 | remaining_bytes += txb->fragments[j]->len - hdr_len; | |
9775 | ||
9776 | printk(KERN_INFO "Trying to reallocate for %d bytes\n", | |
9777 | remaining_bytes); | |
9778 | skb = alloc_skb(remaining_bytes, GFP_ATOMIC); | |
9779 | if (skb != NULL) { | |
a613bffd | 9780 | tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes); |
43f66a6c JK |
9781 | for (j = i; j < txb->nr_frags; j++) { |
9782 | int size = txb->fragments[j]->len - hdr_len; | |
afbf30a2 | 9783 | |
43f66a6c | 9784 | printk(KERN_INFO "Adding frag %d %d...\n", |
0edd5b44 | 9785 | j, size); |
43f66a6c | 9786 | memcpy(skb_put(skb, size), |
0edd5b44 | 9787 | txb->fragments[j]->data + hdr_len, size); |
43f66a6c JK |
9788 | } |
9789 | dev_kfree_skb_any(txb->fragments[i]); | |
9790 | txb->fragments[i] = skb; | |
0edd5b44 | 9791 | tfd->u.data.chunk_ptr[i] = |
a613bffd JK |
9792 | cpu_to_le32(pci_map_single |
9793 | (priv->pci_dev, skb->data, | |
9794 | tfd->u.data.chunk_len[i], | |
9795 | PCI_DMA_TODEVICE)); | |
9796 | ||
9797 | tfd->u.data.num_chunks = | |
9798 | cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) + | |
9799 | 1); | |
bf79451e | 9800 | } |
43f66a6c JK |
9801 | } |
9802 | ||
9803 | /* kick DMA */ | |
9804 | q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); | |
9805 | ipw_write32(priv, q->reg_w, q->first_empty); | |
9806 | ||
f697014a JK |
9807 | if (ipw_queue_space(q) < q->high_mark) |
9808 | netif_stop_queue(priv->net_dev); | |
9809 | ||
227d2dc1 | 9810 | return NETDEV_TX_OK; |
43f66a6c | 9811 | |
0edd5b44 | 9812 | drop: |
43f66a6c JK |
9813 | IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); |
9814 | ieee80211_txb_free(txb); | |
227d2dc1 JK |
9815 | return NETDEV_TX_OK; |
9816 | } | |
9817 | ||
9818 | static int ipw_net_is_queue_full(struct net_device *dev, int pri) | |
9819 | { | |
9820 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9821 | #ifdef CONFIG_IPW_QOS | |
9822 | int tx_id = ipw_get_tx_queue_number(priv, pri); | |
9823 | struct clx2_tx_queue *txq = &priv->txq[tx_id]; | |
9824 | #else | |
9825 | struct clx2_tx_queue *txq = &priv->txq[0]; | |
9826 | #endif /* CONFIG_IPW_QOS */ | |
9827 | ||
9828 | if (ipw_queue_space(&txq->q) < txq->q.high_mark) | |
9829 | return 1; | |
9830 | ||
9831 | return 0; | |
43f66a6c JK |
9832 | } |
9833 | ||
9834 | static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, | |
c8d42d1a | 9835 | struct net_device *dev, int pri) |
43f66a6c JK |
9836 | { |
9837 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9838 | unsigned long flags; | |
227d2dc1 | 9839 | int ret; |
43f66a6c JK |
9840 | |
9841 | IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); | |
43f66a6c JK |
9842 | spin_lock_irqsave(&priv->lock, flags); |
9843 | ||
9844 | if (!(priv->status & STATUS_ASSOCIATED)) { | |
9845 | IPW_DEBUG_INFO("Tx attempt while not associated.\n"); | |
9846 | priv->ieee->stats.tx_carrier_errors++; | |
9847 | netif_stop_queue(dev); | |
9848 | goto fail_unlock; | |
9849 | } | |
9850 | ||
227d2dc1 JK |
9851 | ret = ipw_tx_skb(priv, txb, pri); |
9852 | if (ret == NETDEV_TX_OK) | |
9853 | __ipw_led_activity_on(priv); | |
43f66a6c | 9854 | spin_unlock_irqrestore(&priv->lock, flags); |
43f66a6c | 9855 | |
227d2dc1 | 9856 | return ret; |
43f66a6c | 9857 | |
0edd5b44 | 9858 | fail_unlock: |
43f66a6c JK |
9859 | spin_unlock_irqrestore(&priv->lock, flags); |
9860 | return 1; | |
9861 | } | |
9862 | ||
9863 | static struct net_device_stats *ipw_net_get_stats(struct net_device *dev) | |
9864 | { | |
9865 | struct ipw_priv *priv = ieee80211_priv(dev); | |
bf79451e | 9866 | |
43f66a6c JK |
9867 | priv->ieee->stats.tx_packets = priv->tx_packets; |
9868 | priv->ieee->stats.rx_packets = priv->rx_packets; | |
9869 | return &priv->ieee->stats; | |
9870 | } | |
9871 | ||
9872 | static void ipw_net_set_multicast_list(struct net_device *dev) | |
9873 | { | |
9874 | ||
9875 | } | |
9876 | ||
9877 | static int ipw_net_set_mac_address(struct net_device *dev, void *p) | |
9878 | { | |
9879 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9880 | struct sockaddr *addr = p; | |
9881 | if (!is_valid_ether_addr(addr->sa_data)) | |
9882 | return -EADDRNOTAVAIL; | |
4644151b | 9883 | mutex_lock(&priv->mutex); |
43f66a6c JK |
9884 | priv->config |= CFG_CUSTOM_MAC; |
9885 | memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); | |
9886 | printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n", | |
9887 | priv->net_dev->name, MAC_ARG(priv->mac_addr)); | |
a613bffd | 9888 | queue_work(priv->workqueue, &priv->adapter_restart); |
4644151b | 9889 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
9890 | return 0; |
9891 | } | |
9892 | ||
bf79451e | 9893 | static void ipw_ethtool_get_drvinfo(struct net_device *dev, |
43f66a6c JK |
9894 | struct ethtool_drvinfo *info) |
9895 | { | |
9896 | struct ipw_priv *p = ieee80211_priv(dev); | |
9897 | char vers[64]; | |
9898 | char date[32]; | |
9899 | u32 len; | |
9900 | ||
9901 | strcpy(info->driver, DRV_NAME); | |
9902 | strcpy(info->version, DRV_VERSION); | |
9903 | ||
9904 | len = sizeof(vers); | |
9905 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len); | |
9906 | len = sizeof(date); | |
9907 | ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len); | |
9908 | ||
0edd5b44 | 9909 | snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", |
43f66a6c JK |
9910 | vers, date); |
9911 | strcpy(info->bus_info, pci_name(p->pci_dev)); | |
b095c381 | 9912 | info->eedump_len = IPW_EEPROM_IMAGE_SIZE; |
43f66a6c JK |
9913 | } |
9914 | ||
9915 | static u32 ipw_ethtool_get_link(struct net_device *dev) | |
9916 | { | |
9917 | struct ipw_priv *priv = ieee80211_priv(dev); | |
9918 | return (priv->status & STATUS_ASSOCIATED) != 0; | |
9919 | } | |
9920 | ||
9921 | static int ipw_ethtool_get_eeprom_len(struct net_device *dev) | |
9922 | { | |
b095c381 | 9923 | return IPW_EEPROM_IMAGE_SIZE; |
43f66a6c JK |
9924 | } |
9925 | ||
9926 | static int ipw_ethtool_get_eeprom(struct net_device *dev, | |
0edd5b44 | 9927 | struct ethtool_eeprom *eeprom, u8 * bytes) |
43f66a6c JK |
9928 | { |
9929 | struct ipw_priv *p = ieee80211_priv(dev); | |
9930 | ||
b095c381 | 9931 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
43f66a6c | 9932 | return -EINVAL; |
4644151b | 9933 | mutex_lock(&p->mutex); |
afbf30a2 | 9934 | memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len); |
4644151b | 9935 | mutex_unlock(&p->mutex); |
43f66a6c JK |
9936 | return 0; |
9937 | } | |
9938 | ||
9939 | static int ipw_ethtool_set_eeprom(struct net_device *dev, | |
0edd5b44 | 9940 | struct ethtool_eeprom *eeprom, u8 * bytes) |
43f66a6c JK |
9941 | { |
9942 | struct ipw_priv *p = ieee80211_priv(dev); | |
9943 | int i; | |
9944 | ||
b095c381 | 9945 | if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE) |
43f66a6c | 9946 | return -EINVAL; |
4644151b | 9947 | mutex_lock(&p->mutex); |
afbf30a2 | 9948 | memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len); |
bf79451e | 9949 | for (i = IPW_EEPROM_DATA; |
b095c381 | 9950 | i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++) |
43f66a6c | 9951 | ipw_write8(p, i, p->eeprom[i]); |
4644151b | 9952 | mutex_unlock(&p->mutex); |
43f66a6c JK |
9953 | return 0; |
9954 | } | |
9955 | ||
9956 | static struct ethtool_ops ipw_ethtool_ops = { | |
ea2b26e0 JK |
9957 | .get_link = ipw_ethtool_get_link, |
9958 | .get_drvinfo = ipw_ethtool_get_drvinfo, | |
9959 | .get_eeprom_len = ipw_ethtool_get_eeprom_len, | |
9960 | .get_eeprom = ipw_ethtool_get_eeprom, | |
9961 | .set_eeprom = ipw_ethtool_set_eeprom, | |
43f66a6c JK |
9962 | }; |
9963 | ||
9964 | static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) | |
9965 | { | |
9966 | struct ipw_priv *priv = data; | |
9967 | u32 inta, inta_mask; | |
bf79451e | 9968 | |
43f66a6c JK |
9969 | if (!priv) |
9970 | return IRQ_NONE; | |
9971 | ||
9972 | spin_lock(&priv->lock); | |
9973 | ||
9974 | if (!(priv->status & STATUS_INT_ENABLED)) { | |
9975 | /* Shared IRQ */ | |
9976 | goto none; | |
9977 | } | |
9978 | ||
b095c381 JK |
9979 | inta = ipw_read32(priv, IPW_INTA_RW); |
9980 | inta_mask = ipw_read32(priv, IPW_INTA_MASK_R); | |
bf79451e | 9981 | |
43f66a6c JK |
9982 | if (inta == 0xFFFFFFFF) { |
9983 | /* Hardware disappeared */ | |
9984 | IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n"); | |
9985 | goto none; | |
9986 | } | |
9987 | ||
b095c381 | 9988 | if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) { |
43f66a6c JK |
9989 | /* Shared interrupt */ |
9990 | goto none; | |
9991 | } | |
9992 | ||
9993 | /* tell the device to stop sending interrupts */ | |
9994 | ipw_disable_interrupts(priv); | |
bf79451e | 9995 | |
43f66a6c | 9996 | /* ack current interrupts */ |
b095c381 JK |
9997 | inta &= (IPW_INTA_MASK_ALL & inta_mask); |
9998 | ipw_write32(priv, IPW_INTA_RW, inta); | |
bf79451e | 9999 | |
43f66a6c JK |
10000 | /* Cache INTA value for our tasklet */ |
10001 | priv->isr_inta = inta; | |
10002 | ||
10003 | tasklet_schedule(&priv->irq_tasklet); | |
10004 | ||
0edd5b44 | 10005 | spin_unlock(&priv->lock); |
43f66a6c JK |
10006 | |
10007 | return IRQ_HANDLED; | |
0edd5b44 | 10008 | none: |
43f66a6c JK |
10009 | spin_unlock(&priv->lock); |
10010 | return IRQ_NONE; | |
10011 | } | |
10012 | ||
10013 | static void ipw_rf_kill(void *adapter) | |
10014 | { | |
10015 | struct ipw_priv *priv = adapter; | |
10016 | unsigned long flags; | |
bf79451e | 10017 | |
43f66a6c JK |
10018 | spin_lock_irqsave(&priv->lock, flags); |
10019 | ||
10020 | if (rf_kill_active(priv)) { | |
10021 | IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n"); | |
10022 | if (priv->workqueue) | |
10023 | queue_delayed_work(priv->workqueue, | |
10024 | &priv->rf_kill, 2 * HZ); | |
10025 | goto exit_unlock; | |
10026 | } | |
10027 | ||
10028 | /* RF Kill is now disabled, so bring the device back up */ | |
10029 | ||
10030 | if (!(priv->status & STATUS_RF_KILL_MASK)) { | |
10031 | IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting " | |
10032 | "device\n"); | |
10033 | ||
10034 | /* we can not do an adapter restart while inside an irq lock */ | |
10035 | queue_work(priv->workqueue, &priv->adapter_restart); | |
bf79451e | 10036 | } else |
43f66a6c JK |
10037 | IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still " |
10038 | "enabled\n"); | |
10039 | ||
0edd5b44 | 10040 | exit_unlock: |
43f66a6c JK |
10041 | spin_unlock_irqrestore(&priv->lock, flags); |
10042 | } | |
10043 | ||
c848d0af JK |
10044 | static void ipw_bg_rf_kill(void *data) |
10045 | { | |
10046 | struct ipw_priv *priv = data; | |
4644151b | 10047 | mutex_lock(&priv->mutex); |
c848d0af | 10048 | ipw_rf_kill(data); |
4644151b | 10049 | mutex_unlock(&priv->mutex); |
c848d0af JK |
10050 | } |
10051 | ||
a73e22b2 | 10052 | static void ipw_link_up(struct ipw_priv *priv) |
a613bffd | 10053 | { |
afbf30a2 JK |
10054 | priv->last_seq_num = -1; |
10055 | priv->last_frag_num = -1; | |
10056 | priv->last_packet_time = 0; | |
10057 | ||
a613bffd JK |
10058 | netif_carrier_on(priv->net_dev); |
10059 | if (netif_queue_stopped(priv->net_dev)) { | |
10060 | IPW_DEBUG_NOTIF("waking queue\n"); | |
10061 | netif_wake_queue(priv->net_dev); | |
10062 | } else { | |
10063 | IPW_DEBUG_NOTIF("starting queue\n"); | |
10064 | netif_start_queue(priv->net_dev); | |
10065 | } | |
10066 | ||
c848d0af | 10067 | cancel_delayed_work(&priv->request_scan); |
a613bffd JK |
10068 | ipw_reset_stats(priv); |
10069 | /* Ensure the rate is updated immediately */ | |
10070 | priv->last_rate = ipw_get_current_rate(priv); | |
10071 | ipw_gather_stats(priv); | |
10072 | ipw_led_link_up(priv); | |
10073 | notify_wx_assoc_event(priv); | |
10074 | ||
10075 | if (priv->config & CFG_BACKGROUND_SCAN) | |
10076 | queue_delayed_work(priv->workqueue, &priv->request_scan, HZ); | |
10077 | } | |
10078 | ||
c848d0af JK |
10079 | static void ipw_bg_link_up(void *data) |
10080 | { | |
10081 | struct ipw_priv *priv = data; | |
4644151b | 10082 | mutex_lock(&priv->mutex); |
c848d0af | 10083 | ipw_link_up(data); |
4644151b | 10084 | mutex_unlock(&priv->mutex); |
c848d0af JK |
10085 | } |
10086 | ||
a73e22b2 | 10087 | static void ipw_link_down(struct ipw_priv *priv) |
a613bffd JK |
10088 | { |
10089 | ipw_led_link_down(priv); | |
10090 | netif_carrier_off(priv->net_dev); | |
10091 | netif_stop_queue(priv->net_dev); | |
10092 | notify_wx_assoc_event(priv); | |
10093 | ||
10094 | /* Cancel any queued work ... */ | |
10095 | cancel_delayed_work(&priv->request_scan); | |
10096 | cancel_delayed_work(&priv->adhoc_check); | |
10097 | cancel_delayed_work(&priv->gather_stats); | |
10098 | ||
10099 | ipw_reset_stats(priv); | |
10100 | ||
afbf30a2 JK |
10101 | if (!(priv->status & STATUS_EXIT_PENDING)) { |
10102 | /* Queue up another scan... */ | |
10103 | queue_work(priv->workqueue, &priv->request_scan); | |
10104 | } | |
a613bffd JK |
10105 | } |
10106 | ||
c848d0af JK |
10107 | static void ipw_bg_link_down(void *data) |
10108 | { | |
10109 | struct ipw_priv *priv = data; | |
4644151b | 10110 | mutex_lock(&priv->mutex); |
c848d0af | 10111 | ipw_link_down(data); |
4644151b | 10112 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10113 | } |
10114 | ||
10115 | static int ipw_setup_deferred_work(struct ipw_priv *priv) | |
10116 | { | |
10117 | int ret = 0; | |
10118 | ||
43f66a6c | 10119 | priv->workqueue = create_workqueue(DRV_NAME); |
43f66a6c | 10120 | init_waitqueue_head(&priv->wait_command_queue); |
afbf30a2 | 10121 | init_waitqueue_head(&priv->wait_state); |
43f66a6c | 10122 | |
c848d0af JK |
10123 | INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv); |
10124 | INIT_WORK(&priv->associate, ipw_bg_associate, priv); | |
10125 | INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv); | |
d8bad6df | 10126 | INIT_WORK(&priv->system_config, ipw_system_config, priv); |
c848d0af JK |
10127 | INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv); |
10128 | INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv); | |
10129 | INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv); | |
10130 | INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv); | |
10131 | INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv); | |
bf79451e | 10132 | INIT_WORK(&priv->request_scan, |
43f66a6c | 10133 | (void (*)(void *))ipw_request_scan, priv); |
bf79451e | 10134 | INIT_WORK(&priv->gather_stats, |
c848d0af JK |
10135 | (void (*)(void *))ipw_bg_gather_stats, priv); |
10136 | INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv); | |
10137 | INIT_WORK(&priv->roam, ipw_bg_roam, priv); | |
10138 | INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv); | |
10139 | INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv); | |
10140 | INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv); | |
10141 | INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on, | |
10142 | priv); | |
10143 | INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off, | |
a613bffd | 10144 | priv); |
c848d0af | 10145 | INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off, |
a613bffd | 10146 | priv); |
c848d0af JK |
10147 | INIT_WORK(&priv->merge_networks, |
10148 | (void (*)(void *))ipw_merge_adhoc_network, priv); | |
43f66a6c | 10149 | |
b095c381 JK |
10150 | #ifdef CONFIG_IPW_QOS |
10151 | INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate, | |
10152 | priv); | |
10153 | #endif /* CONFIG_IPW_QOS */ | |
43f66a6c JK |
10154 | |
10155 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) | |
10156 | ipw_irq_tasklet, (unsigned long)priv); | |
10157 | ||
10158 | return ret; | |
10159 | } | |
10160 | ||
43f66a6c JK |
10161 | static void shim__set_security(struct net_device *dev, |
10162 | struct ieee80211_security *sec) | |
10163 | { | |
10164 | struct ipw_priv *priv = ieee80211_priv(dev); | |
10165 | int i; | |
bf79451e | 10166 | for (i = 0; i < 4; i++) { |
43f66a6c | 10167 | if (sec->flags & (1 << i)) { |
afbf30a2 | 10168 | priv->ieee->sec.encode_alg[i] = sec->encode_alg[i]; |
b095c381 | 10169 | priv->ieee->sec.key_sizes[i] = sec->key_sizes[i]; |
43f66a6c | 10170 | if (sec->key_sizes[i] == 0) |
b095c381 JK |
10171 | priv->ieee->sec.flags &= ~(1 << i); |
10172 | else { | |
10173 | memcpy(priv->ieee->sec.keys[i], sec->keys[i], | |
43f66a6c | 10174 | sec->key_sizes[i]); |
b095c381 JK |
10175 | priv->ieee->sec.flags |= (1 << i); |
10176 | } | |
43f66a6c | 10177 | priv->status |= STATUS_SECURITY_UPDATED; |
b095c381 JK |
10178 | } else if (sec->level != SEC_LEVEL_1) |
10179 | priv->ieee->sec.flags &= ~(1 << i); | |
43f66a6c JK |
10180 | } |
10181 | ||
b095c381 | 10182 | if (sec->flags & SEC_ACTIVE_KEY) { |
43f66a6c | 10183 | if (sec->active_key <= 3) { |
b095c381 JK |
10184 | priv->ieee->sec.active_key = sec->active_key; |
10185 | priv->ieee->sec.flags |= SEC_ACTIVE_KEY; | |
bf79451e | 10186 | } else |
b095c381 | 10187 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; |
43f66a6c | 10188 | priv->status |= STATUS_SECURITY_UPDATED; |
b095c381 JK |
10189 | } else |
10190 | priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY; | |
43f66a6c JK |
10191 | |
10192 | if ((sec->flags & SEC_AUTH_MODE) && | |
b095c381 JK |
10193 | (priv->ieee->sec.auth_mode != sec->auth_mode)) { |
10194 | priv->ieee->sec.auth_mode = sec->auth_mode; | |
10195 | priv->ieee->sec.flags |= SEC_AUTH_MODE; | |
43f66a6c JK |
10196 | if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) |
10197 | priv->capability |= CAP_SHARED_KEY; | |
10198 | else | |
10199 | priv->capability &= ~CAP_SHARED_KEY; | |
10200 | priv->status |= STATUS_SECURITY_UPDATED; | |
10201 | } | |
bf79451e | 10202 | |
b095c381 JK |
10203 | if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) { |
10204 | priv->ieee->sec.flags |= SEC_ENABLED; | |
10205 | priv->ieee->sec.enabled = sec->enabled; | |
43f66a6c | 10206 | priv->status |= STATUS_SECURITY_UPDATED; |
bf79451e | 10207 | if (sec->enabled) |
43f66a6c JK |
10208 | priv->capability |= CAP_PRIVACY_ON; |
10209 | else | |
10210 | priv->capability &= ~CAP_PRIVACY_ON; | |
10211 | } | |
bf79451e | 10212 | |
afbf30a2 JK |
10213 | if (sec->flags & SEC_ENCRYPT) |
10214 | priv->ieee->sec.encrypt = sec->encrypt; | |
bf79451e | 10215 | |
b095c381 JK |
10216 | if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) { |
10217 | priv->ieee->sec.level = sec->level; | |
10218 | priv->ieee->sec.flags |= SEC_LEVEL; | |
43f66a6c JK |
10219 | priv->status |= STATUS_SECURITY_UPDATED; |
10220 | } | |
10221 | ||
1fbfea54 ZY |
10222 | if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT)) |
10223 | ipw_set_hwcrypto_keys(priv); | |
10224 | ||
bf79451e JG |
10225 | /* To match current functionality of ipw2100 (which works well w/ |
10226 | * various supplicants, we don't force a disassociate if the | |
43f66a6c JK |
10227 | * privacy capability changes ... */ |
10228 | #if 0 | |
10229 | if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) && | |
bf79451e | 10230 | (((priv->assoc_request.capability & |
43f66a6c | 10231 | WLAN_CAPABILITY_PRIVACY) && !sec->enabled) || |
bf79451e | 10232 | (!(priv->assoc_request.capability & |
0edd5b44 | 10233 | WLAN_CAPABILITY_PRIVACY) && sec->enabled))) { |
43f66a6c JK |
10234 | IPW_DEBUG_ASSOC("Disassociating due to capability " |
10235 | "change.\n"); | |
10236 | ipw_disassociate(priv); | |
10237 | } | |
10238 | #endif | |
10239 | } | |
10240 | ||
bf79451e | 10241 | static int init_supported_rates(struct ipw_priv *priv, |
43f66a6c JK |
10242 | struct ipw_supported_rates *rates) |
10243 | { | |
10244 | /* TODO: Mask out rates based on priv->rates_mask */ | |
10245 | ||
10246 | memset(rates, 0, sizeof(*rates)); | |
0edd5b44 | 10247 | /* configure supported rates */ |
43f66a6c JK |
10248 | switch (priv->ieee->freq_band) { |
10249 | case IEEE80211_52GHZ_BAND: | |
10250 | rates->ieee_mode = IPW_A_MODE; | |
10251 | rates->purpose = IPW_RATE_CAPABILITIES; | |
10252 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, | |
10253 | IEEE80211_OFDM_DEFAULT_RATES_MASK); | |
10254 | break; | |
10255 | ||
0edd5b44 | 10256 | default: /* Mixed or 2.4Ghz */ |
43f66a6c JK |
10257 | rates->ieee_mode = IPW_G_MODE; |
10258 | rates->purpose = IPW_RATE_CAPABILITIES; | |
10259 | ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION, | |
10260 | IEEE80211_CCK_DEFAULT_RATES_MASK); | |
10261 | if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) { | |
10262 | ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION, | |
10263 | IEEE80211_OFDM_DEFAULT_RATES_MASK); | |
10264 | } | |
10265 | break; | |
10266 | } | |
10267 | ||
10268 | return 0; | |
10269 | } | |
10270 | ||
bf79451e | 10271 | static int ipw_config(struct ipw_priv *priv) |
43f66a6c | 10272 | { |
43f66a6c JK |
10273 | /* This is only called from ipw_up, which resets/reloads the firmware |
10274 | so, we don't need to first disable the card before we configure | |
10275 | it */ | |
6de9f7f2 | 10276 | if (ipw_set_tx_power(priv)) |
43f66a6c JK |
10277 | goto error; |
10278 | ||
10279 | /* initialize adapter address */ | |
10280 | if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr)) | |
10281 | goto error; | |
10282 | ||
10283 | /* set basic system config settings */ | |
10284 | init_sys_config(&priv->sys_config); | |
810dabd4 ZY |
10285 | |
10286 | /* Support Bluetooth if we have BT h/w on board, and user wants to. | |
10287 | * Does not support BT priority yet (don't abort or defer our Tx) */ | |
10288 | if (bt_coexist) { | |
2638bc39 | 10289 | unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY]; |
810dabd4 ZY |
10290 | |
10291 | if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG) | |
10292 | priv->sys_config.bt_coexistence | |
2638bc39 | 10293 | |= CFG_BT_COEXISTENCE_SIGNAL_CHNL; |
810dabd4 ZY |
10294 | if (bt_caps & EEPROM_SKU_CAP_BT_OOB) |
10295 | priv->sys_config.bt_coexistence | |
2638bc39 | 10296 | |= CFG_BT_COEXISTENCE_OOB; |
810dabd4 ZY |
10297 | } |
10298 | ||
c848d0af JK |
10299 | if (priv->ieee->iw_mode == IW_MODE_ADHOC) |
10300 | priv->sys_config.answer_broadcast_ssid_probe = 1; | |
10301 | else | |
10302 | priv->sys_config.answer_broadcast_ssid_probe = 0; | |
10303 | ||
43f66a6c JK |
10304 | if (ipw_send_system_config(priv, &priv->sys_config)) |
10305 | goto error; | |
10306 | ||
0edd5b44 JG |
10307 | init_supported_rates(priv, &priv->rates); |
10308 | if (ipw_send_supported_rates(priv, &priv->rates)) | |
43f66a6c JK |
10309 | goto error; |
10310 | ||
10311 | /* Set request-to-send threshold */ | |
10312 | if (priv->rts_threshold) { | |
10313 | if (ipw_send_rts_threshold(priv, priv->rts_threshold)) | |
10314 | goto error; | |
10315 | } | |
b095c381 JK |
10316 | #ifdef CONFIG_IPW_QOS |
10317 | IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n"); | |
10318 | ipw_qos_activate(priv, NULL); | |
10319 | #endif /* CONFIG_IPW_QOS */ | |
43f66a6c JK |
10320 | |
10321 | if (ipw_set_random_seed(priv)) | |
10322 | goto error; | |
bf79451e | 10323 | |
43f66a6c JK |
10324 | /* final state transition to the RUN state */ |
10325 | if (ipw_send_host_complete(priv)) | |
10326 | goto error; | |
10327 | ||
e666619e JK |
10328 | priv->status |= STATUS_INIT; |
10329 | ||
10330 | ipw_led_init(priv); | |
10331 | ipw_led_radio_on(priv); | |
10332 | priv->notif_missed_beacons = 0; | |
10333 | ||
10334 | /* Set hardware WEP key if it is configured. */ | |
10335 | if ((priv->capability & CAP_PRIVACY_ON) && | |
10336 | (priv->ieee->sec.level == SEC_LEVEL_1) && | |
10337 | !(priv->ieee->host_encrypt || priv->ieee->host_decrypt)) | |
10338 | ipw_set_hwcrypto_keys(priv); | |
43f66a6c JK |
10339 | |
10340 | return 0; | |
bf79451e | 10341 | |
0edd5b44 | 10342 | error: |
43f66a6c JK |
10343 | return -EIO; |
10344 | } | |
10345 | ||
4f36f808 JK |
10346 | /* |
10347 | * NOTE: | |
10348 | * | |
10349 | * These tables have been tested in conjunction with the | |
10350 | * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters. | |
10351 | * | |
10352 | * Altering this values, using it on other hardware, or in geographies | |
10353 | * not intended for resale of the above mentioned Intel adapters has | |
10354 | * not been tested. | |
10355 | * | |
48a84770 HBA |
10356 | * Remember to update the table in README.ipw2200 when changing this |
10357 | * table. | |
10358 | * | |
4f36f808 JK |
10359 | */ |
10360 | static const struct ieee80211_geo ipw_geos[] = { | |
10361 | { /* Restricted */ | |
10362 | "---", | |
10363 | .bg_channels = 11, | |
10364 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10365 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10366 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10367 | {2457, 10}, {2462, 11}}, | |
10368 | }, | |
10369 | ||
10370 | { /* Custom US/Canada */ | |
10371 | "ZZF", | |
10372 | .bg_channels = 11, | |
10373 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10374 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10375 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10376 | {2457, 10}, {2462, 11}}, | |
10377 | .a_channels = 8, | |
10378 | .a = {{5180, 36}, | |
10379 | {5200, 40}, | |
10380 | {5220, 44}, | |
10381 | {5240, 48}, | |
10382 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10383 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10384 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10385 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}}, | |
10386 | }, | |
10387 | ||
10388 | { /* Rest of World */ | |
10389 | "ZZD", | |
10390 | .bg_channels = 13, | |
10391 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10392 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10393 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10394 | {2457, 10}, {2462, 11}, {2467, 12}, | |
10395 | {2472, 13}}, | |
10396 | }, | |
10397 | ||
10398 | { /* Custom USA & Europe & High */ | |
10399 | "ZZA", | |
10400 | .bg_channels = 11, | |
10401 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10402 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10403 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10404 | {2457, 10}, {2462, 11}}, | |
10405 | .a_channels = 13, | |
10406 | .a = {{5180, 36}, | |
10407 | {5200, 40}, | |
10408 | {5220, 44}, | |
10409 | {5240, 48}, | |
10410 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10411 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10412 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10413 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10414 | {5745, 149}, | |
10415 | {5765, 153}, | |
10416 | {5785, 157}, | |
10417 | {5805, 161}, | |
10418 | {5825, 165}}, | |
10419 | }, | |
10420 | ||
10421 | { /* Custom NA & Europe */ | |
10422 | "ZZB", | |
10423 | .bg_channels = 11, | |
10424 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10425 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10426 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10427 | {2457, 10}, {2462, 11}}, | |
10428 | .a_channels = 13, | |
10429 | .a = {{5180, 36}, | |
10430 | {5200, 40}, | |
10431 | {5220, 44}, | |
10432 | {5240, 48}, | |
10433 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10434 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10435 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10436 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10437 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, | |
10438 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, | |
10439 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, | |
10440 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, | |
10441 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, | |
10442 | }, | |
10443 | ||
10444 | { /* Custom Japan */ | |
10445 | "ZZC", | |
10446 | .bg_channels = 11, | |
10447 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10448 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10449 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10450 | {2457, 10}, {2462, 11}}, | |
10451 | .a_channels = 4, | |
10452 | .a = {{5170, 34}, {5190, 38}, | |
10453 | {5210, 42}, {5230, 46}}, | |
10454 | }, | |
10455 | ||
10456 | { /* Custom */ | |
10457 | "ZZM", | |
10458 | .bg_channels = 11, | |
10459 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10460 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10461 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10462 | {2457, 10}, {2462, 11}}, | |
10463 | }, | |
10464 | ||
10465 | { /* Europe */ | |
10466 | "ZZE", | |
10467 | .bg_channels = 13, | |
10468 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10469 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10470 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10471 | {2457, 10}, {2462, 11}, {2467, 12}, | |
10472 | {2472, 13}}, | |
10473 | .a_channels = 19, | |
10474 | .a = {{5180, 36}, | |
10475 | {5200, 40}, | |
10476 | {5220, 44}, | |
10477 | {5240, 48}, | |
10478 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10479 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10480 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10481 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10482 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, | |
10483 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, | |
10484 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, | |
10485 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, | |
10486 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, | |
10487 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, | |
10488 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, | |
10489 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, | |
10490 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, | |
10491 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, | |
10492 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}}, | |
10493 | }, | |
10494 | ||
10495 | { /* Custom Japan */ | |
10496 | "ZZJ", | |
10497 | .bg_channels = 14, | |
10498 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10499 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10500 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10501 | {2457, 10}, {2462, 11}, {2467, 12}, | |
10502 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}}, | |
10503 | .a_channels = 4, | |
10504 | .a = {{5170, 34}, {5190, 38}, | |
10505 | {5210, 42}, {5230, 46}}, | |
10506 | }, | |
10507 | ||
03520576 JK |
10508 | { /* Rest of World */ |
10509 | "ZZR", | |
10510 | .bg_channels = 14, | |
10511 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10512 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10513 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10514 | {2457, 10}, {2462, 11}, {2467, 12}, | |
10515 | {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY | | |
10516 | IEEE80211_CH_PASSIVE_ONLY}}, | |
10517 | }, | |
10518 | ||
4f36f808 JK |
10519 | { /* High Band */ |
10520 | "ZZH", | |
10521 | .bg_channels = 13, | |
10522 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10523 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10524 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10525 | {2457, 10}, {2462, 11}, | |
10526 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, | |
10527 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, | |
10528 | .a_channels = 4, | |
10529 | .a = {{5745, 149}, {5765, 153}, | |
10530 | {5785, 157}, {5805, 161}}, | |
10531 | }, | |
10532 | ||
10533 | { /* Custom Europe */ | |
10534 | "ZZG", | |
10535 | .bg_channels = 13, | |
10536 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10537 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10538 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10539 | {2457, 10}, {2462, 11}, | |
10540 | {2467, 12}, {2472, 13}}, | |
10541 | .a_channels = 4, | |
10542 | .a = {{5180, 36}, {5200, 40}, | |
10543 | {5220, 44}, {5240, 48}}, | |
10544 | }, | |
10545 | ||
10546 | { /* Europe */ | |
10547 | "ZZK", | |
10548 | .bg_channels = 13, | |
10549 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10550 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10551 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10552 | {2457, 10}, {2462, 11}, | |
10553 | {2467, 12, IEEE80211_CH_PASSIVE_ONLY}, | |
10554 | {2472, 13, IEEE80211_CH_PASSIVE_ONLY}}, | |
10555 | .a_channels = 24, | |
10556 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, | |
10557 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, | |
10558 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, | |
10559 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, | |
10560 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10561 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10562 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10563 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10564 | {5500, 100, IEEE80211_CH_PASSIVE_ONLY}, | |
10565 | {5520, 104, IEEE80211_CH_PASSIVE_ONLY}, | |
10566 | {5540, 108, IEEE80211_CH_PASSIVE_ONLY}, | |
10567 | {5560, 112, IEEE80211_CH_PASSIVE_ONLY}, | |
10568 | {5580, 116, IEEE80211_CH_PASSIVE_ONLY}, | |
10569 | {5600, 120, IEEE80211_CH_PASSIVE_ONLY}, | |
10570 | {5620, 124, IEEE80211_CH_PASSIVE_ONLY}, | |
10571 | {5640, 128, IEEE80211_CH_PASSIVE_ONLY}, | |
10572 | {5660, 132, IEEE80211_CH_PASSIVE_ONLY}, | |
10573 | {5680, 136, IEEE80211_CH_PASSIVE_ONLY}, | |
10574 | {5700, 140, IEEE80211_CH_PASSIVE_ONLY}, | |
10575 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, | |
10576 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, | |
10577 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, | |
10578 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, | |
10579 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, | |
10580 | }, | |
10581 | ||
10582 | { /* Europe */ | |
10583 | "ZZL", | |
10584 | .bg_channels = 11, | |
10585 | .bg = {{2412, 1}, {2417, 2}, {2422, 3}, | |
10586 | {2427, 4}, {2432, 5}, {2437, 6}, | |
10587 | {2442, 7}, {2447, 8}, {2452, 9}, | |
10588 | {2457, 10}, {2462, 11}}, | |
10589 | .a_channels = 13, | |
10590 | .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY}, | |
10591 | {5200, 40, IEEE80211_CH_PASSIVE_ONLY}, | |
10592 | {5220, 44, IEEE80211_CH_PASSIVE_ONLY}, | |
10593 | {5240, 48, IEEE80211_CH_PASSIVE_ONLY}, | |
10594 | {5260, 52, IEEE80211_CH_PASSIVE_ONLY}, | |
10595 | {5280, 56, IEEE80211_CH_PASSIVE_ONLY}, | |
10596 | {5300, 60, IEEE80211_CH_PASSIVE_ONLY}, | |
10597 | {5320, 64, IEEE80211_CH_PASSIVE_ONLY}, | |
10598 | {5745, 149, IEEE80211_CH_PASSIVE_ONLY}, | |
10599 | {5765, 153, IEEE80211_CH_PASSIVE_ONLY}, | |
10600 | {5785, 157, IEEE80211_CH_PASSIVE_ONLY}, | |
10601 | {5805, 161, IEEE80211_CH_PASSIVE_ONLY}, | |
10602 | {5825, 165, IEEE80211_CH_PASSIVE_ONLY}}, | |
10603 | } | |
afbf30a2 JK |
10604 | }; |
10605 | ||
43f66a6c JK |
10606 | #define MAX_HW_RESTARTS 5 |
10607 | static int ipw_up(struct ipw_priv *priv) | |
10608 | { | |
4f36f808 | 10609 | int rc, i, j; |
43f66a6c JK |
10610 | |
10611 | if (priv->status & STATUS_EXIT_PENDING) | |
10612 | return -EIO; | |
10613 | ||
f6c5cb7c JK |
10614 | if (cmdlog && !priv->cmdlog) { |
10615 | priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog, | |
10616 | GFP_KERNEL); | |
10617 | if (priv->cmdlog == NULL) { | |
10618 | IPW_ERROR("Error allocating %d command log entries.\n", | |
10619 | cmdlog); | |
10620 | } else { | |
10621 | memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog); | |
10622 | priv->cmdlog_len = cmdlog; | |
10623 | } | |
10624 | } | |
10625 | ||
0edd5b44 | 10626 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
bf79451e | 10627 | /* Load the microcode, firmware, and eeprom. |
43f66a6c JK |
10628 | * Also start the clocks. */ |
10629 | rc = ipw_load(priv); | |
10630 | if (rc) { | |
a4f6bbb3 | 10631 | IPW_ERROR("Unable to load firmware: %d\n", rc); |
43f66a6c JK |
10632 | return rc; |
10633 | } | |
10634 | ||
10635 | ipw_init_ordinals(priv); | |
10636 | if (!(priv->config & CFG_CUSTOM_MAC)) | |
10637 | eeprom_parse_mac(priv, priv->mac_addr); | |
10638 | memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); | |
10639 | ||
4f36f808 JK |
10640 | for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) { |
10641 | if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE], | |
10642 | ipw_geos[j].name, 3)) | |
10643 | break; | |
10644 | } | |
03520576 JK |
10645 | if (j == ARRAY_SIZE(ipw_geos)) { |
10646 | IPW_WARNING("SKU [%c%c%c] not recognized.\n", | |
10647 | priv->eeprom[EEPROM_COUNTRY_CODE + 0], | |
10648 | priv->eeprom[EEPROM_COUNTRY_CODE + 1], | |
10649 | priv->eeprom[EEPROM_COUNTRY_CODE + 2]); | |
4f36f808 | 10650 | j = 0; |
03520576 | 10651 | } |
1867b117 | 10652 | if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) { |
4f36f808 JK |
10653 | IPW_WARNING("Could not set geography."); |
10654 | return 0; | |
10655 | } | |
10656 | ||
b095c381 JK |
10657 | if (priv->status & STATUS_RF_KILL_SW) { |
10658 | IPW_WARNING("Radio disabled by module parameter.\n"); | |
10659 | return 0; | |
10660 | } else if (rf_kill_active(priv)) { | |
10661 | IPW_WARNING("Radio Frequency Kill Switch is On:\n" | |
10662 | "Kill switch must be turned off for " | |
10663 | "wireless networking to work.\n"); | |
10664 | queue_delayed_work(priv->workqueue, &priv->rf_kill, | |
10665 | 2 * HZ); | |
43f66a6c | 10666 | return 0; |
c848d0af | 10667 | } |
43f66a6c JK |
10668 | |
10669 | rc = ipw_config(priv); | |
10670 | if (!rc) { | |
10671 | IPW_DEBUG_INFO("Configured device on count %i\n", i); | |
e666619e JK |
10672 | |
10673 | /* If configure to try and auto-associate, kick | |
10674 | * off a scan. */ | |
10675 | queue_work(priv->workqueue, &priv->request_scan); | |
afbf30a2 | 10676 | |
43f66a6c | 10677 | return 0; |
43f66a6c | 10678 | } |
bf79451e | 10679 | |
c848d0af | 10680 | IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc); |
43f66a6c JK |
10681 | IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", |
10682 | i, MAX_HW_RESTARTS); | |
10683 | ||
10684 | /* We had an error bringing up the hardware, so take it | |
10685 | * all the way back down so we can try again */ | |
10686 | ipw_down(priv); | |
10687 | } | |
10688 | ||
bf79451e | 10689 | /* tried to restart and config the device for as long as our |
43f66a6c | 10690 | * patience could withstand */ |
0edd5b44 | 10691 | IPW_ERROR("Unable to initialize device after %d attempts.\n", i); |
c848d0af | 10692 | |
43f66a6c JK |
10693 | return -EIO; |
10694 | } | |
10695 | ||
c848d0af JK |
10696 | static void ipw_bg_up(void *data) |
10697 | { | |
10698 | struct ipw_priv *priv = data; | |
4644151b | 10699 | mutex_lock(&priv->mutex); |
c848d0af | 10700 | ipw_up(data); |
4644151b | 10701 | mutex_unlock(&priv->mutex); |
c848d0af JK |
10702 | } |
10703 | ||
b095c381 | 10704 | static void ipw_deinit(struct ipw_priv *priv) |
43f66a6c | 10705 | { |
b095c381 JK |
10706 | int i; |
10707 | ||
10708 | if (priv->status & STATUS_SCANNING) { | |
10709 | IPW_DEBUG_INFO("Aborting scan during shutdown.\n"); | |
10710 | ipw_abort_scan(priv); | |
10711 | } | |
10712 | ||
10713 | if (priv->status & STATUS_ASSOCIATED) { | |
10714 | IPW_DEBUG_INFO("Disassociating during shutdown.\n"); | |
10715 | ipw_disassociate(priv); | |
10716 | } | |
10717 | ||
10718 | ipw_led_shutdown(priv); | |
10719 | ||
10720 | /* Wait up to 1s for status to change to not scanning and not | |
10721 | * associated (disassociation can take a while for a ful 802.11 | |
10722 | * exchange */ | |
10723 | for (i = 1000; i && (priv->status & | |
10724 | (STATUS_DISASSOCIATING | | |
10725 | STATUS_ASSOCIATED | STATUS_SCANNING)); i--) | |
10726 | udelay(10); | |
10727 | ||
10728 | if (priv->status & (STATUS_DISASSOCIATING | | |
10729 | STATUS_ASSOCIATED | STATUS_SCANNING)) | |
10730 | IPW_DEBUG_INFO("Still associated or scanning...\n"); | |
10731 | else | |
10732 | IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i); | |
10733 | ||
43f66a6c | 10734 | /* Attempt to disable the card */ |
43f66a6c | 10735 | ipw_send_card_disable(priv, 0); |
b095c381 JK |
10736 | |
10737 | priv->status &= ~STATUS_INIT; | |
10738 | } | |
10739 | ||
10740 | static void ipw_down(struct ipw_priv *priv) | |
10741 | { | |
10742 | int exit_pending = priv->status & STATUS_EXIT_PENDING; | |
10743 | ||
10744 | priv->status |= STATUS_EXIT_PENDING; | |
10745 | ||
10746 | if (ipw_is_init(priv)) | |
10747 | ipw_deinit(priv); | |
10748 | ||
10749 | /* Wipe out the EXIT_PENDING status bit if we are not actually | |
10750 | * exiting the module */ | |
10751 | if (!exit_pending) | |
10752 | priv->status &= ~STATUS_EXIT_PENDING; | |
43f66a6c JK |
10753 | |
10754 | /* tell the device to stop sending interrupts */ | |
10755 | ipw_disable_interrupts(priv); | |
10756 | ||
10757 | /* Clear all bits but the RF Kill */ | |
b095c381 | 10758 | priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING; |
43f66a6c JK |
10759 | netif_carrier_off(priv->net_dev); |
10760 | netif_stop_queue(priv->net_dev); | |
10761 | ||
10762 | ipw_stop_nic(priv); | |
a613bffd JK |
10763 | |
10764 | ipw_led_radio_off(priv); | |
43f66a6c JK |
10765 | } |
10766 | ||
c848d0af JK |
10767 | static void ipw_bg_down(void *data) |
10768 | { | |
10769 | struct ipw_priv *priv = data; | |
4644151b | 10770 | mutex_lock(&priv->mutex); |
c848d0af | 10771 | ipw_down(data); |
4644151b | 10772 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10773 | } |
10774 | ||
10775 | /* Called by register_netdev() */ | |
10776 | static int ipw_net_init(struct net_device *dev) | |
10777 | { | |
10778 | struct ipw_priv *priv = ieee80211_priv(dev); | |
4644151b | 10779 | mutex_lock(&priv->mutex); |
43f66a6c | 10780 | |
c848d0af | 10781 | if (ipw_up(priv)) { |
4644151b | 10782 | mutex_unlock(&priv->mutex); |
43f66a6c | 10783 | return -EIO; |
c848d0af | 10784 | } |
43f66a6c | 10785 | |
4644151b | 10786 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10787 | return 0; |
10788 | } | |
10789 | ||
10790 | /* PCI driver stuff */ | |
10791 | static struct pci_device_id card_ids[] = { | |
10792 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0}, | |
10793 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0}, | |
10794 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0}, | |
10795 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0}, | |
10796 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0}, | |
10797 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0}, | |
10798 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0}, | |
10799 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0}, | |
10800 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0}, | |
10801 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0}, | |
10802 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0}, | |
10803 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0}, | |
10804 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0}, | |
10805 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0}, | |
10806 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0}, | |
10807 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0}, | |
10808 | {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, | |
10809 | {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, | |
0edd5b44 | 10810 | {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ |
a613bffd | 10811 | {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ |
0edd5b44 JG |
10812 | {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ |
10813 | {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ | |
bf79451e | 10814 | |
43f66a6c JK |
10815 | /* required last entry */ |
10816 | {0,} | |
10817 | }; | |
10818 | ||
10819 | MODULE_DEVICE_TABLE(pci, card_ids); | |
10820 | ||
10821 | static struct attribute *ipw_sysfs_entries[] = { | |
10822 | &dev_attr_rf_kill.attr, | |
10823 | &dev_attr_direct_dword.attr, | |
10824 | &dev_attr_indirect_byte.attr, | |
10825 | &dev_attr_indirect_dword.attr, | |
10826 | &dev_attr_mem_gpio_reg.attr, | |
10827 | &dev_attr_command_event_reg.attr, | |
10828 | &dev_attr_nic_type.attr, | |
10829 | &dev_attr_status.attr, | |
10830 | &dev_attr_cfg.attr, | |
b39860c6 JK |
10831 | &dev_attr_error.attr, |
10832 | &dev_attr_event_log.attr, | |
f6c5cb7c | 10833 | &dev_attr_cmd_log.attr, |
43f66a6c JK |
10834 | &dev_attr_eeprom_delay.attr, |
10835 | &dev_attr_ucode_version.attr, | |
10836 | &dev_attr_rtc.attr, | |
a613bffd JK |
10837 | &dev_attr_scan_age.attr, |
10838 | &dev_attr_led.attr, | |
b095c381 JK |
10839 | &dev_attr_speed_scan.attr, |
10840 | &dev_attr_net_stats.attr, | |
43f66a6c JK |
10841 | NULL |
10842 | }; | |
10843 | ||
10844 | static struct attribute_group ipw_attribute_group = { | |
10845 | .name = NULL, /* put in device directory */ | |
0edd5b44 | 10846 | .attrs = ipw_sysfs_entries, |
43f66a6c JK |
10847 | }; |
10848 | ||
0edd5b44 | 10849 | static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
43f66a6c JK |
10850 | { |
10851 | int err = 0; | |
10852 | struct net_device *net_dev; | |
10853 | void __iomem *base; | |
10854 | u32 length, val; | |
10855 | struct ipw_priv *priv; | |
afbf30a2 | 10856 | int i; |
43f66a6c JK |
10857 | |
10858 | net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); | |
10859 | if (net_dev == NULL) { | |
10860 | err = -ENOMEM; | |
10861 | goto out; | |
10862 | } | |
10863 | ||
10864 | priv = ieee80211_priv(net_dev); | |
10865 | priv->ieee = netdev_priv(net_dev); | |
a613bffd | 10866 | |
43f66a6c JK |
10867 | priv->net_dev = net_dev; |
10868 | priv->pci_dev = pdev; | |
0f52bf90 | 10869 | #ifdef CONFIG_IPW2200_DEBUG |
43f66a6c JK |
10870 | ipw_debug_level = debug; |
10871 | #endif | |
10872 | spin_lock_init(&priv->lock); | |
afbf30a2 JK |
10873 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) |
10874 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); | |
43f66a6c | 10875 | |
4644151b | 10876 | mutex_init(&priv->mutex); |
43f66a6c JK |
10877 | if (pci_enable_device(pdev)) { |
10878 | err = -ENODEV; | |
10879 | goto out_free_ieee80211; | |
10880 | } | |
10881 | ||
10882 | pci_set_master(pdev); | |
10883 | ||
0e08b44e | 10884 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
bf79451e | 10885 | if (!err) |
0e08b44e | 10886 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
43f66a6c JK |
10887 | if (err) { |
10888 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); | |
10889 | goto out_pci_disable_device; | |
10890 | } | |
10891 | ||
10892 | pci_set_drvdata(pdev, priv); | |
10893 | ||
10894 | err = pci_request_regions(pdev, DRV_NAME); | |
bf79451e | 10895 | if (err) |
43f66a6c JK |
10896 | goto out_pci_disable_device; |
10897 | ||
bf79451e | 10898 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
43f66a6c | 10899 | * PCI Tx retries from interfering with C3 CPU state */ |
bf79451e JG |
10900 | pci_read_config_dword(pdev, 0x40, &val); |
10901 | if ((val & 0x0000ff00) != 0) | |
43f66a6c | 10902 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
bf79451e | 10903 | |
43f66a6c JK |
10904 | length = pci_resource_len(pdev, 0); |
10905 | priv->hw_len = length; | |
bf79451e | 10906 | |
43f66a6c JK |
10907 | base = ioremap_nocache(pci_resource_start(pdev, 0), length); |
10908 | if (!base) { | |
10909 | err = -ENODEV; | |
10910 | goto out_pci_release_regions; | |
10911 | } | |
10912 | ||
10913 | priv->hw_base = base; | |
10914 | IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length); | |
10915 | IPW_DEBUG_INFO("pci_resource_base = %p\n", base); | |
10916 | ||
10917 | err = ipw_setup_deferred_work(priv); | |
10918 | if (err) { | |
10919 | IPW_ERROR("Unable to setup deferred work\n"); | |
10920 | goto out_iounmap; | |
10921 | } | |
10922 | ||
b095c381 | 10923 | ipw_sw_reset(priv, 1); |
43f66a6c | 10924 | |
0edd5b44 | 10925 | err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv); |
43f66a6c JK |
10926 | if (err) { |
10927 | IPW_ERROR("Error allocating IRQ %d\n", pdev->irq); | |
10928 | goto out_destroy_workqueue; | |
10929 | } | |
10930 | ||
10931 | SET_MODULE_OWNER(net_dev); | |
10932 | SET_NETDEV_DEV(net_dev, &pdev->dev); | |
10933 | ||
4644151b | 10934 | mutex_lock(&priv->mutex); |
c848d0af | 10935 | |
43f66a6c JK |
10936 | priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; |
10937 | priv->ieee->set_security = shim__set_security; | |
227d2dc1 | 10938 | priv->ieee->is_queue_full = ipw_net_is_queue_full; |
43f66a6c | 10939 | |
b095c381 | 10940 | #ifdef CONFIG_IPW_QOS |
3b9990cb JK |
10941 | priv->ieee->handle_probe_response = ipw_handle_beacon; |
10942 | priv->ieee->handle_beacon = ipw_handle_probe_response; | |
10943 | priv->ieee->handle_assoc_response = ipw_handle_assoc_response; | |
b095c381 JK |
10944 | #endif /* CONFIG_IPW_QOS */ |
10945 | ||
c848d0af JK |
10946 | priv->ieee->perfect_rssi = -20; |
10947 | priv->ieee->worst_rssi = -85; | |
43f66a6c JK |
10948 | |
10949 | net_dev->open = ipw_net_open; | |
10950 | net_dev->stop = ipw_net_stop; | |
10951 | net_dev->init = ipw_net_init; | |
10952 | net_dev->get_stats = ipw_net_get_stats; | |
10953 | net_dev->set_multicast_list = ipw_net_set_multicast_list; | |
10954 | net_dev->set_mac_address = ipw_net_set_mac_address; | |
97a78ca9 | 10955 | priv->wireless_data.spy_data = &priv->ieee->spy_data; |
97a78ca9 | 10956 | net_dev->wireless_data = &priv->wireless_data; |
43f66a6c JK |
10957 | net_dev->wireless_handlers = &ipw_wx_handler_def; |
10958 | net_dev->ethtool_ops = &ipw_ethtool_ops; | |
10959 | net_dev->irq = pdev->irq; | |
0edd5b44 | 10960 | net_dev->base_addr = (unsigned long)priv->hw_base; |
43f66a6c JK |
10961 | net_dev->mem_start = pci_resource_start(pdev, 0); |
10962 | net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1; | |
10963 | ||
10964 | err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); | |
10965 | if (err) { | |
10966 | IPW_ERROR("failed to create sysfs device attributes\n"); | |
4644151b | 10967 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10968 | goto out_release_irq; |
10969 | } | |
10970 | ||
4644151b | 10971 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
10972 | err = register_netdev(net_dev); |
10973 | if (err) { | |
10974 | IPW_ERROR("failed to register network device\n"); | |
a613bffd | 10975 | goto out_remove_sysfs; |
43f66a6c | 10976 | } |
48a84770 HBA |
10977 | |
10978 | printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg " | |
10979 | "channels, %d 802.11a channels)\n", | |
10980 | priv->ieee->geo.name, priv->ieee->geo.bg_channels, | |
10981 | priv->ieee->geo.a_channels); | |
10982 | ||
43f66a6c JK |
10983 | return 0; |
10984 | ||
a613bffd | 10985 | out_remove_sysfs: |
43f66a6c | 10986 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
0edd5b44 | 10987 | out_release_irq: |
43f66a6c | 10988 | free_irq(pdev->irq, priv); |
0edd5b44 | 10989 | out_destroy_workqueue: |
43f66a6c JK |
10990 | destroy_workqueue(priv->workqueue); |
10991 | priv->workqueue = NULL; | |
0edd5b44 | 10992 | out_iounmap: |
43f66a6c | 10993 | iounmap(priv->hw_base); |
0edd5b44 | 10994 | out_pci_release_regions: |
43f66a6c | 10995 | pci_release_regions(pdev); |
0edd5b44 | 10996 | out_pci_disable_device: |
43f66a6c JK |
10997 | pci_disable_device(pdev); |
10998 | pci_set_drvdata(pdev, NULL); | |
0edd5b44 | 10999 | out_free_ieee80211: |
43f66a6c | 11000 | free_ieee80211(priv->net_dev); |
0edd5b44 | 11001 | out: |
43f66a6c JK |
11002 | return err; |
11003 | } | |
11004 | ||
11005 | static void ipw_pci_remove(struct pci_dev *pdev) | |
11006 | { | |
11007 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
afbf30a2 JK |
11008 | struct list_head *p, *q; |
11009 | int i; | |
b095c381 | 11010 | |
43f66a6c JK |
11011 | if (!priv) |
11012 | return; | |
11013 | ||
4644151b | 11014 | mutex_lock(&priv->mutex); |
43f66a6c | 11015 | |
afbf30a2 | 11016 | priv->status |= STATUS_EXIT_PENDING; |
43f66a6c | 11017 | ipw_down(priv); |
43f66a6c JK |
11018 | sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); |
11019 | ||
4644151b | 11020 | mutex_unlock(&priv->mutex); |
43f66a6c JK |
11021 | |
11022 | unregister_netdev(priv->net_dev); | |
11023 | ||
11024 | if (priv->rxq) { | |
11025 | ipw_rx_queue_free(priv, priv->rxq); | |
11026 | priv->rxq = NULL; | |
11027 | } | |
11028 | ipw_tx_queue_free(priv); | |
11029 | ||
f6c5cb7c JK |
11030 | if (priv->cmdlog) { |
11031 | kfree(priv->cmdlog); | |
11032 | priv->cmdlog = NULL; | |
11033 | } | |
43f66a6c JK |
11034 | /* ipw_down will ensure that there is no more pending work |
11035 | * in the workqueue's, so we can safely remove them now. */ | |
a613bffd JK |
11036 | cancel_delayed_work(&priv->adhoc_check); |
11037 | cancel_delayed_work(&priv->gather_stats); | |
11038 | cancel_delayed_work(&priv->request_scan); | |
11039 | cancel_delayed_work(&priv->rf_kill); | |
11040 | cancel_delayed_work(&priv->scan_check); | |
11041 | destroy_workqueue(priv->workqueue); | |
11042 | priv->workqueue = NULL; | |
43f66a6c | 11043 | |
afbf30a2 JK |
11044 | /* Free MAC hash list for ADHOC */ |
11045 | for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) { | |
11046 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { | |
afbf30a2 | 11047 | list_del(p); |
489f4458 | 11048 | kfree(list_entry(p, struct ipw_ibss_seq, list)); |
afbf30a2 JK |
11049 | } |
11050 | } | |
11051 | ||
b39860c6 JK |
11052 | if (priv->error) { |
11053 | ipw_free_error_log(priv->error); | |
11054 | priv->error = NULL; | |
43f66a6c JK |
11055 | } |
11056 | ||
11057 | free_irq(pdev->irq, priv); | |
11058 | iounmap(priv->hw_base); | |
11059 | pci_release_regions(pdev); | |
11060 | pci_disable_device(pdev); | |
11061 | pci_set_drvdata(pdev, NULL); | |
11062 | free_ieee80211(priv->net_dev); | |
afbf30a2 | 11063 | free_firmware(); |
43f66a6c JK |
11064 | } |
11065 | ||
43f66a6c | 11066 | #ifdef CONFIG_PM |
583a4e88 | 11067 | static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
43f66a6c JK |
11068 | { |
11069 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
11070 | struct net_device *dev = priv->net_dev; | |
11071 | ||
11072 | printk(KERN_INFO "%s: Going into suspend...\n", dev->name); | |
11073 | ||
0edd5b44 | 11074 | /* Take down the device; powers it off, etc. */ |
43f66a6c JK |
11075 | ipw_down(priv); |
11076 | ||
11077 | /* Remove the PRESENT state of the device */ | |
11078 | netif_device_detach(dev); | |
11079 | ||
43f66a6c | 11080 | pci_save_state(pdev); |
43f66a6c | 11081 | pci_disable_device(pdev); |
583a4e88 | 11082 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
bf79451e | 11083 | |
43f66a6c JK |
11084 | return 0; |
11085 | } | |
11086 | ||
11087 | static int ipw_pci_resume(struct pci_dev *pdev) | |
11088 | { | |
11089 | struct ipw_priv *priv = pci_get_drvdata(pdev); | |
11090 | struct net_device *dev = priv->net_dev; | |
11091 | u32 val; | |
bf79451e | 11092 | |
43f66a6c JK |
11093 | printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); |
11094 | ||
ea2b26e0 | 11095 | pci_set_power_state(pdev, PCI_D0); |
43f66a6c | 11096 | pci_enable_device(pdev); |
43f66a6c | 11097 | pci_restore_state(pdev); |
ea2b26e0 | 11098 | |
43f66a6c JK |
11099 | /* |
11100 | * Suspend/Resume resets the PCI configuration space, so we have to | |
11101 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries | |
11102 | * from interfering with C3 CPU state. pci_restore_state won't help | |
11103 | * here since it only restores the first 64 bytes pci config header. | |
11104 | */ | |
bf79451e JG |
11105 | pci_read_config_dword(pdev, 0x40, &val); |
11106 | if ((val & 0x0000ff00) != 0) | |
43f66a6c JK |
11107 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
11108 | ||
11109 | /* Set the device back into the PRESENT state; this will also wake | |
11110 | * the queue of needed */ | |
11111 | netif_device_attach(dev); | |
11112 | ||
11113 | /* Bring the device back up */ | |
11114 | queue_work(priv->workqueue, &priv->up); | |
bf79451e | 11115 | |
43f66a6c JK |
11116 | return 0; |
11117 | } | |
11118 | #endif | |
11119 | ||
11120 | /* driver initialization stuff */ | |
11121 | static struct pci_driver ipw_driver = { | |
11122 | .name = DRV_NAME, | |
11123 | .id_table = card_ids, | |
11124 | .probe = ipw_pci_probe, | |
11125 | .remove = __devexit_p(ipw_pci_remove), | |
11126 | #ifdef CONFIG_PM | |
11127 | .suspend = ipw_pci_suspend, | |
11128 | .resume = ipw_pci_resume, | |
11129 | #endif | |
11130 | }; | |
11131 | ||
11132 | static int __init ipw_init(void) | |
11133 | { | |
11134 | int ret; | |
11135 | ||
11136 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); | |
11137 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); | |
11138 | ||
11139 | ret = pci_module_init(&ipw_driver); | |
11140 | if (ret) { | |
11141 | IPW_ERROR("Unable to initialize PCI module\n"); | |
11142 | return ret; | |
11143 | } | |
11144 | ||
0edd5b44 | 11145 | ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level); |
43f66a6c JK |
11146 | if (ret) { |
11147 | IPW_ERROR("Unable to create driver sysfs file\n"); | |
11148 | pci_unregister_driver(&ipw_driver); | |
11149 | return ret; | |
11150 | } | |
11151 | ||
11152 | return ret; | |
11153 | } | |
11154 | ||
11155 | static void __exit ipw_exit(void) | |
11156 | { | |
11157 | driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level); | |
11158 | pci_unregister_driver(&ipw_driver); | |
11159 | } | |
11160 | ||
11161 | module_param(disable, int, 0444); | |
11162 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); | |
11163 | ||
11164 | module_param(associate, int, 0444); | |
11165 | MODULE_PARM_DESC(associate, "auto associate when scanning (default on)"); | |
11166 | ||
11167 | module_param(auto_create, int, 0444); | |
11168 | MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); | |
11169 | ||
a613bffd | 11170 | module_param(led, int, 0444); |
c848d0af | 11171 | MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n"); |
a613bffd | 11172 | |
43f66a6c JK |
11173 | module_param(debug, int, 0444); |
11174 | MODULE_PARM_DESC(debug, "debug output mask"); | |
11175 | ||
11176 | module_param(channel, int, 0444); | |
bf79451e | 11177 | MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); |
43f66a6c | 11178 | |
b095c381 JK |
11179 | #ifdef CONFIG_IPW_QOS |
11180 | module_param(qos_enable, int, 0444); | |
11181 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis"); | |
11182 | ||
11183 | module_param(qos_burst_enable, int, 0444); | |
11184 | MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode"); | |
11185 | ||
11186 | module_param(qos_no_ack_mask, int, 0444); | |
11187 | MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack"); | |
43f66a6c | 11188 | |
b095c381 JK |
11189 | module_param(burst_duration_CCK, int, 0444); |
11190 | MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value"); | |
11191 | ||
11192 | module_param(burst_duration_OFDM, int, 0444); | |
11193 | MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value"); | |
11194 | #endif /* CONFIG_IPW_QOS */ | |
11195 | ||
11196 | #ifdef CONFIG_IPW2200_MONITOR | |
43f66a6c JK |
11197 | module_param(mode, int, 0444); |
11198 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); | |
11199 | #else | |
11200 | module_param(mode, int, 0444); | |
11201 | MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); | |
11202 | #endif | |
11203 | ||
810dabd4 ZY |
11204 | module_param(bt_coexist, int, 0444); |
11205 | MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)"); | |
11206 | ||
b095c381 | 11207 | module_param(hwcrypto, int, 0444); |
bde37d03 | 11208 | MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)"); |
b095c381 | 11209 | |
f6c5cb7c JK |
11210 | module_param(cmdlog, int, 0444); |
11211 | MODULE_PARM_DESC(cmdlog, | |
11212 | "allocate a ring buffer for logging firmware commands"); | |
11213 | ||
4bfdb91d ZY |
11214 | module_param(roaming, int, 0444); |
11215 | MODULE_PARM_DESC(roaming, "enable roaming support (default on)"); | |
11216 | ||
43f66a6c JK |
11217 | module_exit(ipw_exit); |
11218 | module_init(ipw_init); |