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 iwl_remove_station(priv, iwl_bcast_addr, 0);
319 iwlcore_clear_stations_table(priv);
321 if (!priv->error_recovering)
322 priv->start_calib = 0;
324 iwl_init_sensitivity(priv);
326 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
328 /* If we issue a new RXON command which required a tune then we must
329 * send a new TXPOWER command or we won't be able to Tx any frames */
330 rc = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
332 IWL_ERROR("Error sending TX power (%d).\n", rc);
336 /* Add the broadcast address so we can send broadcast frames */
337 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
338 IWL_INVALID_STATION) {
339 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
343 /* If we have set the ASSOC_MSK and we are in BSS mode then
344 * add the IWL_AP_ID to the station rate table */
345 if (iwl_is_associated(priv) &&
346 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
347 if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
348 == IWL_INVALID_STATION) {
349 IWL_ERROR("Error adding AP address for transmit.\n");
352 priv->assoc_station_added = 1;
353 if (priv->default_wep_key &&
354 iwl_send_static_wepkey_cmd(priv, 0))
355 IWL_ERROR("Could not send WEP static key.\n");
361 void iwl4965_update_chain_flags(struct iwl_priv *priv)
364 iwl_set_rxon_chain(priv);
365 iwl4965_commit_rxon(priv);
368 static int iwl4965_send_bt_config(struct iwl_priv *priv)
370 struct iwl4965_bt_cmd bt_cmd = {
378 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
379 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
382 static void iwl_clear_free_frames(struct iwl_priv *priv)
384 struct list_head *element;
386 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
389 while (!list_empty(&priv->free_frames)) {
390 element = priv->free_frames.next;
392 kfree(list_entry(element, struct iwl_frame, list));
393 priv->frames_count--;
396 if (priv->frames_count) {
397 IWL_WARNING("%d frames still in use. Did we lose one?\n",
399 priv->frames_count = 0;
403 static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
405 struct iwl_frame *frame;
406 struct list_head *element;
407 if (list_empty(&priv->free_frames)) {
408 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
410 IWL_ERROR("Could not allocate frame!\n");
414 priv->frames_count++;
418 element = priv->free_frames.next;
420 return list_entry(element, struct iwl_frame, list);
423 static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
425 memset(frame, 0, sizeof(*frame));
426 list_add(&frame->list, &priv->free_frames);
429 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
430 struct ieee80211_hdr *hdr,
431 const u8 *dest, int left)
434 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
435 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
436 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
439 if (priv->ibss_beacon->len > left)
442 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
444 return priv->ibss_beacon->len;
447 static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
453 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
454 rate_mask = priv->active_rate_basic & 0xF;
456 rate_mask = priv->active_rate_basic & 0xFF0;
458 /* Find lowest valid rate */
459 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
460 i = iwl_rates[i].next_ieee) {
461 if (rate_mask & (1 << i))
462 return iwl_rates[i].plcp;
465 /* No valid rate was found. Assign the lowest one */
466 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
467 return IWL_RATE_1M_PLCP;
469 return IWL_RATE_6M_PLCP;
472 static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
474 struct iwl_frame *frame;
475 unsigned int frame_size;
479 frame = iwl_get_free_frame(priv);
482 IWL_ERROR("Could not obtain free frame buffer for beacon "
487 rate = iwl4965_rate_get_lowest_plcp(priv);
489 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
491 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
494 iwl_free_frame(priv, frame);
499 /******************************************************************************
501 * Misc. internal state and helper functions
503 ******************************************************************************/
505 static void iwl4965_ht_conf(struct iwl_priv *priv,
506 struct ieee80211_bss_conf *bss_conf)
508 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
509 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
510 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
512 IWL_DEBUG_MAC80211("enter: \n");
514 iwl_conf->is_ht = bss_conf->assoc_ht;
516 if (!iwl_conf->is_ht)
519 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
521 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
522 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
523 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
524 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
526 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
527 iwl_conf->max_amsdu_size =
528 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
530 iwl_conf->supported_chan_width =
531 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
532 iwl_conf->extension_chan_offset =
533 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
534 /* If no above or below channel supplied disable FAT channel */
535 if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE &&
536 iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) {
537 iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE;
538 iwl_conf->supported_chan_width = 0;
541 iwl_conf->tx_mimo_ps_mode =
542 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
543 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
545 iwl_conf->control_channel = ht_bss_conf->primary_channel;
546 iwl_conf->tx_chan_width =
547 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
548 iwl_conf->ht_protection =
549 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
550 iwl_conf->non_GF_STA_present =
551 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
553 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
554 IWL_DEBUG_MAC80211("leave\n");
560 static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
561 struct iwl4965_qosparam_cmd *qos)
564 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
565 sizeof(struct iwl4965_qosparam_cmd), qos);
568 static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
572 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
575 if (!priv->qos_data.qos_enable)
578 spin_lock_irqsave(&priv->lock, flags);
579 priv->qos_data.def_qos_parm.qos_flags = 0;
581 if (priv->qos_data.qos_cap.q_AP.queue_request &&
582 !priv->qos_data.qos_cap.q_AP.txop_request)
583 priv->qos_data.def_qos_parm.qos_flags |=
584 QOS_PARAM_FLG_TXOP_TYPE_MSK;
585 if (priv->qos_data.qos_active)
586 priv->qos_data.def_qos_parm.qos_flags |=
587 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
589 if (priv->current_ht_config.is_ht)
590 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
592 spin_unlock_irqrestore(&priv->lock, flags);
594 if (force || iwl_is_associated(priv)) {
595 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
596 priv->qos_data.qos_active,
597 priv->qos_data.def_qos_parm.qos_flags);
599 iwl4965_send_qos_params_command(priv,
600 &(priv->qos_data.def_qos_parm));
604 int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
606 /* Filter incoming packets to determine if they are targeted toward
607 * this network, discarding packets coming from ourselves */
608 switch (priv->iw_mode) {
609 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
610 /* packets from our adapter are dropped (echo) */
611 if (!compare_ether_addr(header->addr2, priv->mac_addr))
613 /* {broad,multi}cast packets to our IBSS go through */
614 if (is_multicast_ether_addr(header->addr1))
615 return !compare_ether_addr(header->addr3, priv->bssid);
616 /* packets to our adapter go through */
617 return !compare_ether_addr(header->addr1, priv->mac_addr);
618 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
619 /* packets from our adapter are dropped (echo) */
620 if (!compare_ether_addr(header->addr3, priv->mac_addr))
622 /* {broad,multi}cast packets to our BSS go through */
623 if (is_multicast_ether_addr(header->addr1))
624 return !compare_ether_addr(header->addr2, priv->bssid);
625 /* packets to our adapter go through */
626 return !compare_ether_addr(header->addr1, priv->mac_addr);
634 static void iwl4965_sequence_reset(struct iwl_priv *priv)
636 /* Reset ieee stats */
638 /* We don't reset the net_device_stats (ieee->stats) on
641 priv->last_seq_num = -1;
642 priv->last_frag_num = -1;
643 priv->last_packet_time = 0;
645 iwl_scan_cancel(priv);
648 #define MAX_UCODE_BEACON_INTERVAL 4096
649 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
651 static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
654 u16 beacon_factor = 0;
657 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
658 / MAX_UCODE_BEACON_INTERVAL;
659 new_val = beacon_val / beacon_factor;
661 return cpu_to_le16(new_val);
664 static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
666 u64 interval_tm_unit;
669 struct ieee80211_conf *conf = NULL;
672 conf = ieee80211_get_hw_conf(priv->hw);
674 spin_lock_irqsave(&priv->lock, flags);
675 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
676 priv->rxon_timing.timestamp.dw[0] =
677 cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
679 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
681 tsf = priv->timestamp;
683 beacon_int = priv->beacon_int;
684 spin_unlock_irqrestore(&priv->lock, flags);
686 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
687 if (beacon_int == 0) {
688 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
689 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
691 priv->rxon_timing.beacon_interval =
692 cpu_to_le16(beacon_int);
693 priv->rxon_timing.beacon_interval =
694 iwl4965_adjust_beacon_interval(
695 le16_to_cpu(priv->rxon_timing.beacon_interval));
698 priv->rxon_timing.atim_window = 0;
700 priv->rxon_timing.beacon_interval =
701 iwl4965_adjust_beacon_interval(conf->beacon_int);
702 /* TODO: we need to get atim_window from upper stack
703 * for now we set to 0 */
704 priv->rxon_timing.atim_window = 0;
708 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
709 result = do_div(tsf, interval_tm_unit);
710 priv->rxon_timing.beacon_init_val =
711 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
714 ("beacon interval %d beacon timer %d beacon tim %d\n",
715 le16_to_cpu(priv->rxon_timing.beacon_interval),
716 le32_to_cpu(priv->rxon_timing.beacon_init_val),
717 le16_to_cpu(priv->rxon_timing.atim_window));
720 static void iwl_set_flags_for_band(struct iwl_priv *priv,
721 enum ieee80211_band band)
723 if (band == IEEE80211_BAND_5GHZ) {
724 priv->staging_rxon.flags &=
725 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
727 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
729 /* Copied from iwl4965_post_associate() */
730 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
731 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
733 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
735 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
736 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
738 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
739 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
740 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
745 * initialize rxon structure with default values from eeprom
747 static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
749 const struct iwl_channel_info *ch_info;
751 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
753 switch (priv->iw_mode) {
754 case IEEE80211_IF_TYPE_AP:
755 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
758 case IEEE80211_IF_TYPE_STA:
759 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
760 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
763 case IEEE80211_IF_TYPE_IBSS:
764 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
765 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
766 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
767 RXON_FILTER_ACCEPT_GRP_MSK;
770 case IEEE80211_IF_TYPE_MNTR:
771 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
772 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
773 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
776 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
781 /* TODO: Figure out when short_preamble would be set and cache from
783 if (!hw_to_local(priv->hw)->short_preamble)
784 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
786 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
789 ch_info = iwl_get_channel_info(priv, priv->band,
790 le16_to_cpu(priv->staging_rxon.channel));
793 ch_info = &priv->channel_info[0];
796 * in some case A channels are all non IBSS
797 * in this case force B/G channel
799 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
800 !(is_channel_ibss(ch_info)))
801 ch_info = &priv->channel_info[0];
803 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
804 priv->band = ch_info->band;
806 iwl_set_flags_for_band(priv, priv->band);
808 priv->staging_rxon.ofdm_basic_rates =
809 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
810 priv->staging_rxon.cck_basic_rates =
811 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
813 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
814 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
815 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
816 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
817 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
818 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
819 iwl_set_rxon_chain(priv);
822 static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
824 priv->iw_mode = mode;
826 /* init channel/phymode to values given at driver init */
827 iwl_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
829 iwl4965_connection_init_rx_config(priv);
830 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
832 iwlcore_clear_stations_table(priv);
834 /* dont commit rxon if rf-kill is on*/
835 if (!iwl_is_ready_rf(priv))
838 cancel_delayed_work(&priv->scan_check);
839 if (iwl_scan_cancel_timeout(priv, 100)) {
840 IWL_WARNING("Aborted scan still in progress after 100ms\n");
841 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
845 iwl4965_commit_rxon(priv);
850 static void iwl4965_set_rate(struct iwl_priv *priv)
852 const struct ieee80211_supported_band *hw = NULL;
853 struct ieee80211_rate *rate;
856 hw = iwl_get_hw_mode(priv, priv->band);
858 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
862 priv->active_rate = 0;
863 priv->active_rate_basic = 0;
865 for (i = 0; i < hw->n_bitrates; i++) {
866 rate = &(hw->bitrates[i]);
867 if (rate->hw_value < IWL_RATE_COUNT)
868 priv->active_rate |= (1 << rate->hw_value);
871 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
872 priv->active_rate, priv->active_rate_basic);
875 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
876 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
879 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
880 priv->staging_rxon.cck_basic_rates =
881 ((priv->active_rate_basic &
882 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
884 priv->staging_rxon.cck_basic_rates =
885 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
887 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
888 priv->staging_rxon.ofdm_basic_rates =
889 ((priv->active_rate_basic &
890 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
891 IWL_FIRST_OFDM_RATE) & 0xFF;
893 priv->staging_rxon.ofdm_basic_rates =
894 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
897 #define IWL_PACKET_RETRY_TIME HZ
899 int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
901 u16 sc = le16_to_cpu(header->seq_ctrl);
902 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
903 u16 frag = sc & IEEE80211_SCTL_FRAG;
904 u16 *last_seq, *last_frag;
905 unsigned long *last_time;
907 switch (priv->iw_mode) {
908 case IEEE80211_IF_TYPE_IBSS:{
910 struct iwl4965_ibss_seq *entry = NULL;
911 u8 *mac = header->addr2;
912 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
914 __list_for_each(p, &priv->ibss_mac_hash[index]) {
915 entry = list_entry(p, struct iwl4965_ibss_seq, list);
916 if (!compare_ether_addr(entry->mac, mac))
919 if (p == &priv->ibss_mac_hash[index]) {
920 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
922 IWL_ERROR("Cannot malloc new mac entry\n");
925 memcpy(entry->mac, mac, ETH_ALEN);
926 entry->seq_num = seq;
927 entry->frag_num = frag;
928 entry->packet_time = jiffies;
929 list_add(&entry->list, &priv->ibss_mac_hash[index]);
932 last_seq = &entry->seq_num;
933 last_frag = &entry->frag_num;
934 last_time = &entry->packet_time;
937 case IEEE80211_IF_TYPE_STA:
938 last_seq = &priv->last_seq_num;
939 last_frag = &priv->last_frag_num;
940 last_time = &priv->last_packet_time;
945 if ((*last_seq == seq) &&
946 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
947 if (*last_frag == frag)
949 if (*last_frag + 1 != frag)
950 /* out-of-order fragment */
956 *last_time = jiffies;
963 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
965 #include "iwl-spectrum.h"
967 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
968 #define BEACON_TIME_MASK_HIGH 0xFF000000
969 #define TIME_UNIT 1024
972 * extended beacon time format
973 * time in usec will be changed into a 32-bit value in 8:24 format
974 * the high 1 byte is the beacon counts
975 * the lower 3 bytes is the time in usec within one beacon interval
978 static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
982 u32 interval = beacon_interval * 1024;
984 if (!interval || !usec)
987 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
988 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
990 return (quot << 24) + rem;
993 /* base is usually what we get from ucode with each received frame,
994 * the same as HW timer counter counting down
997 static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
999 u32 base_low = base & BEACON_TIME_MASK_LOW;
1000 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1001 u32 interval = beacon_interval * TIME_UNIT;
1002 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1003 (addon & BEACON_TIME_MASK_HIGH);
1005 if (base_low > addon_low)
1006 res += base_low - addon_low;
1007 else if (base_low < addon_low) {
1008 res += interval + base_low - addon_low;
1013 return cpu_to_le32(res);
1016 static int iwl4965_get_measurement(struct iwl_priv *priv,
1017 struct ieee80211_measurement_params *params,
1020 struct iwl4965_spectrum_cmd spectrum;
1021 struct iwl_rx_packet *res;
1022 struct iwl_host_cmd cmd = {
1023 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1024 .data = (void *)&spectrum,
1025 .meta.flags = CMD_WANT_SKB,
1027 u32 add_time = le64_to_cpu(params->start_time);
1029 int spectrum_resp_status;
1030 int duration = le16_to_cpu(params->duration);
1032 if (iwl_is_associated(priv))
1034 iwl4965_usecs_to_beacons(
1035 le64_to_cpu(params->start_time) - priv->last_tsf,
1036 le16_to_cpu(priv->rxon_timing.beacon_interval));
1038 memset(&spectrum, 0, sizeof(spectrum));
1040 spectrum.channel_count = cpu_to_le16(1);
1042 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1043 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1044 cmd.len = sizeof(spectrum);
1045 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1047 if (iwl_is_associated(priv))
1048 spectrum.start_time =
1049 iwl4965_add_beacon_time(priv->last_beacon_time,
1051 le16_to_cpu(priv->rxon_timing.beacon_interval));
1053 spectrum.start_time = 0;
1055 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1056 spectrum.channels[0].channel = params->channel;
1057 spectrum.channels[0].type = type;
1058 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
1059 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1060 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1062 rc = iwl_send_cmd_sync(priv, &cmd);
1066 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
1067 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1068 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
1072 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1073 switch (spectrum_resp_status) {
1074 case 0: /* Command will be handled */
1075 if (res->u.spectrum.id != 0xff) {
1077 ("Replaced existing measurement: %d\n",
1078 res->u.spectrum.id);
1079 priv->measurement_status &= ~MEASUREMENT_READY;
1081 priv->measurement_status |= MEASUREMENT_ACTIVE;
1085 case 1: /* Command will not be handled */
1090 dev_kfree_skb_any(cmd.meta.u.skb);
1096 /******************************************************************************
1098 * Generic RX handler implementations
1100 ******************************************************************************/
1101 static void iwl_rx_reply_alive(struct iwl_priv *priv,
1102 struct iwl_rx_mem_buffer *rxb)
1104 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1105 struct iwl_alive_resp *palive;
1106 struct delayed_work *pwork;
1108 palive = &pkt->u.alive_frame;
1110 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1112 palive->is_valid, palive->ver_type,
1113 palive->ver_subtype);
1115 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1116 IWL_DEBUG_INFO("Initialization Alive received.\n");
1117 memcpy(&priv->card_alive_init,
1118 &pkt->u.alive_frame,
1119 sizeof(struct iwl_init_alive_resp));
1120 pwork = &priv->init_alive_start;
1122 IWL_DEBUG_INFO("Runtime Alive received.\n");
1123 memcpy(&priv->card_alive, &pkt->u.alive_frame,
1124 sizeof(struct iwl_alive_resp));
1125 pwork = &priv->alive_start;
1128 /* We delay the ALIVE response by 5ms to
1129 * give the HW RF Kill time to activate... */
1130 if (palive->is_valid == UCODE_VALID_OK)
1131 queue_delayed_work(priv->workqueue, pwork,
1132 msecs_to_jiffies(5));
1134 IWL_WARNING("uCode did not respond OK.\n");
1137 static void iwl4965_rx_reply_error(struct iwl_priv *priv,
1138 struct iwl_rx_mem_buffer *rxb)
1140 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1142 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1143 "seq 0x%04X ser 0x%08X\n",
1144 le32_to_cpu(pkt->u.err_resp.error_type),
1145 get_cmd_string(pkt->u.err_resp.cmd_id),
1146 pkt->u.err_resp.cmd_id,
1147 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1148 le32_to_cpu(pkt->u.err_resp.error_info));
1151 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1153 static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1155 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1156 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
1157 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
1158 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1159 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1160 rxon->channel = csa->channel;
1161 priv->staging_rxon.channel = csa->channel;
1164 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
1165 struct iwl_rx_mem_buffer *rxb)
1167 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
1168 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1169 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
1171 if (!report->state) {
1172 IWL_DEBUG(IWL_DL_11H,
1173 "Spectrum Measure Notification: Start\n");
1177 memcpy(&priv->measure_report, report, sizeof(*report));
1178 priv->measurement_status |= MEASUREMENT_READY;
1182 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
1183 struct iwl_rx_mem_buffer *rxb)
1185 #ifdef CONFIG_IWLWIFI_DEBUG
1186 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1187 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
1188 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1189 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1193 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
1194 struct iwl_rx_mem_buffer *rxb)
1196 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1197 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1198 "notification for %s:\n",
1199 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
1200 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
1203 static void iwl4965_bg_beacon_update(struct work_struct *work)
1205 struct iwl_priv *priv =
1206 container_of(work, struct iwl_priv, beacon_update);
1207 struct sk_buff *beacon;
1209 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
1210 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
1213 IWL_ERROR("update beacon failed\n");
1217 mutex_lock(&priv->mutex);
1218 /* new beacon skb is allocated every time; dispose previous.*/
1219 if (priv->ibss_beacon)
1220 dev_kfree_skb(priv->ibss_beacon);
1222 priv->ibss_beacon = beacon;
1223 mutex_unlock(&priv->mutex);
1225 iwl4965_send_beacon_cmd(priv);
1229 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
1231 * This callback is provided in order to send a statistics request.
1233 * This timer function is continually reset to execute within
1234 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1235 * was received. We need to ensure we receive the statistics in order
1236 * to update the temperature used for calibrating the TXPOWER.
1238 static void iwl4965_bg_statistics_periodic(unsigned long data)
1240 struct iwl_priv *priv = (struct iwl_priv *)data;
1242 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1245 iwl_send_statistics_request(priv, CMD_ASYNC);
1248 static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
1249 struct iwl_rx_mem_buffer *rxb)
1251 #ifdef CONFIG_IWLWIFI_DEBUG
1252 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1253 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
1254 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
1256 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1257 "tsf %d %d rate %d\n",
1258 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
1259 beacon->beacon_notify_hdr.failure_frame,
1260 le32_to_cpu(beacon->ibss_mgr_status),
1261 le32_to_cpu(beacon->high_tsf),
1262 le32_to_cpu(beacon->low_tsf), rate);
1265 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
1266 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1267 queue_work(priv->workqueue, &priv->beacon_update);
1270 /* Handle notification from uCode that card's power state is changing
1271 * due to software, hardware, or critical temperature RFKILL */
1272 static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
1273 struct iwl_rx_mem_buffer *rxb)
1275 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1276 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1277 unsigned long status = priv->status;
1279 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1280 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1281 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1283 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1284 RF_CARD_DISABLED)) {
1286 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
1287 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1289 if (!iwl_grab_nic_access(priv)) {
1291 priv, HBUS_TARG_MBX_C,
1292 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1294 iwl_release_nic_access(priv);
1297 if (!(flags & RXON_CARD_DISABLED)) {
1298 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
1299 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1300 if (!iwl_grab_nic_access(priv)) {
1302 priv, HBUS_TARG_MBX_C,
1303 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1305 iwl_release_nic_access(priv);
1309 if (flags & RF_CARD_DISABLED) {
1310 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
1311 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1312 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1313 if (!iwl_grab_nic_access(priv))
1314 iwl_release_nic_access(priv);
1318 if (flags & HW_CARD_DISABLED)
1319 set_bit(STATUS_RF_KILL_HW, &priv->status);
1321 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1324 if (flags & SW_CARD_DISABLED)
1325 set_bit(STATUS_RF_KILL_SW, &priv->status);
1327 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1329 if (!(flags & RXON_CARD_DISABLED))
1330 iwl_scan_cancel(priv);
1332 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1333 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1334 (test_bit(STATUS_RF_KILL_SW, &status) !=
1335 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1336 queue_work(priv->workqueue, &priv->rf_kill);
1338 wake_up_interruptible(&priv->wait_command_queue);
1341 /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
1342 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
1343 static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
1344 struct iwl_rx_mem_buffer *rxb)
1346 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1347 priv->last_phy_res[0] = 1;
1348 memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
1349 sizeof(struct iwl4965_rx_phy_res));
1353 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
1355 * Setup the RX handlers for each of the reply types sent from the uCode
1358 * This function chains into the hardware specific files for them to setup
1359 * any hardware specific handlers as well.
1361 static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
1363 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
1364 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
1365 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
1366 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
1367 iwl4965_rx_spectrum_measure_notif;
1368 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
1369 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
1370 iwl4965_rx_pm_debug_statistics_notif;
1371 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
1374 * The same handler is used for both the REPLY to a discrete
1375 * statistics request from the host as well as for the periodic
1376 * statistics notifications (after received beacons) from the uCode.
1378 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
1379 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
1381 iwl_setup_rx_scan_handlers(priv);
1383 /* status change handler */
1384 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
1386 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1387 iwl_rx_missed_beacon_notif;
1389 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
1390 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
1391 /* Set up hardware specific Rx handlers */
1392 priv->cfg->ops->lib->rx_handler_setup(priv);
1396 * this should be called while priv->lock is locked
1398 static void __iwl_rx_replenish(struct iwl_priv *priv)
1400 iwl_rx_allocate(priv);
1401 iwl_rx_queue_restock(priv);
1406 * iwl_rx_handle - Main entry function for receiving responses from uCode
1408 * Uses the priv->rx_handlers callback function array to invoke
1409 * the appropriate handlers, including command responses,
1410 * frame-received notifications, and other notifications.
1412 void iwl_rx_handle(struct iwl_priv *priv)
1414 struct iwl_rx_mem_buffer *rxb;
1415 struct iwl_rx_packet *pkt;
1416 struct iwl_rx_queue *rxq = &priv->rxq;
1419 unsigned long flags;
1423 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1424 * buffer that the driver may process (last buffer filled by ucode). */
1425 r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
1428 /* Rx interrupt, but nothing sent from uCode */
1430 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
1432 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
1436 rxb = rxq->queue[i];
1438 /* If an RXB doesn't have a Rx queue slot associated with it,
1439 * then a bug has been introduced in the queue refilling
1440 * routines -- catch it here */
1441 BUG_ON(rxb == NULL);
1443 rxq->queue[i] = NULL;
1445 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
1446 priv->hw_params.rx_buf_size,
1447 PCI_DMA_FROMDEVICE);
1448 pkt = (struct iwl_rx_packet *)rxb->skb->data;
1450 /* Reclaim a command buffer only if this packet is a response
1451 * to a (driver-originated) command.
1452 * If the packet (e.g. Rx frame) originated from uCode,
1453 * there is no command buffer to reclaim.
1454 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1455 * but apparently a few don't get set; catch them here. */
1456 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1457 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
1458 (pkt->hdr.cmd != REPLY_RX) &&
1459 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
1460 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1461 (pkt->hdr.cmd != REPLY_TX);
1463 /* Based on type of command response or notification,
1464 * handle those that need handling via function in
1465 * rx_handlers table. See iwl4965_setup_rx_handlers() */
1466 if (priv->rx_handlers[pkt->hdr.cmd]) {
1467 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1468 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1469 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1471 /* No handling needed */
1472 IWL_DEBUG(IWL_DL_RX,
1473 "r %d i %d No handler needed for %s, 0x%02x\n",
1474 r, i, get_cmd_string(pkt->hdr.cmd),
1479 /* Invoke any callbacks, transfer the skb to caller, and
1480 * fire off the (possibly) blocking iwl_send_cmd()
1481 * as we reclaim the driver command queue */
1482 if (rxb && rxb->skb)
1483 iwl_tx_cmd_complete(priv, rxb);
1485 IWL_WARNING("Claim null rxb?\n");
1488 /* For now we just don't re-use anything. We can tweak this
1489 * later to try and re-use notification packets and SKBs that
1490 * fail to Rx correctly */
1491 if (rxb->skb != NULL) {
1492 priv->alloc_rxb_skb--;
1493 dev_kfree_skb_any(rxb->skb);
1497 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
1498 priv->hw_params.rx_buf_size,
1499 PCI_DMA_FROMDEVICE);
1500 spin_lock_irqsave(&rxq->lock, flags);
1501 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1502 spin_unlock_irqrestore(&rxq->lock, flags);
1503 i = (i + 1) & RX_QUEUE_MASK;
1504 /* If there are a lot of unused frames,
1505 * restock the Rx queue so ucode wont assert. */
1510 __iwl_rx_replenish(priv);
1516 /* Backtrack one entry */
1518 iwl_rx_queue_restock(priv);
1521 #define PERFECT_RSSI (-20) /* dBm */
1522 #define WORST_RSSI (-95) /* dBm */
1523 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1525 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
1526 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1527 * about formulas used below. */
1528 int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
1531 int degradation = PERFECT_RSSI - rssi_dbm;
1533 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1534 * as indicator; formula is (signal dbm - noise dbm).
1535 * SNR at or above 40 is a great signal (100%).
1536 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1537 * Weakest usable signal is usually 10 - 15 dB SNR. */
1539 if (rssi_dbm - noise_dbm >= 40)
1541 else if (rssi_dbm < noise_dbm)
1543 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1545 /* Else use just the signal level.
1546 * This formula is a least squares fit of data points collected and
1547 * compared with a reference system that had a percentage (%) display
1548 * for signal quality. */
1550 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1551 (15 * RSSI_RANGE + 62 * degradation)) /
1552 (RSSI_RANGE * RSSI_RANGE);
1556 else if (sig_qual < 1)
1562 #ifdef CONFIG_IWLWIFI_DEBUG
1563 static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
1565 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
1566 DECLARE_MAC_BUF(mac);
1568 IWL_DEBUG_RADIO("RX CONFIG:\n");
1569 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
1570 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1571 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1572 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1573 le32_to_cpu(rxon->filter_flags));
1574 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1575 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1576 rxon->ofdm_basic_rates);
1577 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
1578 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
1579 print_mac(mac, rxon->node_addr));
1580 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
1581 print_mac(mac, rxon->bssid_addr));
1582 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1586 static void iwl4965_enable_interrupts(struct iwl_priv *priv)
1588 IWL_DEBUG_ISR("Enabling interrupts\n");
1589 set_bit(STATUS_INT_ENABLED, &priv->status);
1590 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
1593 /* call this function to flush any scheduled tasklet */
1594 static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1596 /* wait to make sure we flush pedding tasklet*/
1597 synchronize_irq(priv->pci_dev->irq);
1598 tasklet_kill(&priv->irq_tasklet);
1601 static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
1603 clear_bit(STATUS_INT_ENABLED, &priv->status);
1605 /* disable interrupts from uCode/NIC to host */
1606 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1608 /* acknowledge/clear/reset any interrupts still pending
1609 * from uCode or flow handler (Rx/Tx DMA) */
1610 iwl_write32(priv, CSR_INT, 0xffffffff);
1611 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
1612 IWL_DEBUG_ISR("Disabled interrupts\n");
1617 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
1619 static void iwl4965_irq_handle_error(struct iwl_priv *priv)
1621 /* Set the FW error flag -- cleared on iwl4965_down */
1622 set_bit(STATUS_FW_ERROR, &priv->status);
1624 /* Cancel currently queued command. */
1625 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1627 #ifdef CONFIG_IWLWIFI_DEBUG
1628 if (priv->debug_level & IWL_DL_FW_ERRORS) {
1629 iwl_dump_nic_error_log(priv);
1630 iwl_dump_nic_event_log(priv);
1631 iwl4965_print_rx_config_cmd(priv);
1635 wake_up_interruptible(&priv->wait_command_queue);
1637 /* Keep the restart process from trying to send host
1638 * commands by clearing the INIT status bit */
1639 clear_bit(STATUS_READY, &priv->status);
1641 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
1642 IWL_DEBUG(IWL_DL_FW_ERRORS,
1643 "Restarting adapter due to uCode error.\n");
1645 if (iwl_is_associated(priv)) {
1646 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1647 sizeof(priv->recovery_rxon));
1648 priv->error_recovering = 1;
1650 if (priv->cfg->mod_params->restart_fw)
1651 queue_work(priv->workqueue, &priv->restart);
1655 static void iwl4965_error_recovery(struct iwl_priv *priv)
1657 unsigned long flags;
1659 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1660 sizeof(priv->staging_rxon));
1661 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1662 iwl4965_commit_rxon(priv);
1664 iwl_rxon_add_station(priv, priv->bssid, 1);
1666 spin_lock_irqsave(&priv->lock, flags);
1667 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1668 priv->error_recovering = 0;
1669 spin_unlock_irqrestore(&priv->lock, flags);
1672 static void iwl4965_irq_tasklet(struct iwl_priv *priv)
1674 u32 inta, handled = 0;
1676 unsigned long flags;
1677 #ifdef CONFIG_IWLWIFI_DEBUG
1681 spin_lock_irqsave(&priv->lock, flags);
1683 /* Ack/clear/reset pending uCode interrupts.
1684 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1685 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
1686 inta = iwl_read32(priv, CSR_INT);
1687 iwl_write32(priv, CSR_INT, inta);
1689 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1690 * Any new interrupts that happen after this, either while we're
1691 * in this tasklet, or later, will show up in next ISR/tasklet. */
1692 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1693 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
1695 #ifdef CONFIG_IWLWIFI_DEBUG
1696 if (priv->debug_level & IWL_DL_ISR) {
1697 /* just for debug */
1698 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1699 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1700 inta, inta_mask, inta_fh);
1704 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1705 * atomic, make sure that inta covers all the interrupts that
1706 * we've discovered, even if FH interrupt came in just after
1707 * reading CSR_INT. */
1708 if (inta_fh & CSR49_FH_INT_RX_MASK)
1709 inta |= CSR_INT_BIT_FH_RX;
1710 if (inta_fh & CSR49_FH_INT_TX_MASK)
1711 inta |= CSR_INT_BIT_FH_TX;
1713 /* Now service all interrupt bits discovered above. */
1714 if (inta & CSR_INT_BIT_HW_ERR) {
1715 IWL_ERROR("Microcode HW error detected. Restarting.\n");
1717 /* Tell the device to stop sending interrupts */
1718 iwl4965_disable_interrupts(priv);
1720 iwl4965_irq_handle_error(priv);
1722 handled |= CSR_INT_BIT_HW_ERR;
1724 spin_unlock_irqrestore(&priv->lock, flags);
1729 #ifdef CONFIG_IWLWIFI_DEBUG
1730 if (priv->debug_level & (IWL_DL_ISR)) {
1731 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1732 if (inta & CSR_INT_BIT_SCD)
1733 IWL_DEBUG_ISR("Scheduler finished to transmit "
1734 "the frame/frames.\n");
1736 /* Alive notification via Rx interrupt will do the real work */
1737 if (inta & CSR_INT_BIT_ALIVE)
1738 IWL_DEBUG_ISR("Alive interrupt\n");
1741 /* Safely ignore these bits for debug checks below */
1742 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1744 /* HW RF KILL switch toggled */
1745 if (inta & CSR_INT_BIT_RF_KILL) {
1747 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
1748 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1751 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
1752 hw_rf_kill ? "disable radio":"enable radio");
1754 /* Queue restart only if RF_KILL switch was set to "kill"
1755 * when we loaded driver, and is now set to "enable".
1756 * After we're Alive, RF_KILL gets handled by
1757 * iwl4965_rx_card_state_notif() */
1758 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
1759 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1760 queue_work(priv->workqueue, &priv->restart);
1763 handled |= CSR_INT_BIT_RF_KILL;
1766 /* Chip got too hot and stopped itself */
1767 if (inta & CSR_INT_BIT_CT_KILL) {
1768 IWL_ERROR("Microcode CT kill error detected.\n");
1769 handled |= CSR_INT_BIT_CT_KILL;
1772 /* Error detected by uCode */
1773 if (inta & CSR_INT_BIT_SW_ERR) {
1774 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
1776 iwl4965_irq_handle_error(priv);
1777 handled |= CSR_INT_BIT_SW_ERR;
1780 /* uCode wakes up after power-down sleep */
1781 if (inta & CSR_INT_BIT_WAKEUP) {
1782 IWL_DEBUG_ISR("Wakeup interrupt\n");
1783 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
1784 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1785 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1786 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1787 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1788 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1789 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
1791 handled |= CSR_INT_BIT_WAKEUP;
1794 /* All uCode command responses, including Tx command responses,
1795 * Rx "responses" (frame-received notification), and other
1796 * notifications from uCode come through here*/
1797 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1798 iwl_rx_handle(priv);
1799 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1802 if (inta & CSR_INT_BIT_FH_TX) {
1803 IWL_DEBUG_ISR("Tx interrupt\n");
1804 handled |= CSR_INT_BIT_FH_TX;
1805 /* FH finished to write, send event */
1806 priv->ucode_write_complete = 1;
1807 wake_up_interruptible(&priv->wait_command_queue);
1810 if (inta & ~handled)
1811 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1813 if (inta & ~CSR_INI_SET_MASK) {
1814 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
1815 inta & ~CSR_INI_SET_MASK);
1816 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
1819 /* Re-enable all interrupts */
1820 /* only Re-enable if diabled by irq */
1821 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1822 iwl4965_enable_interrupts(priv);
1824 #ifdef CONFIG_IWLWIFI_DEBUG
1825 if (priv->debug_level & (IWL_DL_ISR)) {
1826 inta = iwl_read32(priv, CSR_INT);
1827 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1828 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1829 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1830 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1833 spin_unlock_irqrestore(&priv->lock, flags);
1836 static irqreturn_t iwl4965_isr(int irq, void *data)
1838 struct iwl_priv *priv = data;
1839 u32 inta, inta_mask;
1844 spin_lock(&priv->lock);
1846 /* Disable (but don't clear!) interrupts here to avoid
1847 * back-to-back ISRs and sporadic interrupts from our NIC.
1848 * If we have something to service, the tasklet will re-enable ints.
1849 * If we *don't* have something, we'll re-enable before leaving here. */
1850 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1851 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1853 /* Discover which interrupts are active/pending */
1854 inta = iwl_read32(priv, CSR_INT);
1855 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1857 /* Ignore interrupt if there's nothing in NIC to service.
1858 * This may be due to IRQ shared with another device,
1859 * or due to sporadic interrupts thrown from our NIC. */
1860 if (!inta && !inta_fh) {
1861 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1865 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1866 /* Hardware disappeared. It might have already raised
1868 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
1872 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1873 inta, inta_mask, inta_fh);
1875 inta &= ~CSR_INT_BIT_SCD;
1877 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
1878 if (likely(inta || inta_fh))
1879 tasklet_schedule(&priv->irq_tasklet);
1882 spin_unlock(&priv->lock);
1886 /* re-enable interrupts here since we don't have anything to service. */
1887 /* only Re-enable if diabled by irq */
1888 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1889 iwl4965_enable_interrupts(priv);
1890 spin_unlock(&priv->lock);
1894 /******************************************************************************
1896 * uCode download functions
1898 ******************************************************************************/
1900 static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
1902 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1903 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1904 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1905 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1906 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1907 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
1910 static void iwl4965_nic_start(struct iwl_priv *priv)
1912 /* Remove all resets to allow NIC to operate */
1913 iwl_write32(priv, CSR_RESET, 0);
1918 * iwl4965_read_ucode - Read uCode images from disk file.
1920 * Copy into buffers for card to fetch via bus-mastering
1922 static int iwl4965_read_ucode(struct iwl_priv *priv)
1924 struct iwl_ucode *ucode;
1926 const struct firmware *ucode_raw;
1927 const char *name = priv->cfg->fw_name;
1930 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
1932 /* Ask kernel firmware_class module to get the boot firmware off disk.
1933 * request_firmware() is synchronous, file is in memory on return. */
1934 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
1936 IWL_ERROR("%s firmware file req failed: Reason %d\n",
1941 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1942 name, ucode_raw->size);
1944 /* Make sure that we got at least our header! */
1945 if (ucode_raw->size < sizeof(*ucode)) {
1946 IWL_ERROR("File size way too small!\n");
1951 /* Data from ucode file: header followed by uCode images */
1952 ucode = (void *)ucode_raw->data;
1954 ver = le32_to_cpu(ucode->ver);
1955 inst_size = le32_to_cpu(ucode->inst_size);
1956 data_size = le32_to_cpu(ucode->data_size);
1957 init_size = le32_to_cpu(ucode->init_size);
1958 init_data_size = le32_to_cpu(ucode->init_data_size);
1959 boot_size = le32_to_cpu(ucode->boot_size);
1961 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
1962 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1964 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1966 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1968 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1970 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1973 /* Verify size of file vs. image size info in file's header */
1974 if (ucode_raw->size < sizeof(*ucode) +
1975 inst_size + data_size + init_size +
1976 init_data_size + boot_size) {
1978 IWL_DEBUG_INFO("uCode file size %d too small\n",
1979 (int)ucode_raw->size);
1984 /* Verify that uCode images will fit in card's SRAM */
1985 if (inst_size > priv->hw_params.max_inst_size) {
1986 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1992 if (data_size > priv->hw_params.max_data_size) {
1993 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1998 if (init_size > priv->hw_params.max_inst_size) {
2000 ("uCode init instr len %d too large to fit in\n",
2005 if (init_data_size > priv->hw_params.max_data_size) {
2007 ("uCode init data len %d too large to fit in\n",
2012 if (boot_size > priv->hw_params.max_bsm_size) {
2014 ("uCode boot instr len %d too large to fit in\n",
2020 /* Allocate ucode buffers for card's bus-master loading ... */
2022 /* Runtime instructions and 2 copies of data:
2023 * 1) unmodified from disk
2024 * 2) backup cache for save/restore during power-downs */
2025 priv->ucode_code.len = inst_size;
2026 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
2028 priv->ucode_data.len = data_size;
2029 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
2031 priv->ucode_data_backup.len = data_size;
2032 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2034 /* Initialization instructions and data */
2035 if (init_size && init_data_size) {
2036 priv->ucode_init.len = init_size;
2037 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
2039 priv->ucode_init_data.len = init_data_size;
2040 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2042 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2046 /* Bootstrap (instructions only, no data) */
2048 priv->ucode_boot.len = boot_size;
2049 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
2051 if (!priv->ucode_boot.v_addr)
2055 /* Copy images into buffers for card's bus-master reads ... */
2057 /* Runtime instructions (first block of data in file) */
2058 src = &ucode->data[0];
2059 len = priv->ucode_code.len;
2060 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
2061 memcpy(priv->ucode_code.v_addr, src, len);
2062 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
2063 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2065 /* Runtime data (2nd block)
2066 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
2067 src = &ucode->data[inst_size];
2068 len = priv->ucode_data.len;
2069 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
2070 memcpy(priv->ucode_data.v_addr, src, len);
2071 memcpy(priv->ucode_data_backup.v_addr, src, len);
2073 /* Initialization instructions (3rd block) */
2075 src = &ucode->data[inst_size + data_size];
2076 len = priv->ucode_init.len;
2077 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
2079 memcpy(priv->ucode_init.v_addr, src, len);
2082 /* Initialization data (4th block) */
2083 if (init_data_size) {
2084 src = &ucode->data[inst_size + data_size + init_size];
2085 len = priv->ucode_init_data.len;
2086 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
2088 memcpy(priv->ucode_init_data.v_addr, src, len);
2091 /* Bootstrap instructions (5th block) */
2092 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2093 len = priv->ucode_boot.len;
2094 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
2095 memcpy(priv->ucode_boot.v_addr, src, len);
2097 /* We have our copies now, allow OS release its copies */
2098 release_firmware(ucode_raw);
2102 IWL_ERROR("failed to allocate pci memory\n");
2104 iwl4965_dealloc_ucode_pci(priv);
2107 release_firmware(ucode_raw);
2114 * iwl_alive_start - called after REPLY_ALIVE notification received
2115 * from protocol/runtime uCode (initialization uCode's
2116 * Alive gets handled by iwl_init_alive_start()).
2118 static void iwl_alive_start(struct iwl_priv *priv)
2122 IWL_DEBUG_INFO("Runtime Alive received.\n");
2124 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2125 /* We had an error bringing up the hardware, so take it
2126 * all the way back down so we can try again */
2127 IWL_DEBUG_INFO("Alive failed.\n");
2131 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2132 * This is a paranoid check, because we would not have gotten the
2133 * "runtime" alive if code weren't properly loaded. */
2134 if (iwl_verify_ucode(priv)) {
2135 /* Runtime instruction load was bad;
2136 * take it all the way back down so we can try again */
2137 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
2141 iwlcore_clear_stations_table(priv);
2142 ret = priv->cfg->ops->lib->alive_notify(priv);
2144 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
2149 /* After the ALIVE response, we can send host commands to 4965 uCode */
2150 set_bit(STATUS_ALIVE, &priv->status);
2152 if (iwl_is_rfkill(priv))
2155 ieee80211_wake_queues(priv->hw);
2157 priv->active_rate = priv->rates_mask;
2158 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2160 if (iwl_is_associated(priv)) {
2161 struct iwl_rxon_cmd *active_rxon =
2162 (struct iwl_rxon_cmd *)&priv->active_rxon;
2164 memcpy(&priv->staging_rxon, &priv->active_rxon,
2165 sizeof(priv->staging_rxon));
2166 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2168 /* Initialize our rx_config data */
2169 iwl4965_connection_init_rx_config(priv);
2170 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2173 /* Configure Bluetooth device coexistence support */
2174 iwl4965_send_bt_config(priv);
2176 iwl_reset_run_time_calib(priv);
2178 /* Configure the adapter for unassociated operation */
2179 iwl4965_commit_rxon(priv);
2181 /* At this point, the NIC is initialized and operational */
2182 iwl_rf_kill_ct_config(priv);
2184 iwl_leds_register(priv);
2186 IWL_DEBUG_INFO("ALIVE processing complete.\n");
2187 set_bit(STATUS_READY, &priv->status);
2188 wake_up_interruptible(&priv->wait_command_queue);
2190 if (priv->error_recovering)
2191 iwl4965_error_recovery(priv);
2193 iwl_power_update_mode(priv, 1);
2194 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
2196 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2197 iwl4965_set_mode(priv, priv->iw_mode);
2202 queue_work(priv->workqueue, &priv->restart);
2205 static void iwl_cancel_deferred_work(struct iwl_priv *priv);
2207 static void __iwl4965_down(struct iwl_priv *priv)
2209 unsigned long flags;
2210 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
2212 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2215 set_bit(STATUS_EXIT_PENDING, &priv->status);
2217 iwl_leds_unregister(priv);
2219 iwlcore_clear_stations_table(priv);
2221 /* Unblock any waiting calls */
2222 wake_up_interruptible_all(&priv->wait_command_queue);
2224 /* Wipe out the EXIT_PENDING status bit if we are not actually
2225 * exiting the module */
2227 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2229 /* stop and reset the on-board processor */
2230 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
2232 /* tell the device to stop sending interrupts */
2233 spin_lock_irqsave(&priv->lock, flags);
2234 iwl4965_disable_interrupts(priv);
2235 spin_unlock_irqrestore(&priv->lock, flags);
2236 iwl_synchronize_irq(priv);
2238 if (priv->mac80211_registered)
2239 ieee80211_stop_queues(priv->hw);
2241 /* If we have not previously called iwl4965_init() then
2242 * clear all bits but the RF Kill and SUSPEND bits and return */
2243 if (!iwl_is_init(priv)) {
2244 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2246 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2248 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2249 STATUS_GEO_CONFIGURED |
2250 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2255 /* ...otherwise clear out all the status bits but the RF Kill and
2256 * SUSPEND bits and continue taking the NIC down. */
2257 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2259 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2261 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2262 STATUS_GEO_CONFIGURED |
2263 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2265 test_bit(STATUS_FW_ERROR, &priv->status) <<
2268 spin_lock_irqsave(&priv->lock, flags);
2269 iwl_clear_bit(priv, CSR_GP_CNTRL,
2270 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2271 spin_unlock_irqrestore(&priv->lock, flags);
2273 iwl_txq_ctx_stop(priv);
2276 spin_lock_irqsave(&priv->lock, flags);
2277 if (!iwl_grab_nic_access(priv)) {
2278 iwl_write_prph(priv, APMG_CLK_DIS_REG,
2279 APMG_CLK_VAL_DMA_CLK_RQT);
2280 iwl_release_nic_access(priv);
2282 spin_unlock_irqrestore(&priv->lock, flags);
2286 /* FIXME: apm_ops.suspend(priv) */
2287 priv->cfg->ops->lib->apm_ops.reset(priv);
2288 priv->cfg->ops->lib->free_shared_mem(priv);
2291 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
2293 if (priv->ibss_beacon)
2294 dev_kfree_skb(priv->ibss_beacon);
2295 priv->ibss_beacon = NULL;
2297 /* clear out any free frames */
2298 iwl_clear_free_frames(priv);
2301 static void iwl4965_down(struct iwl_priv *priv)
2303 mutex_lock(&priv->mutex);
2304 __iwl4965_down(priv);
2305 mutex_unlock(&priv->mutex);
2307 iwl_cancel_deferred_work(priv);
2310 #define MAX_HW_RESTARTS 5
2312 static int __iwl4965_up(struct iwl_priv *priv)
2317 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2318 IWL_WARNING("Exit pending; will not bring the NIC up\n");
2322 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
2323 IWL_ERROR("ucode not available for device bringup\n");
2327 /* If platform's RF_KILL switch is NOT set to KILL */
2328 if (iwl_read32(priv, CSR_GP_CNTRL) &
2329 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2330 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2332 set_bit(STATUS_RF_KILL_HW, &priv->status);
2333 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
2334 iwl_rfkill_set_hw_state(priv);
2335 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
2340 iwl_rfkill_set_hw_state(priv);
2341 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2343 ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
2345 IWL_ERROR("Unable to allocate shared memory\n");
2349 ret = iwl_hw_nic_init(priv);
2351 IWL_ERROR("Unable to init nic\n");
2355 /* make sure rfkill handshake bits are cleared */
2356 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2357 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2358 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2360 /* clear (again), then enable host interrupts */
2361 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2362 iwl4965_enable_interrupts(priv);
2364 /* really make sure rfkill handshake bits are cleared */
2365 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2366 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2368 /* Copy original ucode data image from disk into backup cache.
2369 * This will be used to initialize the on-board processor's
2370 * data SRAM for a clean start when the runtime program first loads. */
2371 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
2372 priv->ucode_data.len);
2374 /* We return success when we resume from suspend and rf_kill is on. */
2375 if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
2376 test_bit(STATUS_RF_KILL_SW, &priv->status))
2379 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2381 iwlcore_clear_stations_table(priv);
2383 /* load bootstrap state machine,
2384 * load bootstrap program into processor's memory,
2385 * prepare to load the "initialize" uCode */
2386 ret = priv->cfg->ops->lib->load_ucode(priv);
2389 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
2393 /* Clear out the uCode error bit if it is set */
2394 clear_bit(STATUS_FW_ERROR, &priv->status);
2396 /* start card; "initialize" will load runtime ucode */
2397 iwl4965_nic_start(priv);
2399 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2404 set_bit(STATUS_EXIT_PENDING, &priv->status);
2405 __iwl4965_down(priv);
2406 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2408 /* tried to restart and config the device for as long as our
2409 * patience could withstand */
2410 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
2415 /*****************************************************************************
2417 * Workqueue callbacks
2419 *****************************************************************************/
2421 static void iwl_bg_init_alive_start(struct work_struct *data)
2423 struct iwl_priv *priv =
2424 container_of(data, struct iwl_priv, init_alive_start.work);
2426 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2429 mutex_lock(&priv->mutex);
2430 priv->cfg->ops->lib->init_alive_start(priv);
2431 mutex_unlock(&priv->mutex);
2434 static void iwl_bg_alive_start(struct work_struct *data)
2436 struct iwl_priv *priv =
2437 container_of(data, struct iwl_priv, alive_start.work);
2439 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2442 mutex_lock(&priv->mutex);
2443 iwl_alive_start(priv);
2444 mutex_unlock(&priv->mutex);
2447 static void iwl4965_bg_rf_kill(struct work_struct *work)
2449 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
2451 wake_up_interruptible(&priv->wait_command_queue);
2453 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2456 mutex_lock(&priv->mutex);
2458 if (!iwl_is_rfkill(priv)) {
2459 IWL_DEBUG(IWL_DL_RF_KILL,
2460 "HW and/or SW RF Kill no longer active, restarting "
2462 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
2463 queue_work(priv->workqueue, &priv->restart);
2465 /* make sure mac80211 stop sending Tx frame */
2466 if (priv->mac80211_registered)
2467 ieee80211_stop_queues(priv->hw);
2469 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
2470 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2471 "disabled by SW switch\n");
2473 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
2474 "Kill switch must be turned off for "
2475 "wireless networking to work.\n");
2477 iwl_rfkill_set_hw_state(priv);
2479 mutex_unlock(&priv->mutex);
2482 static void iwl4965_bg_set_monitor(struct work_struct *work)
2484 struct iwl_priv *priv = container_of(work,
2485 struct iwl_priv, set_monitor);
2488 IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
2490 mutex_lock(&priv->mutex);
2492 ret = iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR);
2496 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
2498 IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret);
2501 mutex_unlock(&priv->mutex);
2504 static void iwl_bg_run_time_calib_work(struct work_struct *work)
2506 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2507 run_time_calib_work);
2509 mutex_lock(&priv->mutex);
2511 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2512 test_bit(STATUS_SCANNING, &priv->status)) {
2513 mutex_unlock(&priv->mutex);
2517 if (priv->start_calib) {
2518 iwl_chain_noise_calibration(priv, &priv->statistics);
2520 iwl_sensitivity_calibration(priv, &priv->statistics);
2523 mutex_unlock(&priv->mutex);
2527 static void iwl4965_bg_up(struct work_struct *data)
2529 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
2531 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2534 mutex_lock(&priv->mutex);
2536 mutex_unlock(&priv->mutex);
2539 static void iwl4965_bg_restart(struct work_struct *data)
2541 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
2543 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2547 queue_work(priv->workqueue, &priv->up);
2550 static void iwl4965_bg_rx_replenish(struct work_struct *data)
2552 struct iwl_priv *priv =
2553 container_of(data, struct iwl_priv, rx_replenish);
2555 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2558 mutex_lock(&priv->mutex);
2559 iwl_rx_replenish(priv);
2560 mutex_unlock(&priv->mutex);
2563 #define IWL_DELAY_NEXT_SCAN (HZ*2)
2565 static void iwl4965_post_associate(struct iwl_priv *priv)
2567 struct ieee80211_conf *conf = NULL;
2569 DECLARE_MAC_BUF(mac);
2571 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2572 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
2576 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
2578 print_mac(mac, priv->active_rxon.bssid_addr));
2581 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2585 if (!priv->vif || !priv->is_open)
2588 iwl_scan_cancel_timeout(priv, 200);
2590 conf = ieee80211_get_hw_conf(priv->hw);
2592 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2593 iwl4965_commit_rxon(priv);
2595 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2596 iwl4965_setup_rxon_timing(priv);
2597 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
2598 sizeof(priv->rxon_timing), &priv->rxon_timing);
2600 IWL_WARNING("REPLY_RXON_TIMING failed - "
2601 "Attempting to continue.\n");
2603 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2605 if (priv->current_ht_config.is_ht)
2606 iwl_set_rxon_ht(priv, &priv->current_ht_config);
2608 iwl_set_rxon_chain(priv);
2609 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2611 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2612 priv->assoc_id, priv->beacon_int);
2614 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2615 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2617 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2619 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2620 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2621 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2623 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2625 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2626 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2630 iwl4965_commit_rxon(priv);
2632 switch (priv->iw_mode) {
2633 case IEEE80211_IF_TYPE_STA:
2634 iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
2637 case IEEE80211_IF_TYPE_IBSS:
2639 /* assume default assoc id */
2642 iwl_rxon_add_station(priv, priv->bssid, 0);
2643 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
2644 iwl4965_send_beacon_cmd(priv);
2649 IWL_ERROR("%s Should not be called in %d mode\n",
2650 __FUNCTION__, priv->iw_mode);
2654 iwl4965_sequence_reset(priv);
2656 /* Enable Rx differential gain and sensitivity calibrations */
2657 iwl_chain_noise_reset(priv);
2658 priv->start_calib = 1;
2660 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2661 priv->assoc_station_added = 1;
2663 iwl4965_activate_qos(priv, 0);
2665 iwl_power_update_mode(priv, 0);
2666 /* we have just associated, don't start scan too early */
2667 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
2671 static void iwl4965_bg_post_associate(struct work_struct *data)
2673 struct iwl_priv *priv = container_of(data, struct iwl_priv,
2674 post_associate.work);
2676 mutex_lock(&priv->mutex);
2677 iwl4965_post_associate(priv);
2678 mutex_unlock(&priv->mutex);
2682 static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
2684 static void iwl_bg_scan_completed(struct work_struct *work)
2686 struct iwl_priv *priv =
2687 container_of(work, struct iwl_priv, scan_completed);
2689 IWL_DEBUG_SCAN("SCAN complete scan\n");
2691 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2694 if (test_bit(STATUS_CONF_PENDING, &priv->status))
2695 iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
2697 ieee80211_scan_completed(priv->hw);
2699 /* Since setting the TXPOWER may have been deferred while
2700 * performing the scan, fire one off */
2701 mutex_lock(&priv->mutex);
2702 iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
2703 mutex_unlock(&priv->mutex);
2706 /*****************************************************************************
2708 * mac80211 entry point functions
2710 *****************************************************************************/
2712 #define UCODE_READY_TIMEOUT (2 * HZ)
2714 static int iwl4965_mac_start(struct ieee80211_hw *hw)
2716 struct iwl_priv *priv = hw->priv;
2719 IWL_DEBUG_MAC80211("enter\n");
2721 if (pci_enable_device(priv->pci_dev)) {
2722 IWL_ERROR("Fail to pci_enable_device\n");
2725 pci_restore_state(priv->pci_dev);
2726 pci_enable_msi(priv->pci_dev);
2728 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
2731 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
2732 goto out_disable_msi;
2735 /* we should be verifying the device is ready to be opened */
2736 mutex_lock(&priv->mutex);
2738 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
2739 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2740 * ucode filename and max sizes are card-specific. */
2742 if (!priv->ucode_code.len) {
2743 ret = iwl4965_read_ucode(priv);
2745 IWL_ERROR("Could not read microcode: %d\n", ret);
2746 mutex_unlock(&priv->mutex);
2747 goto out_release_irq;
2751 ret = __iwl4965_up(priv);
2753 mutex_unlock(&priv->mutex);
2756 goto out_release_irq;
2758 IWL_DEBUG_INFO("Start UP work done.\n");
2760 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2763 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
2764 * mac80211 will not be run successfully. */
2765 if (priv->ucode_type == UCODE_RT) {
2766 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2767 test_bit(STATUS_READY, &priv->status),
2768 UCODE_READY_TIMEOUT);
2770 if (!test_bit(STATUS_READY, &priv->status)) {
2771 IWL_ERROR("START_ALIVE timeout after %dms.\n",
2772 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2774 goto out_release_irq;
2780 IWL_DEBUG_MAC80211("leave\n");
2784 free_irq(priv->pci_dev->irq, priv);
2786 pci_disable_msi(priv->pci_dev);
2787 pci_disable_device(priv->pci_dev);
2789 IWL_DEBUG_MAC80211("leave - failed\n");
2793 static void iwl4965_mac_stop(struct ieee80211_hw *hw)
2795 struct iwl_priv *priv = hw->priv;
2797 IWL_DEBUG_MAC80211("enter\n");
2799 if (!priv->is_open) {
2800 IWL_DEBUG_MAC80211("leave - skip\n");
2806 if (iwl_is_ready_rf(priv)) {
2807 /* stop mac, cancel any scan request and clear
2808 * RXON_FILTER_ASSOC_MSK BIT
2810 mutex_lock(&priv->mutex);
2811 iwl_scan_cancel_timeout(priv, 100);
2812 cancel_delayed_work(&priv->post_associate);
2813 mutex_unlock(&priv->mutex);
2818 flush_workqueue(priv->workqueue);
2819 free_irq(priv->pci_dev->irq, priv);
2820 pci_disable_msi(priv->pci_dev);
2821 pci_save_state(priv->pci_dev);
2822 pci_disable_device(priv->pci_dev);
2824 IWL_DEBUG_MAC80211("leave\n");
2827 static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2829 struct iwl_priv *priv = hw->priv;
2831 IWL_DEBUG_MAC80211("enter\n");
2833 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
2834 IWL_DEBUG_MAC80211("leave - monitor\n");
2838 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
2839 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
2841 if (iwl_tx_skb(priv, skb))
2842 dev_kfree_skb_any(skb);
2844 IWL_DEBUG_MAC80211("leave\n");
2848 static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
2849 struct ieee80211_if_init_conf *conf)
2851 struct iwl_priv *priv = hw->priv;
2852 unsigned long flags;
2853 DECLARE_MAC_BUF(mac);
2855 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
2858 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
2862 spin_lock_irqsave(&priv->lock, flags);
2863 priv->vif = conf->vif;
2865 spin_unlock_irqrestore(&priv->lock, flags);
2867 mutex_lock(&priv->mutex);
2869 if (conf->mac_addr) {
2870 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
2871 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2874 if (iwl4965_set_mode(priv, conf->type) == -EAGAIN)
2875 /* we are not ready, will run again when ready */
2876 set_bit(STATUS_MODE_PENDING, &priv->status);
2878 mutex_unlock(&priv->mutex);
2880 IWL_DEBUG_MAC80211("leave\n");
2885 * iwl4965_mac_config - mac80211 config callback
2887 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2888 * be set inappropriately and the driver currently sets the hardware up to
2889 * use it whenever needed.
2891 static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
2893 struct iwl_priv *priv = hw->priv;
2894 const struct iwl_channel_info *ch_info;
2895 unsigned long flags;
2899 mutex_lock(&priv->mutex);
2900 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
2902 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
2904 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
2905 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
2909 if (!conf->radio_enabled)
2910 iwl_radio_kill_sw_disable_radio(priv);
2912 if (!iwl_is_ready(priv)) {
2913 IWL_DEBUG_MAC80211("leave - not ready\n");
2918 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2919 test_bit(STATUS_SCANNING, &priv->status))) {
2920 IWL_DEBUG_MAC80211("leave - scanning\n");
2921 set_bit(STATUS_CONF_PENDING, &priv->status);
2922 mutex_unlock(&priv->mutex);
2926 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2927 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
2928 if (!is_channel_valid(ch_info)) {
2929 IWL_DEBUG_MAC80211("leave - invalid channel\n");
2934 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
2935 !is_channel_ibss(ch_info)) {
2936 IWL_ERROR("channel %d in band %d not IBSS channel\n",
2937 conf->channel->hw_value, conf->channel->band);
2942 spin_lock_irqsave(&priv->lock, flags);
2944 /* if we are switching from ht to 2.4 clear flags
2945 * from any ht related info since 2.4 does not
2947 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
2948 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
2949 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2952 priv->staging_rxon.flags = 0;
2954 iwl_set_rxon_channel(priv, conf->channel->band, channel);
2956 iwl_set_flags_for_band(priv, conf->channel->band);
2958 /* The list of supported rates and rate mask can be different
2959 * for each band; since the band may have changed, reset
2960 * the rate mask to what mac80211 lists */
2961 iwl4965_set_rate(priv);
2963 spin_unlock_irqrestore(&priv->lock, flags);
2965 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
2966 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
2967 iwl4965_hw_channel_switch(priv, conf->channel);
2972 if (!conf->radio_enabled) {
2973 IWL_DEBUG_MAC80211("leave - radio disabled\n");
2977 if (iwl_is_rfkill(priv)) {
2978 IWL_DEBUG_MAC80211("leave - RF kill\n");
2983 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2984 priv->tx_power_user_lmt, conf->power_level);
2986 iwl_set_tx_power(priv, conf->power_level, false);
2988 iwl4965_set_rate(priv);
2990 if (memcmp(&priv->active_rxon,
2991 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2992 iwl4965_commit_rxon(priv);
2994 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2996 IWL_DEBUG_MAC80211("leave\n");
2999 clear_bit(STATUS_CONF_PENDING, &priv->status);
3000 mutex_unlock(&priv->mutex);
3004 static void iwl4965_config_ap(struct iwl_priv *priv)
3008 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3011 /* The following should be done only at AP bring up */
3012 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
3014 /* RXON - unassoc (to set timing command) */
3015 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3016 iwl4965_commit_rxon(priv);
3019 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
3020 iwl4965_setup_rxon_timing(priv);
3021 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3022 sizeof(priv->rxon_timing), &priv->rxon_timing);
3024 IWL_WARNING("REPLY_RXON_TIMING failed - "
3025 "Attempting to continue.\n");
3027 iwl_set_rxon_chain(priv);
3029 /* FIXME: what should be the assoc_id for AP? */
3030 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
3031 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
3032 priv->staging_rxon.flags |=
3033 RXON_FLG_SHORT_PREAMBLE_MSK;
3035 priv->staging_rxon.flags &=
3036 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3038 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
3039 if (priv->assoc_capability &
3040 WLAN_CAPABILITY_SHORT_SLOT_TIME)
3041 priv->staging_rxon.flags |=
3042 RXON_FLG_SHORT_SLOT_MSK;
3044 priv->staging_rxon.flags &=
3045 ~RXON_FLG_SHORT_SLOT_MSK;
3047 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
3048 priv->staging_rxon.flags &=
3049 ~RXON_FLG_SHORT_SLOT_MSK;
3051 /* restore RXON assoc */
3052 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
3053 iwl4965_commit_rxon(priv);
3054 iwl4965_activate_qos(priv, 1);
3055 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
3057 iwl4965_send_beacon_cmd(priv);
3059 /* FIXME - we need to add code here to detect a totally new
3060 * configuration, reset the AP, unassoc, rxon timing, assoc,
3061 * clear sta table, add BCAST sta... */
3064 static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
3065 struct ieee80211_vif *vif,
3066 struct ieee80211_if_conf *conf)
3068 struct iwl_priv *priv = hw->priv;
3069 DECLARE_MAC_BUF(mac);
3070 unsigned long flags;
3076 if (priv->vif != vif) {
3077 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
3081 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
3082 (!conf->beacon || !conf->ssid_len)) {
3084 ("Leaving in AP mode because HostAPD is not ready.\n");
3088 if (!iwl_is_alive(priv))
3091 mutex_lock(&priv->mutex);
3094 IWL_DEBUG_MAC80211("bssid: %s\n",
3095 print_mac(mac, conf->bssid));
3098 * very dubious code was here; the probe filtering flag is never set:
3100 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3101 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
3104 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
3106 conf->bssid = priv->mac_addr;
3107 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
3108 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
3109 print_mac(mac, conf->bssid));
3111 if (priv->ibss_beacon)
3112 dev_kfree_skb(priv->ibss_beacon);
3114 priv->ibss_beacon = conf->beacon;
3117 if (iwl_is_rfkill(priv))
3120 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3121 !is_multicast_ether_addr(conf->bssid)) {
3122 /* If there is currently a HW scan going on in the background
3123 * then we need to cancel it else the RXON below will fail. */
3124 if (iwl_scan_cancel_timeout(priv, 100)) {
3125 IWL_WARNING("Aborted scan still in progress "
3127 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
3128 mutex_unlock(&priv->mutex);
3131 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
3133 /* TODO: Audit driver for usage of these members and see
3134 * if mac80211 deprecates them (priv->bssid looks like it
3135 * shouldn't be there, but I haven't scanned the IBSS code
3136 * to verify) - jpk */
3137 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
3139 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
3140 iwl4965_config_ap(priv);
3142 rc = iwl4965_commit_rxon(priv);
3143 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
3144 iwl_rxon_add_station(
3145 priv, priv->active_rxon.bssid_addr, 1);
3149 iwl_scan_cancel_timeout(priv, 100);
3150 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3151 iwl4965_commit_rxon(priv);
3155 spin_lock_irqsave(&priv->lock, flags);
3156 if (!conf->ssid_len)
3157 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3159 memcpy(priv->essid, conf->ssid, conf->ssid_len);
3161 priv->essid_len = conf->ssid_len;
3162 spin_unlock_irqrestore(&priv->lock, flags);
3164 IWL_DEBUG_MAC80211("leave\n");
3165 mutex_unlock(&priv->mutex);
3170 static void iwl4965_configure_filter(struct ieee80211_hw *hw,
3171 unsigned int changed_flags,
3172 unsigned int *total_flags,
3173 int mc_count, struct dev_addr_list *mc_list)
3177 * see also iwl4965_connection_init_rx_config
3179 struct iwl_priv *priv = hw->priv;
3181 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
3182 if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
3183 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
3184 IEEE80211_IF_TYPE_MNTR,
3185 changed_flags, *total_flags);
3186 /* queue work 'cuz mac80211 is holding a lock which
3187 * prevents us from issuing (synchronous) f/w cmds */
3188 queue_work(priv->workqueue, &priv->set_monitor);
3189 new_flags &= FIF_PROMISC_IN_BSS |
3194 *total_flags = new_flags;
3197 static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
3198 struct ieee80211_if_init_conf *conf)
3200 struct iwl_priv *priv = hw->priv;
3202 IWL_DEBUG_MAC80211("enter\n");
3204 mutex_lock(&priv->mutex);
3206 if (iwl_is_ready_rf(priv)) {
3207 iwl_scan_cancel_timeout(priv, 100);
3208 cancel_delayed_work(&priv->post_associate);
3209 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3210 iwl4965_commit_rxon(priv);
3212 if (priv->vif == conf->vif) {
3214 memset(priv->bssid, 0, ETH_ALEN);
3215 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3216 priv->essid_len = 0;
3218 mutex_unlock(&priv->mutex);
3220 IWL_DEBUG_MAC80211("leave\n");
3224 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
3225 static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
3226 struct ieee80211_vif *vif,
3227 struct ieee80211_bss_conf *bss_conf,
3230 struct iwl_priv *priv = hw->priv;
3232 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
3234 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
3235 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
3236 bss_conf->use_short_preamble);
3237 if (bss_conf->use_short_preamble)
3238 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3240 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3243 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
3244 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
3245 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
3246 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
3248 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
3251 if (changes & BSS_CHANGED_HT) {
3252 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
3253 iwl4965_ht_conf(priv, bss_conf);
3254 iwl_set_rxon_chain(priv);
3257 if (changes & BSS_CHANGED_ASSOC) {
3258 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
3259 /* This should never happen as this function should
3260 * never be called from interrupt context. */
3261 if (WARN_ON_ONCE(in_interrupt()))
3263 if (bss_conf->assoc) {
3264 priv->assoc_id = bss_conf->aid;
3265 priv->beacon_int = bss_conf->beacon_int;
3266 priv->timestamp = bss_conf->timestamp;
3267 priv->assoc_capability = bss_conf->assoc_capability;
3268 priv->next_scan_jiffies = jiffies +
3269 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
3270 mutex_lock(&priv->mutex);
3271 iwl4965_post_associate(priv);
3272 mutex_unlock(&priv->mutex);
3275 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3277 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3278 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
3279 iwl_send_rxon_assoc(priv);
3284 static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
3287 unsigned long flags;
3288 struct iwl_priv *priv = hw->priv;
3290 IWL_DEBUG_MAC80211("enter\n");
3292 mutex_lock(&priv->mutex);
3293 spin_lock_irqsave(&priv->lock, flags);
3295 if (!iwl_is_ready_rf(priv)) {
3297 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3301 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
3303 IWL_ERROR("ERROR: APs don't scan\n");
3307 /* we don't schedule scan within next_scan_jiffies period */
3308 if (priv->next_scan_jiffies &&
3309 time_after(priv->next_scan_jiffies, jiffies)) {
3313 /* if we just finished scan ask for delay */
3314 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
3315 IWL_DELAY_NEXT_SCAN, jiffies)) {
3320 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
3321 iwl_escape_essid(ssid, len), (int)len);
3323 priv->one_direct_scan = 1;
3324 priv->direct_ssid_len = (u8)
3325 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
3326 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
3328 priv->one_direct_scan = 0;
3330 rc = iwl_scan_initiate(priv);
3332 IWL_DEBUG_MAC80211("leave\n");
3335 spin_unlock_irqrestore(&priv->lock, flags);
3336 mutex_unlock(&priv->mutex);
3341 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
3342 struct ieee80211_key_conf *keyconf, const u8 *addr,
3343 u32 iv32, u16 *phase1key)
3345 struct iwl_priv *priv = hw->priv;
3346 u8 sta_id = IWL_INVALID_STATION;
3347 unsigned long flags;
3348 __le16 key_flags = 0;
3350 DECLARE_MAC_BUF(mac);
3352 IWL_DEBUG_MAC80211("enter\n");
3354 sta_id = iwl_find_station(priv, addr);
3355 if (sta_id == IWL_INVALID_STATION) {
3356 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3357 print_mac(mac, addr));
3361 iwl_scan_cancel_timeout(priv, 100);
3363 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
3364 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
3365 key_flags &= ~STA_KEY_FLG_INVALID;
3367 if (sta_id == priv->hw_params.bcast_sta_id)
3368 key_flags |= STA_KEY_MULTICAST_MSK;
3370 spin_lock_irqsave(&priv->sta_lock, flags);
3372 priv->stations[sta_id].sta.key.key_flags = key_flags;
3373 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
3375 for (i = 0; i < 5; i++)
3376 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
3377 cpu_to_le16(phase1key[i]);
3379 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
3380 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3382 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
3384 spin_unlock_irqrestore(&priv->sta_lock, flags);
3386 IWL_DEBUG_MAC80211("leave\n");
3389 static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3390 const u8 *local_addr, const u8 *addr,
3391 struct ieee80211_key_conf *key)
3393 struct iwl_priv *priv = hw->priv;
3394 DECLARE_MAC_BUF(mac);
3396 u8 sta_id = IWL_INVALID_STATION;
3397 u8 is_default_wep_key = 0;
3399 IWL_DEBUG_MAC80211("enter\n");
3401 if (priv->hw_params.sw_crypto) {
3402 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3406 if (is_zero_ether_addr(addr))
3407 /* only support pairwise keys */
3410 sta_id = iwl_find_station(priv, addr);
3411 if (sta_id == IWL_INVALID_STATION) {
3412 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3413 print_mac(mac, addr));
3418 mutex_lock(&priv->mutex);
3419 iwl_scan_cancel_timeout(priv, 100);
3420 mutex_unlock(&priv->mutex);
3422 /* If we are getting WEP group key and we didn't receive any key mapping
3423 * so far, we are in legacy wep mode (group key only), otherwise we are
3425 * In legacy wep mode, we use another host command to the uCode */
3426 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
3427 priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3429 is_default_wep_key = !priv->key_mapping_key;
3431 is_default_wep_key =
3432 (key->hw_key_idx == HW_KEY_DEFAULT);
3437 if (is_default_wep_key)
3438 ret = iwl_set_default_wep_key(priv, key);
3440 ret = iwl_set_dynamic_key(priv, key, sta_id);
3442 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
3445 if (is_default_wep_key)
3446 ret = iwl_remove_default_wep_key(priv, key);
3448 ret = iwl_remove_dynamic_key(priv, key, sta_id);
3450 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
3456 IWL_DEBUG_MAC80211("leave\n");
3461 static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
3462 const struct ieee80211_tx_queue_params *params)
3464 struct iwl_priv *priv = hw->priv;
3465 unsigned long flags;
3468 IWL_DEBUG_MAC80211("enter\n");
3470 if (!iwl_is_ready_rf(priv)) {
3471 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3475 if (queue >= AC_NUM) {
3476 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3480 if (!priv->qos_data.qos_enable) {
3481 priv->qos_data.qos_active = 0;
3482 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
3485 q = AC_NUM - 1 - queue;
3487 spin_lock_irqsave(&priv->lock, flags);
3489 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3490 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3491 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3492 priv->qos_data.def_qos_parm.ac[q].edca_txop =
3493 cpu_to_le16((params->txop * 32));
3495 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3496 priv->qos_data.qos_active = 1;
3498 spin_unlock_irqrestore(&priv->lock, flags);
3500 mutex_lock(&priv->mutex);
3501 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
3502 iwl4965_activate_qos(priv, 1);
3503 else if (priv->assoc_id && iwl_is_associated(priv))
3504 iwl4965_activate_qos(priv, 0);
3506 mutex_unlock(&priv->mutex);
3508 IWL_DEBUG_MAC80211("leave\n");
3512 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
3513 struct ieee80211_tx_queue_stats *stats)
3515 struct iwl_priv *priv = hw->priv;
3517 struct iwl_tx_queue *txq;
3518 struct iwl_queue *q;
3519 unsigned long flags;
3521 IWL_DEBUG_MAC80211("enter\n");
3523 if (!iwl_is_ready_rf(priv)) {
3524 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3528 spin_lock_irqsave(&priv->lock, flags);
3530 for (i = 0; i < AC_NUM; i++) {
3531 txq = &priv->txq[i];
3533 avail = iwl_queue_space(q);
3535 stats[i].len = q->n_window - avail;
3536 stats[i].limit = q->n_window - q->high_mark;
3537 stats[i].count = q->n_window;
3540 spin_unlock_irqrestore(&priv->lock, flags);
3542 IWL_DEBUG_MAC80211("leave\n");
3547 static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
3548 struct ieee80211_low_level_stats *stats)
3550 struct iwl_priv *priv = hw->priv;
3553 IWL_DEBUG_MAC80211("enter\n");
3554 IWL_DEBUG_MAC80211("leave\n");
3559 static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
3561 struct iwl_priv *priv;
3564 IWL_DEBUG_MAC80211("enter\n");
3565 IWL_DEBUG_MAC80211("leave\n");
3570 static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
3572 struct iwl_priv *priv = hw->priv;
3573 unsigned long flags;
3575 mutex_lock(&priv->mutex);
3576 IWL_DEBUG_MAC80211("enter\n");
3578 priv->lq_mngr.lq_ready = 0;
3579 spin_lock_irqsave(&priv->lock, flags);
3580 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
3581 spin_unlock_irqrestore(&priv->lock, flags);
3583 iwl_reset_qos(priv);
3585 cancel_delayed_work(&priv->post_associate);
3587 spin_lock_irqsave(&priv->lock, flags);
3589 priv->assoc_capability = 0;
3590 priv->assoc_station_added = 0;
3592 /* new association get rid of ibss beacon skb */
3593 if (priv->ibss_beacon)
3594 dev_kfree_skb(priv->ibss_beacon);
3596 priv->ibss_beacon = NULL;
3598 priv->beacon_int = priv->hw->conf.beacon_int;
3599 priv->timestamp = 0;
3600 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
3601 priv->beacon_int = 0;
3603 spin_unlock_irqrestore(&priv->lock, flags);
3605 if (!iwl_is_ready_rf(priv)) {
3606 IWL_DEBUG_MAC80211("leave - not ready\n");
3607 mutex_unlock(&priv->mutex);
3611 /* we are restarting association process
3612 * clear RXON_FILTER_ASSOC_MSK bit
3614 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3615 iwl_scan_cancel_timeout(priv, 100);
3616 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3617 iwl4965_commit_rxon(priv);
3620 iwl_power_update_mode(priv, 0);
3622 /* Per mac80211.h: This is only used in IBSS mode... */
3623 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
3625 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3626 mutex_unlock(&priv->mutex);
3630 iwl4965_set_rate(priv);
3632 mutex_unlock(&priv->mutex);
3634 IWL_DEBUG_MAC80211("leave\n");
3637 static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
3639 struct iwl_priv *priv = hw->priv;
3640 unsigned long flags;
3642 mutex_lock(&priv->mutex);
3643 IWL_DEBUG_MAC80211("enter\n");
3645 if (!iwl_is_ready_rf(priv)) {
3646 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3647 mutex_unlock(&priv->mutex);
3651 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
3652 IWL_DEBUG_MAC80211("leave - not IBSS\n");
3653 mutex_unlock(&priv->mutex);
3657 spin_lock_irqsave(&priv->lock, flags);
3659 if (priv->ibss_beacon)
3660 dev_kfree_skb(priv->ibss_beacon);
3662 priv->ibss_beacon = skb;
3666 IWL_DEBUG_MAC80211("leave\n");
3667 spin_unlock_irqrestore(&priv->lock, flags);
3669 iwl_reset_qos(priv);
3671 iwl4965_post_associate(priv);
3673 mutex_unlock(&priv->mutex);
3678 /*****************************************************************************
3682 *****************************************************************************/
3684 #ifdef CONFIG_IWLWIFI_DEBUG
3687 * The following adds a new attribute to the sysfs representation
3688 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3689 * used for controlling the debug level.
3691 * See the level definitions in iwl for details.
3694 static ssize_t show_debug_level(struct device *d,
3695 struct device_attribute *attr, char *buf)
3697 struct iwl_priv *priv = d->driver_data;
3699 return sprintf(buf, "0x%08X\n", priv->debug_level);
3701 static ssize_t store_debug_level(struct device *d,
3702 struct device_attribute *attr,
3703 const char *buf, size_t count)
3705 struct iwl_priv *priv = d->driver_data;
3706 char *p = (char *)buf;
3709 val = simple_strtoul(p, &p, 0);
3711 printk(KERN_INFO DRV_NAME
3712 ": %s is not in hex or decimal form.\n", buf);
3714 priv->debug_level = val;
3716 return strnlen(buf, count);
3719 static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3720 show_debug_level, store_debug_level);
3723 #endif /* CONFIG_IWLWIFI_DEBUG */
3726 static ssize_t show_version(struct device *d,
3727 struct device_attribute *attr, char *buf)
3729 struct iwl_priv *priv = d->driver_data;
3730 struct iwl_alive_resp *palive = &priv->card_alive;
3732 if (palive->is_valid)
3733 return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3734 "fw type: 0x%01X 0x%01X\n",
3735 palive->ucode_major, palive->ucode_minor,
3736 palive->sw_rev[0], palive->sw_rev[1],
3737 palive->ver_type, palive->ver_subtype);
3740 return sprintf(buf, "fw not loaded\n");
3743 static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3745 static ssize_t show_temperature(struct device *d,
3746 struct device_attribute *attr, char *buf)
3748 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3750 if (!iwl_is_alive(priv))
3753 return sprintf(buf, "%d\n", priv->temperature);
3756 static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3758 static ssize_t show_rs_window(struct device *d,
3759 struct device_attribute *attr,
3762 struct iwl_priv *priv = d->driver_data;
3763 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
3765 static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
3767 static ssize_t show_tx_power(struct device *d,
3768 struct device_attribute *attr, char *buf)
3770 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3771 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
3774 static ssize_t store_tx_power(struct device *d,
3775 struct device_attribute *attr,
3776 const char *buf, size_t count)
3778 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3779 char *p = (char *)buf;
3782 val = simple_strtoul(p, &p, 10);
3784 printk(KERN_INFO DRV_NAME
3785 ": %s is not in decimal form.\n", buf);
3787 iwl_set_tx_power(priv, val, false);
3792 static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3794 static ssize_t show_flags(struct device *d,
3795 struct device_attribute *attr, char *buf)
3797 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3799 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3802 static ssize_t store_flags(struct device *d,
3803 struct device_attribute *attr,
3804 const char *buf, size_t count)
3806 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3807 u32 flags = simple_strtoul(buf, NULL, 0);
3809 mutex_lock(&priv->mutex);
3810 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3811 /* Cancel any currently running scans... */
3812 if (iwl_scan_cancel_timeout(priv, 100))
3813 IWL_WARNING("Could not cancel scan.\n");
3815 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
3817 priv->staging_rxon.flags = cpu_to_le32(flags);
3818 iwl4965_commit_rxon(priv);
3821 mutex_unlock(&priv->mutex);
3826 static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3828 static ssize_t show_filter_flags(struct device *d,
3829 struct device_attribute *attr, char *buf)
3831 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3833 return sprintf(buf, "0x%04X\n",
3834 le32_to_cpu(priv->active_rxon.filter_flags));
3837 static ssize_t store_filter_flags(struct device *d,
3838 struct device_attribute *attr,
3839 const char *buf, size_t count)
3841 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3842 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3844 mutex_lock(&priv->mutex);
3845 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3846 /* Cancel any currently running scans... */
3847 if (iwl_scan_cancel_timeout(priv, 100))
3848 IWL_WARNING("Could not cancel scan.\n");
3850 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3851 "0x%04X\n", filter_flags);
3852 priv->staging_rxon.filter_flags =
3853 cpu_to_le32(filter_flags);
3854 iwl4965_commit_rxon(priv);
3857 mutex_unlock(&priv->mutex);
3862 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3863 store_filter_flags);
3865 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3867 static ssize_t show_measurement(struct device *d,
3868 struct device_attribute *attr, char *buf)
3870 struct iwl_priv *priv = dev_get_drvdata(d);
3871 struct iwl4965_spectrum_notification measure_report;
3872 u32 size = sizeof(measure_report), len = 0, ofs = 0;
3873 u8 *data = (u8 *) & measure_report;
3874 unsigned long flags;
3876 spin_lock_irqsave(&priv->lock, flags);
3877 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3878 spin_unlock_irqrestore(&priv->lock, flags);
3881 memcpy(&measure_report, &priv->measure_report, size);
3882 priv->measurement_status = 0;
3883 spin_unlock_irqrestore(&priv->lock, flags);
3885 while (size && (PAGE_SIZE - len)) {
3886 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3887 PAGE_SIZE - len, 1);
3889 if (PAGE_SIZE - len)
3893 size -= min(size, 16U);
3899 static ssize_t store_measurement(struct device *d,
3900 struct device_attribute *attr,
3901 const char *buf, size_t count)
3903 struct iwl_priv *priv = dev_get_drvdata(d);
3904 struct ieee80211_measurement_params params = {
3905 .channel = le16_to_cpu(priv->active_rxon.channel),
3906 .start_time = cpu_to_le64(priv->last_tsf),
3907 .duration = cpu_to_le16(1),
3909 u8 type = IWL_MEASURE_BASIC;
3915 strncpy(buffer, buf, min(sizeof(buffer), count));
3916 channel = simple_strtoul(p, NULL, 0);
3918 params.channel = channel;
3921 while (*p && *p != ' ')
3924 type = simple_strtoul(p + 1, NULL, 0);
3927 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3928 "channel %d (for '%s')\n", type, params.channel, buf);
3929 iwl4965_get_measurement(priv, ¶ms, type);
3934 static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3935 show_measurement, store_measurement);
3936 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
3938 static ssize_t store_retry_rate(struct device *d,
3939 struct device_attribute *attr,
3940 const char *buf, size_t count)
3942 struct iwl_priv *priv = dev_get_drvdata(d);
3944 priv->retry_rate = simple_strtoul(buf, NULL, 0);
3945 if (priv->retry_rate <= 0)
3946 priv->retry_rate = 1;
3951 static ssize_t show_retry_rate(struct device *d,
3952 struct device_attribute *attr, char *buf)
3954 struct iwl_priv *priv = dev_get_drvdata(d);
3955 return sprintf(buf, "%d", priv->retry_rate);
3958 static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3961 static ssize_t store_power_level(struct device *d,
3962 struct device_attribute *attr,
3963 const char *buf, size_t count)
3965 struct iwl_priv *priv = dev_get_drvdata(d);
3969 mode = simple_strtoul(buf, NULL, 0);
3970 mutex_lock(&priv->mutex);
3972 if (!iwl_is_ready(priv)) {
3977 rc = iwl_power_set_user_mode(priv, mode);
3979 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3985 mutex_unlock(&priv->mutex);
3989 #define MAX_WX_STRING 80
3991 /* Values are in microsecond */
3992 static const s32 timeout_duration[] = {
3999 static const s32 period_duration[] = {
4007 static ssize_t show_power_level(struct device *d,
4008 struct device_attribute *attr, char *buf)
4010 struct iwl_priv *priv = dev_get_drvdata(d);
4011 int level = priv->power_data.power_mode;
4014 p += sprintf(p, "%d ", level);
4016 case IWL_POWER_MODE_CAM:
4018 p += sprintf(p, "(AC)");
4020 case IWL_POWER_BATTERY:
4021 p += sprintf(p, "(BATTERY)");
4025 "(Timeout %dms, Period %dms)",
4026 timeout_duration[level - 1] / 1000,
4027 period_duration[level - 1] / 1000);
4030 if (!(priv->power_mode & IWL_POWER_ENABLED))
4031 p += sprintf(p, " OFF\n");
4033 p += sprintf(p, " \n");
4035 p += sprintf(p, " \n");
4036 return (p - buf + 1);
4039 static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
4042 static ssize_t show_channels(struct device *d,
4043 struct device_attribute *attr, char *buf)
4046 struct iwl_priv *priv = dev_get_drvdata(d);
4047 struct ieee80211_channel *channels = NULL;
4048 const struct ieee80211_supported_band *supp_band = NULL;
4052 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
4055 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
4056 channels = supp_band->channels;
4057 count = supp_band->n_channels;
4059 len += sprintf(&buf[len],
4060 "Displaying %d channels in 2.4GHz band "
4061 "(802.11bg):\n", count);
4063 for (i = 0; i < count; i++)
4064 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
4065 ieee80211_frequency_to_channel(
4066 channels[i].center_freq),
4067 channels[i].max_power,
4068 channels[i].flags & IEEE80211_CHAN_RADAR ?
4069 " (IEEE 802.11h required)" : "",
4070 (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
4071 || (channels[i].flags &
4072 IEEE80211_CHAN_RADAR)) ? "" :
4075 IEEE80211_CHAN_PASSIVE_SCAN ?
4076 "passive only" : "active/passive");
4078 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
4079 channels = supp_band->channels;
4080 count = supp_band->n_channels;
4082 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
4083 "(802.11a):\n", count);
4085 for (i = 0; i < count; i++)
4086 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
4087 ieee80211_frequency_to_channel(
4088 channels[i].center_freq),
4089 channels[i].max_power,
4090 channels[i].flags & IEEE80211_CHAN_RADAR ?
4091 " (IEEE 802.11h required)" : "",
4092 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
4093 || (channels[i].flags &
4094 IEEE80211_CHAN_RADAR)) ? "" :
4097 IEEE80211_CHAN_PASSIVE_SCAN ?
4098 "passive only" : "active/passive");
4103 static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4105 static ssize_t show_statistics(struct device *d,
4106 struct device_attribute *attr, char *buf)
4108 struct iwl_priv *priv = dev_get_drvdata(d);
4109 u32 size = sizeof(struct iwl4965_notif_statistics);
4110 u32 len = 0, ofs = 0;
4111 u8 *data = (u8 *) & priv->statistics;
4114 if (!iwl_is_alive(priv))
4117 mutex_lock(&priv->mutex);
4118 rc = iwl_send_statistics_request(priv, 0);
4119 mutex_unlock(&priv->mutex);
4123 "Error sending statistics request: 0x%08X\n", rc);
4127 while (size && (PAGE_SIZE - len)) {
4128 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4129 PAGE_SIZE - len, 1);
4131 if (PAGE_SIZE - len)
4135 size -= min(size, 16U);
4141 static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4143 static ssize_t show_status(struct device *d,
4144 struct device_attribute *attr, char *buf)
4146 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4147 if (!iwl_is_alive(priv))
4149 return sprintf(buf, "0x%08x\n", (int)priv->status);
4152 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4154 /*****************************************************************************
4156 * driver setup and teardown
4158 *****************************************************************************/
4160 static void iwl_setup_deferred_work(struct iwl_priv *priv)
4162 priv->workqueue = create_workqueue(DRV_NAME);
4164 init_waitqueue_head(&priv->wait_command_queue);
4166 INIT_WORK(&priv->up, iwl4965_bg_up);
4167 INIT_WORK(&priv->restart, iwl4965_bg_restart);
4168 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
4169 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
4170 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
4171 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
4172 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
4173 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
4174 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
4175 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
4177 /* FIXME : remove when resolved PENDING */
4178 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4179 iwl_setup_scan_deferred_work(priv);
4181 if (priv->cfg->ops->lib->setup_deferred_work)
4182 priv->cfg->ops->lib->setup_deferred_work(priv);
4184 init_timer(&priv->statistics_periodic);
4185 priv->statistics_periodic.data = (unsigned long)priv;
4186 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
4188 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
4189 iwl4965_irq_tasklet, (unsigned long)priv);
4192 static void iwl_cancel_deferred_work(struct iwl_priv *priv)
4194 if (priv->cfg->ops->lib->cancel_deferred_work)
4195 priv->cfg->ops->lib->cancel_deferred_work(priv);
4197 cancel_delayed_work_sync(&priv->init_alive_start);
4198 cancel_delayed_work(&priv->scan_check);
4199 cancel_delayed_work(&priv->alive_start);
4200 cancel_delayed_work(&priv->post_associate);
4201 cancel_work_sync(&priv->beacon_update);
4202 del_timer_sync(&priv->statistics_periodic);
4205 static struct attribute *iwl4965_sysfs_entries[] = {
4206 &dev_attr_channels.attr,
4207 &dev_attr_flags.attr,
4208 &dev_attr_filter_flags.attr,
4209 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
4210 &dev_attr_measurement.attr,
4212 &dev_attr_power_level.attr,
4213 &dev_attr_retry_rate.attr,
4214 &dev_attr_rs_window.attr,
4215 &dev_attr_statistics.attr,
4216 &dev_attr_status.attr,
4217 &dev_attr_temperature.attr,
4218 &dev_attr_tx_power.attr,
4219 #ifdef CONFIG_IWLWIFI_DEBUG
4220 &dev_attr_debug_level.attr,
4222 &dev_attr_version.attr,
4227 static struct attribute_group iwl4965_attribute_group = {
4228 .name = NULL, /* put in device directory */
4229 .attrs = iwl4965_sysfs_entries,
4232 static struct ieee80211_ops iwl4965_hw_ops = {
4233 .tx = iwl4965_mac_tx,
4234 .start = iwl4965_mac_start,
4235 .stop = iwl4965_mac_stop,
4236 .add_interface = iwl4965_mac_add_interface,
4237 .remove_interface = iwl4965_mac_remove_interface,
4238 .config = iwl4965_mac_config,
4239 .config_interface = iwl4965_mac_config_interface,
4240 .configure_filter = iwl4965_configure_filter,
4241 .set_key = iwl4965_mac_set_key,
4242 .update_tkip_key = iwl4965_mac_update_tkip_key,
4243 .get_stats = iwl4965_mac_get_stats,
4244 .get_tx_stats = iwl4965_mac_get_tx_stats,
4245 .conf_tx = iwl4965_mac_conf_tx,
4246 .get_tsf = iwl4965_mac_get_tsf,
4247 .reset_tsf = iwl4965_mac_reset_tsf,
4248 .beacon_update = iwl4965_mac_beacon_update,
4249 .bss_info_changed = iwl4965_bss_info_changed,
4250 .ampdu_action = iwl4965_mac_ampdu_action,
4251 .hw_scan = iwl4965_mac_hw_scan
4254 static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4257 struct iwl_priv *priv;
4258 struct ieee80211_hw *hw;
4259 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
4260 unsigned long flags;
4261 DECLARE_MAC_BUF(mac);
4263 /************************
4264 * 1. Allocating HW data
4265 ************************/
4267 /* Disabling hardware scan means that mac80211 will perform scans
4268 * "the hard way", rather than using device's scan. */
4269 if (cfg->mod_params->disable_hw_scan) {
4270 if (cfg->mod_params->debug & IWL_DL_INFO)
4271 dev_printk(KERN_DEBUG, &(pdev->dev),
4272 "Disabling hw_scan\n");
4273 iwl4965_hw_ops.hw_scan = NULL;
4276 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
4282 /* At this point both hw and priv are allocated. */
4284 SET_IEEE80211_DEV(hw, &pdev->dev);
4286 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
4288 priv->pci_dev = pdev;
4290 #ifdef CONFIG_IWLWIFI_DEBUG
4291 priv->debug_level = priv->cfg->mod_params->debug;
4292 atomic_set(&priv->restrict_refcnt, 0);
4295 /**************************
4296 * 2. Initializing PCI bus
4297 **************************/
4298 if (pci_enable_device(pdev)) {
4300 goto out_ieee80211_free_hw;
4303 pci_set_master(pdev);
4305 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
4307 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
4309 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4311 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4312 /* both attempts failed: */
4314 printk(KERN_WARNING "%s: No suitable DMA available.\n",
4316 goto out_pci_disable_device;
4320 err = pci_request_regions(pdev, DRV_NAME);
4322 goto out_pci_disable_device;
4324 pci_set_drvdata(pdev, priv);
4326 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4327 * PCI Tx retries from interfering with C3 CPU state */
4328 pci_write_config_byte(pdev, 0x41, 0x00);
4330 /***********************
4331 * 3. Read REV register
4332 ***********************/
4333 priv->hw_base = pci_iomap(pdev, 0, 0);
4334 if (!priv->hw_base) {
4336 goto out_pci_release_regions;
4339 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
4340 (unsigned long long) pci_resource_len(pdev, 0));
4341 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
4343 iwl_hw_detect(priv);
4344 printk(KERN_INFO DRV_NAME
4345 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
4346 priv->cfg->name, priv->hw_rev);
4349 err = priv->cfg->ops->lib->apm_ops.init(priv);
4351 IWL_DEBUG_INFO("Failed to init APMG\n");
4357 /* Read the EEPROM */
4358 err = iwl_eeprom_init(priv);
4360 IWL_ERROR("Unable to init EEPROM\n");
4363 err = iwl_eeprom_check_version(priv);
4367 /* extract MAC Address */
4368 iwl_eeprom_get_mac(priv, priv->mac_addr);
4369 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
4370 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4372 /************************
4373 * 5. Setup HW constants
4374 ************************/
4375 /* Device-specific setup */
4376 if (priv->cfg->ops->lib->set_hw_params(priv)) {
4377 IWL_ERROR("failed to set hw parameters\n");
4378 goto out_free_eeprom;
4381 /*******************
4383 *******************/
4385 err = iwl_init_drv(priv);
4387 goto out_free_eeprom;
4388 /* At this point both hw and priv are initialized. */
4390 /**********************************
4391 * 7. Initialize module parameters
4392 **********************************/
4394 /* Disable radio (SW RF KILL) via parameter when loading driver */
4395 if (priv->cfg->mod_params->disable) {
4396 set_bit(STATUS_RF_KILL_SW, &priv->status);
4397 IWL_DEBUG_INFO("Radio disabled.\n");
4400 /********************
4402 ********************/
4403 spin_lock_irqsave(&priv->lock, flags);
4404 iwl4965_disable_interrupts(priv);
4405 spin_unlock_irqrestore(&priv->lock, flags);
4407 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4409 IWL_ERROR("failed to create sysfs device attributes\n");
4410 goto out_uninit_drv;
4414 iwl_setup_deferred_work(priv);
4415 iwl4965_setup_rx_handlers(priv);
4417 /********************
4419 ********************/
4420 pci_save_state(pdev);
4421 pci_disable_device(pdev);
4423 /**********************************
4424 * 10. Setup and register mac80211
4425 **********************************/
4427 err = iwl_setup_mac(priv);
4429 goto out_remove_sysfs;
4431 err = iwl_dbgfs_register(priv, DRV_NAME);
4433 IWL_ERROR("failed to create debugfs files\n");
4435 err = iwl_rfkill_init(priv);
4437 IWL_ERROR("Unable to initialize RFKILL system. "
4438 "Ignoring error: %d\n", err);
4439 iwl_power_initialize(priv);
4443 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4445 iwl_uninit_drv(priv);
4447 iwl_eeprom_free(priv);
4449 pci_iounmap(pdev, priv->hw_base);
4450 out_pci_release_regions:
4451 pci_release_regions(pdev);
4452 pci_set_drvdata(pdev, NULL);
4453 out_pci_disable_device:
4454 pci_disable_device(pdev);
4455 out_ieee80211_free_hw:
4456 ieee80211_free_hw(priv->hw);
4461 static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
4463 struct iwl_priv *priv = pci_get_drvdata(pdev);
4464 struct list_head *p, *q;
4466 unsigned long flags;
4471 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4473 iwl_dbgfs_unregister(priv);
4474 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4476 if (priv->mac80211_registered) {
4477 ieee80211_unregister_hw(priv->hw);
4478 priv->mac80211_registered = 0;
4481 set_bit(STATUS_EXIT_PENDING, &priv->status);
4485 /* make sure we flush any pending irq or
4486 * tasklet for the driver
4488 spin_lock_irqsave(&priv->lock, flags);
4489 iwl4965_disable_interrupts(priv);
4490 spin_unlock_irqrestore(&priv->lock, flags);
4492 iwl_synchronize_irq(priv);
4494 /* Free MAC hash list for ADHOC */
4495 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
4496 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
4498 kfree(list_entry(p, struct iwl4965_ibss_seq, list));
4502 iwl_rfkill_unregister(priv);
4503 iwl4965_dealloc_ucode_pci(priv);
4506 iwl_rx_queue_free(priv, &priv->rxq);
4507 iwl_hw_txq_ctx_free(priv);
4509 iwlcore_clear_stations_table(priv);
4510 iwl_eeprom_free(priv);
4513 /*netif_stop_queue(dev); */
4514 flush_workqueue(priv->workqueue);
4516 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
4517 * priv->workqueue... so we can't take down the workqueue
4519 destroy_workqueue(priv->workqueue);
4520 priv->workqueue = NULL;
4522 pci_iounmap(pdev, priv->hw_base);
4523 pci_release_regions(pdev);
4524 pci_disable_device(pdev);
4525 pci_set_drvdata(pdev, NULL);
4527 iwl_uninit_drv(priv);
4529 if (priv->ibss_beacon)
4530 dev_kfree_skb(priv->ibss_beacon);
4532 ieee80211_free_hw(priv->hw);
4537 static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
4539 struct iwl_priv *priv = pci_get_drvdata(pdev);
4541 if (priv->is_open) {
4542 set_bit(STATUS_IN_SUSPEND, &priv->status);
4543 iwl4965_mac_stop(priv->hw);
4547 pci_set_power_state(pdev, PCI_D3hot);
4552 static int iwl4965_pci_resume(struct pci_dev *pdev)
4554 struct iwl_priv *priv = pci_get_drvdata(pdev);
4556 pci_set_power_state(pdev, PCI_D0);
4559 iwl4965_mac_start(priv->hw);
4561 clear_bit(STATUS_IN_SUSPEND, &priv->status);
4565 #endif /* CONFIG_PM */
4567 /*****************************************************************************
4569 * driver and module entry point
4571 *****************************************************************************/
4573 /* Hardware specific file defines the PCI IDs table for that hardware module */
4574 static struct pci_device_id iwl_hw_card_ids[] = {
4575 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4576 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
4577 #ifdef CONFIG_IWL5000
4578 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4579 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
4580 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
4581 #endif /* CONFIG_IWL5000 */
4584 MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4586 static struct pci_driver iwl_driver = {
4588 .id_table = iwl_hw_card_ids,
4589 .probe = iwl4965_pci_probe,
4590 .remove = __devexit_p(iwl4965_pci_remove),
4592 .suspend = iwl4965_pci_suspend,
4593 .resume = iwl4965_pci_resume,
4597 static int __init iwl4965_init(void)
4601 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4602 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
4604 ret = iwl4965_rate_control_register();
4606 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
4610 ret = pci_register_driver(&iwl_driver);
4612 IWL_ERROR("Unable to initialize PCI module\n");
4613 goto error_register;
4619 iwl4965_rate_control_unregister();
4623 static void __exit iwl4965_exit(void)
4625 pci_unregister_driver(&iwl_driver);
4626 iwl4965_rate_control_unregister();
4629 module_exit(iwl4965_exit);
4630 module_init(iwl4965_init);