1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
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.
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
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
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
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
28 *****************************************************************************/
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>
44 #include <net/mac80211.h>
46 #include <asm/div64.h>
48 #include "iwl-eeprom.h"
52 #include "iwl-helpers.h"
54 #include "iwl-calib.h"
57 /******************************************************************************
61 ******************************************************************************/
64 * module name, copyright, version, etc.
65 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
68 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
70 #ifdef CONFIG_IWLWIFI_DEBUG
76 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
82 #define DRV_VERSION IWLWIFI_VERSION VD VS
85 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
86 MODULE_VERSION(DRV_VERSION
);
87 MODULE_AUTHOR(DRV_COPYRIGHT
);
88 MODULE_LICENSE("GPL");
90 static int iwl4965_is_empty_essid(const char *essid
, int essid_len
)
92 /* Single white space is for Linksys APs */
93 if (essid_len
== 1 && essid
[0] == ' ')
96 /* Otherwise, if the entire essid is 0, we assume it is hidden */
99 if (essid
[essid_len
] != '\0')
106 static const char *iwl4965_escape_essid(const char *essid
, u8 essid_len
)
108 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
109 const char *s
= essid
;
112 if (iwl4965_is_empty_essid(essid
, essid_len
)) {
113 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
117 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
118 while (essid_len
--) {
130 /*************** STATION TABLE MANAGEMENT ****
131 * mac80211 should be examined to determine if sta_info is duplicating
132 * the functionality provided here
135 /**************************************************************/
139 static void iwl4965_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
141 struct iwl_rxon_cmd
*rxon
= &priv
->staging_rxon
;
144 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
146 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
151 * iwl4965_check_rxon_cmd - validate RXON structure is valid
153 * NOTE: This is really only useful during development and can eventually
154 * be #ifdef'd out once the driver is stable and folks aren't actively
157 static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd
*rxon
)
162 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
163 error
|= le32_to_cpu(rxon
->flags
&
164 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
165 RXON_FLG_RADAR_DETECT_MSK
));
167 IWL_WARNING("check 24G fields %d | %d\n",
170 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
171 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
173 IWL_WARNING("check 52 fields %d | %d\n",
175 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
177 IWL_WARNING("check 52 CCK %d | %d\n",
180 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
182 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
184 /* make sure basic rates 6Mbps and 1Mbps are supported */
185 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
186 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
188 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
190 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
192 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
194 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
195 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
197 IWL_WARNING("check CCK and short slot %d | %d\n",
200 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
201 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
203 IWL_WARNING("check CCK & auto detect %d | %d\n",
206 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
207 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
209 IWL_WARNING("check TGG and auto detect %d | %d\n",
213 IWL_WARNING("Tuning to channel %d\n",
214 le16_to_cpu(rxon
->channel
));
217 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
224 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
225 * @priv: staging_rxon is compared to active_rxon
227 * If the RXON structure is changing enough to require a new tune,
228 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
229 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
231 static int iwl4965_full_rxon_required(struct iwl_priv
*priv
)
234 /* These items are only settable from the full RXON command */
235 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
236 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
237 priv
->active_rxon
.bssid_addr
) ||
238 compare_ether_addr(priv
->staging_rxon
.node_addr
,
239 priv
->active_rxon
.node_addr
) ||
240 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
241 priv
->active_rxon
.wlap_bssid_addr
) ||
242 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
243 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
244 (priv
->staging_rxon
.air_propagation
!=
245 priv
->active_rxon
.air_propagation
) ||
246 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
247 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
248 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
249 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
250 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
251 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
254 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
255 * be updated with the RXON_ASSOC command -- however only some
256 * flag transitions are allowed using RXON_ASSOC */
258 /* Check if we are not switching bands */
259 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
260 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
263 /* Check if we are switching association toggle */
264 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
265 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
272 * iwl4965_commit_rxon - commit staging_rxon to hardware
274 * The RXON command in staging_rxon is committed to the hardware and
275 * the active_rxon structure is updated with the new data. This
276 * function correctly transitions out of the RXON_ASSOC_MSK state if
277 * a HW tune is required based on the RXON structure changes.
279 static int iwl4965_commit_rxon(struct iwl_priv
*priv
)
281 /* cast away the const for active_rxon in this function */
282 struct iwl_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
283 DECLARE_MAC_BUF(mac
);
286 if (!iwl_is_alive(priv
))
289 /* always get timestamp with Rx frame */
290 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
292 rc
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
294 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
298 /* If we don't need to send a full RXON, we can use
299 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
300 * and other flags for the current radio configuration. */
301 if (!iwl4965_full_rxon_required(priv
)) {
302 rc
= iwl_send_rxon_assoc(priv
);
304 IWL_ERROR("Error setting RXON_ASSOC "
305 "configuration (%d).\n", rc
);
309 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
314 /* station table will be cleared */
315 priv
->assoc_station_added
= 0;
317 /* If we are currently associated and the new config requires
318 * an RXON_ASSOC and the new config wants the associated mask enabled,
319 * we must clear the associated from the active configuration
320 * before we apply the new config */
321 if (iwl_is_associated(priv
) &&
322 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
323 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
324 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
326 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
327 sizeof(struct iwl_rxon_cmd
),
330 /* If the mask clearing failed then we set
331 * active_rxon back to what it was previously */
333 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
334 IWL_ERROR("Error clearing ASSOC_MSK on current "
335 "configuration (%d).\n", rc
);
340 IWL_DEBUG_INFO("Sending RXON\n"
341 "* with%s RXON_FILTER_ASSOC_MSK\n"
344 ((priv
->staging_rxon
.filter_flags
&
345 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
346 le16_to_cpu(priv
->staging_rxon
.channel
),
347 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
349 iwl4965_set_rxon_hwcrypto(priv
, !priv
->hw_params
.sw_crypto
);
350 /* Apply the new configuration */
351 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
352 sizeof(struct iwl_rxon_cmd
), &priv
->staging_rxon
);
354 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
358 iwl_remove_station(priv
, iwl_bcast_addr
, 0);
359 iwlcore_clear_stations_table(priv
);
361 if (!priv
->error_recovering
)
362 priv
->start_calib
= 0;
364 iwl_init_sensitivity(priv
);
366 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
368 /* If we issue a new RXON command which required a tune then we must
369 * send a new TXPOWER command or we won't be able to Tx any frames */
370 rc
= iwl4965_hw_reg_send_txpower(priv
);
372 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
376 /* Add the broadcast address so we can send broadcast frames */
377 if (iwl_rxon_add_station(priv
, iwl_bcast_addr
, 0) ==
378 IWL_INVALID_STATION
) {
379 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
383 /* If we have set the ASSOC_MSK and we are in BSS mode then
384 * add the IWL_AP_ID to the station rate table */
385 if (iwl_is_associated(priv
) &&
386 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
387 if (iwl_rxon_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1)
388 == IWL_INVALID_STATION
) {
389 IWL_ERROR("Error adding AP address for transmit.\n");
392 priv
->assoc_station_added
= 1;
393 if (priv
->default_wep_key
&&
394 iwl_send_static_wepkey_cmd(priv
, 0))
395 IWL_ERROR("Could not send WEP static key.\n");
401 void iwl4965_update_chain_flags(struct iwl_priv
*priv
)
404 iwl_set_rxon_chain(priv
);
405 iwl4965_commit_rxon(priv
);
408 static int iwl4965_send_bt_config(struct iwl_priv
*priv
)
410 struct iwl4965_bt_cmd bt_cmd
= {
418 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
419 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
422 static int iwl4965_send_scan_abort(struct iwl_priv
*priv
)
425 struct iwl_rx_packet
*res
;
426 struct iwl_host_cmd cmd
= {
427 .id
= REPLY_SCAN_ABORT_CMD
,
428 .meta
.flags
= CMD_WANT_SKB
,
431 /* If there isn't a scan actively going on in the hardware
432 * then we are in between scan bands and not actually
433 * actively scanning, so don't send the abort command */
434 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
435 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
439 ret
= iwl_send_cmd_sync(priv
, &cmd
);
441 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
445 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
446 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
447 /* The scan abort will return 1 for success or
448 * 2 for "failure". A failure condition can be
449 * due to simply not being in an active scan which
450 * can occur if we send the scan abort before we
451 * the microcode has notified us that a scan is
453 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
454 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
455 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
458 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
466 * Use: Sets the device's internal card state to enable, disable, or halt
468 * When in the 'enable' state the card operates as normal.
469 * When in the 'disable' state, the card enters into a low power mode.
470 * When in the 'halt' state, the card is shut down and must be fully
471 * restarted to come back on.
473 static int iwl4965_send_card_state(struct iwl_priv
*priv
, u32 flags
, u8 meta_flag
)
475 struct iwl_host_cmd cmd
= {
476 .id
= REPLY_CARD_STATE_CMD
,
479 .meta
.flags
= meta_flag
,
482 return iwl_send_cmd(priv
, &cmd
);
485 static void iwl_clear_free_frames(struct iwl_priv
*priv
)
487 struct list_head
*element
;
489 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
492 while (!list_empty(&priv
->free_frames
)) {
493 element
= priv
->free_frames
.next
;
495 kfree(list_entry(element
, struct iwl_frame
, list
));
496 priv
->frames_count
--;
499 if (priv
->frames_count
) {
500 IWL_WARNING("%d frames still in use. Did we lose one?\n",
502 priv
->frames_count
= 0;
506 static struct iwl_frame
*iwl_get_free_frame(struct iwl_priv
*priv
)
508 struct iwl_frame
*frame
;
509 struct list_head
*element
;
510 if (list_empty(&priv
->free_frames
)) {
511 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
513 IWL_ERROR("Could not allocate frame!\n");
517 priv
->frames_count
++;
521 element
= priv
->free_frames
.next
;
523 return list_entry(element
, struct iwl_frame
, list
);
526 static void iwl_free_frame(struct iwl_priv
*priv
, struct iwl_frame
*frame
)
528 memset(frame
, 0, sizeof(*frame
));
529 list_add(&frame
->list
, &priv
->free_frames
);
532 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv
*priv
,
533 struct ieee80211_hdr
*hdr
,
534 const u8
*dest
, int left
)
537 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
538 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
539 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
542 if (priv
->ibss_beacon
->len
> left
)
545 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
547 return priv
->ibss_beacon
->len
;
550 static u8
iwl4965_rate_get_lowest_plcp(struct iwl_priv
*priv
)
556 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
557 rate_mask
= priv
->active_rate_basic
& 0xF;
559 rate_mask
= priv
->active_rate_basic
& 0xFF0;
561 /* Find lowest valid rate */
562 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
563 i
= iwl_rates
[i
].next_ieee
) {
564 if (rate_mask
& (1 << i
))
565 return iwl_rates
[i
].plcp
;
568 /* No valid rate was found. Assign the lowest one */
569 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
570 return IWL_RATE_1M_PLCP
;
572 return IWL_RATE_6M_PLCP
;
575 static int iwl4965_send_beacon_cmd(struct iwl_priv
*priv
)
577 struct iwl_frame
*frame
;
578 unsigned int frame_size
;
582 frame
= iwl_get_free_frame(priv
);
585 IWL_ERROR("Could not obtain free frame buffer for beacon "
590 rate
= iwl4965_rate_get_lowest_plcp(priv
);
592 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
594 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
597 iwl_free_frame(priv
, frame
);
602 /******************************************************************************
604 * Misc. internal state and helper functions
606 ******************************************************************************/
609 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
611 * return : set the bit for each supported rate insert in ie
613 static u16
iwl4965_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
614 u16 basic_rate
, int *left
)
616 u16 ret_rates
= 0, bit
;
621 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
622 if (bit
& supported_rate
) {
624 rates
[*cnt
] = iwl_rates
[i
].ieee
|
625 ((bit
& basic_rate
) ? 0x80 : 0x00);
629 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
637 static void iwl4965_ht_conf(struct iwl_priv
*priv
,
638 struct ieee80211_bss_conf
*bss_conf
)
640 struct ieee80211_ht_info
*ht_conf
= bss_conf
->ht_conf
;
641 struct ieee80211_ht_bss_info
*ht_bss_conf
= bss_conf
->ht_bss_conf
;
642 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
644 IWL_DEBUG_MAC80211("enter: \n");
646 iwl_conf
->is_ht
= bss_conf
->assoc_ht
;
648 if (!iwl_conf
->is_ht
)
651 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
653 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
654 iwl_conf
->sgf
|= HT_SHORT_GI_20MHZ
;
655 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
656 iwl_conf
->sgf
|= HT_SHORT_GI_40MHZ
;
658 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
659 iwl_conf
->max_amsdu_size
=
660 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
662 iwl_conf
->supported_chan_width
=
663 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
664 iwl_conf
->extension_chan_offset
=
665 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
666 /* If no above or below channel supplied disable FAT channel */
667 if (iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_ABOVE
&&
668 iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_BELOW
)
669 iwl_conf
->supported_chan_width
= 0;
671 iwl_conf
->tx_mimo_ps_mode
=
672 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
673 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
675 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
676 iwl_conf
->tx_chan_width
=
677 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
678 iwl_conf
->ht_protection
=
679 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
680 iwl_conf
->non_GF_STA_present
=
681 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
683 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf
->control_channel
);
684 IWL_DEBUG_MAC80211("leave\n");
687 static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band
*sband
,
690 struct ieee80211_ht_cap
*ht_cap
;
692 if (!sband
|| !sband
->ht_info
.ht_supported
)
695 if (*left
< sizeof(struct ieee80211_ht_cap
))
698 *pos
++ = sizeof(struct ieee80211_ht_cap
);
699 ht_cap
= (struct ieee80211_ht_cap
*) pos
;
701 ht_cap
->cap_info
= cpu_to_le16(sband
->ht_info
.cap
);
702 memcpy(ht_cap
->supp_mcs_set
, sband
->ht_info
.supp_mcs_set
, 16);
703 ht_cap
->ampdu_params_info
=
704 (sband
->ht_info
.ampdu_factor
& IEEE80211_HT_CAP_AMPDU_FACTOR
) |
705 ((sband
->ht_info
.ampdu_density
<< 2) &
706 IEEE80211_HT_CAP_AMPDU_DENSITY
);
707 *left
-= sizeof(struct ieee80211_ht_cap
);
711 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
713 static u16
iwl4965_fill_probe_req(struct iwl_priv
*priv
,
714 enum ieee80211_band band
,
715 struct ieee80211_mgmt
*frame
,
716 int left
, int is_direct
)
720 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
721 const struct ieee80211_supported_band
*sband
=
722 iwl_get_hw_mode(priv
, band
);
724 /* Make sure there is enough space for the probe request,
725 * two mandatory IEs and the data */
731 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
732 memcpy(frame
->da
, iwl_bcast_addr
, ETH_ALEN
);
733 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
734 memcpy(frame
->bssid
, iwl_bcast_addr
, ETH_ALEN
);
737 /* fill in our indirect SSID IE */
744 pos
= &(frame
->u
.probe_req
.variable
[0]);
745 *pos
++ = WLAN_EID_SSID
;
748 /* fill in our direct SSID IE... */
751 left
-= 2 + priv
->essid_len
;
754 /* ... fill it in... */
755 *pos
++ = WLAN_EID_SSID
;
756 *pos
++ = priv
->essid_len
;
757 memcpy(pos
, priv
->essid
, priv
->essid_len
);
758 pos
+= priv
->essid_len
;
759 len
+= 2 + priv
->essid_len
;
762 /* fill in supported rate */
768 /* ... fill it in... */
769 *pos
++ = WLAN_EID_SUPP_RATES
;
772 /* exclude 60M rate */
773 active_rates
= priv
->rates_mask
;
774 active_rates
&= ~IWL_RATE_60M_MASK
;
776 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
778 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
779 ret_rates
= iwl4965_supported_rate_to_ie(pos
, cck_rates
,
780 active_rate_basic
, &left
);
781 active_rates
&= ~ret_rates
;
783 ret_rates
= iwl4965_supported_rate_to_ie(pos
, active_rates
,
784 active_rate_basic
, &left
);
785 active_rates
&= ~ret_rates
;
789 if (active_rates
== 0)
792 /* fill in supported extended rate */
797 /* ... fill it in... */
798 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
800 iwl4965_supported_rate_to_ie(pos
, active_rates
,
801 active_rate_basic
, &left
);
811 *pos
++ = WLAN_EID_HT_CAPABILITY
;
814 iwl_ht_cap_to_ie(sband
, pos
, &left
);
824 static int iwl4965_send_qos_params_command(struct iwl_priv
*priv
,
825 struct iwl4965_qosparam_cmd
*qos
)
828 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
829 sizeof(struct iwl4965_qosparam_cmd
), qos
);
832 static void iwl4965_activate_qos(struct iwl_priv
*priv
, u8 force
)
836 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
839 if (!priv
->qos_data
.qos_enable
)
842 spin_lock_irqsave(&priv
->lock
, flags
);
843 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
845 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
846 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
847 priv
->qos_data
.def_qos_parm
.qos_flags
|=
848 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
849 if (priv
->qos_data
.qos_active
)
850 priv
->qos_data
.def_qos_parm
.qos_flags
|=
851 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
853 if (priv
->current_ht_config
.is_ht
)
854 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
856 spin_unlock_irqrestore(&priv
->lock
, flags
);
858 if (force
|| iwl_is_associated(priv
)) {
859 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
860 priv
->qos_data
.qos_active
,
861 priv
->qos_data
.def_qos_parm
.qos_flags
);
863 iwl4965_send_qos_params_command(priv
,
864 &(priv
->qos_data
.def_qos_parm
));
868 int iwl4965_is_network_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
870 /* Filter incoming packets to determine if they are targeted toward
871 * this network, discarding packets coming from ourselves */
872 switch (priv
->iw_mode
) {
873 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
874 /* packets from our adapter are dropped (echo) */
875 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
877 /* {broad,multi}cast packets to our IBSS go through */
878 if (is_multicast_ether_addr(header
->addr1
))
879 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
880 /* packets to our adapter go through */
881 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
882 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
883 /* packets from our adapter are dropped (echo) */
884 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
886 /* {broad,multi}cast packets to our BSS go through */
887 if (is_multicast_ether_addr(header
->addr1
))
888 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
889 /* packets to our adapter go through */
890 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
901 * iwl4965_scan_cancel - Cancel any currently executing HW scan
903 * NOTE: priv->mutex is not required before calling this function
905 static int iwl4965_scan_cancel(struct iwl_priv
*priv
)
907 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
908 clear_bit(STATUS_SCANNING
, &priv
->status
);
912 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
913 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
914 IWL_DEBUG_SCAN("Queuing scan abort.\n");
915 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
916 queue_work(priv
->workqueue
, &priv
->abort_scan
);
919 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
921 return test_bit(STATUS_SCANNING
, &priv
->status
);
928 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
929 * @ms: amount of time to wait (in milliseconds) for scan to abort
931 * NOTE: priv->mutex must be held before calling this function
933 static int iwl4965_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
935 unsigned long now
= jiffies
;
938 ret
= iwl4965_scan_cancel(priv
);
940 mutex_unlock(&priv
->mutex
);
941 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
942 test_bit(STATUS_SCANNING
, &priv
->status
))
944 mutex_lock(&priv
->mutex
);
946 return test_bit(STATUS_SCANNING
, &priv
->status
);
952 static void iwl4965_sequence_reset(struct iwl_priv
*priv
)
954 /* Reset ieee stats */
956 /* We don't reset the net_device_stats (ieee->stats) on
959 priv
->last_seq_num
= -1;
960 priv
->last_frag_num
= -1;
961 priv
->last_packet_time
= 0;
963 iwl4965_scan_cancel(priv
);
966 #define MAX_UCODE_BEACON_INTERVAL 4096
967 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
969 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
972 u16 beacon_factor
= 0;
975 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
976 / MAX_UCODE_BEACON_INTERVAL
;
977 new_val
= beacon_val
/ beacon_factor
;
979 return cpu_to_le16(new_val
);
982 static void iwl4965_setup_rxon_timing(struct iwl_priv
*priv
)
984 u64 interval_tm_unit
;
987 struct ieee80211_conf
*conf
= NULL
;
990 conf
= ieee80211_get_hw_conf(priv
->hw
);
992 spin_lock_irqsave(&priv
->lock
, flags
);
993 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp
>> 32);
994 priv
->rxon_timing
.timestamp
.dw
[0] =
995 cpu_to_le32(priv
->timestamp
& 0xFFFFFFFF);
997 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
999 tsf
= priv
->timestamp
;
1001 beacon_int
= priv
->beacon_int
;
1002 spin_unlock_irqrestore(&priv
->lock
, flags
);
1004 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
1005 if (beacon_int
== 0) {
1006 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
1007 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
1009 priv
->rxon_timing
.beacon_interval
=
1010 cpu_to_le16(beacon_int
);
1011 priv
->rxon_timing
.beacon_interval
=
1012 iwl4965_adjust_beacon_interval(
1013 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1016 priv
->rxon_timing
.atim_window
= 0;
1018 priv
->rxon_timing
.beacon_interval
=
1019 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
1020 /* TODO: we need to get atim_window from upper stack
1021 * for now we set to 0 */
1022 priv
->rxon_timing
.atim_window
= 0;
1026 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
1027 result
= do_div(tsf
, interval_tm_unit
);
1028 priv
->rxon_timing
.beacon_init_val
=
1029 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
1032 ("beacon interval %d beacon timer %d beacon tim %d\n",
1033 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
1034 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
1035 le16_to_cpu(priv
->rxon_timing
.atim_window
));
1038 static int iwl4965_scan_initiate(struct iwl_priv
*priv
)
1040 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1041 IWL_ERROR("APs don't scan.\n");
1045 if (!iwl_is_ready_rf(priv
)) {
1046 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1050 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1051 IWL_DEBUG_SCAN("Scan already in progress.\n");
1055 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1056 IWL_DEBUG_SCAN("Scan request while abort pending. "
1061 IWL_DEBUG_INFO("Starting scan...\n");
1062 priv
->scan_bands
= 2;
1063 set_bit(STATUS_SCANNING
, &priv
->status
);
1064 priv
->scan_start
= jiffies
;
1065 priv
->scan_pass_start
= priv
->scan_start
;
1067 queue_work(priv
->workqueue
, &priv
->request_scan
);
1073 static void iwl_set_flags_for_band(struct iwl_priv
*priv
,
1074 enum ieee80211_band band
)
1076 if (band
== IEEE80211_BAND_5GHZ
) {
1077 priv
->staging_rxon
.flags
&=
1078 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
1079 | RXON_FLG_CCK_MSK
);
1080 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1082 /* Copied from iwl4965_post_associate() */
1083 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
1084 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1086 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1088 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
1089 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1091 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
1092 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
1093 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
1098 * initialize rxon structure with default values from eeprom
1100 static void iwl4965_connection_init_rx_config(struct iwl_priv
*priv
)
1102 const struct iwl_channel_info
*ch_info
;
1104 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
1106 switch (priv
->iw_mode
) {
1107 case IEEE80211_IF_TYPE_AP
:
1108 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
1111 case IEEE80211_IF_TYPE_STA
:
1112 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
1113 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
1116 case IEEE80211_IF_TYPE_IBSS
:
1117 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
1118 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
1119 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
1120 RXON_FILTER_ACCEPT_GRP_MSK
;
1123 case IEEE80211_IF_TYPE_MNTR
:
1124 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
1125 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
1126 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
1129 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
1134 /* TODO: Figure out when short_preamble would be set and cache from
1136 if (!hw_to_local(priv
->hw
)->short_preamble
)
1137 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1139 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1142 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
1143 le16_to_cpu(priv
->staging_rxon
.channel
));
1146 ch_info
= &priv
->channel_info
[0];
1149 * in some case A channels are all non IBSS
1150 * in this case force B/G channel
1152 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
1153 !(is_channel_ibss(ch_info
)))
1154 ch_info
= &priv
->channel_info
[0];
1156 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
1157 priv
->band
= ch_info
->band
;
1159 iwl_set_flags_for_band(priv
, priv
->band
);
1161 priv
->staging_rxon
.ofdm_basic_rates
=
1162 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
1163 priv
->staging_rxon
.cck_basic_rates
=
1164 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
1166 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
1167 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
1168 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1169 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
1170 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
1171 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
1172 iwl_set_rxon_chain(priv
);
1175 static int iwl4965_set_mode(struct iwl_priv
*priv
, int mode
)
1177 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
1178 const struct iwl_channel_info
*ch_info
;
1180 ch_info
= iwl_get_channel_info(priv
,
1182 le16_to_cpu(priv
->staging_rxon
.channel
));
1184 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
1185 IWL_ERROR("channel %d not IBSS channel\n",
1186 le16_to_cpu(priv
->staging_rxon
.channel
));
1191 priv
->iw_mode
= mode
;
1193 iwl4965_connection_init_rx_config(priv
);
1194 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1196 iwlcore_clear_stations_table(priv
);
1198 /* dont commit rxon if rf-kill is on*/
1199 if (!iwl_is_ready_rf(priv
))
1202 cancel_delayed_work(&priv
->scan_check
);
1203 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
1204 IWL_WARNING("Aborted scan still in progress after 100ms\n");
1205 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1209 iwl4965_commit_rxon(priv
);
1214 static void iwl4965_set_rate(struct iwl_priv
*priv
)
1216 const struct ieee80211_supported_band
*hw
= NULL
;
1217 struct ieee80211_rate
*rate
;
1220 hw
= iwl_get_hw_mode(priv
, priv
->band
);
1222 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
1226 priv
->active_rate
= 0;
1227 priv
->active_rate_basic
= 0;
1229 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
1230 rate
= &(hw
->bitrates
[i
]);
1231 if (rate
->hw_value
< IWL_RATE_COUNT
)
1232 priv
->active_rate
|= (1 << rate
->hw_value
);
1235 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
1236 priv
->active_rate
, priv
->active_rate_basic
);
1239 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
1240 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
1243 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
1244 priv
->staging_rxon
.cck_basic_rates
=
1245 ((priv
->active_rate_basic
&
1246 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
1248 priv
->staging_rxon
.cck_basic_rates
=
1249 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
1251 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
1252 priv
->staging_rxon
.ofdm_basic_rates
=
1253 ((priv
->active_rate_basic
&
1254 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
1255 IWL_FIRST_OFDM_RATE
) & 0xFF;
1257 priv
->staging_rxon
.ofdm_basic_rates
=
1258 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
1261 void iwl4965_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
1263 unsigned long flags
;
1265 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
1268 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
1269 disable_radio
? "OFF" : "ON");
1271 if (disable_radio
) {
1272 iwl4965_scan_cancel(priv
);
1273 /* FIXME: This is a workaround for AP */
1274 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
1275 spin_lock_irqsave(&priv
->lock
, flags
);
1276 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
1277 CSR_UCODE_SW_BIT_RFKILL
);
1278 spin_unlock_irqrestore(&priv
->lock
, flags
);
1279 /* call the host command only if no hw rf-kill set */
1280 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
) &&
1282 iwl4965_send_card_state(priv
,
1283 CARD_STATE_CMD_DISABLE
,
1285 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
1287 /* make sure mac80211 stop sending Tx frame */
1288 if (priv
->mac80211_registered
)
1289 ieee80211_stop_queues(priv
->hw
);
1294 spin_lock_irqsave(&priv
->lock
, flags
);
1295 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
1297 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
1298 spin_unlock_irqrestore(&priv
->lock
, flags
);
1303 spin_lock_irqsave(&priv
->lock
, flags
);
1304 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
1305 if (!iwl_grab_nic_access(priv
))
1306 iwl_release_nic_access(priv
);
1307 spin_unlock_irqrestore(&priv
->lock
, flags
);
1309 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
1310 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
1311 "disabled by HW switch\n");
1315 queue_work(priv
->workqueue
, &priv
->restart
);
1319 #define IWL_PACKET_RETRY_TIME HZ
1321 int iwl4965_is_duplicate_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
1323 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
1324 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
1325 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
1326 u16
*last_seq
, *last_frag
;
1327 unsigned long *last_time
;
1329 switch (priv
->iw_mode
) {
1330 case IEEE80211_IF_TYPE_IBSS
:{
1331 struct list_head
*p
;
1332 struct iwl4965_ibss_seq
*entry
= NULL
;
1333 u8
*mac
= header
->addr2
;
1334 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
1336 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
1337 entry
= list_entry(p
, struct iwl4965_ibss_seq
, list
);
1338 if (!compare_ether_addr(entry
->mac
, mac
))
1341 if (p
== &priv
->ibss_mac_hash
[index
]) {
1342 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
1344 IWL_ERROR("Cannot malloc new mac entry\n");
1347 memcpy(entry
->mac
, mac
, ETH_ALEN
);
1348 entry
->seq_num
= seq
;
1349 entry
->frag_num
= frag
;
1350 entry
->packet_time
= jiffies
;
1351 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
1354 last_seq
= &entry
->seq_num
;
1355 last_frag
= &entry
->frag_num
;
1356 last_time
= &entry
->packet_time
;
1359 case IEEE80211_IF_TYPE_STA
:
1360 last_seq
= &priv
->last_seq_num
;
1361 last_frag
= &priv
->last_frag_num
;
1362 last_time
= &priv
->last_packet_time
;
1367 if ((*last_seq
== seq
) &&
1368 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
1369 if (*last_frag
== frag
)
1371 if (*last_frag
+ 1 != frag
)
1372 /* out-of-order fragment */
1378 *last_time
= jiffies
;
1385 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
1387 #include "iwl-spectrum.h"
1389 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
1390 #define BEACON_TIME_MASK_HIGH 0xFF000000
1391 #define TIME_UNIT 1024
1394 * extended beacon time format
1395 * time in usec will be changed into a 32-bit value in 8:24 format
1396 * the high 1 byte is the beacon counts
1397 * the lower 3 bytes is the time in usec within one beacon interval
1400 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
1404 u32 interval
= beacon_interval
* 1024;
1406 if (!interval
|| !usec
)
1409 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
1410 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
1412 return (quot
<< 24) + rem
;
1415 /* base is usually what we get from ucode with each received frame,
1416 * the same as HW timer counter counting down
1419 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
1421 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
1422 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
1423 u32 interval
= beacon_interval
* TIME_UNIT
;
1424 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
1425 (addon
& BEACON_TIME_MASK_HIGH
);
1427 if (base_low
> addon_low
)
1428 res
+= base_low
- addon_low
;
1429 else if (base_low
< addon_low
) {
1430 res
+= interval
+ base_low
- addon_low
;
1435 return cpu_to_le32(res
);
1438 static int iwl4965_get_measurement(struct iwl_priv
*priv
,
1439 struct ieee80211_measurement_params
*params
,
1442 struct iwl4965_spectrum_cmd spectrum
;
1443 struct iwl_rx_packet
*res
;
1444 struct iwl_host_cmd cmd
= {
1445 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
1446 .data
= (void *)&spectrum
,
1447 .meta
.flags
= CMD_WANT_SKB
,
1449 u32 add_time
= le64_to_cpu(params
->start_time
);
1451 int spectrum_resp_status
;
1452 int duration
= le16_to_cpu(params
->duration
);
1454 if (iwl_is_associated(priv
))
1456 iwl4965_usecs_to_beacons(
1457 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
1458 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1460 memset(&spectrum
, 0, sizeof(spectrum
));
1462 spectrum
.channel_count
= cpu_to_le16(1);
1464 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
1465 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
1466 cmd
.len
= sizeof(spectrum
);
1467 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
1469 if (iwl_is_associated(priv
))
1470 spectrum
.start_time
=
1471 iwl4965_add_beacon_time(priv
->last_beacon_time
,
1473 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1475 spectrum
.start_time
= 0;
1477 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
1478 spectrum
.channels
[0].channel
= params
->channel
;
1479 spectrum
.channels
[0].type
= type
;
1480 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
1481 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
1482 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
1484 rc
= iwl_send_cmd_sync(priv
, &cmd
);
1488 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1489 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1490 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
1494 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
1495 switch (spectrum_resp_status
) {
1496 case 0: /* Command will be handled */
1497 if (res
->u
.spectrum
.id
!= 0xff) {
1499 ("Replaced existing measurement: %d\n",
1500 res
->u
.spectrum
.id
);
1501 priv
->measurement_status
&= ~MEASUREMENT_READY
;
1503 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
1507 case 1: /* Command will not be handled */
1512 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1518 /******************************************************************************
1520 * Generic RX handler implementations
1522 ******************************************************************************/
1523 static void iwl_rx_reply_alive(struct iwl_priv
*priv
,
1524 struct iwl_rx_mem_buffer
*rxb
)
1526 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1527 struct iwl_alive_resp
*palive
;
1528 struct delayed_work
*pwork
;
1530 palive
= &pkt
->u
.alive_frame
;
1532 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1534 palive
->is_valid
, palive
->ver_type
,
1535 palive
->ver_subtype
);
1537 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
1538 IWL_DEBUG_INFO("Initialization Alive received.\n");
1539 memcpy(&priv
->card_alive_init
,
1540 &pkt
->u
.alive_frame
,
1541 sizeof(struct iwl_init_alive_resp
));
1542 pwork
= &priv
->init_alive_start
;
1544 IWL_DEBUG_INFO("Runtime Alive received.\n");
1545 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
1546 sizeof(struct iwl_alive_resp
));
1547 pwork
= &priv
->alive_start
;
1550 /* We delay the ALIVE response by 5ms to
1551 * give the HW RF Kill time to activate... */
1552 if (palive
->is_valid
== UCODE_VALID_OK
)
1553 queue_delayed_work(priv
->workqueue
, pwork
,
1554 msecs_to_jiffies(5));
1556 IWL_WARNING("uCode did not respond OK.\n");
1559 static void iwl4965_rx_reply_error(struct iwl_priv
*priv
,
1560 struct iwl_rx_mem_buffer
*rxb
)
1562 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1564 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1565 "seq 0x%04X ser 0x%08X\n",
1566 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
1567 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
1568 pkt
->u
.err_resp
.cmd_id
,
1569 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
1570 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
1573 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1575 static void iwl4965_rx_csa(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
)
1577 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1578 struct iwl_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
1579 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
1580 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1581 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
1582 rxon
->channel
= csa
->channel
;
1583 priv
->staging_rxon
.channel
= csa
->channel
;
1586 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
1587 struct iwl_rx_mem_buffer
*rxb
)
1589 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
1590 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1591 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
1593 if (!report
->state
) {
1594 IWL_DEBUG(IWL_DL_11H
,
1595 "Spectrum Measure Notification: Start\n");
1599 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
1600 priv
->measurement_status
|= MEASUREMENT_READY
;
1604 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv
*priv
,
1605 struct iwl_rx_mem_buffer
*rxb
)
1607 #ifdef CONFIG_IWLWIFI_DEBUG
1608 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1609 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
1610 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1611 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
1615 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
1616 struct iwl_rx_mem_buffer
*rxb
)
1618 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1619 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1620 "notification for %s:\n",
1621 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
1622 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
1625 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
1627 struct iwl_priv
*priv
=
1628 container_of(work
, struct iwl_priv
, beacon_update
);
1629 struct sk_buff
*beacon
;
1631 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
1632 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
);
1635 IWL_ERROR("update beacon failed\n");
1639 mutex_lock(&priv
->mutex
);
1640 /* new beacon skb is allocated every time; dispose previous.*/
1641 if (priv
->ibss_beacon
)
1642 dev_kfree_skb(priv
->ibss_beacon
);
1644 priv
->ibss_beacon
= beacon
;
1645 mutex_unlock(&priv
->mutex
);
1647 iwl4965_send_beacon_cmd(priv
);
1650 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
1651 struct iwl_rx_mem_buffer
*rxb
)
1653 #ifdef CONFIG_IWLWIFI_DEBUG
1654 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1655 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
1656 u8 rate
= iwl4965_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
1658 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1659 "tsf %d %d rate %d\n",
1660 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
1661 beacon
->beacon_notify_hdr
.failure_frame
,
1662 le32_to_cpu(beacon
->ibss_mgr_status
),
1663 le32_to_cpu(beacon
->high_tsf
),
1664 le32_to_cpu(beacon
->low_tsf
), rate
);
1667 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
1668 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
1669 queue_work(priv
->workqueue
, &priv
->beacon_update
);
1672 /* Service response to REPLY_SCAN_CMD (0x80) */
1673 static void iwl4965_rx_reply_scan(struct iwl_priv
*priv
,
1674 struct iwl_rx_mem_buffer
*rxb
)
1676 #ifdef CONFIG_IWLWIFI_DEBUG
1677 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1678 struct iwl4965_scanreq_notification
*notif
=
1679 (struct iwl4965_scanreq_notification
*)pkt
->u
.raw
;
1681 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
1685 /* Service SCAN_START_NOTIFICATION (0x82) */
1686 static void iwl4965_rx_scan_start_notif(struct iwl_priv
*priv
,
1687 struct iwl_rx_mem_buffer
*rxb
)
1689 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1690 struct iwl4965_scanstart_notification
*notif
=
1691 (struct iwl4965_scanstart_notification
*)pkt
->u
.raw
;
1692 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
1693 IWL_DEBUG_SCAN("Scan start: "
1695 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
1697 notif
->band
? "bg" : "a",
1699 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
1702 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
1703 static void iwl4965_rx_scan_results_notif(struct iwl_priv
*priv
,
1704 struct iwl_rx_mem_buffer
*rxb
)
1706 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1707 struct iwl4965_scanresults_notification
*notif
=
1708 (struct iwl4965_scanresults_notification
*)pkt
->u
.raw
;
1710 IWL_DEBUG_SCAN("Scan ch.res: "
1712 "(TSF: 0x%08X:%08X) - %d "
1713 "elapsed=%lu usec (%dms since last)\n",
1715 notif
->band
? "bg" : "a",
1716 le32_to_cpu(notif
->tsf_high
),
1717 le32_to_cpu(notif
->tsf_low
),
1718 le32_to_cpu(notif
->statistics
[0]),
1719 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
1720 jiffies_to_msecs(elapsed_jiffies
1721 (priv
->last_scan_jiffies
, jiffies
)));
1723 priv
->last_scan_jiffies
= jiffies
;
1724 priv
->next_scan_jiffies
= 0;
1727 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
1728 static void iwl4965_rx_scan_complete_notif(struct iwl_priv
*priv
,
1729 struct iwl_rx_mem_buffer
*rxb
)
1731 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1732 struct iwl4965_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
1734 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
1735 scan_notif
->scanned_channels
,
1736 scan_notif
->tsf_low
,
1737 scan_notif
->tsf_high
, scan_notif
->status
);
1739 /* The HW is no longer scanning */
1740 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
1742 /* The scan completion notification came in, so kill that timer... */
1743 cancel_delayed_work(&priv
->scan_check
);
1745 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
1746 (priv
->scan_bands
== 2) ? "2.4" : "5.2",
1747 jiffies_to_msecs(elapsed_jiffies
1748 (priv
->scan_pass_start
, jiffies
)));
1750 /* Remove this scanned band from the list
1751 * of pending bands to scan */
1754 /* If a request to abort was given, or the scan did not succeed
1755 * then we reset the scan state machine and terminate,
1756 * re-queuing another scan if one has been requested */
1757 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1758 IWL_DEBUG_INFO("Aborted scan completed.\n");
1759 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1761 /* If there are more bands on this scan pass reschedule */
1762 if (priv
->scan_bands
> 0)
1766 priv
->last_scan_jiffies
= jiffies
;
1767 priv
->next_scan_jiffies
= 0;
1768 IWL_DEBUG_INFO("Setting scan to off\n");
1770 clear_bit(STATUS_SCANNING
, &priv
->status
);
1772 IWL_DEBUG_INFO("Scan took %dms\n",
1773 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
1775 queue_work(priv
->workqueue
, &priv
->scan_completed
);
1780 priv
->scan_pass_start
= jiffies
;
1781 queue_work(priv
->workqueue
, &priv
->request_scan
);
1784 /* Handle notification from uCode that card's power state is changing
1785 * due to software, hardware, or critical temperature RFKILL */
1786 static void iwl4965_rx_card_state_notif(struct iwl_priv
*priv
,
1787 struct iwl_rx_mem_buffer
*rxb
)
1789 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1790 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
1791 unsigned long status
= priv
->status
;
1793 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1794 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
1795 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
1797 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
1798 RF_CARD_DISABLED
)) {
1800 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
1801 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
1803 if (!iwl_grab_nic_access(priv
)) {
1805 priv
, HBUS_TARG_MBX_C
,
1806 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
1808 iwl_release_nic_access(priv
);
1811 if (!(flags
& RXON_CARD_DISABLED
)) {
1812 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
1813 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
1814 if (!iwl_grab_nic_access(priv
)) {
1816 priv
, HBUS_TARG_MBX_C
,
1817 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
1819 iwl_release_nic_access(priv
);
1823 if (flags
& RF_CARD_DISABLED
) {
1824 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
1825 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
1826 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
1827 if (!iwl_grab_nic_access(priv
))
1828 iwl_release_nic_access(priv
);
1832 if (flags
& HW_CARD_DISABLED
)
1833 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
1835 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
1838 if (flags
& SW_CARD_DISABLED
)
1839 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
1841 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
1843 if (!(flags
& RXON_CARD_DISABLED
))
1844 iwl4965_scan_cancel(priv
);
1846 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
1847 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
1848 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
1849 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
1850 queue_work(priv
->workqueue
, &priv
->rf_kill
);
1852 wake_up_interruptible(&priv
->wait_command_queue
);
1855 /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
1856 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
1857 static void iwl4965_rx_reply_rx_phy(struct iwl_priv
*priv
,
1858 struct iwl_rx_mem_buffer
*rxb
)
1860 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1861 priv
->last_phy_res
[0] = 1;
1862 memcpy(&priv
->last_phy_res
[1], &(pkt
->u
.raw
[0]),
1863 sizeof(struct iwl4965_rx_phy_res
));
1867 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
1869 * Setup the RX handlers for each of the reply types sent from the uCode
1872 * This function chains into the hardware specific files for them to setup
1873 * any hardware specific handlers as well.
1875 static void iwl4965_setup_rx_handlers(struct iwl_priv
*priv
)
1877 priv
->rx_handlers
[REPLY_ALIVE
] = iwl_rx_reply_alive
;
1878 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
1879 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
1880 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
1881 iwl4965_rx_spectrum_measure_notif
;
1882 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
1883 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
1884 iwl4965_rx_pm_debug_statistics_notif
;
1885 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
1888 * The same handler is used for both the REPLY to a discrete
1889 * statistics request from the host as well as for the periodic
1890 * statistics notifications (after received beacons) from the uCode.
1892 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl4965_hw_rx_statistics
;
1893 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl4965_hw_rx_statistics
;
1895 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl4965_rx_reply_scan
;
1896 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl4965_rx_scan_start_notif
;
1897 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
1898 iwl4965_rx_scan_results_notif
;
1899 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
1900 iwl4965_rx_scan_complete_notif
;
1901 /* status change handler */
1902 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
1904 priv
->rx_handlers
[MISSED_BEACONS_NOTIFICATION
] =
1905 iwl_rx_missed_beacon_notif
;
1907 priv
->rx_handlers
[REPLY_RX_PHY_CMD
] = iwl4965_rx_reply_rx_phy
;
1908 priv
->rx_handlers
[REPLY_RX_MPDU_CMD
] = iwl4965_rx_reply_rx
;
1909 /* Set up hardware specific Rx handlers */
1910 priv
->cfg
->ops
->lib
->rx_handler_setup(priv
);
1914 * this should be called while priv->lock is locked
1916 static void __iwl_rx_replenish(struct iwl_priv
*priv
)
1918 iwl_rx_allocate(priv
);
1919 iwl_rx_queue_restock(priv
);
1924 * iwl_rx_handle - Main entry function for receiving responses from uCode
1926 * Uses the priv->rx_handlers callback function array to invoke
1927 * the appropriate handlers, including command responses,
1928 * frame-received notifications, and other notifications.
1930 void iwl_rx_handle(struct iwl_priv
*priv
)
1932 struct iwl_rx_mem_buffer
*rxb
;
1933 struct iwl_rx_packet
*pkt
;
1934 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
1937 unsigned long flags
;
1941 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1942 * buffer that the driver may process (last buffer filled by ucode). */
1943 r
= priv
->cfg
->ops
->lib
->shared_mem_rx_idx(priv
);
1946 /* Rx interrupt, but nothing sent from uCode */
1948 IWL_DEBUG(IWL_DL_RX
, "r = %d, i = %d\n", r
, i
);
1950 if (iwl_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
1954 rxb
= rxq
->queue
[i
];
1956 /* If an RXB doesn't have a Rx queue slot associated with it,
1957 * then a bug has been introduced in the queue refilling
1958 * routines -- catch it here */
1959 BUG_ON(rxb
== NULL
);
1961 rxq
->queue
[i
] = NULL
;
1963 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
1964 priv
->hw_params
.rx_buf_size
,
1965 PCI_DMA_FROMDEVICE
);
1966 pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1968 /* Reclaim a command buffer only if this packet is a response
1969 * to a (driver-originated) command.
1970 * If the packet (e.g. Rx frame) originated from uCode,
1971 * there is no command buffer to reclaim.
1972 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1973 * but apparently a few don't get set; catch them here. */
1974 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
1975 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
1976 (pkt
->hdr
.cmd
!= REPLY_RX
) &&
1977 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
1978 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
1979 (pkt
->hdr
.cmd
!= REPLY_TX
);
1981 /* Based on type of command response or notification,
1982 * handle those that need handling via function in
1983 * rx_handlers table. See iwl4965_setup_rx_handlers() */
1984 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
1985 IWL_DEBUG(IWL_DL_RX
, "r = %d, i = %d, %s, 0x%02x\n", r
,
1986 i
, get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
1987 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
1989 /* No handling needed */
1990 IWL_DEBUG(IWL_DL_RX
,
1991 "r %d i %d No handler needed for %s, 0x%02x\n",
1992 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
1997 /* Invoke any callbacks, transfer the skb to caller, and
1998 * fire off the (possibly) blocking iwl_send_cmd()
1999 * as we reclaim the driver command queue */
2000 if (rxb
&& rxb
->skb
)
2001 iwl_tx_cmd_complete(priv
, rxb
);
2003 IWL_WARNING("Claim null rxb?\n");
2006 /* For now we just don't re-use anything. We can tweak this
2007 * later to try and re-use notification packets and SKBs that
2008 * fail to Rx correctly */
2009 if (rxb
->skb
!= NULL
) {
2010 priv
->alloc_rxb_skb
--;
2011 dev_kfree_skb_any(rxb
->skb
);
2015 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
2016 priv
->hw_params
.rx_buf_size
,
2017 PCI_DMA_FROMDEVICE
);
2018 spin_lock_irqsave(&rxq
->lock
, flags
);
2019 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
2020 spin_unlock_irqrestore(&rxq
->lock
, flags
);
2021 i
= (i
+ 1) & RX_QUEUE_MASK
;
2022 /* If there are a lot of unused frames,
2023 * restock the Rx queue so ucode wont assert. */
2028 __iwl_rx_replenish(priv
);
2034 /* Backtrack one entry */
2036 iwl_rx_queue_restock(priv
);
2038 /* Convert linear signal-to-noise ratio into dB */
2039 static u8 ratio2dB
[100] = {
2040 /* 0 1 2 3 4 5 6 7 8 9 */
2041 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
2042 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
2043 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
2044 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
2045 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
2046 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
2047 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
2048 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
2049 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
2050 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
2053 /* Calculates a relative dB value from a ratio of linear
2054 * (i.e. not dB) signal levels.
2055 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
2056 int iwl4965_calc_db_from_ratio(int sig_ratio
)
2058 /* 1000:1 or higher just report as 60 dB */
2059 if (sig_ratio
>= 1000)
2062 /* 100:1 or higher, divide by 10 and use table,
2063 * add 20 dB to make up for divide by 10 */
2064 if (sig_ratio
>= 100)
2065 return (20 + (int)ratio2dB
[sig_ratio
/10]);
2067 /* We shouldn't see this */
2071 /* Use table for ratios 1:1 - 99:1 */
2072 return (int)ratio2dB
[sig_ratio
];
2075 #define PERFECT_RSSI (-20) /* dBm */
2076 #define WORST_RSSI (-95) /* dBm */
2077 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
2079 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
2080 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
2081 * about formulas used below. */
2082 int iwl4965_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
2085 int degradation
= PERFECT_RSSI
- rssi_dbm
;
2087 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
2088 * as indicator; formula is (signal dbm - noise dbm).
2089 * SNR at or above 40 is a great signal (100%).
2090 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
2091 * Weakest usable signal is usually 10 - 15 dB SNR. */
2093 if (rssi_dbm
- noise_dbm
>= 40)
2095 else if (rssi_dbm
< noise_dbm
)
2097 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
2099 /* Else use just the signal level.
2100 * This formula is a least squares fit of data points collected and
2101 * compared with a reference system that had a percentage (%) display
2102 * for signal quality. */
2104 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
2105 (15 * RSSI_RANGE
+ 62 * degradation
)) /
2106 (RSSI_RANGE
* RSSI_RANGE
);
2110 else if (sig_qual
< 1)
2116 #ifdef CONFIG_IWLWIFI_DEBUG
2117 static void iwl4965_print_rx_config_cmd(struct iwl_priv
*priv
)
2119 struct iwl_rxon_cmd
*rxon
= &priv
->staging_rxon
;
2120 DECLARE_MAC_BUF(mac
);
2122 IWL_DEBUG_RADIO("RX CONFIG:\n");
2123 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
2124 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
2125 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
2126 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
2127 le32_to_cpu(rxon
->filter_flags
));
2128 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
2129 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
2130 rxon
->ofdm_basic_rates
);
2131 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
2132 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
2133 print_mac(mac
, rxon
->node_addr
));
2134 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
2135 print_mac(mac
, rxon
->bssid_addr
));
2136 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
2140 static void iwl4965_enable_interrupts(struct iwl_priv
*priv
)
2142 IWL_DEBUG_ISR("Enabling interrupts\n");
2143 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
2144 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
2147 /* call this function to flush any scheduled tasklet */
2148 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
2150 /* wait to make sure we flush pedding tasklet*/
2151 synchronize_irq(priv
->pci_dev
->irq
);
2152 tasklet_kill(&priv
->irq_tasklet
);
2155 static inline void iwl4965_disable_interrupts(struct iwl_priv
*priv
)
2157 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
2159 /* disable interrupts from uCode/NIC to host */
2160 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
2162 /* acknowledge/clear/reset any interrupts still pending
2163 * from uCode or flow handler (Rx/Tx DMA) */
2164 iwl_write32(priv
, CSR_INT
, 0xffffffff);
2165 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
2166 IWL_DEBUG_ISR("Disabled interrupts\n");
2171 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
2173 static void iwl4965_irq_handle_error(struct iwl_priv
*priv
)
2175 /* Set the FW error flag -- cleared on iwl4965_down */
2176 set_bit(STATUS_FW_ERROR
, &priv
->status
);
2178 /* Cancel currently queued command. */
2179 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
2181 #ifdef CONFIG_IWLWIFI_DEBUG
2182 if (priv
->debug_level
& IWL_DL_FW_ERRORS
) {
2183 iwl_dump_nic_error_log(priv
);
2184 iwl_dump_nic_event_log(priv
);
2185 iwl4965_print_rx_config_cmd(priv
);
2189 wake_up_interruptible(&priv
->wait_command_queue
);
2191 /* Keep the restart process from trying to send host
2192 * commands by clearing the INIT status bit */
2193 clear_bit(STATUS_READY
, &priv
->status
);
2195 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
2196 IWL_DEBUG(IWL_DL_FW_ERRORS
,
2197 "Restarting adapter due to uCode error.\n");
2199 if (iwl_is_associated(priv
)) {
2200 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
2201 sizeof(priv
->recovery_rxon
));
2202 priv
->error_recovering
= 1;
2204 if (priv
->cfg
->mod_params
->restart_fw
)
2205 queue_work(priv
->workqueue
, &priv
->restart
);
2209 static void iwl4965_error_recovery(struct iwl_priv
*priv
)
2211 unsigned long flags
;
2213 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
2214 sizeof(priv
->staging_rxon
));
2215 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2216 iwl4965_commit_rxon(priv
);
2218 iwl_rxon_add_station(priv
, priv
->bssid
, 1);
2220 spin_lock_irqsave(&priv
->lock
, flags
);
2221 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
2222 priv
->error_recovering
= 0;
2223 spin_unlock_irqrestore(&priv
->lock
, flags
);
2226 static void iwl4965_irq_tasklet(struct iwl_priv
*priv
)
2228 u32 inta
, handled
= 0;
2230 unsigned long flags
;
2231 #ifdef CONFIG_IWLWIFI_DEBUG
2235 spin_lock_irqsave(&priv
->lock
, flags
);
2237 /* Ack/clear/reset pending uCode interrupts.
2238 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2239 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
2240 inta
= iwl_read32(priv
, CSR_INT
);
2241 iwl_write32(priv
, CSR_INT
, inta
);
2243 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2244 * Any new interrupts that happen after this, either while we're
2245 * in this tasklet, or later, will show up in next ISR/tasklet. */
2246 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
2247 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
2249 #ifdef CONFIG_IWLWIFI_DEBUG
2250 if (priv
->debug_level
& IWL_DL_ISR
) {
2251 /* just for debug */
2252 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
2253 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
2254 inta
, inta_mask
, inta_fh
);
2258 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2259 * atomic, make sure that inta covers all the interrupts that
2260 * we've discovered, even if FH interrupt came in just after
2261 * reading CSR_INT. */
2262 if (inta_fh
& CSR49_FH_INT_RX_MASK
)
2263 inta
|= CSR_INT_BIT_FH_RX
;
2264 if (inta_fh
& CSR49_FH_INT_TX_MASK
)
2265 inta
|= CSR_INT_BIT_FH_TX
;
2267 /* Now service all interrupt bits discovered above. */
2268 if (inta
& CSR_INT_BIT_HW_ERR
) {
2269 IWL_ERROR("Microcode HW error detected. Restarting.\n");
2271 /* Tell the device to stop sending interrupts */
2272 iwl4965_disable_interrupts(priv
);
2274 iwl4965_irq_handle_error(priv
);
2276 handled
|= CSR_INT_BIT_HW_ERR
;
2278 spin_unlock_irqrestore(&priv
->lock
, flags
);
2283 #ifdef CONFIG_IWLWIFI_DEBUG
2284 if (priv
->debug_level
& (IWL_DL_ISR
)) {
2285 /* NIC fires this, but we don't use it, redundant with WAKEUP */
2286 if (inta
& CSR_INT_BIT_SCD
)
2287 IWL_DEBUG_ISR("Scheduler finished to transmit "
2288 "the frame/frames.\n");
2290 /* Alive notification via Rx interrupt will do the real work */
2291 if (inta
& CSR_INT_BIT_ALIVE
)
2292 IWL_DEBUG_ISR("Alive interrupt\n");
2295 /* Safely ignore these bits for debug checks below */
2296 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
2298 /* HW RF KILL switch toggled */
2299 if (inta
& CSR_INT_BIT_RF_KILL
) {
2301 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
2302 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
2305 IWL_DEBUG(IWL_DL_RF_KILL
, "RF_KILL bit toggled to %s.\n",
2306 hw_rf_kill
? "disable radio":"enable radio");
2308 /* Queue restart only if RF_KILL switch was set to "kill"
2309 * when we loaded driver, and is now set to "enable".
2310 * After we're Alive, RF_KILL gets handled by
2311 * iwl4965_rx_card_state_notif() */
2312 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
2313 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2314 queue_work(priv
->workqueue
, &priv
->restart
);
2317 handled
|= CSR_INT_BIT_RF_KILL
;
2320 /* Chip got too hot and stopped itself */
2321 if (inta
& CSR_INT_BIT_CT_KILL
) {
2322 IWL_ERROR("Microcode CT kill error detected.\n");
2323 handled
|= CSR_INT_BIT_CT_KILL
;
2326 /* Error detected by uCode */
2327 if (inta
& CSR_INT_BIT_SW_ERR
) {
2328 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
2330 iwl4965_irq_handle_error(priv
);
2331 handled
|= CSR_INT_BIT_SW_ERR
;
2334 /* uCode wakes up after power-down sleep */
2335 if (inta
& CSR_INT_BIT_WAKEUP
) {
2336 IWL_DEBUG_ISR("Wakeup interrupt\n");
2337 iwl_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
2338 iwl_txq_update_write_ptr(priv
, &priv
->txq
[0]);
2339 iwl_txq_update_write_ptr(priv
, &priv
->txq
[1]);
2340 iwl_txq_update_write_ptr(priv
, &priv
->txq
[2]);
2341 iwl_txq_update_write_ptr(priv
, &priv
->txq
[3]);
2342 iwl_txq_update_write_ptr(priv
, &priv
->txq
[4]);
2343 iwl_txq_update_write_ptr(priv
, &priv
->txq
[5]);
2345 handled
|= CSR_INT_BIT_WAKEUP
;
2348 /* All uCode command responses, including Tx command responses,
2349 * Rx "responses" (frame-received notification), and other
2350 * notifications from uCode come through here*/
2351 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
2352 iwl_rx_handle(priv
);
2353 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
2356 if (inta
& CSR_INT_BIT_FH_TX
) {
2357 IWL_DEBUG_ISR("Tx interrupt\n");
2358 handled
|= CSR_INT_BIT_FH_TX
;
2359 /* FH finished to write, send event */
2360 priv
->ucode_write_complete
= 1;
2361 wake_up_interruptible(&priv
->wait_command_queue
);
2364 if (inta
& ~handled
)
2365 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
2367 if (inta
& ~CSR_INI_SET_MASK
) {
2368 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
2369 inta
& ~CSR_INI_SET_MASK
);
2370 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
2373 /* Re-enable all interrupts */
2374 /* only Re-enable if diabled by irq */
2375 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
2376 iwl4965_enable_interrupts(priv
);
2378 #ifdef CONFIG_IWLWIFI_DEBUG
2379 if (priv
->debug_level
& (IWL_DL_ISR
)) {
2380 inta
= iwl_read32(priv
, CSR_INT
);
2381 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
2382 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
2383 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
2384 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
2387 spin_unlock_irqrestore(&priv
->lock
, flags
);
2390 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
2392 struct iwl_priv
*priv
= data
;
2393 u32 inta
, inta_mask
;
2398 spin_lock(&priv
->lock
);
2400 /* Disable (but don't clear!) interrupts here to avoid
2401 * back-to-back ISRs and sporadic interrupts from our NIC.
2402 * If we have something to service, the tasklet will re-enable ints.
2403 * If we *don't* have something, we'll re-enable before leaving here. */
2404 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
2405 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
2407 /* Discover which interrupts are active/pending */
2408 inta
= iwl_read32(priv
, CSR_INT
);
2409 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
2411 /* Ignore interrupt if there's nothing in NIC to service.
2412 * This may be due to IRQ shared with another device,
2413 * or due to sporadic interrupts thrown from our NIC. */
2414 if (!inta
&& !inta_fh
) {
2415 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
2419 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
2420 /* Hardware disappeared. It might have already raised
2422 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
2426 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
2427 inta
, inta_mask
, inta_fh
);
2429 inta
&= ~CSR_INT_BIT_SCD
;
2431 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
2432 if (likely(inta
|| inta_fh
))
2433 tasklet_schedule(&priv
->irq_tasklet
);
2436 spin_unlock(&priv
->lock
);
2440 /* re-enable interrupts here since we don't have anything to service. */
2441 /* only Re-enable if diabled by irq */
2442 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
2443 iwl4965_enable_interrupts(priv
);
2444 spin_unlock(&priv
->lock
);
2448 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
2449 * sending probe req. This should be set long enough to hear probe responses
2450 * from more than one AP. */
2451 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
2452 #define IWL_ACTIVE_DWELL_TIME_52 (10)
2454 /* For faster active scanning, scan will move to the next channel if fewer than
2455 * PLCP_QUIET_THRESH packets are heard on this channel within
2456 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
2457 * time if it's a quiet channel (nothing responded to our probe, and there's
2458 * no other traffic).
2459 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
2460 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
2461 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
2463 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
2464 * Must be set longer than active dwell time.
2465 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
2466 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
2467 #define IWL_PASSIVE_DWELL_TIME_52 (10)
2468 #define IWL_PASSIVE_DWELL_BASE (100)
2469 #define IWL_CHANNEL_TUNE_TIME 5
2471 static inline u16
iwl4965_get_active_dwell_time(struct iwl_priv
*priv
,
2472 enum ieee80211_band band
)
2474 if (band
== IEEE80211_BAND_5GHZ
)
2475 return IWL_ACTIVE_DWELL_TIME_52
;
2477 return IWL_ACTIVE_DWELL_TIME_24
;
2480 static u16
iwl4965_get_passive_dwell_time(struct iwl_priv
*priv
,
2481 enum ieee80211_band band
)
2483 u16 active
= iwl4965_get_active_dwell_time(priv
, band
);
2484 u16 passive
= (band
!= IEEE80211_BAND_5GHZ
) ?
2485 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
2486 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
2488 if (iwl_is_associated(priv
)) {
2489 /* If we're associated, we clamp the maximum passive
2490 * dwell time to be 98% of the beacon interval (minus
2491 * 2 * channel tune time) */
2492 passive
= priv
->beacon_int
;
2493 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
2494 passive
= IWL_PASSIVE_DWELL_BASE
;
2495 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
2498 if (passive
<= active
)
2499 passive
= active
+ 1;
2504 static int iwl4965_get_channels_for_scan(struct iwl_priv
*priv
,
2505 enum ieee80211_band band
,
2506 u8 is_active
, u8 direct_mask
,
2507 struct iwl4965_scan_channel
*scan_ch
)
2509 const struct ieee80211_channel
*channels
= NULL
;
2510 const struct ieee80211_supported_band
*sband
;
2511 const struct iwl_channel_info
*ch_info
;
2512 u16 passive_dwell
= 0;
2513 u16 active_dwell
= 0;
2516 sband
= iwl_get_hw_mode(priv
, band
);
2520 channels
= sband
->channels
;
2522 active_dwell
= iwl4965_get_active_dwell_time(priv
, band
);
2523 passive_dwell
= iwl4965_get_passive_dwell_time(priv
, band
);
2525 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
2526 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
2529 scan_ch
->channel
= ieee80211_frequency_to_channel(channels
[i
].center_freq
);
2531 ch_info
= iwl_get_channel_info(priv
, band
,
2533 if (!is_channel_valid(ch_info
)) {
2534 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
2539 if (!is_active
|| is_channel_passive(ch_info
) ||
2540 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
2541 scan_ch
->type
= 0; /* passive */
2543 scan_ch
->type
= 1; /* active */
2545 if (scan_ch
->type
& 1)
2546 scan_ch
->type
|= (direct_mask
<< 1);
2548 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
2549 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
2551 /* Set txpower levels to defaults */
2552 scan_ch
->tpc
.dsp_atten
= 110;
2553 /* scan_pwr_info->tpc.dsp_atten; */
2555 /*scan_pwr_info->tpc.tx_gain; */
2556 if (band
== IEEE80211_BAND_5GHZ
)
2557 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
2559 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
2560 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
2562 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
2566 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
2568 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
2569 (scan_ch
->type
& 1) ?
2570 active_dwell
: passive_dwell
);
2576 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
2580 /******************************************************************************
2582 * uCode download functions
2584 ******************************************************************************/
2586 static void iwl4965_dealloc_ucode_pci(struct iwl_priv
*priv
)
2588 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
2589 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
2590 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
2591 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
2592 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
2593 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
2596 static void iwl4965_nic_start(struct iwl_priv
*priv
)
2598 /* Remove all resets to allow NIC to operate */
2599 iwl_write32(priv
, CSR_RESET
, 0);
2604 * iwl4965_read_ucode - Read uCode images from disk file.
2606 * Copy into buffers for card to fetch via bus-mastering
2608 static int iwl4965_read_ucode(struct iwl_priv
*priv
)
2610 struct iwl4965_ucode
*ucode
;
2612 const struct firmware
*ucode_raw
;
2613 const char *name
= priv
->cfg
->fw_name
;
2616 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
2618 /* Ask kernel firmware_class module to get the boot firmware off disk.
2619 * request_firmware() is synchronous, file is in memory on return. */
2620 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
2622 IWL_ERROR("%s firmware file req failed: Reason %d\n",
2627 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
2628 name
, ucode_raw
->size
);
2630 /* Make sure that we got at least our header! */
2631 if (ucode_raw
->size
< sizeof(*ucode
)) {
2632 IWL_ERROR("File size way too small!\n");
2637 /* Data from ucode file: header followed by uCode images */
2638 ucode
= (void *)ucode_raw
->data
;
2640 ver
= le32_to_cpu(ucode
->ver
);
2641 inst_size
= le32_to_cpu(ucode
->inst_size
);
2642 data_size
= le32_to_cpu(ucode
->data_size
);
2643 init_size
= le32_to_cpu(ucode
->init_size
);
2644 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
2645 boot_size
= le32_to_cpu(ucode
->boot_size
);
2647 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
2648 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
2650 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
2652 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
2654 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
2656 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
2659 /* Verify size of file vs. image size info in file's header */
2660 if (ucode_raw
->size
< sizeof(*ucode
) +
2661 inst_size
+ data_size
+ init_size
+
2662 init_data_size
+ boot_size
) {
2664 IWL_DEBUG_INFO("uCode file size %d too small\n",
2665 (int)ucode_raw
->size
);
2670 /* Verify that uCode images will fit in card's SRAM */
2671 if (inst_size
> priv
->hw_params
.max_inst_size
) {
2672 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
2678 if (data_size
> priv
->hw_params
.max_data_size
) {
2679 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
2684 if (init_size
> priv
->hw_params
.max_inst_size
) {
2686 ("uCode init instr len %d too large to fit in\n",
2691 if (init_data_size
> priv
->hw_params
.max_data_size
) {
2693 ("uCode init data len %d too large to fit in\n",
2698 if (boot_size
> priv
->hw_params
.max_bsm_size
) {
2700 ("uCode boot instr len %d too large to fit in\n",
2706 /* Allocate ucode buffers for card's bus-master loading ... */
2708 /* Runtime instructions and 2 copies of data:
2709 * 1) unmodified from disk
2710 * 2) backup cache for save/restore during power-downs */
2711 priv
->ucode_code
.len
= inst_size
;
2712 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
2714 priv
->ucode_data
.len
= data_size
;
2715 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
2717 priv
->ucode_data_backup
.len
= data_size
;
2718 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
2720 /* Initialization instructions and data */
2721 if (init_size
&& init_data_size
) {
2722 priv
->ucode_init
.len
= init_size
;
2723 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
2725 priv
->ucode_init_data
.len
= init_data_size
;
2726 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
2728 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
2732 /* Bootstrap (instructions only, no data) */
2734 priv
->ucode_boot
.len
= boot_size
;
2735 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
2737 if (!priv
->ucode_boot
.v_addr
)
2741 /* Copy images into buffers for card's bus-master reads ... */
2743 /* Runtime instructions (first block of data in file) */
2744 src
= &ucode
->data
[0];
2745 len
= priv
->ucode_code
.len
;
2746 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
2747 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
2748 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
2749 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
2751 /* Runtime data (2nd block)
2752 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
2753 src
= &ucode
->data
[inst_size
];
2754 len
= priv
->ucode_data
.len
;
2755 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
2756 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
2757 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
2759 /* Initialization instructions (3rd block) */
2761 src
= &ucode
->data
[inst_size
+ data_size
];
2762 len
= priv
->ucode_init
.len
;
2763 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
2765 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
2768 /* Initialization data (4th block) */
2769 if (init_data_size
) {
2770 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
2771 len
= priv
->ucode_init_data
.len
;
2772 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
2774 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
2777 /* Bootstrap instructions (5th block) */
2778 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
2779 len
= priv
->ucode_boot
.len
;
2780 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
2781 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
2783 /* We have our copies now, allow OS release its copies */
2784 release_firmware(ucode_raw
);
2788 IWL_ERROR("failed to allocate pci memory\n");
2790 iwl4965_dealloc_ucode_pci(priv
);
2793 release_firmware(ucode_raw
);
2800 * iwl_alive_start - called after REPLY_ALIVE notification received
2801 * from protocol/runtime uCode (initialization uCode's
2802 * Alive gets handled by iwl_init_alive_start()).
2804 static void iwl_alive_start(struct iwl_priv
*priv
)
2808 IWL_DEBUG_INFO("Runtime Alive received.\n");
2810 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
2811 /* We had an error bringing up the hardware, so take it
2812 * all the way back down so we can try again */
2813 IWL_DEBUG_INFO("Alive failed.\n");
2817 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2818 * This is a paranoid check, because we would not have gotten the
2819 * "runtime" alive if code weren't properly loaded. */
2820 if (iwl_verify_ucode(priv
)) {
2821 /* Runtime instruction load was bad;
2822 * take it all the way back down so we can try again */
2823 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
2827 iwlcore_clear_stations_table(priv
);
2828 ret
= priv
->cfg
->ops
->lib
->alive_notify(priv
);
2830 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
2835 /* After the ALIVE response, we can send host commands to 4965 uCode */
2836 set_bit(STATUS_ALIVE
, &priv
->status
);
2838 /* Clear out the uCode error bit if it is set */
2839 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
2841 if (iwl_is_rfkill(priv
))
2844 ieee80211_wake_queues(priv
->hw
);
2846 priv
->active_rate
= priv
->rates_mask
;
2847 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
2849 if (iwl_is_associated(priv
)) {
2850 struct iwl_rxon_cmd
*active_rxon
=
2851 (struct iwl_rxon_cmd
*)&priv
->active_rxon
;
2853 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
2854 sizeof(priv
->staging_rxon
));
2855 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2857 /* Initialize our rx_config data */
2858 iwl4965_connection_init_rx_config(priv
);
2859 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2862 /* Configure Bluetooth device coexistence support */
2863 iwl4965_send_bt_config(priv
);
2865 iwl_reset_run_time_calib(priv
);
2867 /* Configure the adapter for unassociated operation */
2868 iwl4965_commit_rxon(priv
);
2870 /* At this point, the NIC is initialized and operational */
2871 iwl4965_rf_kill_ct_config(priv
);
2873 iwl_leds_register(priv
);
2875 IWL_DEBUG_INFO("ALIVE processing complete.\n");
2876 set_bit(STATUS_READY
, &priv
->status
);
2877 wake_up_interruptible(&priv
->wait_command_queue
);
2879 if (priv
->error_recovering
)
2880 iwl4965_error_recovery(priv
);
2882 iwlcore_low_level_notify(priv
, IWLCORE_START_EVT
);
2883 ieee80211_notify_mac(priv
->hw
, IEEE80211_NOTIFY_RE_ASSOC
);
2887 queue_work(priv
->workqueue
, &priv
->restart
);
2890 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
);
2892 static void __iwl4965_down(struct iwl_priv
*priv
)
2894 unsigned long flags
;
2895 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2897 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
2900 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2902 iwl_leds_unregister(priv
);
2904 iwlcore_low_level_notify(priv
, IWLCORE_STOP_EVT
);
2906 iwlcore_clear_stations_table(priv
);
2908 /* Unblock any waiting calls */
2909 wake_up_interruptible_all(&priv
->wait_command_queue
);
2911 /* Wipe out the EXIT_PENDING status bit if we are not actually
2912 * exiting the module */
2914 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2916 /* stop and reset the on-board processor */
2917 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
2919 /* tell the device to stop sending interrupts */
2920 spin_lock_irqsave(&priv
->lock
, flags
);
2921 iwl4965_disable_interrupts(priv
);
2922 spin_unlock_irqrestore(&priv
->lock
, flags
);
2923 iwl_synchronize_irq(priv
);
2925 if (priv
->mac80211_registered
)
2926 ieee80211_stop_queues(priv
->hw
);
2928 /* If we have not previously called iwl4965_init() then
2929 * clear all bits but the RF Kill and SUSPEND bits and return */
2930 if (!iwl_is_init(priv
)) {
2931 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2933 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
2935 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2936 STATUS_GEO_CONFIGURED
|
2937 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
2942 /* ...otherwise clear out all the status bits but the RF Kill and
2943 * SUSPEND bits and continue taking the NIC down. */
2944 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2946 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
2948 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2949 STATUS_GEO_CONFIGURED
|
2950 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
2952 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
2955 spin_lock_irqsave(&priv
->lock
, flags
);
2956 iwl_clear_bit(priv
, CSR_GP_CNTRL
,
2957 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
2958 spin_unlock_irqrestore(&priv
->lock
, flags
);
2960 iwl_txq_ctx_stop(priv
);
2963 spin_lock_irqsave(&priv
->lock
, flags
);
2964 if (!iwl_grab_nic_access(priv
)) {
2965 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
2966 APMG_CLK_VAL_DMA_CLK_RQT
);
2967 iwl_release_nic_access(priv
);
2969 spin_unlock_irqrestore(&priv
->lock
, flags
);
2973 /* FIXME: apm_ops.suspend(priv) */
2974 priv
->cfg
->ops
->lib
->apm_ops
.reset(priv
);
2975 priv
->cfg
->ops
->lib
->free_shared_mem(priv
);
2978 memset(&priv
->card_alive
, 0, sizeof(struct iwl_alive_resp
));
2980 if (priv
->ibss_beacon
)
2981 dev_kfree_skb(priv
->ibss_beacon
);
2982 priv
->ibss_beacon
= NULL
;
2984 /* clear out any free frames */
2985 iwl_clear_free_frames(priv
);
2988 static void iwl4965_down(struct iwl_priv
*priv
)
2990 mutex_lock(&priv
->mutex
);
2991 __iwl4965_down(priv
);
2992 mutex_unlock(&priv
->mutex
);
2994 iwl4965_cancel_deferred_work(priv
);
2997 #define MAX_HW_RESTARTS 5
2999 static int __iwl4965_up(struct iwl_priv
*priv
)
3004 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
3005 IWL_WARNING("Exit pending; will not bring the NIC up\n");
3009 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
3010 IWL_WARNING("Radio disabled by SW RF kill (module "
3012 iwl_rfkill_set_hw_state(priv
);
3016 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
3017 IWL_ERROR("ucode not available for device bringup\n");
3021 /* If platform's RF_KILL switch is NOT set to KILL */
3022 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
3023 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
3024 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3026 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3027 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
3028 iwl_rfkill_set_hw_state(priv
);
3029 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
3034 iwl_rfkill_set_hw_state(priv
);
3035 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
3037 ret
= priv
->cfg
->ops
->lib
->alloc_shared_mem(priv
);
3039 IWL_ERROR("Unable to allocate shared memory\n");
3043 ret
= iwl_hw_nic_init(priv
);
3045 IWL_ERROR("Unable to init nic\n");
3049 /* make sure rfkill handshake bits are cleared */
3050 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
3051 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
3052 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3054 /* clear (again), then enable host interrupts */
3055 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
3056 iwl4965_enable_interrupts(priv
);
3058 /* really make sure rfkill handshake bits are cleared */
3059 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
3060 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
3062 /* Copy original ucode data image from disk into backup cache.
3063 * This will be used to initialize the on-board processor's
3064 * data SRAM for a clean start when the runtime program first loads. */
3065 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
3066 priv
->ucode_data
.len
);
3068 /* We return success when we resume from suspend and rf_kill is on. */
3069 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
3072 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
3074 iwlcore_clear_stations_table(priv
);
3076 /* load bootstrap state machine,
3077 * load bootstrap program into processor's memory,
3078 * prepare to load the "initialize" uCode */
3079 ret
= priv
->cfg
->ops
->lib
->load_ucode(priv
);
3082 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret
);
3086 /* start card; "initialize" will load runtime ucode */
3087 iwl4965_nic_start(priv
);
3089 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
3094 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
3095 __iwl4965_down(priv
);
3097 /* tried to restart and config the device for as long as our
3098 * patience could withstand */
3099 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
3104 /*****************************************************************************
3106 * Workqueue callbacks
3108 *****************************************************************************/
3110 static void iwl_bg_init_alive_start(struct work_struct
*data
)
3112 struct iwl_priv
*priv
=
3113 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
3115 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3118 mutex_lock(&priv
->mutex
);
3119 priv
->cfg
->ops
->lib
->init_alive_start(priv
);
3120 mutex_unlock(&priv
->mutex
);
3123 static void iwl_bg_alive_start(struct work_struct
*data
)
3125 struct iwl_priv
*priv
=
3126 container_of(data
, struct iwl_priv
, alive_start
.work
);
3128 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3131 mutex_lock(&priv
->mutex
);
3132 iwl_alive_start(priv
);
3133 mutex_unlock(&priv
->mutex
);
3136 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
3138 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
3140 wake_up_interruptible(&priv
->wait_command_queue
);
3142 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3145 mutex_lock(&priv
->mutex
);
3147 if (!iwl_is_rfkill(priv
)) {
3148 IWL_DEBUG(IWL_DL_RF_KILL
,
3149 "HW and/or SW RF Kill no longer active, restarting "
3151 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3152 queue_work(priv
->workqueue
, &priv
->restart
);
3154 /* make sure mac80211 stop sending Tx frame */
3155 if (priv
->mac80211_registered
)
3156 ieee80211_stop_queues(priv
->hw
);
3158 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
3159 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
3160 "disabled by SW switch\n");
3162 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
3163 "Kill switch must be turned off for "
3164 "wireless networking to work.\n");
3166 iwl_rfkill_set_hw_state(priv
);
3168 mutex_unlock(&priv
->mutex
);
3171 static void iwl4965_bg_set_monitor(struct work_struct
*work
)
3173 struct iwl_priv
*priv
= container_of(work
,
3174 struct iwl_priv
, set_monitor
);
3176 IWL_DEBUG(IWL_DL_STATE
, "setting monitor mode\n");
3178 mutex_lock(&priv
->mutex
);
3180 if (!iwl_is_ready(priv
))
3181 IWL_DEBUG(IWL_DL_STATE
, "leave - not ready\n");
3183 if (iwl4965_set_mode(priv
, IEEE80211_IF_TYPE_MNTR
) != 0)
3184 IWL_ERROR("iwl4965_set_mode() failed\n");
3186 mutex_unlock(&priv
->mutex
);
3189 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
3191 static void iwl4965_bg_scan_check(struct work_struct
*data
)
3193 struct iwl_priv
*priv
=
3194 container_of(data
, struct iwl_priv
, scan_check
.work
);
3196 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3199 mutex_lock(&priv
->mutex
);
3200 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
3201 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3202 IWL_DEBUG(IWL_DL_SCAN
, "Scan completion watchdog resetting "
3204 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
3206 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3207 iwl4965_send_scan_abort(priv
);
3209 mutex_unlock(&priv
->mutex
);
3212 static void iwl4965_bg_request_scan(struct work_struct
*data
)
3214 struct iwl_priv
*priv
=
3215 container_of(data
, struct iwl_priv
, request_scan
);
3216 struct iwl_host_cmd cmd
= {
3217 .id
= REPLY_SCAN_CMD
,
3218 .len
= sizeof(struct iwl4965_scan_cmd
),
3219 .meta
.flags
= CMD_SIZE_HUGE
,
3221 struct iwl4965_scan_cmd
*scan
;
3222 struct ieee80211_conf
*conf
= NULL
;
3224 enum ieee80211_band band
;
3228 conf
= ieee80211_get_hw_conf(priv
->hw
);
3230 mutex_lock(&priv
->mutex
);
3232 if (!iwl_is_ready(priv
)) {
3233 IWL_WARNING("request scan called when driver not ready.\n");
3237 /* Make sure the scan wasn't cancelled before this queued work
3238 * was given the chance to run... */
3239 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
3242 /* This should never be called or scheduled if there is currently
3243 * a scan active in the hardware. */
3244 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
3245 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
3246 "Ignoring second request.\n");
3251 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
3252 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
3256 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3257 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
3261 if (iwl_is_rfkill(priv
)) {
3262 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
3266 if (!test_bit(STATUS_READY
, &priv
->status
)) {
3267 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
3271 if (!priv
->scan_bands
) {
3272 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
3277 priv
->scan
= kmalloc(sizeof(struct iwl4965_scan_cmd
) +
3278 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
3285 memset(scan
, 0, sizeof(struct iwl4965_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
3287 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
3288 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
3290 if (iwl_is_associated(priv
)) {
3293 u32 suspend_time
= 100;
3294 u32 scan_suspend_time
= 100;
3295 unsigned long flags
;
3297 IWL_DEBUG_INFO("Scanning while associated...\n");
3299 spin_lock_irqsave(&priv
->lock
, flags
);
3300 interval
= priv
->beacon_int
;
3301 spin_unlock_irqrestore(&priv
->lock
, flags
);
3303 scan
->suspend_time
= 0;
3304 scan
->max_out_time
= cpu_to_le32(200 * 1024);
3306 interval
= suspend_time
;
3308 extra
= (suspend_time
/ interval
) << 22;
3309 scan_suspend_time
= (extra
|
3310 ((suspend_time
% interval
) * 1024));
3311 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
3312 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
3313 scan_suspend_time
, interval
);
3316 /* We should add the ability for user to lock to PASSIVE ONLY */
3317 if (priv
->one_direct_scan
) {
3319 ("Kicking off one direct scan for '%s'\n",
3320 iwl4965_escape_essid(priv
->direct_ssid
,
3321 priv
->direct_ssid_len
));
3322 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
3323 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
3324 memcpy(scan
->direct_scan
[0].ssid
,
3325 priv
->direct_ssid
, priv
->direct_ssid_len
);
3327 } else if (!iwl_is_associated(priv
) && priv
->essid_len
) {
3329 ("Kicking off one direct scan for '%s' when not associated\n",
3330 iwl4965_escape_essid(priv
->essid
, priv
->essid_len
));
3331 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
3332 scan
->direct_scan
[0].len
= priv
->essid_len
;
3333 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
3336 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
3340 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
3341 scan
->tx_cmd
.sta_id
= priv
->hw_params
.bcast_sta_id
;
3342 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
3345 switch (priv
->scan_bands
) {
3347 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
3348 scan
->tx_cmd
.rate_n_flags
=
3349 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP
,
3350 RATE_MCS_ANT_B_MSK
|RATE_MCS_CCK_MSK
);
3352 scan
->good_CRC_th
= 0;
3353 band
= IEEE80211_BAND_2GHZ
;
3357 scan
->tx_cmd
.rate_n_flags
=
3358 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
3359 RATE_MCS_ANT_B_MSK
);
3360 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
3361 band
= IEEE80211_BAND_5GHZ
;
3365 IWL_WARNING("Invalid scan band count\n");
3369 /* We don't build a direct scan probe request; the uCode will do
3370 * that based on the direct_mask added to each channel entry */
3371 cmd_len
= iwl4965_fill_probe_req(priv
, band
,
3372 (struct ieee80211_mgmt
*)scan
->data
,
3373 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0);
3375 scan
->tx_cmd
.len
= cpu_to_le16(cmd_len
);
3376 /* select Rx chains */
3378 /* Force use of chains B and C (0x6) for scan Rx.
3379 * Avoid A (0x1) because of its off-channel reception on A-band.
3380 * MIMO is not used here, but value is required to make uCode happy. */
3381 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
3382 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
3383 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS
) |
3384 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
3386 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
3387 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
3390 scan
->channel_count
=
3391 iwl4965_get_channels_for_scan(
3392 priv
, band
, 1, /* active */
3394 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
3396 scan
->channel_count
=
3397 iwl4965_get_channels_for_scan(
3398 priv
, band
, 0, /* passive */
3400 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
3402 scan
->filter_flags
|= (RXON_FILTER_ACCEPT_GRP_MSK
|
3403 RXON_FILTER_BCON_AWARE_MSK
);
3404 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
3405 scan
->channel_count
* sizeof(struct iwl4965_scan_channel
);
3407 scan
->len
= cpu_to_le16(cmd
.len
);
3409 set_bit(STATUS_SCAN_HW
, &priv
->status
);
3410 ret
= iwl_send_cmd_sync(priv
, &cmd
);
3414 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
3415 IWL_SCAN_CHECK_WATCHDOG
);
3417 mutex_unlock(&priv
->mutex
);
3421 /* inform mac80211 scan aborted */
3422 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3423 mutex_unlock(&priv
->mutex
);
3426 static void iwl_bg_run_time_calib_work(struct work_struct
*work
)
3428 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
,
3429 run_time_calib_work
);
3431 mutex_lock(&priv
->mutex
);
3433 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
) ||
3434 test_bit(STATUS_SCANNING
, &priv
->status
)) {
3435 mutex_unlock(&priv
->mutex
);
3439 if (priv
->start_calib
) {
3440 iwl_chain_noise_calibration(priv
, &priv
->statistics
);
3442 iwl_sensitivity_calibration(priv
, &priv
->statistics
);
3445 mutex_unlock(&priv
->mutex
);
3449 static void iwl4965_bg_up(struct work_struct
*data
)
3451 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
3453 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3456 mutex_lock(&priv
->mutex
);
3458 mutex_unlock(&priv
->mutex
);
3461 static void iwl4965_bg_restart(struct work_struct
*data
)
3463 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
3465 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3469 queue_work(priv
->workqueue
, &priv
->up
);
3472 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
3474 struct iwl_priv
*priv
=
3475 container_of(data
, struct iwl_priv
, rx_replenish
);
3477 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3480 mutex_lock(&priv
->mutex
);
3481 iwl_rx_replenish(priv
);
3482 mutex_unlock(&priv
->mutex
);
3485 #define IWL_DELAY_NEXT_SCAN (HZ*2)
3487 static void iwl4965_post_associate(struct iwl_priv
*priv
)
3489 struct ieee80211_conf
*conf
= NULL
;
3491 DECLARE_MAC_BUF(mac
);
3493 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
3494 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
3498 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
3500 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
3503 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3507 if (!priv
->vif
|| !priv
->is_open
)
3510 iwl4965_scan_cancel_timeout(priv
, 200);
3512 conf
= ieee80211_get_hw_conf(priv
->hw
);
3514 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3515 iwl4965_commit_rxon(priv
);
3517 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
3518 iwl4965_setup_rxon_timing(priv
);
3519 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
3520 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
3522 IWL_WARNING("REPLY_RXON_TIMING failed - "
3523 "Attempting to continue.\n");
3525 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
3527 if (priv
->current_ht_config
.is_ht
)
3528 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
3530 iwl_set_rxon_chain(priv
);
3531 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
3533 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
3534 priv
->assoc_id
, priv
->beacon_int
);
3536 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
3537 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
3539 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
3541 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
3542 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
3543 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
3545 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
3547 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
3548 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
3552 iwl4965_commit_rxon(priv
);
3554 switch (priv
->iw_mode
) {
3555 case IEEE80211_IF_TYPE_STA
:
3556 iwl4965_rate_scale_init(priv
->hw
, IWL_AP_ID
);
3559 case IEEE80211_IF_TYPE_IBSS
:
3561 /* clear out the station table */
3562 iwlcore_clear_stations_table(priv
);
3564 iwl_rxon_add_station(priv
, iwl_bcast_addr
, 0);
3565 iwl_rxon_add_station(priv
, priv
->bssid
, 0);
3566 iwl4965_rate_scale_init(priv
->hw
, IWL_STA_ID
);
3567 iwl4965_send_beacon_cmd(priv
);
3572 IWL_ERROR("%s Should not be called in %d mode\n",
3573 __FUNCTION__
, priv
->iw_mode
);
3577 iwl4965_sequence_reset(priv
);
3579 /* Enable Rx differential gain and sensitivity calibrations */
3580 iwl_chain_noise_reset(priv
);
3581 priv
->start_calib
= 1;
3583 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
3584 priv
->assoc_station_added
= 1;
3586 iwl4965_activate_qos(priv
, 0);
3588 iwl_power_update_mode(priv
, 0);
3589 /* we have just associated, don't start scan too early */
3590 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
3594 static void iwl4965_bg_post_associate(struct work_struct
*data
)
3596 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
,
3597 post_associate
.work
);
3599 mutex_lock(&priv
->mutex
);
3600 iwl4965_post_associate(priv
);
3601 mutex_unlock(&priv
->mutex
);
3605 static void iwl4965_bg_abort_scan(struct work_struct
*work
)
3607 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
3609 if (!iwl_is_ready(priv
))
3612 mutex_lock(&priv
->mutex
);
3614 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3615 iwl4965_send_scan_abort(priv
);
3617 mutex_unlock(&priv
->mutex
);
3620 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
3622 static void iwl4965_bg_scan_completed(struct work_struct
*work
)
3624 struct iwl_priv
*priv
=
3625 container_of(work
, struct iwl_priv
, scan_completed
);
3627 IWL_DEBUG(IWL_DL_SCAN
, "SCAN complete scan\n");
3629 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3632 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
3633 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
3635 ieee80211_scan_completed(priv
->hw
);
3637 /* Since setting the TXPOWER may have been deferred while
3638 * performing the scan, fire one off */
3639 mutex_lock(&priv
->mutex
);
3640 iwl4965_hw_reg_send_txpower(priv
);
3641 mutex_unlock(&priv
->mutex
);
3644 /*****************************************************************************
3646 * mac80211 entry point functions
3648 *****************************************************************************/
3650 #define UCODE_READY_TIMEOUT (2 * HZ)
3652 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
3654 struct iwl_priv
*priv
= hw
->priv
;
3657 IWL_DEBUG_MAC80211("enter\n");
3659 if (pci_enable_device(priv
->pci_dev
)) {
3660 IWL_ERROR("Fail to pci_enable_device\n");
3663 pci_restore_state(priv
->pci_dev
);
3664 pci_enable_msi(priv
->pci_dev
);
3666 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
3669 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
3670 goto out_disable_msi
;
3673 /* we should be verifying the device is ready to be opened */
3674 mutex_lock(&priv
->mutex
);
3676 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl_rxon_cmd
));
3677 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3678 * ucode filename and max sizes are card-specific. */
3680 if (!priv
->ucode_code
.len
) {
3681 ret
= iwl4965_read_ucode(priv
);
3683 IWL_ERROR("Could not read microcode: %d\n", ret
);
3684 mutex_unlock(&priv
->mutex
);
3685 goto out_release_irq
;
3689 ret
= __iwl4965_up(priv
);
3691 mutex_unlock(&priv
->mutex
);
3694 goto out_release_irq
;
3696 IWL_DEBUG_INFO("Start UP work done.\n");
3698 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
3701 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
3702 * mac80211 will not be run successfully. */
3703 if (priv
->ucode_type
== UCODE_RT
) {
3704 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
3705 test_bit(STATUS_READY
, &priv
->status
),
3706 UCODE_READY_TIMEOUT
);
3708 if (!test_bit(STATUS_READY
, &priv
->status
)) {
3709 IWL_ERROR("START_ALIVE timeout after %dms.\n",
3710 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
3712 goto out_release_irq
;
3718 IWL_DEBUG_MAC80211("leave\n");
3722 free_irq(priv
->pci_dev
->irq
, priv
);
3724 pci_disable_msi(priv
->pci_dev
);
3725 pci_disable_device(priv
->pci_dev
);
3727 IWL_DEBUG_MAC80211("leave - failed\n");
3731 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
3733 struct iwl_priv
*priv
= hw
->priv
;
3735 IWL_DEBUG_MAC80211("enter\n");
3737 if (!priv
->is_open
) {
3738 IWL_DEBUG_MAC80211("leave - skip\n");
3744 if (iwl_is_ready_rf(priv
)) {
3745 /* stop mac, cancel any scan request and clear
3746 * RXON_FILTER_ASSOC_MSK BIT
3748 mutex_lock(&priv
->mutex
);
3749 iwl4965_scan_cancel_timeout(priv
, 100);
3750 cancel_delayed_work(&priv
->post_associate
);
3751 mutex_unlock(&priv
->mutex
);
3756 flush_workqueue(priv
->workqueue
);
3757 free_irq(priv
->pci_dev
->irq
, priv
);
3758 pci_disable_msi(priv
->pci_dev
);
3759 pci_save_state(priv
->pci_dev
);
3760 pci_disable_device(priv
->pci_dev
);
3762 IWL_DEBUG_MAC80211("leave\n");
3765 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3767 struct iwl_priv
*priv
= hw
->priv
;
3769 IWL_DEBUG_MAC80211("enter\n");
3771 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
3772 IWL_DEBUG_MAC80211("leave - monitor\n");
3776 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
3777 ieee80211_get_tx_rate(hw
, IEEE80211_SKB_CB(skb
))->bitrate
);
3779 if (iwl_tx_skb(priv
, skb
))
3780 dev_kfree_skb_any(skb
);
3782 IWL_DEBUG_MAC80211("leave\n");
3786 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
3787 struct ieee80211_if_init_conf
*conf
)
3789 struct iwl_priv
*priv
= hw
->priv
;
3790 unsigned long flags
;
3791 DECLARE_MAC_BUF(mac
);
3793 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
3796 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
3800 spin_lock_irqsave(&priv
->lock
, flags
);
3801 priv
->vif
= conf
->vif
;
3803 spin_unlock_irqrestore(&priv
->lock
, flags
);
3805 mutex_lock(&priv
->mutex
);
3807 if (conf
->mac_addr
) {
3808 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
3809 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
3812 if (iwl_is_ready(priv
))
3813 iwl4965_set_mode(priv
, conf
->type
);
3815 mutex_unlock(&priv
->mutex
);
3817 IWL_DEBUG_MAC80211("leave\n");
3822 * iwl4965_mac_config - mac80211 config callback
3824 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3825 * be set inappropriately and the driver currently sets the hardware up to
3826 * use it whenever needed.
3828 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
3830 struct iwl_priv
*priv
= hw
->priv
;
3831 const struct iwl_channel_info
*ch_info
;
3832 unsigned long flags
;
3836 mutex_lock(&priv
->mutex
);
3837 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
3839 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
3841 if (!iwl_is_ready(priv
)) {
3842 IWL_DEBUG_MAC80211("leave - not ready\n");
3847 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
3848 test_bit(STATUS_SCANNING
, &priv
->status
))) {
3849 IWL_DEBUG_MAC80211("leave - scanning\n");
3850 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
3851 mutex_unlock(&priv
->mutex
);
3855 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
3856 ch_info
= iwl_get_channel_info(priv
, conf
->channel
->band
, channel
);
3857 if (!is_channel_valid(ch_info
)) {
3858 IWL_DEBUG_MAC80211("leave - invalid channel\n");
3863 spin_lock_irqsave(&priv
->lock
, flags
);
3865 /* if we are switching from ht to 2.4 clear flags
3866 * from any ht related info since 2.4 does not
3868 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != channel
)
3869 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
3870 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
3873 priv
->staging_rxon
.flags
= 0;
3875 iwl_set_rxon_channel(priv
, conf
->channel
->band
, channel
);
3877 iwl_set_flags_for_band(priv
, conf
->channel
->band
);
3879 /* The list of supported rates and rate mask can be different
3880 * for each band; since the band may have changed, reset
3881 * the rate mask to what mac80211 lists */
3882 iwl4965_set_rate(priv
);
3884 spin_unlock_irqrestore(&priv
->lock
, flags
);
3886 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
3887 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
3888 iwl4965_hw_channel_switch(priv
, conf
->channel
);
3893 if (priv
->cfg
->ops
->lib
->radio_kill_sw
)
3894 priv
->cfg
->ops
->lib
->radio_kill_sw(priv
, !conf
->radio_enabled
);
3896 if (!conf
->radio_enabled
) {
3897 IWL_DEBUG_MAC80211("leave - radio disabled\n");
3901 if (iwl_is_rfkill(priv
)) {
3902 IWL_DEBUG_MAC80211("leave - RF kill\n");
3907 iwl4965_set_rate(priv
);
3909 if (memcmp(&priv
->active_rxon
,
3910 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
3911 iwl4965_commit_rxon(priv
);
3913 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
3915 IWL_DEBUG_MAC80211("leave\n");
3918 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
3919 mutex_unlock(&priv
->mutex
);
3923 static void iwl4965_config_ap(struct iwl_priv
*priv
)
3927 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3930 /* The following should be done only at AP bring up */
3931 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
3933 /* RXON - unassoc (to set timing command) */
3934 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3935 iwl4965_commit_rxon(priv
);
3938 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
3939 iwl4965_setup_rxon_timing(priv
);
3940 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
3941 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
3943 IWL_WARNING("REPLY_RXON_TIMING failed - "
3944 "Attempting to continue.\n");
3946 iwl_set_rxon_chain(priv
);
3948 /* FIXME: what should be the assoc_id for AP? */
3949 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
3950 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
3951 priv
->staging_rxon
.flags
|=
3952 RXON_FLG_SHORT_PREAMBLE_MSK
;
3954 priv
->staging_rxon
.flags
&=
3955 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
3957 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
3958 if (priv
->assoc_capability
&
3959 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
3960 priv
->staging_rxon
.flags
|=
3961 RXON_FLG_SHORT_SLOT_MSK
;
3963 priv
->staging_rxon
.flags
&=
3964 ~RXON_FLG_SHORT_SLOT_MSK
;
3966 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
3967 priv
->staging_rxon
.flags
&=
3968 ~RXON_FLG_SHORT_SLOT_MSK
;
3970 /* restore RXON assoc */
3971 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
3972 iwl4965_commit_rxon(priv
);
3973 iwl4965_activate_qos(priv
, 1);
3974 iwl_rxon_add_station(priv
, iwl_bcast_addr
, 0);
3976 iwl4965_send_beacon_cmd(priv
);
3978 /* FIXME - we need to add code here to detect a totally new
3979 * configuration, reset the AP, unassoc, rxon timing, assoc,
3980 * clear sta table, add BCAST sta... */
3983 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
3984 struct ieee80211_vif
*vif
,
3985 struct ieee80211_if_conf
*conf
)
3987 struct iwl_priv
*priv
= hw
->priv
;
3988 DECLARE_MAC_BUF(mac
);
3989 unsigned long flags
;
3995 if (priv
->vif
!= vif
) {
3996 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
4000 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
4001 (!conf
->beacon
|| !conf
->ssid_len
)) {
4003 ("Leaving in AP mode because HostAPD is not ready.\n");
4007 if (!iwl_is_alive(priv
))
4010 mutex_lock(&priv
->mutex
);
4013 IWL_DEBUG_MAC80211("bssid: %s\n",
4014 print_mac(mac
, conf
->bssid
));
4017 * very dubious code was here; the probe filtering flag is never set:
4019 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4020 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
4023 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
4025 conf
->bssid
= priv
->mac_addr
;
4026 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
4027 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
4028 print_mac(mac
, conf
->bssid
));
4030 if (priv
->ibss_beacon
)
4031 dev_kfree_skb(priv
->ibss_beacon
);
4033 priv
->ibss_beacon
= conf
->beacon
;
4036 if (iwl_is_rfkill(priv
))
4039 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
4040 !is_multicast_ether_addr(conf
->bssid
)) {
4041 /* If there is currently a HW scan going on in the background
4042 * then we need to cancel it else the RXON below will fail. */
4043 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
4044 IWL_WARNING("Aborted scan still in progress "
4046 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
4047 mutex_unlock(&priv
->mutex
);
4050 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
4052 /* TODO: Audit driver for usage of these members and see
4053 * if mac80211 deprecates them (priv->bssid looks like it
4054 * shouldn't be there, but I haven't scanned the IBSS code
4055 * to verify) - jpk */
4056 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
4058 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
4059 iwl4965_config_ap(priv
);
4061 rc
= iwl4965_commit_rxon(priv
);
4062 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
4063 iwl_rxon_add_station(
4064 priv
, priv
->active_rxon
.bssid_addr
, 1);
4068 iwl4965_scan_cancel_timeout(priv
, 100);
4069 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4070 iwl4965_commit_rxon(priv
);
4074 spin_lock_irqsave(&priv
->lock
, flags
);
4075 if (!conf
->ssid_len
)
4076 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
4078 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
4080 priv
->essid_len
= conf
->ssid_len
;
4081 spin_unlock_irqrestore(&priv
->lock
, flags
);
4083 IWL_DEBUG_MAC80211("leave\n");
4084 mutex_unlock(&priv
->mutex
);
4089 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
4090 unsigned int changed_flags
,
4091 unsigned int *total_flags
,
4092 int mc_count
, struct dev_addr_list
*mc_list
)
4096 * see also iwl4965_connection_init_rx_config
4098 struct iwl_priv
*priv
= hw
->priv
;
4100 if (changed_flags
& (FIF_PROMISC_IN_BSS
| FIF_OTHER_BSS
)) {
4101 if (*total_flags
& (FIF_PROMISC_IN_BSS
| FIF_OTHER_BSS
)) {
4102 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
4103 IEEE80211_IF_TYPE_MNTR
,
4104 changed_flags
, *total_flags
);
4105 /* queue work 'cuz mac80211 is holding a lock which
4106 * prevents us from issuing (synchronous) f/w cmds */
4107 queue_work(priv
->workqueue
, &priv
->set_monitor
);
4108 new_flags
&= FIF_PROMISC_IN_BSS
|
4113 *total_flags
= new_flags
;
4116 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
4117 struct ieee80211_if_init_conf
*conf
)
4119 struct iwl_priv
*priv
= hw
->priv
;
4121 IWL_DEBUG_MAC80211("enter\n");
4123 mutex_lock(&priv
->mutex
);
4125 if (iwl_is_ready_rf(priv
)) {
4126 iwl4965_scan_cancel_timeout(priv
, 100);
4127 cancel_delayed_work(&priv
->post_associate
);
4128 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4129 iwl4965_commit_rxon(priv
);
4131 if (priv
->vif
== conf
->vif
) {
4133 memset(priv
->bssid
, 0, ETH_ALEN
);
4134 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
4135 priv
->essid_len
= 0;
4137 mutex_unlock(&priv
->mutex
);
4139 IWL_DEBUG_MAC80211("leave\n");
4143 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4144 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
4145 struct ieee80211_vif
*vif
,
4146 struct ieee80211_bss_conf
*bss_conf
,
4149 struct iwl_priv
*priv
= hw
->priv
;
4151 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
4153 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
4154 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
4155 bss_conf
->use_short_preamble
);
4156 if (bss_conf
->use_short_preamble
)
4157 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
4159 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
4162 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
4163 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
4164 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
4165 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
4167 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
4170 if (changes
& BSS_CHANGED_HT
) {
4171 IWL_DEBUG_MAC80211("HT %d\n", bss_conf
->assoc_ht
);
4172 iwl4965_ht_conf(priv
, bss_conf
);
4173 iwl_set_rxon_chain(priv
);
4176 if (changes
& BSS_CHANGED_ASSOC
) {
4177 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
4178 /* This should never happen as this function should
4179 * never be called from interrupt context. */
4180 if (WARN_ON_ONCE(in_interrupt()))
4182 if (bss_conf
->assoc
) {
4183 priv
->assoc_id
= bss_conf
->aid
;
4184 priv
->beacon_int
= bss_conf
->beacon_int
;
4185 priv
->timestamp
= bss_conf
->timestamp
;
4186 priv
->assoc_capability
= bss_conf
->assoc_capability
;
4187 priv
->next_scan_jiffies
= jiffies
+
4188 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
4189 mutex_lock(&priv
->mutex
);
4190 iwl4965_post_associate(priv
);
4191 mutex_unlock(&priv
->mutex
);
4194 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
4196 } else if (changes
&& iwl_is_associated(priv
) && priv
->assoc_id
) {
4197 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
4198 iwl_send_rxon_assoc(priv
);
4203 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
4206 unsigned long flags
;
4207 struct iwl_priv
*priv
= hw
->priv
;
4209 IWL_DEBUG_MAC80211("enter\n");
4211 mutex_lock(&priv
->mutex
);
4212 spin_lock_irqsave(&priv
->lock
, flags
);
4214 if (!iwl_is_ready_rf(priv
)) {
4216 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
4220 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
4222 IWL_ERROR("ERROR: APs don't scan\n");
4226 /* we don't schedule scan within next_scan_jiffies period */
4227 if (priv
->next_scan_jiffies
&&
4228 time_after(priv
->next_scan_jiffies
, jiffies
)) {
4232 /* if we just finished scan ask for delay */
4233 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
4234 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
4239 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
4240 iwl4965_escape_essid(ssid
, len
), (int)len
);
4242 priv
->one_direct_scan
= 1;
4243 priv
->direct_ssid_len
= (u8
)
4244 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
4245 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
4247 priv
->one_direct_scan
= 0;
4249 rc
= iwl4965_scan_initiate(priv
);
4251 IWL_DEBUG_MAC80211("leave\n");
4254 spin_unlock_irqrestore(&priv
->lock
, flags
);
4255 mutex_unlock(&priv
->mutex
);
4260 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw
*hw
,
4261 struct ieee80211_key_conf
*keyconf
, const u8
*addr
,
4262 u32 iv32
, u16
*phase1key
)
4264 struct iwl_priv
*priv
= hw
->priv
;
4265 u8 sta_id
= IWL_INVALID_STATION
;
4266 unsigned long flags
;
4267 __le16 key_flags
= 0;
4269 DECLARE_MAC_BUF(mac
);
4271 IWL_DEBUG_MAC80211("enter\n");
4273 sta_id
= iwl_find_station(priv
, addr
);
4274 if (sta_id
== IWL_INVALID_STATION
) {
4275 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
4276 print_mac(mac
, addr
));
4280 iwl4965_scan_cancel_timeout(priv
, 100);
4282 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
4283 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
4284 key_flags
&= ~STA_KEY_FLG_INVALID
;
4286 if (sta_id
== priv
->hw_params
.bcast_sta_id
)
4287 key_flags
|= STA_KEY_MULTICAST_MSK
;
4289 spin_lock_irqsave(&priv
->sta_lock
, flags
);
4291 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
4292 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
4294 for (i
= 0; i
< 5; i
++)
4295 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
4296 cpu_to_le16(phase1key
[i
]);
4298 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
4299 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
4301 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
4303 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
4305 IWL_DEBUG_MAC80211("leave\n");
4308 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
4309 const u8
*local_addr
, const u8
*addr
,
4310 struct ieee80211_key_conf
*key
)
4312 struct iwl_priv
*priv
= hw
->priv
;
4313 DECLARE_MAC_BUF(mac
);
4315 u8 sta_id
= IWL_INVALID_STATION
;
4316 u8 is_default_wep_key
= 0;
4318 IWL_DEBUG_MAC80211("enter\n");
4320 if (priv
->hw_params
.sw_crypto
) {
4321 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
4325 if (is_zero_ether_addr(addr
))
4326 /* only support pairwise keys */
4329 sta_id
= iwl_find_station(priv
, addr
);
4330 if (sta_id
== IWL_INVALID_STATION
) {
4331 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
4332 print_mac(mac
, addr
));
4337 mutex_lock(&priv
->mutex
);
4338 iwl4965_scan_cancel_timeout(priv
, 100);
4339 mutex_unlock(&priv
->mutex
);
4341 /* If we are getting WEP group key and we didn't receive any key mapping
4342 * so far, we are in legacy wep mode (group key only), otherwise we are
4344 * In legacy wep mode, we use another host command to the uCode */
4345 if (key
->alg
== ALG_WEP
&& sta_id
== priv
->hw_params
.bcast_sta_id
&&
4346 priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
4348 is_default_wep_key
= !priv
->key_mapping_key
;
4350 is_default_wep_key
=
4351 (key
->hw_key_idx
== HW_KEY_DEFAULT
);
4356 if (is_default_wep_key
)
4357 ret
= iwl_set_default_wep_key(priv
, key
);
4359 ret
= iwl_set_dynamic_key(priv
, key
, sta_id
);
4361 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
4364 if (is_default_wep_key
)
4365 ret
= iwl_remove_default_wep_key(priv
, key
);
4367 ret
= iwl_remove_dynamic_key(priv
, key
, sta_id
);
4369 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
4375 IWL_DEBUG_MAC80211("leave\n");
4380 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
4381 const struct ieee80211_tx_queue_params
*params
)
4383 struct iwl_priv
*priv
= hw
->priv
;
4384 unsigned long flags
;
4387 IWL_DEBUG_MAC80211("enter\n");
4389 if (!iwl_is_ready_rf(priv
)) {
4390 IWL_DEBUG_MAC80211("leave - RF not ready\n");
4394 if (queue
>= AC_NUM
) {
4395 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
4399 if (!priv
->qos_data
.qos_enable
) {
4400 priv
->qos_data
.qos_active
= 0;
4401 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
4404 q
= AC_NUM
- 1 - queue
;
4406 spin_lock_irqsave(&priv
->lock
, flags
);
4408 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
4409 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
4410 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
4411 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
4412 cpu_to_le16((params
->txop
* 32));
4414 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
4415 priv
->qos_data
.qos_active
= 1;
4417 spin_unlock_irqrestore(&priv
->lock
, flags
);
4419 mutex_lock(&priv
->mutex
);
4420 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
4421 iwl4965_activate_qos(priv
, 1);
4422 else if (priv
->assoc_id
&& iwl_is_associated(priv
))
4423 iwl4965_activate_qos(priv
, 0);
4425 mutex_unlock(&priv
->mutex
);
4427 IWL_DEBUG_MAC80211("leave\n");
4431 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
4432 struct ieee80211_tx_queue_stats
*stats
)
4434 struct iwl_priv
*priv
= hw
->priv
;
4436 struct iwl_tx_queue
*txq
;
4437 struct iwl_queue
*q
;
4438 unsigned long flags
;
4440 IWL_DEBUG_MAC80211("enter\n");
4442 if (!iwl_is_ready_rf(priv
)) {
4443 IWL_DEBUG_MAC80211("leave - RF not ready\n");
4447 spin_lock_irqsave(&priv
->lock
, flags
);
4449 for (i
= 0; i
< AC_NUM
; i
++) {
4450 txq
= &priv
->txq
[i
];
4452 avail
= iwl_queue_space(q
);
4454 stats
[i
].len
= q
->n_window
- avail
;
4455 stats
[i
].limit
= q
->n_window
- q
->high_mark
;
4456 stats
[i
].count
= q
->n_window
;
4459 spin_unlock_irqrestore(&priv
->lock
, flags
);
4461 IWL_DEBUG_MAC80211("leave\n");
4466 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
4467 struct ieee80211_low_level_stats
*stats
)
4469 struct iwl_priv
*priv
= hw
->priv
;
4472 IWL_DEBUG_MAC80211("enter\n");
4473 IWL_DEBUG_MAC80211("leave\n");
4478 static u64
iwl4965_mac_get_tsf(struct ieee80211_hw
*hw
)
4480 struct iwl_priv
*priv
;
4483 IWL_DEBUG_MAC80211("enter\n");
4484 IWL_DEBUG_MAC80211("leave\n");
4489 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
4491 struct iwl_priv
*priv
= hw
->priv
;
4492 unsigned long flags
;
4494 mutex_lock(&priv
->mutex
);
4495 IWL_DEBUG_MAC80211("enter\n");
4497 priv
->lq_mngr
.lq_ready
= 0;
4498 spin_lock_irqsave(&priv
->lock
, flags
);
4499 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
4500 spin_unlock_irqrestore(&priv
->lock
, flags
);
4502 iwl_reset_qos(priv
);
4504 cancel_delayed_work(&priv
->post_associate
);
4506 spin_lock_irqsave(&priv
->lock
, flags
);
4508 priv
->assoc_capability
= 0;
4509 priv
->assoc_station_added
= 0;
4511 /* new association get rid of ibss beacon skb */
4512 if (priv
->ibss_beacon
)
4513 dev_kfree_skb(priv
->ibss_beacon
);
4515 priv
->ibss_beacon
= NULL
;
4517 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
4518 priv
->timestamp
= 0;
4519 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
4520 priv
->beacon_int
= 0;
4522 spin_unlock_irqrestore(&priv
->lock
, flags
);
4524 if (!iwl_is_ready_rf(priv
)) {
4525 IWL_DEBUG_MAC80211("leave - not ready\n");
4526 mutex_unlock(&priv
->mutex
);
4530 /* we are restarting association process
4531 * clear RXON_FILTER_ASSOC_MSK bit
4533 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
4534 iwl4965_scan_cancel_timeout(priv
, 100);
4535 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4536 iwl4965_commit_rxon(priv
);
4539 iwl_power_update_mode(priv
, 0);
4541 /* Per mac80211.h: This is only used in IBSS mode... */
4542 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
4544 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
4545 mutex_unlock(&priv
->mutex
);
4549 iwl4965_set_rate(priv
);
4551 mutex_unlock(&priv
->mutex
);
4553 IWL_DEBUG_MAC80211("leave\n");
4556 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
4558 struct iwl_priv
*priv
= hw
->priv
;
4559 unsigned long flags
;
4561 mutex_lock(&priv
->mutex
);
4562 IWL_DEBUG_MAC80211("enter\n");
4564 if (!iwl_is_ready_rf(priv
)) {
4565 IWL_DEBUG_MAC80211("leave - RF not ready\n");
4566 mutex_unlock(&priv
->mutex
);
4570 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
4571 IWL_DEBUG_MAC80211("leave - not IBSS\n");
4572 mutex_unlock(&priv
->mutex
);
4576 spin_lock_irqsave(&priv
->lock
, flags
);
4578 if (priv
->ibss_beacon
)
4579 dev_kfree_skb(priv
->ibss_beacon
);
4581 priv
->ibss_beacon
= skb
;
4585 IWL_DEBUG_MAC80211("leave\n");
4586 spin_unlock_irqrestore(&priv
->lock
, flags
);
4588 iwl_reset_qos(priv
);
4590 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
4592 mutex_unlock(&priv
->mutex
);
4597 /*****************************************************************************
4601 *****************************************************************************/
4603 #ifdef CONFIG_IWLWIFI_DEBUG
4606 * The following adds a new attribute to the sysfs representation
4607 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4608 * used for controlling the debug level.
4610 * See the level definitions in iwl for details.
4613 static ssize_t
show_debug_level(struct device
*d
,
4614 struct device_attribute
*attr
, char *buf
)
4616 struct iwl_priv
*priv
= d
->driver_data
;
4618 return sprintf(buf
, "0x%08X\n", priv
->debug_level
);
4620 static ssize_t
store_debug_level(struct device
*d
,
4621 struct device_attribute
*attr
,
4622 const char *buf
, size_t count
)
4624 struct iwl_priv
*priv
= d
->driver_data
;
4625 char *p
= (char *)buf
;
4628 val
= simple_strtoul(p
, &p
, 0);
4630 printk(KERN_INFO DRV_NAME
4631 ": %s is not in hex or decimal form.\n", buf
);
4633 priv
->debug_level
= val
;
4635 return strnlen(buf
, count
);
4638 static DEVICE_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
4639 show_debug_level
, store_debug_level
);
4642 #endif /* CONFIG_IWLWIFI_DEBUG */
4645 static ssize_t
show_version(struct device
*d
,
4646 struct device_attribute
*attr
, char *buf
)
4648 struct iwl_priv
*priv
= d
->driver_data
;
4649 struct iwl_alive_resp
*palive
= &priv
->card_alive
;
4651 if (palive
->is_valid
)
4652 return sprintf(buf
, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
4653 "fw type: 0x%01X 0x%01X\n",
4654 palive
->ucode_major
, palive
->ucode_minor
,
4655 palive
->sw_rev
[0], palive
->sw_rev
[1],
4656 palive
->ver_type
, palive
->ver_subtype
);
4659 return sprintf(buf
, "fw not loaded\n");
4662 static DEVICE_ATTR(version
, S_IWUSR
| S_IRUGO
, show_version
, NULL
);
4664 static ssize_t
show_temperature(struct device
*d
,
4665 struct device_attribute
*attr
, char *buf
)
4667 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
4669 if (!iwl_is_alive(priv
))
4672 return sprintf(buf
, "%d\n", iwl4965_hw_get_temperature(priv
));
4675 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
4677 static ssize_t
show_rs_window(struct device
*d
,
4678 struct device_attribute
*attr
,
4681 struct iwl_priv
*priv
= d
->driver_data
;
4682 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
4684 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
4686 static ssize_t
show_tx_power(struct device
*d
,
4687 struct device_attribute
*attr
, char *buf
)
4689 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
4690 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
4693 static ssize_t
store_tx_power(struct device
*d
,
4694 struct device_attribute
*attr
,
4695 const char *buf
, size_t count
)
4697 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
4698 char *p
= (char *)buf
;
4701 val
= simple_strtoul(p
, &p
, 10);
4703 printk(KERN_INFO DRV_NAME
4704 ": %s is not in decimal form.\n", buf
);
4706 iwl4965_hw_reg_set_txpower(priv
, val
);
4711 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
4713 static ssize_t
show_flags(struct device
*d
,
4714 struct device_attribute
*attr
, char *buf
)
4716 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
4718 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
4721 static ssize_t
store_flags(struct device
*d
,
4722 struct device_attribute
*attr
,
4723 const char *buf
, size_t count
)
4725 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
4726 u32 flags
= simple_strtoul(buf
, NULL
, 0);
4728 mutex_lock(&priv
->mutex
);
4729 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
4730 /* Cancel any currently running scans... */
4731 if (iwl4965_scan_cancel_timeout(priv
, 100))
4732 IWL_WARNING("Could not cancel scan.\n");
4734 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
4736 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
4737 iwl4965_commit_rxon(priv
);
4740 mutex_unlock(&priv
->mutex
);
4745 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
4747 static ssize_t
show_filter_flags(struct device
*d
,
4748 struct device_attribute
*attr
, char *buf
)
4750 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
4752 return sprintf(buf
, "0x%04X\n",
4753 le32_to_cpu(priv
->active_rxon
.filter_flags
));
4756 static ssize_t
store_filter_flags(struct device
*d
,
4757 struct device_attribute
*attr
,
4758 const char *buf
, size_t count
)
4760 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
4761 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
4763 mutex_lock(&priv
->mutex
);
4764 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
4765 /* Cancel any currently running scans... */
4766 if (iwl4965_scan_cancel_timeout(priv
, 100))
4767 IWL_WARNING("Could not cancel scan.\n");
4769 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
4770 "0x%04X\n", filter_flags
);
4771 priv
->staging_rxon
.filter_flags
=
4772 cpu_to_le32(filter_flags
);
4773 iwl4965_commit_rxon(priv
);
4776 mutex_unlock(&priv
->mutex
);
4781 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
4782 store_filter_flags
);
4784 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
4786 static ssize_t
show_measurement(struct device
*d
,
4787 struct device_attribute
*attr
, char *buf
)
4789 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4790 struct iwl4965_spectrum_notification measure_report
;
4791 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
4792 u8
*data
= (u8
*) & measure_report
;
4793 unsigned long flags
;
4795 spin_lock_irqsave(&priv
->lock
, flags
);
4796 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
4797 spin_unlock_irqrestore(&priv
->lock
, flags
);
4800 memcpy(&measure_report
, &priv
->measure_report
, size
);
4801 priv
->measurement_status
= 0;
4802 spin_unlock_irqrestore(&priv
->lock
, flags
);
4804 while (size
&& (PAGE_SIZE
- len
)) {
4805 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
4806 PAGE_SIZE
- len
, 1);
4808 if (PAGE_SIZE
- len
)
4812 size
-= min(size
, 16U);
4818 static ssize_t
store_measurement(struct device
*d
,
4819 struct device_attribute
*attr
,
4820 const char *buf
, size_t count
)
4822 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4823 struct ieee80211_measurement_params params
= {
4824 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
4825 .start_time
= cpu_to_le64(priv
->last_tsf
),
4826 .duration
= cpu_to_le16(1),
4828 u8 type
= IWL_MEASURE_BASIC
;
4834 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
4835 channel
= simple_strtoul(p
, NULL
, 0);
4837 params
.channel
= channel
;
4840 while (*p
&& *p
!= ' ')
4843 type
= simple_strtoul(p
+ 1, NULL
, 0);
4846 IWL_DEBUG_INFO("Invoking measurement of type %d on "
4847 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
4848 iwl4965_get_measurement(priv
, ¶ms
, type
);
4853 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
4854 show_measurement
, store_measurement
);
4855 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
4857 static ssize_t
store_retry_rate(struct device
*d
,
4858 struct device_attribute
*attr
,
4859 const char *buf
, size_t count
)
4861 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4863 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
4864 if (priv
->retry_rate
<= 0)
4865 priv
->retry_rate
= 1;
4870 static ssize_t
show_retry_rate(struct device
*d
,
4871 struct device_attribute
*attr
, char *buf
)
4873 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4874 return sprintf(buf
, "%d", priv
->retry_rate
);
4877 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
4880 static ssize_t
store_power_level(struct device
*d
,
4881 struct device_attribute
*attr
,
4882 const char *buf
, size_t count
)
4884 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4888 mode
= simple_strtoul(buf
, NULL
, 0);
4889 mutex_lock(&priv
->mutex
);
4891 if (!iwl_is_ready(priv
)) {
4896 rc
= iwl_power_set_user_mode(priv
, mode
);
4898 IWL_DEBUG_MAC80211("failed setting power mode.\n");
4904 mutex_unlock(&priv
->mutex
);
4908 #define MAX_WX_STRING 80
4910 /* Values are in microsecond */
4911 static const s32 timeout_duration
[] = {
4918 static const s32 period_duration
[] = {
4926 static ssize_t
show_power_level(struct device
*d
,
4927 struct device_attribute
*attr
, char *buf
)
4929 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4930 int level
= priv
->power_data
.power_mode
;
4933 p
+= sprintf(p
, "%d ", level
);
4935 case IWL_POWER_MODE_CAM
:
4937 p
+= sprintf(p
, "(AC)");
4939 case IWL_POWER_BATTERY
:
4940 p
+= sprintf(p
, "(BATTERY)");
4944 "(Timeout %dms, Period %dms)",
4945 timeout_duration
[level
- 1] / 1000,
4946 period_duration
[level
- 1] / 1000);
4949 if (!(priv->power_mode & IWL_POWER_ENABLED))
4950 p += sprintf(p, " OFF\n");
4952 p += sprintf(p, " \n");
4954 p
+= sprintf(p
, " \n");
4955 return (p
- buf
+ 1);
4958 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
4961 static ssize_t
show_channels(struct device
*d
,
4962 struct device_attribute
*attr
, char *buf
)
4964 /* all this shit doesn't belong into sysfs anyway */
4968 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
4970 static ssize_t
show_statistics(struct device
*d
,
4971 struct device_attribute
*attr
, char *buf
)
4973 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4974 u32 size
= sizeof(struct iwl4965_notif_statistics
);
4975 u32 len
= 0, ofs
= 0;
4976 u8
*data
= (u8
*) & priv
->statistics
;
4979 if (!iwl_is_alive(priv
))
4982 mutex_lock(&priv
->mutex
);
4983 rc
= iwl_send_statistics_request(priv
, 0);
4984 mutex_unlock(&priv
->mutex
);
4988 "Error sending statistics request: 0x%08X\n", rc
);
4992 while (size
&& (PAGE_SIZE
- len
)) {
4993 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
4994 PAGE_SIZE
- len
, 1);
4996 if (PAGE_SIZE
- len
)
5000 size
-= min(size
, 16U);
5006 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
5008 static ssize_t
show_status(struct device
*d
,
5009 struct device_attribute
*attr
, char *buf
)
5011 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
5012 if (!iwl_is_alive(priv
))
5014 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
5017 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
5019 /*****************************************************************************
5021 * driver setup and teardown
5023 *****************************************************************************/
5025 static void iwl4965_setup_deferred_work(struct iwl_priv
*priv
)
5027 priv
->workqueue
= create_workqueue(DRV_NAME
);
5029 init_waitqueue_head(&priv
->wait_command_queue
);
5031 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
5032 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
5033 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
5034 INIT_WORK(&priv
->scan_completed
, iwl4965_bg_scan_completed
);
5035 INIT_WORK(&priv
->request_scan
, iwl4965_bg_request_scan
);
5036 INIT_WORK(&priv
->abort_scan
, iwl4965_bg_abort_scan
);
5037 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
5038 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
5039 INIT_WORK(&priv
->set_monitor
, iwl4965_bg_set_monitor
);
5040 INIT_WORK(&priv
->run_time_calib_work
, iwl_bg_run_time_calib_work
);
5041 INIT_DELAYED_WORK(&priv
->post_associate
, iwl4965_bg_post_associate
);
5042 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl_bg_init_alive_start
);
5043 INIT_DELAYED_WORK(&priv
->alive_start
, iwl_bg_alive_start
);
5044 INIT_DELAYED_WORK(&priv
->scan_check
, iwl4965_bg_scan_check
);
5046 iwl4965_hw_setup_deferred_work(priv
);
5048 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
5049 iwl4965_irq_tasklet
, (unsigned long)priv
);
5052 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
)
5054 iwl4965_hw_cancel_deferred_work(priv
);
5056 cancel_delayed_work_sync(&priv
->init_alive_start
);
5057 cancel_delayed_work(&priv
->scan_check
);
5058 cancel_delayed_work(&priv
->alive_start
);
5059 cancel_delayed_work(&priv
->post_associate
);
5060 cancel_work_sync(&priv
->beacon_update
);
5063 static struct attribute
*iwl4965_sysfs_entries
[] = {
5064 &dev_attr_channels
.attr
,
5065 &dev_attr_flags
.attr
,
5066 &dev_attr_filter_flags
.attr
,
5067 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
5068 &dev_attr_measurement
.attr
,
5070 &dev_attr_power_level
.attr
,
5071 &dev_attr_retry_rate
.attr
,
5072 &dev_attr_rs_window
.attr
,
5073 &dev_attr_statistics
.attr
,
5074 &dev_attr_status
.attr
,
5075 &dev_attr_temperature
.attr
,
5076 &dev_attr_tx_power
.attr
,
5077 #ifdef CONFIG_IWLWIFI_DEBUG
5078 &dev_attr_debug_level
.attr
,
5080 &dev_attr_version
.attr
,
5085 static struct attribute_group iwl4965_attribute_group
= {
5086 .name
= NULL
, /* put in device directory */
5087 .attrs
= iwl4965_sysfs_entries
,
5090 static struct ieee80211_ops iwl4965_hw_ops
= {
5091 .tx
= iwl4965_mac_tx
,
5092 .start
= iwl4965_mac_start
,
5093 .stop
= iwl4965_mac_stop
,
5094 .add_interface
= iwl4965_mac_add_interface
,
5095 .remove_interface
= iwl4965_mac_remove_interface
,
5096 .config
= iwl4965_mac_config
,
5097 .config_interface
= iwl4965_mac_config_interface
,
5098 .configure_filter
= iwl4965_configure_filter
,
5099 .set_key
= iwl4965_mac_set_key
,
5100 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
5101 .get_stats
= iwl4965_mac_get_stats
,
5102 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
5103 .conf_tx
= iwl4965_mac_conf_tx
,
5104 .get_tsf
= iwl4965_mac_get_tsf
,
5105 .reset_tsf
= iwl4965_mac_reset_tsf
,
5106 .beacon_update
= iwl4965_mac_beacon_update
,
5107 .bss_info_changed
= iwl4965_bss_info_changed
,
5108 .ampdu_action
= iwl4965_mac_ampdu_action
,
5109 .hw_scan
= iwl4965_mac_hw_scan
5112 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
5115 struct iwl_priv
*priv
;
5116 struct ieee80211_hw
*hw
;
5117 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
5118 unsigned long flags
;
5119 DECLARE_MAC_BUF(mac
);
5121 /************************
5122 * 1. Allocating HW data
5123 ************************/
5125 /* Disabling hardware scan means that mac80211 will perform scans
5126 * "the hard way", rather than using device's scan. */
5127 if (cfg
->mod_params
->disable_hw_scan
) {
5128 if (cfg
->mod_params
->debug
& IWL_DL_INFO
)
5129 dev_printk(KERN_DEBUG
, &(pdev
->dev
),
5130 "Disabling hw_scan\n");
5131 iwl4965_hw_ops
.hw_scan
= NULL
;
5134 hw
= iwl_alloc_all(cfg
, &iwl4965_hw_ops
);
5140 /* At this point both hw and priv are allocated. */
5142 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
5144 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
5146 priv
->pci_dev
= pdev
;
5148 #ifdef CONFIG_IWLWIFI_DEBUG
5149 priv
->debug_level
= priv
->cfg
->mod_params
->debug
;
5150 atomic_set(&priv
->restrict_refcnt
, 0);
5153 /**************************
5154 * 2. Initializing PCI bus
5155 **************************/
5156 if (pci_enable_device(pdev
)) {
5158 goto out_ieee80211_free_hw
;
5161 pci_set_master(pdev
);
5163 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
5165 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
5167 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
5169 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
5170 /* both attempts failed: */
5172 printk(KERN_WARNING
"%s: No suitable DMA available.\n",
5174 goto out_pci_disable_device
;
5178 err
= pci_request_regions(pdev
, DRV_NAME
);
5180 goto out_pci_disable_device
;
5182 pci_set_drvdata(pdev
, priv
);
5184 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5185 * PCI Tx retries from interfering with C3 CPU state */
5186 pci_write_config_byte(pdev
, 0x41, 0x00);
5188 /***********************
5189 * 3. Read REV register
5190 ***********************/
5191 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
5192 if (!priv
->hw_base
) {
5194 goto out_pci_release_regions
;
5197 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
5198 (unsigned long long) pci_resource_len(pdev
, 0));
5199 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
5201 iwl_hw_detect(priv
);
5202 printk(KERN_INFO DRV_NAME
5203 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
5204 priv
->cfg
->name
, priv
->hw_rev
);
5207 err
= priv
->cfg
->ops
->lib
->apm_ops
.init(priv
);
5209 IWL_DEBUG_INFO("Failed to init APMG\n");
5215 /* Read the EEPROM */
5216 err
= iwl_eeprom_init(priv
);
5218 IWL_ERROR("Unable to init EEPROM\n");
5221 err
= iwl_eeprom_check_version(priv
);
5225 /* extract MAC Address */
5226 iwl_eeprom_get_mac(priv
, priv
->mac_addr
);
5227 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
5228 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
5230 /************************
5231 * 5. Setup HW constants
5232 ************************/
5233 /* Device-specific setup */
5234 if (priv
->cfg
->ops
->lib
->set_hw_params(priv
)) {
5235 IWL_ERROR("failed to set hw parameters\n");
5236 goto out_free_eeprom
;
5239 /*******************
5241 *******************/
5243 err
= iwl_init_drv(priv
);
5245 goto out_free_eeprom
;
5246 /* At this point both hw and priv are initialized. */
5248 /**********************************
5249 * 7. Initialize module parameters
5250 **********************************/
5252 /* Disable radio (SW RF KILL) via parameter when loading driver */
5253 if (priv
->cfg
->mod_params
->disable
) {
5254 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
5255 IWL_DEBUG_INFO("Radio disabled.\n");
5258 /********************
5260 ********************/
5261 spin_lock_irqsave(&priv
->lock
, flags
);
5262 iwl4965_disable_interrupts(priv
);
5263 spin_unlock_irqrestore(&priv
->lock
, flags
);
5265 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
5267 IWL_ERROR("failed to create sysfs device attributes\n");
5268 goto out_uninit_drv
;
5272 iwl4965_setup_deferred_work(priv
);
5273 iwl4965_setup_rx_handlers(priv
);
5275 /********************
5277 ********************/
5278 pci_save_state(pdev
);
5279 pci_disable_device(pdev
);
5281 /**********************************
5282 * 10. Setup and register mac80211
5283 **********************************/
5285 err
= iwl_setup_mac(priv
);
5287 goto out_remove_sysfs
;
5289 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
5291 IWL_ERROR("failed to create debugfs files\n");
5293 /* notify iwlcore to init */
5294 iwlcore_low_level_notify(priv
, IWLCORE_INIT_EVT
);
5298 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
5300 iwl_uninit_drv(priv
);
5302 iwl_eeprom_free(priv
);
5304 pci_iounmap(pdev
, priv
->hw_base
);
5305 out_pci_release_regions
:
5306 pci_release_regions(pdev
);
5307 pci_set_drvdata(pdev
, NULL
);
5308 out_pci_disable_device
:
5309 pci_disable_device(pdev
);
5310 out_ieee80211_free_hw
:
5311 ieee80211_free_hw(priv
->hw
);
5316 static void __devexit
iwl4965_pci_remove(struct pci_dev
*pdev
)
5318 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
5319 struct list_head
*p
, *q
;
5321 unsigned long flags
;
5326 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
5328 iwl_dbgfs_unregister(priv
);
5329 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
5331 if (priv
->mac80211_registered
) {
5332 ieee80211_unregister_hw(priv
->hw
);
5333 priv
->mac80211_registered
= 0;
5336 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5340 /* make sure we flush any pending irq or
5341 * tasklet for the driver
5343 spin_lock_irqsave(&priv
->lock
, flags
);
5344 iwl4965_disable_interrupts(priv
);
5345 spin_unlock_irqrestore(&priv
->lock
, flags
);
5347 iwl_synchronize_irq(priv
);
5349 /* Free MAC hash list for ADHOC */
5350 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
5351 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
5353 kfree(list_entry(p
, struct iwl4965_ibss_seq
, list
));
5357 iwlcore_low_level_notify(priv
, IWLCORE_REMOVE_EVT
);
5359 iwl4965_dealloc_ucode_pci(priv
);
5362 iwl_rx_queue_free(priv
, &priv
->rxq
);
5363 iwl_hw_txq_ctx_free(priv
);
5365 iwlcore_clear_stations_table(priv
);
5366 iwl_eeprom_free(priv
);
5369 /*netif_stop_queue(dev); */
5370 flush_workqueue(priv
->workqueue
);
5372 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
5373 * priv->workqueue... so we can't take down the workqueue
5375 destroy_workqueue(priv
->workqueue
);
5376 priv
->workqueue
= NULL
;
5378 pci_iounmap(pdev
, priv
->hw_base
);
5379 pci_release_regions(pdev
);
5380 pci_disable_device(pdev
);
5381 pci_set_drvdata(pdev
, NULL
);
5383 iwl_uninit_drv(priv
);
5385 if (priv
->ibss_beacon
)
5386 dev_kfree_skb(priv
->ibss_beacon
);
5388 ieee80211_free_hw(priv
->hw
);
5393 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
5395 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
5397 if (priv
->is_open
) {
5398 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
5399 iwl4965_mac_stop(priv
->hw
);
5403 pci_set_power_state(pdev
, PCI_D3hot
);
5408 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
5410 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
5412 pci_set_power_state(pdev
, PCI_D0
);
5415 iwl4965_mac_start(priv
->hw
);
5417 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
5421 #endif /* CONFIG_PM */
5423 /*****************************************************************************
5425 * driver and module entry point
5427 *****************************************************************************/
5429 /* Hardware specific file defines the PCI IDs table for that hardware module */
5430 static struct pci_device_id iwl_hw_card_ids
[] = {
5431 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID
, iwl4965_agn_cfg
)},
5432 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID
, iwl4965_agn_cfg
)},
5433 #ifdef CONFIG_IWL5000
5434 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID
, iwl5300_agn_cfg
)},
5435 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID
, iwl5100_agn_cfg
)},
5436 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID
, iwl5350_agn_cfg
)},
5437 #endif /* CONFIG_IWL5000 */
5440 MODULE_DEVICE_TABLE(pci
, iwl_hw_card_ids
);
5442 static struct pci_driver iwl_driver
= {
5444 .id_table
= iwl_hw_card_ids
,
5445 .probe
= iwl4965_pci_probe
,
5446 .remove
= __devexit_p(iwl4965_pci_remove
),
5448 .suspend
= iwl4965_pci_suspend
,
5449 .resume
= iwl4965_pci_resume
,
5453 static int __init
iwl4965_init(void)
5457 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
5458 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
5460 ret
= iwl4965_rate_control_register();
5462 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret
);
5466 ret
= pci_register_driver(&iwl_driver
);
5468 IWL_ERROR("Unable to initialize PCI module\n");
5469 goto error_register
;
5475 iwl4965_rate_control_unregister();
5479 static void __exit
iwl4965_exit(void)
5481 pci_unregister_driver(&iwl_driver
);
5482 iwl4965_rate_control_unregister();
5485 module_exit(iwl4965_exit
);
5486 module_init(iwl4965_init
);