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