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