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