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