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 (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
196 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
197 priv
->active_rxon
.bssid_addr
) ||
198 compare_ether_addr(priv
->staging_rxon
.node_addr
,
199 priv
->active_rxon
.node_addr
) ||
200 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
201 priv
->active_rxon
.wlap_bssid_addr
) ||
202 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
203 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
204 (priv
->staging_rxon
.air_propagation
!=
205 priv
->active_rxon
.air_propagation
) ||
206 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
207 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
208 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
209 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
210 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
211 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
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 if (!iwl_is_alive(priv
))
249 /* always get timestamp with Rx frame */
250 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
252 rc
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
254 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
258 /* If we don't need to send a full RXON, we can use
259 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
260 * and other flags for the current radio configuration. */
261 if (!iwl4965_full_rxon_required(priv
)) {
262 rc
= iwl_send_rxon_assoc(priv
);
264 IWL_ERROR("Error setting RXON_ASSOC "
265 "configuration (%d).\n", rc
);
269 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
274 /* station table will be cleared */
275 priv
->assoc_station_added
= 0;
277 /* If we are currently associated and the new config requires
278 * an RXON_ASSOC and the new config wants the associated mask enabled,
279 * we must clear the associated from the active configuration
280 * before we apply the new config */
281 if (iwl_is_associated(priv
) &&
282 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
283 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
284 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
286 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
287 sizeof(struct iwl_rxon_cmd
),
290 /* If the mask clearing failed then we set
291 * active_rxon back to what it was previously */
293 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
294 IWL_ERROR("Error clearing ASSOC_MSK on current "
295 "configuration (%d).\n", rc
);
300 IWL_DEBUG_INFO("Sending RXON\n"
301 "* with%s RXON_FILTER_ASSOC_MSK\n"
304 ((priv
->staging_rxon
.filter_flags
&
305 RXON_FILTER_ASSOC_MSK
) ? "" : "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
);
310 /* Apply the new configuration */
311 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
312 sizeof(struct iwl_rxon_cmd
), &priv
->staging_rxon
);
314 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
318 iwlcore_clear_stations_table(priv
);
320 if (!priv
->error_recovering
)
321 priv
->start_calib
= 0;
323 iwl_init_sensitivity(priv
);
325 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
327 /* If we issue a new RXON command which required a tune then we must
328 * send a new TXPOWER command or we won't be able to Tx any frames */
329 rc
= iwl_set_tx_power(priv
, priv
->tx_power_user_lmt
, true);
331 IWL_ERROR("Error sending TX power (%d).\n", rc
);
335 /* Add the broadcast address so we can send broadcast frames */
336 if (iwl_rxon_add_station(priv
, iwl_bcast_addr
, 0) ==
337 IWL_INVALID_STATION
) {
338 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
342 /* If we have set the ASSOC_MSK and we are in BSS mode then
343 * add the IWL_AP_ID to the station rate table */
344 if (iwl_is_associated(priv
) &&
345 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
346 if (iwl_rxon_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1)
347 == IWL_INVALID_STATION
) {
348 IWL_ERROR("Error adding AP address for transmit.\n");
351 priv
->assoc_station_added
= 1;
352 if (priv
->default_wep_key
&&
353 iwl_send_static_wepkey_cmd(priv
, 0))
354 IWL_ERROR("Could not send WEP static key.\n");
360 void iwl4965_update_chain_flags(struct iwl_priv
*priv
)
363 iwl_set_rxon_chain(priv
);
364 iwl4965_commit_rxon(priv
);
367 static int iwl4965_send_bt_config(struct iwl_priv
*priv
)
369 struct iwl4965_bt_cmd bt_cmd
= {
377 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
378 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
381 static void iwl_clear_free_frames(struct iwl_priv
*priv
)
383 struct list_head
*element
;
385 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
388 while (!list_empty(&priv
->free_frames
)) {
389 element
= priv
->free_frames
.next
;
391 kfree(list_entry(element
, struct iwl_frame
, list
));
392 priv
->frames_count
--;
395 if (priv
->frames_count
) {
396 IWL_WARNING("%d frames still in use. Did we lose one?\n",
398 priv
->frames_count
= 0;
402 static struct iwl_frame
*iwl_get_free_frame(struct iwl_priv
*priv
)
404 struct iwl_frame
*frame
;
405 struct list_head
*element
;
406 if (list_empty(&priv
->free_frames
)) {
407 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
409 IWL_ERROR("Could not allocate frame!\n");
413 priv
->frames_count
++;
417 element
= priv
->free_frames
.next
;
419 return list_entry(element
, struct iwl_frame
, list
);
422 static void iwl_free_frame(struct iwl_priv
*priv
, struct iwl_frame
*frame
)
424 memset(frame
, 0, sizeof(*frame
));
425 list_add(&frame
->list
, &priv
->free_frames
);
428 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv
*priv
,
429 struct ieee80211_hdr
*hdr
,
430 const u8
*dest
, int left
)
433 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
434 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
435 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
438 if (priv
->ibss_beacon
->len
> left
)
441 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
443 return priv
->ibss_beacon
->len
;
446 static u8
iwl4965_rate_get_lowest_plcp(struct iwl_priv
*priv
)
452 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
453 rate_mask
= priv
->active_rate_basic
& 0xF;
455 rate_mask
= priv
->active_rate_basic
& 0xFF0;
457 /* Find lowest valid rate */
458 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
459 i
= iwl_rates
[i
].next_ieee
) {
460 if (rate_mask
& (1 << i
))
461 return iwl_rates
[i
].plcp
;
464 /* No valid rate was found. Assign the lowest one */
465 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
466 return IWL_RATE_1M_PLCP
;
468 return IWL_RATE_6M_PLCP
;
471 static int iwl4965_send_beacon_cmd(struct iwl_priv
*priv
)
473 struct iwl_frame
*frame
;
474 unsigned int frame_size
;
478 frame
= iwl_get_free_frame(priv
);
481 IWL_ERROR("Could not obtain free frame buffer for beacon "
486 rate
= iwl4965_rate_get_lowest_plcp(priv
);
488 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
490 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
493 iwl_free_frame(priv
, frame
);
498 /******************************************************************************
500 * Misc. internal state and helper functions
502 ******************************************************************************/
504 static void iwl4965_ht_conf(struct iwl_priv
*priv
,
505 struct ieee80211_bss_conf
*bss_conf
)
507 struct ieee80211_ht_info
*ht_conf
= bss_conf
->ht_conf
;
508 struct ieee80211_ht_bss_info
*ht_bss_conf
= bss_conf
->ht_bss_conf
;
509 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
511 IWL_DEBUG_MAC80211("enter: \n");
513 iwl_conf
->is_ht
= bss_conf
->assoc_ht
;
515 if (!iwl_conf
->is_ht
)
518 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
520 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
521 iwl_conf
->sgf
|= HT_SHORT_GI_20MHZ
;
522 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
523 iwl_conf
->sgf
|= HT_SHORT_GI_40MHZ
;
525 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
526 iwl_conf
->max_amsdu_size
=
527 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
529 iwl_conf
->supported_chan_width
=
530 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
531 iwl_conf
->extension_chan_offset
=
532 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
533 /* If no above or below channel supplied disable FAT channel */
534 if (iwl_conf
->extension_chan_offset
!= IEEE80211_HT_IE_CHA_SEC_ABOVE
&&
535 iwl_conf
->extension_chan_offset
!= IEEE80211_HT_IE_CHA_SEC_BELOW
) {
536 iwl_conf
->extension_chan_offset
= IEEE80211_HT_IE_CHA_SEC_NONE
;
537 iwl_conf
->supported_chan_width
= 0;
540 iwl_conf
->tx_mimo_ps_mode
=
541 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
542 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
544 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
545 iwl_conf
->tx_chan_width
=
546 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
547 iwl_conf
->ht_protection
=
548 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
549 iwl_conf
->non_GF_STA_present
=
550 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
552 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf
->control_channel
);
553 IWL_DEBUG_MAC80211("leave\n");
559 static int iwl4965_send_qos_params_command(struct iwl_priv
*priv
,
560 struct iwl4965_qosparam_cmd
*qos
)
563 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
564 sizeof(struct iwl4965_qosparam_cmd
), qos
);
567 static void iwl4965_activate_qos(struct iwl_priv
*priv
, u8 force
)
571 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
574 if (!priv
->qos_data
.qos_enable
)
577 spin_lock_irqsave(&priv
->lock
, flags
);
578 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
580 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
581 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
582 priv
->qos_data
.def_qos_parm
.qos_flags
|=
583 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
584 if (priv
->qos_data
.qos_active
)
585 priv
->qos_data
.def_qos_parm
.qos_flags
|=
586 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
588 if (priv
->current_ht_config
.is_ht
)
589 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
591 spin_unlock_irqrestore(&priv
->lock
, flags
);
593 if (force
|| iwl_is_associated(priv
)) {
594 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
595 priv
->qos_data
.qos_active
,
596 priv
->qos_data
.def_qos_parm
.qos_flags
);
598 iwl4965_send_qos_params_command(priv
,
599 &(priv
->qos_data
.def_qos_parm
));
603 int iwl4965_is_network_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
605 /* Filter incoming packets to determine if they are targeted toward
606 * this network, discarding packets coming from ourselves */
607 switch (priv
->iw_mode
) {
608 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
609 /* packets from our adapter are dropped (echo) */
610 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
612 /* {broad,multi}cast packets to our IBSS go through */
613 if (is_multicast_ether_addr(header
->addr1
))
614 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
615 /* packets to our adapter go through */
616 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
617 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
618 /* packets from our adapter are dropped (echo) */
619 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
621 /* {broad,multi}cast packets to our BSS go through */
622 if (is_multicast_ether_addr(header
->addr1
))
623 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
624 /* packets to our adapter go through */
625 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
633 static void iwl4965_sequence_reset(struct iwl_priv
*priv
)
635 /* Reset ieee stats */
637 /* We don't reset the net_device_stats (ieee->stats) on
640 priv
->last_seq_num
= -1;
641 priv
->last_frag_num
= -1;
642 priv
->last_packet_time
= 0;
644 iwl_scan_cancel(priv
);
647 #define MAX_UCODE_BEACON_INTERVAL 4096
648 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
650 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
653 u16 beacon_factor
= 0;
656 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
657 / MAX_UCODE_BEACON_INTERVAL
;
658 new_val
= beacon_val
/ beacon_factor
;
660 return cpu_to_le16(new_val
);
663 static void iwl4965_setup_rxon_timing(struct iwl_priv
*priv
)
665 u64 interval_tm_unit
;
668 struct ieee80211_conf
*conf
= NULL
;
671 conf
= ieee80211_get_hw_conf(priv
->hw
);
673 spin_lock_irqsave(&priv
->lock
, flags
);
674 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp
>> 32);
675 priv
->rxon_timing
.timestamp
.dw
[0] =
676 cpu_to_le32(priv
->timestamp
& 0xFFFFFFFF);
678 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
680 tsf
= priv
->timestamp
;
682 beacon_int
= priv
->beacon_int
;
683 spin_unlock_irqrestore(&priv
->lock
, flags
);
685 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
686 if (beacon_int
== 0) {
687 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
688 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
690 priv
->rxon_timing
.beacon_interval
=
691 cpu_to_le16(beacon_int
);
692 priv
->rxon_timing
.beacon_interval
=
693 iwl4965_adjust_beacon_interval(
694 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
697 priv
->rxon_timing
.atim_window
= 0;
699 priv
->rxon_timing
.beacon_interval
=
700 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
701 /* TODO: we need to get atim_window from upper stack
702 * for now we set to 0 */
703 priv
->rxon_timing
.atim_window
= 0;
707 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
708 result
= do_div(tsf
, interval_tm_unit
);
709 priv
->rxon_timing
.beacon_init_val
=
710 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
713 ("beacon interval %d beacon timer %d beacon tim %d\n",
714 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
715 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
716 le16_to_cpu(priv
->rxon_timing
.atim_window
));
719 static void iwl_set_flags_for_band(struct iwl_priv
*priv
,
720 enum ieee80211_band band
)
722 if (band
== IEEE80211_BAND_5GHZ
) {
723 priv
->staging_rxon
.flags
&=
724 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
726 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
728 /* Copied from iwl4965_post_associate() */
729 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
730 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
732 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
734 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
735 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
737 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
738 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
739 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
744 * initialize rxon structure with default values from eeprom
746 static void iwl4965_connection_init_rx_config(struct iwl_priv
*priv
)
748 const struct iwl_channel_info
*ch_info
;
750 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
752 switch (priv
->iw_mode
) {
753 case IEEE80211_IF_TYPE_AP
:
754 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
757 case IEEE80211_IF_TYPE_STA
:
758 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
759 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
762 case IEEE80211_IF_TYPE_IBSS
:
763 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
764 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
765 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
766 RXON_FILTER_ACCEPT_GRP_MSK
;
769 case IEEE80211_IF_TYPE_MNTR
:
770 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
771 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
772 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
775 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
780 /* TODO: Figure out when short_preamble would be set and cache from
782 if (!hw_to_local(priv
->hw
)->short_preamble
)
783 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
785 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
788 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
789 le16_to_cpu(priv
->staging_rxon
.channel
));
792 ch_info
= &priv
->channel_info
[0];
795 * in some case A channels are all non IBSS
796 * in this case force B/G channel
798 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
799 !(is_channel_ibss(ch_info
)))
800 ch_info
= &priv
->channel_info
[0];
802 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
803 priv
->band
= ch_info
->band
;
805 iwl_set_flags_for_band(priv
, priv
->band
);
807 priv
->staging_rxon
.ofdm_basic_rates
=
808 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
809 priv
->staging_rxon
.cck_basic_rates
=
810 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
812 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
813 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
814 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
815 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
816 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
817 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
818 iwl_set_rxon_chain(priv
);
821 static int iwl4965_set_mode(struct iwl_priv
*priv
, int mode
)
823 priv
->iw_mode
= mode
;
825 /* init channel/phymode to values given at driver init */
826 iwl_set_rxon_channel(priv
, IEEE80211_BAND_2GHZ
, 6);
828 iwl4965_connection_init_rx_config(priv
);
829 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
831 iwlcore_clear_stations_table(priv
);
833 /* dont commit rxon if rf-kill is on*/
834 if (!iwl_is_ready_rf(priv
))
837 cancel_delayed_work(&priv
->scan_check
);
838 if (iwl_scan_cancel_timeout(priv
, 100)) {
839 IWL_WARNING("Aborted scan still in progress after 100ms\n");
840 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
844 iwl4965_commit_rxon(priv
);
849 static void iwl4965_set_rate(struct iwl_priv
*priv
)
851 const struct ieee80211_supported_band
*hw
= NULL
;
852 struct ieee80211_rate
*rate
;
855 hw
= iwl_get_hw_mode(priv
, priv
->band
);
857 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
861 priv
->active_rate
= 0;
862 priv
->active_rate_basic
= 0;
864 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
865 rate
= &(hw
->bitrates
[i
]);
866 if (rate
->hw_value
< IWL_RATE_COUNT
)
867 priv
->active_rate
|= (1 << rate
->hw_value
);
870 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
871 priv
->active_rate
, priv
->active_rate_basic
);
874 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
875 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
878 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
879 priv
->staging_rxon
.cck_basic_rates
=
880 ((priv
->active_rate_basic
&
881 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
883 priv
->staging_rxon
.cck_basic_rates
=
884 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
886 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
887 priv
->staging_rxon
.ofdm_basic_rates
=
888 ((priv
->active_rate_basic
&
889 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
890 IWL_FIRST_OFDM_RATE
) & 0xFF;
892 priv
->staging_rxon
.ofdm_basic_rates
=
893 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
896 #define IWL_PACKET_RETRY_TIME HZ
898 int iwl4965_is_duplicate_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
900 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
901 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
902 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
903 u16
*last_seq
, *last_frag
;
904 unsigned long *last_time
;
906 switch (priv
->iw_mode
) {
907 case IEEE80211_IF_TYPE_IBSS
:{
909 struct iwl4965_ibss_seq
*entry
= NULL
;
910 u8
*mac
= header
->addr2
;
911 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
913 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
914 entry
= list_entry(p
, struct iwl4965_ibss_seq
, list
);
915 if (!compare_ether_addr(entry
->mac
, mac
))
918 if (p
== &priv
->ibss_mac_hash
[index
]) {
919 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
921 IWL_ERROR("Cannot malloc new mac entry\n");
924 memcpy(entry
->mac
, mac
, ETH_ALEN
);
925 entry
->seq_num
= seq
;
926 entry
->frag_num
= frag
;
927 entry
->packet_time
= jiffies
;
928 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
931 last_seq
= &entry
->seq_num
;
932 last_frag
= &entry
->frag_num
;
933 last_time
= &entry
->packet_time
;
936 case IEEE80211_IF_TYPE_STA
:
937 last_seq
= &priv
->last_seq_num
;
938 last_frag
= &priv
->last_frag_num
;
939 last_time
= &priv
->last_packet_time
;
944 if ((*last_seq
== seq
) &&
945 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
946 if (*last_frag
== frag
)
948 if (*last_frag
+ 1 != frag
)
949 /* out-of-order fragment */
955 *last_time
= jiffies
;
962 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
964 #include "iwl-spectrum.h"
966 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
967 #define BEACON_TIME_MASK_HIGH 0xFF000000
968 #define TIME_UNIT 1024
971 * extended beacon time format
972 * time in usec will be changed into a 32-bit value in 8:24 format
973 * the high 1 byte is the beacon counts
974 * the lower 3 bytes is the time in usec within one beacon interval
977 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
981 u32 interval
= beacon_interval
* 1024;
983 if (!interval
|| !usec
)
986 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
987 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
989 return (quot
<< 24) + rem
;
992 /* base is usually what we get from ucode with each received frame,
993 * the same as HW timer counter counting down
996 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
998 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
999 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
1000 u32 interval
= beacon_interval
* TIME_UNIT
;
1001 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
1002 (addon
& BEACON_TIME_MASK_HIGH
);
1004 if (base_low
> addon_low
)
1005 res
+= base_low
- addon_low
;
1006 else if (base_low
< addon_low
) {
1007 res
+= interval
+ base_low
- addon_low
;
1012 return cpu_to_le32(res
);
1015 static int iwl4965_get_measurement(struct iwl_priv
*priv
,
1016 struct ieee80211_measurement_params
*params
,
1019 struct iwl4965_spectrum_cmd spectrum
;
1020 struct iwl_rx_packet
*res
;
1021 struct iwl_host_cmd cmd
= {
1022 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
1023 .data
= (void *)&spectrum
,
1024 .meta
.flags
= CMD_WANT_SKB
,
1026 u32 add_time
= le64_to_cpu(params
->start_time
);
1028 int spectrum_resp_status
;
1029 int duration
= le16_to_cpu(params
->duration
);
1031 if (iwl_is_associated(priv
))
1033 iwl4965_usecs_to_beacons(
1034 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
1035 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1037 memset(&spectrum
, 0, sizeof(spectrum
));
1039 spectrum
.channel_count
= cpu_to_le16(1);
1041 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
1042 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
1043 cmd
.len
= sizeof(spectrum
);
1044 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
1046 if (iwl_is_associated(priv
))
1047 spectrum
.start_time
=
1048 iwl4965_add_beacon_time(priv
->last_beacon_time
,
1050 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1052 spectrum
.start_time
= 0;
1054 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
1055 spectrum
.channels
[0].channel
= params
->channel
;
1056 spectrum
.channels
[0].type
= type
;
1057 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
1058 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
1059 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
1061 rc
= iwl_send_cmd_sync(priv
, &cmd
);
1065 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1066 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1067 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
1071 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
1072 switch (spectrum_resp_status
) {
1073 case 0: /* Command will be handled */
1074 if (res
->u
.spectrum
.id
!= 0xff) {
1076 ("Replaced existing measurement: %d\n",
1077 res
->u
.spectrum
.id
);
1078 priv
->measurement_status
&= ~MEASUREMENT_READY
;
1080 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
1084 case 1: /* Command will not be handled */
1089 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1095 /******************************************************************************
1097 * Generic RX handler implementations
1099 ******************************************************************************/
1100 static void iwl_rx_reply_alive(struct iwl_priv
*priv
,
1101 struct iwl_rx_mem_buffer
*rxb
)
1103 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1104 struct iwl_alive_resp
*palive
;
1105 struct delayed_work
*pwork
;
1107 palive
= &pkt
->u
.alive_frame
;
1109 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1111 palive
->is_valid
, palive
->ver_type
,
1112 palive
->ver_subtype
);
1114 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
1115 IWL_DEBUG_INFO("Initialization Alive received.\n");
1116 memcpy(&priv
->card_alive_init
,
1117 &pkt
->u
.alive_frame
,
1118 sizeof(struct iwl_init_alive_resp
));
1119 pwork
= &priv
->init_alive_start
;
1121 IWL_DEBUG_INFO("Runtime Alive received.\n");
1122 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
1123 sizeof(struct iwl_alive_resp
));
1124 pwork
= &priv
->alive_start
;
1127 /* We delay the ALIVE response by 5ms to
1128 * give the HW RF Kill time to activate... */
1129 if (palive
->is_valid
== UCODE_VALID_OK
)
1130 queue_delayed_work(priv
->workqueue
, pwork
,
1131 msecs_to_jiffies(5));
1133 IWL_WARNING("uCode did not respond OK.\n");
1136 static void iwl4965_rx_reply_error(struct iwl_priv
*priv
,
1137 struct iwl_rx_mem_buffer
*rxb
)
1139 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1141 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1142 "seq 0x%04X ser 0x%08X\n",
1143 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
1144 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
1145 pkt
->u
.err_resp
.cmd_id
,
1146 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
1147 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
1150 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1152 static void iwl4965_rx_csa(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
)
1154 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1155 struct iwl_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
1156 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
1157 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1158 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
1159 rxon
->channel
= csa
->channel
;
1160 priv
->staging_rxon
.channel
= csa
->channel
;
1163 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
1164 struct iwl_rx_mem_buffer
*rxb
)
1166 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
1167 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1168 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
1170 if (!report
->state
) {
1171 IWL_DEBUG(IWL_DL_11H
,
1172 "Spectrum Measure Notification: Start\n");
1176 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
1177 priv
->measurement_status
|= MEASUREMENT_READY
;
1181 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv
*priv
,
1182 struct iwl_rx_mem_buffer
*rxb
)
1184 #ifdef CONFIG_IWLWIFI_DEBUG
1185 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1186 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
1187 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1188 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
1192 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
1193 struct iwl_rx_mem_buffer
*rxb
)
1195 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1196 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1197 "notification for %s:\n",
1198 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
1199 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
1202 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
1204 struct iwl_priv
*priv
=
1205 container_of(work
, struct iwl_priv
, beacon_update
);
1206 struct sk_buff
*beacon
;
1208 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
1209 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
);
1212 IWL_ERROR("update beacon failed\n");
1216 mutex_lock(&priv
->mutex
);
1217 /* new beacon skb is allocated every time; dispose previous.*/
1218 if (priv
->ibss_beacon
)
1219 dev_kfree_skb(priv
->ibss_beacon
);
1221 priv
->ibss_beacon
= beacon
;
1222 mutex_unlock(&priv
->mutex
);
1224 iwl4965_send_beacon_cmd(priv
);
1228 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
1230 * This callback is provided in order to send a statistics request.
1232 * This timer function is continually reset to execute within
1233 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1234 * was received. We need to ensure we receive the statistics in order
1235 * to update the temperature used for calibrating the TXPOWER.
1237 static void iwl4965_bg_statistics_periodic(unsigned long data
)
1239 struct iwl_priv
*priv
= (struct iwl_priv
*)data
;
1241 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1244 iwl_send_statistics_request(priv
, CMD_ASYNC
);
1247 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
1248 struct iwl_rx_mem_buffer
*rxb
)
1250 #ifdef CONFIG_IWLWIFI_DEBUG
1251 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1252 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
1253 u8 rate
= iwl_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
1255 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1256 "tsf %d %d rate %d\n",
1257 le32_to_cpu(beacon
->beacon_notify_hdr
.u
.status
) & TX_STATUS_MSK
,
1258 beacon
->beacon_notify_hdr
.failure_frame
,
1259 le32_to_cpu(beacon
->ibss_mgr_status
),
1260 le32_to_cpu(beacon
->high_tsf
),
1261 le32_to_cpu(beacon
->low_tsf
), rate
);
1264 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
1265 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
1266 queue_work(priv
->workqueue
, &priv
->beacon_update
);
1269 /* Handle notification from uCode that card's power state is changing
1270 * due to software, hardware, or critical temperature RFKILL */
1271 static void iwl4965_rx_card_state_notif(struct iwl_priv
*priv
,
1272 struct iwl_rx_mem_buffer
*rxb
)
1274 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1275 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
1276 unsigned long status
= priv
->status
;
1278 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1279 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
1280 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
1282 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
1283 RF_CARD_DISABLED
)) {
1285 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
1286 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
1288 if (!iwl_grab_nic_access(priv
)) {
1290 priv
, HBUS_TARG_MBX_C
,
1291 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
1293 iwl_release_nic_access(priv
);
1296 if (!(flags
& RXON_CARD_DISABLED
)) {
1297 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
1298 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
1299 if (!iwl_grab_nic_access(priv
)) {
1301 priv
, HBUS_TARG_MBX_C
,
1302 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
1304 iwl_release_nic_access(priv
);
1308 if (flags
& RF_CARD_DISABLED
) {
1309 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
1310 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
1311 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
1312 if (!iwl_grab_nic_access(priv
))
1313 iwl_release_nic_access(priv
);
1317 if (flags
& HW_CARD_DISABLED
)
1318 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
1320 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
1323 if (flags
& SW_CARD_DISABLED
)
1324 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
1326 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
1328 if (!(flags
& RXON_CARD_DISABLED
))
1329 iwl_scan_cancel(priv
);
1331 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
1332 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
1333 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
1334 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
1335 queue_work(priv
->workqueue
, &priv
->rf_kill
);
1337 wake_up_interruptible(&priv
->wait_command_queue
);
1340 /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
1341 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
1342 static void iwl4965_rx_reply_rx_phy(struct iwl_priv
*priv
,
1343 struct iwl_rx_mem_buffer
*rxb
)
1345 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1346 priv
->last_phy_res
[0] = 1;
1347 memcpy(&priv
->last_phy_res
[1], &(pkt
->u
.raw
[0]),
1348 sizeof(struct iwl4965_rx_phy_res
));
1352 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
1354 * Setup the RX handlers for each of the reply types sent from the uCode
1357 * This function chains into the hardware specific files for them to setup
1358 * any hardware specific handlers as well.
1360 static void iwl4965_setup_rx_handlers(struct iwl_priv
*priv
)
1362 priv
->rx_handlers
[REPLY_ALIVE
] = iwl_rx_reply_alive
;
1363 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
1364 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
1365 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
1366 iwl4965_rx_spectrum_measure_notif
;
1367 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
1368 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
1369 iwl4965_rx_pm_debug_statistics_notif
;
1370 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
1373 * The same handler is used for both the REPLY to a discrete
1374 * statistics request from the host as well as for the periodic
1375 * statistics notifications (after received beacons) from the uCode.
1377 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl4965_hw_rx_statistics
;
1378 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl4965_hw_rx_statistics
;
1380 iwl_setup_rx_scan_handlers(priv
);
1382 /* status change handler */
1383 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
1385 priv
->rx_handlers
[MISSED_BEACONS_NOTIFICATION
] =
1386 iwl_rx_missed_beacon_notif
;
1388 priv
->rx_handlers
[REPLY_RX_PHY_CMD
] = iwl4965_rx_reply_rx_phy
;
1389 priv
->rx_handlers
[REPLY_RX_MPDU_CMD
] = iwl4965_rx_reply_rx
;
1390 /* Set up hardware specific Rx handlers */
1391 priv
->cfg
->ops
->lib
->rx_handler_setup(priv
);
1395 * this should be called while priv->lock is locked
1397 static void __iwl_rx_replenish(struct iwl_priv
*priv
)
1399 iwl_rx_allocate(priv
);
1400 iwl_rx_queue_restock(priv
);
1405 * iwl_rx_handle - Main entry function for receiving responses from uCode
1407 * Uses the priv->rx_handlers callback function array to invoke
1408 * the appropriate handlers, including command responses,
1409 * frame-received notifications, and other notifications.
1411 void iwl_rx_handle(struct iwl_priv
*priv
)
1413 struct iwl_rx_mem_buffer
*rxb
;
1414 struct iwl_rx_packet
*pkt
;
1415 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
1418 unsigned long flags
;
1422 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1423 * buffer that the driver may process (last buffer filled by ucode). */
1424 r
= priv
->cfg
->ops
->lib
->shared_mem_rx_idx(priv
);
1427 /* Rx interrupt, but nothing sent from uCode */
1429 IWL_DEBUG(IWL_DL_RX
, "r = %d, i = %d\n", r
, i
);
1431 if (iwl_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
1435 rxb
= rxq
->queue
[i
];
1437 /* If an RXB doesn't have a Rx queue slot associated with it,
1438 * then a bug has been introduced in the queue refilling
1439 * routines -- catch it here */
1440 BUG_ON(rxb
== NULL
);
1442 rxq
->queue
[i
] = NULL
;
1444 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
1445 priv
->hw_params
.rx_buf_size
,
1446 PCI_DMA_FROMDEVICE
);
1447 pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
1449 /* Reclaim a command buffer only if this packet is a response
1450 * to a (driver-originated) command.
1451 * If the packet (e.g. Rx frame) originated from uCode,
1452 * there is no command buffer to reclaim.
1453 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1454 * but apparently a few don't get set; catch them here. */
1455 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
1456 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
1457 (pkt
->hdr
.cmd
!= REPLY_RX
) &&
1458 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
1459 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
1460 (pkt
->hdr
.cmd
!= REPLY_TX
);
1462 /* Based on type of command response or notification,
1463 * handle those that need handling via function in
1464 * rx_handlers table. See iwl4965_setup_rx_handlers() */
1465 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
1466 IWL_DEBUG(IWL_DL_RX
, "r = %d, i = %d, %s, 0x%02x\n", r
,
1467 i
, get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
1468 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
1470 /* No handling needed */
1471 IWL_DEBUG(IWL_DL_RX
,
1472 "r %d i %d No handler needed for %s, 0x%02x\n",
1473 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
1478 /* Invoke any callbacks, transfer the skb to caller, and
1479 * fire off the (possibly) blocking iwl_send_cmd()
1480 * as we reclaim the driver command queue */
1481 if (rxb
&& rxb
->skb
)
1482 iwl_tx_cmd_complete(priv
, rxb
);
1484 IWL_WARNING("Claim null rxb?\n");
1487 /* For now we just don't re-use anything. We can tweak this
1488 * later to try and re-use notification packets and SKBs that
1489 * fail to Rx correctly */
1490 if (rxb
->skb
!= NULL
) {
1491 priv
->alloc_rxb_skb
--;
1492 dev_kfree_skb_any(rxb
->skb
);
1496 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
1497 priv
->hw_params
.rx_buf_size
,
1498 PCI_DMA_FROMDEVICE
);
1499 spin_lock_irqsave(&rxq
->lock
, flags
);
1500 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
1501 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1502 i
= (i
+ 1) & RX_QUEUE_MASK
;
1503 /* If there are a lot of unused frames,
1504 * restock the Rx queue so ucode wont assert. */
1509 __iwl_rx_replenish(priv
);
1515 /* Backtrack one entry */
1517 iwl_rx_queue_restock(priv
);
1520 #define PERFECT_RSSI (-20) /* dBm */
1521 #define WORST_RSSI (-95) /* dBm */
1522 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1524 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
1525 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1526 * about formulas used below. */
1527 int iwl4965_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
1530 int degradation
= PERFECT_RSSI
- rssi_dbm
;
1532 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1533 * as indicator; formula is (signal dbm - noise dbm).
1534 * SNR at or above 40 is a great signal (100%).
1535 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1536 * Weakest usable signal is usually 10 - 15 dB SNR. */
1538 if (rssi_dbm
- noise_dbm
>= 40)
1540 else if (rssi_dbm
< noise_dbm
)
1542 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
1544 /* Else use just the signal level.
1545 * This formula is a least squares fit of data points collected and
1546 * compared with a reference system that had a percentage (%) display
1547 * for signal quality. */
1549 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
1550 (15 * RSSI_RANGE
+ 62 * degradation
)) /
1551 (RSSI_RANGE
* RSSI_RANGE
);
1555 else if (sig_qual
< 1)
1561 #ifdef CONFIG_IWLWIFI_DEBUG
1562 static void iwl4965_print_rx_config_cmd(struct iwl_priv
*priv
)
1564 struct iwl_rxon_cmd
*rxon
= &priv
->staging_rxon
;
1565 DECLARE_MAC_BUF(mac
);
1567 IWL_DEBUG_RADIO("RX CONFIG:\n");
1568 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
1569 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
1570 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
1571 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1572 le32_to_cpu(rxon
->filter_flags
));
1573 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
1574 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1575 rxon
->ofdm_basic_rates
);
1576 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
1577 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
1578 print_mac(mac
, rxon
->node_addr
));
1579 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
1580 print_mac(mac
, rxon
->bssid_addr
));
1581 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
1585 static void iwl4965_enable_interrupts(struct iwl_priv
*priv
)
1587 IWL_DEBUG_ISR("Enabling interrupts\n");
1588 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
1589 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
1592 /* call this function to flush any scheduled tasklet */
1593 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
1595 /* wait to make sure we flush pedding tasklet*/
1596 synchronize_irq(priv
->pci_dev
->irq
);
1597 tasklet_kill(&priv
->irq_tasklet
);
1600 static inline void iwl4965_disable_interrupts(struct iwl_priv
*priv
)
1602 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
1604 /* disable interrupts from uCode/NIC to host */
1605 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
1607 /* acknowledge/clear/reset any interrupts still pending
1608 * from uCode or flow handler (Rx/Tx DMA) */
1609 iwl_write32(priv
, CSR_INT
, 0xffffffff);
1610 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
1611 IWL_DEBUG_ISR("Disabled interrupts\n");
1616 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
1618 static void iwl4965_irq_handle_error(struct iwl_priv
*priv
)
1620 /* Set the FW error flag -- cleared on iwl4965_down */
1621 set_bit(STATUS_FW_ERROR
, &priv
->status
);
1623 /* Cancel currently queued command. */
1624 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
1626 #ifdef CONFIG_IWLWIFI_DEBUG
1627 if (priv
->debug_level
& IWL_DL_FW_ERRORS
) {
1628 iwl_dump_nic_error_log(priv
);
1629 iwl_dump_nic_event_log(priv
);
1630 iwl4965_print_rx_config_cmd(priv
);
1634 wake_up_interruptible(&priv
->wait_command_queue
);
1636 /* Keep the restart process from trying to send host
1637 * commands by clearing the INIT status bit */
1638 clear_bit(STATUS_READY
, &priv
->status
);
1640 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
1641 IWL_DEBUG(IWL_DL_FW_ERRORS
,
1642 "Restarting adapter due to uCode error.\n");
1644 if (iwl_is_associated(priv
)) {
1645 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
1646 sizeof(priv
->recovery_rxon
));
1647 priv
->error_recovering
= 1;
1649 if (priv
->cfg
->mod_params
->restart_fw
)
1650 queue_work(priv
->workqueue
, &priv
->restart
);
1654 static void iwl4965_error_recovery(struct iwl_priv
*priv
)
1656 unsigned long flags
;
1658 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
1659 sizeof(priv
->staging_rxon
));
1660 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1661 iwl4965_commit_rxon(priv
);
1663 iwl_rxon_add_station(priv
, priv
->bssid
, 1);
1665 spin_lock_irqsave(&priv
->lock
, flags
);
1666 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
1667 priv
->error_recovering
= 0;
1668 spin_unlock_irqrestore(&priv
->lock
, flags
);
1671 static void iwl4965_irq_tasklet(struct iwl_priv
*priv
)
1673 u32 inta
, handled
= 0;
1675 unsigned long flags
;
1676 #ifdef CONFIG_IWLWIFI_DEBUG
1680 spin_lock_irqsave(&priv
->lock
, flags
);
1682 /* Ack/clear/reset pending uCode interrupts.
1683 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1684 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
1685 inta
= iwl_read32(priv
, CSR_INT
);
1686 iwl_write32(priv
, CSR_INT
, inta
);
1688 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1689 * Any new interrupts that happen after this, either while we're
1690 * in this tasklet, or later, will show up in next ISR/tasklet. */
1691 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1692 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
1694 #ifdef CONFIG_IWLWIFI_DEBUG
1695 if (priv
->debug_level
& IWL_DL_ISR
) {
1696 /* just for debug */
1697 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
1698 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1699 inta
, inta_mask
, inta_fh
);
1703 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1704 * atomic, make sure that inta covers all the interrupts that
1705 * we've discovered, even if FH interrupt came in just after
1706 * reading CSR_INT. */
1707 if (inta_fh
& CSR49_FH_INT_RX_MASK
)
1708 inta
|= CSR_INT_BIT_FH_RX
;
1709 if (inta_fh
& CSR49_FH_INT_TX_MASK
)
1710 inta
|= CSR_INT_BIT_FH_TX
;
1712 /* Now service all interrupt bits discovered above. */
1713 if (inta
& CSR_INT_BIT_HW_ERR
) {
1714 IWL_ERROR("Microcode HW error detected. Restarting.\n");
1716 /* Tell the device to stop sending interrupts */
1717 iwl4965_disable_interrupts(priv
);
1719 iwl4965_irq_handle_error(priv
);
1721 handled
|= CSR_INT_BIT_HW_ERR
;
1723 spin_unlock_irqrestore(&priv
->lock
, flags
);
1728 #ifdef CONFIG_IWLWIFI_DEBUG
1729 if (priv
->debug_level
& (IWL_DL_ISR
)) {
1730 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1731 if (inta
& CSR_INT_BIT_SCD
)
1732 IWL_DEBUG_ISR("Scheduler finished to transmit "
1733 "the frame/frames.\n");
1735 /* Alive notification via Rx interrupt will do the real work */
1736 if (inta
& CSR_INT_BIT_ALIVE
)
1737 IWL_DEBUG_ISR("Alive interrupt\n");
1740 /* Safely ignore these bits for debug checks below */
1741 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
1743 /* HW RF KILL switch toggled */
1744 if (inta
& CSR_INT_BIT_RF_KILL
) {
1746 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
1747 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
1750 IWL_DEBUG(IWL_DL_RF_KILL
, "RF_KILL bit toggled to %s.\n",
1751 hw_rf_kill
? "disable radio":"enable radio");
1753 /* Queue restart only if RF_KILL switch was set to "kill"
1754 * when we loaded driver, and is now set to "enable".
1755 * After we're Alive, RF_KILL gets handled by
1756 * iwl4965_rx_card_state_notif() */
1757 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
1758 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
1759 queue_work(priv
->workqueue
, &priv
->restart
);
1762 handled
|= CSR_INT_BIT_RF_KILL
;
1765 /* Chip got too hot and stopped itself */
1766 if (inta
& CSR_INT_BIT_CT_KILL
) {
1767 IWL_ERROR("Microcode CT kill error detected.\n");
1768 handled
|= CSR_INT_BIT_CT_KILL
;
1771 /* Error detected by uCode */
1772 if (inta
& CSR_INT_BIT_SW_ERR
) {
1773 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
1775 iwl4965_irq_handle_error(priv
);
1776 handled
|= CSR_INT_BIT_SW_ERR
;
1779 /* uCode wakes up after power-down sleep */
1780 if (inta
& CSR_INT_BIT_WAKEUP
) {
1781 IWL_DEBUG_ISR("Wakeup interrupt\n");
1782 iwl_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
1783 iwl_txq_update_write_ptr(priv
, &priv
->txq
[0]);
1784 iwl_txq_update_write_ptr(priv
, &priv
->txq
[1]);
1785 iwl_txq_update_write_ptr(priv
, &priv
->txq
[2]);
1786 iwl_txq_update_write_ptr(priv
, &priv
->txq
[3]);
1787 iwl_txq_update_write_ptr(priv
, &priv
->txq
[4]);
1788 iwl_txq_update_write_ptr(priv
, &priv
->txq
[5]);
1790 handled
|= CSR_INT_BIT_WAKEUP
;
1793 /* All uCode command responses, including Tx command responses,
1794 * Rx "responses" (frame-received notification), and other
1795 * notifications from uCode come through here*/
1796 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
1797 iwl_rx_handle(priv
);
1798 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
1801 if (inta
& CSR_INT_BIT_FH_TX
) {
1802 IWL_DEBUG_ISR("Tx interrupt\n");
1803 handled
|= CSR_INT_BIT_FH_TX
;
1804 /* FH finished to write, send event */
1805 priv
->ucode_write_complete
= 1;
1806 wake_up_interruptible(&priv
->wait_command_queue
);
1809 if (inta
& ~handled
)
1810 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
1812 if (inta
& ~CSR_INI_SET_MASK
) {
1813 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
1814 inta
& ~CSR_INI_SET_MASK
);
1815 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
1818 /* Re-enable all interrupts */
1819 /* only Re-enable if diabled by irq */
1820 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
1821 iwl4965_enable_interrupts(priv
);
1823 #ifdef CONFIG_IWLWIFI_DEBUG
1824 if (priv
->debug_level
& (IWL_DL_ISR
)) {
1825 inta
= iwl_read32(priv
, CSR_INT
);
1826 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
1827 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1828 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1829 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
1832 spin_unlock_irqrestore(&priv
->lock
, flags
);
1835 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
1837 struct iwl_priv
*priv
= data
;
1838 u32 inta
, inta_mask
;
1843 spin_lock(&priv
->lock
);
1845 /* Disable (but don't clear!) interrupts here to avoid
1846 * back-to-back ISRs and sporadic interrupts from our NIC.
1847 * If we have something to service, the tasklet will re-enable ints.
1848 * If we *don't* have something, we'll re-enable before leaving here. */
1849 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
1850 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
1852 /* Discover which interrupts are active/pending */
1853 inta
= iwl_read32(priv
, CSR_INT
);
1854 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1856 /* Ignore interrupt if there's nothing in NIC to service.
1857 * This may be due to IRQ shared with another device,
1858 * or due to sporadic interrupts thrown from our NIC. */
1859 if (!inta
&& !inta_fh
) {
1860 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1864 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
1865 /* Hardware disappeared. It might have already raised
1867 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
1871 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1872 inta
, inta_mask
, inta_fh
);
1874 inta
&= ~CSR_INT_BIT_SCD
;
1876 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
1877 if (likely(inta
|| inta_fh
))
1878 tasklet_schedule(&priv
->irq_tasklet
);
1881 spin_unlock(&priv
->lock
);
1885 /* re-enable interrupts here since we don't have anything to service. */
1886 /* only Re-enable if diabled by irq */
1887 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
1888 iwl4965_enable_interrupts(priv
);
1889 spin_unlock(&priv
->lock
);
1893 /******************************************************************************
1895 * uCode download functions
1897 ******************************************************************************/
1899 static void iwl4965_dealloc_ucode_pci(struct iwl_priv
*priv
)
1901 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
1902 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
1903 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
1904 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
1905 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
1906 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
1909 static void iwl4965_nic_start(struct iwl_priv
*priv
)
1911 /* Remove all resets to allow NIC to operate */
1912 iwl_write32(priv
, CSR_RESET
, 0);
1917 * iwl4965_read_ucode - Read uCode images from disk file.
1919 * Copy into buffers for card to fetch via bus-mastering
1921 static int iwl4965_read_ucode(struct iwl_priv
*priv
)
1923 struct iwl_ucode
*ucode
;
1925 const struct firmware
*ucode_raw
;
1926 const char *name
= priv
->cfg
->fw_name
;
1929 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
1931 /* Ask kernel firmware_class module to get the boot firmware off disk.
1932 * request_firmware() is synchronous, file is in memory on return. */
1933 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
1935 IWL_ERROR("%s firmware file req failed: Reason %d\n",
1940 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1941 name
, ucode_raw
->size
);
1943 /* Make sure that we got at least our header! */
1944 if (ucode_raw
->size
< sizeof(*ucode
)) {
1945 IWL_ERROR("File size way too small!\n");
1950 /* Data from ucode file: header followed by uCode images */
1951 ucode
= (void *)ucode_raw
->data
;
1953 ver
= le32_to_cpu(ucode
->ver
);
1954 inst_size
= le32_to_cpu(ucode
->inst_size
);
1955 data_size
= le32_to_cpu(ucode
->data_size
);
1956 init_size
= le32_to_cpu(ucode
->init_size
);
1957 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
1958 boot_size
= le32_to_cpu(ucode
->boot_size
);
1960 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
1961 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1963 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1965 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1967 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1969 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1972 /* Verify size of file vs. image size info in file's header */
1973 if (ucode_raw
->size
< sizeof(*ucode
) +
1974 inst_size
+ data_size
+ init_size
+
1975 init_data_size
+ boot_size
) {
1977 IWL_DEBUG_INFO("uCode file size %d too small\n",
1978 (int)ucode_raw
->size
);
1983 /* Verify that uCode images will fit in card's SRAM */
1984 if (inst_size
> priv
->hw_params
.max_inst_size
) {
1985 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1991 if (data_size
> priv
->hw_params
.max_data_size
) {
1992 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1997 if (init_size
> priv
->hw_params
.max_inst_size
) {
1999 ("uCode init instr len %d too large to fit in\n",
2004 if (init_data_size
> priv
->hw_params
.max_data_size
) {
2006 ("uCode init data len %d too large to fit in\n",
2011 if (boot_size
> priv
->hw_params
.max_bsm_size
) {
2013 ("uCode boot instr len %d too large to fit in\n",
2019 /* Allocate ucode buffers for card's bus-master loading ... */
2021 /* Runtime instructions and 2 copies of data:
2022 * 1) unmodified from disk
2023 * 2) backup cache for save/restore during power-downs */
2024 priv
->ucode_code
.len
= inst_size
;
2025 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
2027 priv
->ucode_data
.len
= data_size
;
2028 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
2030 priv
->ucode_data_backup
.len
= data_size
;
2031 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
2033 /* Initialization instructions and data */
2034 if (init_size
&& init_data_size
) {
2035 priv
->ucode_init
.len
= init_size
;
2036 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
2038 priv
->ucode_init_data
.len
= init_data_size
;
2039 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
2041 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
2045 /* Bootstrap (instructions only, no data) */
2047 priv
->ucode_boot
.len
= boot_size
;
2048 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
2050 if (!priv
->ucode_boot
.v_addr
)
2054 /* Copy images into buffers for card's bus-master reads ... */
2056 /* Runtime instructions (first block of data in file) */
2057 src
= &ucode
->data
[0];
2058 len
= priv
->ucode_code
.len
;
2059 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
2060 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
2061 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
2062 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
2064 /* Runtime data (2nd block)
2065 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
2066 src
= &ucode
->data
[inst_size
];
2067 len
= priv
->ucode_data
.len
;
2068 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
2069 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
2070 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
2072 /* Initialization instructions (3rd block) */
2074 src
= &ucode
->data
[inst_size
+ data_size
];
2075 len
= priv
->ucode_init
.len
;
2076 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
2078 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
2081 /* Initialization data (4th block) */
2082 if (init_data_size
) {
2083 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
2084 len
= priv
->ucode_init_data
.len
;
2085 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
2087 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
2090 /* Bootstrap instructions (5th block) */
2091 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
2092 len
= priv
->ucode_boot
.len
;
2093 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
2094 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
2096 /* We have our copies now, allow OS release its copies */
2097 release_firmware(ucode_raw
);
2101 IWL_ERROR("failed to allocate pci memory\n");
2103 iwl4965_dealloc_ucode_pci(priv
);
2106 release_firmware(ucode_raw
);
2113 * iwl_alive_start - called after REPLY_ALIVE notification received
2114 * from protocol/runtime uCode (initialization uCode's
2115 * Alive gets handled by iwl_init_alive_start()).
2117 static void iwl_alive_start(struct iwl_priv
*priv
)
2121 IWL_DEBUG_INFO("Runtime Alive received.\n");
2123 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
2124 /* We had an error bringing up the hardware, so take it
2125 * all the way back down so we can try again */
2126 IWL_DEBUG_INFO("Alive failed.\n");
2130 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2131 * This is a paranoid check, because we would not have gotten the
2132 * "runtime" alive if code weren't properly loaded. */
2133 if (iwl_verify_ucode(priv
)) {
2134 /* Runtime instruction load was bad;
2135 * take it all the way back down so we can try again */
2136 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
2140 iwlcore_clear_stations_table(priv
);
2141 ret
= priv
->cfg
->ops
->lib
->alive_notify(priv
);
2143 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
2148 /* After the ALIVE response, we can send host commands to 4965 uCode */
2149 set_bit(STATUS_ALIVE
, &priv
->status
);
2151 if (iwl_is_rfkill(priv
))
2154 ieee80211_wake_queues(priv
->hw
);
2156 priv
->active_rate
= priv
->rates_mask
;
2157 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
2159 if (iwl_is_associated(priv
)) {
2160 struct iwl_rxon_cmd
*active_rxon
=
2161 (struct iwl_rxon_cmd
*)&priv
->active_rxon
;
2163 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
2164 sizeof(priv
->staging_rxon
));
2165 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2167 /* Initialize our rx_config data */
2168 iwl4965_connection_init_rx_config(priv
);
2169 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2172 /* Configure Bluetooth device coexistence support */
2173 iwl4965_send_bt_config(priv
);
2175 iwl_reset_run_time_calib(priv
);
2177 /* Configure the adapter for unassociated operation */
2178 iwl4965_commit_rxon(priv
);
2180 /* At this point, the NIC is initialized and operational */
2181 iwl_rf_kill_ct_config(priv
);
2183 iwl_leds_register(priv
);
2185 IWL_DEBUG_INFO("ALIVE processing complete.\n");
2186 set_bit(STATUS_READY
, &priv
->status
);
2187 wake_up_interruptible(&priv
->wait_command_queue
);
2189 if (priv
->error_recovering
)
2190 iwl4965_error_recovery(priv
);
2192 iwl_power_update_mode(priv
, 1);
2193 ieee80211_notify_mac(priv
->hw
, IEEE80211_NOTIFY_RE_ASSOC
);
2195 if (test_and_clear_bit(STATUS_MODE_PENDING
, &priv
->status
))
2196 iwl4965_set_mode(priv
, priv
->iw_mode
);
2201 queue_work(priv
->workqueue
, &priv
->restart
);
2204 static void iwl_cancel_deferred_work(struct iwl_priv
*priv
);
2206 static void __iwl4965_down(struct iwl_priv
*priv
)
2208 unsigned long flags
;
2209 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2211 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
2214 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2216 iwl_leds_unregister(priv
);
2218 iwlcore_clear_stations_table(priv
);
2220 /* Unblock any waiting calls */
2221 wake_up_interruptible_all(&priv
->wait_command_queue
);
2223 /* Wipe out the EXIT_PENDING status bit if we are not actually
2224 * exiting the module */
2226 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2228 /* stop and reset the on-board processor */
2229 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
2231 /* tell the device to stop sending interrupts */
2232 spin_lock_irqsave(&priv
->lock
, flags
);
2233 iwl4965_disable_interrupts(priv
);
2234 spin_unlock_irqrestore(&priv
->lock
, flags
);
2235 iwl_synchronize_irq(priv
);
2237 if (priv
->mac80211_registered
)
2238 ieee80211_stop_queues(priv
->hw
);
2240 /* If we have not previously called iwl4965_init() then
2241 * clear all bits but the RF Kill and SUSPEND bits and return */
2242 if (!iwl_is_init(priv
)) {
2243 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2245 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
2247 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2248 STATUS_GEO_CONFIGURED
|
2249 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
2254 /* ...otherwise clear out all the status bits but the RF Kill and
2255 * SUSPEND bits and continue taking the NIC down. */
2256 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2258 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
2260 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2261 STATUS_GEO_CONFIGURED
|
2262 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
2264 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
2267 spin_lock_irqsave(&priv
->lock
, flags
);
2268 iwl_clear_bit(priv
, CSR_GP_CNTRL
,
2269 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
2270 spin_unlock_irqrestore(&priv
->lock
, flags
);
2272 iwl_txq_ctx_stop(priv
);
2275 spin_lock_irqsave(&priv
->lock
, flags
);
2276 if (!iwl_grab_nic_access(priv
)) {
2277 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
2278 APMG_CLK_VAL_DMA_CLK_RQT
);
2279 iwl_release_nic_access(priv
);
2281 spin_unlock_irqrestore(&priv
->lock
, flags
);
2285 /* FIXME: apm_ops.suspend(priv) */
2286 priv
->cfg
->ops
->lib
->apm_ops
.reset(priv
);
2287 priv
->cfg
->ops
->lib
->free_shared_mem(priv
);
2290 memset(&priv
->card_alive
, 0, sizeof(struct iwl_alive_resp
));
2292 if (priv
->ibss_beacon
)
2293 dev_kfree_skb(priv
->ibss_beacon
);
2294 priv
->ibss_beacon
= NULL
;
2296 /* clear out any free frames */
2297 iwl_clear_free_frames(priv
);
2300 static void iwl4965_down(struct iwl_priv
*priv
)
2302 mutex_lock(&priv
->mutex
);
2303 __iwl4965_down(priv
);
2304 mutex_unlock(&priv
->mutex
);
2306 iwl_cancel_deferred_work(priv
);
2309 #define MAX_HW_RESTARTS 5
2311 static int __iwl4965_up(struct iwl_priv
*priv
)
2316 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
2317 IWL_WARNING("Exit pending; will not bring the NIC up\n");
2321 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
2322 IWL_ERROR("ucode not available for device bringup\n");
2326 /* If platform's RF_KILL switch is NOT set to KILL */
2327 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
2328 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
2329 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2331 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2332 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
2333 iwl_rfkill_set_hw_state(priv
);
2334 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
2339 iwl_rfkill_set_hw_state(priv
);
2340 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
2342 ret
= priv
->cfg
->ops
->lib
->alloc_shared_mem(priv
);
2344 IWL_ERROR("Unable to allocate shared memory\n");
2348 ret
= iwl_hw_nic_init(priv
);
2350 IWL_ERROR("Unable to init nic\n");
2354 /* make sure rfkill handshake bits are cleared */
2355 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2356 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
2357 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
2359 /* clear (again), then enable host interrupts */
2360 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
2361 iwl4965_enable_interrupts(priv
);
2363 /* really make sure rfkill handshake bits are cleared */
2364 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2365 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2367 /* Copy original ucode data image from disk into backup cache.
2368 * This will be used to initialize the on-board processor's
2369 * data SRAM for a clean start when the runtime program first loads. */
2370 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
2371 priv
->ucode_data
.len
);
2373 /* We return success when we resume from suspend and rf_kill is on. */
2374 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ||
2375 test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2378 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
2380 iwlcore_clear_stations_table(priv
);
2382 /* load bootstrap state machine,
2383 * load bootstrap program into processor's memory,
2384 * prepare to load the "initialize" uCode */
2385 ret
= priv
->cfg
->ops
->lib
->load_ucode(priv
);
2388 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret
);
2392 /* Clear out the uCode error bit if it is set */
2393 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
2395 /* start card; "initialize" will load runtime ucode */
2396 iwl4965_nic_start(priv
);
2398 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
2403 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2404 __iwl4965_down(priv
);
2405 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2407 /* tried to restart and config the device for as long as our
2408 * patience could withstand */
2409 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
2414 /*****************************************************************************
2416 * Workqueue callbacks
2418 *****************************************************************************/
2420 static void iwl_bg_init_alive_start(struct work_struct
*data
)
2422 struct iwl_priv
*priv
=
2423 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
2425 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2428 mutex_lock(&priv
->mutex
);
2429 priv
->cfg
->ops
->lib
->init_alive_start(priv
);
2430 mutex_unlock(&priv
->mutex
);
2433 static void iwl_bg_alive_start(struct work_struct
*data
)
2435 struct iwl_priv
*priv
=
2436 container_of(data
, struct iwl_priv
, alive_start
.work
);
2438 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2441 mutex_lock(&priv
->mutex
);
2442 iwl_alive_start(priv
);
2443 mutex_unlock(&priv
->mutex
);
2446 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
2448 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
2450 wake_up_interruptible(&priv
->wait_command_queue
);
2452 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2455 mutex_lock(&priv
->mutex
);
2457 if (!iwl_is_rfkill(priv
)) {
2458 IWL_DEBUG(IWL_DL_RF_KILL
,
2459 "HW and/or SW RF Kill no longer active, restarting "
2461 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2462 queue_work(priv
->workqueue
, &priv
->restart
);
2464 /* make sure mac80211 stop sending Tx frame */
2465 if (priv
->mac80211_registered
)
2466 ieee80211_stop_queues(priv
->hw
);
2468 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
2469 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2470 "disabled by SW switch\n");
2472 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
2473 "Kill switch must be turned off for "
2474 "wireless networking to work.\n");
2476 iwl_rfkill_set_hw_state(priv
);
2478 mutex_unlock(&priv
->mutex
);
2481 static void iwl4965_bg_set_monitor(struct work_struct
*work
)
2483 struct iwl_priv
*priv
= container_of(work
,
2484 struct iwl_priv
, set_monitor
);
2487 IWL_DEBUG(IWL_DL_STATE
, "setting monitor mode\n");
2489 mutex_lock(&priv
->mutex
);
2491 ret
= iwl4965_set_mode(priv
, IEEE80211_IF_TYPE_MNTR
);
2495 IWL_DEBUG(IWL_DL_STATE
, "leave - not ready\n");
2497 IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret
);
2500 mutex_unlock(&priv
->mutex
);
2503 static void iwl_bg_run_time_calib_work(struct work_struct
*work
)
2505 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
,
2506 run_time_calib_work
);
2508 mutex_lock(&priv
->mutex
);
2510 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
) ||
2511 test_bit(STATUS_SCANNING
, &priv
->status
)) {
2512 mutex_unlock(&priv
->mutex
);
2516 if (priv
->start_calib
) {
2517 iwl_chain_noise_calibration(priv
, &priv
->statistics
);
2519 iwl_sensitivity_calibration(priv
, &priv
->statistics
);
2522 mutex_unlock(&priv
->mutex
);
2526 static void iwl4965_bg_up(struct work_struct
*data
)
2528 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
2530 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2533 mutex_lock(&priv
->mutex
);
2535 mutex_unlock(&priv
->mutex
);
2538 static void iwl4965_bg_restart(struct work_struct
*data
)
2540 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
2542 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2546 queue_work(priv
->workqueue
, &priv
->up
);
2549 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
2551 struct iwl_priv
*priv
=
2552 container_of(data
, struct iwl_priv
, rx_replenish
);
2554 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2557 mutex_lock(&priv
->mutex
);
2558 iwl_rx_replenish(priv
);
2559 mutex_unlock(&priv
->mutex
);
2562 #define IWL_DELAY_NEXT_SCAN (HZ*2)
2564 static void iwl4965_post_associate(struct iwl_priv
*priv
)
2566 struct ieee80211_conf
*conf
= NULL
;
2568 DECLARE_MAC_BUF(mac
);
2570 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
2571 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
2575 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
2577 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
2580 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2584 if (!priv
->vif
|| !priv
->is_open
)
2587 iwl_scan_cancel_timeout(priv
, 200);
2589 conf
= ieee80211_get_hw_conf(priv
->hw
);
2591 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2592 iwl4965_commit_rxon(priv
);
2594 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
2595 iwl4965_setup_rxon_timing(priv
);
2596 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
2597 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
2599 IWL_WARNING("REPLY_RXON_TIMING failed - "
2600 "Attempting to continue.\n");
2602 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
2604 if (priv
->current_ht_config
.is_ht
)
2605 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
2607 iwl_set_rxon_chain(priv
);
2608 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
2610 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2611 priv
->assoc_id
, priv
->beacon_int
);
2613 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
2614 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2616 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2618 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
2619 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
2620 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2622 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2624 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2625 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2629 iwl4965_commit_rxon(priv
);
2631 switch (priv
->iw_mode
) {
2632 case IEEE80211_IF_TYPE_STA
:
2633 iwl4965_rate_scale_init(priv
->hw
, IWL_AP_ID
);
2636 case IEEE80211_IF_TYPE_IBSS
:
2638 /* assume default assoc id */
2641 iwl_rxon_add_station(priv
, priv
->bssid
, 0);
2642 iwl4965_rate_scale_init(priv
->hw
, IWL_STA_ID
);
2643 iwl4965_send_beacon_cmd(priv
);
2648 IWL_ERROR("%s Should not be called in %d mode\n",
2649 __FUNCTION__
, priv
->iw_mode
);
2653 iwl4965_sequence_reset(priv
);
2655 /* Enable Rx differential gain and sensitivity calibrations */
2656 iwl_chain_noise_reset(priv
);
2657 priv
->start_calib
= 1;
2659 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2660 priv
->assoc_station_added
= 1;
2662 iwl4965_activate_qos(priv
, 0);
2664 iwl_power_update_mode(priv
, 0);
2665 /* we have just associated, don't start scan too early */
2666 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
2670 static void iwl4965_bg_post_associate(struct work_struct
*data
)
2672 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
,
2673 post_associate
.work
);
2675 mutex_lock(&priv
->mutex
);
2676 iwl4965_post_associate(priv
);
2677 mutex_unlock(&priv
->mutex
);
2681 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
2683 static void iwl_bg_scan_completed(struct work_struct
*work
)
2685 struct iwl_priv
*priv
=
2686 container_of(work
, struct iwl_priv
, scan_completed
);
2688 IWL_DEBUG_SCAN("SCAN complete scan\n");
2690 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2693 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
2694 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
2696 ieee80211_scan_completed(priv
->hw
);
2698 /* Since setting the TXPOWER may have been deferred while
2699 * performing the scan, fire one off */
2700 mutex_lock(&priv
->mutex
);
2701 iwl_set_tx_power(priv
, priv
->tx_power_user_lmt
, true);
2702 mutex_unlock(&priv
->mutex
);
2705 /*****************************************************************************
2707 * mac80211 entry point functions
2709 *****************************************************************************/
2711 #define UCODE_READY_TIMEOUT (2 * HZ)
2713 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
2715 struct iwl_priv
*priv
= hw
->priv
;
2718 IWL_DEBUG_MAC80211("enter\n");
2720 if (pci_enable_device(priv
->pci_dev
)) {
2721 IWL_ERROR("Fail to pci_enable_device\n");
2724 pci_restore_state(priv
->pci_dev
);
2725 pci_enable_msi(priv
->pci_dev
);
2727 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
2730 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
2731 goto out_disable_msi
;
2734 /* we should be verifying the device is ready to be opened */
2735 mutex_lock(&priv
->mutex
);
2737 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl_rxon_cmd
));
2738 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2739 * ucode filename and max sizes are card-specific. */
2741 if (!priv
->ucode_code
.len
) {
2742 ret
= iwl4965_read_ucode(priv
);
2744 IWL_ERROR("Could not read microcode: %d\n", ret
);
2745 mutex_unlock(&priv
->mutex
);
2746 goto out_release_irq
;
2750 ret
= __iwl4965_up(priv
);
2752 mutex_unlock(&priv
->mutex
);
2755 goto out_release_irq
;
2757 IWL_DEBUG_INFO("Start UP work done.\n");
2759 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
2762 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
2763 * mac80211 will not be run successfully. */
2764 if (priv
->ucode_type
== UCODE_RT
) {
2765 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
2766 test_bit(STATUS_READY
, &priv
->status
),
2767 UCODE_READY_TIMEOUT
);
2769 if (!test_bit(STATUS_READY
, &priv
->status
)) {
2770 IWL_ERROR("START_ALIVE timeout after %dms.\n",
2771 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
2773 goto out_release_irq
;
2779 IWL_DEBUG_MAC80211("leave\n");
2783 free_irq(priv
->pci_dev
->irq
, priv
);
2785 pci_disable_msi(priv
->pci_dev
);
2786 pci_disable_device(priv
->pci_dev
);
2788 IWL_DEBUG_MAC80211("leave - failed\n");
2792 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
2794 struct iwl_priv
*priv
= hw
->priv
;
2796 IWL_DEBUG_MAC80211("enter\n");
2798 if (!priv
->is_open
) {
2799 IWL_DEBUG_MAC80211("leave - skip\n");
2805 if (iwl_is_ready_rf(priv
)) {
2806 /* stop mac, cancel any scan request and clear
2807 * RXON_FILTER_ASSOC_MSK BIT
2809 mutex_lock(&priv
->mutex
);
2810 iwl_scan_cancel_timeout(priv
, 100);
2811 cancel_delayed_work(&priv
->post_associate
);
2812 mutex_unlock(&priv
->mutex
);
2817 flush_workqueue(priv
->workqueue
);
2818 free_irq(priv
->pci_dev
->irq
, priv
);
2819 pci_disable_msi(priv
->pci_dev
);
2820 pci_save_state(priv
->pci_dev
);
2821 pci_disable_device(priv
->pci_dev
);
2823 IWL_DEBUG_MAC80211("leave\n");
2826 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2828 struct iwl_priv
*priv
= hw
->priv
;
2830 IWL_DEBUG_MAC80211("enter\n");
2832 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
2833 IWL_DEBUG_MAC80211("leave - monitor\n");
2837 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
2838 ieee80211_get_tx_rate(hw
, IEEE80211_SKB_CB(skb
))->bitrate
);
2840 if (iwl_tx_skb(priv
, skb
))
2841 dev_kfree_skb_any(skb
);
2843 IWL_DEBUG_MAC80211("leave\n");
2847 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
2848 struct ieee80211_if_init_conf
*conf
)
2850 struct iwl_priv
*priv
= hw
->priv
;
2851 unsigned long flags
;
2852 DECLARE_MAC_BUF(mac
);
2854 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
2857 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
2861 spin_lock_irqsave(&priv
->lock
, flags
);
2862 priv
->vif
= conf
->vif
;
2864 spin_unlock_irqrestore(&priv
->lock
, flags
);
2866 mutex_lock(&priv
->mutex
);
2868 if (conf
->mac_addr
) {
2869 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
2870 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
2873 if (iwl4965_set_mode(priv
, conf
->type
) == -EAGAIN
)
2874 /* we are not ready, will run again when ready */
2875 set_bit(STATUS_MODE_PENDING
, &priv
->status
);
2877 mutex_unlock(&priv
->mutex
);
2879 IWL_DEBUG_MAC80211("leave\n");
2884 * iwl4965_mac_config - mac80211 config callback
2886 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2887 * be set inappropriately and the driver currently sets the hardware up to
2888 * use it whenever needed.
2890 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
2892 struct iwl_priv
*priv
= hw
->priv
;
2893 const struct iwl_channel_info
*ch_info
;
2894 unsigned long flags
;
2898 mutex_lock(&priv
->mutex
);
2899 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
2901 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
2903 if (conf
->radio_enabled
&& iwl_radio_kill_sw_enable_radio(priv
)) {
2904 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
2908 if (!conf
->radio_enabled
)
2909 iwl_radio_kill_sw_disable_radio(priv
);
2911 if (!iwl_is_ready(priv
)) {
2912 IWL_DEBUG_MAC80211("leave - not ready\n");
2917 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
2918 test_bit(STATUS_SCANNING
, &priv
->status
))) {
2919 IWL_DEBUG_MAC80211("leave - scanning\n");
2920 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
2921 mutex_unlock(&priv
->mutex
);
2925 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2926 ch_info
= iwl_get_channel_info(priv
, conf
->channel
->band
, channel
);
2927 if (!is_channel_valid(ch_info
)) {
2928 IWL_DEBUG_MAC80211("leave - invalid channel\n");
2933 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
&&
2934 !is_channel_ibss(ch_info
)) {
2935 IWL_ERROR("channel %d in band %d not IBSS channel\n",
2936 conf
->channel
->hw_value
, conf
->channel
->band
);
2941 spin_lock_irqsave(&priv
->lock
, flags
);
2943 /* if we are switching from ht to 2.4 clear flags
2944 * from any ht related info since 2.4 does not
2946 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != channel
)
2947 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
2948 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
2951 priv
->staging_rxon
.flags
= 0;
2953 iwl_set_rxon_channel(priv
, conf
->channel
->band
, channel
);
2955 iwl_set_flags_for_band(priv
, conf
->channel
->band
);
2957 /* The list of supported rates and rate mask can be different
2958 * for each band; since the band may have changed, reset
2959 * the rate mask to what mac80211 lists */
2960 iwl4965_set_rate(priv
);
2962 spin_unlock_irqrestore(&priv
->lock
, flags
);
2964 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
2965 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
2966 iwl4965_hw_channel_switch(priv
, conf
->channel
);
2971 if (!conf
->radio_enabled
) {
2972 IWL_DEBUG_MAC80211("leave - radio disabled\n");
2976 if (iwl_is_rfkill(priv
)) {
2977 IWL_DEBUG_MAC80211("leave - RF kill\n");
2982 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2983 priv
->tx_power_user_lmt
, conf
->power_level
);
2985 iwl_set_tx_power(priv
, conf
->power_level
, false);
2987 iwl4965_set_rate(priv
);
2989 if (memcmp(&priv
->active_rxon
,
2990 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
2991 iwl4965_commit_rxon(priv
);
2993 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2995 IWL_DEBUG_MAC80211("leave\n");
2998 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
2999 mutex_unlock(&priv
->mutex
);
3003 static void iwl4965_config_ap(struct iwl_priv
*priv
)
3007 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3010 /* The following should be done only at AP bring up */
3011 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
3013 /* RXON - unassoc (to set timing command) */
3014 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3015 iwl4965_commit_rxon(priv
);
3018 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
3019 iwl4965_setup_rxon_timing(priv
);
3020 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
3021 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
3023 IWL_WARNING("REPLY_RXON_TIMING failed - "
3024 "Attempting to continue.\n");
3026 iwl_set_rxon_chain(priv
);
3028 /* FIXME: what should be the assoc_id for AP? */
3029 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
3030 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
3031 priv
->staging_rxon
.flags
|=
3032 RXON_FLG_SHORT_PREAMBLE_MSK
;
3034 priv
->staging_rxon
.flags
&=
3035 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
3037 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
3038 if (priv
->assoc_capability
&
3039 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
3040 priv
->staging_rxon
.flags
|=
3041 RXON_FLG_SHORT_SLOT_MSK
;
3043 priv
->staging_rxon
.flags
&=
3044 ~RXON_FLG_SHORT_SLOT_MSK
;
3046 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
3047 priv
->staging_rxon
.flags
&=
3048 ~RXON_FLG_SHORT_SLOT_MSK
;
3050 /* restore RXON assoc */
3051 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
3052 iwl4965_commit_rxon(priv
);
3053 iwl4965_activate_qos(priv
, 1);
3054 iwl_rxon_add_station(priv
, iwl_bcast_addr
, 0);
3056 iwl4965_send_beacon_cmd(priv
);
3058 /* FIXME - we need to add code here to detect a totally new
3059 * configuration, reset the AP, unassoc, rxon timing, assoc,
3060 * clear sta table, add BCAST sta... */
3063 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
3064 struct ieee80211_vif
*vif
,
3065 struct ieee80211_if_conf
*conf
)
3067 struct iwl_priv
*priv
= hw
->priv
;
3068 DECLARE_MAC_BUF(mac
);
3069 unsigned long flags
;
3075 if (priv
->vif
!= vif
) {
3076 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
3080 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3081 (!conf
->beacon
|| !conf
->ssid_len
)) {
3083 ("Leaving in AP mode because HostAPD is not ready.\n");
3087 if (!iwl_is_alive(priv
))
3090 mutex_lock(&priv
->mutex
);
3093 IWL_DEBUG_MAC80211("bssid: %s\n",
3094 print_mac(mac
, conf
->bssid
));
3097 * very dubious code was here; the probe filtering flag is never set:
3099 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3100 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
3103 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
3105 conf
->bssid
= priv
->mac_addr
;
3106 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
3107 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
3108 print_mac(mac
, conf
->bssid
));
3110 if (priv
->ibss_beacon
)
3111 dev_kfree_skb(priv
->ibss_beacon
);
3113 priv
->ibss_beacon
= conf
->beacon
;
3116 if (iwl_is_rfkill(priv
))
3119 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
3120 !is_multicast_ether_addr(conf
->bssid
)) {
3121 /* If there is currently a HW scan going on in the background
3122 * then we need to cancel it else the RXON below will fail. */
3123 if (iwl_scan_cancel_timeout(priv
, 100)) {
3124 IWL_WARNING("Aborted scan still in progress "
3126 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
3127 mutex_unlock(&priv
->mutex
);
3130 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
3132 /* TODO: Audit driver for usage of these members and see
3133 * if mac80211 deprecates them (priv->bssid looks like it
3134 * shouldn't be there, but I haven't scanned the IBSS code
3135 * to verify) - jpk */
3136 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
3138 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
3139 iwl4965_config_ap(priv
);
3141 rc
= iwl4965_commit_rxon(priv
);
3142 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
3143 iwl_rxon_add_station(
3144 priv
, priv
->active_rxon
.bssid_addr
, 1);
3148 iwl_scan_cancel_timeout(priv
, 100);
3149 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3150 iwl4965_commit_rxon(priv
);
3154 spin_lock_irqsave(&priv
->lock
, flags
);
3155 if (!conf
->ssid_len
)
3156 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
3158 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
3160 priv
->essid_len
= conf
->ssid_len
;
3161 spin_unlock_irqrestore(&priv
->lock
, flags
);
3163 IWL_DEBUG_MAC80211("leave\n");
3164 mutex_unlock(&priv
->mutex
);
3169 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
3170 unsigned int changed_flags
,
3171 unsigned int *total_flags
,
3172 int mc_count
, struct dev_addr_list
*mc_list
)
3176 * see also iwl4965_connection_init_rx_config
3178 struct iwl_priv
*priv
= hw
->priv
;
3180 if (changed_flags
& (FIF_PROMISC_IN_BSS
| FIF_OTHER_BSS
)) {
3181 if (*total_flags
& (FIF_PROMISC_IN_BSS
| FIF_OTHER_BSS
)) {
3182 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
3183 IEEE80211_IF_TYPE_MNTR
,
3184 changed_flags
, *total_flags
);
3185 /* queue work 'cuz mac80211 is holding a lock which
3186 * prevents us from issuing (synchronous) f/w cmds */
3187 queue_work(priv
->workqueue
, &priv
->set_monitor
);
3188 new_flags
&= FIF_PROMISC_IN_BSS
|
3193 *total_flags
= new_flags
;
3196 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
3197 struct ieee80211_if_init_conf
*conf
)
3199 struct iwl_priv
*priv
= hw
->priv
;
3201 IWL_DEBUG_MAC80211("enter\n");
3203 mutex_lock(&priv
->mutex
);
3205 if (iwl_is_ready_rf(priv
)) {
3206 iwl_scan_cancel_timeout(priv
, 100);
3207 cancel_delayed_work(&priv
->post_associate
);
3208 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3209 iwl4965_commit_rxon(priv
);
3211 if (priv
->vif
== conf
->vif
) {
3213 memset(priv
->bssid
, 0, ETH_ALEN
);
3214 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
3215 priv
->essid_len
= 0;
3217 mutex_unlock(&priv
->mutex
);
3219 IWL_DEBUG_MAC80211("leave\n");
3223 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
3224 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
3225 struct ieee80211_vif
*vif
,
3226 struct ieee80211_bss_conf
*bss_conf
,
3229 struct iwl_priv
*priv
= hw
->priv
;
3231 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
3233 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
3234 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
3235 bss_conf
->use_short_preamble
);
3236 if (bss_conf
->use_short_preamble
)
3237 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
3239 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
3242 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
3243 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
3244 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
3245 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
3247 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
3250 if (changes
& BSS_CHANGED_HT
) {
3251 IWL_DEBUG_MAC80211("HT %d\n", bss_conf
->assoc_ht
);
3252 iwl4965_ht_conf(priv
, bss_conf
);
3253 iwl_set_rxon_chain(priv
);
3256 if (changes
& BSS_CHANGED_ASSOC
) {
3257 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
3258 /* This should never happen as this function should
3259 * never be called from interrupt context. */
3260 if (WARN_ON_ONCE(in_interrupt()))
3262 if (bss_conf
->assoc
) {
3263 priv
->assoc_id
= bss_conf
->aid
;
3264 priv
->beacon_int
= bss_conf
->beacon_int
;
3265 priv
->timestamp
= bss_conf
->timestamp
;
3266 priv
->assoc_capability
= bss_conf
->assoc_capability
;
3267 priv
->next_scan_jiffies
= jiffies
+
3268 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
3269 mutex_lock(&priv
->mutex
);
3270 iwl4965_post_associate(priv
);
3271 mutex_unlock(&priv
->mutex
);
3274 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
3276 } else if (changes
&& iwl_is_associated(priv
) && priv
->assoc_id
) {
3277 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
3278 iwl_send_rxon_assoc(priv
);
3283 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
3286 unsigned long flags
;
3287 struct iwl_priv
*priv
= hw
->priv
;
3289 IWL_DEBUG_MAC80211("enter\n");
3291 mutex_lock(&priv
->mutex
);
3292 spin_lock_irqsave(&priv
->lock
, flags
);
3294 if (!iwl_is_ready_rf(priv
)) {
3296 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3300 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
3302 IWL_ERROR("ERROR: APs don't scan\n");
3306 /* we don't schedule scan within next_scan_jiffies period */
3307 if (priv
->next_scan_jiffies
&&
3308 time_after(priv
->next_scan_jiffies
, jiffies
)) {
3312 /* if we just finished scan ask for delay */
3313 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
3314 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
3319 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
3320 iwl_escape_essid(ssid
, len
), (int)len
);
3322 priv
->one_direct_scan
= 1;
3323 priv
->direct_ssid_len
= (u8
)
3324 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
3325 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
3327 priv
->one_direct_scan
= 0;
3329 rc
= iwl_scan_initiate(priv
);
3331 IWL_DEBUG_MAC80211("leave\n");
3334 spin_unlock_irqrestore(&priv
->lock
, flags
);
3335 mutex_unlock(&priv
->mutex
);
3340 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw
*hw
,
3341 struct ieee80211_key_conf
*keyconf
, const u8
*addr
,
3342 u32 iv32
, u16
*phase1key
)
3344 struct iwl_priv
*priv
= hw
->priv
;
3345 u8 sta_id
= IWL_INVALID_STATION
;
3346 unsigned long flags
;
3347 __le16 key_flags
= 0;
3349 DECLARE_MAC_BUF(mac
);
3351 IWL_DEBUG_MAC80211("enter\n");
3353 sta_id
= iwl_find_station(priv
, addr
);
3354 if (sta_id
== IWL_INVALID_STATION
) {
3355 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3356 print_mac(mac
, addr
));
3360 iwl_scan_cancel_timeout(priv
, 100);
3362 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
3363 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
3364 key_flags
&= ~STA_KEY_FLG_INVALID
;
3366 if (sta_id
== priv
->hw_params
.bcast_sta_id
)
3367 key_flags
|= STA_KEY_MULTICAST_MSK
;
3369 spin_lock_irqsave(&priv
->sta_lock
, flags
);
3371 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
3372 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
3374 for (i
= 0; i
< 5; i
++)
3375 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
3376 cpu_to_le16(phase1key
[i
]);
3378 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
3379 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
3381 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
3383 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
3385 IWL_DEBUG_MAC80211("leave\n");
3388 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3389 const u8
*local_addr
, const u8
*addr
,
3390 struct ieee80211_key_conf
*key
)
3392 struct iwl_priv
*priv
= hw
->priv
;
3393 DECLARE_MAC_BUF(mac
);
3395 u8 sta_id
= IWL_INVALID_STATION
;
3396 u8 is_default_wep_key
= 0;
3398 IWL_DEBUG_MAC80211("enter\n");
3400 if (priv
->hw_params
.sw_crypto
) {
3401 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3405 if (is_zero_ether_addr(addr
))
3406 /* only support pairwise keys */
3409 sta_id
= iwl_find_station(priv
, addr
);
3410 if (sta_id
== IWL_INVALID_STATION
) {
3411 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3412 print_mac(mac
, addr
));
3417 mutex_lock(&priv
->mutex
);
3418 iwl_scan_cancel_timeout(priv
, 100);
3419 mutex_unlock(&priv
->mutex
);
3421 /* If we are getting WEP group key and we didn't receive any key mapping
3422 * so far, we are in legacy wep mode (group key only), otherwise we are
3424 * In legacy wep mode, we use another host command to the uCode */
3425 if (key
->alg
== ALG_WEP
&& sta_id
== priv
->hw_params
.bcast_sta_id
&&
3426 priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
3428 is_default_wep_key
= !priv
->key_mapping_key
;
3430 is_default_wep_key
=
3431 (key
->hw_key_idx
== HW_KEY_DEFAULT
);
3436 if (is_default_wep_key
)
3437 ret
= iwl_set_default_wep_key(priv
, key
);
3439 ret
= iwl_set_dynamic_key(priv
, key
, sta_id
);
3441 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
3444 if (is_default_wep_key
)
3445 ret
= iwl_remove_default_wep_key(priv
, key
);
3447 ret
= iwl_remove_dynamic_key(priv
, key
, sta_id
);
3449 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
3455 IWL_DEBUG_MAC80211("leave\n");
3460 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
3461 const struct ieee80211_tx_queue_params
*params
)
3463 struct iwl_priv
*priv
= hw
->priv
;
3464 unsigned long flags
;
3467 IWL_DEBUG_MAC80211("enter\n");
3469 if (!iwl_is_ready_rf(priv
)) {
3470 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3474 if (queue
>= AC_NUM
) {
3475 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
3479 if (!priv
->qos_data
.qos_enable
) {
3480 priv
->qos_data
.qos_active
= 0;
3481 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
3484 q
= AC_NUM
- 1 - queue
;
3486 spin_lock_irqsave(&priv
->lock
, flags
);
3488 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
3489 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
3490 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
3491 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
3492 cpu_to_le16((params
->txop
* 32));
3494 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
3495 priv
->qos_data
.qos_active
= 1;
3497 spin_unlock_irqrestore(&priv
->lock
, flags
);
3499 mutex_lock(&priv
->mutex
);
3500 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
3501 iwl4965_activate_qos(priv
, 1);
3502 else if (priv
->assoc_id
&& iwl_is_associated(priv
))
3503 iwl4965_activate_qos(priv
, 0);
3505 mutex_unlock(&priv
->mutex
);
3507 IWL_DEBUG_MAC80211("leave\n");
3511 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
3512 struct ieee80211_tx_queue_stats
*stats
)
3514 struct iwl_priv
*priv
= hw
->priv
;
3516 struct iwl_tx_queue
*txq
;
3517 struct iwl_queue
*q
;
3518 unsigned long flags
;
3520 IWL_DEBUG_MAC80211("enter\n");
3522 if (!iwl_is_ready_rf(priv
)) {
3523 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3527 spin_lock_irqsave(&priv
->lock
, flags
);
3529 for (i
= 0; i
< AC_NUM
; i
++) {
3530 txq
= &priv
->txq
[i
];
3532 avail
= iwl_queue_space(q
);
3534 stats
[i
].len
= q
->n_window
- avail
;
3535 stats
[i
].limit
= q
->n_window
- q
->high_mark
;
3536 stats
[i
].count
= q
->n_window
;
3539 spin_unlock_irqrestore(&priv
->lock
, flags
);
3541 IWL_DEBUG_MAC80211("leave\n");
3546 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
3547 struct ieee80211_low_level_stats
*stats
)
3549 struct iwl_priv
*priv
= hw
->priv
;
3552 IWL_DEBUG_MAC80211("enter\n");
3553 IWL_DEBUG_MAC80211("leave\n");
3558 static u64
iwl4965_mac_get_tsf(struct ieee80211_hw
*hw
)
3560 struct iwl_priv
*priv
;
3563 IWL_DEBUG_MAC80211("enter\n");
3564 IWL_DEBUG_MAC80211("leave\n");
3569 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
3571 struct iwl_priv
*priv
= hw
->priv
;
3572 unsigned long flags
;
3574 mutex_lock(&priv
->mutex
);
3575 IWL_DEBUG_MAC80211("enter\n");
3577 priv
->lq_mngr
.lq_ready
= 0;
3578 spin_lock_irqsave(&priv
->lock
, flags
);
3579 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
3580 spin_unlock_irqrestore(&priv
->lock
, flags
);
3582 iwl_reset_qos(priv
);
3584 cancel_delayed_work(&priv
->post_associate
);
3586 spin_lock_irqsave(&priv
->lock
, flags
);
3588 priv
->assoc_capability
= 0;
3589 priv
->assoc_station_added
= 0;
3591 /* new association get rid of ibss beacon skb */
3592 if (priv
->ibss_beacon
)
3593 dev_kfree_skb(priv
->ibss_beacon
);
3595 priv
->ibss_beacon
= NULL
;
3597 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
3598 priv
->timestamp
= 0;
3599 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
3600 priv
->beacon_int
= 0;
3602 spin_unlock_irqrestore(&priv
->lock
, flags
);
3604 if (!iwl_is_ready_rf(priv
)) {
3605 IWL_DEBUG_MAC80211("leave - not ready\n");
3606 mutex_unlock(&priv
->mutex
);
3610 /* we are restarting association process
3611 * clear RXON_FILTER_ASSOC_MSK bit
3613 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
3614 iwl_scan_cancel_timeout(priv
, 100);
3615 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3616 iwl4965_commit_rxon(priv
);
3619 iwl_power_update_mode(priv
, 0);
3621 /* Per mac80211.h: This is only used in IBSS mode... */
3622 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
3624 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3625 mutex_unlock(&priv
->mutex
);
3629 iwl4965_set_rate(priv
);
3631 mutex_unlock(&priv
->mutex
);
3633 IWL_DEBUG_MAC80211("leave\n");
3636 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3638 struct iwl_priv
*priv
= hw
->priv
;
3639 unsigned long flags
;
3641 mutex_lock(&priv
->mutex
);
3642 IWL_DEBUG_MAC80211("enter\n");
3644 if (!iwl_is_ready_rf(priv
)) {
3645 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3646 mutex_unlock(&priv
->mutex
);
3650 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
3651 IWL_DEBUG_MAC80211("leave - not IBSS\n");
3652 mutex_unlock(&priv
->mutex
);
3656 spin_lock_irqsave(&priv
->lock
, flags
);
3658 if (priv
->ibss_beacon
)
3659 dev_kfree_skb(priv
->ibss_beacon
);
3661 priv
->ibss_beacon
= skb
;
3665 IWL_DEBUG_MAC80211("leave\n");
3666 spin_unlock_irqrestore(&priv
->lock
, flags
);
3668 iwl_reset_qos(priv
);
3670 iwl4965_post_associate(priv
);
3672 mutex_unlock(&priv
->mutex
);
3677 /*****************************************************************************
3681 *****************************************************************************/
3683 #ifdef CONFIG_IWLWIFI_DEBUG
3686 * The following adds a new attribute to the sysfs representation
3687 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3688 * used for controlling the debug level.
3690 * See the level definitions in iwl for details.
3693 static ssize_t
show_debug_level(struct device
*d
,
3694 struct device_attribute
*attr
, char *buf
)
3696 struct iwl_priv
*priv
= d
->driver_data
;
3698 return sprintf(buf
, "0x%08X\n", priv
->debug_level
);
3700 static ssize_t
store_debug_level(struct device
*d
,
3701 struct device_attribute
*attr
,
3702 const char *buf
, size_t count
)
3704 struct iwl_priv
*priv
= d
->driver_data
;
3705 char *p
= (char *)buf
;
3708 val
= simple_strtoul(p
, &p
, 0);
3710 printk(KERN_INFO DRV_NAME
3711 ": %s is not in hex or decimal form.\n", buf
);
3713 priv
->debug_level
= val
;
3715 return strnlen(buf
, count
);
3718 static DEVICE_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
3719 show_debug_level
, store_debug_level
);
3722 #endif /* CONFIG_IWLWIFI_DEBUG */
3725 static ssize_t
show_version(struct device
*d
,
3726 struct device_attribute
*attr
, char *buf
)
3728 struct iwl_priv
*priv
= d
->driver_data
;
3729 struct iwl_alive_resp
*palive
= &priv
->card_alive
;
3733 if (palive
->is_valid
)
3734 pos
+= sprintf(buf
+ pos
,
3735 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3736 "fw type: 0x%01X 0x%01X\n",
3737 palive
->ucode_major
, palive
->ucode_minor
,
3738 palive
->sw_rev
[0], palive
->sw_rev
[1],
3739 palive
->ver_type
, palive
->ver_subtype
);
3741 pos
+= sprintf(buf
+ pos
, "fw not loaded\n");
3744 eeprom_ver
= iwl_eeprom_query16(priv
, EEPROM_VERSION
);
3745 pos
+= sprintf(buf
+ pos
, "EEPROM version: 0x%x\n",
3748 pos
+= sprintf(buf
+ pos
, "EEPROM not initialzed\n");
3754 static DEVICE_ATTR(version
, S_IWUSR
| S_IRUGO
, show_version
, NULL
);
3756 static ssize_t
show_temperature(struct device
*d
,
3757 struct device_attribute
*attr
, char *buf
)
3759 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3761 if (!iwl_is_alive(priv
))
3764 return sprintf(buf
, "%d\n", priv
->temperature
);
3767 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
3769 static ssize_t
show_rs_window(struct device
*d
,
3770 struct device_attribute
*attr
,
3773 struct iwl_priv
*priv
= d
->driver_data
;
3774 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
3776 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
3778 static ssize_t
show_tx_power(struct device
*d
,
3779 struct device_attribute
*attr
, char *buf
)
3781 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3782 return sprintf(buf
, "%d\n", priv
->tx_power_user_lmt
);
3785 static ssize_t
store_tx_power(struct device
*d
,
3786 struct device_attribute
*attr
,
3787 const char *buf
, size_t count
)
3789 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3790 char *p
= (char *)buf
;
3793 val
= simple_strtoul(p
, &p
, 10);
3795 printk(KERN_INFO DRV_NAME
3796 ": %s is not in decimal form.\n", buf
);
3798 iwl_set_tx_power(priv
, val
, false);
3803 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
3805 static ssize_t
show_flags(struct device
*d
,
3806 struct device_attribute
*attr
, char *buf
)
3808 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3810 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
3813 static ssize_t
store_flags(struct device
*d
,
3814 struct device_attribute
*attr
,
3815 const char *buf
, size_t count
)
3817 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3818 u32 flags
= simple_strtoul(buf
, NULL
, 0);
3820 mutex_lock(&priv
->mutex
);
3821 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
3822 /* Cancel any currently running scans... */
3823 if (iwl_scan_cancel_timeout(priv
, 100))
3824 IWL_WARNING("Could not cancel scan.\n");
3826 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
3828 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
3829 iwl4965_commit_rxon(priv
);
3832 mutex_unlock(&priv
->mutex
);
3837 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
3839 static ssize_t
show_filter_flags(struct device
*d
,
3840 struct device_attribute
*attr
, char *buf
)
3842 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3844 return sprintf(buf
, "0x%04X\n",
3845 le32_to_cpu(priv
->active_rxon
.filter_flags
));
3848 static ssize_t
store_filter_flags(struct device
*d
,
3849 struct device_attribute
*attr
,
3850 const char *buf
, size_t count
)
3852 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
3853 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
3855 mutex_lock(&priv
->mutex
);
3856 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
3857 /* Cancel any currently running scans... */
3858 if (iwl_scan_cancel_timeout(priv
, 100))
3859 IWL_WARNING("Could not cancel scan.\n");
3861 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3862 "0x%04X\n", filter_flags
);
3863 priv
->staging_rxon
.filter_flags
=
3864 cpu_to_le32(filter_flags
);
3865 iwl4965_commit_rxon(priv
);
3868 mutex_unlock(&priv
->mutex
);
3873 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
3874 store_filter_flags
);
3876 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3878 static ssize_t
show_measurement(struct device
*d
,
3879 struct device_attribute
*attr
, char *buf
)
3881 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3882 struct iwl4965_spectrum_notification measure_report
;
3883 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
3884 u8
*data
= (u8
*) & measure_report
;
3885 unsigned long flags
;
3887 spin_lock_irqsave(&priv
->lock
, flags
);
3888 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
3889 spin_unlock_irqrestore(&priv
->lock
, flags
);
3892 memcpy(&measure_report
, &priv
->measure_report
, size
);
3893 priv
->measurement_status
= 0;
3894 spin_unlock_irqrestore(&priv
->lock
, flags
);
3896 while (size
&& (PAGE_SIZE
- len
)) {
3897 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
3898 PAGE_SIZE
- len
, 1);
3900 if (PAGE_SIZE
- len
)
3904 size
-= min(size
, 16U);
3910 static ssize_t
store_measurement(struct device
*d
,
3911 struct device_attribute
*attr
,
3912 const char *buf
, size_t count
)
3914 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3915 struct ieee80211_measurement_params params
= {
3916 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
3917 .start_time
= cpu_to_le64(priv
->last_tsf
),
3918 .duration
= cpu_to_le16(1),
3920 u8 type
= IWL_MEASURE_BASIC
;
3926 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
3927 channel
= simple_strtoul(p
, NULL
, 0);
3929 params
.channel
= channel
;
3932 while (*p
&& *p
!= ' ')
3935 type
= simple_strtoul(p
+ 1, NULL
, 0);
3938 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3939 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
3940 iwl4965_get_measurement(priv
, ¶ms
, type
);
3945 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
3946 show_measurement
, store_measurement
);
3947 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
3949 static ssize_t
store_retry_rate(struct device
*d
,
3950 struct device_attribute
*attr
,
3951 const char *buf
, size_t count
)
3953 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3955 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
3956 if (priv
->retry_rate
<= 0)
3957 priv
->retry_rate
= 1;
3962 static ssize_t
show_retry_rate(struct device
*d
,
3963 struct device_attribute
*attr
, char *buf
)
3965 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3966 return sprintf(buf
, "%d", priv
->retry_rate
);
3969 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
3972 static ssize_t
store_power_level(struct device
*d
,
3973 struct device_attribute
*attr
,
3974 const char *buf
, size_t count
)
3976 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3980 mode
= simple_strtoul(buf
, NULL
, 0);
3981 mutex_lock(&priv
->mutex
);
3983 if (!iwl_is_ready(priv
)) {
3988 rc
= iwl_power_set_user_mode(priv
, mode
);
3990 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3996 mutex_unlock(&priv
->mutex
);
4000 #define MAX_WX_STRING 80
4002 /* Values are in microsecond */
4003 static const s32 timeout_duration
[] = {
4010 static const s32 period_duration
[] = {
4018 static ssize_t
show_power_level(struct device
*d
,
4019 struct device_attribute
*attr
, char *buf
)
4021 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4022 int level
= priv
->power_data
.power_mode
;
4025 p
+= sprintf(p
, "%d ", level
);
4027 case IWL_POWER_MODE_CAM
:
4029 p
+= sprintf(p
, "(AC)");
4031 case IWL_POWER_BATTERY
:
4032 p
+= sprintf(p
, "(BATTERY)");
4036 "(Timeout %dms, Period %dms)",
4037 timeout_duration
[level
- 1] / 1000,
4038 period_duration
[level
- 1] / 1000);
4041 if (!(priv->power_mode & IWL_POWER_ENABLED))
4042 p += sprintf(p, " OFF\n");
4044 p += sprintf(p, " \n");
4046 p
+= sprintf(p
, " \n");
4047 return (p
- buf
+ 1);
4050 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
4053 static ssize_t
show_channels(struct device
*d
,
4054 struct device_attribute
*attr
, char *buf
)
4057 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4058 struct ieee80211_channel
*channels
= NULL
;
4059 const struct ieee80211_supported_band
*supp_band
= NULL
;
4063 if (!test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
))
4066 supp_band
= iwl_get_hw_mode(priv
, IEEE80211_BAND_2GHZ
);
4067 channels
= supp_band
->channels
;
4068 count
= supp_band
->n_channels
;
4070 len
+= sprintf(&buf
[len
],
4071 "Displaying %d channels in 2.4GHz band "
4072 "(802.11bg):\n", count
);
4074 for (i
= 0; i
< count
; i
++)
4075 len
+= sprintf(&buf
[len
], "%d: %ddBm: BSS%s%s, %s.\n",
4076 ieee80211_frequency_to_channel(
4077 channels
[i
].center_freq
),
4078 channels
[i
].max_power
,
4079 channels
[i
].flags
& IEEE80211_CHAN_RADAR
?
4080 " (IEEE 802.11h required)" : "",
4081 (!(channels
[i
].flags
& IEEE80211_CHAN_NO_IBSS
)
4082 || (channels
[i
].flags
&
4083 IEEE80211_CHAN_RADAR
)) ? "" :
4086 IEEE80211_CHAN_PASSIVE_SCAN
?
4087 "passive only" : "active/passive");
4089 supp_band
= iwl_get_hw_mode(priv
, IEEE80211_BAND_5GHZ
);
4090 channels
= supp_band
->channels
;
4091 count
= supp_band
->n_channels
;
4093 len
+= sprintf(&buf
[len
], "Displaying %d channels in 5.2GHz band "
4094 "(802.11a):\n", count
);
4096 for (i
= 0; i
< count
; i
++)
4097 len
+= sprintf(&buf
[len
], "%d: %ddBm: BSS%s%s, %s.\n",
4098 ieee80211_frequency_to_channel(
4099 channels
[i
].center_freq
),
4100 channels
[i
].max_power
,
4101 channels
[i
].flags
& IEEE80211_CHAN_RADAR
?
4102 " (IEEE 802.11h required)" : "",
4103 ((channels
[i
].flags
& IEEE80211_CHAN_NO_IBSS
)
4104 || (channels
[i
].flags
&
4105 IEEE80211_CHAN_RADAR
)) ? "" :
4108 IEEE80211_CHAN_PASSIVE_SCAN
?
4109 "passive only" : "active/passive");
4114 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
4116 static ssize_t
show_statistics(struct device
*d
,
4117 struct device_attribute
*attr
, char *buf
)
4119 struct iwl_priv
*priv
= dev_get_drvdata(d
);
4120 u32 size
= sizeof(struct iwl4965_notif_statistics
);
4121 u32 len
= 0, ofs
= 0;
4122 u8
*data
= (u8
*) & priv
->statistics
;
4125 if (!iwl_is_alive(priv
))
4128 mutex_lock(&priv
->mutex
);
4129 rc
= iwl_send_statistics_request(priv
, 0);
4130 mutex_unlock(&priv
->mutex
);
4134 "Error sending statistics request: 0x%08X\n", rc
);
4138 while (size
&& (PAGE_SIZE
- len
)) {
4139 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
4140 PAGE_SIZE
- len
, 1);
4142 if (PAGE_SIZE
- len
)
4146 size
-= min(size
, 16U);
4152 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
4154 static ssize_t
show_status(struct device
*d
,
4155 struct device_attribute
*attr
, char *buf
)
4157 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
4158 if (!iwl_is_alive(priv
))
4160 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
4163 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
4165 /*****************************************************************************
4167 * driver setup and teardown
4169 *****************************************************************************/
4171 static void iwl_setup_deferred_work(struct iwl_priv
*priv
)
4173 priv
->workqueue
= create_workqueue(DRV_NAME
);
4175 init_waitqueue_head(&priv
->wait_command_queue
);
4177 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
4178 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
4179 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
4180 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
4181 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
4182 INIT_WORK(&priv
->set_monitor
, iwl4965_bg_set_monitor
);
4183 INIT_WORK(&priv
->run_time_calib_work
, iwl_bg_run_time_calib_work
);
4184 INIT_DELAYED_WORK(&priv
->post_associate
, iwl4965_bg_post_associate
);
4185 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl_bg_init_alive_start
);
4186 INIT_DELAYED_WORK(&priv
->alive_start
, iwl_bg_alive_start
);
4188 /* FIXME : remove when resolved PENDING */
4189 INIT_WORK(&priv
->scan_completed
, iwl_bg_scan_completed
);
4190 iwl_setup_scan_deferred_work(priv
);
4192 if (priv
->cfg
->ops
->lib
->setup_deferred_work
)
4193 priv
->cfg
->ops
->lib
->setup_deferred_work(priv
);
4195 init_timer(&priv
->statistics_periodic
);
4196 priv
->statistics_periodic
.data
= (unsigned long)priv
;
4197 priv
->statistics_periodic
.function
= iwl4965_bg_statistics_periodic
;
4199 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
4200 iwl4965_irq_tasklet
, (unsigned long)priv
);
4203 static void iwl_cancel_deferred_work(struct iwl_priv
*priv
)
4205 if (priv
->cfg
->ops
->lib
->cancel_deferred_work
)
4206 priv
->cfg
->ops
->lib
->cancel_deferred_work(priv
);
4208 cancel_delayed_work_sync(&priv
->init_alive_start
);
4209 cancel_delayed_work(&priv
->scan_check
);
4210 cancel_delayed_work(&priv
->alive_start
);
4211 cancel_delayed_work(&priv
->post_associate
);
4212 cancel_work_sync(&priv
->beacon_update
);
4213 del_timer_sync(&priv
->statistics_periodic
);
4216 static struct attribute
*iwl4965_sysfs_entries
[] = {
4217 &dev_attr_channels
.attr
,
4218 &dev_attr_flags
.attr
,
4219 &dev_attr_filter_flags
.attr
,
4220 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
4221 &dev_attr_measurement
.attr
,
4223 &dev_attr_power_level
.attr
,
4224 &dev_attr_retry_rate
.attr
,
4225 &dev_attr_rs_window
.attr
,
4226 &dev_attr_statistics
.attr
,
4227 &dev_attr_status
.attr
,
4228 &dev_attr_temperature
.attr
,
4229 &dev_attr_tx_power
.attr
,
4230 #ifdef CONFIG_IWLWIFI_DEBUG
4231 &dev_attr_debug_level
.attr
,
4233 &dev_attr_version
.attr
,
4238 static struct attribute_group iwl4965_attribute_group
= {
4239 .name
= NULL
, /* put in device directory */
4240 .attrs
= iwl4965_sysfs_entries
,
4243 static struct ieee80211_ops iwl4965_hw_ops
= {
4244 .tx
= iwl4965_mac_tx
,
4245 .start
= iwl4965_mac_start
,
4246 .stop
= iwl4965_mac_stop
,
4247 .add_interface
= iwl4965_mac_add_interface
,
4248 .remove_interface
= iwl4965_mac_remove_interface
,
4249 .config
= iwl4965_mac_config
,
4250 .config_interface
= iwl4965_mac_config_interface
,
4251 .configure_filter
= iwl4965_configure_filter
,
4252 .set_key
= iwl4965_mac_set_key
,
4253 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
4254 .get_stats
= iwl4965_mac_get_stats
,
4255 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
4256 .conf_tx
= iwl4965_mac_conf_tx
,
4257 .get_tsf
= iwl4965_mac_get_tsf
,
4258 .reset_tsf
= iwl4965_mac_reset_tsf
,
4259 .beacon_update
= iwl4965_mac_beacon_update
,
4260 .bss_info_changed
= iwl4965_bss_info_changed
,
4261 .ampdu_action
= iwl4965_mac_ampdu_action
,
4262 .hw_scan
= iwl4965_mac_hw_scan
4265 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
4268 struct iwl_priv
*priv
;
4269 struct ieee80211_hw
*hw
;
4270 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
4271 unsigned long flags
;
4272 DECLARE_MAC_BUF(mac
);
4274 /************************
4275 * 1. Allocating HW data
4276 ************************/
4278 /* Disabling hardware scan means that mac80211 will perform scans
4279 * "the hard way", rather than using device's scan. */
4280 if (cfg
->mod_params
->disable_hw_scan
) {
4281 if (cfg
->mod_params
->debug
& IWL_DL_INFO
)
4282 dev_printk(KERN_DEBUG
, &(pdev
->dev
),
4283 "Disabling hw_scan\n");
4284 iwl4965_hw_ops
.hw_scan
= NULL
;
4287 hw
= iwl_alloc_all(cfg
, &iwl4965_hw_ops
);
4293 /* At this point both hw and priv are allocated. */
4295 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
4297 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
4299 priv
->pci_dev
= pdev
;
4301 #ifdef CONFIG_IWLWIFI_DEBUG
4302 priv
->debug_level
= priv
->cfg
->mod_params
->debug
;
4303 atomic_set(&priv
->restrict_refcnt
, 0);
4306 /**************************
4307 * 2. Initializing PCI bus
4308 **************************/
4309 if (pci_enable_device(pdev
)) {
4311 goto out_ieee80211_free_hw
;
4314 pci_set_master(pdev
);
4316 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
4318 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
4320 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
4322 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
4323 /* both attempts failed: */
4325 printk(KERN_WARNING
"%s: No suitable DMA available.\n",
4327 goto out_pci_disable_device
;
4331 err
= pci_request_regions(pdev
, DRV_NAME
);
4333 goto out_pci_disable_device
;
4335 pci_set_drvdata(pdev
, priv
);
4337 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4338 * PCI Tx retries from interfering with C3 CPU state */
4339 pci_write_config_byte(pdev
, 0x41, 0x00);
4341 /***********************
4342 * 3. Read REV register
4343 ***********************/
4344 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
4345 if (!priv
->hw_base
) {
4347 goto out_pci_release_regions
;
4350 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
4351 (unsigned long long) pci_resource_len(pdev
, 0));
4352 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
4354 iwl_hw_detect(priv
);
4355 printk(KERN_INFO DRV_NAME
4356 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
4357 priv
->cfg
->name
, priv
->hw_rev
);
4360 err
= priv
->cfg
->ops
->lib
->apm_ops
.init(priv
);
4362 IWL_DEBUG_INFO("Failed to init APMG\n");
4368 /* Read the EEPROM */
4369 err
= iwl_eeprom_init(priv
);
4371 IWL_ERROR("Unable to init EEPROM\n");
4374 err
= iwl_eeprom_check_version(priv
);
4378 /* extract MAC Address */
4379 iwl_eeprom_get_mac(priv
, priv
->mac_addr
);
4380 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
4381 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
4383 /************************
4384 * 5. Setup HW constants
4385 ************************/
4386 /* Device-specific setup */
4387 if (priv
->cfg
->ops
->lib
->set_hw_params(priv
)) {
4388 IWL_ERROR("failed to set hw parameters\n");
4389 goto out_free_eeprom
;
4392 /*******************
4394 *******************/
4396 err
= iwl_init_drv(priv
);
4398 goto out_free_eeprom
;
4399 /* At this point both hw and priv are initialized. */
4401 /**********************************
4402 * 7. Initialize module parameters
4403 **********************************/
4405 /* Disable radio (SW RF KILL) via parameter when loading driver */
4406 if (priv
->cfg
->mod_params
->disable
) {
4407 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
4408 IWL_DEBUG_INFO("Radio disabled.\n");
4411 /********************
4413 ********************/
4414 spin_lock_irqsave(&priv
->lock
, flags
);
4415 iwl4965_disable_interrupts(priv
);
4416 spin_unlock_irqrestore(&priv
->lock
, flags
);
4418 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
4420 IWL_ERROR("failed to create sysfs device attributes\n");
4421 goto out_uninit_drv
;
4425 iwl_setup_deferred_work(priv
);
4426 iwl4965_setup_rx_handlers(priv
);
4428 /********************
4430 ********************/
4431 pci_save_state(pdev
);
4432 pci_disable_device(pdev
);
4434 /**********************************
4435 * 10. Setup and register mac80211
4436 **********************************/
4438 err
= iwl_setup_mac(priv
);
4440 goto out_remove_sysfs
;
4442 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
4444 IWL_ERROR("failed to create debugfs files\n");
4446 err
= iwl_rfkill_init(priv
);
4448 IWL_ERROR("Unable to initialize RFKILL system. "
4449 "Ignoring error: %d\n", err
);
4450 iwl_power_initialize(priv
);
4454 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
4456 iwl_uninit_drv(priv
);
4458 iwl_eeprom_free(priv
);
4460 pci_iounmap(pdev
, priv
->hw_base
);
4461 out_pci_release_regions
:
4462 pci_release_regions(pdev
);
4463 pci_set_drvdata(pdev
, NULL
);
4464 out_pci_disable_device
:
4465 pci_disable_device(pdev
);
4466 out_ieee80211_free_hw
:
4467 ieee80211_free_hw(priv
->hw
);
4472 static void __devexit
iwl4965_pci_remove(struct pci_dev
*pdev
)
4474 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
4475 struct list_head
*p
, *q
;
4477 unsigned long flags
;
4482 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4484 iwl_dbgfs_unregister(priv
);
4485 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
4487 if (priv
->mac80211_registered
) {
4488 ieee80211_unregister_hw(priv
->hw
);
4489 priv
->mac80211_registered
= 0;
4492 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4496 /* make sure we flush any pending irq or
4497 * tasklet for the driver
4499 spin_lock_irqsave(&priv
->lock
, flags
);
4500 iwl4965_disable_interrupts(priv
);
4501 spin_unlock_irqrestore(&priv
->lock
, flags
);
4503 iwl_synchronize_irq(priv
);
4505 /* Free MAC hash list for ADHOC */
4506 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
4507 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
4509 kfree(list_entry(p
, struct iwl4965_ibss_seq
, list
));
4513 iwl_rfkill_unregister(priv
);
4514 iwl4965_dealloc_ucode_pci(priv
);
4517 iwl_rx_queue_free(priv
, &priv
->rxq
);
4518 iwl_hw_txq_ctx_free(priv
);
4520 iwlcore_clear_stations_table(priv
);
4521 iwl_eeprom_free(priv
);
4524 /*netif_stop_queue(dev); */
4525 flush_workqueue(priv
->workqueue
);
4527 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
4528 * priv->workqueue... so we can't take down the workqueue
4530 destroy_workqueue(priv
->workqueue
);
4531 priv
->workqueue
= NULL
;
4533 pci_iounmap(pdev
, priv
->hw_base
);
4534 pci_release_regions(pdev
);
4535 pci_disable_device(pdev
);
4536 pci_set_drvdata(pdev
, NULL
);
4538 iwl_uninit_drv(priv
);
4540 if (priv
->ibss_beacon
)
4541 dev_kfree_skb(priv
->ibss_beacon
);
4543 ieee80211_free_hw(priv
->hw
);
4548 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4550 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
4552 if (priv
->is_open
) {
4553 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
4554 iwl4965_mac_stop(priv
->hw
);
4558 pci_set_power_state(pdev
, PCI_D3hot
);
4563 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
4565 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
4567 pci_set_power_state(pdev
, PCI_D0
);
4570 iwl4965_mac_start(priv
->hw
);
4572 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
4576 #endif /* CONFIG_PM */
4578 /*****************************************************************************
4580 * driver and module entry point
4582 *****************************************************************************/
4584 /* Hardware specific file defines the PCI IDs table for that hardware module */
4585 static struct pci_device_id iwl_hw_card_ids
[] = {
4586 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID
, iwl4965_agn_cfg
)},
4587 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID
, iwl4965_agn_cfg
)},
4588 #ifdef CONFIG_IWL5000
4589 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID
, iwl5300_agn_cfg
)},
4590 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID
, iwl5100_agn_cfg
)},
4591 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID
, iwl5350_agn_cfg
)},
4592 #endif /* CONFIG_IWL5000 */
4595 MODULE_DEVICE_TABLE(pci
, iwl_hw_card_ids
);
4597 static struct pci_driver iwl_driver
= {
4599 .id_table
= iwl_hw_card_ids
,
4600 .probe
= iwl4965_pci_probe
,
4601 .remove
= __devexit_p(iwl4965_pci_remove
),
4603 .suspend
= iwl4965_pci_suspend
,
4604 .resume
= iwl4965_pci_resume
,
4608 static int __init
iwl4965_init(void)
4612 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
4613 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
4615 ret
= iwl4965_rate_control_register();
4617 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret
);
4621 ret
= pci_register_driver(&iwl_driver
);
4623 IWL_ERROR("Unable to initialize PCI module\n");
4624 goto error_register
;
4630 iwl4965_rate_control_unregister();
4634 static void __exit
iwl4965_exit(void)
4636 pci_unregister_driver(&iwl_driver
);
4637 iwl4965_rate_control_unregister();
4640 module_exit(iwl4965_exit
);
4641 module_init(iwl4965_init
);