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 /*************** STATION TABLE MANAGEMENT ****
91 * mac80211 should be examined to determine if sta_info is duplicating
92 * the functionality provided here
95 /**************************************************************/
99 static void iwl4965_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
101 struct iwl_rxon_cmd
*rxon
= &priv
->staging_rxon
;
104 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
106 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
111 * iwl4965_check_rxon_cmd - validate RXON structure is valid
113 * NOTE: This is really only useful during development and can eventually
114 * be #ifdef'd out once the driver is stable and folks aren't actively
117 static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd
*rxon
)
122 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
123 error
|= le32_to_cpu(rxon
->flags
&
124 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
125 RXON_FLG_RADAR_DETECT_MSK
));
127 IWL_WARNING("check 24G fields %d | %d\n",
130 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
131 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
133 IWL_WARNING("check 52 fields %d | %d\n",
135 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
137 IWL_WARNING("check 52 CCK %d | %d\n",
140 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
142 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
144 /* make sure basic rates 6Mbps and 1Mbps are supported */
145 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
146 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
148 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
150 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
152 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
154 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
155 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
157 IWL_WARNING("check CCK and short slot %d | %d\n",
160 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
161 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
163 IWL_WARNING("check CCK & auto detect %d | %d\n",
166 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
167 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
169 IWL_WARNING("check TGG and auto detect %d | %d\n",
173 IWL_WARNING("Tuning to channel %d\n",
174 le16_to_cpu(rxon
->channel
));
177 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
184 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
185 * @priv: staging_rxon is compared to active_rxon
187 * If the RXON structure is changing enough to require a new tune,
188 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
189 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
191 static int iwl4965_full_rxon_required(struct iwl_priv
*priv
)
194 /* These items are only settable from the full RXON command */
195 if (!(iwl_is_associated(priv
)) ||
196 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
197 priv
->active_rxon
.bssid_addr
) ||
198 compare_ether_addr(priv
->staging_rxon
.node_addr
,
199 priv
->active_rxon
.node_addr
) ||
200 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
201 priv
->active_rxon
.wlap_bssid_addr
) ||
202 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
203 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
204 (priv
->staging_rxon
.air_propagation
!=
205 priv
->active_rxon
.air_propagation
) ||
206 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
207 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
208 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
209 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
210 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
211 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
214 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
215 * be updated with the RXON_ASSOC command -- however only some
216 * flag transitions are allowed using RXON_ASSOC */
218 /* Check if we are not switching bands */
219 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
220 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
223 /* Check if we are switching association toggle */
224 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
225 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
232 * iwl4965_commit_rxon - commit staging_rxon to hardware
234 * The RXON command in staging_rxon is committed to the hardware and
235 * the active_rxon structure is updated with the new data. This
236 * function correctly transitions out of the RXON_ASSOC_MSK state if
237 * a HW tune is required based on the RXON structure changes.
239 static int iwl4965_commit_rxon(struct iwl_priv
*priv
)
241 /* cast away the const for active_rxon in this function */
242 struct iwl_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
243 DECLARE_MAC_BUF(mac
);
246 !!(priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
248 if (!iwl_is_alive(priv
))
251 /* always get timestamp with Rx frame */
252 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
253 /* allow CTS-to-self if possible. this is relevant only for
254 * 5000, but will not damage 4965 */
255 priv
->staging_rxon
.flags
|= RXON_FLG_SELF_CTS_EN
;
257 ret
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
259 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
263 /* If we don't need to send a full RXON, we can use
264 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
265 * and other flags for the current radio configuration. */
266 if (!iwl4965_full_rxon_required(priv
)) {
267 ret
= iwl_send_rxon_assoc(priv
);
269 IWL_ERROR("Error setting RXON_ASSOC (%d)\n", ret
);
273 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
277 /* station table will be cleared */
278 priv
->assoc_station_added
= 0;
280 /* If we are currently associated and the new config requires
281 * an RXON_ASSOC and the new config wants the associated mask enabled,
282 * we must clear the associated from the active configuration
283 * before we apply the new config */
284 if (iwl_is_associated(priv
) && new_assoc
) {
285 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
286 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
288 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
289 sizeof(struct iwl_rxon_cmd
),
292 /* If the mask clearing failed then we set
293 * active_rxon back to what it was previously */
295 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
296 IWL_ERROR("Error clearing ASSOC_MSK (%d)\n", ret
);
301 IWL_DEBUG_INFO("Sending RXON\n"
302 "* with%s RXON_FILTER_ASSOC_MSK\n"
305 (new_assoc
? "" : "out"),
306 le16_to_cpu(priv
->staging_rxon
.channel
),
307 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
309 iwl4965_set_rxon_hwcrypto(priv
, !priv
->hw_params
.sw_crypto
);
311 /* Apply the new configuration
312 * RXON unassoc clears the station table in uCode, send it before
313 * we add the bcast station. If assoc bit is set, we will send RXON
314 * after having added the bcast and bssid station.
317 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
318 sizeof(struct iwl_rxon_cmd
), &priv
->staging_rxon
);
320 IWL_ERROR("Error setting new RXON (%d)\n", ret
);
323 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
326 iwl_clear_stations_table(priv
);
328 if (!priv
->error_recovering
)
329 priv
->start_calib
= 0;
331 iwl_init_sensitivity(priv
);
333 /* If we issue a new RXON command which required a tune then we must
334 * send a new TXPOWER command or we won't be able to Tx any frames */
335 ret
= iwl_set_tx_power(priv
, priv
->tx_power_user_lmt
, true);
337 IWL_ERROR("Error sending TX power (%d)\n", ret
);
341 /* Add the broadcast address so we can send broadcast frames */
342 if (iwl_rxon_add_station(priv
, iwl_bcast_addr
, 0) ==
343 IWL_INVALID_STATION
) {
344 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
348 /* If we have set the ASSOC_MSK and we are in BSS mode then
349 * add the IWL_AP_ID to the station rate table */
351 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
352 ret
= iwl_rxon_add_station(priv
,
353 priv
->active_rxon
.bssid_addr
, 1);
354 if (ret
== IWL_INVALID_STATION
) {
355 IWL_ERROR("Error adding AP address for TX.\n");
358 priv
->assoc_station_added
= 1;
359 if (priv
->default_wep_key
&&
360 iwl_send_static_wepkey_cmd(priv
, 0))
361 IWL_ERROR("Could not send WEP static key.\n");
364 /* Apply the new configuration
365 * RXON assoc doesn't clear the station table in uCode,
367 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
368 sizeof(struct iwl_rxon_cmd
), &priv
->staging_rxon
);
370 IWL_ERROR("Error setting new RXON (%d)\n", ret
);
373 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
379 void iwl4965_update_chain_flags(struct iwl_priv
*priv
)
382 iwl_set_rxon_chain(priv
);
383 iwl4965_commit_rxon(priv
);
386 static int iwl4965_send_bt_config(struct iwl_priv
*priv
)
388 struct iwl4965_bt_cmd bt_cmd
= {
396 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
397 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
400 static void iwl_clear_free_frames(struct iwl_priv
*priv
)
402 struct list_head
*element
;
404 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
407 while (!list_empty(&priv
->free_frames
)) {
408 element
= priv
->free_frames
.next
;
410 kfree(list_entry(element
, struct iwl_frame
, list
));
411 priv
->frames_count
--;
414 if (priv
->frames_count
) {
415 IWL_WARNING("%d frames still in use. Did we lose one?\n",
417 priv
->frames_count
= 0;
421 static struct iwl_frame
*iwl_get_free_frame(struct iwl_priv
*priv
)
423 struct iwl_frame
*frame
;
424 struct list_head
*element
;
425 if (list_empty(&priv
->free_frames
)) {
426 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
428 IWL_ERROR("Could not allocate frame!\n");
432 priv
->frames_count
++;
436 element
= priv
->free_frames
.next
;
438 return list_entry(element
, struct iwl_frame
, list
);
441 static void iwl_free_frame(struct iwl_priv
*priv
, struct iwl_frame
*frame
)
443 memset(frame
, 0, sizeof(*frame
));
444 list_add(&frame
->list
, &priv
->free_frames
);
447 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv
*priv
,
448 struct ieee80211_hdr
*hdr
,
449 const u8
*dest
, int left
)
452 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
453 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
454 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
457 if (priv
->ibss_beacon
->len
> left
)
460 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
462 return priv
->ibss_beacon
->len
;
465 static u8
iwl4965_rate_get_lowest_plcp(struct iwl_priv
*priv
)
471 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
472 rate_mask
= priv
->active_rate_basic
& 0xF;
474 rate_mask
= priv
->active_rate_basic
& 0xFF0;
476 /* Find lowest valid rate */
477 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
478 i
= iwl_rates
[i
].next_ieee
) {
479 if (rate_mask
& (1 << i
))
480 return iwl_rates
[i
].plcp
;
483 /* No valid rate was found. Assign the lowest one */
484 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
485 return IWL_RATE_1M_PLCP
;
487 return IWL_RATE_6M_PLCP
;
490 static int iwl4965_send_beacon_cmd(struct iwl_priv
*priv
)
492 struct iwl_frame
*frame
;
493 unsigned int frame_size
;
497 frame
= iwl_get_free_frame(priv
);
500 IWL_ERROR("Could not obtain free frame buffer for beacon "
505 rate
= iwl4965_rate_get_lowest_plcp(priv
);
507 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
509 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
512 iwl_free_frame(priv
, frame
);
517 /******************************************************************************
519 * Misc. internal state and helper functions
521 ******************************************************************************/
523 static void iwl4965_ht_conf(struct iwl_priv
*priv
,
524 struct ieee80211_bss_conf
*bss_conf
)
526 struct ieee80211_ht_info
*ht_conf
= bss_conf
->ht_conf
;
527 struct ieee80211_ht_bss_info
*ht_bss_conf
= bss_conf
->ht_bss_conf
;
528 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
530 IWL_DEBUG_MAC80211("enter: \n");
532 iwl_conf
->is_ht
= bss_conf
->assoc_ht
;
534 if (!iwl_conf
->is_ht
)
537 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
539 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
540 iwl_conf
->sgf
|= HT_SHORT_GI_20MHZ
;
541 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
542 iwl_conf
->sgf
|= HT_SHORT_GI_40MHZ
;
544 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
545 iwl_conf
->max_amsdu_size
=
546 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
548 iwl_conf
->supported_chan_width
=
549 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
550 iwl_conf
->extension_chan_offset
=
551 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
552 /* If no above or below channel supplied disable FAT channel */
553 if (iwl_conf
->extension_chan_offset
!= IEEE80211_HT_IE_CHA_SEC_ABOVE
&&
554 iwl_conf
->extension_chan_offset
!= IEEE80211_HT_IE_CHA_SEC_BELOW
) {
555 iwl_conf
->extension_chan_offset
= IEEE80211_HT_IE_CHA_SEC_NONE
;
556 iwl_conf
->supported_chan_width
= 0;
559 iwl_conf
->tx_mimo_ps_mode
=
560 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
561 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
563 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
564 iwl_conf
->tx_chan_width
=
565 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
566 iwl_conf
->ht_protection
=
567 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
568 iwl_conf
->non_GF_STA_present
=
569 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
571 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf
->control_channel
);
572 IWL_DEBUG_MAC80211("leave\n");
578 static int iwl4965_send_qos_params_command(struct iwl_priv
*priv
,
579 struct iwl4965_qosparam_cmd
*qos
)
582 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
583 sizeof(struct iwl4965_qosparam_cmd
), qos
);
586 static void iwl4965_activate_qos(struct iwl_priv
*priv
, u8 force
)
590 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
593 if (!priv
->qos_data
.qos_enable
)
596 spin_lock_irqsave(&priv
->lock
, flags
);
597 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
599 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
600 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
601 priv
->qos_data
.def_qos_parm
.qos_flags
|=
602 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
603 if (priv
->qos_data
.qos_active
)
604 priv
->qos_data
.def_qos_parm
.qos_flags
|=
605 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
607 if (priv
->current_ht_config
.is_ht
)
608 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
610 spin_unlock_irqrestore(&priv
->lock
, flags
);
612 if (force
|| iwl_is_associated(priv
)) {
613 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
614 priv
->qos_data
.qos_active
,
615 priv
->qos_data
.def_qos_parm
.qos_flags
);
617 iwl4965_send_qos_params_command(priv
,
618 &(priv
->qos_data
.def_qos_parm
));
622 #define MAX_UCODE_BEACON_INTERVAL 4096
623 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
625 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
628 u16 beacon_factor
= 0;
631 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
632 / MAX_UCODE_BEACON_INTERVAL
;
633 new_val
= beacon_val
/ beacon_factor
;
635 return cpu_to_le16(new_val
);
638 static void iwl4965_setup_rxon_timing(struct iwl_priv
*priv
)
640 u64 interval_tm_unit
;
643 struct ieee80211_conf
*conf
= NULL
;
646 conf
= ieee80211_get_hw_conf(priv
->hw
);
648 spin_lock_irqsave(&priv
->lock
, flags
);
649 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp
>> 32);
650 priv
->rxon_timing
.timestamp
.dw
[0] =
651 cpu_to_le32(priv
->timestamp
& 0xFFFFFFFF);
653 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
655 tsf
= priv
->timestamp
;
657 beacon_int
= priv
->beacon_int
;
658 spin_unlock_irqrestore(&priv
->lock
, flags
);
660 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
661 if (beacon_int
== 0) {
662 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
663 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
665 priv
->rxon_timing
.beacon_interval
=
666 cpu_to_le16(beacon_int
);
667 priv
->rxon_timing
.beacon_interval
=
668 iwl4965_adjust_beacon_interval(
669 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
672 priv
->rxon_timing
.atim_window
= 0;
674 priv
->rxon_timing
.beacon_interval
=
675 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
676 /* TODO: we need to get atim_window from upper stack
677 * for now we set to 0 */
678 priv
->rxon_timing
.atim_window
= 0;
682 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
683 result
= do_div(tsf
, interval_tm_unit
);
684 priv
->rxon_timing
.beacon_init_val
=
685 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
688 ("beacon interval %d beacon timer %d beacon tim %d\n",
689 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
690 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
691 le16_to_cpu(priv
->rxon_timing
.atim_window
));
694 static void iwl_set_flags_for_band(struct iwl_priv
*priv
,
695 enum ieee80211_band band
)
697 if (band
== IEEE80211_BAND_5GHZ
) {
698 priv
->staging_rxon
.flags
&=
699 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
701 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
703 /* Copied from iwl4965_post_associate() */
704 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
705 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
707 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
709 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
710 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
712 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
713 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
714 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
719 * initialize rxon structure with default values from eeprom
721 static void iwl4965_connection_init_rx_config(struct iwl_priv
*priv
)
723 const struct iwl_channel_info
*ch_info
;
725 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
727 switch (priv
->iw_mode
) {
728 case IEEE80211_IF_TYPE_AP
:
729 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
732 case IEEE80211_IF_TYPE_STA
:
733 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
734 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
737 case IEEE80211_IF_TYPE_IBSS
:
738 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
739 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
740 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
741 RXON_FILTER_ACCEPT_GRP_MSK
;
744 case IEEE80211_IF_TYPE_MNTR
:
745 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
746 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
747 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
750 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
755 /* TODO: Figure out when short_preamble would be set and cache from
757 if (!hw_to_local(priv
->hw
)->short_preamble
)
758 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
760 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
763 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
764 le16_to_cpu(priv
->active_rxon
.channel
));
767 ch_info
= &priv
->channel_info
[0];
770 * in some case A channels are all non IBSS
771 * in this case force B/G channel
773 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
774 !(is_channel_ibss(ch_info
)))
775 ch_info
= &priv
->channel_info
[0];
777 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
778 priv
->band
= ch_info
->band
;
780 iwl_set_flags_for_band(priv
, priv
->band
);
782 priv
->staging_rxon
.ofdm_basic_rates
=
783 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
784 priv
->staging_rxon
.cck_basic_rates
=
785 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
787 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
788 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
789 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
790 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
791 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
792 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
793 iwl_set_rxon_chain(priv
);
796 static int iwl4965_set_mode(struct iwl_priv
*priv
, int mode
)
798 priv
->iw_mode
= mode
;
800 iwl4965_connection_init_rx_config(priv
);
801 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
803 iwl_clear_stations_table(priv
);
805 /* dont commit rxon if rf-kill is on*/
806 if (!iwl_is_ready_rf(priv
))
809 cancel_delayed_work(&priv
->scan_check
);
810 if (iwl_scan_cancel_timeout(priv
, 100)) {
811 IWL_WARNING("Aborted scan still in progress after 100ms\n");
812 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
816 iwl4965_commit_rxon(priv
);
821 static void iwl4965_set_rate(struct iwl_priv
*priv
)
823 const struct ieee80211_supported_band
*hw
= NULL
;
824 struct ieee80211_rate
*rate
;
827 hw
= iwl_get_hw_mode(priv
, priv
->band
);
829 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
833 priv
->active_rate
= 0;
834 priv
->active_rate_basic
= 0;
836 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
837 rate
= &(hw
->bitrates
[i
]);
838 if (rate
->hw_value
< IWL_RATE_COUNT
)
839 priv
->active_rate
|= (1 << rate
->hw_value
);
842 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
843 priv
->active_rate
, priv
->active_rate_basic
);
846 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
847 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
850 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
851 priv
->staging_rxon
.cck_basic_rates
=
852 ((priv
->active_rate_basic
&
853 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
855 priv
->staging_rxon
.cck_basic_rates
=
856 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
858 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
859 priv
->staging_rxon
.ofdm_basic_rates
=
860 ((priv
->active_rate_basic
&
861 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
862 IWL_FIRST_OFDM_RATE
) & 0xFF;
864 priv
->staging_rxon
.ofdm_basic_rates
=
865 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
868 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
870 #include "iwl-spectrum.h"
872 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
873 #define BEACON_TIME_MASK_HIGH 0xFF000000
874 #define TIME_UNIT 1024
877 * extended beacon time format
878 * time in usec will be changed into a 32-bit value in 8:24 format
879 * the high 1 byte is the beacon counts
880 * the lower 3 bytes is the time in usec within one beacon interval
883 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
887 u32 interval
= beacon_interval
* 1024;
889 if (!interval
|| !usec
)
892 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
893 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
895 return (quot
<< 24) + rem
;
898 /* base is usually what we get from ucode with each received frame,
899 * the same as HW timer counter counting down
902 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
904 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
905 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
906 u32 interval
= beacon_interval
* TIME_UNIT
;
907 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
908 (addon
& BEACON_TIME_MASK_HIGH
);
910 if (base_low
> addon_low
)
911 res
+= base_low
- addon_low
;
912 else if (base_low
< addon_low
) {
913 res
+= interval
+ base_low
- addon_low
;
918 return cpu_to_le32(res
);
921 static int iwl4965_get_measurement(struct iwl_priv
*priv
,
922 struct ieee80211_measurement_params
*params
,
925 struct iwl4965_spectrum_cmd spectrum
;
926 struct iwl_rx_packet
*res
;
927 struct iwl_host_cmd cmd
= {
928 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
929 .data
= (void *)&spectrum
,
930 .meta
.flags
= CMD_WANT_SKB
,
932 u32 add_time
= le64_to_cpu(params
->start_time
);
934 int spectrum_resp_status
;
935 int duration
= le16_to_cpu(params
->duration
);
937 if (iwl_is_associated(priv
))
939 iwl4965_usecs_to_beacons(
940 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
941 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
943 memset(&spectrum
, 0, sizeof(spectrum
));
945 spectrum
.channel_count
= cpu_to_le16(1);
947 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
948 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
949 cmd
.len
= sizeof(spectrum
);
950 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
952 if (iwl_is_associated(priv
))
953 spectrum
.start_time
=
954 iwl4965_add_beacon_time(priv
->last_beacon_time
,
956 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
958 spectrum
.start_time
= 0;
960 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
961 spectrum
.channels
[0].channel
= params
->channel
;
962 spectrum
.channels
[0].type
= type
;
963 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
964 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
965 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
967 rc
= iwl_send_cmd_sync(priv
, &cmd
);
971 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
972 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
973 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
977 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
978 switch (spectrum_resp_status
) {
979 case 0: /* Command will be handled */
980 if (res
->u
.spectrum
.id
!= 0xff) {
982 ("Replaced existing measurement: %d\n",
984 priv
->measurement_status
&= ~MEASUREMENT_READY
;
986 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
990 case 1: /* Command will not be handled */
995 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1001 /******************************************************************************
1003 * Generic RX handler implementations
1005 ******************************************************************************/
1006 static void iwl_rx_reply_alive(struct iwl_priv
*priv
,
1007 struct iwl_rx_mem_buffer
*rxb
)
1009 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1010 struct iwl_alive_resp
*palive
;
1011 struct delayed_work
*pwork
;
1013 palive
= &pkt
->u
.alive_frame
;
1015 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1017 palive
->is_valid
, palive
->ver_type
,
1018 palive
->ver_subtype
);
1020 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
1021 IWL_DEBUG_INFO("Initialization Alive received.\n");
1022 memcpy(&priv
->card_alive_init
,
1023 &pkt
->u
.alive_frame
,
1024 sizeof(struct iwl_init_alive_resp
));
1025 pwork
= &priv
->init_alive_start
;
1027 IWL_DEBUG_INFO("Runtime Alive received.\n");
1028 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
1029 sizeof(struct iwl_alive_resp
));
1030 pwork
= &priv
->alive_start
;
1033 /* We delay the ALIVE response by 5ms to
1034 * give the HW RF Kill time to activate... */
1035 if (palive
->is_valid
== UCODE_VALID_OK
)
1036 queue_delayed_work(priv
->workqueue
, pwork
,
1037 msecs_to_jiffies(5));
1039 IWL_WARNING("uCode did not respond OK.\n");
1042 static void iwl4965_rx_reply_error(struct iwl_priv
*priv
,
1043 struct iwl_rx_mem_buffer
*rxb
)
1045 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1047 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1048 "seq 0x%04X ser 0x%08X\n",
1049 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
1050 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
1051 pkt
->u
.err_resp
.cmd_id
,
1052 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
1053 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
1056 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1058 static void iwl4965_rx_csa(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
)
1060 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1061 struct iwl_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
1062 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
1063 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1064 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
1065 rxon
->channel
= csa
->channel
;
1066 priv
->staging_rxon
.channel
= csa
->channel
;
1069 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
1070 struct iwl_rx_mem_buffer
*rxb
)
1072 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
1073 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1074 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
1076 if (!report
->state
) {
1077 IWL_DEBUG(IWL_DL_11H
,
1078 "Spectrum Measure Notification: Start\n");
1082 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
1083 priv
->measurement_status
|= MEASUREMENT_READY
;
1087 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv
*priv
,
1088 struct iwl_rx_mem_buffer
*rxb
)
1090 #ifdef CONFIG_IWLWIFI_DEBUG
1091 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1092 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
1093 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1094 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
1098 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
1099 struct iwl_rx_mem_buffer
*rxb
)
1101 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1102 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1103 "notification for %s:\n",
1104 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
1105 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
1108 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
1110 struct iwl_priv
*priv
=
1111 container_of(work
, struct iwl_priv
, beacon_update
);
1112 struct sk_buff
*beacon
;
1114 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
1115 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
);
1118 IWL_ERROR("update beacon failed\n");
1122 mutex_lock(&priv
->mutex
);
1123 /* new beacon skb is allocated every time; dispose previous.*/
1124 if (priv
->ibss_beacon
)
1125 dev_kfree_skb(priv
->ibss_beacon
);
1127 priv
->ibss_beacon
= beacon
;
1128 mutex_unlock(&priv
->mutex
);
1130 iwl4965_send_beacon_cmd(priv
);
1134 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
1136 * This callback is provided in order to send a statistics request.
1138 * This timer function is continually reset to execute within
1139 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1140 * was received. We need to ensure we receive the statistics in order
1141 * to update the temperature used for calibrating the TXPOWER.
1143 static void iwl4965_bg_statistics_periodic(unsigned long data
)
1145 struct iwl_priv
*priv
= (struct iwl_priv
*)data
;
1147 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1150 iwl_send_statistics_request(priv
, CMD_ASYNC
);
1153 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
1154 struct iwl_rx_mem_buffer
*rxb
)
1156 #ifdef CONFIG_IWLWIFI_DEBUG
1157 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1158 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
1159 u8 rate
= iwl_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
1161 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1162 "tsf %d %d rate %d\n",
1163 le32_to_cpu(beacon
->beacon_notify_hdr
.u
.status
) & TX_STATUS_MSK
,
1164 beacon
->beacon_notify_hdr
.failure_frame
,
1165 le32_to_cpu(beacon
->ibss_mgr_status
),
1166 le32_to_cpu(beacon
->high_tsf
),
1167 le32_to_cpu(beacon
->low_tsf
), rate
);
1170 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
1171 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
1172 queue_work(priv
->workqueue
, &priv
->beacon_update
);
1175 /* Handle notification from uCode that card's power state is changing
1176 * due to software, hardware, or critical temperature RFKILL */
1177 static void iwl4965_rx_card_state_notif(struct iwl_priv
*priv
,
1178 struct iwl_rx_mem_buffer
*rxb
)
1180 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1181 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
1182 unsigned long status
= priv
->status
;
1184 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1185 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
1186 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
1188 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
1189 RF_CARD_DISABLED
)) {
1191 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
1192 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
1194 if (!iwl_grab_nic_access(priv
)) {
1196 priv
, HBUS_TARG_MBX_C
,
1197 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
1199 iwl_release_nic_access(priv
);
1202 if (!(flags
& RXON_CARD_DISABLED
)) {
1203 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
1204 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
1205 if (!iwl_grab_nic_access(priv
)) {
1207 priv
, HBUS_TARG_MBX_C
,
1208 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
1210 iwl_release_nic_access(priv
);
1214 if (flags
& RF_CARD_DISABLED
) {
1215 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
1216 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
1217 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
1218 if (!iwl_grab_nic_access(priv
))
1219 iwl_release_nic_access(priv
);
1223 if (flags
& HW_CARD_DISABLED
)
1224 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
1226 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
1229 if (flags
& SW_CARD_DISABLED
)
1230 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
1232 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
1234 if (!(flags
& RXON_CARD_DISABLED
))
1235 iwl_scan_cancel(priv
);
1237 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
1238 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
1239 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
1240 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
1241 queue_work(priv
->workqueue
, &priv
->rf_kill
);
1243 wake_up_interruptible(&priv
->wait_command_queue
);
1247 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
1249 * Setup the RX handlers for each of the reply types sent from the uCode
1252 * This function chains into the hardware specific files for them to setup
1253 * any hardware specific handlers as well.
1255 static void iwl_setup_rx_handlers(struct iwl_priv
*priv
)
1257 priv
->rx_handlers
[REPLY_ALIVE
] = iwl_rx_reply_alive
;
1258 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
1259 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
1260 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
1261 iwl4965_rx_spectrum_measure_notif
;
1262 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
1263 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
1264 iwl4965_rx_pm_debug_statistics_notif
;
1265 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
1268 * The same handler is used for both the REPLY to a discrete
1269 * statistics request from the host as well as for the periodic
1270 * statistics notifications (after received beacons) from the uCode.
1272 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl_rx_statistics
;
1273 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl_rx_statistics
;
1275 iwl_setup_rx_scan_handlers(priv
);
1277 /* status change handler */
1278 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
1280 priv
->rx_handlers
[MISSED_BEACONS_NOTIFICATION
] =
1281 iwl_rx_missed_beacon_notif
;
1283 priv
->rx_handlers
[REPLY_RX_PHY_CMD
] = iwl_rx_reply_rx_phy
;
1284 priv
->rx_handlers
[REPLY_RX_MPDU_CMD
] = iwl_rx_reply_rx
;
1286 priv
->rx_handlers
[REPLY_COMPRESSED_BA
] = iwl_rx_reply_compressed_ba
;
1287 /* Set up hardware specific Rx handlers */
1288 priv
->cfg
->ops
->lib
->rx_handler_setup(priv
);
1292 * this should be called while priv->lock is locked
1294 static void __iwl_rx_replenish(struct iwl_priv
*priv
)
1296 iwl_rx_allocate(priv
);
1297 iwl_rx_queue_restock(priv
);
1302 * iwl_rx_handle - Main entry function for receiving responses from uCode
1304 * Uses the priv->rx_handlers callback function array to invoke
1305 * the appropriate handlers, including command responses,
1306 * frame-received notifications, and other notifications.
1308 void iwl_rx_handle(struct iwl_priv
*priv
)
1310 struct iwl_rx_mem_buffer
*rxb
;
1311 struct iwl_rx_packet
*pkt
;
1312 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
1315 unsigned long flags
;
1319 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1320 * buffer that the driver may process (last buffer filled by ucode). */
1321 r
= priv
->cfg
->ops
->lib
->shared_mem_rx_idx(priv
);
1324 /* Rx interrupt, but nothing sent from uCode */
1326 IWL_DEBUG(IWL_DL_RX
, "r = %d, i = %d\n", r
, i
);
1328 if (iwl_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
1332 rxb
= rxq
->queue
[i
];
1334 /* If an RXB doesn't have a Rx queue slot associated with it,
1335 * then a bug has been introduced in the queue refilling
1336 * routines -- catch it here */
1337 BUG_ON(rxb
== NULL
);
1339 rxq
->queue
[i
] = NULL
;
1341 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
1342 priv
->hw_params
.rx_buf_size
,
1343 PCI_DMA_FROMDEVICE
);
1344 pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1346 /* Reclaim a command buffer only if this packet is a response
1347 * to a (driver-originated) command.
1348 * If the packet (e.g. Rx frame) originated from uCode,
1349 * there is no command buffer to reclaim.
1350 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1351 * but apparently a few don't get set; catch them here. */
1352 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
1353 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
1354 (pkt
->hdr
.cmd
!= REPLY_RX
) &&
1355 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
1356 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
1357 (pkt
->hdr
.cmd
!= REPLY_TX
);
1359 /* Based on type of command response or notification,
1360 * handle those that need handling via function in
1361 * rx_handlers table. See iwl4965_setup_rx_handlers() */
1362 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
1363 IWL_DEBUG(IWL_DL_RX
, "r = %d, i = %d, %s, 0x%02x\n", r
,
1364 i
, get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
1365 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
1367 /* No handling needed */
1368 IWL_DEBUG(IWL_DL_RX
,
1369 "r %d i %d No handler needed for %s, 0x%02x\n",
1370 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
1375 /* Invoke any callbacks, transfer the skb to caller, and
1376 * fire off the (possibly) blocking iwl_send_cmd()
1377 * as we reclaim the driver command queue */
1378 if (rxb
&& rxb
->skb
)
1379 iwl_tx_cmd_complete(priv
, rxb
);
1381 IWL_WARNING("Claim null rxb?\n");
1384 /* For now we just don't re-use anything. We can tweak this
1385 * later to try and re-use notification packets and SKBs that
1386 * fail to Rx correctly */
1387 if (rxb
->skb
!= NULL
) {
1388 priv
->alloc_rxb_skb
--;
1389 dev_kfree_skb_any(rxb
->skb
);
1393 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
1394 priv
->hw_params
.rx_buf_size
,
1395 PCI_DMA_FROMDEVICE
);
1396 spin_lock_irqsave(&rxq
->lock
, flags
);
1397 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
1398 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1399 i
= (i
+ 1) & RX_QUEUE_MASK
;
1400 /* If there are a lot of unused frames,
1401 * restock the Rx queue so ucode wont assert. */
1406 __iwl_rx_replenish(priv
);
1412 /* Backtrack one entry */
1414 iwl_rx_queue_restock(priv
);
1417 #ifdef CONFIG_IWLWIFI_DEBUG
1418 static void iwl4965_print_rx_config_cmd(struct iwl_priv
*priv
)
1420 struct iwl_rxon_cmd
*rxon
= &priv
->staging_rxon
;
1421 DECLARE_MAC_BUF(mac
);
1423 IWL_DEBUG_RADIO("RX CONFIG:\n");
1424 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
1425 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
1426 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
1427 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1428 le32_to_cpu(rxon
->filter_flags
));
1429 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
1430 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1431 rxon
->ofdm_basic_rates
);
1432 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
1433 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
1434 print_mac(mac
, rxon
->node_addr
));
1435 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
1436 print_mac(mac
, rxon
->bssid_addr
));
1437 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
1441 static void iwl4965_enable_interrupts(struct iwl_priv
*priv
)
1443 IWL_DEBUG_ISR("Enabling interrupts\n");
1444 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
1445 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
1448 /* call this function to flush any scheduled tasklet */
1449 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
1451 /* wait to make sure we flush pedding tasklet*/
1452 synchronize_irq(priv
->pci_dev
->irq
);
1453 tasklet_kill(&priv
->irq_tasklet
);
1456 static inline void iwl4965_disable_interrupts(struct iwl_priv
*priv
)
1458 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
1460 /* disable interrupts from uCode/NIC to host */
1461 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
1463 /* acknowledge/clear/reset any interrupts still pending
1464 * from uCode or flow handler (Rx/Tx DMA) */
1465 iwl_write32(priv
, CSR_INT
, 0xffffffff);
1466 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
1467 IWL_DEBUG_ISR("Disabled interrupts\n");
1472 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
1474 static void iwl4965_irq_handle_error(struct iwl_priv
*priv
)
1476 /* Set the FW error flag -- cleared on iwl4965_down */
1477 set_bit(STATUS_FW_ERROR
, &priv
->status
);
1479 /* Cancel currently queued command. */
1480 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
1482 #ifdef CONFIG_IWLWIFI_DEBUG
1483 if (priv
->debug_level
& IWL_DL_FW_ERRORS
) {
1484 iwl_dump_nic_error_log(priv
);
1485 iwl_dump_nic_event_log(priv
);
1486 iwl4965_print_rx_config_cmd(priv
);
1490 wake_up_interruptible(&priv
->wait_command_queue
);
1492 /* Keep the restart process from trying to send host
1493 * commands by clearing the INIT status bit */
1494 clear_bit(STATUS_READY
, &priv
->status
);
1496 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
1497 IWL_DEBUG(IWL_DL_FW_ERRORS
,
1498 "Restarting adapter due to uCode error.\n");
1500 if (iwl_is_associated(priv
)) {
1501 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
1502 sizeof(priv
->recovery_rxon
));
1503 priv
->error_recovering
= 1;
1505 if (priv
->cfg
->mod_params
->restart_fw
)
1506 queue_work(priv
->workqueue
, &priv
->restart
);
1510 static void iwl4965_error_recovery(struct iwl_priv
*priv
)
1512 unsigned long flags
;
1514 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
1515 sizeof(priv
->staging_rxon
));
1516 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1517 iwl4965_commit_rxon(priv
);
1519 iwl_rxon_add_station(priv
, priv
->bssid
, 1);
1521 spin_lock_irqsave(&priv
->lock
, flags
);
1522 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
1523 priv
->error_recovering
= 0;
1524 spin_unlock_irqrestore(&priv
->lock
, flags
);
1527 static void iwl4965_irq_tasklet(struct iwl_priv
*priv
)
1529 u32 inta
, handled
= 0;
1531 unsigned long flags
;
1532 #ifdef CONFIG_IWLWIFI_DEBUG
1536 spin_lock_irqsave(&priv
->lock
, flags
);
1538 /* Ack/clear/reset pending uCode interrupts.
1539 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1540 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
1541 inta
= iwl_read32(priv
, CSR_INT
);
1542 iwl_write32(priv
, CSR_INT
, inta
);
1544 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1545 * Any new interrupts that happen after this, either while we're
1546 * in this tasklet, or later, will show up in next ISR/tasklet. */
1547 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1548 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
1550 #ifdef CONFIG_IWLWIFI_DEBUG
1551 if (priv
->debug_level
& IWL_DL_ISR
) {
1552 /* just for debug */
1553 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
1554 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1555 inta
, inta_mask
, inta_fh
);
1559 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1560 * atomic, make sure that inta covers all the interrupts that
1561 * we've discovered, even if FH interrupt came in just after
1562 * reading CSR_INT. */
1563 if (inta_fh
& CSR49_FH_INT_RX_MASK
)
1564 inta
|= CSR_INT_BIT_FH_RX
;
1565 if (inta_fh
& CSR49_FH_INT_TX_MASK
)
1566 inta
|= CSR_INT_BIT_FH_TX
;
1568 /* Now service all interrupt bits discovered above. */
1569 if (inta
& CSR_INT_BIT_HW_ERR
) {
1570 IWL_ERROR("Microcode HW error detected. Restarting.\n");
1572 /* Tell the device to stop sending interrupts */
1573 iwl4965_disable_interrupts(priv
);
1575 iwl4965_irq_handle_error(priv
);
1577 handled
|= CSR_INT_BIT_HW_ERR
;
1579 spin_unlock_irqrestore(&priv
->lock
, flags
);
1584 #ifdef CONFIG_IWLWIFI_DEBUG
1585 if (priv
->debug_level
& (IWL_DL_ISR
)) {
1586 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1587 if (inta
& CSR_INT_BIT_SCD
)
1588 IWL_DEBUG_ISR("Scheduler finished to transmit "
1589 "the frame/frames.\n");
1591 /* Alive notification via Rx interrupt will do the real work */
1592 if (inta
& CSR_INT_BIT_ALIVE
)
1593 IWL_DEBUG_ISR("Alive interrupt\n");
1596 /* Safely ignore these bits for debug checks below */
1597 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
1599 /* HW RF KILL switch toggled */
1600 if (inta
& CSR_INT_BIT_RF_KILL
) {
1602 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
1603 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
1606 IWL_DEBUG(IWL_DL_RF_KILL
, "RF_KILL bit toggled to %s.\n",
1607 hw_rf_kill
? "disable radio":"enable radio");
1609 /* driver only loads ucode once setting the interface up.
1610 * the driver as well won't allow loading if RFKILL is set
1611 * therefore no need to restart the driver from this handler
1613 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
))
1614 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
1616 handled
|= CSR_INT_BIT_RF_KILL
;
1619 /* Chip got too hot and stopped itself */
1620 if (inta
& CSR_INT_BIT_CT_KILL
) {
1621 IWL_ERROR("Microcode CT kill error detected.\n");
1622 handled
|= CSR_INT_BIT_CT_KILL
;
1625 /* Error detected by uCode */
1626 if (inta
& CSR_INT_BIT_SW_ERR
) {
1627 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
1629 iwl4965_irq_handle_error(priv
);
1630 handled
|= CSR_INT_BIT_SW_ERR
;
1633 /* uCode wakes up after power-down sleep */
1634 if (inta
& CSR_INT_BIT_WAKEUP
) {
1635 IWL_DEBUG_ISR("Wakeup interrupt\n");
1636 iwl_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
1637 iwl_txq_update_write_ptr(priv
, &priv
->txq
[0]);
1638 iwl_txq_update_write_ptr(priv
, &priv
->txq
[1]);
1639 iwl_txq_update_write_ptr(priv
, &priv
->txq
[2]);
1640 iwl_txq_update_write_ptr(priv
, &priv
->txq
[3]);
1641 iwl_txq_update_write_ptr(priv
, &priv
->txq
[4]);
1642 iwl_txq_update_write_ptr(priv
, &priv
->txq
[5]);
1644 handled
|= CSR_INT_BIT_WAKEUP
;
1647 /* All uCode command responses, including Tx command responses,
1648 * Rx "responses" (frame-received notification), and other
1649 * notifications from uCode come through here*/
1650 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
1651 iwl_rx_handle(priv
);
1652 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
1655 if (inta
& CSR_INT_BIT_FH_TX
) {
1656 IWL_DEBUG_ISR("Tx interrupt\n");
1657 handled
|= CSR_INT_BIT_FH_TX
;
1658 /* FH finished to write, send event */
1659 priv
->ucode_write_complete
= 1;
1660 wake_up_interruptible(&priv
->wait_command_queue
);
1663 if (inta
& ~handled
)
1664 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
1666 if (inta
& ~CSR_INI_SET_MASK
) {
1667 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
1668 inta
& ~CSR_INI_SET_MASK
);
1669 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
1672 /* Re-enable all interrupts */
1673 /* only Re-enable if diabled by irq */
1674 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
1675 iwl4965_enable_interrupts(priv
);
1677 #ifdef CONFIG_IWLWIFI_DEBUG
1678 if (priv
->debug_level
& (IWL_DL_ISR
)) {
1679 inta
= iwl_read32(priv
, CSR_INT
);
1680 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
1681 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1682 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1683 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
1686 spin_unlock_irqrestore(&priv
->lock
, flags
);
1689 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
1691 struct iwl_priv
*priv
= data
;
1692 u32 inta
, inta_mask
;
1697 spin_lock(&priv
->lock
);
1699 /* Disable (but don't clear!) interrupts here to avoid
1700 * back-to-back ISRs and sporadic interrupts from our NIC.
1701 * If we have something to service, the tasklet will re-enable ints.
1702 * If we *don't* have something, we'll re-enable before leaving here. */
1703 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
1704 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
1706 /* Discover which interrupts are active/pending */
1707 inta
= iwl_read32(priv
, CSR_INT
);
1708 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1710 /* Ignore interrupt if there's nothing in NIC to service.
1711 * This may be due to IRQ shared with another device,
1712 * or due to sporadic interrupts thrown from our NIC. */
1713 if (!inta
&& !inta_fh
) {
1714 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1718 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
1719 /* Hardware disappeared. It might have already raised
1721 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
1725 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1726 inta
, inta_mask
, inta_fh
);
1728 inta
&= ~CSR_INT_BIT_SCD
;
1730 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
1731 if (likely(inta
|| inta_fh
))
1732 tasklet_schedule(&priv
->irq_tasklet
);
1735 spin_unlock(&priv
->lock
);
1739 /* re-enable interrupts here since we don't have anything to service. */
1740 /* only Re-enable if diabled by irq */
1741 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
1742 iwl4965_enable_interrupts(priv
);
1743 spin_unlock(&priv
->lock
);
1747 /******************************************************************************
1749 * uCode download functions
1751 ******************************************************************************/
1753 static void iwl4965_dealloc_ucode_pci(struct iwl_priv
*priv
)
1755 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
1756 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
1757 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
1758 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
1759 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
1760 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
1763 static void iwl4965_nic_start(struct iwl_priv
*priv
)
1765 /* Remove all resets to allow NIC to operate */
1766 iwl_write32(priv
, CSR_RESET
, 0);
1771 * iwl4965_read_ucode - Read uCode images from disk file.
1773 * Copy into buffers for card to fetch via bus-mastering
1775 static int iwl4965_read_ucode(struct iwl_priv
*priv
)
1777 struct iwl_ucode
*ucode
;
1779 const struct firmware
*ucode_raw
;
1780 const char *name
= priv
->cfg
->fw_name
;
1783 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
1785 /* Ask kernel firmware_class module to get the boot firmware off disk.
1786 * request_firmware() is synchronous, file is in memory on return. */
1787 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
1789 IWL_ERROR("%s firmware file req failed: Reason %d\n",
1794 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1795 name
, ucode_raw
->size
);
1797 /* Make sure that we got at least our header! */
1798 if (ucode_raw
->size
< sizeof(*ucode
)) {
1799 IWL_ERROR("File size way too small!\n");
1804 /* Data from ucode file: header followed by uCode images */
1805 ucode
= (void *)ucode_raw
->data
;
1807 ver
= le32_to_cpu(ucode
->ver
);
1808 inst_size
= le32_to_cpu(ucode
->inst_size
);
1809 data_size
= le32_to_cpu(ucode
->data_size
);
1810 init_size
= le32_to_cpu(ucode
->init_size
);
1811 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
1812 boot_size
= le32_to_cpu(ucode
->boot_size
);
1814 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
1815 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1817 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1819 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1821 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1823 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1826 /* Verify size of file vs. image size info in file's header */
1827 if (ucode_raw
->size
< sizeof(*ucode
) +
1828 inst_size
+ data_size
+ init_size
+
1829 init_data_size
+ boot_size
) {
1831 IWL_DEBUG_INFO("uCode file size %d too small\n",
1832 (int)ucode_raw
->size
);
1837 /* Verify that uCode images will fit in card's SRAM */
1838 if (inst_size
> priv
->hw_params
.max_inst_size
) {
1839 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1845 if (data_size
> priv
->hw_params
.max_data_size
) {
1846 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1851 if (init_size
> priv
->hw_params
.max_inst_size
) {
1853 ("uCode init instr len %d too large to fit in\n",
1858 if (init_data_size
> priv
->hw_params
.max_data_size
) {
1860 ("uCode init data len %d too large to fit in\n",
1865 if (boot_size
> priv
->hw_params
.max_bsm_size
) {
1867 ("uCode boot instr len %d too large to fit in\n",
1873 /* Allocate ucode buffers for card's bus-master loading ... */
1875 /* Runtime instructions and 2 copies of data:
1876 * 1) unmodified from disk
1877 * 2) backup cache for save/restore during power-downs */
1878 priv
->ucode_code
.len
= inst_size
;
1879 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
1881 priv
->ucode_data
.len
= data_size
;
1882 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
1884 priv
->ucode_data_backup
.len
= data_size
;
1885 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
1887 /* Initialization instructions and data */
1888 if (init_size
&& init_data_size
) {
1889 priv
->ucode_init
.len
= init_size
;
1890 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
1892 priv
->ucode_init_data
.len
= init_data_size
;
1893 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
1895 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
1899 /* Bootstrap (instructions only, no data) */
1901 priv
->ucode_boot
.len
= boot_size
;
1902 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
1904 if (!priv
->ucode_boot
.v_addr
)
1908 /* Copy images into buffers for card's bus-master reads ... */
1910 /* Runtime instructions (first block of data in file) */
1911 src
= &ucode
->data
[0];
1912 len
= priv
->ucode_code
.len
;
1913 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
1914 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
1915 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1916 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
1918 /* Runtime data (2nd block)
1919 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
1920 src
= &ucode
->data
[inst_size
];
1921 len
= priv
->ucode_data
.len
;
1922 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
1923 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
1924 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
1926 /* Initialization instructions (3rd block) */
1928 src
= &ucode
->data
[inst_size
+ data_size
];
1929 len
= priv
->ucode_init
.len
;
1930 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1932 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
1935 /* Initialization data (4th block) */
1936 if (init_data_size
) {
1937 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
1938 len
= priv
->ucode_init_data
.len
;
1939 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1941 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
1944 /* Bootstrap instructions (5th block) */
1945 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
1946 len
= priv
->ucode_boot
.len
;
1947 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
1948 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
1950 /* We have our copies now, allow OS release its copies */
1951 release_firmware(ucode_raw
);
1955 IWL_ERROR("failed to allocate pci memory\n");
1957 iwl4965_dealloc_ucode_pci(priv
);
1960 release_firmware(ucode_raw
);
1967 * iwl_alive_start - called after REPLY_ALIVE notification received
1968 * from protocol/runtime uCode (initialization uCode's
1969 * Alive gets handled by iwl_init_alive_start()).
1971 static void iwl_alive_start(struct iwl_priv
*priv
)
1975 IWL_DEBUG_INFO("Runtime Alive received.\n");
1977 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
1978 /* We had an error bringing up the hardware, so take it
1979 * all the way back down so we can try again */
1980 IWL_DEBUG_INFO("Alive failed.\n");
1984 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1985 * This is a paranoid check, because we would not have gotten the
1986 * "runtime" alive if code weren't properly loaded. */
1987 if (iwl_verify_ucode(priv
)) {
1988 /* Runtime instruction load was bad;
1989 * take it all the way back down so we can try again */
1990 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
1994 iwl_clear_stations_table(priv
);
1995 ret
= priv
->cfg
->ops
->lib
->alive_notify(priv
);
1997 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
2002 /* After the ALIVE response, we can send host commands to 4965 uCode */
2003 set_bit(STATUS_ALIVE
, &priv
->status
);
2005 if (iwl_is_rfkill(priv
))
2008 ieee80211_wake_queues(priv
->hw
);
2010 priv
->active_rate
= priv
->rates_mask
;
2011 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
2013 if (iwl_is_associated(priv
)) {
2014 struct iwl_rxon_cmd
*active_rxon
=
2015 (struct iwl_rxon_cmd
*)&priv
->active_rxon
;
2017 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
2018 sizeof(priv
->staging_rxon
));
2019 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2021 /* Initialize our rx_config data */
2022 iwl4965_connection_init_rx_config(priv
);
2023 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2026 /* Configure Bluetooth device coexistence support */
2027 iwl4965_send_bt_config(priv
);
2029 iwl_reset_run_time_calib(priv
);
2031 /* Configure the adapter for unassociated operation */
2032 iwl4965_commit_rxon(priv
);
2034 /* At this point, the NIC is initialized and operational */
2035 iwl_rf_kill_ct_config(priv
);
2037 iwl_leds_register(priv
);
2039 IWL_DEBUG_INFO("ALIVE processing complete.\n");
2040 set_bit(STATUS_READY
, &priv
->status
);
2041 wake_up_interruptible(&priv
->wait_command_queue
);
2043 if (priv
->error_recovering
)
2044 iwl4965_error_recovery(priv
);
2046 iwl_power_update_mode(priv
, 1);
2047 ieee80211_notify_mac(priv
->hw
, IEEE80211_NOTIFY_RE_ASSOC
);
2049 if (test_and_clear_bit(STATUS_MODE_PENDING
, &priv
->status
))
2050 iwl4965_set_mode(priv
, priv
->iw_mode
);
2055 queue_work(priv
->workqueue
, &priv
->restart
);
2058 static void iwl_cancel_deferred_work(struct iwl_priv
*priv
);
2060 static void __iwl4965_down(struct iwl_priv
*priv
)
2062 unsigned long flags
;
2063 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2065 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
2068 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2070 iwl_leds_unregister(priv
);
2072 iwl_clear_stations_table(priv
);
2074 /* Unblock any waiting calls */
2075 wake_up_interruptible_all(&priv
->wait_command_queue
);
2077 /* Wipe out the EXIT_PENDING status bit if we are not actually
2078 * exiting the module */
2080 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2082 /* stop and reset the on-board processor */
2083 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
2085 /* tell the device to stop sending interrupts */
2086 spin_lock_irqsave(&priv
->lock
, flags
);
2087 iwl4965_disable_interrupts(priv
);
2088 spin_unlock_irqrestore(&priv
->lock
, flags
);
2089 iwl_synchronize_irq(priv
);
2091 if (priv
->mac80211_registered
)
2092 ieee80211_stop_queues(priv
->hw
);
2094 /* If we have not previously called iwl4965_init() then
2095 * clear all bits but the RF Kill and SUSPEND bits and return */
2096 if (!iwl_is_init(priv
)) {
2097 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2099 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
2101 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2102 STATUS_GEO_CONFIGURED
|
2103 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
2105 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
2106 STATUS_EXIT_PENDING
;
2110 /* ...otherwise clear out all the status bits but the RF Kill and
2111 * SUSPEND bits and continue taking the NIC down. */
2112 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2114 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
2116 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2117 STATUS_GEO_CONFIGURED
|
2118 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
2120 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
2122 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
2123 STATUS_EXIT_PENDING
;
2125 spin_lock_irqsave(&priv
->lock
, flags
);
2126 iwl_clear_bit(priv
, CSR_GP_CNTRL
,
2127 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
2128 spin_unlock_irqrestore(&priv
->lock
, flags
);
2130 iwl_txq_ctx_stop(priv
);
2133 spin_lock_irqsave(&priv
->lock
, flags
);
2134 if (!iwl_grab_nic_access(priv
)) {
2135 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
2136 APMG_CLK_VAL_DMA_CLK_RQT
);
2137 iwl_release_nic_access(priv
);
2139 spin_unlock_irqrestore(&priv
->lock
, flags
);
2143 /* FIXME: apm_ops.suspend(priv) */
2144 priv
->cfg
->ops
->lib
->apm_ops
.reset(priv
);
2145 priv
->cfg
->ops
->lib
->free_shared_mem(priv
);
2148 memset(&priv
->card_alive
, 0, sizeof(struct iwl_alive_resp
));
2150 if (priv
->ibss_beacon
)
2151 dev_kfree_skb(priv
->ibss_beacon
);
2152 priv
->ibss_beacon
= NULL
;
2154 /* clear out any free frames */
2155 iwl_clear_free_frames(priv
);
2158 static void iwl4965_down(struct iwl_priv
*priv
)
2160 mutex_lock(&priv
->mutex
);
2161 __iwl4965_down(priv
);
2162 mutex_unlock(&priv
->mutex
);
2164 iwl_cancel_deferred_work(priv
);
2167 #define MAX_HW_RESTARTS 5
2169 static int __iwl4965_up(struct iwl_priv
*priv
)
2174 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
2175 IWL_WARNING("Exit pending; will not bring the NIC up\n");
2179 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
2180 IWL_ERROR("ucode not available for device bringup\n");
2184 /* If platform's RF_KILL switch is NOT set to KILL */
2185 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
2186 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
2187 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2189 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2191 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
) &&
2192 iwl_is_rfkill(priv
)) {
2193 IWL_WARNING("Radio disabled by %s RF Kill switch\n",
2194 test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ? "HW" : "SW");
2198 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
2200 ret
= priv
->cfg
->ops
->lib
->alloc_shared_mem(priv
);
2202 IWL_ERROR("Unable to allocate shared memory\n");
2206 ret
= iwl_hw_nic_init(priv
);
2208 IWL_ERROR("Unable to init nic\n");
2212 /* make sure rfkill handshake bits are cleared */
2213 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2214 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
2215 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
2217 /* clear (again), then enable host interrupts */
2218 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
2219 iwl4965_enable_interrupts(priv
);
2221 /* really make sure rfkill handshake bits are cleared */
2222 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2223 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2225 /* Copy original ucode data image from disk into backup cache.
2226 * This will be used to initialize the on-board processor's
2227 * data SRAM for a clean start when the runtime program first loads. */
2228 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
2229 priv
->ucode_data
.len
);
2231 /* We return success when we resume from suspend and rf_kill is on. */
2232 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ||
2233 test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2236 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
2238 iwl_clear_stations_table(priv
);
2240 /* load bootstrap state machine,
2241 * load bootstrap program into processor's memory,
2242 * prepare to load the "initialize" uCode */
2243 ret
= priv
->cfg
->ops
->lib
->load_ucode(priv
);
2246 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret
);
2250 /* Clear out the uCode error bit if it is set */
2251 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
2253 /* start card; "initialize" will load runtime ucode */
2254 iwl4965_nic_start(priv
);
2256 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
2261 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2262 __iwl4965_down(priv
);
2263 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2265 /* tried to restart and config the device for as long as our
2266 * patience could withstand */
2267 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
2272 /*****************************************************************************
2274 * Workqueue callbacks
2276 *****************************************************************************/
2278 static void iwl_bg_init_alive_start(struct work_struct
*data
)
2280 struct iwl_priv
*priv
=
2281 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
2283 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2286 mutex_lock(&priv
->mutex
);
2287 priv
->cfg
->ops
->lib
->init_alive_start(priv
);
2288 mutex_unlock(&priv
->mutex
);
2291 static void iwl_bg_alive_start(struct work_struct
*data
)
2293 struct iwl_priv
*priv
=
2294 container_of(data
, struct iwl_priv
, alive_start
.work
);
2296 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2299 mutex_lock(&priv
->mutex
);
2300 iwl_alive_start(priv
);
2301 mutex_unlock(&priv
->mutex
);
2304 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
2306 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
2308 wake_up_interruptible(&priv
->wait_command_queue
);
2310 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2313 mutex_lock(&priv
->mutex
);
2315 if (!iwl_is_rfkill(priv
)) {
2316 IWL_DEBUG(IWL_DL_RF_KILL
,
2317 "HW and/or SW RF Kill no longer active, restarting "
2319 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2320 queue_work(priv
->workqueue
, &priv
->restart
);
2322 /* make sure mac80211 stop sending Tx frame */
2323 if (priv
->mac80211_registered
)
2324 ieee80211_stop_queues(priv
->hw
);
2326 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
2327 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2328 "disabled by SW switch\n");
2330 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
2331 "Kill switch must be turned off for "
2332 "wireless networking to work.\n");
2334 mutex_unlock(&priv
->mutex
);
2335 iwl_rfkill_set_hw_state(priv
);
2338 static void iwl4965_bg_set_monitor(struct work_struct
*work
)
2340 struct iwl_priv
*priv
= container_of(work
,
2341 struct iwl_priv
, set_monitor
);
2344 IWL_DEBUG(IWL_DL_STATE
, "setting monitor mode\n");
2346 mutex_lock(&priv
->mutex
);
2348 ret
= iwl4965_set_mode(priv
, IEEE80211_IF_TYPE_MNTR
);
2352 IWL_DEBUG(IWL_DL_STATE
, "leave - not ready\n");
2354 IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret
);
2357 mutex_unlock(&priv
->mutex
);
2360 static void iwl_bg_run_time_calib_work(struct work_struct
*work
)
2362 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
,
2363 run_time_calib_work
);
2365 mutex_lock(&priv
->mutex
);
2367 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
) ||
2368 test_bit(STATUS_SCANNING
, &priv
->status
)) {
2369 mutex_unlock(&priv
->mutex
);
2373 if (priv
->start_calib
) {
2374 iwl_chain_noise_calibration(priv
, &priv
->statistics
);
2376 iwl_sensitivity_calibration(priv
, &priv
->statistics
);
2379 mutex_unlock(&priv
->mutex
);
2383 static void iwl4965_bg_up(struct work_struct
*data
)
2385 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
2387 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2390 mutex_lock(&priv
->mutex
);
2392 mutex_unlock(&priv
->mutex
);
2393 iwl_rfkill_set_hw_state(priv
);
2396 static void iwl4965_bg_restart(struct work_struct
*data
)
2398 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
2400 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2404 queue_work(priv
->workqueue
, &priv
->up
);
2407 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
2409 struct iwl_priv
*priv
=
2410 container_of(data
, struct iwl_priv
, rx_replenish
);
2412 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2415 mutex_lock(&priv
->mutex
);
2416 iwl_rx_replenish(priv
);
2417 mutex_unlock(&priv
->mutex
);
2420 #define IWL_DELAY_NEXT_SCAN (HZ*2)
2422 static void iwl4965_post_associate(struct iwl_priv
*priv
)
2424 struct ieee80211_conf
*conf
= NULL
;
2426 DECLARE_MAC_BUF(mac
);
2428 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
2429 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
2433 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
2435 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
2438 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2442 if (!priv
->vif
|| !priv
->is_open
)
2445 iwl_scan_cancel_timeout(priv
, 200);
2447 conf
= ieee80211_get_hw_conf(priv
->hw
);
2449 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2450 iwl4965_commit_rxon(priv
);
2452 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
2453 iwl4965_setup_rxon_timing(priv
);
2454 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
2455 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
2457 IWL_WARNING("REPLY_RXON_TIMING failed - "
2458 "Attempting to continue.\n");
2460 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
2462 if (priv
->current_ht_config
.is_ht
)
2463 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
2465 iwl_set_rxon_chain(priv
);
2466 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
2468 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2469 priv
->assoc_id
, priv
->beacon_int
);
2471 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
2472 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2474 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2476 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
2477 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
2478 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2480 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2482 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2483 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2487 iwl4965_commit_rxon(priv
);
2489 switch (priv
->iw_mode
) {
2490 case IEEE80211_IF_TYPE_STA
:
2493 case IEEE80211_IF_TYPE_IBSS
:
2495 /* assume default assoc id */
2498 iwl_rxon_add_station(priv
, priv
->bssid
, 0);
2499 iwl4965_send_beacon_cmd(priv
);
2504 IWL_ERROR("%s Should not be called in %d mode\n",
2505 __FUNCTION__
, priv
->iw_mode
);
2509 /* Enable Rx differential gain and sensitivity calibrations */
2510 iwl_chain_noise_reset(priv
);
2511 priv
->start_calib
= 1;
2513 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2514 priv
->assoc_station_added
= 1;
2516 iwl4965_activate_qos(priv
, 0);
2518 iwl_power_update_mode(priv
, 0);
2519 /* we have just associated, don't start scan too early */
2520 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
2523 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
2525 static void iwl_bg_scan_completed(struct work_struct
*work
)
2527 struct iwl_priv
*priv
=
2528 container_of(work
, struct iwl_priv
, scan_completed
);
2530 IWL_DEBUG_SCAN("SCAN complete scan\n");
2532 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2535 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
2536 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
2538 ieee80211_scan_completed(priv
->hw
);
2540 /* Since setting the TXPOWER may have been deferred while
2541 * performing the scan, fire one off */
2542 mutex_lock(&priv
->mutex
);
2543 iwl_set_tx_power(priv
, priv
->tx_power_user_lmt
, true);
2544 mutex_unlock(&priv
->mutex
);
2547 /*****************************************************************************
2549 * mac80211 entry point functions
2551 *****************************************************************************/
2553 #define UCODE_READY_TIMEOUT (4 * HZ)
2555 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
2557 struct iwl_priv
*priv
= hw
->priv
;
2560 IWL_DEBUG_MAC80211("enter\n");
2562 if (pci_enable_device(priv
->pci_dev
)) {
2563 IWL_ERROR("Fail to pci_enable_device\n");
2566 pci_restore_state(priv
->pci_dev
);
2567 pci_enable_msi(priv
->pci_dev
);
2569 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
2572 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
2573 goto out_disable_msi
;
2576 /* we should be verifying the device is ready to be opened */
2577 mutex_lock(&priv
->mutex
);
2579 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl_rxon_cmd
));
2580 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2581 * ucode filename and max sizes are card-specific. */
2583 if (!priv
->ucode_code
.len
) {
2584 ret
= iwl4965_read_ucode(priv
);
2586 IWL_ERROR("Could not read microcode: %d\n", ret
);
2587 mutex_unlock(&priv
->mutex
);
2588 goto out_release_irq
;
2592 ret
= __iwl4965_up(priv
);
2594 mutex_unlock(&priv
->mutex
);
2596 iwl_rfkill_set_hw_state(priv
);
2599 goto out_release_irq
;
2601 IWL_DEBUG_INFO("Start UP work done.\n");
2603 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
2606 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
2607 * mac80211 will not be run successfully. */
2608 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
2609 test_bit(STATUS_READY
, &priv
->status
),
2610 UCODE_READY_TIMEOUT
);
2612 if (!test_bit(STATUS_READY
, &priv
->status
)) {
2613 IWL_ERROR("START_ALIVE timeout after %dms.\n",
2614 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
2616 goto out_release_irq
;
2621 IWL_DEBUG_MAC80211("leave\n");
2625 free_irq(priv
->pci_dev
->irq
, priv
);
2627 pci_disable_msi(priv
->pci_dev
);
2628 pci_disable_device(priv
->pci_dev
);
2630 IWL_DEBUG_MAC80211("leave - failed\n");
2634 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
2636 struct iwl_priv
*priv
= hw
->priv
;
2638 IWL_DEBUG_MAC80211("enter\n");
2640 if (!priv
->is_open
) {
2641 IWL_DEBUG_MAC80211("leave - skip\n");
2647 if (iwl_is_ready_rf(priv
)) {
2648 /* stop mac, cancel any scan request and clear
2649 * RXON_FILTER_ASSOC_MSK BIT
2651 mutex_lock(&priv
->mutex
);
2652 iwl_scan_cancel_timeout(priv
, 100);
2653 mutex_unlock(&priv
->mutex
);
2658 flush_workqueue(priv
->workqueue
);
2659 free_irq(priv
->pci_dev
->irq
, priv
);
2660 pci_disable_msi(priv
->pci_dev
);
2661 pci_save_state(priv
->pci_dev
);
2662 pci_disable_device(priv
->pci_dev
);
2664 IWL_DEBUG_MAC80211("leave\n");
2667 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2669 struct iwl_priv
*priv
= hw
->priv
;
2671 IWL_DEBUG_MAC80211("enter\n");
2673 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
2674 IWL_DEBUG_MAC80211("leave - monitor\n");
2675 dev_kfree_skb_any(skb
);
2679 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
2680 ieee80211_get_tx_rate(hw
, IEEE80211_SKB_CB(skb
))->bitrate
);
2682 if (iwl_tx_skb(priv
, skb
))
2683 dev_kfree_skb_any(skb
);
2685 IWL_DEBUG_MAC80211("leave\n");
2689 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
2690 struct ieee80211_if_init_conf
*conf
)
2692 struct iwl_priv
*priv
= hw
->priv
;
2693 unsigned long flags
;
2694 DECLARE_MAC_BUF(mac
);
2696 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
2699 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
2703 spin_lock_irqsave(&priv
->lock
, flags
);
2704 priv
->vif
= conf
->vif
;
2706 spin_unlock_irqrestore(&priv
->lock
, flags
);
2708 mutex_lock(&priv
->mutex
);
2710 if (conf
->mac_addr
) {
2711 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
2712 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
2715 if (iwl4965_set_mode(priv
, conf
->type
) == -EAGAIN
)
2716 /* we are not ready, will run again when ready */
2717 set_bit(STATUS_MODE_PENDING
, &priv
->status
);
2719 mutex_unlock(&priv
->mutex
);
2721 IWL_DEBUG_MAC80211("leave\n");
2726 * iwl4965_mac_config - mac80211 config callback
2728 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2729 * be set inappropriately and the driver currently sets the hardware up to
2730 * use it whenever needed.
2732 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
2734 struct iwl_priv
*priv
= hw
->priv
;
2735 const struct iwl_channel_info
*ch_info
;
2736 unsigned long flags
;
2740 mutex_lock(&priv
->mutex
);
2741 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
2743 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
2745 if (conf
->radio_enabled
&& iwl_radio_kill_sw_enable_radio(priv
)) {
2746 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
2750 if (!conf
->radio_enabled
)
2751 iwl_radio_kill_sw_disable_radio(priv
);
2753 if (!iwl_is_ready(priv
)) {
2754 IWL_DEBUG_MAC80211("leave - not ready\n");
2759 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
2760 test_bit(STATUS_SCANNING
, &priv
->status
))) {
2761 IWL_DEBUG_MAC80211("leave - scanning\n");
2762 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
2763 mutex_unlock(&priv
->mutex
);
2767 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2768 ch_info
= iwl_get_channel_info(priv
, conf
->channel
->band
, channel
);
2769 if (!is_channel_valid(ch_info
)) {
2770 IWL_DEBUG_MAC80211("leave - invalid channel\n");
2775 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
&&
2776 !is_channel_ibss(ch_info
)) {
2777 IWL_ERROR("channel %d in band %d not IBSS channel\n",
2778 conf
->channel
->hw_value
, conf
->channel
->band
);
2783 spin_lock_irqsave(&priv
->lock
, flags
);
2785 /* if we are switching from ht to 2.4 clear flags
2786 * from any ht related info since 2.4 does not
2788 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != channel
)
2789 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
2790 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
2793 priv
->staging_rxon
.flags
= 0;
2795 iwl_set_rxon_channel(priv
, conf
->channel
->band
, channel
);
2797 iwl_set_flags_for_band(priv
, conf
->channel
->band
);
2799 /* The list of supported rates and rate mask can be different
2800 * for each band; since the band may have changed, reset
2801 * the rate mask to what mac80211 lists */
2802 iwl4965_set_rate(priv
);
2804 spin_unlock_irqrestore(&priv
->lock
, flags
);
2806 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
2807 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
2808 iwl4965_hw_channel_switch(priv
, conf
->channel
);
2813 if (!conf
->radio_enabled
) {
2814 IWL_DEBUG_MAC80211("leave - radio disabled\n");
2818 if (iwl_is_rfkill(priv
)) {
2819 IWL_DEBUG_MAC80211("leave - RF kill\n");
2824 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2825 priv
->tx_power_user_lmt
, conf
->power_level
);
2827 iwl_set_tx_power(priv
, conf
->power_level
, false);
2829 iwl4965_set_rate(priv
);
2831 if (memcmp(&priv
->active_rxon
,
2832 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
2833 iwl4965_commit_rxon(priv
);
2835 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2837 IWL_DEBUG_MAC80211("leave\n");
2840 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
2841 mutex_unlock(&priv
->mutex
);
2845 static void iwl4965_config_ap(struct iwl_priv
*priv
)
2849 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2852 /* The following should be done only at AP bring up */
2853 if (!(iwl_is_associated(priv
))) {
2855 /* RXON - unassoc (to set timing command) */
2856 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2857 iwl4965_commit_rxon(priv
);
2860 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
2861 iwl4965_setup_rxon_timing(priv
);
2862 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
2863 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
2865 IWL_WARNING("REPLY_RXON_TIMING failed - "
2866 "Attempting to continue.\n");
2868 iwl_set_rxon_chain(priv
);
2870 /* FIXME: what should be the assoc_id for AP? */
2871 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
2872 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
2873 priv
->staging_rxon
.flags
|=
2874 RXON_FLG_SHORT_PREAMBLE_MSK
;
2876 priv
->staging_rxon
.flags
&=
2877 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2879 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
2880 if (priv
->assoc_capability
&
2881 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
2882 priv
->staging_rxon
.flags
|=
2883 RXON_FLG_SHORT_SLOT_MSK
;
2885 priv
->staging_rxon
.flags
&=
2886 ~RXON_FLG_SHORT_SLOT_MSK
;
2888 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2889 priv
->staging_rxon
.flags
&=
2890 ~RXON_FLG_SHORT_SLOT_MSK
;
2892 /* restore RXON assoc */
2893 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
2894 iwl4965_commit_rxon(priv
);
2895 iwl4965_activate_qos(priv
, 1);
2896 iwl_rxon_add_station(priv
, iwl_bcast_addr
, 0);
2898 iwl4965_send_beacon_cmd(priv
);
2900 /* FIXME - we need to add code here to detect a totally new
2901 * configuration, reset the AP, unassoc, rxon timing, assoc,
2902 * clear sta table, add BCAST sta... */
2906 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
);
2908 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
2909 struct ieee80211_vif
*vif
,
2910 struct ieee80211_if_conf
*conf
)
2912 struct iwl_priv
*priv
= hw
->priv
;
2913 DECLARE_MAC_BUF(mac
);
2914 unsigned long flags
;
2920 if (priv
->vif
!= vif
) {
2921 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
2925 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
&&
2926 conf
->changed
& IEEE80211_IFCC_BEACON
) {
2927 struct sk_buff
*beacon
= ieee80211_beacon_get(hw
, vif
);
2930 rc
= iwl4965_mac_beacon_update(hw
, beacon
);
2935 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
2936 (!conf
->ssid_len
)) {
2938 ("Leaving in AP mode because HostAPD is not ready.\n");
2942 if (!iwl_is_alive(priv
))
2945 mutex_lock(&priv
->mutex
);
2948 IWL_DEBUG_MAC80211("bssid: %s\n",
2949 print_mac(mac
, conf
->bssid
));
2952 * very dubious code was here; the probe filtering flag is never set:
2954 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2955 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
2958 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
2960 conf
->bssid
= priv
->mac_addr
;
2961 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
2962 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
2963 print_mac(mac
, conf
->bssid
));
2965 if (priv
->ibss_beacon
)
2966 dev_kfree_skb(priv
->ibss_beacon
);
2968 priv
->ibss_beacon
= ieee80211_beacon_get(hw
, vif
);
2971 if (iwl_is_rfkill(priv
))
2974 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
2975 !is_multicast_ether_addr(conf
->bssid
)) {
2976 /* If there is currently a HW scan going on in the background
2977 * then we need to cancel it else the RXON below will fail. */
2978 if (iwl_scan_cancel_timeout(priv
, 100)) {
2979 IWL_WARNING("Aborted scan still in progress "
2981 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2982 mutex_unlock(&priv
->mutex
);
2985 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
2987 /* TODO: Audit driver for usage of these members and see
2988 * if mac80211 deprecates them (priv->bssid looks like it
2989 * shouldn't be there, but I haven't scanned the IBSS code
2990 * to verify) - jpk */
2991 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
2993 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
2994 iwl4965_config_ap(priv
);
2996 rc
= iwl4965_commit_rxon(priv
);
2997 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
2998 iwl_rxon_add_station(
2999 priv
, priv
->active_rxon
.bssid_addr
, 1);
3003 iwl_scan_cancel_timeout(priv
, 100);
3004 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3005 iwl4965_commit_rxon(priv
);
3009 spin_lock_irqsave(&priv
->lock
, flags
);
3010 if (!conf
->ssid_len
)
3011 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
3013 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
3015 priv
->essid_len
= conf
->ssid_len
;
3016 spin_unlock_irqrestore(&priv
->lock
, flags
);
3018 IWL_DEBUG_MAC80211("leave\n");
3019 mutex_unlock(&priv
->mutex
);
3024 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
3025 unsigned int changed_flags
,
3026 unsigned int *total_flags
,
3027 int mc_count
, struct dev_addr_list
*mc_list
)
3029 struct iwl_priv
*priv
= hw
->priv
;
3031 if (changed_flags
& (*total_flags
) & FIF_OTHER_BSS
) {
3032 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
3033 IEEE80211_IF_TYPE_MNTR
,
3034 changed_flags
, *total_flags
);
3035 /* queue work 'cuz mac80211 is holding a lock which
3036 * prevents us from issuing (synchronous) f/w cmds */
3037 queue_work(priv
->workqueue
, &priv
->set_monitor
);
3039 *total_flags
&= FIF_OTHER_BSS
| FIF_ALLMULTI
|
3040 FIF_BCN_PRBRESP_PROMISC
| FIF_CONTROL
;
3043 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
3044 struct ieee80211_if_init_conf
*conf
)
3046 struct iwl_priv
*priv
= hw
->priv
;
3048 IWL_DEBUG_MAC80211("enter\n");
3050 mutex_lock(&priv
->mutex
);
3052 if (iwl_is_ready_rf(priv
)) {
3053 iwl_scan_cancel_timeout(priv
, 100);
3054 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3055 iwl4965_commit_rxon(priv
);
3057 if (priv
->vif
== conf
->vif
) {
3059 memset(priv
->bssid
, 0, ETH_ALEN
);
3060 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
3061 priv
->essid_len
= 0;
3063 mutex_unlock(&priv
->mutex
);
3065 IWL_DEBUG_MAC80211("leave\n");
3069 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
3070 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
3071 struct ieee80211_vif
*vif
,
3072 struct ieee80211_bss_conf
*bss_conf
,
3075 struct iwl_priv
*priv
= hw
->priv
;
3077 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
3079 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
3080 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
3081 bss_conf
->use_short_preamble
);
3082 if (bss_conf
->use_short_preamble
)
3083 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
3085 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
3088 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
3089 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
3090 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
3091 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
3093 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
3096 if (changes
& BSS_CHANGED_HT
) {
3097 IWL_DEBUG_MAC80211("HT %d\n", bss_conf
->assoc_ht
);
3098 iwl4965_ht_conf(priv
, bss_conf
);
3099 iwl_set_rxon_chain(priv
);
3102 if (changes
& BSS_CHANGED_ASSOC
) {
3103 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
3104 /* This should never happen as this function should
3105 * never be called from interrupt context. */
3106 if (WARN_ON_ONCE(in_interrupt()))
3108 if (bss_conf
->assoc
) {
3109 priv
->assoc_id
= bss_conf
->aid
;
3110 priv
->beacon_int
= bss_conf
->beacon_int
;
3111 priv
->timestamp
= bss_conf
->timestamp
;
3112 priv
->assoc_capability
= bss_conf
->assoc_capability
;
3113 priv
->next_scan_jiffies
= jiffies
+
3114 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
3115 mutex_lock(&priv
->mutex
);
3116 iwl4965_post_associate(priv
);
3117 mutex_unlock(&priv
->mutex
);
3120 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
3122 } else if (changes
&& iwl_is_associated(priv
) && priv
->assoc_id
) {
3123 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
3124 iwl_send_rxon_assoc(priv
);
3129 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
3132 unsigned long flags
;
3133 struct iwl_priv
*priv
= hw
->priv
;
3135 IWL_DEBUG_MAC80211("enter\n");
3137 mutex_lock(&priv
->mutex
);
3138 spin_lock_irqsave(&priv
->lock
, flags
);
3140 if (!iwl_is_ready_rf(priv
)) {
3142 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3146 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
3148 IWL_ERROR("ERROR: APs don't scan\n");
3152 /* we don't schedule scan within next_scan_jiffies period */
3153 if (priv
->next_scan_jiffies
&&
3154 time_after(priv
->next_scan_jiffies
, jiffies
)) {
3158 /* if we just finished scan ask for delay */
3159 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
3160 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
3165 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
3166 iwl_escape_essid(ssid
, len
), (int)len
);
3168 priv
->one_direct_scan
= 1;
3169 priv
->direct_ssid_len
= (u8
)
3170 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
3171 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
3173 priv
->one_direct_scan
= 0;
3175 rc
= iwl_scan_initiate(priv
);
3177 IWL_DEBUG_MAC80211("leave\n");
3180 spin_unlock_irqrestore(&priv
->lock
, flags
);
3181 mutex_unlock(&priv
->mutex
);
3186 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw
*hw
,
3187 struct ieee80211_key_conf
*keyconf
, const u8
*addr
,
3188 u32 iv32
, u16
*phase1key
)
3190 struct iwl_priv
*priv
= hw
->priv
;
3191 u8 sta_id
= IWL_INVALID_STATION
;
3192 unsigned long flags
;
3193 __le16 key_flags
= 0;
3195 DECLARE_MAC_BUF(mac
);
3197 IWL_DEBUG_MAC80211("enter\n");
3199 sta_id
= iwl_find_station(priv
, addr
);
3200 if (sta_id
== IWL_INVALID_STATION
) {
3201 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3202 print_mac(mac
, addr
));
3206 iwl_scan_cancel_timeout(priv
, 100);
3208 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
3209 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
3210 key_flags
&= ~STA_KEY_FLG_INVALID
;
3212 if (sta_id
== priv
->hw_params
.bcast_sta_id
)
3213 key_flags
|= STA_KEY_MULTICAST_MSK
;
3215 spin_lock_irqsave(&priv
->sta_lock
, flags
);
3217 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
3218 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
3220 for (i
= 0; i
< 5; i
++)
3221 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
3222 cpu_to_le16(phase1key
[i
]);
3224 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
3225 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
3227 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
3229 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
3231 IWL_DEBUG_MAC80211("leave\n");
3234 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3235 const u8
*local_addr
, const u8
*addr
,
3236 struct ieee80211_key_conf
*key
)
3238 struct iwl_priv
*priv
= hw
->priv
;
3239 DECLARE_MAC_BUF(mac
);
3241 u8 sta_id
= IWL_INVALID_STATION
;
3242 u8 is_default_wep_key
= 0;
3244 IWL_DEBUG_MAC80211("enter\n");
3246 if (priv
->hw_params
.sw_crypto
) {
3247 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3251 if (is_zero_ether_addr(addr
))
3252 /* only support pairwise keys */
3255 sta_id
= iwl_find_station(priv
, addr
);
3256 if (sta_id
== IWL_INVALID_STATION
) {
3257 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3258 print_mac(mac
, addr
));
3263 mutex_lock(&priv
->mutex
);
3264 iwl_scan_cancel_timeout(priv
, 100);
3265 mutex_unlock(&priv
->mutex
);
3267 /* If we are getting WEP group key and we didn't receive any key mapping
3268 * so far, we are in legacy wep mode (group key only), otherwise we are
3270 * In legacy wep mode, we use another host command to the uCode */
3271 if (key
->alg
== ALG_WEP
&& sta_id
== priv
->hw_params
.bcast_sta_id
&&
3272 priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
3274 is_default_wep_key
= !priv
->key_mapping_key
;
3276 is_default_wep_key
=
3277 (key
->hw_key_idx
== HW_KEY_DEFAULT
);
3282 if (is_default_wep_key
)
3283 ret
= iwl_set_default_wep_key(priv
, key
);
3285 ret
= iwl_set_dynamic_key(priv
, key
, sta_id
);
3287 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
3290 if (is_default_wep_key
)
3291 ret
= iwl_remove_default_wep_key(priv
, key
);
3293 ret
= iwl_remove_dynamic_key(priv
, key
, sta_id
);
3295 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
3301 IWL_DEBUG_MAC80211("leave\n");
3306 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
3307 const struct ieee80211_tx_queue_params
*params
)
3309 struct iwl_priv
*priv
= hw
->priv
;
3310 unsigned long flags
;
3313 IWL_DEBUG_MAC80211("enter\n");
3315 if (!iwl_is_ready_rf(priv
)) {
3316 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3320 if (queue
>= AC_NUM
) {
3321 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
3325 if (!priv
->qos_data
.qos_enable
) {
3326 priv
->qos_data
.qos_active
= 0;
3327 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
3330 q
= AC_NUM
- 1 - queue
;
3332 spin_lock_irqsave(&priv
->lock
, flags
);
3334 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
3335 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
3336 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
3337 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
3338 cpu_to_le16((params
->txop
* 32));
3340 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
3341 priv
->qos_data
.qos_active
= 1;
3343 spin_unlock_irqrestore(&priv
->lock
, flags
);
3345 mutex_lock(&priv
->mutex
);
3346 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
3347 iwl4965_activate_qos(priv
, 1);
3348 else if (priv
->assoc_id
&& iwl_is_associated(priv
))
3349 iwl4965_activate_qos(priv
, 0);
3351 mutex_unlock(&priv
->mutex
);
3353 IWL_DEBUG_MAC80211("leave\n");
3357 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
3358 struct ieee80211_tx_queue_stats
*stats
)
3360 struct iwl_priv
*priv
= hw
->priv
;
3362 struct iwl_tx_queue
*txq
;
3363 struct iwl_queue
*q
;
3364 unsigned long flags
;
3366 IWL_DEBUG_MAC80211("enter\n");
3368 if (!iwl_is_ready_rf(priv
)) {
3369 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3373 spin_lock_irqsave(&priv
->lock
, flags
);
3375 for (i
= 0; i
< AC_NUM
; i
++) {
3376 txq
= &priv
->txq
[i
];
3378 avail
= iwl_queue_space(q
);
3380 stats
[i
].len
= q
->n_window
- avail
;
3381 stats
[i
].limit
= q
->n_window
- q
->high_mark
;
3382 stats
[i
].count
= q
->n_window
;
3385 spin_unlock_irqrestore(&priv
->lock
, flags
);
3387 IWL_DEBUG_MAC80211("leave\n");
3392 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
3393 struct ieee80211_low_level_stats
*stats
)
3395 struct iwl_priv
*priv
= hw
->priv
;
3398 IWL_DEBUG_MAC80211("enter\n");
3399 IWL_DEBUG_MAC80211("leave\n");
3404 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
3406 struct iwl_priv
*priv
= hw
->priv
;
3407 unsigned long flags
;
3409 mutex_lock(&priv
->mutex
);
3410 IWL_DEBUG_MAC80211("enter\n");
3412 spin_lock_irqsave(&priv
->lock
, flags
);
3413 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
3414 spin_unlock_irqrestore(&priv
->lock
, flags
);
3416 iwl_reset_qos(priv
);
3418 spin_lock_irqsave(&priv
->lock
, flags
);
3420 priv
->assoc_capability
= 0;
3421 priv
->assoc_station_added
= 0;
3423 /* new association get rid of ibss beacon skb */
3424 if (priv
->ibss_beacon
)
3425 dev_kfree_skb(priv
->ibss_beacon
);
3427 priv
->ibss_beacon
= NULL
;
3429 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
3430 priv
->timestamp
= 0;
3431 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
3432 priv
->beacon_int
= 0;
3434 spin_unlock_irqrestore(&priv
->lock
, flags
);
3436 if (!iwl_is_ready_rf(priv
)) {
3437 IWL_DEBUG_MAC80211("leave - not ready\n");
3438 mutex_unlock(&priv
->mutex
);
3442 /* we are restarting association process
3443 * clear RXON_FILTER_ASSOC_MSK bit
3445 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
3446 iwl_scan_cancel_timeout(priv
, 100);
3447 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3448 iwl4965_commit_rxon(priv
);
3451 iwl_power_update_mode(priv
, 0);
3453 /* Per mac80211.h: This is only used in IBSS mode... */
3454 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
3456 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3457 mutex_unlock(&priv
->mutex
);
3461 iwl4965_set_rate(priv
);
3463 mutex_unlock(&priv
->mutex
);
3465 IWL_DEBUG_MAC80211("leave\n");
3468 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3470 struct iwl_priv
*priv
= hw
->priv
;
3471 unsigned long flags
;
3474 mutex_lock(&priv
->mutex
);
3475 IWL_DEBUG_MAC80211("enter\n");
3477 if (!iwl_is_ready_rf(priv
)) {
3478 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3479 mutex_unlock(&priv
->mutex
);
3483 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
3484 IWL_DEBUG_MAC80211("leave - not IBSS\n");
3485 mutex_unlock(&priv
->mutex
);
3489 spin_lock_irqsave(&priv
->lock
, flags
);
3491 if (priv
->ibss_beacon
)
3492 dev_kfree_skb(priv
->ibss_beacon
);
3494 priv
->ibss_beacon
= skb
;
3497 timestamp
= ((struct ieee80211_mgmt
*)skb
->data
)->u
.beacon
.timestamp
;
3498 priv
->timestamp
= le64_to_cpu(timestamp
) + (priv
->beacon_int
* 1000);
3500 IWL_DEBUG_MAC80211("leave\n");
3501 spin_unlock_irqrestore(&priv
->lock
, flags
);
3503 iwl_reset_qos(priv
);
3505 iwl4965_post_associate(priv
);
3507 mutex_unlock(&priv
->mutex
);
3512 /*****************************************************************************
3516 *****************************************************************************/
3518 #ifdef CONFIG_IWLWIFI_DEBUG
3521 * The following adds a new attribute to the sysfs representation
3522 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3523 * used for controlling the debug level.
3525 * See the level definitions in iwl for details.
3528 static ssize_t
show_debug_level(struct device
*d
,
3529 struct device_attribute
*attr
, char *buf
)
3531 struct iwl_priv
*priv
= d
->driver_data
;
3533 return sprintf(buf
, "0x%08X\n", priv
->debug_level
);
3535 static ssize_t
store_debug_level(struct device
*d
,
3536 struct device_attribute
*attr
,
3537 const char *buf
, size_t count
)
3539 struct iwl_priv
*priv
= d
->driver_data
;
3540 char *p
= (char *)buf
;
3543 val
= simple_strtoul(p
, &p
, 0);
3545 printk(KERN_INFO DRV_NAME
3546 ": %s is not in hex or decimal form.\n", buf
);
3548 priv
->debug_level
= val
;
3550 return strnlen(buf
, count
);
3553 static DEVICE_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
3554 show_debug_level
, store_debug_level
);
3557 #endif /* CONFIG_IWLWIFI_DEBUG */
3560 static ssize_t
show_version(struct device
*d
,
3561 struct device_attribute
*attr
, char *buf
)
3563 struct iwl_priv
*priv
= d
->driver_data
;
3564 struct iwl_alive_resp
*palive
= &priv
->card_alive
;
3568 if (palive
->is_valid
)
3569 pos
+= sprintf(buf
+ pos
,
3570 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3571 "fw type: 0x%01X 0x%01X\n",
3572 palive
->ucode_major
, palive
->ucode_minor
,
3573 palive
->sw_rev
[0], palive
->sw_rev
[1],
3574 palive
->ver_type
, palive
->ver_subtype
);
3576 pos
+= sprintf(buf
+ pos
, "fw not loaded\n");
3579 eeprom_ver
= iwl_eeprom_query16(priv
, EEPROM_VERSION
);
3580 pos
+= sprintf(buf
+ pos
, "EEPROM version: 0x%x\n",
3583 pos
+= sprintf(buf
+ pos
, "EEPROM not initialzed\n");
3589 static DEVICE_ATTR(version
, S_IWUSR
| S_IRUGO
, show_version
, NULL
);
3591 static ssize_t
show_temperature(struct device
*d
,
3592 struct device_attribute
*attr
, char *buf
)
3594 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3596 if (!iwl_is_alive(priv
))
3599 return sprintf(buf
, "%d\n", priv
->temperature
);
3602 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
3604 static ssize_t
show_rs_window(struct device
*d
,
3605 struct device_attribute
*attr
,
3608 struct iwl_priv
*priv
= d
->driver_data
;
3609 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
3611 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
3613 static ssize_t
show_tx_power(struct device
*d
,
3614 struct device_attribute
*attr
, char *buf
)
3616 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3617 return sprintf(buf
, "%d\n", priv
->tx_power_user_lmt
);
3620 static ssize_t
store_tx_power(struct device
*d
,
3621 struct device_attribute
*attr
,
3622 const char *buf
, size_t count
)
3624 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3625 char *p
= (char *)buf
;
3628 val
= simple_strtoul(p
, &p
, 10);
3630 printk(KERN_INFO DRV_NAME
3631 ": %s is not in decimal form.\n", buf
);
3633 iwl_set_tx_power(priv
, val
, false);
3638 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
3640 static ssize_t
show_flags(struct device
*d
,
3641 struct device_attribute
*attr
, char *buf
)
3643 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3645 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
3648 static ssize_t
store_flags(struct device
*d
,
3649 struct device_attribute
*attr
,
3650 const char *buf
, size_t count
)
3652 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3653 u32 flags
= simple_strtoul(buf
, NULL
, 0);
3655 mutex_lock(&priv
->mutex
);
3656 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
3657 /* Cancel any currently running scans... */
3658 if (iwl_scan_cancel_timeout(priv
, 100))
3659 IWL_WARNING("Could not cancel scan.\n");
3661 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
3663 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
3664 iwl4965_commit_rxon(priv
);
3667 mutex_unlock(&priv
->mutex
);
3672 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
3674 static ssize_t
show_filter_flags(struct device
*d
,
3675 struct device_attribute
*attr
, char *buf
)
3677 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3679 return sprintf(buf
, "0x%04X\n",
3680 le32_to_cpu(priv
->active_rxon
.filter_flags
));
3683 static ssize_t
store_filter_flags(struct device
*d
,
3684 struct device_attribute
*attr
,
3685 const char *buf
, size_t count
)
3687 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3688 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
3690 mutex_lock(&priv
->mutex
);
3691 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
3692 /* Cancel any currently running scans... */
3693 if (iwl_scan_cancel_timeout(priv
, 100))
3694 IWL_WARNING("Could not cancel scan.\n");
3696 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3697 "0x%04X\n", filter_flags
);
3698 priv
->staging_rxon
.filter_flags
=
3699 cpu_to_le32(filter_flags
);
3700 iwl4965_commit_rxon(priv
);
3703 mutex_unlock(&priv
->mutex
);
3708 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
3709 store_filter_flags
);
3711 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3713 static ssize_t
show_measurement(struct device
*d
,
3714 struct device_attribute
*attr
, char *buf
)
3716 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3717 struct iwl4965_spectrum_notification measure_report
;
3718 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
3719 u8
*data
= (u8
*) & measure_report
;
3720 unsigned long flags
;
3722 spin_lock_irqsave(&priv
->lock
, flags
);
3723 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
3724 spin_unlock_irqrestore(&priv
->lock
, flags
);
3727 memcpy(&measure_report
, &priv
->measure_report
, size
);
3728 priv
->measurement_status
= 0;
3729 spin_unlock_irqrestore(&priv
->lock
, flags
);
3731 while (size
&& (PAGE_SIZE
- len
)) {
3732 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
3733 PAGE_SIZE
- len
, 1);
3735 if (PAGE_SIZE
- len
)
3739 size
-= min(size
, 16U);
3745 static ssize_t
store_measurement(struct device
*d
,
3746 struct device_attribute
*attr
,
3747 const char *buf
, size_t count
)
3749 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3750 struct ieee80211_measurement_params params
= {
3751 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
3752 .start_time
= cpu_to_le64(priv
->last_tsf
),
3753 .duration
= cpu_to_le16(1),
3755 u8 type
= IWL_MEASURE_BASIC
;
3761 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
3762 channel
= simple_strtoul(p
, NULL
, 0);
3764 params
.channel
= channel
;
3767 while (*p
&& *p
!= ' ')
3770 type
= simple_strtoul(p
+ 1, NULL
, 0);
3773 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3774 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
3775 iwl4965_get_measurement(priv
, ¶ms
, type
);
3780 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
3781 show_measurement
, store_measurement
);
3782 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
3784 static ssize_t
store_retry_rate(struct device
*d
,
3785 struct device_attribute
*attr
,
3786 const char *buf
, size_t count
)
3788 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3790 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
3791 if (priv
->retry_rate
<= 0)
3792 priv
->retry_rate
= 1;
3797 static ssize_t
show_retry_rate(struct device
*d
,
3798 struct device_attribute
*attr
, char *buf
)
3800 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3801 return sprintf(buf
, "%d", priv
->retry_rate
);
3804 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
3807 static ssize_t
store_power_level(struct device
*d
,
3808 struct device_attribute
*attr
,
3809 const char *buf
, size_t count
)
3811 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3815 mode
= simple_strtoul(buf
, NULL
, 0);
3816 mutex_lock(&priv
->mutex
);
3818 if (!iwl_is_ready(priv
)) {
3823 rc
= iwl_power_set_user_mode(priv
, mode
);
3825 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3831 mutex_unlock(&priv
->mutex
);
3835 #define MAX_WX_STRING 80
3837 /* Values are in microsecond */
3838 static const s32 timeout_duration
[] = {
3845 static const s32 period_duration
[] = {
3853 static ssize_t
show_power_level(struct device
*d
,
3854 struct device_attribute
*attr
, char *buf
)
3856 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3857 int level
= priv
->power_data
.power_mode
;
3860 p
+= sprintf(p
, "%d ", level
);
3862 case IWL_POWER_MODE_CAM
:
3864 p
+= sprintf(p
, "(AC)");
3866 case IWL_POWER_BATTERY
:
3867 p
+= sprintf(p
, "(BATTERY)");
3871 "(Timeout %dms, Period %dms)",
3872 timeout_duration
[level
- 1] / 1000,
3873 period_duration
[level
- 1] / 1000);
3876 if (!(priv->power_mode & IWL_POWER_ENABLED))
3877 p += sprintf(p, " OFF\n");
3879 p += sprintf(p, " \n");
3881 p
+= sprintf(p
, " \n");
3882 return (p
- buf
+ 1);
3885 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
3888 static ssize_t
show_channels(struct device
*d
,
3889 struct device_attribute
*attr
, char *buf
)
3892 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3893 struct ieee80211_channel
*channels
= NULL
;
3894 const struct ieee80211_supported_band
*supp_band
= NULL
;
3898 if (!test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
))
3901 supp_band
= iwl_get_hw_mode(priv
, IEEE80211_BAND_2GHZ
);
3902 channels
= supp_band
->channels
;
3903 count
= supp_band
->n_channels
;
3905 len
+= sprintf(&buf
[len
],
3906 "Displaying %d channels in 2.4GHz band "
3907 "(802.11bg):\n", count
);
3909 for (i
= 0; i
< count
; i
++)
3910 len
+= sprintf(&buf
[len
], "%d: %ddBm: BSS%s%s, %s.\n",
3911 ieee80211_frequency_to_channel(
3912 channels
[i
].center_freq
),
3913 channels
[i
].max_power
,
3914 channels
[i
].flags
& IEEE80211_CHAN_RADAR
?
3915 " (IEEE 802.11h required)" : "",
3916 (!(channels
[i
].flags
& IEEE80211_CHAN_NO_IBSS
)
3917 || (channels
[i
].flags
&
3918 IEEE80211_CHAN_RADAR
)) ? "" :
3921 IEEE80211_CHAN_PASSIVE_SCAN
?
3922 "passive only" : "active/passive");
3924 supp_band
= iwl_get_hw_mode(priv
, IEEE80211_BAND_5GHZ
);
3925 channels
= supp_band
->channels
;
3926 count
= supp_band
->n_channels
;
3928 len
+= sprintf(&buf
[len
], "Displaying %d channels in 5.2GHz band "
3929 "(802.11a):\n", count
);
3931 for (i
= 0; i
< count
; i
++)
3932 len
+= sprintf(&buf
[len
], "%d: %ddBm: BSS%s%s, %s.\n",
3933 ieee80211_frequency_to_channel(
3934 channels
[i
].center_freq
),
3935 channels
[i
].max_power
,
3936 channels
[i
].flags
& IEEE80211_CHAN_RADAR
?
3937 " (IEEE 802.11h required)" : "",
3938 ((channels
[i
].flags
& IEEE80211_CHAN_NO_IBSS
)
3939 || (channels
[i
].flags
&
3940 IEEE80211_CHAN_RADAR
)) ? "" :
3943 IEEE80211_CHAN_PASSIVE_SCAN
?
3944 "passive only" : "active/passive");
3949 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
3951 static ssize_t
show_statistics(struct device
*d
,
3952 struct device_attribute
*attr
, char *buf
)
3954 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3955 u32 size
= sizeof(struct iwl_notif_statistics
);
3956 u32 len
= 0, ofs
= 0;
3957 u8
*data
= (u8
*) & priv
->statistics
;
3960 if (!iwl_is_alive(priv
))
3963 mutex_lock(&priv
->mutex
);
3964 rc
= iwl_send_statistics_request(priv
, 0);
3965 mutex_unlock(&priv
->mutex
);
3969 "Error sending statistics request: 0x%08X\n", rc
);
3973 while (size
&& (PAGE_SIZE
- len
)) {
3974 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
3975 PAGE_SIZE
- len
, 1);
3977 if (PAGE_SIZE
- len
)
3981 size
-= min(size
, 16U);
3987 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
3989 static ssize_t
show_status(struct device
*d
,
3990 struct device_attribute
*attr
, char *buf
)
3992 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3993 if (!iwl_is_alive(priv
))
3995 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
3998 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
4000 /*****************************************************************************
4002 * driver setup and teardown
4004 *****************************************************************************/
4006 static void iwl_setup_deferred_work(struct iwl_priv
*priv
)
4008 priv
->workqueue
= create_workqueue(DRV_NAME
);
4010 init_waitqueue_head(&priv
->wait_command_queue
);
4012 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
4013 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
4014 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
4015 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
4016 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
4017 INIT_WORK(&priv
->set_monitor
, iwl4965_bg_set_monitor
);
4018 INIT_WORK(&priv
->run_time_calib_work
, iwl_bg_run_time_calib_work
);
4019 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl_bg_init_alive_start
);
4020 INIT_DELAYED_WORK(&priv
->alive_start
, iwl_bg_alive_start
);
4022 /* FIXME : remove when resolved PENDING */
4023 INIT_WORK(&priv
->scan_completed
, iwl_bg_scan_completed
);
4024 iwl_setup_scan_deferred_work(priv
);
4026 if (priv
->cfg
->ops
->lib
->setup_deferred_work
)
4027 priv
->cfg
->ops
->lib
->setup_deferred_work(priv
);
4029 init_timer(&priv
->statistics_periodic
);
4030 priv
->statistics_periodic
.data
= (unsigned long)priv
;
4031 priv
->statistics_periodic
.function
= iwl4965_bg_statistics_periodic
;
4033 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
4034 iwl4965_irq_tasklet
, (unsigned long)priv
);
4037 static void iwl_cancel_deferred_work(struct iwl_priv
*priv
)
4039 if (priv
->cfg
->ops
->lib
->cancel_deferred_work
)
4040 priv
->cfg
->ops
->lib
->cancel_deferred_work(priv
);
4042 cancel_delayed_work_sync(&priv
->init_alive_start
);
4043 cancel_delayed_work(&priv
->scan_check
);
4044 cancel_delayed_work(&priv
->alive_start
);
4045 cancel_work_sync(&priv
->beacon_update
);
4046 del_timer_sync(&priv
->statistics_periodic
);
4049 static struct attribute
*iwl4965_sysfs_entries
[] = {
4050 &dev_attr_channels
.attr
,
4051 &dev_attr_flags
.attr
,
4052 &dev_attr_filter_flags
.attr
,
4053 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
4054 &dev_attr_measurement
.attr
,
4056 &dev_attr_power_level
.attr
,
4057 &dev_attr_retry_rate
.attr
,
4058 &dev_attr_rs_window
.attr
,
4059 &dev_attr_statistics
.attr
,
4060 &dev_attr_status
.attr
,
4061 &dev_attr_temperature
.attr
,
4062 &dev_attr_tx_power
.attr
,
4063 #ifdef CONFIG_IWLWIFI_DEBUG
4064 &dev_attr_debug_level
.attr
,
4066 &dev_attr_version
.attr
,
4071 static struct attribute_group iwl4965_attribute_group
= {
4072 .name
= NULL
, /* put in device directory */
4073 .attrs
= iwl4965_sysfs_entries
,
4076 static struct ieee80211_ops iwl4965_hw_ops
= {
4077 .tx
= iwl4965_mac_tx
,
4078 .start
= iwl4965_mac_start
,
4079 .stop
= iwl4965_mac_stop
,
4080 .add_interface
= iwl4965_mac_add_interface
,
4081 .remove_interface
= iwl4965_mac_remove_interface
,
4082 .config
= iwl4965_mac_config
,
4083 .config_interface
= iwl4965_mac_config_interface
,
4084 .configure_filter
= iwl4965_configure_filter
,
4085 .set_key
= iwl4965_mac_set_key
,
4086 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
4087 .get_stats
= iwl4965_mac_get_stats
,
4088 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
4089 .conf_tx
= iwl4965_mac_conf_tx
,
4090 .reset_tsf
= iwl4965_mac_reset_tsf
,
4091 .bss_info_changed
= iwl4965_bss_info_changed
,
4092 .ampdu_action
= iwl4965_mac_ampdu_action
,
4093 .hw_scan
= iwl4965_mac_hw_scan
4096 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
4099 struct iwl_priv
*priv
;
4100 struct ieee80211_hw
*hw
;
4101 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
4102 unsigned long flags
;
4103 DECLARE_MAC_BUF(mac
);
4105 /************************
4106 * 1. Allocating HW data
4107 ************************/
4109 /* Disabling hardware scan means that mac80211 will perform scans
4110 * "the hard way", rather than using device's scan. */
4111 if (cfg
->mod_params
->disable_hw_scan
) {
4112 if (cfg
->mod_params
->debug
& IWL_DL_INFO
)
4113 dev_printk(KERN_DEBUG
, &(pdev
->dev
),
4114 "Disabling hw_scan\n");
4115 iwl4965_hw_ops
.hw_scan
= NULL
;
4118 hw
= iwl_alloc_all(cfg
, &iwl4965_hw_ops
);
4124 /* At this point both hw and priv are allocated. */
4126 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
4128 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
4130 priv
->pci_dev
= pdev
;
4132 #ifdef CONFIG_IWLWIFI_DEBUG
4133 priv
->debug_level
= priv
->cfg
->mod_params
->debug
;
4134 atomic_set(&priv
->restrict_refcnt
, 0);
4137 /**************************
4138 * 2. Initializing PCI bus
4139 **************************/
4140 if (pci_enable_device(pdev
)) {
4142 goto out_ieee80211_free_hw
;
4145 pci_set_master(pdev
);
4147 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
4149 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
4151 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
4153 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
4154 /* both attempts failed: */
4156 printk(KERN_WARNING
"%s: No suitable DMA available.\n",
4158 goto out_pci_disable_device
;
4162 err
= pci_request_regions(pdev
, DRV_NAME
);
4164 goto out_pci_disable_device
;
4166 pci_set_drvdata(pdev
, priv
);
4168 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4169 * PCI Tx retries from interfering with C3 CPU state */
4170 pci_write_config_byte(pdev
, 0x41, 0x00);
4172 /***********************
4173 * 3. Read REV register
4174 ***********************/
4175 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
4176 if (!priv
->hw_base
) {
4178 goto out_pci_release_regions
;
4181 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
4182 (unsigned long long) pci_resource_len(pdev
, 0));
4183 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
4185 iwl_hw_detect(priv
);
4186 printk(KERN_INFO DRV_NAME
4187 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
4188 priv
->cfg
->name
, priv
->hw_rev
);
4191 err
= priv
->cfg
->ops
->lib
->apm_ops
.init(priv
);
4193 IWL_DEBUG_INFO("Failed to init APMG\n");
4199 /* Read the EEPROM */
4200 err
= iwl_eeprom_init(priv
);
4202 IWL_ERROR("Unable to init EEPROM\n");
4205 err
= iwl_eeprom_check_version(priv
);
4209 /* extract MAC Address */
4210 iwl_eeprom_get_mac(priv
, priv
->mac_addr
);
4211 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
4212 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
4214 /************************
4215 * 5. Setup HW constants
4216 ************************/
4217 if (iwl_set_hw_params(priv
)) {
4218 IWL_ERROR("failed to set hw parameters\n");
4219 goto out_free_eeprom
;
4222 /*******************
4224 *******************/
4226 err
= iwl_init_drv(priv
);
4228 goto out_free_eeprom
;
4229 /* At this point both hw and priv are initialized. */
4231 /**********************************
4232 * 7. Initialize module parameters
4233 **********************************/
4235 /* Disable radio (SW RF KILL) via parameter when loading driver */
4236 if (priv
->cfg
->mod_params
->disable
) {
4237 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
4238 IWL_DEBUG_INFO("Radio disabled.\n");
4241 /********************
4243 ********************/
4244 spin_lock_irqsave(&priv
->lock
, flags
);
4245 iwl4965_disable_interrupts(priv
);
4246 spin_unlock_irqrestore(&priv
->lock
, flags
);
4248 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
4250 IWL_ERROR("failed to create sysfs device attributes\n");
4251 goto out_uninit_drv
;
4255 iwl_setup_deferred_work(priv
);
4256 iwl_setup_rx_handlers(priv
);
4258 /********************
4260 ********************/
4261 pci_save_state(pdev
);
4262 pci_disable_device(pdev
);
4264 /**********************************
4265 * 10. Setup and register mac80211
4266 **********************************/
4268 err
= iwl_setup_mac(priv
);
4270 goto out_remove_sysfs
;
4272 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
4274 IWL_ERROR("failed to create debugfs files\n");
4276 err
= iwl_rfkill_init(priv
);
4278 IWL_ERROR("Unable to initialize RFKILL system. "
4279 "Ignoring error: %d\n", err
);
4280 iwl_power_initialize(priv
);
4284 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
4286 iwl_uninit_drv(priv
);
4288 iwl_eeprom_free(priv
);
4290 pci_iounmap(pdev
, priv
->hw_base
);
4291 out_pci_release_regions
:
4292 pci_release_regions(pdev
);
4293 pci_set_drvdata(pdev
, NULL
);
4294 out_pci_disable_device
:
4295 pci_disable_device(pdev
);
4296 out_ieee80211_free_hw
:
4297 ieee80211_free_hw(priv
->hw
);
4302 static void __devexit
iwl4965_pci_remove(struct pci_dev
*pdev
)
4304 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
4305 unsigned long flags
;
4310 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4312 iwl_dbgfs_unregister(priv
);
4313 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
4315 if (priv
->mac80211_registered
) {
4316 ieee80211_unregister_hw(priv
->hw
);
4317 priv
->mac80211_registered
= 0;
4320 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4324 /* make sure we flush any pending irq or
4325 * tasklet for the driver
4327 spin_lock_irqsave(&priv
->lock
, flags
);
4328 iwl4965_disable_interrupts(priv
);
4329 spin_unlock_irqrestore(&priv
->lock
, flags
);
4331 iwl_synchronize_irq(priv
);
4333 iwl_rfkill_unregister(priv
);
4334 iwl4965_dealloc_ucode_pci(priv
);
4337 iwl_rx_queue_free(priv
, &priv
->rxq
);
4338 iwl_hw_txq_ctx_free(priv
);
4340 iwl_clear_stations_table(priv
);
4341 iwl_eeprom_free(priv
);
4344 /*netif_stop_queue(dev); */
4345 flush_workqueue(priv
->workqueue
);
4347 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
4348 * priv->workqueue... so we can't take down the workqueue
4350 destroy_workqueue(priv
->workqueue
);
4351 priv
->workqueue
= NULL
;
4353 pci_iounmap(pdev
, priv
->hw_base
);
4354 pci_release_regions(pdev
);
4355 pci_disable_device(pdev
);
4356 pci_set_drvdata(pdev
, NULL
);
4358 iwl_uninit_drv(priv
);
4360 if (priv
->ibss_beacon
)
4361 dev_kfree_skb(priv
->ibss_beacon
);
4363 ieee80211_free_hw(priv
->hw
);
4368 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4370 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
4372 if (priv
->is_open
) {
4373 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
4374 iwl4965_mac_stop(priv
->hw
);
4378 pci_set_power_state(pdev
, PCI_D3hot
);
4383 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
4385 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
4387 pci_set_power_state(pdev
, PCI_D0
);
4390 iwl4965_mac_start(priv
->hw
);
4392 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
4396 #endif /* CONFIG_PM */
4398 /*****************************************************************************
4400 * driver and module entry point
4402 *****************************************************************************/
4404 /* Hardware specific file defines the PCI IDs table for that hardware module */
4405 static struct pci_device_id iwl_hw_card_ids
[] = {
4406 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID
, iwl4965_agn_cfg
)},
4407 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID
, iwl4965_agn_cfg
)},
4408 #ifdef CONFIG_IWL5000
4409 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg
)},
4410 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg
)},
4411 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg
)},
4412 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg
)},
4413 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg
)},
4414 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg
)},
4415 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID
, iwl5100_agn_cfg
)},
4416 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID
, iwl5300_agn_cfg
)},
4417 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID
, iwl5300_agn_cfg
)},
4418 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID
, iwl5100_agn_cfg
)},
4419 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID
, iwl5350_agn_cfg
)},
4420 #endif /* CONFIG_IWL5000 */
4423 MODULE_DEVICE_TABLE(pci
, iwl_hw_card_ids
);
4425 static struct pci_driver iwl_driver
= {
4427 .id_table
= iwl_hw_card_ids
,
4428 .probe
= iwl4965_pci_probe
,
4429 .remove
= __devexit_p(iwl4965_pci_remove
),
4431 .suspend
= iwl4965_pci_suspend
,
4432 .resume
= iwl4965_pci_resume
,
4436 static int __init
iwl4965_init(void)
4440 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
4441 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
4443 ret
= iwl4965_rate_control_register();
4445 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret
);
4449 ret
= pci_register_driver(&iwl_driver
);
4451 IWL_ERROR("Unable to initialize PCI module\n");
4452 goto error_register
;
4458 iwl4965_rate_control_unregister();
4462 static void __exit
iwl4965_exit(void)
4464 pci_unregister_driver(&iwl_driver
);
4465 iwl4965_rate_control_unregister();
4468 module_exit(iwl4965_exit
);
4469 module_init(iwl4965_init
);