]>
Commit | Line | Data |
---|---|---|
b481de9c ZY |
1 | /****************************************************************************** |
2 | * | |
eb7ae89c | 3 | * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. |
b481de9c ZY |
4 | * |
5 | * Portions of this file are derived from the ipw3945 project, as well | |
6 | * as portions of the ieee80211 subsystem header files. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify it | |
9 | * under the terms of version 2 of the GNU General Public License as | |
10 | * published by the Free Software Foundation. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 | * more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License along with | |
18 | * this program; if not, write to the Free Software Foundation, Inc., | |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | |
20 | * | |
21 | * The full GNU General Public License is included in this distribution in the | |
22 | * file called LICENSE. | |
23 | * | |
24 | * Contact Information: | |
25 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> | |
26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
27 | * | |
28 | *****************************************************************************/ | |
29 | ||
b481de9c ZY |
30 | #include <linux/kernel.h> |
31 | #include <linux/module.h> | |
32 | #include <linux/version.h> | |
33 | #include <linux/init.h> | |
34 | #include <linux/pci.h> | |
35 | #include <linux/dma-mapping.h> | |
36 | #include <linux/delay.h> | |
37 | #include <linux/skbuff.h> | |
38 | #include <linux/netdevice.h> | |
39 | #include <linux/wireless.h> | |
40 | #include <linux/firmware.h> | |
b481de9c ZY |
41 | #include <linux/etherdevice.h> |
42 | #include <linux/if_arp.h> | |
43 | ||
b481de9c ZY |
44 | #include <net/mac80211.h> |
45 | ||
46 | #include <asm/div64.h> | |
47 | ||
6bc913bd | 48 | #include "iwl-eeprom.h" |
3e0d4cb1 | 49 | #include "iwl-dev.h" |
fee1247a | 50 | #include "iwl-core.h" |
3395f6e9 | 51 | #include "iwl-io.h" |
b481de9c | 52 | #include "iwl-helpers.h" |
6974e363 | 53 | #include "iwl-sta.h" |
f0832f13 | 54 | #include "iwl-calib.h" |
b481de9c | 55 | |
416e1438 | 56 | |
b481de9c ZY |
57 | /****************************************************************************** |
58 | * | |
59 | * module boiler plate | |
60 | * | |
61 | ******************************************************************************/ | |
62 | ||
b481de9c ZY |
63 | /* |
64 | * module name, copyright, version, etc. | |
65 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk | |
66 | */ | |
67 | ||
68 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" | |
69 | ||
0a6857e7 | 70 | #ifdef CONFIG_IWLWIFI_DEBUG |
b481de9c ZY |
71 | #define VD "d" |
72 | #else | |
73 | #define VD | |
74 | #endif | |
75 | ||
c8b0e6e1 | 76 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
b481de9c ZY |
77 | #define VS "s" |
78 | #else | |
79 | #define VS | |
80 | #endif | |
81 | ||
df48c323 | 82 | #define DRV_VERSION IWLWIFI_VERSION VD VS |
b481de9c | 83 | |
b481de9c ZY |
84 | |
85 | MODULE_DESCRIPTION(DRV_DESCRIPTION); | |
86 | MODULE_VERSION(DRV_VERSION); | |
87 | MODULE_AUTHOR(DRV_COPYRIGHT); | |
88 | MODULE_LICENSE("GPL"); | |
89 | ||
bb8c093b | 90 | static int iwl4965_is_empty_essid(const char *essid, int essid_len) |
b481de9c ZY |
91 | { |
92 | /* Single white space is for Linksys APs */ | |
93 | if (essid_len == 1 && essid[0] == ' ') | |
94 | return 1; | |
95 | ||
96 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ | |
97 | while (essid_len) { | |
98 | essid_len--; | |
99 | if (essid[essid_len] != '\0') | |
100 | return 0; | |
101 | } | |
102 | ||
103 | return 1; | |
104 | } | |
105 | ||
bb8c093b | 106 | static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) |
b481de9c ZY |
107 | { |
108 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; | |
109 | const char *s = essid; | |
110 | char *d = escaped; | |
111 | ||
bb8c093b | 112 | if (iwl4965_is_empty_essid(essid, essid_len)) { |
b481de9c ZY |
113 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
114 | return escaped; | |
115 | } | |
116 | ||
117 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); | |
118 | while (essid_len--) { | |
119 | if (*s == '\0') { | |
120 | *d++ = '\\'; | |
121 | *d++ = '0'; | |
122 | s++; | |
123 | } else | |
124 | *d++ = *s++; | |
125 | } | |
126 | *d = '\0'; | |
127 | return escaped; | |
128 | } | |
129 | ||
b481de9c | 130 | /*************** STATION TABLE MANAGEMENT **** |
9fbab516 | 131 | * mac80211 should be examined to determine if sta_info is duplicating |
b481de9c ZY |
132 | * the functionality provided here |
133 | */ | |
134 | ||
135 | /**************************************************************/ | |
136 | ||
b481de9c | 137 | |
b481de9c | 138 | |
deb09c43 EG |
139 | static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
140 | { | |
c1adf9fb | 141 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
deb09c43 EG |
142 | |
143 | if (hw_decrypt) | |
144 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; | |
145 | else | |
146 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; | |
147 | ||
148 | } | |
149 | ||
b481de9c | 150 | /** |
bb8c093b | 151 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
b481de9c ZY |
152 | * |
153 | * NOTE: This is really only useful during development and can eventually | |
154 | * be #ifdef'd out once the driver is stable and folks aren't actively | |
155 | * making changes | |
156 | */ | |
c1adf9fb | 157 | static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon) |
b481de9c ZY |
158 | { |
159 | int error = 0; | |
160 | int counter = 1; | |
161 | ||
162 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { | |
163 | error |= le32_to_cpu(rxon->flags & | |
164 | (RXON_FLG_TGJ_NARROW_BAND_MSK | | |
165 | RXON_FLG_RADAR_DETECT_MSK)); | |
166 | if (error) | |
167 | IWL_WARNING("check 24G fields %d | %d\n", | |
168 | counter++, error); | |
169 | } else { | |
170 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? | |
171 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); | |
172 | if (error) | |
173 | IWL_WARNING("check 52 fields %d | %d\n", | |
174 | counter++, error); | |
175 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); | |
176 | if (error) | |
177 | IWL_WARNING("check 52 CCK %d | %d\n", | |
178 | counter++, error); | |
179 | } | |
180 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; | |
181 | if (error) | |
182 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); | |
183 | ||
184 | /* make sure basic rates 6Mbps and 1Mbps are supported */ | |
185 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && | |
186 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); | |
187 | if (error) | |
188 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); | |
189 | ||
190 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); | |
191 | if (error) | |
192 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); | |
193 | ||
194 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) | |
195 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); | |
196 | if (error) | |
197 | IWL_WARNING("check CCK and short slot %d | %d\n", | |
198 | counter++, error); | |
199 | ||
200 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) | |
201 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); | |
202 | if (error) | |
203 | IWL_WARNING("check CCK & auto detect %d | %d\n", | |
204 | counter++, error); | |
205 | ||
206 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | | |
207 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); | |
208 | if (error) | |
209 | IWL_WARNING("check TGG and auto detect %d | %d\n", | |
210 | counter++, error); | |
211 | ||
212 | if (error) | |
213 | IWL_WARNING("Tuning to channel %d\n", | |
214 | le16_to_cpu(rxon->channel)); | |
215 | ||
216 | if (error) { | |
bb8c093b | 217 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
b481de9c ZY |
218 | return -1; |
219 | } | |
220 | return 0; | |
221 | } | |
222 | ||
223 | /** | |
9fbab516 | 224 | * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed |
01ebd063 | 225 | * @priv: staging_rxon is compared to active_rxon |
b481de9c | 226 | * |
9fbab516 BC |
227 | * If the RXON structure is changing enough to require a new tune, |
228 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that | |
229 | * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. | |
b481de9c | 230 | */ |
c79dd5b5 | 231 | static int iwl4965_full_rxon_required(struct iwl_priv *priv) |
b481de9c ZY |
232 | { |
233 | ||
234 | /* These items are only settable from the full RXON command */ | |
235 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || | |
236 | compare_ether_addr(priv->staging_rxon.bssid_addr, | |
237 | priv->active_rxon.bssid_addr) || | |
238 | compare_ether_addr(priv->staging_rxon.node_addr, | |
239 | priv->active_rxon.node_addr) || | |
240 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, | |
241 | priv->active_rxon.wlap_bssid_addr) || | |
242 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || | |
243 | (priv->staging_rxon.channel != priv->active_rxon.channel) || | |
244 | (priv->staging_rxon.air_propagation != | |
245 | priv->active_rxon.air_propagation) || | |
246 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != | |
247 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || | |
248 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != | |
249 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || | |
250 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || | |
251 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) | |
252 | return 1; | |
253 | ||
254 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can | |
255 | * be updated with the RXON_ASSOC command -- however only some | |
256 | * flag transitions are allowed using RXON_ASSOC */ | |
257 | ||
258 | /* Check if we are not switching bands */ | |
259 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != | |
260 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) | |
261 | return 1; | |
262 | ||
263 | /* Check if we are switching association toggle */ | |
264 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != | |
265 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) | |
266 | return 1; | |
267 | ||
268 | return 0; | |
269 | } | |
270 | ||
b481de9c | 271 | /** |
bb8c093b | 272 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
b481de9c | 273 | * |
01ebd063 | 274 | * The RXON command in staging_rxon is committed to the hardware and |
b481de9c ZY |
275 | * the active_rxon structure is updated with the new data. This |
276 | * function correctly transitions out of the RXON_ASSOC_MSK state if | |
277 | * a HW tune is required based on the RXON structure changes. | |
278 | */ | |
c79dd5b5 | 279 | static int iwl4965_commit_rxon(struct iwl_priv *priv) |
b481de9c ZY |
280 | { |
281 | /* cast away the const for active_rxon in this function */ | |
c1adf9fb | 282 | struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
0795af57 | 283 | DECLARE_MAC_BUF(mac); |
b481de9c ZY |
284 | int rc = 0; |
285 | ||
fee1247a | 286 | if (!iwl_is_alive(priv)) |
b481de9c ZY |
287 | return -1; |
288 | ||
289 | /* always get timestamp with Rx frame */ | |
290 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; | |
291 | ||
bb8c093b | 292 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
b481de9c ZY |
293 | if (rc) { |
294 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); | |
295 | return -EINVAL; | |
296 | } | |
297 | ||
298 | /* If we don't need to send a full RXON, we can use | |
bb8c093b | 299 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
b481de9c | 300 | * and other flags for the current radio configuration. */ |
bb8c093b | 301 | if (!iwl4965_full_rxon_required(priv)) { |
7e8c519e | 302 | rc = iwl_send_rxon_assoc(priv); |
b481de9c ZY |
303 | if (rc) { |
304 | IWL_ERROR("Error setting RXON_ASSOC " | |
305 | "configuration (%d).\n", rc); | |
306 | return rc; | |
307 | } | |
308 | ||
309 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); | |
310 | ||
311 | return 0; | |
312 | } | |
313 | ||
314 | /* station table will be cleared */ | |
315 | priv->assoc_station_added = 0; | |
316 | ||
b481de9c ZY |
317 | /* If we are currently associated and the new config requires |
318 | * an RXON_ASSOC and the new config wants the associated mask enabled, | |
319 | * we must clear the associated from the active configuration | |
320 | * before we apply the new config */ | |
3109ece1 | 321 | if (iwl_is_associated(priv) && |
b481de9c ZY |
322 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
323 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); | |
324 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
325 | ||
857485c0 | 326 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
c1adf9fb | 327 | sizeof(struct iwl_rxon_cmd), |
b481de9c ZY |
328 | &priv->active_rxon); |
329 | ||
330 | /* If the mask clearing failed then we set | |
331 | * active_rxon back to what it was previously */ | |
332 | if (rc) { | |
333 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; | |
334 | IWL_ERROR("Error clearing ASSOC_MSK on current " | |
335 | "configuration (%d).\n", rc); | |
336 | return rc; | |
337 | } | |
b481de9c ZY |
338 | } |
339 | ||
340 | IWL_DEBUG_INFO("Sending RXON\n" | |
341 | "* with%s RXON_FILTER_ASSOC_MSK\n" | |
342 | "* channel = %d\n" | |
0795af57 | 343 | "* bssid = %s\n", |
b481de9c ZY |
344 | ((priv->staging_rxon.filter_flags & |
345 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), | |
346 | le16_to_cpu(priv->staging_rxon.channel), | |
0795af57 | 347 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
b481de9c | 348 | |
099b40b7 | 349 | iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); |
b481de9c | 350 | /* Apply the new configuration */ |
857485c0 | 351 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
c1adf9fb | 352 | sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); |
b481de9c ZY |
353 | if (rc) { |
354 | IWL_ERROR("Error setting new configuration (%d).\n", rc); | |
355 | return rc; | |
356 | } | |
357 | ||
7a999bf0 | 358 | iwl_remove_station(priv, iwl_bcast_addr, 0); |
bf85ea4f | 359 | iwlcore_clear_stations_table(priv); |
556f8db7 | 360 | |
b481de9c ZY |
361 | if (!priv->error_recovering) |
362 | priv->start_calib = 0; | |
363 | ||
f0832f13 | 364 | iwl_init_sensitivity(priv); |
b481de9c ZY |
365 | |
366 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); | |
367 | ||
368 | /* If we issue a new RXON command which required a tune then we must | |
369 | * send a new TXPOWER command or we won't be able to Tx any frames */ | |
bb8c093b | 370 | rc = iwl4965_hw_reg_send_txpower(priv); |
b481de9c ZY |
371 | if (rc) { |
372 | IWL_ERROR("Error setting Tx power (%d).\n", rc); | |
373 | return rc; | |
374 | } | |
375 | ||
376 | /* Add the broadcast address so we can send broadcast frames */ | |
4f40e4d9 | 377 | if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) == |
b481de9c ZY |
378 | IWL_INVALID_STATION) { |
379 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); | |
380 | return -EIO; | |
381 | } | |
382 | ||
383 | /* If we have set the ASSOC_MSK and we are in BSS mode then | |
384 | * add the IWL_AP_ID to the station rate table */ | |
3109ece1 | 385 | if (iwl_is_associated(priv) && |
b481de9c | 386 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
4f40e4d9 | 387 | if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
b481de9c ZY |
388 | == IWL_INVALID_STATION) { |
389 | IWL_ERROR("Error adding AP address for transmit.\n"); | |
390 | return -EIO; | |
391 | } | |
392 | priv->assoc_station_added = 1; | |
6974e363 EG |
393 | if (priv->default_wep_key && |
394 | iwl_send_static_wepkey_cmd(priv, 0)) | |
395 | IWL_ERROR("Could not send WEP static key.\n"); | |
b481de9c ZY |
396 | } |
397 | ||
398 | return 0; | |
399 | } | |
400 | ||
5da4b55f MA |
401 | void iwl4965_update_chain_flags(struct iwl_priv *priv) |
402 | { | |
403 | ||
c7de35cd | 404 | iwl_set_rxon_chain(priv); |
5da4b55f MA |
405 | iwl4965_commit_rxon(priv); |
406 | } | |
407 | ||
c79dd5b5 | 408 | static int iwl4965_send_bt_config(struct iwl_priv *priv) |
b481de9c | 409 | { |
bb8c093b | 410 | struct iwl4965_bt_cmd bt_cmd = { |
b481de9c ZY |
411 | .flags = 3, |
412 | .lead_time = 0xAA, | |
413 | .max_kill = 1, | |
414 | .kill_ack_mask = 0, | |
415 | .kill_cts_mask = 0, | |
416 | }; | |
417 | ||
857485c0 | 418 | return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
bb8c093b | 419 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
b481de9c ZY |
420 | } |
421 | ||
c79dd5b5 | 422 | static int iwl4965_send_scan_abort(struct iwl_priv *priv) |
b481de9c | 423 | { |
db11d634 TW |
424 | int ret = 0; |
425 | struct iwl_rx_packet *res; | |
857485c0 | 426 | struct iwl_host_cmd cmd = { |
b481de9c ZY |
427 | .id = REPLY_SCAN_ABORT_CMD, |
428 | .meta.flags = CMD_WANT_SKB, | |
429 | }; | |
430 | ||
431 | /* If there isn't a scan actively going on in the hardware | |
432 | * then we are in between scan bands and not actually | |
433 | * actively scanning, so don't send the abort command */ | |
434 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { | |
435 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); | |
436 | return 0; | |
437 | } | |
438 | ||
db11d634 TW |
439 | ret = iwl_send_cmd_sync(priv, &cmd); |
440 | if (ret) { | |
b481de9c | 441 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
db11d634 | 442 | return ret; |
b481de9c ZY |
443 | } |
444 | ||
db11d634 | 445 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
b481de9c ZY |
446 | if (res->u.status != CAN_ABORT_STATUS) { |
447 | /* The scan abort will return 1 for success or | |
448 | * 2 for "failure". A failure condition can be | |
449 | * due to simply not being in an active scan which | |
450 | * can occur if we send the scan abort before we | |
451 | * the microcode has notified us that a scan is | |
452 | * completed. */ | |
453 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); | |
454 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); | |
455 | clear_bit(STATUS_SCAN_HW, &priv->status); | |
456 | } | |
457 | ||
458 | dev_kfree_skb_any(cmd.meta.u.skb); | |
459 | ||
db11d634 | 460 | return ret; |
b481de9c ZY |
461 | } |
462 | ||
b481de9c ZY |
463 | /* |
464 | * CARD_STATE_CMD | |
465 | * | |
9fbab516 | 466 | * Use: Sets the device's internal card state to enable, disable, or halt |
b481de9c ZY |
467 | * |
468 | * When in the 'enable' state the card operates as normal. | |
469 | * When in the 'disable' state, the card enters into a low power mode. | |
470 | * When in the 'halt' state, the card is shut down and must be fully | |
471 | * restarted to come back on. | |
472 | */ | |
c79dd5b5 | 473 | static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag) |
b481de9c | 474 | { |
857485c0 | 475 | struct iwl_host_cmd cmd = { |
b481de9c ZY |
476 | .id = REPLY_CARD_STATE_CMD, |
477 | .len = sizeof(u32), | |
478 | .data = &flags, | |
479 | .meta.flags = meta_flag, | |
480 | }; | |
481 | ||
857485c0 | 482 | return iwl_send_cmd(priv, &cmd); |
b481de9c ZY |
483 | } |
484 | ||
fcab423d | 485 | static void iwl_clear_free_frames(struct iwl_priv *priv) |
b481de9c ZY |
486 | { |
487 | struct list_head *element; | |
488 | ||
489 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", | |
490 | priv->frames_count); | |
491 | ||
492 | while (!list_empty(&priv->free_frames)) { | |
493 | element = priv->free_frames.next; | |
494 | list_del(element); | |
fcab423d | 495 | kfree(list_entry(element, struct iwl_frame, list)); |
b481de9c ZY |
496 | priv->frames_count--; |
497 | } | |
498 | ||
499 | if (priv->frames_count) { | |
500 | IWL_WARNING("%d frames still in use. Did we lose one?\n", | |
501 | priv->frames_count); | |
502 | priv->frames_count = 0; | |
503 | } | |
504 | } | |
505 | ||
fcab423d | 506 | static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) |
b481de9c | 507 | { |
fcab423d | 508 | struct iwl_frame *frame; |
b481de9c ZY |
509 | struct list_head *element; |
510 | if (list_empty(&priv->free_frames)) { | |
511 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); | |
512 | if (!frame) { | |
513 | IWL_ERROR("Could not allocate frame!\n"); | |
514 | return NULL; | |
515 | } | |
516 | ||
517 | priv->frames_count++; | |
518 | return frame; | |
519 | } | |
520 | ||
521 | element = priv->free_frames.next; | |
522 | list_del(element); | |
fcab423d | 523 | return list_entry(element, struct iwl_frame, list); |
b481de9c ZY |
524 | } |
525 | ||
fcab423d | 526 | static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame) |
b481de9c ZY |
527 | { |
528 | memset(frame, 0, sizeof(*frame)); | |
529 | list_add(&frame->list, &priv->free_frames); | |
530 | } | |
531 | ||
c79dd5b5 | 532 | unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, |
b481de9c ZY |
533 | struct ieee80211_hdr *hdr, |
534 | const u8 *dest, int left) | |
535 | { | |
536 | ||
3109ece1 | 537 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
b481de9c ZY |
538 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
539 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) | |
540 | return 0; | |
541 | ||
542 | if (priv->ibss_beacon->len > left) | |
543 | return 0; | |
544 | ||
545 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); | |
546 | ||
547 | return priv->ibss_beacon->len; | |
548 | } | |
549 | ||
39e88504 | 550 | static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv) |
b481de9c | 551 | { |
39e88504 GC |
552 | int i; |
553 | int rate_mask; | |
554 | ||
555 | /* Set rate mask*/ | |
556 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) | |
557 | rate_mask = priv->active_rate_basic & 0xF; | |
558 | else | |
559 | rate_mask = priv->active_rate_basic & 0xFF0; | |
b481de9c | 560 | |
39e88504 | 561 | /* Find lowest valid rate */ |
b481de9c | 562 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
1826dcc0 | 563 | i = iwl_rates[i].next_ieee) { |
b481de9c | 564 | if (rate_mask & (1 << i)) |
1826dcc0 | 565 | return iwl_rates[i].plcp; |
b481de9c ZY |
566 | } |
567 | ||
39e88504 GC |
568 | /* No valid rate was found. Assign the lowest one */ |
569 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) | |
570 | return IWL_RATE_1M_PLCP; | |
571 | else | |
572 | return IWL_RATE_6M_PLCP; | |
b481de9c ZY |
573 | } |
574 | ||
c79dd5b5 | 575 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
b481de9c | 576 | { |
fcab423d | 577 | struct iwl_frame *frame; |
b481de9c ZY |
578 | unsigned int frame_size; |
579 | int rc; | |
580 | u8 rate; | |
581 | ||
fcab423d | 582 | frame = iwl_get_free_frame(priv); |
b481de9c ZY |
583 | |
584 | if (!frame) { | |
585 | IWL_ERROR("Could not obtain free frame buffer for beacon " | |
586 | "command.\n"); | |
587 | return -ENOMEM; | |
588 | } | |
589 | ||
39e88504 | 590 | rate = iwl4965_rate_get_lowest_plcp(priv); |
b481de9c | 591 | |
bb8c093b | 592 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
b481de9c | 593 | |
857485c0 | 594 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
b481de9c ZY |
595 | &frame->u.cmd[0]); |
596 | ||
fcab423d | 597 | iwl_free_frame(priv, frame); |
b481de9c ZY |
598 | |
599 | return rc; | |
600 | } | |
601 | ||
b481de9c ZY |
602 | /****************************************************************************** |
603 | * | |
604 | * Misc. internal state and helper functions | |
605 | * | |
606 | ******************************************************************************/ | |
b481de9c | 607 | |
b481de9c | 608 | /** |
bb8c093b | 609 | * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field |
b481de9c ZY |
610 | * |
611 | * return : set the bit for each supported rate insert in ie | |
612 | */ | |
bb8c093b | 613 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
c7c46676 | 614 | u16 basic_rate, int *left) |
b481de9c ZY |
615 | { |
616 | u16 ret_rates = 0, bit; | |
617 | int i; | |
c7c46676 TW |
618 | u8 *cnt = ie; |
619 | u8 *rates = ie + 1; | |
b481de9c ZY |
620 | |
621 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { | |
622 | if (bit & supported_rate) { | |
623 | ret_rates |= bit; | |
1826dcc0 | 624 | rates[*cnt] = iwl_rates[i].ieee | |
c7c46676 TW |
625 | ((bit & basic_rate) ? 0x80 : 0x00); |
626 | (*cnt)++; | |
627 | (*left)--; | |
628 | if ((*left <= 0) || | |
629 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) | |
b481de9c ZY |
630 | break; |
631 | } | |
632 | } | |
633 | ||
634 | return ret_rates; | |
635 | } | |
636 | ||
d1141dfb EG |
637 | static void iwl4965_ht_conf(struct iwl_priv *priv, |
638 | struct ieee80211_bss_conf *bss_conf) | |
639 | { | |
640 | struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf; | |
641 | struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf; | |
642 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; | |
643 | ||
644 | IWL_DEBUG_MAC80211("enter: \n"); | |
645 | ||
646 | iwl_conf->is_ht = bss_conf->assoc_ht; | |
647 | ||
648 | if (!iwl_conf->is_ht) | |
649 | return; | |
650 | ||
651 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); | |
652 | ||
653 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) | |
a9841013 | 654 | iwl_conf->sgf |= HT_SHORT_GI_20MHZ; |
d1141dfb | 655 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
a9841013 | 656 | iwl_conf->sgf |= HT_SHORT_GI_40MHZ; |
d1141dfb EG |
657 | |
658 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); | |
659 | iwl_conf->max_amsdu_size = | |
660 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); | |
661 | ||
662 | iwl_conf->supported_chan_width = | |
663 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); | |
664 | iwl_conf->extension_chan_offset = | |
665 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; | |
666 | /* If no above or below channel supplied disable FAT channel */ | |
963f5517 EG |
667 | if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE && |
668 | iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) { | |
669 | iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE; | |
d1141dfb | 670 | iwl_conf->supported_chan_width = 0; |
963f5517 | 671 | } |
d1141dfb EG |
672 | |
673 | iwl_conf->tx_mimo_ps_mode = | |
674 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); | |
675 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); | |
676 | ||
677 | iwl_conf->control_channel = ht_bss_conf->primary_channel; | |
678 | iwl_conf->tx_chan_width = | |
679 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); | |
680 | iwl_conf->ht_protection = | |
681 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; | |
682 | iwl_conf->non_GF_STA_present = | |
683 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); | |
684 | ||
685 | IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel); | |
686 | IWL_DEBUG_MAC80211("leave\n"); | |
687 | } | |
688 | ||
689 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, | |
690 | u8 *pos, int *left) | |
691 | { | |
692 | struct ieee80211_ht_cap *ht_cap; | |
693 | ||
694 | if (!sband || !sband->ht_info.ht_supported) | |
695 | return; | |
696 | ||
697 | if (*left < sizeof(struct ieee80211_ht_cap)) | |
698 | return; | |
699 | ||
700 | *pos++ = sizeof(struct ieee80211_ht_cap); | |
701 | ht_cap = (struct ieee80211_ht_cap *) pos; | |
702 | ||
703 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); | |
704 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); | |
705 | ht_cap->ampdu_params_info = | |
706 | (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | | |
707 | ((sband->ht_info.ampdu_density << 2) & | |
708 | IEEE80211_HT_CAP_AMPDU_DENSITY); | |
709 | *left -= sizeof(struct ieee80211_ht_cap); | |
710 | } | |
d1141dfb | 711 | |
b481de9c | 712 | /** |
bb8c093b | 713 | * iwl4965_fill_probe_req - fill in all required fields and IE for probe request |
b481de9c | 714 | */ |
c79dd5b5 | 715 | static u16 iwl4965_fill_probe_req(struct iwl_priv *priv, |
78330fdd TW |
716 | enum ieee80211_band band, |
717 | struct ieee80211_mgmt *frame, | |
718 | int left, int is_direct) | |
b481de9c ZY |
719 | { |
720 | int len = 0; | |
721 | u8 *pos = NULL; | |
bee488db | 722 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
78330fdd | 723 | const struct ieee80211_supported_band *sband = |
d1141dfb | 724 | iwl_get_hw_mode(priv, band); |
b481de9c ZY |
725 | |
726 | /* Make sure there is enough space for the probe request, | |
727 | * two mandatory IEs and the data */ | |
728 | left -= 24; | |
729 | if (left < 0) | |
730 | return 0; | |
731 | len += 24; | |
732 | ||
733 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); | |
57bd1bea | 734 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
b481de9c | 735 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
57bd1bea | 736 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
b481de9c ZY |
737 | frame->seq_ctrl = 0; |
738 | ||
739 | /* fill in our indirect SSID IE */ | |
740 | /* ...next IE... */ | |
741 | ||
742 | left -= 2; | |
743 | if (left < 0) | |
744 | return 0; | |
745 | len += 2; | |
746 | pos = &(frame->u.probe_req.variable[0]); | |
747 | *pos++ = WLAN_EID_SSID; | |
748 | *pos++ = 0; | |
749 | ||
750 | /* fill in our direct SSID IE... */ | |
751 | if (is_direct) { | |
752 | /* ...next IE... */ | |
753 | left -= 2 + priv->essid_len; | |
754 | if (left < 0) | |
755 | return 0; | |
756 | /* ... fill it in... */ | |
757 | *pos++ = WLAN_EID_SSID; | |
758 | *pos++ = priv->essid_len; | |
759 | memcpy(pos, priv->essid, priv->essid_len); | |
760 | pos += priv->essid_len; | |
761 | len += 2 + priv->essid_len; | |
762 | } | |
763 | ||
764 | /* fill in supported rate */ | |
765 | /* ...next IE... */ | |
766 | left -= 2; | |
767 | if (left < 0) | |
768 | return 0; | |
c7c46676 | 769 | |
b481de9c ZY |
770 | /* ... fill it in... */ |
771 | *pos++ = WLAN_EID_SUPP_RATES; | |
772 | *pos = 0; | |
c7c46676 | 773 | |
bee488db | 774 | /* exclude 60M rate */ |
775 | active_rates = priv->rates_mask; | |
776 | active_rates &= ~IWL_RATE_60M_MASK; | |
777 | ||
778 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; | |
b481de9c | 779 | |
c7c46676 | 780 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
bb8c093b | 781 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
bee488db | 782 | active_rate_basic, &left); |
c7c46676 TW |
783 | active_rates &= ~ret_rates; |
784 | ||
bb8c093b | 785 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
bee488db | 786 | active_rate_basic, &left); |
c7c46676 TW |
787 | active_rates &= ~ret_rates; |
788 | ||
b481de9c ZY |
789 | len += 2 + *pos; |
790 | pos += (*pos) + 1; | |
c7c46676 | 791 | if (active_rates == 0) |
b481de9c ZY |
792 | goto fill_end; |
793 | ||
794 | /* fill in supported extended rate */ | |
795 | /* ...next IE... */ | |
796 | left -= 2; | |
797 | if (left < 0) | |
798 | return 0; | |
799 | /* ... fill it in... */ | |
800 | *pos++ = WLAN_EID_EXT_SUPP_RATES; | |
801 | *pos = 0; | |
bb8c093b | 802 | iwl4965_supported_rate_to_ie(pos, active_rates, |
bee488db | 803 | active_rate_basic, &left); |
b481de9c ZY |
804 | if (*pos > 0) |
805 | len += 2 + *pos; | |
806 | ||
b481de9c | 807 | fill_end: |
d1141dfb EG |
808 | /* fill in HT IE */ |
809 | left -= 2; | |
810 | if (left < 0) | |
811 | return 0; | |
812 | ||
813 | *pos++ = WLAN_EID_HT_CAPABILITY; | |
814 | *pos = 0; | |
815 | ||
816 | iwl_ht_cap_to_ie(sband, pos, &left); | |
817 | ||
818 | if (*pos > 0) | |
819 | len += 2 + *pos; | |
b481de9c ZY |
820 | return (u16)len; |
821 | } | |
822 | ||
823 | /* | |
824 | * QoS support | |
825 | */ | |
c79dd5b5 | 826 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
bb8c093b | 827 | struct iwl4965_qosparam_cmd *qos) |
b481de9c ZY |
828 | { |
829 | ||
857485c0 | 830 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
bb8c093b | 831 | sizeof(struct iwl4965_qosparam_cmd), qos); |
b481de9c ZY |
832 | } |
833 | ||
c79dd5b5 | 834 | static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
b481de9c ZY |
835 | { |
836 | unsigned long flags; | |
837 | ||
b481de9c ZY |
838 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
839 | return; | |
840 | ||
841 | if (!priv->qos_data.qos_enable) | |
842 | return; | |
843 | ||
844 | spin_lock_irqsave(&priv->lock, flags); | |
845 | priv->qos_data.def_qos_parm.qos_flags = 0; | |
846 | ||
847 | if (priv->qos_data.qos_cap.q_AP.queue_request && | |
848 | !priv->qos_data.qos_cap.q_AP.txop_request) | |
849 | priv->qos_data.def_qos_parm.qos_flags |= | |
850 | QOS_PARAM_FLG_TXOP_TYPE_MSK; | |
b481de9c ZY |
851 | if (priv->qos_data.qos_active) |
852 | priv->qos_data.def_qos_parm.qos_flags |= | |
853 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; | |
854 | ||
fd105e79 | 855 | if (priv->current_ht_config.is_ht) |
f1f1f5c7 | 856 | priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; |
f1f1f5c7 | 857 | |
b481de9c ZY |
858 | spin_unlock_irqrestore(&priv->lock, flags); |
859 | ||
3109ece1 | 860 | if (force || iwl_is_associated(priv)) { |
f1f1f5c7 TW |
861 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
862 | priv->qos_data.qos_active, | |
863 | priv->qos_data.def_qos_parm.qos_flags); | |
b481de9c | 864 | |
bb8c093b | 865 | iwl4965_send_qos_params_command(priv, |
b481de9c ZY |
866 | &(priv->qos_data.def_qos_parm)); |
867 | } | |
868 | } | |
869 | ||
c79dd5b5 | 870 | int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) |
b481de9c ZY |
871 | { |
872 | /* Filter incoming packets to determine if they are targeted toward | |
873 | * this network, discarding packets coming from ourselves */ | |
874 | switch (priv->iw_mode) { | |
875 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ | |
876 | /* packets from our adapter are dropped (echo) */ | |
877 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) | |
878 | return 0; | |
879 | /* {broad,multi}cast packets to our IBSS go through */ | |
880 | if (is_multicast_ether_addr(header->addr1)) | |
881 | return !compare_ether_addr(header->addr3, priv->bssid); | |
882 | /* packets to our adapter go through */ | |
883 | return !compare_ether_addr(header->addr1, priv->mac_addr); | |
884 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ | |
885 | /* packets from our adapter are dropped (echo) */ | |
886 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) | |
887 | return 0; | |
888 | /* {broad,multi}cast packets to our BSS go through */ | |
889 | if (is_multicast_ether_addr(header->addr1)) | |
890 | return !compare_ether_addr(header->addr2, priv->bssid); | |
891 | /* packets to our adapter go through */ | |
892 | return !compare_ether_addr(header->addr1, priv->mac_addr); | |
69dc5d9d TW |
893 | default: |
894 | break; | |
b481de9c ZY |
895 | } |
896 | ||
897 | return 1; | |
898 | } | |
899 | ||
b481de9c | 900 | |
b481de9c ZY |
901 | |
902 | /** | |
bb8c093b | 903 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
b481de9c ZY |
904 | * |
905 | * NOTE: priv->mutex is not required before calling this function | |
906 | */ | |
c79dd5b5 | 907 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
b481de9c ZY |
908 | { |
909 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { | |
910 | clear_bit(STATUS_SCANNING, &priv->status); | |
911 | return 0; | |
912 | } | |
913 | ||
914 | if (test_bit(STATUS_SCANNING, &priv->status)) { | |
915 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { | |
916 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); | |
917 | set_bit(STATUS_SCAN_ABORTING, &priv->status); | |
918 | queue_work(priv->workqueue, &priv->abort_scan); | |
919 | ||
920 | } else | |
921 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); | |
922 | ||
923 | return test_bit(STATUS_SCANNING, &priv->status); | |
924 | } | |
925 | ||
926 | return 0; | |
927 | } | |
928 | ||
929 | /** | |
bb8c093b | 930 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
b481de9c ZY |
931 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
932 | * | |
933 | * NOTE: priv->mutex must be held before calling this function | |
934 | */ | |
c79dd5b5 | 935 | static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) |
b481de9c ZY |
936 | { |
937 | unsigned long now = jiffies; | |
938 | int ret; | |
939 | ||
bb8c093b | 940 | ret = iwl4965_scan_cancel(priv); |
b481de9c ZY |
941 | if (ret && ms) { |
942 | mutex_unlock(&priv->mutex); | |
943 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && | |
944 | test_bit(STATUS_SCANNING, &priv->status)) | |
945 | msleep(1); | |
946 | mutex_lock(&priv->mutex); | |
947 | ||
948 | return test_bit(STATUS_SCANNING, &priv->status); | |
949 | } | |
950 | ||
951 | return ret; | |
952 | } | |
953 | ||
c79dd5b5 | 954 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
b481de9c ZY |
955 | { |
956 | /* Reset ieee stats */ | |
957 | ||
958 | /* We don't reset the net_device_stats (ieee->stats) on | |
959 | * re-association */ | |
960 | ||
961 | priv->last_seq_num = -1; | |
962 | priv->last_frag_num = -1; | |
963 | priv->last_packet_time = 0; | |
964 | ||
bb8c093b | 965 | iwl4965_scan_cancel(priv); |
b481de9c ZY |
966 | } |
967 | ||
968 | #define MAX_UCODE_BEACON_INTERVAL 4096 | |
969 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) | |
970 | ||
bb8c093b | 971 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
b481de9c ZY |
972 | { |
973 | u16 new_val = 0; | |
974 | u16 beacon_factor = 0; | |
975 | ||
976 | beacon_factor = | |
977 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) | |
978 | / MAX_UCODE_BEACON_INTERVAL; | |
979 | new_val = beacon_val / beacon_factor; | |
980 | ||
981 | return cpu_to_le16(new_val); | |
982 | } | |
983 | ||
c79dd5b5 | 984 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
b481de9c ZY |
985 | { |
986 | u64 interval_tm_unit; | |
987 | u64 tsf, result; | |
988 | unsigned long flags; | |
989 | struct ieee80211_conf *conf = NULL; | |
990 | u16 beacon_int = 0; | |
991 | ||
992 | conf = ieee80211_get_hw_conf(priv->hw); | |
993 | ||
994 | spin_lock_irqsave(&priv->lock, flags); | |
3109ece1 TW |
995 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
996 | priv->rxon_timing.timestamp.dw[0] = | |
997 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); | |
b481de9c ZY |
998 | |
999 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; | |
1000 | ||
3109ece1 | 1001 | tsf = priv->timestamp; |
b481de9c ZY |
1002 | |
1003 | beacon_int = priv->beacon_int; | |
1004 | spin_unlock_irqrestore(&priv->lock, flags); | |
1005 | ||
1006 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { | |
1007 | if (beacon_int == 0) { | |
1008 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); | |
1009 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); | |
1010 | } else { | |
1011 | priv->rxon_timing.beacon_interval = | |
1012 | cpu_to_le16(beacon_int); | |
1013 | priv->rxon_timing.beacon_interval = | |
bb8c093b | 1014 | iwl4965_adjust_beacon_interval( |
b481de9c ZY |
1015 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
1016 | } | |
1017 | ||
1018 | priv->rxon_timing.atim_window = 0; | |
1019 | } else { | |
1020 | priv->rxon_timing.beacon_interval = | |
bb8c093b | 1021 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
b481de9c ZY |
1022 | /* TODO: we need to get atim_window from upper stack |
1023 | * for now we set to 0 */ | |
1024 | priv->rxon_timing.atim_window = 0; | |
1025 | } | |
1026 | ||
1027 | interval_tm_unit = | |
1028 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); | |
1029 | result = do_div(tsf, interval_tm_unit); | |
1030 | priv->rxon_timing.beacon_init_val = | |
1031 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); | |
1032 | ||
1033 | IWL_DEBUG_ASSOC | |
1034 | ("beacon interval %d beacon timer %d beacon tim %d\n", | |
1035 | le16_to_cpu(priv->rxon_timing.beacon_interval), | |
1036 | le32_to_cpu(priv->rxon_timing.beacon_init_val), | |
1037 | le16_to_cpu(priv->rxon_timing.atim_window)); | |
1038 | } | |
1039 | ||
c79dd5b5 | 1040 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
b481de9c ZY |
1041 | { |
1042 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { | |
1043 | IWL_ERROR("APs don't scan.\n"); | |
1044 | return 0; | |
1045 | } | |
1046 | ||
fee1247a | 1047 | if (!iwl_is_ready_rf(priv)) { |
b481de9c ZY |
1048 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
1049 | return -EIO; | |
1050 | } | |
1051 | ||
1052 | if (test_bit(STATUS_SCANNING, &priv->status)) { | |
1053 | IWL_DEBUG_SCAN("Scan already in progress.\n"); | |
1054 | return -EAGAIN; | |
1055 | } | |
1056 | ||
1057 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { | |
1058 | IWL_DEBUG_SCAN("Scan request while abort pending. " | |
1059 | "Queuing.\n"); | |
1060 | return -EAGAIN; | |
1061 | } | |
1062 | ||
1063 | IWL_DEBUG_INFO("Starting scan...\n"); | |
1064 | priv->scan_bands = 2; | |
1065 | set_bit(STATUS_SCANNING, &priv->status); | |
1066 | priv->scan_start = jiffies; | |
1067 | priv->scan_pass_start = priv->scan_start; | |
1068 | ||
1069 | queue_work(priv->workqueue, &priv->request_scan); | |
1070 | ||
1071 | return 0; | |
1072 | } | |
1073 | ||
b481de9c | 1074 | |
82a66bbb TW |
1075 | static void iwl_set_flags_for_band(struct iwl_priv *priv, |
1076 | enum ieee80211_band band) | |
b481de9c | 1077 | { |
8318d78a | 1078 | if (band == IEEE80211_BAND_5GHZ) { |
b481de9c ZY |
1079 | priv->staging_rxon.flags &= |
1080 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK | |
1081 | | RXON_FLG_CCK_MSK); | |
1082 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; | |
1083 | } else { | |
508e32e1 | 1084 | /* Copied from iwl4965_post_associate() */ |
b481de9c ZY |
1085 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
1086 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; | |
1087 | else | |
1088 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; | |
1089 | ||
1090 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) | |
1091 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; | |
1092 | ||
1093 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; | |
1094 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; | |
1095 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; | |
1096 | } | |
1097 | } | |
1098 | ||
1099 | /* | |
01ebd063 | 1100 | * initialize rxon structure with default values from eeprom |
b481de9c | 1101 | */ |
c79dd5b5 | 1102 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
b481de9c | 1103 | { |
bf85ea4f | 1104 | const struct iwl_channel_info *ch_info; |
b481de9c ZY |
1105 | |
1106 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); | |
1107 | ||
1108 | switch (priv->iw_mode) { | |
1109 | case IEEE80211_IF_TYPE_AP: | |
1110 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; | |
1111 | break; | |
1112 | ||
1113 | case IEEE80211_IF_TYPE_STA: | |
1114 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; | |
1115 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; | |
1116 | break; | |
1117 | ||
1118 | case IEEE80211_IF_TYPE_IBSS: | |
1119 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; | |
1120 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; | |
1121 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | | |
1122 | RXON_FILTER_ACCEPT_GRP_MSK; | |
1123 | break; | |
1124 | ||
1125 | case IEEE80211_IF_TYPE_MNTR: | |
1126 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; | |
1127 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | | |
1128 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; | |
1129 | break; | |
69dc5d9d TW |
1130 | default: |
1131 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); | |
1132 | break; | |
b481de9c ZY |
1133 | } |
1134 | ||
1135 | #if 0 | |
1136 | /* TODO: Figure out when short_preamble would be set and cache from | |
1137 | * that */ | |
1138 | if (!hw_to_local(priv->hw)->short_preamble) | |
1139 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; | |
1140 | else | |
1141 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; | |
1142 | #endif | |
1143 | ||
8622e705 | 1144 | ch_info = iwl_get_channel_info(priv, priv->band, |
b481de9c ZY |
1145 | le16_to_cpu(priv->staging_rxon.channel)); |
1146 | ||
1147 | if (!ch_info) | |
1148 | ch_info = &priv->channel_info[0]; | |
1149 | ||
1150 | /* | |
1151 | * in some case A channels are all non IBSS | |
1152 | * in this case force B/G channel | |
1153 | */ | |
1154 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && | |
1155 | !(is_channel_ibss(ch_info))) | |
1156 | ch_info = &priv->channel_info[0]; | |
1157 | ||
1158 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); | |
8318d78a | 1159 | priv->band = ch_info->band; |
b481de9c | 1160 | |
82a66bbb | 1161 | iwl_set_flags_for_band(priv, priv->band); |
b481de9c ZY |
1162 | |
1163 | priv->staging_rxon.ofdm_basic_rates = | |
1164 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; | |
1165 | priv->staging_rxon.cck_basic_rates = | |
1166 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; | |
1167 | ||
1168 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | | |
1169 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); | |
1170 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); | |
1171 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); | |
1172 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; | |
1173 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; | |
c7de35cd | 1174 | iwl_set_rxon_chain(priv); |
b481de9c ZY |
1175 | } |
1176 | ||
c79dd5b5 | 1177 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
b481de9c | 1178 | { |
b481de9c | 1179 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
bf85ea4f | 1180 | const struct iwl_channel_info *ch_info; |
b481de9c | 1181 | |
8622e705 | 1182 | ch_info = iwl_get_channel_info(priv, |
8318d78a | 1183 | priv->band, |
b481de9c ZY |
1184 | le16_to_cpu(priv->staging_rxon.channel)); |
1185 | ||
1186 | if (!ch_info || !is_channel_ibss(ch_info)) { | |
1187 | IWL_ERROR("channel %d not IBSS channel\n", | |
1188 | le16_to_cpu(priv->staging_rxon.channel)); | |
1189 | return -EINVAL; | |
1190 | } | |
1191 | } | |
1192 | ||
b481de9c ZY |
1193 | priv->iw_mode = mode; |
1194 | ||
bb8c093b | 1195 | iwl4965_connection_init_rx_config(priv); |
b481de9c ZY |
1196 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
1197 | ||
bf85ea4f | 1198 | iwlcore_clear_stations_table(priv); |
b481de9c | 1199 | |
fde3571f | 1200 | /* dont commit rxon if rf-kill is on*/ |
fee1247a | 1201 | if (!iwl_is_ready_rf(priv)) |
fde3571f MA |
1202 | return -EAGAIN; |
1203 | ||
1204 | cancel_delayed_work(&priv->scan_check); | |
1205 | if (iwl4965_scan_cancel_timeout(priv, 100)) { | |
1206 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); | |
1207 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); | |
1208 | return -EAGAIN; | |
1209 | } | |
1210 | ||
bb8c093b | 1211 | iwl4965_commit_rxon(priv); |
b481de9c ZY |
1212 | |
1213 | return 0; | |
1214 | } | |
1215 | ||
c79dd5b5 | 1216 | static void iwl4965_set_rate(struct iwl_priv *priv) |
b481de9c | 1217 | { |
8318d78a | 1218 | const struct ieee80211_supported_band *hw = NULL; |
b481de9c ZY |
1219 | struct ieee80211_rate *rate; |
1220 | int i; | |
1221 | ||
d1141dfb | 1222 | hw = iwl_get_hw_mode(priv, priv->band); |
c4ba9621 SA |
1223 | if (!hw) { |
1224 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); | |
1225 | return; | |
1226 | } | |
b481de9c ZY |
1227 | |
1228 | priv->active_rate = 0; | |
1229 | priv->active_rate_basic = 0; | |
1230 | ||
8318d78a JB |
1231 | for (i = 0; i < hw->n_bitrates; i++) { |
1232 | rate = &(hw->bitrates[i]); | |
1233 | if (rate->hw_value < IWL_RATE_COUNT) | |
1234 | priv->active_rate |= (1 << rate->hw_value); | |
b481de9c ZY |
1235 | } |
1236 | ||
1237 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", | |
1238 | priv->active_rate, priv->active_rate_basic); | |
1239 | ||
1240 | /* | |
1241 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) | |
1242 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for | |
1243 | * OFDM | |
1244 | */ | |
1245 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) | |
1246 | priv->staging_rxon.cck_basic_rates = | |
1247 | ((priv->active_rate_basic & | |
1248 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; | |
1249 | else | |
1250 | priv->staging_rxon.cck_basic_rates = | |
1251 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; | |
1252 | ||
1253 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) | |
1254 | priv->staging_rxon.ofdm_basic_rates = | |
1255 | ((priv->active_rate_basic & | |
1256 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> | |
1257 | IWL_FIRST_OFDM_RATE) & 0xFF; | |
1258 | else | |
1259 | priv->staging_rxon.ofdm_basic_rates = | |
1260 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; | |
1261 | } | |
1262 | ||
64e72c3e | 1263 | int iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
b481de9c ZY |
1264 | { |
1265 | unsigned long flags; | |
1266 | ||
1267 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) | |
64e72c3e | 1268 | return 0; |
b481de9c ZY |
1269 | |
1270 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", | |
1271 | disable_radio ? "OFF" : "ON"); | |
1272 | ||
1273 | if (disable_radio) { | |
bb8c093b | 1274 | iwl4965_scan_cancel(priv); |
b481de9c ZY |
1275 | /* FIXME: This is a workaround for AP */ |
1276 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { | |
1277 | spin_lock_irqsave(&priv->lock, flags); | |
3395f6e9 | 1278 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
b481de9c ZY |
1279 | CSR_UCODE_SW_BIT_RFKILL); |
1280 | spin_unlock_irqrestore(&priv->lock, flags); | |
ad97edd2 | 1281 | /* call the host command only if no hw rf-kill set */ |
59003835 MA |
1282 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status) && |
1283 | iwl_is_ready(priv)) | |
ad97edd2 MA |
1284 | iwl4965_send_card_state(priv, |
1285 | CARD_STATE_CMD_DISABLE, | |
1286 | 0); | |
b481de9c | 1287 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
ad97edd2 MA |
1288 | |
1289 | /* make sure mac80211 stop sending Tx frame */ | |
1290 | if (priv->mac80211_registered) | |
1291 | ieee80211_stop_queues(priv->hw); | |
b481de9c | 1292 | } |
64e72c3e | 1293 | return 0; |
b481de9c ZY |
1294 | } |
1295 | ||
1296 | spin_lock_irqsave(&priv->lock, flags); | |
3395f6e9 | 1297 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
b481de9c ZY |
1298 | |
1299 | clear_bit(STATUS_RF_KILL_SW, &priv->status); | |
1300 | spin_unlock_irqrestore(&priv->lock, flags); | |
1301 | ||
1302 | /* wake up ucode */ | |
1303 | msleep(10); | |
1304 | ||
1305 | spin_lock_irqsave(&priv->lock, flags); | |
3395f6e9 TW |
1306 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
1307 | if (!iwl_grab_nic_access(priv)) | |
1308 | iwl_release_nic_access(priv); | |
b481de9c ZY |
1309 | spin_unlock_irqrestore(&priv->lock, flags); |
1310 | ||
1311 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { | |
1312 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " | |
1313 | "disabled by HW switch\n"); | |
64e72c3e | 1314 | return 0; |
b481de9c ZY |
1315 | } |
1316 | ||
1317 | queue_work(priv->workqueue, &priv->restart); | |
64e72c3e | 1318 | return 1; |
b481de9c ZY |
1319 | } |
1320 | ||
b481de9c ZY |
1321 | #define IWL_PACKET_RETRY_TIME HZ |
1322 | ||
c79dd5b5 | 1323 | int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) |
b481de9c ZY |
1324 | { |
1325 | u16 sc = le16_to_cpu(header->seq_ctrl); | |
1326 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; | |
1327 | u16 frag = sc & IEEE80211_SCTL_FRAG; | |
1328 | u16 *last_seq, *last_frag; | |
1329 | unsigned long *last_time; | |
1330 | ||
1331 | switch (priv->iw_mode) { | |
1332 | case IEEE80211_IF_TYPE_IBSS:{ | |
1333 | struct list_head *p; | |
bb8c093b | 1334 | struct iwl4965_ibss_seq *entry = NULL; |
b481de9c ZY |
1335 | u8 *mac = header->addr2; |
1336 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); | |
1337 | ||
1338 | __list_for_each(p, &priv->ibss_mac_hash[index]) { | |
bb8c093b | 1339 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
b481de9c ZY |
1340 | if (!compare_ether_addr(entry->mac, mac)) |
1341 | break; | |
1342 | } | |
1343 | if (p == &priv->ibss_mac_hash[index]) { | |
1344 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); | |
1345 | if (!entry) { | |
bc434dd2 | 1346 | IWL_ERROR("Cannot malloc new mac entry\n"); |
b481de9c ZY |
1347 | return 0; |
1348 | } | |
1349 | memcpy(entry->mac, mac, ETH_ALEN); | |
1350 | entry->seq_num = seq; | |
1351 | entry->frag_num = frag; | |
1352 | entry->packet_time = jiffies; | |
bc434dd2 | 1353 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
b481de9c ZY |
1354 | return 0; |
1355 | } | |
1356 | last_seq = &entry->seq_num; | |
1357 | last_frag = &entry->frag_num; | |
1358 | last_time = &entry->packet_time; | |
1359 | break; | |
1360 | } | |
1361 | case IEEE80211_IF_TYPE_STA: | |
1362 | last_seq = &priv->last_seq_num; | |
1363 | last_frag = &priv->last_frag_num; | |
1364 | last_time = &priv->last_packet_time; | |
1365 | break; | |
1366 | default: | |
1367 | return 0; | |
1368 | } | |
1369 | if ((*last_seq == seq) && | |
1370 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { | |
1371 | if (*last_frag == frag) | |
1372 | goto drop; | |
1373 | if (*last_frag + 1 != frag) | |
1374 | /* out-of-order fragment */ | |
1375 | goto drop; | |
1376 | } else | |
1377 | *last_seq = seq; | |
1378 | ||
1379 | *last_frag = frag; | |
1380 | *last_time = jiffies; | |
1381 | return 0; | |
1382 | ||
1383 | drop: | |
1384 | return 1; | |
1385 | } | |
1386 | ||
c8b0e6e1 | 1387 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
b481de9c ZY |
1388 | |
1389 | #include "iwl-spectrum.h" | |
1390 | ||
1391 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF | |
1392 | #define BEACON_TIME_MASK_HIGH 0xFF000000 | |
1393 | #define TIME_UNIT 1024 | |
1394 | ||
1395 | /* | |
1396 | * extended beacon time format | |
1397 | * time in usec will be changed into a 32-bit value in 8:24 format | |
1398 | * the high 1 byte is the beacon counts | |
1399 | * the lower 3 bytes is the time in usec within one beacon interval | |
1400 | */ | |
1401 | ||
bb8c093b | 1402 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
b481de9c ZY |
1403 | { |
1404 | u32 quot; | |
1405 | u32 rem; | |
1406 | u32 interval = beacon_interval * 1024; | |
1407 | ||
1408 | if (!interval || !usec) | |
1409 | return 0; | |
1410 | ||
1411 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); | |
1412 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; | |
1413 | ||
1414 | return (quot << 24) + rem; | |
1415 | } | |
1416 | ||
1417 | /* base is usually what we get from ucode with each received frame, | |
1418 | * the same as HW timer counter counting down | |
1419 | */ | |
1420 | ||
bb8c093b | 1421 | static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) |
b481de9c ZY |
1422 | { |
1423 | u32 base_low = base & BEACON_TIME_MASK_LOW; | |
1424 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; | |
1425 | u32 interval = beacon_interval * TIME_UNIT; | |
1426 | u32 res = (base & BEACON_TIME_MASK_HIGH) + | |
1427 | (addon & BEACON_TIME_MASK_HIGH); | |
1428 | ||
1429 | if (base_low > addon_low) | |
1430 | res += base_low - addon_low; | |
1431 | else if (base_low < addon_low) { | |
1432 | res += interval + base_low - addon_low; | |
1433 | res += (1 << 24); | |
1434 | } else | |
1435 | res += (1 << 24); | |
1436 | ||
1437 | return cpu_to_le32(res); | |
1438 | } | |
1439 | ||
c79dd5b5 | 1440 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
b481de9c ZY |
1441 | struct ieee80211_measurement_params *params, |
1442 | u8 type) | |
1443 | { | |
bb8c093b | 1444 | struct iwl4965_spectrum_cmd spectrum; |
db11d634 | 1445 | struct iwl_rx_packet *res; |
857485c0 | 1446 | struct iwl_host_cmd cmd = { |
b481de9c ZY |
1447 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
1448 | .data = (void *)&spectrum, | |
1449 | .meta.flags = CMD_WANT_SKB, | |
1450 | }; | |
1451 | u32 add_time = le64_to_cpu(params->start_time); | |
1452 | int rc; | |
1453 | int spectrum_resp_status; | |
1454 | int duration = le16_to_cpu(params->duration); | |
1455 | ||
3109ece1 | 1456 | if (iwl_is_associated(priv)) |
b481de9c | 1457 | add_time = |
bb8c093b | 1458 | iwl4965_usecs_to_beacons( |
b481de9c ZY |
1459 | le64_to_cpu(params->start_time) - priv->last_tsf, |
1460 | le16_to_cpu(priv->rxon_timing.beacon_interval)); | |
1461 | ||
1462 | memset(&spectrum, 0, sizeof(spectrum)); | |
1463 | ||
1464 | spectrum.channel_count = cpu_to_le16(1); | |
1465 | spectrum.flags = | |
1466 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; | |
1467 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; | |
1468 | cmd.len = sizeof(spectrum); | |
1469 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); | |
1470 | ||
3109ece1 | 1471 | if (iwl_is_associated(priv)) |
b481de9c | 1472 | spectrum.start_time = |
bb8c093b | 1473 | iwl4965_add_beacon_time(priv->last_beacon_time, |
b481de9c ZY |
1474 | add_time, |
1475 | le16_to_cpu(priv->rxon_timing.beacon_interval)); | |
1476 | else | |
1477 | spectrum.start_time = 0; | |
1478 | ||
1479 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); | |
1480 | spectrum.channels[0].channel = params->channel; | |
1481 | spectrum.channels[0].type = type; | |
1482 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) | |
1483 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | | |
1484 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; | |
1485 | ||
857485c0 | 1486 | rc = iwl_send_cmd_sync(priv, &cmd); |
b481de9c ZY |
1487 | if (rc) |
1488 | return rc; | |
1489 | ||
db11d634 | 1490 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
b481de9c ZY |
1491 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
1492 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); | |
1493 | rc = -EIO; | |
1494 | } | |
1495 | ||
1496 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); | |
1497 | switch (spectrum_resp_status) { | |
1498 | case 0: /* Command will be handled */ | |
1499 | if (res->u.spectrum.id != 0xff) { | |
1500 | IWL_DEBUG_INFO | |
1501 | ("Replaced existing measurement: %d\n", | |
1502 | res->u.spectrum.id); | |
1503 | priv->measurement_status &= ~MEASUREMENT_READY; | |
1504 | } | |
1505 | priv->measurement_status |= MEASUREMENT_ACTIVE; | |
1506 | rc = 0; | |
1507 | break; | |
1508 | ||
1509 | case 1: /* Command will not be handled */ | |
1510 | rc = -EAGAIN; | |
1511 | break; | |
1512 | } | |
1513 | ||
1514 | dev_kfree_skb_any(cmd.meta.u.skb); | |
1515 | ||
1516 | return rc; | |
1517 | } | |
1518 | #endif | |
1519 | ||
b481de9c ZY |
1520 | /****************************************************************************** |
1521 | * | |
1522 | * Generic RX handler implementations | |
1523 | * | |
1524 | ******************************************************************************/ | |
885ba202 TW |
1525 | static void iwl_rx_reply_alive(struct iwl_priv *priv, |
1526 | struct iwl_rx_mem_buffer *rxb) | |
b481de9c | 1527 | { |
db11d634 | 1528 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
885ba202 | 1529 | struct iwl_alive_resp *palive; |
b481de9c ZY |
1530 | struct delayed_work *pwork; |
1531 | ||
1532 | palive = &pkt->u.alive_frame; | |
1533 | ||
1534 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " | |
1535 | "0x%01X 0x%01X\n", | |
1536 | palive->is_valid, palive->ver_type, | |
1537 | palive->ver_subtype); | |
1538 | ||
1539 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { | |
1540 | IWL_DEBUG_INFO("Initialization Alive received.\n"); | |
1541 | memcpy(&priv->card_alive_init, | |
1542 | &pkt->u.alive_frame, | |
885ba202 | 1543 | sizeof(struct iwl_init_alive_resp)); |
b481de9c ZY |
1544 | pwork = &priv->init_alive_start; |
1545 | } else { | |
1546 | IWL_DEBUG_INFO("Runtime Alive received.\n"); | |
1547 | memcpy(&priv->card_alive, &pkt->u.alive_frame, | |
885ba202 | 1548 | sizeof(struct iwl_alive_resp)); |
b481de9c ZY |
1549 | pwork = &priv->alive_start; |
1550 | } | |
1551 | ||
1552 | /* We delay the ALIVE response by 5ms to | |
1553 | * give the HW RF Kill time to activate... */ | |
1554 | if (palive->is_valid == UCODE_VALID_OK) | |
1555 | queue_delayed_work(priv->workqueue, pwork, | |
1556 | msecs_to_jiffies(5)); | |
1557 | else | |
1558 | IWL_WARNING("uCode did not respond OK.\n"); | |
1559 | } | |
1560 | ||
c79dd5b5 | 1561 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
a55360e4 | 1562 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1563 | { |
db11d634 | 1564 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
b481de9c ZY |
1565 | |
1566 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " | |
1567 | "seq 0x%04X ser 0x%08X\n", | |
1568 | le32_to_cpu(pkt->u.err_resp.error_type), | |
1569 | get_cmd_string(pkt->u.err_resp.cmd_id), | |
1570 | pkt->u.err_resp.cmd_id, | |
1571 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), | |
1572 | le32_to_cpu(pkt->u.err_resp.error_info)); | |
1573 | } | |
1574 | ||
1575 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x | |
1576 | ||
a55360e4 | 1577 | static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1578 | { |
db11d634 | 1579 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
c1adf9fb | 1580 | struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; |
bb8c093b | 1581 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
b481de9c ZY |
1582 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
1583 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); | |
1584 | rxon->channel = csa->channel; | |
1585 | priv->staging_rxon.channel = csa->channel; | |
1586 | } | |
1587 | ||
c79dd5b5 | 1588 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
a55360e4 | 1589 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1590 | { |
c8b0e6e1 | 1591 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
db11d634 | 1592 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
bb8c093b | 1593 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
b481de9c ZY |
1594 | |
1595 | if (!report->state) { | |
f3d67999 EK |
1596 | IWL_DEBUG(IWL_DL_11H, |
1597 | "Spectrum Measure Notification: Start\n"); | |
b481de9c ZY |
1598 | return; |
1599 | } | |
1600 | ||
1601 | memcpy(&priv->measure_report, report, sizeof(*report)); | |
1602 | priv->measurement_status |= MEASUREMENT_READY; | |
1603 | #endif | |
1604 | } | |
1605 | ||
c79dd5b5 | 1606 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
a55360e4 | 1607 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1608 | { |
0a6857e7 | 1609 | #ifdef CONFIG_IWLWIFI_DEBUG |
db11d634 | 1610 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
bb8c093b | 1611 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
b481de9c ZY |
1612 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
1613 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); | |
1614 | #endif | |
1615 | } | |
1616 | ||
c79dd5b5 | 1617 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
a55360e4 | 1618 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1619 | { |
db11d634 | 1620 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
b481de9c ZY |
1621 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
1622 | "notification for %s:\n", | |
1623 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); | |
bf403db8 | 1624 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); |
b481de9c ZY |
1625 | } |
1626 | ||
bb8c093b | 1627 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
b481de9c | 1628 | { |
c79dd5b5 TW |
1629 | struct iwl_priv *priv = |
1630 | container_of(work, struct iwl_priv, beacon_update); | |
b481de9c ZY |
1631 | struct sk_buff *beacon; |
1632 | ||
1633 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ | |
e039fa4a | 1634 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
b481de9c ZY |
1635 | |
1636 | if (!beacon) { | |
1637 | IWL_ERROR("update beacon failed\n"); | |
1638 | return; | |
1639 | } | |
1640 | ||
1641 | mutex_lock(&priv->mutex); | |
1642 | /* new beacon skb is allocated every time; dispose previous.*/ | |
1643 | if (priv->ibss_beacon) | |
1644 | dev_kfree_skb(priv->ibss_beacon); | |
1645 | ||
1646 | priv->ibss_beacon = beacon; | |
1647 | mutex_unlock(&priv->mutex); | |
1648 | ||
bb8c093b | 1649 | iwl4965_send_beacon_cmd(priv); |
b481de9c ZY |
1650 | } |
1651 | ||
4e39317d EG |
1652 | /** |
1653 | * iwl4965_bg_statistics_periodic - Timer callback to queue statistics | |
1654 | * | |
1655 | * This callback is provided in order to send a statistics request. | |
1656 | * | |
1657 | * This timer function is continually reset to execute within | |
1658 | * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION | |
1659 | * was received. We need to ensure we receive the statistics in order | |
1660 | * to update the temperature used for calibrating the TXPOWER. | |
1661 | */ | |
1662 | static void iwl4965_bg_statistics_periodic(unsigned long data) | |
1663 | { | |
1664 | struct iwl_priv *priv = (struct iwl_priv *)data; | |
1665 | ||
1666 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
1667 | return; | |
1668 | ||
1669 | iwl_send_statistics_request(priv, CMD_ASYNC); | |
1670 | } | |
1671 | ||
c79dd5b5 | 1672 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
a55360e4 | 1673 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1674 | { |
0a6857e7 | 1675 | #ifdef CONFIG_IWLWIFI_DEBUG |
db11d634 | 1676 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
bb8c093b CH |
1677 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
1678 | u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); | |
b481de9c ZY |
1679 | |
1680 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " | |
1681 | "tsf %d %d rate %d\n", | |
1682 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, | |
1683 | beacon->beacon_notify_hdr.failure_frame, | |
1684 | le32_to_cpu(beacon->ibss_mgr_status), | |
1685 | le32_to_cpu(beacon->high_tsf), | |
1686 | le32_to_cpu(beacon->low_tsf), rate); | |
1687 | #endif | |
1688 | ||
1689 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && | |
1690 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) | |
1691 | queue_work(priv->workqueue, &priv->beacon_update); | |
1692 | } | |
1693 | ||
1694 | /* Service response to REPLY_SCAN_CMD (0x80) */ | |
c79dd5b5 | 1695 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
a55360e4 | 1696 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1697 | { |
0a6857e7 | 1698 | #ifdef CONFIG_IWLWIFI_DEBUG |
db11d634 | 1699 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
bb8c093b CH |
1700 | struct iwl4965_scanreq_notification *notif = |
1701 | (struct iwl4965_scanreq_notification *)pkt->u.raw; | |
b481de9c ZY |
1702 | |
1703 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); | |
1704 | #endif | |
1705 | } | |
1706 | ||
1707 | /* Service SCAN_START_NOTIFICATION (0x82) */ | |
c79dd5b5 | 1708 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
a55360e4 | 1709 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1710 | { |
db11d634 | 1711 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
bb8c093b CH |
1712 | struct iwl4965_scanstart_notification *notif = |
1713 | (struct iwl4965_scanstart_notification *)pkt->u.raw; | |
b481de9c ZY |
1714 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
1715 | IWL_DEBUG_SCAN("Scan start: " | |
1716 | "%d [802.11%s] " | |
1717 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", | |
1718 | notif->channel, | |
1719 | notif->band ? "bg" : "a", | |
1720 | notif->tsf_high, | |
1721 | notif->tsf_low, notif->status, notif->beacon_timer); | |
1722 | } | |
1723 | ||
1724 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ | |
c79dd5b5 | 1725 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
a55360e4 | 1726 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1727 | { |
db11d634 | 1728 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
bb8c093b CH |
1729 | struct iwl4965_scanresults_notification *notif = |
1730 | (struct iwl4965_scanresults_notification *)pkt->u.raw; | |
b481de9c ZY |
1731 | |
1732 | IWL_DEBUG_SCAN("Scan ch.res: " | |
1733 | "%d [802.11%s] " | |
1734 | "(TSF: 0x%08X:%08X) - %d " | |
1735 | "elapsed=%lu usec (%dms since last)\n", | |
1736 | notif->channel, | |
1737 | notif->band ? "bg" : "a", | |
1738 | le32_to_cpu(notif->tsf_high), | |
1739 | le32_to_cpu(notif->tsf_low), | |
1740 | le32_to_cpu(notif->statistics[0]), | |
1741 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, | |
1742 | jiffies_to_msecs(elapsed_jiffies | |
1743 | (priv->last_scan_jiffies, jiffies))); | |
1744 | ||
1745 | priv->last_scan_jiffies = jiffies; | |
7878a5a4 | 1746 | priv->next_scan_jiffies = 0; |
b481de9c ZY |
1747 | } |
1748 | ||
1749 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ | |
c79dd5b5 | 1750 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
a55360e4 | 1751 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1752 | { |
db11d634 | 1753 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
bb8c093b | 1754 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
b481de9c ZY |
1755 | |
1756 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", | |
1757 | scan_notif->scanned_channels, | |
1758 | scan_notif->tsf_low, | |
1759 | scan_notif->tsf_high, scan_notif->status); | |
1760 | ||
1761 | /* The HW is no longer scanning */ | |
1762 | clear_bit(STATUS_SCAN_HW, &priv->status); | |
1763 | ||
1764 | /* The scan completion notification came in, so kill that timer... */ | |
1765 | cancel_delayed_work(&priv->scan_check); | |
1766 | ||
1767 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", | |
1768 | (priv->scan_bands == 2) ? "2.4" : "5.2", | |
1769 | jiffies_to_msecs(elapsed_jiffies | |
1770 | (priv->scan_pass_start, jiffies))); | |
1771 | ||
1772 | /* Remove this scanned band from the list | |
1773 | * of pending bands to scan */ | |
1774 | priv->scan_bands--; | |
1775 | ||
1776 | /* If a request to abort was given, or the scan did not succeed | |
1777 | * then we reset the scan state machine and terminate, | |
1778 | * re-queuing another scan if one has been requested */ | |
1779 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { | |
1780 | IWL_DEBUG_INFO("Aborted scan completed.\n"); | |
1781 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); | |
1782 | } else { | |
1783 | /* If there are more bands on this scan pass reschedule */ | |
1784 | if (priv->scan_bands > 0) | |
1785 | goto reschedule; | |
1786 | } | |
1787 | ||
1788 | priv->last_scan_jiffies = jiffies; | |
7878a5a4 | 1789 | priv->next_scan_jiffies = 0; |
b481de9c ZY |
1790 | IWL_DEBUG_INFO("Setting scan to off\n"); |
1791 | ||
1792 | clear_bit(STATUS_SCANNING, &priv->status); | |
1793 | ||
1794 | IWL_DEBUG_INFO("Scan took %dms\n", | |
1795 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); | |
1796 | ||
1797 | queue_work(priv->workqueue, &priv->scan_completed); | |
1798 | ||
1799 | return; | |
1800 | ||
1801 | reschedule: | |
1802 | priv->scan_pass_start = jiffies; | |
1803 | queue_work(priv->workqueue, &priv->request_scan); | |
1804 | } | |
1805 | ||
1806 | /* Handle notification from uCode that card's power state is changing | |
1807 | * due to software, hardware, or critical temperature RFKILL */ | |
c79dd5b5 | 1808 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
a55360e4 | 1809 | struct iwl_rx_mem_buffer *rxb) |
b481de9c | 1810 | { |
db11d634 | 1811 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
b481de9c ZY |
1812 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
1813 | unsigned long status = priv->status; | |
1814 | ||
1815 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", | |
1816 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", | |
1817 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); | |
1818 | ||
1819 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | | |
1820 | RF_CARD_DISABLED)) { | |
1821 | ||
3395f6e9 | 1822 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
b481de9c ZY |
1823 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
1824 | ||
3395f6e9 TW |
1825 | if (!iwl_grab_nic_access(priv)) { |
1826 | iwl_write_direct32( | |
b481de9c ZY |
1827 | priv, HBUS_TARG_MBX_C, |
1828 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); | |
1829 | ||
3395f6e9 | 1830 | iwl_release_nic_access(priv); |
b481de9c ZY |
1831 | } |
1832 | ||
1833 | if (!(flags & RXON_CARD_DISABLED)) { | |
3395f6e9 | 1834 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
b481de9c | 1835 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
3395f6e9 TW |
1836 | if (!iwl_grab_nic_access(priv)) { |
1837 | iwl_write_direct32( | |
b481de9c ZY |
1838 | priv, HBUS_TARG_MBX_C, |
1839 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); | |
1840 | ||
3395f6e9 | 1841 | iwl_release_nic_access(priv); |
b481de9c ZY |
1842 | } |
1843 | } | |
1844 | ||
1845 | if (flags & RF_CARD_DISABLED) { | |
3395f6e9 | 1846 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
b481de9c | 1847 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
3395f6e9 TW |
1848 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
1849 | if (!iwl_grab_nic_access(priv)) | |
1850 | iwl_release_nic_access(priv); | |
b481de9c ZY |
1851 | } |
1852 | } | |
1853 | ||
1854 | if (flags & HW_CARD_DISABLED) | |
1855 | set_bit(STATUS_RF_KILL_HW, &priv->status); | |
1856 | else | |
1857 | clear_bit(STATUS_RF_KILL_HW, &priv->status); | |
1858 | ||
1859 | ||
1860 | if (flags & SW_CARD_DISABLED) | |
1861 | set_bit(STATUS_RF_KILL_SW, &priv->status); | |
1862 | else | |
1863 | clear_bit(STATUS_RF_KILL_SW, &priv->status); | |
1864 | ||
1865 | if (!(flags & RXON_CARD_DISABLED)) | |
bb8c093b | 1866 | iwl4965_scan_cancel(priv); |
b481de9c ZY |
1867 | |
1868 | if ((test_bit(STATUS_RF_KILL_HW, &status) != | |
1869 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || | |
1870 | (test_bit(STATUS_RF_KILL_SW, &status) != | |
1871 | test_bit(STATUS_RF_KILL_SW, &priv->status))) | |
1872 | queue_work(priv->workqueue, &priv->rf_kill); | |
1873 | else | |
1874 | wake_up_interruptible(&priv->wait_command_queue); | |
1875 | } | |
1876 | ||
37a44211 RR |
1877 | /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). |
1878 | * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ | |
1879 | static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv, | |
1880 | struct iwl_rx_mem_buffer *rxb) | |
1881 | { | |
1882 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; | |
1883 | priv->last_phy_res[0] = 1; | |
1884 | memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]), | |
1885 | sizeof(struct iwl4965_rx_phy_res)); | |
1886 | } | |
1887 | ||
b481de9c | 1888 | /** |
bb8c093b | 1889 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
b481de9c ZY |
1890 | * |
1891 | * Setup the RX handlers for each of the reply types sent from the uCode | |
1892 | * to the host. | |
1893 | * | |
1894 | * This function chains into the hardware specific files for them to setup | |
1895 | * any hardware specific handlers as well. | |
1896 | */ | |
c79dd5b5 | 1897 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
b481de9c | 1898 | { |
885ba202 | 1899 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; |
bb8c093b CH |
1900 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
1901 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; | |
b481de9c | 1902 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
bb8c093b CH |
1903 | iwl4965_rx_spectrum_measure_notif; |
1904 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; | |
b481de9c | 1905 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
bb8c093b CH |
1906 | iwl4965_rx_pm_debug_statistics_notif; |
1907 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; | |
b481de9c | 1908 | |
9fbab516 BC |
1909 | /* |
1910 | * The same handler is used for both the REPLY to a discrete | |
1911 | * statistics request from the host as well as for the periodic | |
1912 | * statistics notifications (after received beacons) from the uCode. | |
b481de9c | 1913 | */ |
bb8c093b CH |
1914 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
1915 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; | |
37a44211 | 1916 | /* scan handlers */ |
bb8c093b CH |
1917 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
1918 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; | |
b481de9c | 1919 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
bb8c093b | 1920 | iwl4965_rx_scan_results_notif; |
b481de9c | 1921 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
bb8c093b | 1922 | iwl4965_rx_scan_complete_notif; |
37a44211 | 1923 | /* status change handler */ |
bb8c093b | 1924 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
b481de9c | 1925 | |
c1354754 TW |
1926 | priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = |
1927 | iwl_rx_missed_beacon_notif; | |
37a44211 RR |
1928 | /* Rx handlers */ |
1929 | priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy; | |
1930 | priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx; | |
9fbab516 | 1931 | /* Set up hardware specific Rx handlers */ |
d4789efe | 1932 | priv->cfg->ops->lib->rx_handler_setup(priv); |
b481de9c ZY |
1933 | } |
1934 | ||
5c0eef96 MA |
1935 | /* |
1936 | * this should be called while priv->lock is locked | |
1937 | */ | |
a55360e4 | 1938 | static void __iwl_rx_replenish(struct iwl_priv *priv) |
b481de9c | 1939 | { |
a55360e4 TW |
1940 | iwl_rx_allocate(priv); |
1941 | iwl_rx_queue_restock(priv); | |
b481de9c ZY |
1942 | } |
1943 | ||
b481de9c ZY |
1944 | |
1945 | /** | |
a55360e4 | 1946 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
b481de9c ZY |
1947 | * |
1948 | * Uses the priv->rx_handlers callback function array to invoke | |
1949 | * the appropriate handlers, including command responses, | |
1950 | * frame-received notifications, and other notifications. | |
1951 | */ | |
a55360e4 | 1952 | void iwl_rx_handle(struct iwl_priv *priv) |
b481de9c | 1953 | { |
a55360e4 | 1954 | struct iwl_rx_mem_buffer *rxb; |
db11d634 | 1955 | struct iwl_rx_packet *pkt; |
a55360e4 | 1956 | struct iwl_rx_queue *rxq = &priv->rxq; |
b481de9c ZY |
1957 | u32 r, i; |
1958 | int reclaim; | |
1959 | unsigned long flags; | |
5c0eef96 | 1960 | u8 fill_rx = 0; |
d68ab680 | 1961 | u32 count = 8; |
b481de9c | 1962 | |
6440adb5 BC |
1963 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
1964 | * buffer that the driver may process (last buffer filled by ucode). */ | |
d67f5489 | 1965 | r = priv->cfg->ops->lib->shared_mem_rx_idx(priv); |
b481de9c ZY |
1966 | i = rxq->read; |
1967 | ||
1968 | /* Rx interrupt, but nothing sent from uCode */ | |
1969 | if (i == r) | |
f3d67999 | 1970 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i); |
b481de9c | 1971 | |
a55360e4 | 1972 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
5c0eef96 MA |
1973 | fill_rx = 1; |
1974 | ||
b481de9c ZY |
1975 | while (i != r) { |
1976 | rxb = rxq->queue[i]; | |
1977 | ||
9fbab516 | 1978 | /* If an RXB doesn't have a Rx queue slot associated with it, |
b481de9c ZY |
1979 | * then a bug has been introduced in the queue refilling |
1980 | * routines -- catch it here */ | |
1981 | BUG_ON(rxb == NULL); | |
1982 | ||
1983 | rxq->queue[i] = NULL; | |
1984 | ||
1985 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, | |
5425e490 | 1986 | priv->hw_params.rx_buf_size, |
b481de9c | 1987 | PCI_DMA_FROMDEVICE); |
db11d634 | 1988 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
b481de9c ZY |
1989 | |
1990 | /* Reclaim a command buffer only if this packet is a response | |
1991 | * to a (driver-originated) command. | |
1992 | * If the packet (e.g. Rx frame) originated from uCode, | |
1993 | * there is no command buffer to reclaim. | |
1994 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, | |
1995 | * but apparently a few don't get set; catch them here. */ | |
1996 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && | |
1997 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && | |
857485c0 | 1998 | (pkt->hdr.cmd != REPLY_RX) && |
cfe01709 | 1999 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
b481de9c ZY |
2000 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
2001 | (pkt->hdr.cmd != REPLY_TX); | |
2002 | ||
2003 | /* Based on type of command response or notification, | |
2004 | * handle those that need handling via function in | |
bb8c093b | 2005 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
b481de9c | 2006 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
f3d67999 EK |
2007 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r, |
2008 | i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); | |
b481de9c ZY |
2009 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
2010 | } else { | |
2011 | /* No handling needed */ | |
f3d67999 | 2012 | IWL_DEBUG(IWL_DL_RX, |
b481de9c ZY |
2013 | "r %d i %d No handler needed for %s, 0x%02x\n", |
2014 | r, i, get_cmd_string(pkt->hdr.cmd), | |
2015 | pkt->hdr.cmd); | |
2016 | } | |
2017 | ||
2018 | if (reclaim) { | |
9fbab516 | 2019 | /* Invoke any callbacks, transfer the skb to caller, and |
857485c0 | 2020 | * fire off the (possibly) blocking iwl_send_cmd() |
b481de9c ZY |
2021 | * as we reclaim the driver command queue */ |
2022 | if (rxb && rxb->skb) | |
17b88929 | 2023 | iwl_tx_cmd_complete(priv, rxb); |
b481de9c ZY |
2024 | else |
2025 | IWL_WARNING("Claim null rxb?\n"); | |
2026 | } | |
2027 | ||
2028 | /* For now we just don't re-use anything. We can tweak this | |
2029 | * later to try and re-use notification packets and SKBs that | |
2030 | * fail to Rx correctly */ | |
2031 | if (rxb->skb != NULL) { | |
2032 | priv->alloc_rxb_skb--; | |
2033 | dev_kfree_skb_any(rxb->skb); | |
2034 | rxb->skb = NULL; | |
2035 | } | |
2036 | ||
2037 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, | |
5425e490 | 2038 | priv->hw_params.rx_buf_size, |
9ee1ba47 | 2039 | PCI_DMA_FROMDEVICE); |
b481de9c ZY |
2040 | spin_lock_irqsave(&rxq->lock, flags); |
2041 | list_add_tail(&rxb->list, &priv->rxq.rx_used); | |
2042 | spin_unlock_irqrestore(&rxq->lock, flags); | |
2043 | i = (i + 1) & RX_QUEUE_MASK; | |
5c0eef96 MA |
2044 | /* If there are a lot of unused frames, |
2045 | * restock the Rx queue so ucode wont assert. */ | |
2046 | if (fill_rx) { | |
2047 | count++; | |
2048 | if (count >= 8) { | |
2049 | priv->rxq.read = i; | |
a55360e4 | 2050 | __iwl_rx_replenish(priv); |
5c0eef96 MA |
2051 | count = 0; |
2052 | } | |
2053 | } | |
b481de9c ZY |
2054 | } |
2055 | ||
2056 | /* Backtrack one entry */ | |
2057 | priv->rxq.read = i; | |
a55360e4 TW |
2058 | iwl_rx_queue_restock(priv); |
2059 | } | |
2060 | /* Convert linear signal-to-noise ratio into dB */ | |
2061 | static u8 ratio2dB[100] = { | |
2062 | /* 0 1 2 3 4 5 6 7 8 9 */ | |
2063 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ | |
2064 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ | |
2065 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ | |
2066 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ | |
2067 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ | |
2068 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ | |
2069 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ | |
2070 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ | |
2071 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ | |
2072 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ | |
2073 | }; | |
2074 | ||
2075 | /* Calculates a relative dB value from a ratio of linear | |
2076 | * (i.e. not dB) signal levels. | |
2077 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ | |
2078 | int iwl4965_calc_db_from_ratio(int sig_ratio) | |
2079 | { | |
2080 | /* 1000:1 or higher just report as 60 dB */ | |
2081 | if (sig_ratio >= 1000) | |
2082 | return 60; | |
2083 | ||
2084 | /* 100:1 or higher, divide by 10 and use table, | |
2085 | * add 20 dB to make up for divide by 10 */ | |
2086 | if (sig_ratio >= 100) | |
2087 | return (20 + (int)ratio2dB[sig_ratio/10]); | |
2088 | ||
2089 | /* We shouldn't see this */ | |
2090 | if (sig_ratio < 1) | |
2091 | return 0; | |
2092 | ||
2093 | /* Use table for ratios 1:1 - 99:1 */ | |
2094 | return (int)ratio2dB[sig_ratio]; | |
2095 | } | |
2096 | ||
2097 | #define PERFECT_RSSI (-20) /* dBm */ | |
2098 | #define WORST_RSSI (-95) /* dBm */ | |
2099 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) | |
2100 | ||
2101 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). | |
2102 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info | |
2103 | * about formulas used below. */ | |
2104 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) | |
2105 | { | |
2106 | int sig_qual; | |
2107 | int degradation = PERFECT_RSSI - rssi_dbm; | |
2108 | ||
2109 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) | |
2110 | * as indicator; formula is (signal dbm - noise dbm). | |
2111 | * SNR at or above 40 is a great signal (100%). | |
2112 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. | |
2113 | * Weakest usable signal is usually 10 - 15 dB SNR. */ | |
2114 | if (noise_dbm) { | |
2115 | if (rssi_dbm - noise_dbm >= 40) | |
2116 | return 100; | |
2117 | else if (rssi_dbm < noise_dbm) | |
2118 | return 0; | |
2119 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; | |
2120 | ||
2121 | /* Else use just the signal level. | |
2122 | * This formula is a least squares fit of data points collected and | |
2123 | * compared with a reference system that had a percentage (%) display | |
2124 | * for signal quality. */ | |
2125 | } else | |
2126 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * | |
2127 | (15 * RSSI_RANGE + 62 * degradation)) / | |
2128 | (RSSI_RANGE * RSSI_RANGE); | |
2129 | ||
2130 | if (sig_qual > 100) | |
2131 | sig_qual = 100; | |
2132 | else if (sig_qual < 1) | |
2133 | sig_qual = 0; | |
2134 | ||
2135 | return sig_qual; | |
b481de9c ZY |
2136 | } |
2137 | ||
0a6857e7 | 2138 | #ifdef CONFIG_IWLWIFI_DEBUG |
bf403db8 | 2139 | static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) |
b481de9c | 2140 | { |
c1adf9fb | 2141 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
0795af57 JP |
2142 | DECLARE_MAC_BUF(mac); |
2143 | ||
b481de9c | 2144 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
bf403db8 | 2145 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
b481de9c ZY |
2146 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
2147 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); | |
2148 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", | |
2149 | le32_to_cpu(rxon->filter_flags)); | |
2150 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); | |
2151 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", | |
2152 | rxon->ofdm_basic_rates); | |
2153 | IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates); | |
0795af57 JP |
2154 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
2155 | print_mac(mac, rxon->node_addr)); | |
2156 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", | |
2157 | print_mac(mac, rxon->bssid_addr)); | |
b481de9c ZY |
2158 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
2159 | } | |
2160 | #endif | |
2161 | ||
c79dd5b5 | 2162 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
b481de9c ZY |
2163 | { |
2164 | IWL_DEBUG_ISR("Enabling interrupts\n"); | |
2165 | set_bit(STATUS_INT_ENABLED, &priv->status); | |
3395f6e9 | 2166 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
b481de9c ZY |
2167 | } |
2168 | ||
0359facc MA |
2169 | /* call this function to flush any scheduled tasklet */ |
2170 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) | |
2171 | { | |
2172 | /* wait to make sure we flush pedding tasklet*/ | |
2173 | synchronize_irq(priv->pci_dev->irq); | |
2174 | tasklet_kill(&priv->irq_tasklet); | |
2175 | } | |
2176 | ||
c79dd5b5 | 2177 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
b481de9c ZY |
2178 | { |
2179 | clear_bit(STATUS_INT_ENABLED, &priv->status); | |
2180 | ||
2181 | /* disable interrupts from uCode/NIC to host */ | |
3395f6e9 | 2182 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
b481de9c ZY |
2183 | |
2184 | /* acknowledge/clear/reset any interrupts still pending | |
2185 | * from uCode or flow handler (Rx/Tx DMA) */ | |
3395f6e9 TW |
2186 | iwl_write32(priv, CSR_INT, 0xffffffff); |
2187 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); | |
b481de9c ZY |
2188 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
2189 | } | |
2190 | ||
b481de9c | 2191 | |
b481de9c | 2192 | /** |
bb8c093b | 2193 | * iwl4965_irq_handle_error - called for HW or SW error interrupt from card |
b481de9c | 2194 | */ |
c79dd5b5 | 2195 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
b481de9c | 2196 | { |
bb8c093b | 2197 | /* Set the FW error flag -- cleared on iwl4965_down */ |
b481de9c ZY |
2198 | set_bit(STATUS_FW_ERROR, &priv->status); |
2199 | ||
2200 | /* Cancel currently queued command. */ | |
2201 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); | |
2202 | ||
0a6857e7 | 2203 | #ifdef CONFIG_IWLWIFI_DEBUG |
bf403db8 | 2204 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
ede0cba4 | 2205 | iwl_dump_nic_error_log(priv); |
189a2b59 | 2206 | iwl_dump_nic_event_log(priv); |
bf403db8 | 2207 | iwl4965_print_rx_config_cmd(priv); |
b481de9c ZY |
2208 | } |
2209 | #endif | |
2210 | ||
2211 | wake_up_interruptible(&priv->wait_command_queue); | |
2212 | ||
2213 | /* Keep the restart process from trying to send host | |
2214 | * commands by clearing the INIT status bit */ | |
2215 | clear_bit(STATUS_READY, &priv->status); | |
2216 | ||
2217 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { | |
f3d67999 | 2218 | IWL_DEBUG(IWL_DL_FW_ERRORS, |
b481de9c ZY |
2219 | "Restarting adapter due to uCode error.\n"); |
2220 | ||
3109ece1 | 2221 | if (iwl_is_associated(priv)) { |
b481de9c ZY |
2222 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
2223 | sizeof(priv->recovery_rxon)); | |
2224 | priv->error_recovering = 1; | |
2225 | } | |
3a1081e8 EK |
2226 | if (priv->cfg->mod_params->restart_fw) |
2227 | queue_work(priv->workqueue, &priv->restart); | |
b481de9c ZY |
2228 | } |
2229 | } | |
2230 | ||
c79dd5b5 | 2231 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
b481de9c ZY |
2232 | { |
2233 | unsigned long flags; | |
2234 | ||
2235 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, | |
2236 | sizeof(priv->staging_rxon)); | |
2237 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
bb8c093b | 2238 | iwl4965_commit_rxon(priv); |
b481de9c | 2239 | |
4f40e4d9 | 2240 | iwl_rxon_add_station(priv, priv->bssid, 1); |
b481de9c ZY |
2241 | |
2242 | spin_lock_irqsave(&priv->lock, flags); | |
2243 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); | |
2244 | priv->error_recovering = 0; | |
2245 | spin_unlock_irqrestore(&priv->lock, flags); | |
2246 | } | |
2247 | ||
c79dd5b5 | 2248 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
b481de9c ZY |
2249 | { |
2250 | u32 inta, handled = 0; | |
2251 | u32 inta_fh; | |
2252 | unsigned long flags; | |
0a6857e7 | 2253 | #ifdef CONFIG_IWLWIFI_DEBUG |
b481de9c ZY |
2254 | u32 inta_mask; |
2255 | #endif | |
2256 | ||
2257 | spin_lock_irqsave(&priv->lock, flags); | |
2258 | ||
2259 | /* Ack/clear/reset pending uCode interrupts. | |
2260 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, | |
2261 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ | |
3395f6e9 TW |
2262 | inta = iwl_read32(priv, CSR_INT); |
2263 | iwl_write32(priv, CSR_INT, inta); | |
b481de9c ZY |
2264 | |
2265 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. | |
2266 | * Any new interrupts that happen after this, either while we're | |
2267 | * in this tasklet, or later, will show up in next ISR/tasklet. */ | |
3395f6e9 TW |
2268 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
2269 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); | |
b481de9c | 2270 | |
0a6857e7 | 2271 | #ifdef CONFIG_IWLWIFI_DEBUG |
bf403db8 | 2272 | if (priv->debug_level & IWL_DL_ISR) { |
9fbab516 | 2273 | /* just for debug */ |
3395f6e9 | 2274 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
b481de9c ZY |
2275 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
2276 | inta, inta_mask, inta_fh); | |
2277 | } | |
2278 | #endif | |
2279 | ||
2280 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not | |
2281 | * atomic, make sure that inta covers all the interrupts that | |
2282 | * we've discovered, even if FH interrupt came in just after | |
2283 | * reading CSR_INT. */ | |
6f83eaa1 | 2284 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
b481de9c | 2285 | inta |= CSR_INT_BIT_FH_RX; |
6f83eaa1 | 2286 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
b481de9c ZY |
2287 | inta |= CSR_INT_BIT_FH_TX; |
2288 | ||
2289 | /* Now service all interrupt bits discovered above. */ | |
2290 | if (inta & CSR_INT_BIT_HW_ERR) { | |
2291 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); | |
2292 | ||
2293 | /* Tell the device to stop sending interrupts */ | |
bb8c093b | 2294 | iwl4965_disable_interrupts(priv); |
b481de9c | 2295 | |
bb8c093b | 2296 | iwl4965_irq_handle_error(priv); |
b481de9c ZY |
2297 | |
2298 | handled |= CSR_INT_BIT_HW_ERR; | |
2299 | ||
2300 | spin_unlock_irqrestore(&priv->lock, flags); | |
2301 | ||
2302 | return; | |
2303 | } | |
2304 | ||
0a6857e7 | 2305 | #ifdef CONFIG_IWLWIFI_DEBUG |
bf403db8 | 2306 | if (priv->debug_level & (IWL_DL_ISR)) { |
b481de9c | 2307 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
25c03d8e JP |
2308 | if (inta & CSR_INT_BIT_SCD) |
2309 | IWL_DEBUG_ISR("Scheduler finished to transmit " | |
2310 | "the frame/frames.\n"); | |
b481de9c ZY |
2311 | |
2312 | /* Alive notification via Rx interrupt will do the real work */ | |
2313 | if (inta & CSR_INT_BIT_ALIVE) | |
2314 | IWL_DEBUG_ISR("Alive interrupt\n"); | |
2315 | } | |
2316 | #endif | |
2317 | /* Safely ignore these bits for debug checks below */ | |
25c03d8e | 2318 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
b481de9c | 2319 | |
9fbab516 | 2320 | /* HW RF KILL switch toggled */ |
b481de9c ZY |
2321 | if (inta & CSR_INT_BIT_RF_KILL) { |
2322 | int hw_rf_kill = 0; | |
3395f6e9 | 2323 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
b481de9c ZY |
2324 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
2325 | hw_rf_kill = 1; | |
2326 | ||
f3d67999 | 2327 | IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n", |
b481de9c ZY |
2328 | hw_rf_kill ? "disable radio":"enable radio"); |
2329 | ||
2330 | /* Queue restart only if RF_KILL switch was set to "kill" | |
2331 | * when we loaded driver, and is now set to "enable". | |
2332 | * After we're Alive, RF_KILL gets handled by | |
3230455d | 2333 | * iwl4965_rx_card_state_notif() */ |
53e49093 ZY |
2334 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
2335 | clear_bit(STATUS_RF_KILL_HW, &priv->status); | |
b481de9c | 2336 | queue_work(priv->workqueue, &priv->restart); |
53e49093 | 2337 | } |
b481de9c ZY |
2338 | |
2339 | handled |= CSR_INT_BIT_RF_KILL; | |
2340 | } | |
2341 | ||
9fbab516 | 2342 | /* Chip got too hot and stopped itself */ |
b481de9c ZY |
2343 | if (inta & CSR_INT_BIT_CT_KILL) { |
2344 | IWL_ERROR("Microcode CT kill error detected.\n"); | |
2345 | handled |= CSR_INT_BIT_CT_KILL; | |
2346 | } | |
2347 | ||
2348 | /* Error detected by uCode */ | |
2349 | if (inta & CSR_INT_BIT_SW_ERR) { | |
2350 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", | |
2351 | inta); | |
bb8c093b | 2352 | iwl4965_irq_handle_error(priv); |
b481de9c ZY |
2353 | handled |= CSR_INT_BIT_SW_ERR; |
2354 | } | |
2355 | ||
2356 | /* uCode wakes up after power-down sleep */ | |
2357 | if (inta & CSR_INT_BIT_WAKEUP) { | |
2358 | IWL_DEBUG_ISR("Wakeup interrupt\n"); | |
a55360e4 | 2359 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
babcebfa TW |
2360 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
2361 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); | |
2362 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); | |
2363 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); | |
2364 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); | |
2365 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); | |
b481de9c ZY |
2366 | |
2367 | handled |= CSR_INT_BIT_WAKEUP; | |
2368 | } | |
2369 | ||
2370 | /* All uCode command responses, including Tx command responses, | |
2371 | * Rx "responses" (frame-received notification), and other | |
2372 | * notifications from uCode come through here*/ | |
2373 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { | |
a55360e4 | 2374 | iwl_rx_handle(priv); |
b481de9c ZY |
2375 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
2376 | } | |
2377 | ||
2378 | if (inta & CSR_INT_BIT_FH_TX) { | |
2379 | IWL_DEBUG_ISR("Tx interrupt\n"); | |
2380 | handled |= CSR_INT_BIT_FH_TX; | |
dbb983b7 RR |
2381 | /* FH finished to write, send event */ |
2382 | priv->ucode_write_complete = 1; | |
2383 | wake_up_interruptible(&priv->wait_command_queue); | |
b481de9c ZY |
2384 | } |
2385 | ||
2386 | if (inta & ~handled) | |
2387 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); | |
2388 | ||
2389 | if (inta & ~CSR_INI_SET_MASK) { | |
2390 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", | |
2391 | inta & ~CSR_INI_SET_MASK); | |
2392 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); | |
2393 | } | |
2394 | ||
2395 | /* Re-enable all interrupts */ | |
0359facc MA |
2396 | /* only Re-enable if diabled by irq */ |
2397 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) | |
2398 | iwl4965_enable_interrupts(priv); | |
b481de9c | 2399 | |
0a6857e7 | 2400 | #ifdef CONFIG_IWLWIFI_DEBUG |
bf403db8 | 2401 | if (priv->debug_level & (IWL_DL_ISR)) { |
3395f6e9 TW |
2402 | inta = iwl_read32(priv, CSR_INT); |
2403 | inta_mask = iwl_read32(priv, CSR_INT_MASK); | |
2404 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); | |
b481de9c ZY |
2405 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
2406 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); | |
2407 | } | |
2408 | #endif | |
2409 | spin_unlock_irqrestore(&priv->lock, flags); | |
2410 | } | |
2411 | ||
bb8c093b | 2412 | static irqreturn_t iwl4965_isr(int irq, void *data) |
b481de9c | 2413 | { |
c79dd5b5 | 2414 | struct iwl_priv *priv = data; |
b481de9c ZY |
2415 | u32 inta, inta_mask; |
2416 | u32 inta_fh; | |
2417 | if (!priv) | |
2418 | return IRQ_NONE; | |
2419 | ||
2420 | spin_lock(&priv->lock); | |
2421 | ||
2422 | /* Disable (but don't clear!) interrupts here to avoid | |
2423 | * back-to-back ISRs and sporadic interrupts from our NIC. | |
2424 | * If we have something to service, the tasklet will re-enable ints. | |
2425 | * If we *don't* have something, we'll re-enable before leaving here. */ | |
3395f6e9 TW |
2426 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
2427 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); | |
b481de9c ZY |
2428 | |
2429 | /* Discover which interrupts are active/pending */ | |
3395f6e9 TW |
2430 | inta = iwl_read32(priv, CSR_INT); |
2431 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); | |
b481de9c ZY |
2432 | |
2433 | /* Ignore interrupt if there's nothing in NIC to service. | |
2434 | * This may be due to IRQ shared with another device, | |
2435 | * or due to sporadic interrupts thrown from our NIC. */ | |
2436 | if (!inta && !inta_fh) { | |
2437 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); | |
2438 | goto none; | |
2439 | } | |
2440 | ||
2441 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { | |
66fbb541 ON |
2442 | /* Hardware disappeared. It might have already raised |
2443 | * an interrupt */ | |
b481de9c | 2444 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
66fbb541 | 2445 | goto unplugged; |
b481de9c ZY |
2446 | } |
2447 | ||
2448 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", | |
2449 | inta, inta_mask, inta_fh); | |
2450 | ||
25c03d8e JP |
2451 | inta &= ~CSR_INT_BIT_SCD; |
2452 | ||
bb8c093b | 2453 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
25c03d8e JP |
2454 | if (likely(inta || inta_fh)) |
2455 | tasklet_schedule(&priv->irq_tasklet); | |
b481de9c | 2456 | |
66fbb541 ON |
2457 | unplugged: |
2458 | spin_unlock(&priv->lock); | |
b481de9c ZY |
2459 | return IRQ_HANDLED; |
2460 | ||
2461 | none: | |
2462 | /* re-enable interrupts here since we don't have anything to service. */ | |
0359facc MA |
2463 | /* only Re-enable if diabled by irq */ |
2464 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) | |
2465 | iwl4965_enable_interrupts(priv); | |
b481de9c ZY |
2466 | spin_unlock(&priv->lock); |
2467 | return IRQ_NONE; | |
2468 | } | |
2469 | ||
b481de9c ZY |
2470 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
2471 | * sending probe req. This should be set long enough to hear probe responses | |
2472 | * from more than one AP. */ | |
2473 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ | |
2474 | #define IWL_ACTIVE_DWELL_TIME_52 (10) | |
2475 | ||
2476 | /* For faster active scanning, scan will move to the next channel if fewer than | |
2477 | * PLCP_QUIET_THRESH packets are heard on this channel within | |
2478 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell | |
2479 | * time if it's a quiet channel (nothing responded to our probe, and there's | |
2480 | * no other traffic). | |
2481 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ | |
2482 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ | |
2483 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ | |
2484 | ||
2485 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. | |
2486 | * Must be set longer than active dwell time. | |
2487 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ | |
2488 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ | |
2489 | #define IWL_PASSIVE_DWELL_TIME_52 (10) | |
2490 | #define IWL_PASSIVE_DWELL_BASE (100) | |
2491 | #define IWL_CHANNEL_TUNE_TIME 5 | |
2492 | ||
c79dd5b5 | 2493 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
8318d78a | 2494 | enum ieee80211_band band) |
b481de9c | 2495 | { |
8318d78a | 2496 | if (band == IEEE80211_BAND_5GHZ) |
b481de9c ZY |
2497 | return IWL_ACTIVE_DWELL_TIME_52; |
2498 | else | |
2499 | return IWL_ACTIVE_DWELL_TIME_24; | |
2500 | } | |
2501 | ||
c79dd5b5 | 2502 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
8318d78a | 2503 | enum ieee80211_band band) |
b481de9c | 2504 | { |
8318d78a JB |
2505 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
2506 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? | |
b481de9c ZY |
2507 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
2508 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; | |
2509 | ||
3109ece1 | 2510 | if (iwl_is_associated(priv)) { |
b481de9c ZY |
2511 | /* If we're associated, we clamp the maximum passive |
2512 | * dwell time to be 98% of the beacon interval (minus | |
2513 | * 2 * channel tune time) */ | |
2514 | passive = priv->beacon_int; | |
2515 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) | |
2516 | passive = IWL_PASSIVE_DWELL_BASE; | |
2517 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; | |
2518 | } | |
2519 | ||
2520 | if (passive <= active) | |
2521 | passive = active + 1; | |
2522 | ||
2523 | return passive; | |
2524 | } | |
2525 | ||
c79dd5b5 | 2526 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
8318d78a | 2527 | enum ieee80211_band band, |
b481de9c | 2528 | u8 is_active, u8 direct_mask, |
bb8c093b | 2529 | struct iwl4965_scan_channel *scan_ch) |
b481de9c ZY |
2530 | { |
2531 | const struct ieee80211_channel *channels = NULL; | |
8318d78a | 2532 | const struct ieee80211_supported_band *sband; |
bf85ea4f | 2533 | const struct iwl_channel_info *ch_info; |
b481de9c ZY |
2534 | u16 passive_dwell = 0; |
2535 | u16 active_dwell = 0; | |
2536 | int added, i; | |
2537 | ||
d1141dfb | 2538 | sband = iwl_get_hw_mode(priv, band); |
8318d78a | 2539 | if (!sband) |
b481de9c ZY |
2540 | return 0; |
2541 | ||
8318d78a | 2542 | channels = sband->channels; |
b481de9c | 2543 | |
8318d78a JB |
2544 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
2545 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); | |
b481de9c | 2546 | |
8318d78a | 2547 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
182e2e66 JB |
2548 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
2549 | continue; | |
2550 | ||
8318d78a | 2551 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
b481de9c | 2552 | |
8622e705 | 2553 | ch_info = iwl_get_channel_info(priv, band, |
9fbab516 | 2554 | scan_ch->channel); |
b481de9c ZY |
2555 | if (!is_channel_valid(ch_info)) { |
2556 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", | |
2557 | scan_ch->channel); | |
2558 | continue; | |
2559 | } | |
2560 | ||
2561 | if (!is_active || is_channel_passive(ch_info) || | |
8318d78a | 2562 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
b481de9c ZY |
2563 | scan_ch->type = 0; /* passive */ |
2564 | else | |
2565 | scan_ch->type = 1; /* active */ | |
2566 | ||
2567 | if (scan_ch->type & 1) | |
2568 | scan_ch->type |= (direct_mask << 1); | |
2569 | ||
b481de9c ZY |
2570 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
2571 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); | |
2572 | ||
9fbab516 | 2573 | /* Set txpower levels to defaults */ |
b481de9c ZY |
2574 | scan_ch->tpc.dsp_atten = 110; |
2575 | /* scan_pwr_info->tpc.dsp_atten; */ | |
2576 | ||
2577 | /*scan_pwr_info->tpc.tx_gain; */ | |
8318d78a | 2578 | if (band == IEEE80211_BAND_5GHZ) |
b481de9c ZY |
2579 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
2580 | else { | |
2581 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); | |
2582 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use | |
9fbab516 | 2583 | * power level: |
8a1b0245 | 2584 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
b481de9c ZY |
2585 | */ |
2586 | } | |
2587 | ||
2588 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", | |
2589 | scan_ch->channel, | |
2590 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", | |
2591 | (scan_ch->type & 1) ? | |
2592 | active_dwell : passive_dwell); | |
2593 | ||
2594 | scan_ch++; | |
2595 | added++; | |
2596 | } | |
2597 | ||
2598 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); | |
2599 | return added; | |
2600 | } | |
2601 | ||
b481de9c ZY |
2602 | /****************************************************************************** |
2603 | * | |
2604 | * uCode download functions | |
2605 | * | |
2606 | ******************************************************************************/ | |
2607 | ||
c79dd5b5 | 2608 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
b481de9c | 2609 | { |
98c92211 TW |
2610 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
2611 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); | |
2612 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); | |
2613 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); | |
2614 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); | |
2615 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); | |
b481de9c ZY |
2616 | } |
2617 | ||
edcdf8b2 RR |
2618 | static void iwl4965_nic_start(struct iwl_priv *priv) |
2619 | { | |
2620 | /* Remove all resets to allow NIC to operate */ | |
2621 | iwl_write32(priv, CSR_RESET, 0); | |
2622 | } | |
2623 | ||
2624 | ||
b481de9c | 2625 | /** |
bb8c093b | 2626 | * iwl4965_read_ucode - Read uCode images from disk file. |
b481de9c ZY |
2627 | * |
2628 | * Copy into buffers for card to fetch via bus-mastering | |
2629 | */ | |
c79dd5b5 | 2630 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
b481de9c | 2631 | { |
bb8c093b | 2632 | struct iwl4965_ucode *ucode; |
90e759d1 | 2633 | int ret; |
b481de9c | 2634 | const struct firmware *ucode_raw; |
4bf775cd | 2635 | const char *name = priv->cfg->fw_name; |
b481de9c ZY |
2636 | u8 *src; |
2637 | size_t len; | |
2638 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; | |
2639 | ||
2640 | /* Ask kernel firmware_class module to get the boot firmware off disk. | |
2641 | * request_firmware() is synchronous, file is in memory on return. */ | |
90e759d1 TW |
2642 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
2643 | if (ret < 0) { | |
2644 | IWL_ERROR("%s firmware file req failed: Reason %d\n", | |
2645 | name, ret); | |
b481de9c ZY |
2646 | goto error; |
2647 | } | |
2648 | ||
2649 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", | |
2650 | name, ucode_raw->size); | |
2651 | ||
2652 | /* Make sure that we got at least our header! */ | |
2653 | if (ucode_raw->size < sizeof(*ucode)) { | |
2654 | IWL_ERROR("File size way too small!\n"); | |
90e759d1 | 2655 | ret = -EINVAL; |
b481de9c ZY |
2656 | goto err_release; |
2657 | } | |
2658 | ||
2659 | /* Data from ucode file: header followed by uCode images */ | |
2660 | ucode = (void *)ucode_raw->data; | |
2661 | ||
2662 | ver = le32_to_cpu(ucode->ver); | |
2663 | inst_size = le32_to_cpu(ucode->inst_size); | |
2664 | data_size = le32_to_cpu(ucode->data_size); | |
2665 | init_size = le32_to_cpu(ucode->init_size); | |
2666 | init_data_size = le32_to_cpu(ucode->init_data_size); | |
2667 | boot_size = le32_to_cpu(ucode->boot_size); | |
2668 | ||
2669 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); | |
2670 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", | |
2671 | inst_size); | |
2672 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", | |
2673 | data_size); | |
2674 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", | |
2675 | init_size); | |
2676 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", | |
2677 | init_data_size); | |
2678 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", | |
2679 | boot_size); | |
2680 | ||
2681 | /* Verify size of file vs. image size info in file's header */ | |
2682 | if (ucode_raw->size < sizeof(*ucode) + | |
2683 | inst_size + data_size + init_size + | |
2684 | init_data_size + boot_size) { | |
2685 | ||
2686 | IWL_DEBUG_INFO("uCode file size %d too small\n", | |
2687 | (int)ucode_raw->size); | |
90e759d1 | 2688 | ret = -EINVAL; |
b481de9c ZY |
2689 | goto err_release; |
2690 | } | |
2691 | ||
2692 | /* Verify that uCode images will fit in card's SRAM */ | |
099b40b7 | 2693 | if (inst_size > priv->hw_params.max_inst_size) { |
90e759d1 TW |
2694 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
2695 | inst_size); | |
2696 | ret = -EINVAL; | |
b481de9c ZY |
2697 | goto err_release; |
2698 | } | |
2699 | ||
099b40b7 | 2700 | if (data_size > priv->hw_params.max_data_size) { |
90e759d1 TW |
2701 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
2702 | data_size); | |
2703 | ret = -EINVAL; | |
b481de9c ZY |
2704 | goto err_release; |
2705 | } | |
099b40b7 | 2706 | if (init_size > priv->hw_params.max_inst_size) { |
b481de9c | 2707 | IWL_DEBUG_INFO |
90e759d1 TW |
2708 | ("uCode init instr len %d too large to fit in\n", |
2709 | init_size); | |
2710 | ret = -EINVAL; | |
b481de9c ZY |
2711 | goto err_release; |
2712 | } | |
099b40b7 | 2713 | if (init_data_size > priv->hw_params.max_data_size) { |
b481de9c | 2714 | IWL_DEBUG_INFO |
90e759d1 TW |
2715 | ("uCode init data len %d too large to fit in\n", |
2716 | init_data_size); | |
2717 | ret = -EINVAL; | |
b481de9c ZY |
2718 | goto err_release; |
2719 | } | |
099b40b7 | 2720 | if (boot_size > priv->hw_params.max_bsm_size) { |
b481de9c | 2721 | IWL_DEBUG_INFO |
90e759d1 TW |
2722 | ("uCode boot instr len %d too large to fit in\n", |
2723 | boot_size); | |
2724 | ret = -EINVAL; | |
b481de9c ZY |
2725 | goto err_release; |
2726 | } | |
2727 | ||
2728 | /* Allocate ucode buffers for card's bus-master loading ... */ | |
2729 | ||
2730 | /* Runtime instructions and 2 copies of data: | |
2731 | * 1) unmodified from disk | |
2732 | * 2) backup cache for save/restore during power-downs */ | |
2733 | priv->ucode_code.len = inst_size; | |
98c92211 | 2734 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
b481de9c ZY |
2735 | |
2736 | priv->ucode_data.len = data_size; | |
98c92211 | 2737 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
b481de9c ZY |
2738 | |
2739 | priv->ucode_data_backup.len = data_size; | |
98c92211 | 2740 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
b481de9c ZY |
2741 | |
2742 | /* Initialization instructions and data */ | |
90e759d1 TW |
2743 | if (init_size && init_data_size) { |
2744 | priv->ucode_init.len = init_size; | |
98c92211 | 2745 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
90e759d1 TW |
2746 | |
2747 | priv->ucode_init_data.len = init_data_size; | |
98c92211 | 2748 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
90e759d1 TW |
2749 | |
2750 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) | |
2751 | goto err_pci_alloc; | |
2752 | } | |
b481de9c ZY |
2753 | |
2754 | /* Bootstrap (instructions only, no data) */ | |
90e759d1 TW |
2755 | if (boot_size) { |
2756 | priv->ucode_boot.len = boot_size; | |
98c92211 | 2757 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
b481de9c | 2758 | |
90e759d1 TW |
2759 | if (!priv->ucode_boot.v_addr) |
2760 | goto err_pci_alloc; | |
2761 | } | |
b481de9c ZY |
2762 | |
2763 | /* Copy images into buffers for card's bus-master reads ... */ | |
2764 | ||
2765 | /* Runtime instructions (first block of data in file) */ | |
2766 | src = &ucode->data[0]; | |
2767 | len = priv->ucode_code.len; | |
90e759d1 | 2768 | IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len); |
b481de9c ZY |
2769 | memcpy(priv->ucode_code.v_addr, src, len); |
2770 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", | |
2771 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); | |
2772 | ||
2773 | /* Runtime data (2nd block) | |
bb8c093b | 2774 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
b481de9c ZY |
2775 | src = &ucode->data[inst_size]; |
2776 | len = priv->ucode_data.len; | |
90e759d1 | 2777 | IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len); |
b481de9c ZY |
2778 | memcpy(priv->ucode_data.v_addr, src, len); |
2779 | memcpy(priv->ucode_data_backup.v_addr, src, len); | |
2780 | ||
2781 | /* Initialization instructions (3rd block) */ | |
2782 | if (init_size) { | |
2783 | src = &ucode->data[inst_size + data_size]; | |
2784 | len = priv->ucode_init.len; | |
90e759d1 TW |
2785 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
2786 | len); | |
b481de9c ZY |
2787 | memcpy(priv->ucode_init.v_addr, src, len); |
2788 | } | |
2789 | ||
2790 | /* Initialization data (4th block) */ | |
2791 | if (init_data_size) { | |
2792 | src = &ucode->data[inst_size + data_size + init_size]; | |
2793 | len = priv->ucode_init_data.len; | |
90e759d1 TW |
2794 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
2795 | len); | |
b481de9c ZY |
2796 | memcpy(priv->ucode_init_data.v_addr, src, len); |
2797 | } | |
2798 | ||
2799 | /* Bootstrap instructions (5th block) */ | |
2800 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; | |
2801 | len = priv->ucode_boot.len; | |
90e759d1 | 2802 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len); |
b481de9c ZY |
2803 | memcpy(priv->ucode_boot.v_addr, src, len); |
2804 | ||
2805 | /* We have our copies now, allow OS release its copies */ | |
2806 | release_firmware(ucode_raw); | |
2807 | return 0; | |
2808 | ||
2809 | err_pci_alloc: | |
2810 | IWL_ERROR("failed to allocate pci memory\n"); | |
90e759d1 | 2811 | ret = -ENOMEM; |
bb8c093b | 2812 | iwl4965_dealloc_ucode_pci(priv); |
b481de9c ZY |
2813 | |
2814 | err_release: | |
2815 | release_firmware(ucode_raw); | |
2816 | ||
2817 | error: | |
90e759d1 | 2818 | return ret; |
b481de9c ZY |
2819 | } |
2820 | ||
b481de9c | 2821 | /** |
4a4a9e81 | 2822 | * iwl_alive_start - called after REPLY_ALIVE notification received |
b481de9c | 2823 | * from protocol/runtime uCode (initialization uCode's |
4a4a9e81 | 2824 | * Alive gets handled by iwl_init_alive_start()). |
b481de9c | 2825 | */ |
4a4a9e81 | 2826 | static void iwl_alive_start(struct iwl_priv *priv) |
b481de9c | 2827 | { |
57aab75a | 2828 | int ret = 0; |
b481de9c ZY |
2829 | |
2830 | IWL_DEBUG_INFO("Runtime Alive received.\n"); | |
2831 | ||
2832 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { | |
2833 | /* We had an error bringing up the hardware, so take it | |
2834 | * all the way back down so we can try again */ | |
2835 | IWL_DEBUG_INFO("Alive failed.\n"); | |
2836 | goto restart; | |
2837 | } | |
2838 | ||
2839 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. | |
2840 | * This is a paranoid check, because we would not have gotten the | |
2841 | * "runtime" alive if code weren't properly loaded. */ | |
b0692f2f | 2842 | if (iwl_verify_ucode(priv)) { |
b481de9c ZY |
2843 | /* Runtime instruction load was bad; |
2844 | * take it all the way back down so we can try again */ | |
2845 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); | |
2846 | goto restart; | |
2847 | } | |
2848 | ||
bf85ea4f | 2849 | iwlcore_clear_stations_table(priv); |
57aab75a TW |
2850 | ret = priv->cfg->ops->lib->alive_notify(priv); |
2851 | if (ret) { | |
b481de9c | 2852 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
57aab75a | 2853 | ret); |
b481de9c ZY |
2854 | goto restart; |
2855 | } | |
2856 | ||
9fbab516 | 2857 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
b481de9c ZY |
2858 | set_bit(STATUS_ALIVE, &priv->status); |
2859 | ||
2860 | /* Clear out the uCode error bit if it is set */ | |
2861 | clear_bit(STATUS_FW_ERROR, &priv->status); | |
2862 | ||
fee1247a | 2863 | if (iwl_is_rfkill(priv)) |
b481de9c ZY |
2864 | return; |
2865 | ||
36d6825b | 2866 | ieee80211_wake_queues(priv->hw); |
b481de9c ZY |
2867 | |
2868 | priv->active_rate = priv->rates_mask; | |
2869 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; | |
2870 | ||
3109ece1 | 2871 | if (iwl_is_associated(priv)) { |
c1adf9fb GG |
2872 | struct iwl_rxon_cmd *active_rxon = |
2873 | (struct iwl_rxon_cmd *)&priv->active_rxon; | |
b481de9c ZY |
2874 | |
2875 | memcpy(&priv->staging_rxon, &priv->active_rxon, | |
2876 | sizeof(priv->staging_rxon)); | |
2877 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
2878 | } else { | |
2879 | /* Initialize our rx_config data */ | |
bb8c093b | 2880 | iwl4965_connection_init_rx_config(priv); |
b481de9c ZY |
2881 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
2882 | } | |
2883 | ||
9fbab516 | 2884 | /* Configure Bluetooth device coexistence support */ |
bb8c093b | 2885 | iwl4965_send_bt_config(priv); |
b481de9c | 2886 | |
4a4a9e81 TW |
2887 | iwl_reset_run_time_calib(priv); |
2888 | ||
b481de9c | 2889 | /* Configure the adapter for unassociated operation */ |
bb8c093b | 2890 | iwl4965_commit_rxon(priv); |
b481de9c ZY |
2891 | |
2892 | /* At this point, the NIC is initialized and operational */ | |
b481de9c | 2893 | iwl4965_rf_kill_ct_config(priv); |
5a66926a | 2894 | |
fe00b5a5 RC |
2895 | iwl_leds_register(priv); |
2896 | ||
b481de9c | 2897 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
a9f46786 | 2898 | set_bit(STATUS_READY, &priv->status); |
5a66926a | 2899 | wake_up_interruptible(&priv->wait_command_queue); |
b481de9c ZY |
2900 | |
2901 | if (priv->error_recovering) | |
bb8c093b | 2902 | iwl4965_error_recovery(priv); |
b481de9c | 2903 | |
c8381fdc | 2904 | iwlcore_low_level_notify(priv, IWLCORE_START_EVT); |
84363e6e | 2905 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
b481de9c ZY |
2906 | return; |
2907 | ||
2908 | restart: | |
2909 | queue_work(priv->workqueue, &priv->restart); | |
2910 | } | |
2911 | ||
4e39317d | 2912 | static void iwl_cancel_deferred_work(struct iwl_priv *priv); |
b481de9c | 2913 | |
c79dd5b5 | 2914 | static void __iwl4965_down(struct iwl_priv *priv) |
b481de9c ZY |
2915 | { |
2916 | unsigned long flags; | |
2917 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); | |
b481de9c ZY |
2918 | |
2919 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); | |
2920 | ||
b481de9c ZY |
2921 | if (!exit_pending) |
2922 | set_bit(STATUS_EXIT_PENDING, &priv->status); | |
2923 | ||
ab53d8af MA |
2924 | iwl_leds_unregister(priv); |
2925 | ||
c8381fdc MA |
2926 | iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT); |
2927 | ||
bf85ea4f | 2928 | iwlcore_clear_stations_table(priv); |
b481de9c ZY |
2929 | |
2930 | /* Unblock any waiting calls */ | |
2931 | wake_up_interruptible_all(&priv->wait_command_queue); | |
2932 | ||
b481de9c ZY |
2933 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
2934 | * exiting the module */ | |
2935 | if (!exit_pending) | |
2936 | clear_bit(STATUS_EXIT_PENDING, &priv->status); | |
2937 | ||
2938 | /* stop and reset the on-board processor */ | |
3395f6e9 | 2939 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
b481de9c ZY |
2940 | |
2941 | /* tell the device to stop sending interrupts */ | |
0359facc | 2942 | spin_lock_irqsave(&priv->lock, flags); |
bb8c093b | 2943 | iwl4965_disable_interrupts(priv); |
0359facc MA |
2944 | spin_unlock_irqrestore(&priv->lock, flags); |
2945 | iwl_synchronize_irq(priv); | |
b481de9c ZY |
2946 | |
2947 | if (priv->mac80211_registered) | |
2948 | ieee80211_stop_queues(priv->hw); | |
2949 | ||
bb8c093b | 2950 | /* If we have not previously called iwl4965_init() then |
b481de9c | 2951 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
fee1247a | 2952 | if (!iwl_is_init(priv)) { |
b481de9c ZY |
2953 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
2954 | STATUS_RF_KILL_HW | | |
2955 | test_bit(STATUS_RF_KILL_SW, &priv->status) << | |
2956 | STATUS_RF_KILL_SW | | |
9788864e RC |
2957 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
2958 | STATUS_GEO_CONFIGURED | | |
b481de9c ZY |
2959 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
2960 | STATUS_IN_SUSPEND; | |
2961 | goto exit; | |
2962 | } | |
2963 | ||
2964 | /* ...otherwise clear out all the status bits but the RF Kill and | |
2965 | * SUSPEND bits and continue taking the NIC down. */ | |
2966 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << | |
2967 | STATUS_RF_KILL_HW | | |
2968 | test_bit(STATUS_RF_KILL_SW, &priv->status) << | |
2969 | STATUS_RF_KILL_SW | | |
9788864e RC |
2970 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
2971 | STATUS_GEO_CONFIGURED | | |
b481de9c ZY |
2972 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
2973 | STATUS_IN_SUSPEND | | |
2974 | test_bit(STATUS_FW_ERROR, &priv->status) << | |
2975 | STATUS_FW_ERROR; | |
2976 | ||
2977 | spin_lock_irqsave(&priv->lock, flags); | |
3395f6e9 | 2978 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
9fbab516 | 2979 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
b481de9c ZY |
2980 | spin_unlock_irqrestore(&priv->lock, flags); |
2981 | ||
da1bc453 | 2982 | iwl_txq_ctx_stop(priv); |
b3bbacb7 | 2983 | iwl_rxq_stop(priv); |
b481de9c ZY |
2984 | |
2985 | spin_lock_irqsave(&priv->lock, flags); | |
3395f6e9 TW |
2986 | if (!iwl_grab_nic_access(priv)) { |
2987 | iwl_write_prph(priv, APMG_CLK_DIS_REG, | |
b481de9c | 2988 | APMG_CLK_VAL_DMA_CLK_RQT); |
3395f6e9 | 2989 | iwl_release_nic_access(priv); |
b481de9c ZY |
2990 | } |
2991 | spin_unlock_irqrestore(&priv->lock, flags); | |
2992 | ||
2993 | udelay(5); | |
2994 | ||
7f066108 TW |
2995 | /* FIXME: apm_ops.suspend(priv) */ |
2996 | priv->cfg->ops->lib->apm_ops.reset(priv); | |
399f4900 | 2997 | priv->cfg->ops->lib->free_shared_mem(priv); |
b481de9c ZY |
2998 | |
2999 | exit: | |
885ba202 | 3000 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
b481de9c ZY |
3001 | |
3002 | if (priv->ibss_beacon) | |
3003 | dev_kfree_skb(priv->ibss_beacon); | |
3004 | priv->ibss_beacon = NULL; | |
3005 | ||
3006 | /* clear out any free frames */ | |
fcab423d | 3007 | iwl_clear_free_frames(priv); |
b481de9c ZY |
3008 | } |
3009 | ||
c79dd5b5 | 3010 | static void iwl4965_down(struct iwl_priv *priv) |
b481de9c ZY |
3011 | { |
3012 | mutex_lock(&priv->mutex); | |
bb8c093b | 3013 | __iwl4965_down(priv); |
b481de9c | 3014 | mutex_unlock(&priv->mutex); |
b24d22b1 | 3015 | |
4e39317d | 3016 | iwl_cancel_deferred_work(priv); |
b481de9c ZY |
3017 | } |
3018 | ||
3019 | #define MAX_HW_RESTARTS 5 | |
3020 | ||
c79dd5b5 | 3021 | static int __iwl4965_up(struct iwl_priv *priv) |
b481de9c | 3022 | { |
57aab75a TW |
3023 | int i; |
3024 | int ret; | |
b481de9c ZY |
3025 | |
3026 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { | |
3027 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); | |
3028 | return -EIO; | |
3029 | } | |
3030 | ||
e903fbd4 RC |
3031 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
3032 | IWL_ERROR("ucode not available for device bringup\n"); | |
3033 | return -EIO; | |
3034 | } | |
3035 | ||
e655b9f0 | 3036 | /* If platform's RF_KILL switch is NOT set to KILL */ |
3395f6e9 | 3037 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
e655b9f0 ZY |
3038 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
3039 | clear_bit(STATUS_RF_KILL_HW, &priv->status); | |
3040 | else { | |
3041 | set_bit(STATUS_RF_KILL_HW, &priv->status); | |
3042 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { | |
ad97edd2 | 3043 | iwl_rfkill_set_hw_state(priv); |
e655b9f0 ZY |
3044 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
3045 | return -ENODEV; | |
3046 | } | |
b481de9c ZY |
3047 | } |
3048 | ||
ad97edd2 | 3049 | iwl_rfkill_set_hw_state(priv); |
3395f6e9 | 3050 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
b481de9c | 3051 | |
399f4900 RR |
3052 | ret = priv->cfg->ops->lib->alloc_shared_mem(priv); |
3053 | if (ret) { | |
3054 | IWL_ERROR("Unable to allocate shared memory\n"); | |
3055 | return ret; | |
3056 | } | |
3057 | ||
1053d35f | 3058 | ret = iwl_hw_nic_init(priv); |
57aab75a TW |
3059 | if (ret) { |
3060 | IWL_ERROR("Unable to init nic\n"); | |
3061 | return ret; | |
b481de9c ZY |
3062 | } |
3063 | ||
3064 | /* make sure rfkill handshake bits are cleared */ | |
3395f6e9 TW |
3065 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
3066 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, | |
b481de9c ZY |
3067 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
3068 | ||
3069 | /* clear (again), then enable host interrupts */ | |
3395f6e9 | 3070 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
bb8c093b | 3071 | iwl4965_enable_interrupts(priv); |
b481de9c ZY |
3072 | |
3073 | /* really make sure rfkill handshake bits are cleared */ | |
3395f6e9 TW |
3074 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
3075 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); | |
b481de9c ZY |
3076 | |
3077 | /* Copy original ucode data image from disk into backup cache. | |
3078 | * This will be used to initialize the on-board processor's | |
3079 | * data SRAM for a clean start when the runtime program first loads. */ | |
3080 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, | |
5a66926a | 3081 | priv->ucode_data.len); |
b481de9c | 3082 | |
e655b9f0 | 3083 | /* We return success when we resume from suspend and rf_kill is on. */ |
64e72c3e MA |
3084 | if (test_bit(STATUS_RF_KILL_HW, &priv->status) || |
3085 | test_bit(STATUS_RF_KILL_SW, &priv->status)) | |
b481de9c | 3086 | return 0; |
b481de9c ZY |
3087 | |
3088 | for (i = 0; i < MAX_HW_RESTARTS; i++) { | |
3089 | ||
bf85ea4f | 3090 | iwlcore_clear_stations_table(priv); |
b481de9c ZY |
3091 | |
3092 | /* load bootstrap state machine, | |
3093 | * load bootstrap program into processor's memory, | |
3094 | * prepare to load the "initialize" uCode */ | |
57aab75a | 3095 | ret = priv->cfg->ops->lib->load_ucode(priv); |
b481de9c | 3096 | |
57aab75a TW |
3097 | if (ret) { |
3098 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); | |
b481de9c ZY |
3099 | continue; |
3100 | } | |
3101 | ||
3102 | /* start card; "initialize" will load runtime ucode */ | |
edcdf8b2 | 3103 | iwl4965_nic_start(priv); |
b481de9c | 3104 | |
b481de9c ZY |
3105 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
3106 | ||
3107 | return 0; | |
3108 | } | |
3109 | ||
3110 | set_bit(STATUS_EXIT_PENDING, &priv->status); | |
bb8c093b | 3111 | __iwl4965_down(priv); |
64e72c3e | 3112 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
b481de9c ZY |
3113 | |
3114 | /* tried to restart and config the device for as long as our | |
3115 | * patience could withstand */ | |
3116 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); | |
3117 | return -EIO; | |
3118 | } | |
3119 | ||
3120 | ||
3121 | /***************************************************************************** | |
3122 | * | |
3123 | * Workqueue callbacks | |
3124 | * | |
3125 | *****************************************************************************/ | |
3126 | ||
4a4a9e81 | 3127 | static void iwl_bg_init_alive_start(struct work_struct *data) |
b481de9c | 3128 | { |
c79dd5b5 TW |
3129 | struct iwl_priv *priv = |
3130 | container_of(data, struct iwl_priv, init_alive_start.work); | |
b481de9c ZY |
3131 | |
3132 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3133 | return; | |
3134 | ||
3135 | mutex_lock(&priv->mutex); | |
f3ccc08c | 3136 | priv->cfg->ops->lib->init_alive_start(priv); |
b481de9c ZY |
3137 | mutex_unlock(&priv->mutex); |
3138 | } | |
3139 | ||
4a4a9e81 | 3140 | static void iwl_bg_alive_start(struct work_struct *data) |
b481de9c | 3141 | { |
c79dd5b5 TW |
3142 | struct iwl_priv *priv = |
3143 | container_of(data, struct iwl_priv, alive_start.work); | |
b481de9c ZY |
3144 | |
3145 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3146 | return; | |
3147 | ||
3148 | mutex_lock(&priv->mutex); | |
4a4a9e81 | 3149 | iwl_alive_start(priv); |
b481de9c ZY |
3150 | mutex_unlock(&priv->mutex); |
3151 | } | |
3152 | ||
bb8c093b | 3153 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
b481de9c | 3154 | { |
c79dd5b5 | 3155 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
b481de9c ZY |
3156 | |
3157 | wake_up_interruptible(&priv->wait_command_queue); | |
3158 | ||
3159 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3160 | return; | |
3161 | ||
3162 | mutex_lock(&priv->mutex); | |
3163 | ||
fee1247a | 3164 | if (!iwl_is_rfkill(priv)) { |
f3d67999 | 3165 | IWL_DEBUG(IWL_DL_RF_KILL, |
b481de9c ZY |
3166 | "HW and/or SW RF Kill no longer active, restarting " |
3167 | "device\n"); | |
3168 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3169 | queue_work(priv->workqueue, &priv->restart); | |
3170 | } else { | |
ad97edd2 MA |
3171 | /* make sure mac80211 stop sending Tx frame */ |
3172 | if (priv->mac80211_registered) | |
3173 | ieee80211_stop_queues(priv->hw); | |
b481de9c ZY |
3174 | |
3175 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) | |
3176 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " | |
3177 | "disabled by SW switch\n"); | |
3178 | else | |
3179 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" | |
3180 | "Kill switch must be turned off for " | |
3181 | "wireless networking to work.\n"); | |
3182 | } | |
ad97edd2 MA |
3183 | iwl_rfkill_set_hw_state(priv); |
3184 | ||
b481de9c ZY |
3185 | mutex_unlock(&priv->mutex); |
3186 | } | |
3187 | ||
4419e39b AK |
3188 | static void iwl4965_bg_set_monitor(struct work_struct *work) |
3189 | { | |
3190 | struct iwl_priv *priv = container_of(work, | |
3191 | struct iwl_priv, set_monitor); | |
3192 | ||
3193 | IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n"); | |
3194 | ||
3195 | mutex_lock(&priv->mutex); | |
3196 | ||
3197 | if (!iwl_is_ready(priv)) | |
3198 | IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n"); | |
3199 | else | |
3200 | if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0) | |
3201 | IWL_ERROR("iwl4965_set_mode() failed\n"); | |
3202 | ||
3203 | mutex_unlock(&priv->mutex); | |
3204 | } | |
3205 | ||
b481de9c ZY |
3206 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
3207 | ||
bb8c093b | 3208 | static void iwl4965_bg_scan_check(struct work_struct *data) |
b481de9c | 3209 | { |
c79dd5b5 TW |
3210 | struct iwl_priv *priv = |
3211 | container_of(data, struct iwl_priv, scan_check.work); | |
b481de9c ZY |
3212 | |
3213 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3214 | return; | |
3215 | ||
3216 | mutex_lock(&priv->mutex); | |
3217 | if (test_bit(STATUS_SCANNING, &priv->status) || | |
3218 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { | |
f3d67999 EK |
3219 | IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting " |
3220 | "adapter (%dms)\n", | |
3221 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); | |
052c4b9f | 3222 | |
b481de9c | 3223 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
bb8c093b | 3224 | iwl4965_send_scan_abort(priv); |
b481de9c ZY |
3225 | } |
3226 | mutex_unlock(&priv->mutex); | |
3227 | } | |
3228 | ||
bb8c093b | 3229 | static void iwl4965_bg_request_scan(struct work_struct *data) |
b481de9c | 3230 | { |
c79dd5b5 TW |
3231 | struct iwl_priv *priv = |
3232 | container_of(data, struct iwl_priv, request_scan); | |
857485c0 | 3233 | struct iwl_host_cmd cmd = { |
b481de9c | 3234 | .id = REPLY_SCAN_CMD, |
bb8c093b | 3235 | .len = sizeof(struct iwl4965_scan_cmd), |
b481de9c ZY |
3236 | .meta.flags = CMD_SIZE_HUGE, |
3237 | }; | |
bb8c093b | 3238 | struct iwl4965_scan_cmd *scan; |
b481de9c | 3239 | struct ieee80211_conf *conf = NULL; |
78330fdd | 3240 | u16 cmd_len; |
8318d78a | 3241 | enum ieee80211_band band; |
78330fdd | 3242 | u8 direct_mask; |
857485c0 | 3243 | int ret = 0; |
b481de9c ZY |
3244 | |
3245 | conf = ieee80211_get_hw_conf(priv->hw); | |
3246 | ||
3247 | mutex_lock(&priv->mutex); | |
3248 | ||
fee1247a | 3249 | if (!iwl_is_ready(priv)) { |
b481de9c ZY |
3250 | IWL_WARNING("request scan called when driver not ready.\n"); |
3251 | goto done; | |
3252 | } | |
3253 | ||
3254 | /* Make sure the scan wasn't cancelled before this queued work | |
3255 | * was given the chance to run... */ | |
3256 | if (!test_bit(STATUS_SCANNING, &priv->status)) | |
3257 | goto done; | |
3258 | ||
3259 | /* This should never be called or scheduled if there is currently | |
3260 | * a scan active in the hardware. */ | |
3261 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { | |
3262 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " | |
3263 | "Ignoring second request.\n"); | |
857485c0 | 3264 | ret = -EIO; |
b481de9c ZY |
3265 | goto done; |
3266 | } | |
3267 | ||
3268 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { | |
3269 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); | |
3270 | goto done; | |
3271 | } | |
3272 | ||
3273 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { | |
3274 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); | |
3275 | goto done; | |
3276 | } | |
3277 | ||
fee1247a | 3278 | if (iwl_is_rfkill(priv)) { |
b481de9c ZY |
3279 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
3280 | goto done; | |
3281 | } | |
3282 | ||
3283 | if (!test_bit(STATUS_READY, &priv->status)) { | |
3284 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); | |
3285 | goto done; | |
3286 | } | |
3287 | ||
3288 | if (!priv->scan_bands) { | |
3289 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); | |
3290 | goto done; | |
3291 | } | |
3292 | ||
3293 | if (!priv->scan) { | |
bb8c093b | 3294 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
b481de9c ZY |
3295 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
3296 | if (!priv->scan) { | |
857485c0 | 3297 | ret = -ENOMEM; |
b481de9c ZY |
3298 | goto done; |
3299 | } | |
3300 | } | |
3301 | scan = priv->scan; | |
bb8c093b | 3302 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
b481de9c ZY |
3303 | |
3304 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; | |
3305 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; | |
3306 | ||
3109ece1 | 3307 | if (iwl_is_associated(priv)) { |
b481de9c ZY |
3308 | u16 interval = 0; |
3309 | u32 extra; | |
3310 | u32 suspend_time = 100; | |
3311 | u32 scan_suspend_time = 100; | |
3312 | unsigned long flags; | |
3313 | ||
3314 | IWL_DEBUG_INFO("Scanning while associated...\n"); | |
3315 | ||
3316 | spin_lock_irqsave(&priv->lock, flags); | |
3317 | interval = priv->beacon_int; | |
3318 | spin_unlock_irqrestore(&priv->lock, flags); | |
3319 | ||
3320 | scan->suspend_time = 0; | |
052c4b9f | 3321 | scan->max_out_time = cpu_to_le32(200 * 1024); |
b481de9c ZY |
3322 | if (!interval) |
3323 | interval = suspend_time; | |
3324 | ||
3325 | extra = (suspend_time / interval) << 22; | |
3326 | scan_suspend_time = (extra | | |
3327 | ((suspend_time % interval) * 1024)); | |
3328 | scan->suspend_time = cpu_to_le32(scan_suspend_time); | |
3329 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", | |
3330 | scan_suspend_time, interval); | |
3331 | } | |
3332 | ||
3333 | /* We should add the ability for user to lock to PASSIVE ONLY */ | |
3334 | if (priv->one_direct_scan) { | |
3335 | IWL_DEBUG_SCAN | |
3336 | ("Kicking off one direct scan for '%s'\n", | |
bb8c093b | 3337 | iwl4965_escape_essid(priv->direct_ssid, |
b481de9c ZY |
3338 | priv->direct_ssid_len)); |
3339 | scan->direct_scan[0].id = WLAN_EID_SSID; | |
3340 | scan->direct_scan[0].len = priv->direct_ssid_len; | |
3341 | memcpy(scan->direct_scan[0].ssid, | |
3342 | priv->direct_ssid, priv->direct_ssid_len); | |
3343 | direct_mask = 1; | |
3109ece1 | 3344 | } else if (!iwl_is_associated(priv) && priv->essid_len) { |
786b4557 BM |
3345 | IWL_DEBUG_SCAN |
3346 | ("Kicking off one direct scan for '%s' when not associated\n", | |
3347 | iwl4965_escape_essid(priv->essid, priv->essid_len)); | |
b481de9c ZY |
3348 | scan->direct_scan[0].id = WLAN_EID_SSID; |
3349 | scan->direct_scan[0].len = priv->essid_len; | |
3350 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); | |
3351 | direct_mask = 1; | |
857485c0 | 3352 | } else { |
786b4557 | 3353 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
b481de9c | 3354 | direct_mask = 0; |
857485c0 | 3355 | } |
b481de9c | 3356 | |
b481de9c | 3357 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
5425e490 | 3358 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
b481de9c ZY |
3359 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
3360 | ||
b481de9c ZY |
3361 | |
3362 | switch (priv->scan_bands) { | |
3363 | case 2: | |
3364 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; | |
3365 | scan->tx_cmd.rate_n_flags = | |
bb8c093b | 3366 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
b481de9c ZY |
3367 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
3368 | ||
3369 | scan->good_CRC_th = 0; | |
8318d78a | 3370 | band = IEEE80211_BAND_2GHZ; |
b481de9c ZY |
3371 | break; |
3372 | ||
3373 | case 1: | |
3374 | scan->tx_cmd.rate_n_flags = | |
bb8c093b | 3375 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
b481de9c ZY |
3376 | RATE_MCS_ANT_B_MSK); |
3377 | scan->good_CRC_th = IWL_GOOD_CRC_TH; | |
8318d78a | 3378 | band = IEEE80211_BAND_5GHZ; |
b481de9c ZY |
3379 | break; |
3380 | ||
3381 | default: | |
3382 | IWL_WARNING("Invalid scan band count\n"); | |
3383 | goto done; | |
3384 | } | |
3385 | ||
78330fdd TW |
3386 | /* We don't build a direct scan probe request; the uCode will do |
3387 | * that based on the direct_mask added to each channel entry */ | |
3388 | cmd_len = iwl4965_fill_probe_req(priv, band, | |
3389 | (struct ieee80211_mgmt *)scan->data, | |
3390 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); | |
3391 | ||
3392 | scan->tx_cmd.len = cpu_to_le16(cmd_len); | |
b481de9c ZY |
3393 | /* select Rx chains */ |
3394 | ||
3395 | /* Force use of chains B and C (0x6) for scan Rx. | |
3396 | * Avoid A (0x1) because of its off-channel reception on A-band. | |
3397 | * MIMO is not used here, but value is required to make uCode happy. */ | |
3398 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | | |
3399 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | | |
3400 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | | |
3401 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); | |
3402 | ||
3403 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) | |
3404 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; | |
3405 | ||
786b4557 | 3406 | if (direct_mask) |
26c0f03f RC |
3407 | scan->channel_count = |
3408 | iwl4965_get_channels_for_scan( | |
3409 | priv, band, 1, /* active */ | |
3410 | direct_mask, | |
3411 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); | |
786b4557 | 3412 | else |
26c0f03f RC |
3413 | scan->channel_count = |
3414 | iwl4965_get_channels_for_scan( | |
3415 | priv, band, 0, /* passive */ | |
3416 | direct_mask, | |
3417 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); | |
b481de9c | 3418 | |
5da4b55f MA |
3419 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
3420 | RXON_FILTER_BCON_AWARE_MSK); | |
b481de9c | 3421 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
bb8c093b | 3422 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
b481de9c ZY |
3423 | cmd.data = scan; |
3424 | scan->len = cpu_to_le16(cmd.len); | |
3425 | ||
3426 | set_bit(STATUS_SCAN_HW, &priv->status); | |
857485c0 TW |
3427 | ret = iwl_send_cmd_sync(priv, &cmd); |
3428 | if (ret) | |
b481de9c ZY |
3429 | goto done; |
3430 | ||
3431 | queue_delayed_work(priv->workqueue, &priv->scan_check, | |
3432 | IWL_SCAN_CHECK_WATCHDOG); | |
3433 | ||
3434 | mutex_unlock(&priv->mutex); | |
3435 | return; | |
3436 | ||
3437 | done: | |
01ebd063 | 3438 | /* inform mac80211 scan aborted */ |
b481de9c ZY |
3439 | queue_work(priv->workqueue, &priv->scan_completed); |
3440 | mutex_unlock(&priv->mutex); | |
3441 | } | |
3442 | ||
16e727e8 EG |
3443 | static void iwl_bg_run_time_calib_work(struct work_struct *work) |
3444 | { | |
3445 | struct iwl_priv *priv = container_of(work, struct iwl_priv, | |
3446 | run_time_calib_work); | |
3447 | ||
3448 | mutex_lock(&priv->mutex); | |
3449 | ||
3450 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || | |
3451 | test_bit(STATUS_SCANNING, &priv->status)) { | |
3452 | mutex_unlock(&priv->mutex); | |
3453 | return; | |
3454 | } | |
3455 | ||
3456 | if (priv->start_calib) { | |
3457 | iwl_chain_noise_calibration(priv, &priv->statistics); | |
3458 | ||
3459 | iwl_sensitivity_calibration(priv, &priv->statistics); | |
3460 | } | |
3461 | ||
3462 | mutex_unlock(&priv->mutex); | |
3463 | return; | |
3464 | } | |
3465 | ||
bb8c093b | 3466 | static void iwl4965_bg_up(struct work_struct *data) |
b481de9c | 3467 | { |
c79dd5b5 | 3468 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
b481de9c ZY |
3469 | |
3470 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3471 | return; | |
3472 | ||
3473 | mutex_lock(&priv->mutex); | |
bb8c093b | 3474 | __iwl4965_up(priv); |
b481de9c ZY |
3475 | mutex_unlock(&priv->mutex); |
3476 | } | |
3477 | ||
bb8c093b | 3478 | static void iwl4965_bg_restart(struct work_struct *data) |
b481de9c | 3479 | { |
c79dd5b5 | 3480 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
b481de9c ZY |
3481 | |
3482 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3483 | return; | |
3484 | ||
bb8c093b | 3485 | iwl4965_down(priv); |
b481de9c ZY |
3486 | queue_work(priv->workqueue, &priv->up); |
3487 | } | |
3488 | ||
bb8c093b | 3489 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
b481de9c | 3490 | { |
c79dd5b5 TW |
3491 | struct iwl_priv *priv = |
3492 | container_of(data, struct iwl_priv, rx_replenish); | |
b481de9c ZY |
3493 | |
3494 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3495 | return; | |
3496 | ||
3497 | mutex_lock(&priv->mutex); | |
a55360e4 | 3498 | iwl_rx_replenish(priv); |
b481de9c ZY |
3499 | mutex_unlock(&priv->mutex); |
3500 | } | |
3501 | ||
7878a5a4 MA |
3502 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
3503 | ||
508e32e1 | 3504 | static void iwl4965_post_associate(struct iwl_priv *priv) |
b481de9c | 3505 | { |
b481de9c | 3506 | struct ieee80211_conf *conf = NULL; |
857485c0 | 3507 | int ret = 0; |
0795af57 | 3508 | DECLARE_MAC_BUF(mac); |
b481de9c ZY |
3509 | |
3510 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { | |
3511 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); | |
3512 | return; | |
3513 | } | |
3514 | ||
0795af57 JP |
3515 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
3516 | priv->assoc_id, | |
3517 | print_mac(mac, priv->active_rxon.bssid_addr)); | |
b481de9c ZY |
3518 | |
3519 | ||
3520 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3521 | return; | |
3522 | ||
b481de9c | 3523 | |
508e32e1 | 3524 | if (!priv->vif || !priv->is_open) |
948c171c | 3525 | return; |
508e32e1 | 3526 | |
bb8c093b | 3527 | iwl4965_scan_cancel_timeout(priv, 200); |
052c4b9f | 3528 | |
b481de9c ZY |
3529 | conf = ieee80211_get_hw_conf(priv->hw); |
3530 | ||
3531 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
bb8c093b | 3532 | iwl4965_commit_rxon(priv); |
b481de9c | 3533 | |
bb8c093b CH |
3534 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
3535 | iwl4965_setup_rxon_timing(priv); | |
857485c0 | 3536 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
b481de9c | 3537 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
857485c0 | 3538 | if (ret) |
b481de9c ZY |
3539 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
3540 | "Attempting to continue.\n"); | |
3541 | ||
3542 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; | |
3543 | ||
fd105e79 | 3544 | if (priv->current_ht_config.is_ht) |
47c5196e | 3545 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
4f85f5b3 | 3546 | |
c7de35cd | 3547 | iwl_set_rxon_chain(priv); |
b481de9c ZY |
3548 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
3549 | ||
3550 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", | |
3551 | priv->assoc_id, priv->beacon_int); | |
3552 | ||
3553 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) | |
3554 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; | |
3555 | else | |
3556 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; | |
3557 | ||
3558 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { | |
3559 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) | |
3560 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; | |
3561 | else | |
3562 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; | |
3563 | ||
3564 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) | |
3565 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; | |
3566 | ||
3567 | } | |
3568 | ||
bb8c093b | 3569 | iwl4965_commit_rxon(priv); |
b481de9c ZY |
3570 | |
3571 | switch (priv->iw_mode) { | |
3572 | case IEEE80211_IF_TYPE_STA: | |
bb8c093b | 3573 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
b481de9c ZY |
3574 | break; |
3575 | ||
3576 | case IEEE80211_IF_TYPE_IBSS: | |
3577 | ||
3578 | /* clear out the station table */ | |
bf85ea4f | 3579 | iwlcore_clear_stations_table(priv); |
b481de9c | 3580 | |
4f40e4d9 TW |
3581 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
3582 | iwl_rxon_add_station(priv, priv->bssid, 0); | |
bb8c093b CH |
3583 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
3584 | iwl4965_send_beacon_cmd(priv); | |
b481de9c ZY |
3585 | |
3586 | break; | |
3587 | ||
3588 | default: | |
3589 | IWL_ERROR("%s Should not be called in %d mode\n", | |
3590 | __FUNCTION__, priv->iw_mode); | |
3591 | break; | |
3592 | } | |
3593 | ||
bb8c093b | 3594 | iwl4965_sequence_reset(priv); |
b481de9c | 3595 | |
b481de9c | 3596 | /* Enable Rx differential gain and sensitivity calibrations */ |
f0832f13 | 3597 | iwl_chain_noise_reset(priv); |
b481de9c | 3598 | priv->start_calib = 1; |
b481de9c ZY |
3599 | |
3600 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) | |
3601 | priv->assoc_station_added = 1; | |
3602 | ||
bb8c093b | 3603 | iwl4965_activate_qos(priv, 0); |
292ae174 | 3604 | |
5da4b55f | 3605 | iwl_power_update_mode(priv, 0); |
7878a5a4 MA |
3606 | /* we have just associated, don't start scan too early */ |
3607 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; | |
508e32e1 RC |
3608 | } |
3609 | ||
3610 | ||
3611 | static void iwl4965_bg_post_associate(struct work_struct *data) | |
3612 | { | |
3613 | struct iwl_priv *priv = container_of(data, struct iwl_priv, | |
3614 | post_associate.work); | |
3615 | ||
3616 | mutex_lock(&priv->mutex); | |
3617 | iwl4965_post_associate(priv); | |
b481de9c | 3618 | mutex_unlock(&priv->mutex); |
508e32e1 | 3619 | |
b481de9c ZY |
3620 | } |
3621 | ||
bb8c093b | 3622 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
b481de9c | 3623 | { |
c79dd5b5 | 3624 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
b481de9c | 3625 | |
fee1247a | 3626 | if (!iwl_is_ready(priv)) |
b481de9c ZY |
3627 | return; |
3628 | ||
3629 | mutex_lock(&priv->mutex); | |
3630 | ||
3631 | set_bit(STATUS_SCAN_ABORTING, &priv->status); | |
bb8c093b | 3632 | iwl4965_send_scan_abort(priv); |
b481de9c ZY |
3633 | |
3634 | mutex_unlock(&priv->mutex); | |
3635 | } | |
3636 | ||
76bb77e0 ZY |
3637 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
3638 | ||
bb8c093b | 3639 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
b481de9c | 3640 | { |
c79dd5b5 TW |
3641 | struct iwl_priv *priv = |
3642 | container_of(work, struct iwl_priv, scan_completed); | |
b481de9c | 3643 | |
f3d67999 | 3644 | IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n"); |
b481de9c ZY |
3645 | |
3646 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
3647 | return; | |
3648 | ||
a0646470 ZY |
3649 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
3650 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); | |
76bb77e0 | 3651 | |
b481de9c ZY |
3652 | ieee80211_scan_completed(priv->hw); |
3653 | ||
3654 | /* Since setting the TXPOWER may have been deferred while | |
3655 | * performing the scan, fire one off */ | |
3656 | mutex_lock(&priv->mutex); | |
bb8c093b | 3657 | iwl4965_hw_reg_send_txpower(priv); |
b481de9c ZY |
3658 | mutex_unlock(&priv->mutex); |
3659 | } | |
3660 | ||
3661 | /***************************************************************************** | |
3662 | * | |
3663 | * mac80211 entry point functions | |
3664 | * | |
3665 | *****************************************************************************/ | |
3666 | ||
5a66926a ZY |
3667 | #define UCODE_READY_TIMEOUT (2 * HZ) |
3668 | ||
bb8c093b | 3669 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
b481de9c | 3670 | { |
c79dd5b5 | 3671 | struct iwl_priv *priv = hw->priv; |
5a66926a | 3672 | int ret; |
b481de9c ZY |
3673 | |
3674 | IWL_DEBUG_MAC80211("enter\n"); | |
3675 | ||
5a66926a ZY |
3676 | if (pci_enable_device(priv->pci_dev)) { |
3677 | IWL_ERROR("Fail to pci_enable_device\n"); | |
3678 | return -ENODEV; | |
3679 | } | |
3680 | pci_restore_state(priv->pci_dev); | |
3681 | pci_enable_msi(priv->pci_dev); | |
3682 | ||
3683 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, | |
3684 | DRV_NAME, priv); | |
3685 | if (ret) { | |
3686 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); | |
3687 | goto out_disable_msi; | |
3688 | } | |
3689 | ||
b481de9c ZY |
3690 | /* we should be verifying the device is ready to be opened */ |
3691 | mutex_lock(&priv->mutex); | |
3692 | ||
c1adf9fb | 3693 | memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd)); |
5a66926a ZY |
3694 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
3695 | * ucode filename and max sizes are card-specific. */ | |
b481de9c | 3696 | |
5a66926a ZY |
3697 | if (!priv->ucode_code.len) { |
3698 | ret = iwl4965_read_ucode(priv); | |
3699 | if (ret) { | |
3700 | IWL_ERROR("Could not read microcode: %d\n", ret); | |
3701 | mutex_unlock(&priv->mutex); | |
3702 | goto out_release_irq; | |
3703 | } | |
3704 | } | |
b481de9c | 3705 | |
e655b9f0 | 3706 | ret = __iwl4965_up(priv); |
5a66926a | 3707 | |
b481de9c | 3708 | mutex_unlock(&priv->mutex); |
5a66926a | 3709 | |
e655b9f0 ZY |
3710 | if (ret) |
3711 | goto out_release_irq; | |
3712 | ||
3713 | IWL_DEBUG_INFO("Start UP work done.\n"); | |
3714 | ||
3715 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) | |
3716 | return 0; | |
3717 | ||
fe9b6b72 | 3718 | /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from |
5a66926a | 3719 | * mac80211 will not be run successfully. */ |
fe9b6b72 RR |
3720 | if (priv->ucode_type == UCODE_RT) { |
3721 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, | |
3722 | test_bit(STATUS_READY, &priv->status), | |
3723 | UCODE_READY_TIMEOUT); | |
3724 | if (!ret) { | |
3725 | if (!test_bit(STATUS_READY, &priv->status)) { | |
3726 | IWL_ERROR("START_ALIVE timeout after %dms.\n", | |
3727 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); | |
3728 | ret = -ETIMEDOUT; | |
3729 | goto out_release_irq; | |
3730 | } | |
5a66926a | 3731 | } |
5a66926a | 3732 | |
fe9b6b72 RR |
3733 | priv->is_open = 1; |
3734 | } | |
b481de9c ZY |
3735 | IWL_DEBUG_MAC80211("leave\n"); |
3736 | return 0; | |
5a66926a ZY |
3737 | |
3738 | out_release_irq: | |
3739 | free_irq(priv->pci_dev->irq, priv); | |
3740 | out_disable_msi: | |
3741 | pci_disable_msi(priv->pci_dev); | |
e655b9f0 ZY |
3742 | pci_disable_device(priv->pci_dev); |
3743 | priv->is_open = 0; | |
3744 | IWL_DEBUG_MAC80211("leave - failed\n"); | |
5a66926a | 3745 | return ret; |
b481de9c ZY |
3746 | } |
3747 | ||
bb8c093b | 3748 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
b481de9c | 3749 | { |
c79dd5b5 | 3750 | struct iwl_priv *priv = hw->priv; |
b481de9c ZY |
3751 | |
3752 | IWL_DEBUG_MAC80211("enter\n"); | |
948c171c | 3753 | |
e655b9f0 ZY |
3754 | if (!priv->is_open) { |
3755 | IWL_DEBUG_MAC80211("leave - skip\n"); | |
3756 | return; | |
3757 | } | |
3758 | ||
b481de9c | 3759 | priv->is_open = 0; |
5a66926a | 3760 | |
fee1247a | 3761 | if (iwl_is_ready_rf(priv)) { |
e655b9f0 ZY |
3762 | /* stop mac, cancel any scan request and clear |
3763 | * RXON_FILTER_ASSOC_MSK BIT | |
3764 | */ | |
5a66926a ZY |
3765 | mutex_lock(&priv->mutex); |
3766 | iwl4965_scan_cancel_timeout(priv, 100); | |
3767 | cancel_delayed_work(&priv->post_associate); | |
fde3571f | 3768 | mutex_unlock(&priv->mutex); |
fde3571f MA |
3769 | } |
3770 | ||
5a66926a ZY |
3771 | iwl4965_down(priv); |
3772 | ||
3773 | flush_workqueue(priv->workqueue); | |
3774 | free_irq(priv->pci_dev->irq, priv); | |
3775 | pci_disable_msi(priv->pci_dev); | |
3776 | pci_save_state(priv->pci_dev); | |
3777 | pci_disable_device(priv->pci_dev); | |
948c171c | 3778 | |
b481de9c | 3779 | IWL_DEBUG_MAC80211("leave\n"); |
b481de9c ZY |
3780 | } |
3781 | ||
e039fa4a | 3782 | static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
b481de9c | 3783 | { |
c79dd5b5 | 3784 | struct iwl_priv *priv = hw->priv; |
b481de9c ZY |
3785 | |
3786 | IWL_DEBUG_MAC80211("enter\n"); | |
3787 | ||
3788 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { | |
3789 | IWL_DEBUG_MAC80211("leave - monitor\n"); | |
3790 | return -1; | |
3791 | } | |
3792 | ||
3793 | IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, | |
e039fa4a | 3794 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
b481de9c | 3795 | |
e039fa4a | 3796 | if (iwl_tx_skb(priv, skb)) |
b481de9c ZY |
3797 | dev_kfree_skb_any(skb); |
3798 | ||
3799 | IWL_DEBUG_MAC80211("leave\n"); | |
3800 | return 0; | |
3801 | } | |
3802 | ||
bb8c093b | 3803 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
b481de9c ZY |
3804 | struct ieee80211_if_init_conf *conf) |
3805 | { | |
c79dd5b5 | 3806 | struct iwl_priv *priv = hw->priv; |
b481de9c | 3807 | unsigned long flags; |
0795af57 | 3808 | DECLARE_MAC_BUF(mac); |
b481de9c | 3809 | |
32bfd35d | 3810 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
b481de9c | 3811 | |
32bfd35d JB |
3812 | if (priv->vif) { |
3813 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); | |
75849d28 | 3814 | return -EOPNOTSUPP; |
b481de9c ZY |
3815 | } |
3816 | ||
3817 | spin_lock_irqsave(&priv->lock, flags); | |
32bfd35d | 3818 | priv->vif = conf->vif; |
b481de9c ZY |
3819 | |
3820 | spin_unlock_irqrestore(&priv->lock, flags); | |
3821 | ||
3822 | mutex_lock(&priv->mutex); | |
864792e3 TW |
3823 | |
3824 | if (conf->mac_addr) { | |
3825 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); | |
3826 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); | |
3827 | } | |
b481de9c | 3828 | |
fee1247a | 3829 | if (iwl_is_ready(priv)) |
5a66926a ZY |
3830 | iwl4965_set_mode(priv, conf->type); |
3831 | ||
b481de9c ZY |
3832 | mutex_unlock(&priv->mutex); |
3833 | ||
5a66926a | 3834 | IWL_DEBUG_MAC80211("leave\n"); |
b481de9c ZY |
3835 | return 0; |
3836 | } | |
3837 | ||
3838 | /** | |
bb8c093b | 3839 | * iwl4965_mac_config - mac80211 config callback |
b481de9c ZY |
3840 | * |
3841 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to | |
3842 | * be set inappropriately and the driver currently sets the hardware up to | |
3843 | * use it whenever needed. | |
3844 | */ | |
bb8c093b | 3845 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) |
b481de9c | 3846 | { |
c79dd5b5 | 3847 | struct iwl_priv *priv = hw->priv; |
bf85ea4f | 3848 | const struct iwl_channel_info *ch_info; |
b481de9c | 3849 | unsigned long flags; |
76bb77e0 | 3850 | int ret = 0; |
82a66bbb | 3851 | u16 channel; |
b481de9c ZY |
3852 | |
3853 | mutex_lock(&priv->mutex); | |
8318d78a | 3854 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
b481de9c | 3855 | |
12342c47 ZY |
3856 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
3857 | ||
64e72c3e MA |
3858 | |
3859 | if (priv->cfg->ops->lib->radio_kill_sw && | |
3860 | priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled)) { | |
3861 | IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n"); | |
3862 | mutex_unlock(&priv->mutex); | |
3863 | } | |
3864 | ||
fee1247a | 3865 | if (!iwl_is_ready(priv)) { |
b481de9c | 3866 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
76bb77e0 ZY |
3867 | ret = -EIO; |
3868 | goto out; | |
b481de9c ZY |
3869 | } |
3870 | ||
1ea87396 | 3871 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
b481de9c | 3872 | test_bit(STATUS_SCANNING, &priv->status))) { |
a0646470 ZY |
3873 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
3874 | set_bit(STATUS_CONF_PENDING, &priv->status); | |
b481de9c | 3875 | mutex_unlock(&priv->mutex); |
a0646470 | 3876 | return 0; |
b481de9c ZY |
3877 | } |
3878 | ||
82a66bbb TW |
3879 | channel = ieee80211_frequency_to_channel(conf->channel->center_freq); |
3880 | ch_info = iwl_get_channel_info(priv, conf->channel->band, channel); | |
b481de9c | 3881 | if (!is_channel_valid(ch_info)) { |
b481de9c | 3882 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
76bb77e0 ZY |
3883 | ret = -EINVAL; |
3884 | goto out; | |
b481de9c ZY |
3885 | } |
3886 | ||
82a66bbb TW |
3887 | spin_lock_irqsave(&priv->lock, flags); |
3888 | ||
78330fdd | 3889 | /* if we are switching from ht to 2.4 clear flags |
b481de9c ZY |
3890 | * from any ht related info since 2.4 does not |
3891 | * support ht */ | |
82a66bbb | 3892 | if ((le16_to_cpu(priv->staging_rxon.channel) != channel) |
b481de9c ZY |
3893 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
3894 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) | |
3895 | #endif | |
3896 | ) | |
3897 | priv->staging_rxon.flags = 0; | |
b481de9c | 3898 | |
82a66bbb | 3899 | iwl_set_rxon_channel(priv, conf->channel->band, channel); |
b481de9c | 3900 | |
82a66bbb | 3901 | iwl_set_flags_for_band(priv, conf->channel->band); |
b481de9c ZY |
3902 | |
3903 | /* The list of supported rates and rate mask can be different | |
8318d78a | 3904 | * for each band; since the band may have changed, reset |
b481de9c | 3905 | * the rate mask to what mac80211 lists */ |
bb8c093b | 3906 | iwl4965_set_rate(priv); |
b481de9c ZY |
3907 | |
3908 | spin_unlock_irqrestore(&priv->lock, flags); | |
3909 | ||
3910 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH | |
3911 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { | |
bb8c093b | 3912 | iwl4965_hw_channel_switch(priv, conf->channel); |
76bb77e0 | 3913 | goto out; |
b481de9c ZY |
3914 | } |
3915 | #endif | |
3916 | ||
b481de9c ZY |
3917 | if (!conf->radio_enabled) { |
3918 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); | |
76bb77e0 | 3919 | goto out; |
b481de9c ZY |
3920 | } |
3921 | ||
fee1247a | 3922 | if (iwl_is_rfkill(priv)) { |
b481de9c | 3923 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
76bb77e0 ZY |
3924 | ret = -EIO; |
3925 | goto out; | |
b481de9c ZY |
3926 | } |
3927 | ||
bb8c093b | 3928 | iwl4965_set_rate(priv); |
b481de9c ZY |
3929 | |
3930 | if (memcmp(&priv->active_rxon, | |
3931 | &priv->staging_rxon, sizeof(priv->staging_rxon))) | |
bb8c093b | 3932 | iwl4965_commit_rxon(priv); |
b481de9c ZY |
3933 | else |
3934 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); | |
3935 | ||
3936 | IWL_DEBUG_MAC80211("leave\n"); | |
3937 | ||
a0646470 ZY |
3938 | out: |
3939 | clear_bit(STATUS_CONF_PENDING, &priv->status); | |
5a66926a | 3940 | mutex_unlock(&priv->mutex); |
76bb77e0 | 3941 | return ret; |
b481de9c ZY |
3942 | } |
3943 | ||
c79dd5b5 | 3944 | static void iwl4965_config_ap(struct iwl_priv *priv) |
b481de9c | 3945 | { |
857485c0 | 3946 | int ret = 0; |
b481de9c | 3947 | |
d986bcd1 | 3948 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
b481de9c ZY |
3949 | return; |
3950 | ||
3951 | /* The following should be done only at AP bring up */ | |
3952 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { | |
3953 | ||
3954 | /* RXON - unassoc (to set timing command) */ | |
3955 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
bb8c093b | 3956 | iwl4965_commit_rxon(priv); |
b481de9c ZY |
3957 | |
3958 | /* RXON Timing */ | |
bb8c093b CH |
3959 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
3960 | iwl4965_setup_rxon_timing(priv); | |
857485c0 | 3961 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
b481de9c | 3962 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
857485c0 | 3963 | if (ret) |
b481de9c ZY |
3964 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
3965 | "Attempting to continue.\n"); | |
3966 | ||
c7de35cd | 3967 | iwl_set_rxon_chain(priv); |
b481de9c ZY |
3968 | |
3969 | /* FIXME: what should be the assoc_id for AP? */ | |
3970 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); | |
3971 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) | |
3972 | priv->staging_rxon.flags |= | |
3973 | RXON_FLG_SHORT_PREAMBLE_MSK; | |
3974 | else | |
3975 | priv->staging_rxon.flags &= | |
3976 | ~RXON_FLG_SHORT_PREAMBLE_MSK; | |
3977 | ||
3978 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { | |
3979 | if (priv->assoc_capability & | |
3980 | WLAN_CAPABILITY_SHORT_SLOT_TIME) | |
3981 | priv->staging_rxon.flags |= | |
3982 | RXON_FLG_SHORT_SLOT_MSK; | |
3983 | else | |
3984 | priv->staging_rxon.flags &= | |
3985 | ~RXON_FLG_SHORT_SLOT_MSK; | |
3986 | ||
3987 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) | |
3988 | priv->staging_rxon.flags &= | |
3989 | ~RXON_FLG_SHORT_SLOT_MSK; | |
3990 | } | |
3991 | /* restore RXON assoc */ | |
3992 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; | |
bb8c093b | 3993 | iwl4965_commit_rxon(priv); |
bb8c093b | 3994 | iwl4965_activate_qos(priv, 1); |
4f40e4d9 | 3995 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
e1493deb | 3996 | } |
bb8c093b | 3997 | iwl4965_send_beacon_cmd(priv); |
b481de9c ZY |
3998 | |
3999 | /* FIXME - we need to add code here to detect a totally new | |
4000 | * configuration, reset the AP, unassoc, rxon timing, assoc, | |
4001 | * clear sta table, add BCAST sta... */ | |
4002 | } | |
4003 | ||
32bfd35d JB |
4004 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
4005 | struct ieee80211_vif *vif, | |
b481de9c ZY |
4006 | struct ieee80211_if_conf *conf) |
4007 | { | |
c79dd5b5 | 4008 | struct iwl_priv *priv = hw->priv; |
0795af57 | 4009 | DECLARE_MAC_BUF(mac); |
b481de9c ZY |
4010 | unsigned long flags; |
4011 | int rc; | |
4012 | ||
4013 | if (conf == NULL) | |
4014 | return -EIO; | |
4015 | ||
b716bb91 EG |
4016 | if (priv->vif != vif) { |
4017 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); | |
b716bb91 EG |
4018 | return 0; |
4019 | } | |
4020 | ||
b481de9c ZY |
4021 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
4022 | (!conf->beacon || !conf->ssid_len)) { | |
4023 | IWL_DEBUG_MAC80211 | |
4024 | ("Leaving in AP mode because HostAPD is not ready.\n"); | |
4025 | return 0; | |
4026 | } | |
4027 | ||
fee1247a | 4028 | if (!iwl_is_alive(priv)) |
5a66926a ZY |
4029 | return -EAGAIN; |
4030 | ||
b481de9c ZY |
4031 | mutex_lock(&priv->mutex); |
4032 | ||
b481de9c | 4033 | if (conf->bssid) |
0795af57 JP |
4034 | IWL_DEBUG_MAC80211("bssid: %s\n", |
4035 | print_mac(mac, conf->bssid)); | |
b481de9c | 4036 | |
4150c572 JB |
4037 | /* |
4038 | * very dubious code was here; the probe filtering flag is never set: | |
4039 | * | |
b481de9c ZY |
4040 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
4041 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { | |
4150c572 | 4042 | */ |
b481de9c ZY |
4043 | |
4044 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { | |
4045 | if (!conf->bssid) { | |
4046 | conf->bssid = priv->mac_addr; | |
4047 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); | |
0795af57 JP |
4048 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
4049 | print_mac(mac, conf->bssid)); | |
b481de9c ZY |
4050 | } |
4051 | if (priv->ibss_beacon) | |
4052 | dev_kfree_skb(priv->ibss_beacon); | |
4053 | ||
4054 | priv->ibss_beacon = conf->beacon; | |
4055 | } | |
4056 | ||
fee1247a | 4057 | if (iwl_is_rfkill(priv)) |
fde3571f MA |
4058 | goto done; |
4059 | ||
b481de9c ZY |
4060 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
4061 | !is_multicast_ether_addr(conf->bssid)) { | |
4062 | /* If there is currently a HW scan going on in the background | |
4063 | * then we need to cancel it else the RXON below will fail. */ | |
bb8c093b | 4064 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
b481de9c ZY |
4065 | IWL_WARNING("Aborted scan still in progress " |
4066 | "after 100ms\n"); | |
4067 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); | |
4068 | mutex_unlock(&priv->mutex); | |
4069 | return -EAGAIN; | |
4070 | } | |
4071 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); | |
4072 | ||
4073 | /* TODO: Audit driver for usage of these members and see | |
4074 | * if mac80211 deprecates them (priv->bssid looks like it | |
4075 | * shouldn't be there, but I haven't scanned the IBSS code | |
4076 | * to verify) - jpk */ | |
4077 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); | |
4078 | ||
4079 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) | |
bb8c093b | 4080 | iwl4965_config_ap(priv); |
b481de9c | 4081 | else { |
bb8c093b | 4082 | rc = iwl4965_commit_rxon(priv); |
b481de9c | 4083 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
4f40e4d9 | 4084 | iwl_rxon_add_station( |
b481de9c ZY |
4085 | priv, priv->active_rxon.bssid_addr, 1); |
4086 | } | |
4087 | ||
4088 | } else { | |
bb8c093b | 4089 | iwl4965_scan_cancel_timeout(priv, 100); |
b481de9c | 4090 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
bb8c093b | 4091 | iwl4965_commit_rxon(priv); |
b481de9c ZY |
4092 | } |
4093 | ||
fde3571f | 4094 | done: |
b481de9c ZY |
4095 | spin_lock_irqsave(&priv->lock, flags); |
4096 | if (!conf->ssid_len) | |
4097 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); | |
4098 | else | |
4099 | memcpy(priv->essid, conf->ssid, conf->ssid_len); | |
4100 | ||
4101 | priv->essid_len = conf->ssid_len; | |
4102 | spin_unlock_irqrestore(&priv->lock, flags); | |
4103 | ||
4104 | IWL_DEBUG_MAC80211("leave\n"); | |
4105 | mutex_unlock(&priv->mutex); | |
4106 | ||
4107 | return 0; | |
4108 | } | |
4109 | ||
bb8c093b | 4110 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
4150c572 JB |
4111 | unsigned int changed_flags, |
4112 | unsigned int *total_flags, | |
4113 | int mc_count, struct dev_addr_list *mc_list) | |
4114 | { | |
4115 | /* | |
4116 | * XXX: dummy | |
bb8c093b | 4117 | * see also iwl4965_connection_init_rx_config |
4150c572 | 4118 | */ |
4419e39b AK |
4119 | struct iwl_priv *priv = hw->priv; |
4120 | int new_flags = 0; | |
4121 | if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { | |
4122 | if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { | |
4123 | IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n", | |
4124 | IEEE80211_IF_TYPE_MNTR, | |
4125 | changed_flags, *total_flags); | |
4126 | /* queue work 'cuz mac80211 is holding a lock which | |
4127 | * prevents us from issuing (synchronous) f/w cmds */ | |
4128 | queue_work(priv->workqueue, &priv->set_monitor); | |
4129 | new_flags &= FIF_PROMISC_IN_BSS | | |
4130 | FIF_OTHER_BSS | | |
4131 | FIF_ALLMULTI; | |
4132 | } | |
4133 | } | |
4134 | *total_flags = new_flags; | |
4150c572 JB |
4135 | } |
4136 | ||
bb8c093b | 4137 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
b481de9c ZY |
4138 | struct ieee80211_if_init_conf *conf) |
4139 | { | |
c79dd5b5 | 4140 | struct iwl_priv *priv = hw->priv; |
b481de9c ZY |
4141 | |
4142 | IWL_DEBUG_MAC80211("enter\n"); | |
4143 | ||
4144 | mutex_lock(&priv->mutex); | |
948c171c | 4145 | |
fee1247a | 4146 | if (iwl_is_ready_rf(priv)) { |
fde3571f MA |
4147 | iwl4965_scan_cancel_timeout(priv, 100); |
4148 | cancel_delayed_work(&priv->post_associate); | |
4149 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
4150 | iwl4965_commit_rxon(priv); | |
4151 | } | |
32bfd35d JB |
4152 | if (priv->vif == conf->vif) { |
4153 | priv->vif = NULL; | |
b481de9c ZY |
4154 | memset(priv->bssid, 0, ETH_ALEN); |
4155 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); | |
4156 | priv->essid_len = 0; | |
4157 | } | |
4158 | mutex_unlock(&priv->mutex); | |
4159 | ||
4160 | IWL_DEBUG_MAC80211("leave\n"); | |
4161 | ||
4162 | } | |
471b3efd | 4163 | |
3109ece1 | 4164 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
471b3efd JB |
4165 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
4166 | struct ieee80211_vif *vif, | |
4167 | struct ieee80211_bss_conf *bss_conf, | |
4168 | u32 changes) | |
220173b0 | 4169 | { |
c79dd5b5 | 4170 | struct iwl_priv *priv = hw->priv; |
220173b0 | 4171 | |
3109ece1 TW |
4172 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
4173 | ||
471b3efd | 4174 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
3109ece1 TW |
4175 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
4176 | bss_conf->use_short_preamble); | |
471b3efd | 4177 | if (bss_conf->use_short_preamble) |
220173b0 TW |
4178 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
4179 | else | |
4180 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; | |
4181 | } | |
4182 | ||
471b3efd | 4183 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
3109ece1 | 4184 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
8318d78a | 4185 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
220173b0 TW |
4186 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
4187 | else | |
4188 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; | |
4189 | } | |
4190 | ||
98952d5d | 4191 | if (changes & BSS_CHANGED_HT) { |
3109ece1 | 4192 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
98952d5d | 4193 | iwl4965_ht_conf(priv, bss_conf); |
c7de35cd | 4194 | iwl_set_rxon_chain(priv); |
98952d5d TW |
4195 | } |
4196 | ||
471b3efd | 4197 | if (changes & BSS_CHANGED_ASSOC) { |
3109ece1 | 4198 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
508e32e1 RC |
4199 | /* This should never happen as this function should |
4200 | * never be called from interrupt context. */ | |
4201 | if (WARN_ON_ONCE(in_interrupt())) | |
4202 | return; | |
3109ece1 TW |
4203 | if (bss_conf->assoc) { |
4204 | priv->assoc_id = bss_conf->aid; | |
4205 | priv->beacon_int = bss_conf->beacon_int; | |
4206 | priv->timestamp = bss_conf->timestamp; | |
4207 | priv->assoc_capability = bss_conf->assoc_capability; | |
4208 | priv->next_scan_jiffies = jiffies + | |
4209 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; | |
508e32e1 RC |
4210 | mutex_lock(&priv->mutex); |
4211 | iwl4965_post_associate(priv); | |
4212 | mutex_unlock(&priv->mutex); | |
3109ece1 TW |
4213 | } else { |
4214 | priv->assoc_id = 0; | |
4215 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); | |
4216 | } | |
4217 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { | |
4218 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); | |
7e8c519e | 4219 | iwl_send_rxon_assoc(priv); |
471b3efd JB |
4220 | } |
4221 | ||
220173b0 | 4222 | } |
b481de9c | 4223 | |
bb8c093b | 4224 | static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) |
b481de9c ZY |
4225 | { |
4226 | int rc = 0; | |
4227 | unsigned long flags; | |
c79dd5b5 | 4228 | struct iwl_priv *priv = hw->priv; |
b481de9c ZY |
4229 | |
4230 | IWL_DEBUG_MAC80211("enter\n"); | |
4231 | ||
052c4b9f | 4232 | mutex_lock(&priv->mutex); |
b481de9c ZY |
4233 | spin_lock_irqsave(&priv->lock, flags); |
4234 | ||
fee1247a | 4235 | if (!iwl_is_ready_rf(priv)) { |
b481de9c ZY |
4236 | rc = -EIO; |
4237 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); | |
4238 | goto out_unlock; | |
4239 | } | |
4240 | ||
4241 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ | |
4242 | rc = -EIO; | |
4243 | IWL_ERROR("ERROR: APs don't scan\n"); | |
4244 | goto out_unlock; | |
4245 | } | |
4246 | ||
7878a5a4 MA |
4247 | /* we don't schedule scan within next_scan_jiffies period */ |
4248 | if (priv->next_scan_jiffies && | |
4249 | time_after(priv->next_scan_jiffies, jiffies)) { | |
4250 | rc = -EAGAIN; | |
4251 | goto out_unlock; | |
4252 | } | |
b481de9c | 4253 | /* if we just finished scan ask for delay */ |
7878a5a4 MA |
4254 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
4255 | IWL_DELAY_NEXT_SCAN, jiffies)) { | |
b481de9c ZY |
4256 | rc = -EAGAIN; |
4257 | goto out_unlock; | |
4258 | } | |
4259 | if (len) { | |
7878a5a4 | 4260 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
bb8c093b | 4261 | iwl4965_escape_essid(ssid, len), (int)len); |
b481de9c ZY |
4262 | |
4263 | priv->one_direct_scan = 1; | |
4264 | priv->direct_ssid_len = (u8) | |
4265 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); | |
4266 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); | |
948c171c MA |
4267 | } else |
4268 | priv->one_direct_scan = 0; | |
b481de9c | 4269 | |
bb8c093b | 4270 | rc = iwl4965_scan_initiate(priv); |
b481de9c ZY |
4271 | |
4272 | IWL_DEBUG_MAC80211("leave\n"); | |
4273 | ||
4274 | out_unlock: | |
4275 | spin_unlock_irqrestore(&priv->lock, flags); | |
052c4b9f | 4276 | mutex_unlock(&priv->mutex); |
b481de9c ZY |
4277 | |
4278 | return rc; | |
4279 | } | |
4280 | ||
ab885f8c EG |
4281 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
4282 | struct ieee80211_key_conf *keyconf, const u8 *addr, | |
4283 | u32 iv32, u16 *phase1key) | |
4284 | { | |
4285 | struct iwl_priv *priv = hw->priv; | |
4286 | u8 sta_id = IWL_INVALID_STATION; | |
4287 | unsigned long flags; | |
4288 | __le16 key_flags = 0; | |
4289 | int i; | |
4290 | DECLARE_MAC_BUF(mac); | |
4291 | ||
4292 | IWL_DEBUG_MAC80211("enter\n"); | |
4293 | ||
947b13a7 | 4294 | sta_id = iwl_find_station(priv, addr); |
ab885f8c EG |
4295 | if (sta_id == IWL_INVALID_STATION) { |
4296 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", | |
4297 | print_mac(mac, addr)); | |
4298 | return; | |
4299 | } | |
4300 | ||
4301 | iwl4965_scan_cancel_timeout(priv, 100); | |
4302 | ||
4303 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); | |
4304 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); | |
4305 | key_flags &= ~STA_KEY_FLG_INVALID; | |
4306 | ||
5425e490 | 4307 | if (sta_id == priv->hw_params.bcast_sta_id) |
ab885f8c EG |
4308 | key_flags |= STA_KEY_MULTICAST_MSK; |
4309 | ||
4310 | spin_lock_irqsave(&priv->sta_lock, flags); | |
4311 | ||
ab885f8c EG |
4312 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
4313 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; | |
4314 | ||
4315 | for (i = 0; i < 5; i++) | |
4316 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = | |
4317 | cpu_to_le16(phase1key[i]); | |
4318 | ||
4319 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; | |
4320 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; | |
4321 | ||
133636de | 4322 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
ab885f8c EG |
4323 | |
4324 | spin_unlock_irqrestore(&priv->sta_lock, flags); | |
4325 | ||
4326 | IWL_DEBUG_MAC80211("leave\n"); | |
4327 | } | |
4328 | ||
bb8c093b | 4329 | static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
b481de9c ZY |
4330 | const u8 *local_addr, const u8 *addr, |
4331 | struct ieee80211_key_conf *key) | |
4332 | { | |
c79dd5b5 | 4333 | struct iwl_priv *priv = hw->priv; |
0795af57 | 4334 | DECLARE_MAC_BUF(mac); |
deb09c43 EG |
4335 | int ret = 0; |
4336 | u8 sta_id = IWL_INVALID_STATION; | |
6974e363 | 4337 | u8 is_default_wep_key = 0; |
b481de9c ZY |
4338 | |
4339 | IWL_DEBUG_MAC80211("enter\n"); | |
4340 | ||
099b40b7 | 4341 | if (priv->hw_params.sw_crypto) { |
b481de9c ZY |
4342 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
4343 | return -EOPNOTSUPP; | |
4344 | } | |
4345 | ||
4346 | if (is_zero_ether_addr(addr)) | |
4347 | /* only support pairwise keys */ | |
4348 | return -EOPNOTSUPP; | |
4349 | ||
947b13a7 | 4350 | sta_id = iwl_find_station(priv, addr); |
6974e363 EG |
4351 | if (sta_id == IWL_INVALID_STATION) { |
4352 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", | |
4353 | print_mac(mac, addr)); | |
4354 | return -EINVAL; | |
b481de9c | 4355 | |
deb09c43 | 4356 | } |
b481de9c | 4357 | |
6974e363 | 4358 | mutex_lock(&priv->mutex); |
bb8c093b | 4359 | iwl4965_scan_cancel_timeout(priv, 100); |
6974e363 EG |
4360 | mutex_unlock(&priv->mutex); |
4361 | ||
4362 | /* If we are getting WEP group key and we didn't receive any key mapping | |
4363 | * so far, we are in legacy wep mode (group key only), otherwise we are | |
4364 | * in 1X mode. | |
4365 | * In legacy wep mode, we use another host command to the uCode */ | |
5425e490 | 4366 | if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id && |
6974e363 EG |
4367 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
4368 | if (cmd == SET_KEY) | |
4369 | is_default_wep_key = !priv->key_mapping_key; | |
4370 | else | |
ccc038ab EG |
4371 | is_default_wep_key = |
4372 | (key->hw_key_idx == HW_KEY_DEFAULT); | |
6974e363 | 4373 | } |
052c4b9f | 4374 | |
b481de9c | 4375 | switch (cmd) { |
deb09c43 | 4376 | case SET_KEY: |
6974e363 EG |
4377 | if (is_default_wep_key) |
4378 | ret = iwl_set_default_wep_key(priv, key); | |
deb09c43 | 4379 | else |
7480513f | 4380 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
deb09c43 EG |
4381 | |
4382 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); | |
b481de9c ZY |
4383 | break; |
4384 | case DISABLE_KEY: | |
6974e363 EG |
4385 | if (is_default_wep_key) |
4386 | ret = iwl_remove_default_wep_key(priv, key); | |
deb09c43 | 4387 | else |
3ec47732 | 4388 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
deb09c43 EG |
4389 | |
4390 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); | |
b481de9c ZY |
4391 | break; |
4392 | default: | |
deb09c43 | 4393 | ret = -EINVAL; |
b481de9c ZY |
4394 | } |
4395 | ||
4396 | IWL_DEBUG_MAC80211("leave\n"); | |
b481de9c | 4397 | |
deb09c43 | 4398 | return ret; |
b481de9c ZY |
4399 | } |
4400 | ||
e100bb64 | 4401 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
b481de9c ZY |
4402 | const struct ieee80211_tx_queue_params *params) |
4403 | { | |
c79dd5b5 | 4404 | struct iwl_priv *priv = hw->priv; |
b481de9c ZY |
4405 | unsigned long flags; |
4406 | int q; | |
b481de9c ZY |
4407 | |
4408 | IWL_DEBUG_MAC80211("enter\n"); | |
4409 | ||
fee1247a | 4410 | if (!iwl_is_ready_rf(priv)) { |
b481de9c ZY |
4411 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
4412 | return -EIO; | |
4413 | } | |
4414 | ||
4415 | if (queue >= AC_NUM) { | |
4416 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); | |
4417 | return 0; | |
4418 | } | |
4419 | ||
b481de9c ZY |
4420 | if (!priv->qos_data.qos_enable) { |
4421 | priv->qos_data.qos_active = 0; | |
4422 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); | |
4423 | return 0; | |
4424 | } | |
4425 | q = AC_NUM - 1 - queue; | |
4426 | ||
4427 | spin_lock_irqsave(&priv->lock, flags); | |
4428 | ||
4429 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); | |
4430 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); | |
4431 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; | |
4432 | priv->qos_data.def_qos_parm.ac[q].edca_txop = | |
3330d7be | 4433 | cpu_to_le16((params->txop * 32)); |
b481de9c ZY |
4434 | |
4435 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; | |
4436 | priv->qos_data.qos_active = 1; | |
4437 | ||
4438 | spin_unlock_irqrestore(&priv->lock, flags); | |
4439 | ||
4440 | mutex_lock(&priv->mutex); | |
4441 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) | |
bb8c093b | 4442 | iwl4965_activate_qos(priv, 1); |
3109ece1 | 4443 | else if (priv->assoc_id && iwl_is_associated(priv)) |
bb8c093b | 4444 | iwl4965_activate_qos(priv, 0); |
b481de9c ZY |
4445 | |
4446 | mutex_unlock(&priv->mutex); | |
4447 | ||
b481de9c ZY |
4448 | IWL_DEBUG_MAC80211("leave\n"); |
4449 | return 0; | |
4450 | } | |
4451 | ||
bb8c093b | 4452 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
b481de9c ZY |
4453 | struct ieee80211_tx_queue_stats *stats) |
4454 | { | |
c79dd5b5 | 4455 | struct iwl_priv *priv = hw->priv; |
b481de9c | 4456 | int i, avail; |
16466903 | 4457 | struct iwl_tx_queue *txq; |
443cfd45 | 4458 | struct iwl_queue *q; |
b481de9c ZY |
4459 | unsigned long flags; |
4460 | ||
4461 | IWL_DEBUG_MAC80211("enter\n"); | |
4462 | ||
fee1247a | 4463 | if (!iwl_is_ready_rf(priv)) { |
b481de9c ZY |
4464 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
4465 | return -EIO; | |
4466 | } | |
4467 | ||
4468 | spin_lock_irqsave(&priv->lock, flags); | |
4469 | ||
4470 | for (i = 0; i < AC_NUM; i++) { | |
4471 | txq = &priv->txq[i]; | |
4472 | q = &txq->q; | |
443cfd45 | 4473 | avail = iwl_queue_space(q); |
b481de9c | 4474 | |
57ffc589 JB |
4475 | stats[i].len = q->n_window - avail; |
4476 | stats[i].limit = q->n_window - q->high_mark; | |
4477 | stats[i].count = q->n_window; | |
b481de9c ZY |
4478 | |
4479 | } | |
4480 | spin_unlock_irqrestore(&priv->lock, flags); | |
4481 | ||
4482 | IWL_DEBUG_MAC80211("leave\n"); | |
4483 | ||
4484 | return 0; | |
4485 | } | |
4486 | ||
bb8c093b | 4487 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
b481de9c ZY |
4488 | struct ieee80211_low_level_stats *stats) |
4489 | { | |
bf403db8 EK |
4490 | struct iwl_priv *priv = hw->priv; |
4491 | ||
4492 | priv = hw->priv; | |
b481de9c ZY |
4493 | IWL_DEBUG_MAC80211("enter\n"); |
4494 | IWL_DEBUG_MAC80211("leave\n"); | |
4495 | ||
4496 | return 0; | |
4497 | } | |
4498 | ||
bb8c093b | 4499 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
b481de9c | 4500 | { |
bf403db8 EK |
4501 | struct iwl_priv *priv; |
4502 | ||
4503 | priv = hw->priv; | |
b481de9c ZY |
4504 | IWL_DEBUG_MAC80211("enter\n"); |
4505 | IWL_DEBUG_MAC80211("leave\n"); | |
4506 | ||
4507 | return 0; | |
4508 | } | |
4509 | ||
bb8c093b | 4510 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
b481de9c | 4511 | { |
c79dd5b5 | 4512 | struct iwl_priv *priv = hw->priv; |
b481de9c ZY |
4513 | unsigned long flags; |
4514 | ||
4515 | mutex_lock(&priv->mutex); | |
4516 | IWL_DEBUG_MAC80211("enter\n"); | |
4517 | ||
4518 | priv->lq_mngr.lq_ready = 0; | |
b481de9c | 4519 | spin_lock_irqsave(&priv->lock, flags); |
fd105e79 | 4520 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
b481de9c | 4521 | spin_unlock_irqrestore(&priv->lock, flags); |
b481de9c | 4522 | |
c7de35cd | 4523 | iwl_reset_qos(priv); |
b481de9c ZY |
4524 | |
4525 | cancel_delayed_work(&priv->post_associate); | |
4526 | ||
4527 | spin_lock_irqsave(&priv->lock, flags); | |
4528 | priv->assoc_id = 0; | |
4529 | priv->assoc_capability = 0; | |
b481de9c ZY |
4530 | priv->assoc_station_added = 0; |
4531 | ||
4532 | /* new association get rid of ibss beacon skb */ | |
4533 | if (priv->ibss_beacon) | |
4534 | dev_kfree_skb(priv->ibss_beacon); | |
4535 | ||
4536 | priv->ibss_beacon = NULL; | |
4537 | ||
4538 | priv->beacon_int = priv->hw->conf.beacon_int; | |
3109ece1 | 4539 | priv->timestamp = 0; |
b481de9c ZY |
4540 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
4541 | priv->beacon_int = 0; | |
4542 | ||
4543 | spin_unlock_irqrestore(&priv->lock, flags); | |
4544 | ||
fee1247a | 4545 | if (!iwl_is_ready_rf(priv)) { |
fde3571f MA |
4546 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
4547 | mutex_unlock(&priv->mutex); | |
4548 | return; | |
4549 | } | |
4550 | ||
052c4b9f | 4551 | /* we are restarting association process |
4552 | * clear RXON_FILTER_ASSOC_MSK bit | |
4553 | */ | |
4554 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { | |
bb8c093b | 4555 | iwl4965_scan_cancel_timeout(priv, 100); |
052c4b9f | 4556 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
bb8c093b | 4557 | iwl4965_commit_rxon(priv); |
052c4b9f | 4558 | } |
4559 | ||
5da4b55f MA |
4560 | iwl_power_update_mode(priv, 0); |
4561 | ||
b481de9c ZY |
4562 | /* Per mac80211.h: This is only used in IBSS mode... */ |
4563 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { | |
052c4b9f | 4564 | |
b481de9c ZY |
4565 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
4566 | mutex_unlock(&priv->mutex); | |
4567 | return; | |
4568 | } | |
4569 | ||
bb8c093b | 4570 | iwl4965_set_rate(priv); |
b481de9c ZY |
4571 | |
4572 | mutex_unlock(&priv->mutex); | |
4573 | ||
4574 | IWL_DEBUG_MAC80211("leave\n"); | |
b481de9c ZY |
4575 | } |
4576 | ||
e039fa4a | 4577 | static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb) |
b481de9c | 4578 | { |
c79dd5b5 | 4579 | struct iwl_priv *priv = hw->priv; |
b481de9c ZY |
4580 | unsigned long flags; |
4581 | ||
4582 | mutex_lock(&priv->mutex); | |
4583 | IWL_DEBUG_MAC80211("enter\n"); | |
4584 | ||
fee1247a | 4585 | if (!iwl_is_ready_rf(priv)) { |
b481de9c ZY |
4586 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
4587 | mutex_unlock(&priv->mutex); | |
4588 | return -EIO; | |
4589 | } | |
4590 | ||
4591 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { | |
4592 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); | |
4593 | mutex_unlock(&priv->mutex); | |
4594 | return -EIO; | |
4595 | } | |
4596 | ||
4597 | spin_lock_irqsave(&priv->lock, flags); | |
4598 | ||
4599 | if (priv->ibss_beacon) | |
4600 | dev_kfree_skb(priv->ibss_beacon); | |
4601 | ||
4602 | priv->ibss_beacon = skb; | |
4603 | ||
4604 | priv->assoc_id = 0; | |
4605 | ||
4606 | IWL_DEBUG_MAC80211("leave\n"); | |
4607 | spin_unlock_irqrestore(&priv->lock, flags); | |
4608 | ||
c7de35cd | 4609 | iwl_reset_qos(priv); |
b481de9c ZY |
4610 | |
4611 | queue_work(priv->workqueue, &priv->post_associate.work); | |
4612 | ||
4613 | mutex_unlock(&priv->mutex); | |
4614 | ||
4615 | return 0; | |
4616 | } | |
4617 | ||
b481de9c ZY |
4618 | /***************************************************************************** |
4619 | * | |
4620 | * sysfs attributes | |
4621 | * | |
4622 | *****************************************************************************/ | |
4623 | ||
0a6857e7 | 4624 | #ifdef CONFIG_IWLWIFI_DEBUG |
b481de9c ZY |
4625 | |
4626 | /* | |
4627 | * The following adds a new attribute to the sysfs representation | |
4628 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) | |
4629 | * used for controlling the debug level. | |
4630 | * | |
4631 | * See the level definitions in iwl for details. | |
4632 | */ | |
4633 | ||
8cf769c6 EK |
4634 | static ssize_t show_debug_level(struct device *d, |
4635 | struct device_attribute *attr, char *buf) | |
b481de9c | 4636 | { |
8cf769c6 EK |
4637 | struct iwl_priv *priv = d->driver_data; |
4638 | ||
4639 | return sprintf(buf, "0x%08X\n", priv->debug_level); | |
b481de9c | 4640 | } |
8cf769c6 EK |
4641 | static ssize_t store_debug_level(struct device *d, |
4642 | struct device_attribute *attr, | |
b481de9c ZY |
4643 | const char *buf, size_t count) |
4644 | { | |
8cf769c6 | 4645 | struct iwl_priv *priv = d->driver_data; |
b481de9c ZY |
4646 | char *p = (char *)buf; |
4647 | u32 val; | |
4648 | ||
4649 | val = simple_strtoul(p, &p, 0); | |
4650 | if (p == buf) | |
4651 | printk(KERN_INFO DRV_NAME | |
4652 | ": %s is not in hex or decimal form.\n", buf); | |
4653 | else | |
8cf769c6 | 4654 | priv->debug_level = val; |
b481de9c ZY |
4655 | |
4656 | return strnlen(buf, count); | |
4657 | } | |
4658 | ||
8cf769c6 EK |
4659 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
4660 | show_debug_level, store_debug_level); | |
4661 | ||
b481de9c | 4662 | |
0a6857e7 | 4663 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
b481de9c | 4664 | |
b481de9c | 4665 | |
bc6f59bc TW |
4666 | static ssize_t show_version(struct device *d, |
4667 | struct device_attribute *attr, char *buf) | |
4668 | { | |
4669 | struct iwl_priv *priv = d->driver_data; | |
885ba202 | 4670 | struct iwl_alive_resp *palive = &priv->card_alive; |
bc6f59bc TW |
4671 | |
4672 | if (palive->is_valid) | |
4673 | return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" | |
4674 | "fw type: 0x%01X 0x%01X\n", | |
4675 | palive->ucode_major, palive->ucode_minor, | |
4676 | palive->sw_rev[0], palive->sw_rev[1], | |
4677 | palive->ver_type, palive->ver_subtype); | |
4678 | ||
4679 | else | |
4680 | return sprintf(buf, "fw not loaded\n"); | |
4681 | } | |
4682 | ||
4683 | static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL); | |
4684 | ||
b481de9c ZY |
4685 | static ssize_t show_temperature(struct device *d, |
4686 | struct device_attribute *attr, char *buf) | |
4687 | { | |
c79dd5b5 | 4688 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
b481de9c | 4689 | |
fee1247a | 4690 | if (!iwl_is_alive(priv)) |
b481de9c ZY |
4691 | return -EAGAIN; |
4692 | ||
bb8c093b | 4693 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
b481de9c ZY |
4694 | } |
4695 | ||
4696 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); | |
4697 | ||
4698 | static ssize_t show_rs_window(struct device *d, | |
4699 | struct device_attribute *attr, | |
4700 | char *buf) | |
4701 | { | |
c79dd5b5 | 4702 | struct iwl_priv *priv = d->driver_data; |
bb8c093b | 4703 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
b481de9c ZY |
4704 | } |
4705 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); | |
4706 | ||
4707 | static ssize_t show_tx_power(struct device *d, | |
4708 | struct device_attribute *attr, char *buf) | |
4709 | { | |
c79dd5b5 | 4710 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
b481de9c ZY |
4711 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
4712 | } | |
4713 | ||
4714 | static ssize_t store_tx_power(struct device *d, | |
4715 | struct device_attribute *attr, | |
4716 | const char *buf, size_t count) | |
4717 | { | |
c79dd5b5 | 4718 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
b481de9c ZY |
4719 | char *p = (char *)buf; |
4720 | u32 val; | |
4721 | ||
4722 | val = simple_strtoul(p, &p, 10); | |
4723 | if (p == buf) | |
4724 | printk(KERN_INFO DRV_NAME | |
4725 | ": %s is not in decimal form.\n", buf); | |
4726 | else | |
bb8c093b | 4727 | iwl4965_hw_reg_set_txpower(priv, val); |
b481de9c ZY |
4728 | |
4729 | return count; | |
4730 | } | |
4731 | ||
4732 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); | |
4733 | ||
4734 | static ssize_t show_flags(struct device *d, | |
4735 | struct device_attribute *attr, char *buf) | |
4736 | { | |
c79dd5b5 | 4737 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
b481de9c ZY |
4738 | |
4739 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); | |
4740 | } | |
4741 | ||
4742 | static ssize_t store_flags(struct device *d, | |
4743 | struct device_attribute *attr, | |
4744 | const char *buf, size_t count) | |
4745 | { | |
c79dd5b5 | 4746 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
b481de9c ZY |
4747 | u32 flags = simple_strtoul(buf, NULL, 0); |
4748 | ||
4749 | mutex_lock(&priv->mutex); | |
4750 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { | |
4751 | /* Cancel any currently running scans... */ | |
bb8c093b | 4752 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
b481de9c ZY |
4753 | IWL_WARNING("Could not cancel scan.\n"); |
4754 | else { | |
4755 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", | |
4756 | flags); | |
4757 | priv->staging_rxon.flags = cpu_to_le32(flags); | |
bb8c093b | 4758 | iwl4965_commit_rxon(priv); |
b481de9c ZY |
4759 | } |
4760 | } | |
4761 | mutex_unlock(&priv->mutex); | |
4762 | ||
4763 | return count; | |
4764 | } | |
4765 | ||
4766 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); | |
4767 | ||
4768 | static ssize_t show_filter_flags(struct device *d, | |
4769 | struct device_attribute *attr, char *buf) | |
4770 | { | |
c79dd5b5 | 4771 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
b481de9c ZY |
4772 | |
4773 | return sprintf(buf, "0x%04X\n", | |
4774 | le32_to_cpu(priv->active_rxon.filter_flags)); | |
4775 | } | |
4776 | ||
4777 | static ssize_t store_filter_flags(struct device *d, | |
4778 | struct device_attribute *attr, | |
4779 | const char *buf, size_t count) | |
4780 | { | |
c79dd5b5 | 4781 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
b481de9c ZY |
4782 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
4783 | ||
4784 | mutex_lock(&priv->mutex); | |
4785 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { | |
4786 | /* Cancel any currently running scans... */ | |
bb8c093b | 4787 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
b481de9c ZY |
4788 | IWL_WARNING("Could not cancel scan.\n"); |
4789 | else { | |
4790 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " | |
4791 | "0x%04X\n", filter_flags); | |
4792 | priv->staging_rxon.filter_flags = | |
4793 | cpu_to_le32(filter_flags); | |
bb8c093b | 4794 | iwl4965_commit_rxon(priv); |
b481de9c ZY |
4795 | } |
4796 | } | |
4797 | mutex_unlock(&priv->mutex); | |
4798 | ||
4799 | return count; | |
4800 | } | |
4801 | ||
4802 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, | |
4803 | store_filter_flags); | |
4804 | ||
c8b0e6e1 | 4805 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
b481de9c ZY |
4806 | |
4807 | static ssize_t show_measurement(struct device *d, | |
4808 | struct device_attribute *attr, char *buf) | |
4809 | { | |
c79dd5b5 | 4810 | struct iwl_priv *priv = dev_get_drvdata(d); |
bb8c093b | 4811 | struct iwl4965_spectrum_notification measure_report; |
b481de9c ZY |
4812 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
4813 | u8 *data = (u8 *) & measure_report; | |
4814 | unsigned long flags; | |
4815 | ||
4816 | spin_lock_irqsave(&priv->lock, flags); | |
4817 | if (!(priv->measurement_status & MEASUREMENT_READY)) { | |
4818 | spin_unlock_irqrestore(&priv->lock, flags); | |
4819 | return 0; | |
4820 | } | |
4821 | memcpy(&measure_report, &priv->measure_report, size); | |
4822 | priv->measurement_status = 0; | |
4823 | spin_unlock_irqrestore(&priv->lock, flags); | |
4824 | ||
4825 | while (size && (PAGE_SIZE - len)) { | |
4826 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, | |
4827 | PAGE_SIZE - len, 1); | |
4828 | len = strlen(buf); | |
4829 | if (PAGE_SIZE - len) | |
4830 | buf[len++] = '\n'; | |
4831 | ||
4832 | ofs += 16; | |
4833 | size -= min(size, 16U); | |
4834 | } | |
4835 | ||
4836 | return len; | |
4837 | } | |
4838 | ||
4839 | static ssize_t store_measurement(struct device *d, | |
4840 | struct device_attribute *attr, | |
4841 | const char *buf, size_t count) | |
4842 | { | |
c79dd5b5 | 4843 | struct iwl_priv *priv = dev_get_drvdata(d); |
b481de9c ZY |
4844 | struct ieee80211_measurement_params params = { |
4845 | .channel = le16_to_cpu(priv->active_rxon.channel), | |
4846 | .start_time = cpu_to_le64(priv->last_tsf), | |
4847 | .duration = cpu_to_le16(1), | |
4848 | }; | |
4849 | u8 type = IWL_MEASURE_BASIC; | |
4850 | u8 buffer[32]; | |
4851 | u8 channel; | |
4852 | ||
4853 | if (count) { | |
4854 | char *p = buffer; | |
4855 | strncpy(buffer, buf, min(sizeof(buffer), count)); | |
4856 | channel = simple_strtoul(p, NULL, 0); | |
4857 | if (channel) | |
4858 | params.channel = channel; | |
4859 | ||
4860 | p = buffer; | |
4861 | while (*p && *p != ' ') | |
4862 | p++; | |
4863 | if (*p) | |
4864 | type = simple_strtoul(p + 1, NULL, 0); | |
4865 | } | |
4866 | ||
4867 | IWL_DEBUG_INFO("Invoking measurement of type %d on " | |
4868 | "channel %d (for '%s')\n", type, params.channel, buf); | |
bb8c093b | 4869 | iwl4965_get_measurement(priv, ¶ms, type); |
b481de9c ZY |
4870 | |
4871 | return count; | |
4872 | } | |
4873 | ||
4874 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, | |
4875 | show_measurement, store_measurement); | |
c8b0e6e1 | 4876 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
b481de9c ZY |
4877 | |
4878 | static ssize_t store_retry_rate(struct device *d, | |
4879 | struct device_attribute *attr, | |
4880 | const char *buf, size_t count) | |
4881 | { | |
c79dd5b5 | 4882 | struct iwl_priv *priv = dev_get_drvdata(d); |
b481de9c ZY |
4883 | |
4884 | priv->retry_rate = simple_strtoul(buf, NULL, 0); | |
4885 | if (priv->retry_rate <= 0) | |
4886 | priv->retry_rate = 1; | |
4887 | ||
4888 | return count; | |
4889 | } | |
4890 | ||
4891 | static ssize_t show_retry_rate(struct device *d, | |
4892 | struct device_attribute *attr, char *buf) | |
4893 | { | |
c79dd5b5 | 4894 | struct iwl_priv *priv = dev_get_drvdata(d); |
b481de9c ZY |
4895 | return sprintf(buf, "%d", priv->retry_rate); |
4896 | } | |
4897 | ||
4898 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, | |
4899 | store_retry_rate); | |
4900 | ||
4901 | static ssize_t store_power_level(struct device *d, | |
4902 | struct device_attribute *attr, | |
4903 | const char *buf, size_t count) | |
4904 | { | |
c79dd5b5 | 4905 | struct iwl_priv *priv = dev_get_drvdata(d); |
b481de9c ZY |
4906 | int rc; |
4907 | int mode; | |
4908 | ||
4909 | mode = simple_strtoul(buf, NULL, 0); | |
4910 | mutex_lock(&priv->mutex); | |
4911 | ||
fee1247a | 4912 | if (!iwl_is_ready(priv)) { |
b481de9c ZY |
4913 | rc = -EAGAIN; |
4914 | goto out; | |
4915 | } | |
4916 | ||
5da4b55f MA |
4917 | rc = iwl_power_set_user_mode(priv, mode); |
4918 | if (rc) { | |
4919 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); | |
4920 | goto out; | |
b481de9c | 4921 | } |
b481de9c ZY |
4922 | rc = count; |
4923 | ||
4924 | out: | |
4925 | mutex_unlock(&priv->mutex); | |
4926 | return rc; | |
4927 | } | |
4928 | ||
4929 | #define MAX_WX_STRING 80 | |
4930 | ||
4931 | /* Values are in microsecond */ | |
4932 | static const s32 timeout_duration[] = { | |
4933 | 350000, | |
4934 | 250000, | |
4935 | 75000, | |
4936 | 37000, | |
4937 | 25000, | |
4938 | }; | |
4939 | static const s32 period_duration[] = { | |
4940 | 400000, | |
4941 | 700000, | |
4942 | 1000000, | |
4943 | 1000000, | |
4944 | 1000000 | |
4945 | }; | |
4946 | ||
4947 | static ssize_t show_power_level(struct device *d, | |
4948 | struct device_attribute *attr, char *buf) | |
4949 | { | |
c79dd5b5 | 4950 | struct iwl_priv *priv = dev_get_drvdata(d); |
5da4b55f | 4951 | int level = priv->power_data.power_mode; |
b481de9c ZY |
4952 | char *p = buf; |
4953 | ||
4954 | p += sprintf(p, "%d ", level); | |
4955 | switch (level) { | |
4956 | case IWL_POWER_MODE_CAM: | |
4957 | case IWL_POWER_AC: | |
4958 | p += sprintf(p, "(AC)"); | |
4959 | break; | |
4960 | case IWL_POWER_BATTERY: | |
4961 | p += sprintf(p, "(BATTERY)"); | |
4962 | break; | |
4963 | default: | |
4964 | p += sprintf(p, | |
4965 | "(Timeout %dms, Period %dms)", | |
4966 | timeout_duration[level - 1] / 1000, | |
4967 | period_duration[level - 1] / 1000); | |
4968 | } | |
5da4b55f | 4969 | /* |
b481de9c ZY |
4970 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
4971 | p += sprintf(p, " OFF\n"); | |
4972 | else | |
4973 | p += sprintf(p, " \n"); | |
5da4b55f MA |
4974 | */ |
4975 | p += sprintf(p, " \n"); | |
b481de9c | 4976 | return (p - buf + 1); |
b481de9c ZY |
4977 | } |
4978 | ||
4979 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, | |
4980 | store_power_level); | |
4981 | ||
4982 | static ssize_t show_channels(struct device *d, | |
4983 | struct device_attribute *attr, char *buf) | |
4984 | { | |
8318d78a JB |
4985 | /* all this shit doesn't belong into sysfs anyway */ |
4986 | return 0; | |
b481de9c ZY |
4987 | } |
4988 | ||
4989 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); | |
4990 | ||
4991 | static ssize_t show_statistics(struct device *d, | |
4992 | struct device_attribute *attr, char *buf) | |
4993 | { | |
c79dd5b5 | 4994 | struct iwl_priv *priv = dev_get_drvdata(d); |
bb8c093b | 4995 | u32 size = sizeof(struct iwl4965_notif_statistics); |
b481de9c ZY |
4996 | u32 len = 0, ofs = 0; |
4997 | u8 *data = (u8 *) & priv->statistics; | |
4998 | int rc = 0; | |
4999 | ||
fee1247a | 5000 | if (!iwl_is_alive(priv)) |
b481de9c ZY |
5001 | return -EAGAIN; |
5002 | ||
5003 | mutex_lock(&priv->mutex); | |
49ea8596 | 5004 | rc = iwl_send_statistics_request(priv, 0); |
b481de9c ZY |
5005 | mutex_unlock(&priv->mutex); |
5006 | ||
5007 | if (rc) { | |
5008 | len = sprintf(buf, | |
5009 | "Error sending statistics request: 0x%08X\n", rc); | |
5010 | return len; | |
5011 | } | |
5012 | ||
5013 | while (size && (PAGE_SIZE - len)) { | |
5014 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, | |
5015 | PAGE_SIZE - len, 1); | |
5016 | len = strlen(buf); | |
5017 | if (PAGE_SIZE - len) | |
5018 | buf[len++] = '\n'; | |
5019 | ||
5020 | ofs += 16; | |
5021 | size -= min(size, 16U); | |
5022 | } | |
5023 | ||
5024 | return len; | |
5025 | } | |
5026 | ||
5027 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); | |
5028 | ||
b481de9c ZY |
5029 | static ssize_t show_status(struct device *d, |
5030 | struct device_attribute *attr, char *buf) | |
5031 | { | |
c79dd5b5 | 5032 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
fee1247a | 5033 | if (!iwl_is_alive(priv)) |
b481de9c ZY |
5034 | return -EAGAIN; |
5035 | return sprintf(buf, "0x%08x\n", (int)priv->status); | |
5036 | } | |
5037 | ||
5038 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | |
5039 | ||
b481de9c ZY |
5040 | /***************************************************************************** |
5041 | * | |
5042 | * driver setup and teardown | |
5043 | * | |
5044 | *****************************************************************************/ | |
5045 | ||
4e39317d | 5046 | static void iwl_setup_deferred_work(struct iwl_priv *priv) |
b481de9c ZY |
5047 | { |
5048 | priv->workqueue = create_workqueue(DRV_NAME); | |
5049 | ||
5050 | init_waitqueue_head(&priv->wait_command_queue); | |
5051 | ||
bb8c093b CH |
5052 | INIT_WORK(&priv->up, iwl4965_bg_up); |
5053 | INIT_WORK(&priv->restart, iwl4965_bg_restart); | |
5054 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); | |
5055 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); | |
5056 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); | |
5057 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); | |
5058 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); | |
5059 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); | |
4419e39b | 5060 | INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); |
16e727e8 | 5061 | INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work); |
bb8c093b | 5062 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
4a4a9e81 TW |
5063 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); |
5064 | INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); | |
bb8c093b CH |
5065 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
5066 | ||
4e39317d EG |
5067 | if (priv->cfg->ops->lib->setup_deferred_work) |
5068 | priv->cfg->ops->lib->setup_deferred_work(priv); | |
5069 | ||
5070 | init_timer(&priv->statistics_periodic); | |
5071 | priv->statistics_periodic.data = (unsigned long)priv; | |
5072 | priv->statistics_periodic.function = iwl4965_bg_statistics_periodic; | |
b481de9c ZY |
5073 | |
5074 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) | |
bb8c093b | 5075 | iwl4965_irq_tasklet, (unsigned long)priv); |
b481de9c ZY |
5076 | } |
5077 | ||
4e39317d | 5078 | static void iwl_cancel_deferred_work(struct iwl_priv *priv) |
b481de9c | 5079 | { |
4e39317d EG |
5080 | if (priv->cfg->ops->lib->cancel_deferred_work) |
5081 | priv->cfg->ops->lib->cancel_deferred_work(priv); | |
b481de9c | 5082 | |
3ae6a054 | 5083 | cancel_delayed_work_sync(&priv->init_alive_start); |
b481de9c ZY |
5084 | cancel_delayed_work(&priv->scan_check); |
5085 | cancel_delayed_work(&priv->alive_start); | |
5086 | cancel_delayed_work(&priv->post_associate); | |
5087 | cancel_work_sync(&priv->beacon_update); | |
4e39317d | 5088 | del_timer_sync(&priv->statistics_periodic); |
b481de9c ZY |
5089 | } |
5090 | ||
bb8c093b | 5091 | static struct attribute *iwl4965_sysfs_entries[] = { |
b481de9c | 5092 | &dev_attr_channels.attr, |
b481de9c ZY |
5093 | &dev_attr_flags.attr, |
5094 | &dev_attr_filter_flags.attr, | |
c8b0e6e1 | 5095 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
b481de9c ZY |
5096 | &dev_attr_measurement.attr, |
5097 | #endif | |
5098 | &dev_attr_power_level.attr, | |
5099 | &dev_attr_retry_rate.attr, | |
b481de9c ZY |
5100 | &dev_attr_rs_window.attr, |
5101 | &dev_attr_statistics.attr, | |
5102 | &dev_attr_status.attr, | |
5103 | &dev_attr_temperature.attr, | |
b481de9c | 5104 | &dev_attr_tx_power.attr, |
8cf769c6 EK |
5105 | #ifdef CONFIG_IWLWIFI_DEBUG |
5106 | &dev_attr_debug_level.attr, | |
5107 | #endif | |
bc6f59bc | 5108 | &dev_attr_version.attr, |
b481de9c ZY |
5109 | |
5110 | NULL | |
5111 | }; | |
5112 | ||
bb8c093b | 5113 | static struct attribute_group iwl4965_attribute_group = { |
b481de9c | 5114 | .name = NULL, /* put in device directory */ |
bb8c093b | 5115 | .attrs = iwl4965_sysfs_entries, |
b481de9c ZY |
5116 | }; |
5117 | ||
bb8c093b CH |
5118 | static struct ieee80211_ops iwl4965_hw_ops = { |
5119 | .tx = iwl4965_mac_tx, | |
5120 | .start = iwl4965_mac_start, | |
5121 | .stop = iwl4965_mac_stop, | |
5122 | .add_interface = iwl4965_mac_add_interface, | |
5123 | .remove_interface = iwl4965_mac_remove_interface, | |
5124 | .config = iwl4965_mac_config, | |
5125 | .config_interface = iwl4965_mac_config_interface, | |
5126 | .configure_filter = iwl4965_configure_filter, | |
5127 | .set_key = iwl4965_mac_set_key, | |
ab885f8c | 5128 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
bb8c093b CH |
5129 | .get_stats = iwl4965_mac_get_stats, |
5130 | .get_tx_stats = iwl4965_mac_get_tx_stats, | |
5131 | .conf_tx = iwl4965_mac_conf_tx, | |
5132 | .get_tsf = iwl4965_mac_get_tsf, | |
5133 | .reset_tsf = iwl4965_mac_reset_tsf, | |
5134 | .beacon_update = iwl4965_mac_beacon_update, | |
471b3efd | 5135 | .bss_info_changed = iwl4965_bss_info_changed, |
9ab46173 | 5136 | .ampdu_action = iwl4965_mac_ampdu_action, |
bb8c093b | 5137 | .hw_scan = iwl4965_mac_hw_scan |
b481de9c ZY |
5138 | }; |
5139 | ||
bb8c093b | 5140 | static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
b481de9c ZY |
5141 | { |
5142 | int err = 0; | |
c79dd5b5 | 5143 | struct iwl_priv *priv; |
b481de9c | 5144 | struct ieee80211_hw *hw; |
82b9a121 | 5145 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
0359facc | 5146 | unsigned long flags; |
5a66926a | 5147 | DECLARE_MAC_BUF(mac); |
b481de9c | 5148 | |
316c30d9 AK |
5149 | /************************ |
5150 | * 1. Allocating HW data | |
5151 | ************************/ | |
5152 | ||
6440adb5 BC |
5153 | /* Disabling hardware scan means that mac80211 will perform scans |
5154 | * "the hard way", rather than using device's scan. */ | |
1ea87396 | 5155 | if (cfg->mod_params->disable_hw_scan) { |
bf403db8 EK |
5156 | if (cfg->mod_params->debug & IWL_DL_INFO) |
5157 | dev_printk(KERN_DEBUG, &(pdev->dev), | |
5158 | "Disabling hw_scan\n"); | |
bb8c093b | 5159 | iwl4965_hw_ops.hw_scan = NULL; |
b481de9c ZY |
5160 | } |
5161 | ||
1d0a082d AK |
5162 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
5163 | if (!hw) { | |
b481de9c ZY |
5164 | err = -ENOMEM; |
5165 | goto out; | |
5166 | } | |
1d0a082d AK |
5167 | priv = hw->priv; |
5168 | /* At this point both hw and priv are allocated. */ | |
5169 | ||
b481de9c ZY |
5170 | SET_IEEE80211_DEV(hw, &pdev->dev); |
5171 | ||
5172 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); | |
82b9a121 | 5173 | priv->cfg = cfg; |
b481de9c | 5174 | priv->pci_dev = pdev; |
316c30d9 | 5175 | |
0a6857e7 | 5176 | #ifdef CONFIG_IWLWIFI_DEBUG |
bf403db8 | 5177 | priv->debug_level = priv->cfg->mod_params->debug; |
b481de9c ZY |
5178 | atomic_set(&priv->restrict_refcnt, 0); |
5179 | #endif | |
b481de9c | 5180 | |
316c30d9 AK |
5181 | /************************** |
5182 | * 2. Initializing PCI bus | |
5183 | **************************/ | |
5184 | if (pci_enable_device(pdev)) { | |
5185 | err = -ENODEV; | |
5186 | goto out_ieee80211_free_hw; | |
5187 | } | |
5188 | ||
5189 | pci_set_master(pdev); | |
5190 | ||
cc2a8ea8 | 5191 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
316c30d9 | 5192 | if (!err) |
cc2a8ea8 RR |
5193 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
5194 | if (err) { | |
5195 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | |
5196 | if (!err) | |
5197 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); | |
5198 | /* both attempts failed: */ | |
316c30d9 | 5199 | if (err) { |
cc2a8ea8 RR |
5200 | printk(KERN_WARNING "%s: No suitable DMA available.\n", |
5201 | DRV_NAME); | |
316c30d9 | 5202 | goto out_pci_disable_device; |
cc2a8ea8 | 5203 | } |
316c30d9 AK |
5204 | } |
5205 | ||
5206 | err = pci_request_regions(pdev, DRV_NAME); | |
5207 | if (err) | |
5208 | goto out_pci_disable_device; | |
5209 | ||
5210 | pci_set_drvdata(pdev, priv); | |
5211 | ||
5212 | /* We disable the RETRY_TIMEOUT register (0x41) to keep | |
5213 | * PCI Tx retries from interfering with C3 CPU state */ | |
5214 | pci_write_config_byte(pdev, 0x41, 0x00); | |
5215 | ||
5216 | /*********************** | |
5217 | * 3. Read REV register | |
5218 | ***********************/ | |
5219 | priv->hw_base = pci_iomap(pdev, 0, 0); | |
5220 | if (!priv->hw_base) { | |
5221 | err = -ENODEV; | |
5222 | goto out_pci_release_regions; | |
5223 | } | |
5224 | ||
5225 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", | |
5226 | (unsigned long long) pci_resource_len(pdev, 0)); | |
5227 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); | |
5228 | ||
b661c819 | 5229 | iwl_hw_detect(priv); |
316c30d9 | 5230 | printk(KERN_INFO DRV_NAME |
b661c819 TW |
5231 | ": Detected Intel Wireless WiFi Link %s REV=0x%X\n", |
5232 | priv->cfg->name, priv->hw_rev); | |
316c30d9 | 5233 | |
91238714 TW |
5234 | /* amp init */ |
5235 | err = priv->cfg->ops->lib->apm_ops.init(priv); | |
316c30d9 | 5236 | if (err < 0) { |
91238714 | 5237 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
316c30d9 AK |
5238 | goto out_iounmap; |
5239 | } | |
91238714 TW |
5240 | /***************** |
5241 | * 4. Read EEPROM | |
5242 | *****************/ | |
316c30d9 AK |
5243 | /* Read the EEPROM */ |
5244 | err = iwl_eeprom_init(priv); | |
5245 | if (err) { | |
5246 | IWL_ERROR("Unable to init EEPROM\n"); | |
5247 | goto out_iounmap; | |
5248 | } | |
8614f360 TW |
5249 | err = iwl_eeprom_check_version(priv); |
5250 | if (err) | |
5251 | goto out_iounmap; | |
5252 | ||
02883017 | 5253 | /* extract MAC Address */ |
316c30d9 AK |
5254 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
5255 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); | |
5256 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); | |
5257 | ||
5258 | /************************ | |
5259 | * 5. Setup HW constants | |
5260 | ************************/ | |
5261 | /* Device-specific setup */ | |
5425e490 TW |
5262 | if (priv->cfg->ops->lib->set_hw_params(priv)) { |
5263 | IWL_ERROR("failed to set hw parameters\n"); | |
073d3f5f | 5264 | goto out_free_eeprom; |
316c30d9 AK |
5265 | } |
5266 | ||
5267 | /******************* | |
6ba87956 | 5268 | * 6. Setup priv |
316c30d9 | 5269 | *******************/ |
b481de9c | 5270 | |
6ba87956 | 5271 | err = iwl_init_drv(priv); |
bf85ea4f | 5272 | if (err) |
399f4900 | 5273 | goto out_free_eeprom; |
bf85ea4f | 5274 | /* At this point both hw and priv are initialized. */ |
316c30d9 AK |
5275 | |
5276 | /********************************** | |
5277 | * 7. Initialize module parameters | |
5278 | **********************************/ | |
5279 | ||
5280 | /* Disable radio (SW RF KILL) via parameter when loading driver */ | |
1ea87396 | 5281 | if (priv->cfg->mod_params->disable) { |
316c30d9 AK |
5282 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
5283 | IWL_DEBUG_INFO("Radio disabled.\n"); | |
5284 | } | |
5285 | ||
316c30d9 AK |
5286 | /******************** |
5287 | * 8. Setup services | |
5288 | ********************/ | |
0359facc | 5289 | spin_lock_irqsave(&priv->lock, flags); |
316c30d9 | 5290 | iwl4965_disable_interrupts(priv); |
0359facc | 5291 | spin_unlock_irqrestore(&priv->lock, flags); |
316c30d9 AK |
5292 | |
5293 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); | |
5294 | if (err) { | |
5295 | IWL_ERROR("failed to create sysfs device attributes\n"); | |
6ba87956 | 5296 | goto out_uninit_drv; |
316c30d9 AK |
5297 | } |
5298 | ||
316c30d9 | 5299 | |
4e39317d | 5300 | iwl_setup_deferred_work(priv); |
316c30d9 AK |
5301 | iwl4965_setup_rx_handlers(priv); |
5302 | ||
5303 | /******************** | |
5304 | * 9. Conclude | |
5305 | ********************/ | |
5a66926a ZY |
5306 | pci_save_state(pdev); |
5307 | pci_disable_device(pdev); | |
b481de9c | 5308 | |
6ba87956 TW |
5309 | /********************************** |
5310 | * 10. Setup and register mac80211 | |
5311 | **********************************/ | |
5312 | ||
5313 | err = iwl_setup_mac(priv); | |
5314 | if (err) | |
5315 | goto out_remove_sysfs; | |
5316 | ||
5317 | err = iwl_dbgfs_register(priv, DRV_NAME); | |
5318 | if (err) | |
5319 | IWL_ERROR("failed to create debugfs files\n"); | |
5320 | ||
c8381fdc MA |
5321 | /* notify iwlcore to init */ |
5322 | iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); | |
b481de9c ZY |
5323 | return 0; |
5324 | ||
316c30d9 AK |
5325 | out_remove_sysfs: |
5326 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); | |
6ba87956 TW |
5327 | out_uninit_drv: |
5328 | iwl_uninit_drv(priv); | |
073d3f5f TW |
5329 | out_free_eeprom: |
5330 | iwl_eeprom_free(priv); | |
b481de9c ZY |
5331 | out_iounmap: |
5332 | pci_iounmap(pdev, priv->hw_base); | |
5333 | out_pci_release_regions: | |
5334 | pci_release_regions(pdev); | |
316c30d9 | 5335 | pci_set_drvdata(pdev, NULL); |
b481de9c ZY |
5336 | out_pci_disable_device: |
5337 | pci_disable_device(pdev); | |
b481de9c ZY |
5338 | out_ieee80211_free_hw: |
5339 | ieee80211_free_hw(priv->hw); | |
5340 | out: | |
5341 | return err; | |
5342 | } | |
5343 | ||
c83dbf68 | 5344 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
b481de9c | 5345 | { |
c79dd5b5 | 5346 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
b481de9c ZY |
5347 | struct list_head *p, *q; |
5348 | int i; | |
0359facc | 5349 | unsigned long flags; |
b481de9c ZY |
5350 | |
5351 | if (!priv) | |
5352 | return; | |
5353 | ||
5354 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); | |
5355 | ||
67249625 EG |
5356 | iwl_dbgfs_unregister(priv); |
5357 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); | |
5358 | ||
c4f55232 RR |
5359 | if (priv->mac80211_registered) { |
5360 | ieee80211_unregister_hw(priv->hw); | |
5361 | priv->mac80211_registered = 0; | |
5362 | } | |
5363 | ||
b481de9c | 5364 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
b24d22b1 | 5365 | |
bb8c093b | 5366 | iwl4965_down(priv); |
b481de9c | 5367 | |
0359facc MA |
5368 | /* make sure we flush any pending irq or |
5369 | * tasklet for the driver | |
5370 | */ | |
5371 | spin_lock_irqsave(&priv->lock, flags); | |
5372 | iwl4965_disable_interrupts(priv); | |
5373 | spin_unlock_irqrestore(&priv->lock, flags); | |
5374 | ||
5375 | iwl_synchronize_irq(priv); | |
5376 | ||
b481de9c ZY |
5377 | /* Free MAC hash list for ADHOC */ |
5378 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { | |
5379 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { | |
5380 | list_del(p); | |
bb8c093b | 5381 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
b481de9c ZY |
5382 | } |
5383 | } | |
5384 | ||
c8381fdc | 5385 | iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); |
b481de9c | 5386 | |
bb8c093b | 5387 | iwl4965_dealloc_ucode_pci(priv); |
b481de9c ZY |
5388 | |
5389 | if (priv->rxq.bd) | |
a55360e4 | 5390 | iwl_rx_queue_free(priv, &priv->rxq); |
1053d35f | 5391 | iwl_hw_txq_ctx_free(priv); |
b481de9c | 5392 | |
bf85ea4f | 5393 | iwlcore_clear_stations_table(priv); |
073d3f5f | 5394 | iwl_eeprom_free(priv); |
b481de9c | 5395 | |
b481de9c | 5396 | |
948c171c MA |
5397 | /*netif_stop_queue(dev); */ |
5398 | flush_workqueue(priv->workqueue); | |
5399 | ||
bb8c093b | 5400 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
b481de9c ZY |
5401 | * priv->workqueue... so we can't take down the workqueue |
5402 | * until now... */ | |
5403 | destroy_workqueue(priv->workqueue); | |
5404 | priv->workqueue = NULL; | |
5405 | ||
b481de9c ZY |
5406 | pci_iounmap(pdev, priv->hw_base); |
5407 | pci_release_regions(pdev); | |
5408 | pci_disable_device(pdev); | |
5409 | pci_set_drvdata(pdev, NULL); | |
5410 | ||
6ba87956 | 5411 | iwl_uninit_drv(priv); |
b481de9c ZY |
5412 | |
5413 | if (priv->ibss_beacon) | |
5414 | dev_kfree_skb(priv->ibss_beacon); | |
5415 | ||
5416 | ieee80211_free_hw(priv->hw); | |
5417 | } | |
5418 | ||
5419 | #ifdef CONFIG_PM | |
5420 | ||
bb8c093b | 5421 | static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
b481de9c | 5422 | { |
c79dd5b5 | 5423 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
b481de9c | 5424 | |
e655b9f0 ZY |
5425 | if (priv->is_open) { |
5426 | set_bit(STATUS_IN_SUSPEND, &priv->status); | |
5427 | iwl4965_mac_stop(priv->hw); | |
5428 | priv->is_open = 1; | |
5429 | } | |
b481de9c | 5430 | |
b481de9c ZY |
5431 | pci_set_power_state(pdev, PCI_D3hot); |
5432 | ||
b481de9c ZY |
5433 | return 0; |
5434 | } | |
5435 | ||
bb8c093b | 5436 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
b481de9c | 5437 | { |
c79dd5b5 | 5438 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
b481de9c | 5439 | |
b481de9c | 5440 | pci_set_power_state(pdev, PCI_D0); |
b481de9c | 5441 | |
e655b9f0 ZY |
5442 | if (priv->is_open) |
5443 | iwl4965_mac_start(priv->hw); | |
b481de9c | 5444 | |
e655b9f0 | 5445 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
b481de9c ZY |
5446 | return 0; |
5447 | } | |
5448 | ||
5449 | #endif /* CONFIG_PM */ | |
5450 | ||
5451 | /***************************************************************************** | |
5452 | * | |
5453 | * driver and module entry point | |
5454 | * | |
5455 | *****************************************************************************/ | |
5456 | ||
fed9017e RR |
5457 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
5458 | static struct pci_device_id iwl_hw_card_ids[] = { | |
5459 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, | |
5460 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, | |
5a6a256e TW |
5461 | #ifdef CONFIG_IWL5000 |
5462 | {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)}, | |
5463 | {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)}, | |
5464 | {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)}, | |
5465 | #endif /* CONFIG_IWL5000 */ | |
fed9017e RR |
5466 | {0} |
5467 | }; | |
5468 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); | |
5469 | ||
5470 | static struct pci_driver iwl_driver = { | |
b481de9c | 5471 | .name = DRV_NAME, |
fed9017e | 5472 | .id_table = iwl_hw_card_ids, |
bb8c093b CH |
5473 | .probe = iwl4965_pci_probe, |
5474 | .remove = __devexit_p(iwl4965_pci_remove), | |
b481de9c | 5475 | #ifdef CONFIG_PM |
bb8c093b CH |
5476 | .suspend = iwl4965_pci_suspend, |
5477 | .resume = iwl4965_pci_resume, | |
b481de9c ZY |
5478 | #endif |
5479 | }; | |
5480 | ||
bb8c093b | 5481 | static int __init iwl4965_init(void) |
b481de9c ZY |
5482 | { |
5483 | ||
5484 | int ret; | |
5485 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); | |
5486 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); | |
897e1cf2 RC |
5487 | |
5488 | ret = iwl4965_rate_control_register(); | |
5489 | if (ret) { | |
5490 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); | |
5491 | return ret; | |
5492 | } | |
5493 | ||
fed9017e | 5494 | ret = pci_register_driver(&iwl_driver); |
b481de9c ZY |
5495 | if (ret) { |
5496 | IWL_ERROR("Unable to initialize PCI module\n"); | |
897e1cf2 | 5497 | goto error_register; |
b481de9c | 5498 | } |
b481de9c ZY |
5499 | |
5500 | return ret; | |
897e1cf2 | 5501 | |
897e1cf2 RC |
5502 | error_register: |
5503 | iwl4965_rate_control_unregister(); | |
5504 | return ret; | |
b481de9c ZY |
5505 | } |
5506 | ||
bb8c093b | 5507 | static void __exit iwl4965_exit(void) |
b481de9c | 5508 | { |
fed9017e | 5509 | pci_unregister_driver(&iwl_driver); |
897e1cf2 | 5510 | iwl4965_rate_control_unregister(); |
b481de9c ZY |
5511 | } |
5512 | ||
bb8c093b CH |
5513 | module_exit(iwl4965_exit); |
5514 | module_init(iwl4965_init); |