1 /******************************************************************************
3 * Copyright(c) 2003 - 2009 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 * Intel Linux Wireless <ilw@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/init.h>
33 #include <linux/pci.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/delay.h>
36 #include <linux/skbuff.h>
37 #include <linux/netdevice.h>
38 #include <linux/wireless.h>
39 #include <linux/firmware.h>
40 #include <linux/etherdevice.h>
41 #include <linux/if_arp.h>
43 #include <net/ieee80211_radiotap.h>
44 #include <net/lib80211.h>
45 #include <net/mac80211.h>
47 #include <asm/div64.h>
49 #define DRV_NAME "iwl3945"
52 #include "iwl-3945-fh.h"
53 #include "iwl-commands.h"
56 #include "iwl-helpers.h"
61 * module name, copyright, version, etc.
64 #define DRV_DESCRIPTION \
65 "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
67 #ifdef CONFIG_IWLWIFI_DEBUG
73 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
79 #define IWL39_VERSION "1.2.26k" VD VS
80 #define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
81 #define DRV_AUTHOR "<ilw@linux.intel.com>"
82 #define DRV_VERSION IWL39_VERSION
85 MODULE_DESCRIPTION(DRV_DESCRIPTION);
86 MODULE_VERSION(DRV_VERSION);
87 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
88 MODULE_LICENSE("GPL");
90 /* module parameters */
91 struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
95 /* the rest are 0 by default */
98 /*************** STATION TABLE MANAGEMENT ****
99 * mac80211 should be examined to determine if sta_info is duplicating
100 * the functionality provided here
103 /**************************************************************/
104 #if 0 /* temporary disable till we add real remove station */
106 * iwl3945_remove_station - Remove driver's knowledge of station.
108 * NOTE: This does not remove station from device's station table.
110 static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
112 int index = IWL_INVALID_STATION;
116 spin_lock_irqsave(&priv->sta_lock, flags);
120 else if (is_broadcast_ether_addr(addr))
121 index = priv->hw_params.bcast_sta_id;
123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
131 if (unlikely(index == IWL_INVALID_STATION))
134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
136 priv->num_stations--;
139 BUG_ON(priv->num_stations < 0);
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
148 * iwl3945_clear_stations_table - Clear the driver's station table
150 * NOTE: This does not clear or otherwise alter the device's station table.
152 static void iwl3945_clear_stations_table(struct iwl_priv *priv)
156 spin_lock_irqsave(&priv->sta_lock, flags);
158 priv->num_stations = 0;
159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
165 * iwl3945_add_station - Add station to station tables in driver and device
167 u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
170 int index = IWL_INVALID_STATION;
171 struct iwl3945_station_entry *station;
172 unsigned long flags_spin;
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
178 else if (is_broadcast_ether_addr(addr))
179 index = priv->hw_params.bcast_sta_id;
181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
188 if (!priv->stations_39[i].used &&
189 index == IWL_INVALID_STATION)
193 /* These two conditions has the same outcome but keep them separate
194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
206 IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
207 station = &priv->stations_39[index];
209 priv->num_stations++;
211 /* Set up the REPLY_ADD_STA command to send to device */
212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
218 if (priv->band == IEEE80211_BAND_5GHZ)
219 rate = IWL_RATE_6M_PLCP;
221 rate = IWL_RATE_1M_PLCP;
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
229 /* Add station to device's station table */
230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
236 static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
239 struct iwl_rx_packet *res = NULL;
240 struct iwl3945_rxon_assoc_cmd rxon_assoc;
241 struct iwl_host_cmd cmd = {
242 .id = REPLY_RXON_ASSOC,
243 .len = sizeof(rxon_assoc),
244 .meta.flags = CMD_WANT_SKB,
247 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
248 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
250 if ((rxon1->flags == rxon2->flags) &&
251 (rxon1->filter_flags == rxon2->filter_flags) &&
252 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
253 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
254 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
258 rxon_assoc.flags = priv->staging_rxon.flags;
259 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
260 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
261 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
262 rxon_assoc.reserved = 0;
264 rc = iwl_send_cmd_sync(priv, &cmd);
268 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
269 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
270 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
274 priv->alloc_rxb_skb--;
275 dev_kfree_skb_any(cmd.meta.u.skb);
281 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
282 * @priv: eeprom and antenna fields are used to determine antenna flags
284 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
285 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
287 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
288 * IWL_ANTENNA_MAIN - Force MAIN antenna
289 * IWL_ANTENNA_AUX - Force AUX antenna
291 __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
293 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
295 switch (iwl3945_mod_params.antenna) {
296 case IWL_ANTENNA_DIVERSITY:
299 case IWL_ANTENNA_MAIN:
300 if (eeprom->antenna_switch_type)
301 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
302 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
304 case IWL_ANTENNA_AUX:
305 if (eeprom->antenna_switch_type)
306 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
307 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
310 /* bad antenna selector value */
311 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
312 iwl3945_mod_params.antenna);
314 return 0; /* "diversity" is default if error */
318 * iwl3945_commit_rxon - commit staging_rxon to hardware
320 * The RXON command in staging_rxon is committed to the hardware and
321 * the active_rxon structure is updated with the new data. This
322 * function correctly transitions out of the RXON_ASSOC_MSK state if
323 * a HW tune is required based on the RXON structure changes.
325 static int iwl3945_commit_rxon(struct iwl_priv *priv)
327 /* cast away the const for active_rxon in this function */
328 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
329 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
332 if (!iwl_is_alive(priv))
335 /* always get timestamp with Rx frame */
336 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
339 staging_rxon->flags &=
340 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
341 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
343 rc = iwl_check_rxon_cmd(priv);
345 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
349 /* If we don't need to send a full RXON, we can use
350 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
351 * and other flags for the current radio configuration. */
352 if (!iwl_full_rxon_required(priv)) {
353 rc = iwl3945_send_rxon_assoc(priv);
355 IWL_ERR(priv, "Error setting RXON_ASSOC "
356 "configuration (%d).\n", rc);
360 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
365 /* If we are currently associated and the new config requires
366 * an RXON_ASSOC and the new config wants the associated mask enabled,
367 * we must clear the associated from the active configuration
368 * before we apply the new config */
369 if (iwl_is_associated(priv) &&
370 (staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK)) {
371 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
372 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
375 * reserved4 and 5 could have been filled by the iwlcore code.
376 * Let's clear them before pushing to the 3945.
378 active_rxon->reserved4 = 0;
379 active_rxon->reserved5 = 0;
380 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
381 sizeof(struct iwl3945_rxon_cmd),
384 /* If the mask clearing failed then we set
385 * active_rxon back to what it was previously */
387 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
388 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
389 "configuration (%d).\n", rc);
394 IWL_DEBUG_INFO(priv, "Sending RXON\n"
395 "* with%s RXON_FILTER_ASSOC_MSK\n"
398 ((priv->staging_rxon.filter_flags &
399 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
400 le16_to_cpu(staging_rxon->channel),
401 staging_rxon->bssid_addr);
404 * reserved4 and 5 could have been filled by the iwlcore code.
405 * Let's clear them before pushing to the 3945.
407 staging_rxon->reserved4 = 0;
408 staging_rxon->reserved5 = 0;
410 /* Apply the new configuration */
411 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
412 sizeof(struct iwl3945_rxon_cmd),
415 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
419 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
421 iwl3945_clear_stations_table(priv);
423 /* If we issue a new RXON command which required a tune then we must
424 * send a new TXPOWER command or we won't be able to Tx any frames */
425 rc = priv->cfg->ops->lib->send_tx_power(priv);
427 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
431 /* Add the broadcast address so we can send broadcast frames */
432 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
433 IWL_INVALID_STATION) {
434 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
438 /* If we have set the ASSOC_MSK and we are in BSS mode then
439 * add the IWL_AP_ID to the station rate table */
440 if (iwl_is_associated(priv) &&
441 (priv->iw_mode == NL80211_IFTYPE_STATION))
442 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
444 == IWL_INVALID_STATION) {
445 IWL_ERR(priv, "Error adding AP address for transmit\n");
449 /* Init the hardware's rate fallback order based on the band */
450 rc = iwl3945_init_hw_rate_table(priv);
452 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
459 static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
460 struct ieee80211_key_conf *keyconf,
464 __le16 key_flags = 0;
466 switch (keyconf->alg) {
468 key_flags |= STA_KEY_FLG_CCMP;
469 key_flags |= cpu_to_le16(
470 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
471 key_flags &= ~STA_KEY_FLG_INVALID;
478 spin_lock_irqsave(&priv->sta_lock, flags);
479 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
480 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
481 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
484 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
486 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
487 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
488 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
490 spin_unlock_irqrestore(&priv->sta_lock, flags);
492 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
493 iwl_send_add_sta(priv,
494 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
498 static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
502 spin_lock_irqsave(&priv->sta_lock, flags);
503 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
504 memset(&priv->stations_39[sta_id].sta.key, 0,
505 sizeof(struct iwl4965_keyinfo));
506 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
507 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
508 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
509 spin_unlock_irqrestore(&priv->sta_lock, flags);
511 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
512 iwl_send_add_sta(priv,
513 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
517 static void iwl3945_clear_free_frames(struct iwl_priv *priv)
519 struct list_head *element;
521 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
524 while (!list_empty(&priv->free_frames)) {
525 element = priv->free_frames.next;
527 kfree(list_entry(element, struct iwl3945_frame, list));
528 priv->frames_count--;
531 if (priv->frames_count) {
532 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
534 priv->frames_count = 0;
538 static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
540 struct iwl3945_frame *frame;
541 struct list_head *element;
542 if (list_empty(&priv->free_frames)) {
543 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
545 IWL_ERR(priv, "Could not allocate frame!\n");
549 priv->frames_count++;
553 element = priv->free_frames.next;
555 return list_entry(element, struct iwl3945_frame, list);
558 static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
560 memset(frame, 0, sizeof(*frame));
561 list_add(&frame->list, &priv->free_frames);
564 unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
565 struct ieee80211_hdr *hdr,
569 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
570 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
571 (priv->iw_mode != NL80211_IFTYPE_AP)))
574 if (priv->ibss_beacon->len > left)
577 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
579 return priv->ibss_beacon->len;
582 static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
584 struct iwl3945_frame *frame;
585 unsigned int frame_size;
589 frame = iwl3945_get_free_frame(priv);
592 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
597 rate = iwl_rate_get_lowest_plcp(priv);
599 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
601 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
604 iwl3945_free_frame(priv, frame);
609 static void iwl3945_unset_hw_params(struct iwl_priv *priv)
611 if (priv->shared_virt)
612 pci_free_consistent(priv->pci_dev,
613 sizeof(struct iwl3945_shared),
621 static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
622 struct iwl_qosparam_cmd *qos)
625 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
626 sizeof(struct iwl_qosparam_cmd), qos);
629 static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
633 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
636 spin_lock_irqsave(&priv->lock, flags);
637 priv->qos_data.def_qos_parm.qos_flags = 0;
639 if (priv->qos_data.qos_cap.q_AP.queue_request &&
640 !priv->qos_data.qos_cap.q_AP.txop_request)
641 priv->qos_data.def_qos_parm.qos_flags |=
642 QOS_PARAM_FLG_TXOP_TYPE_MSK;
644 if (priv->qos_data.qos_active)
645 priv->qos_data.def_qos_parm.qos_flags |=
646 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
648 spin_unlock_irqrestore(&priv->lock, flags);
650 if (force || iwl_is_associated(priv)) {
651 IWL_DEBUG_QOS(priv, "send QoS cmd with QoS active %d \n",
652 priv->qos_data.qos_active);
654 iwl3945_send_qos_params_command(priv,
655 &(priv->qos_data.def_qos_parm));
660 #define MAX_UCODE_BEACON_INTERVAL 1024
661 #define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
663 static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
666 u16 beacon_factor = 0;
669 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
670 / MAX_UCODE_BEACON_INTERVAL;
671 new_val = beacon_val / beacon_factor;
673 return cpu_to_le16(new_val);
676 static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
678 u64 interval_tm_unit;
681 struct ieee80211_conf *conf = NULL;
684 conf = ieee80211_get_hw_conf(priv->hw);
686 spin_lock_irqsave(&priv->lock, flags);
687 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
688 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
690 tsf = priv->timestamp;
692 beacon_int = priv->beacon_int;
693 spin_unlock_irqrestore(&priv->lock, flags);
695 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
696 if (beacon_int == 0) {
697 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
698 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
700 priv->rxon_timing.beacon_interval =
701 cpu_to_le16(beacon_int);
702 priv->rxon_timing.beacon_interval =
703 iwl3945_adjust_beacon_interval(
704 le16_to_cpu(priv->rxon_timing.beacon_interval));
707 priv->rxon_timing.atim_window = 0;
709 priv->rxon_timing.beacon_interval =
710 iwl3945_adjust_beacon_interval(conf->beacon_int);
711 /* TODO: we need to get atim_window from upper stack
712 * for now we set to 0 */
713 priv->rxon_timing.atim_window = 0;
717 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
718 result = do_div(tsf, interval_tm_unit);
719 priv->rxon_timing.beacon_init_val =
720 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
722 IWL_DEBUG_ASSOC(priv,
723 "beacon interval %d beacon timer %d beacon tim %d\n",
724 le16_to_cpu(priv->rxon_timing.beacon_interval),
725 le32_to_cpu(priv->rxon_timing.beacon_init_val),
726 le16_to_cpu(priv->rxon_timing.atim_window));
729 static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
731 if (mode == NL80211_IFTYPE_ADHOC) {
732 const struct iwl_channel_info *ch_info;
734 ch_info = iwl_get_channel_info(priv,
736 le16_to_cpu(priv->staging_rxon.channel));
738 if (!ch_info || !is_channel_ibss(ch_info)) {
739 IWL_ERR(priv, "channel %d not IBSS channel\n",
740 le16_to_cpu(priv->staging_rxon.channel));
745 iwl_connection_init_rx_config(priv, mode);
747 iwl3945_clear_stations_table(priv);
749 /* don't commit rxon if rf-kill is on*/
750 if (!iwl_is_ready_rf(priv))
753 cancel_delayed_work(&priv->scan_check);
754 if (iwl_scan_cancel_timeout(priv, 100)) {
755 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
756 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
760 iwl3945_commit_rxon(priv);
765 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
766 struct ieee80211_tx_info *info,
768 struct sk_buff *skb_frag,
771 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
772 struct iwl3945_hw_key *keyinfo =
773 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
775 switch (keyinfo->alg) {
777 tx->sec_ctl = TX_CMD_SEC_CCM;
778 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
779 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
784 tx->sec_ctl = TX_CMD_SEC_TKIP;
787 memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
790 memset(tx->tkip_mic.byte, 0, 8);
795 tx->sec_ctl = TX_CMD_SEC_WEP |
796 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
798 if (keyinfo->keylen == 13)
799 tx->sec_ctl |= TX_CMD_SEC_KEY128;
801 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
803 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
804 "with key %d\n", info->control.hw_key->hw_key_idx);
808 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
814 * handle build REPLY_TX command notification.
816 static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
818 struct ieee80211_tx_info *info,
819 struct ieee80211_hdr *hdr, u8 std_id)
821 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
822 __le32 tx_flags = tx->tx_flags;
823 __le16 fc = hdr->frame_control;
824 u8 rc_flags = info->control.rates[0].flags;
826 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
827 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
828 tx_flags |= TX_CMD_FLG_ACK_MSK;
829 if (ieee80211_is_mgmt(fc))
830 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
831 if (ieee80211_is_probe_resp(fc) &&
832 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
833 tx_flags |= TX_CMD_FLG_TSF_MSK;
835 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
836 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
840 if (ieee80211_has_morefrags(fc))
841 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
843 if (ieee80211_is_data_qos(fc)) {
844 u8 *qc = ieee80211_get_qos_ctl(hdr);
845 tx->tid_tspec = qc[0] & 0xf;
846 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
848 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
851 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
852 tx_flags |= TX_CMD_FLG_RTS_MSK;
853 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
854 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
855 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
856 tx_flags |= TX_CMD_FLG_CTS_MSK;
859 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
860 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
862 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
863 if (ieee80211_is_mgmt(fc)) {
864 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
865 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
867 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
869 tx->timeout.pm_frame_timeout = 0;
870 #ifdef CONFIG_IWL3945_LEDS
871 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
876 tx->tx_flags = tx_flags;
877 tx->next_frame_len = 0;
881 * iwl3945_get_sta_id - Find station's index within station table
883 static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
886 u16 fc = le16_to_cpu(hdr->frame_control);
888 /* If this frame is broadcast or management, use broadcast station id */
889 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
890 is_multicast_ether_addr(hdr->addr1))
891 return priv->hw_params.bcast_sta_id;
893 switch (priv->iw_mode) {
895 /* If we are a client station in a BSS network, use the special
896 * AP station entry (that's the only station we communicate with) */
897 case NL80211_IFTYPE_STATION:
900 /* If we are an AP, then find the station, or use BCAST */
901 case NL80211_IFTYPE_AP:
902 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
903 if (sta_id != IWL_INVALID_STATION)
905 return priv->hw_params.bcast_sta_id;
907 /* If this frame is going out to an IBSS network, find the station,
908 * or create a new station table entry */
909 case NL80211_IFTYPE_ADHOC: {
910 /* Create new station table entry */
911 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
912 if (sta_id != IWL_INVALID_STATION)
915 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
917 if (sta_id != IWL_INVALID_STATION)
920 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
921 "Defaulting to broadcast...\n",
923 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
924 return priv->hw_params.bcast_sta_id;
926 /* If we are in monitor mode, use BCAST. This is required for
927 * packet injection. */
928 case NL80211_IFTYPE_MONITOR:
929 return priv->hw_params.bcast_sta_id;
932 IWL_WARN(priv, "Unknown mode of operation: %d\n",
934 return priv->hw_params.bcast_sta_id;
939 * start REPLY_TX command process
941 static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
943 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
944 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
945 struct iwl3945_tx_cmd *tx;
946 struct iwl_tx_queue *txq = NULL;
947 struct iwl_queue *q = NULL;
948 struct iwl_cmd *out_cmd = NULL;
949 dma_addr_t phys_addr;
950 dma_addr_t txcmd_phys;
951 int txq_id = skb_get_queue_mapping(skb);
952 u16 len, idx, len_org, hdr_len;
959 u8 wait_write_ptr = 0;
964 spin_lock_irqsave(&priv->lock, flags);
965 if (iwl_is_rfkill(priv)) {
966 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
970 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
971 IWL_ERR(priv, "ERROR: No TX rate available.\n");
975 unicast = !is_multicast_ether_addr(hdr->addr1);
978 fc = hdr->frame_control;
980 #ifdef CONFIG_IWLWIFI_DEBUG
981 if (ieee80211_is_auth(fc))
982 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
983 else if (ieee80211_is_assoc_req(fc))
984 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
985 else if (ieee80211_is_reassoc_req(fc))
986 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
989 /* drop all data frame if we are not associated */
990 if (ieee80211_is_data(fc) &&
991 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
992 (!iwl_is_associated(priv) ||
993 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
994 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
998 spin_unlock_irqrestore(&priv->lock, flags);
1000 hdr_len = ieee80211_hdrlen(fc);
1002 /* Find (or create) index into station table for destination station */
1003 sta_id = iwl3945_get_sta_id(priv, hdr);
1004 if (sta_id == IWL_INVALID_STATION) {
1005 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
1010 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
1012 if (ieee80211_is_data_qos(fc)) {
1013 qc = ieee80211_get_qos_ctl(hdr);
1014 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1015 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
1017 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1019 cpu_to_le16(IEEE80211_SCTL_FRAG));
1023 /* Descriptor for chosen Tx queue */
1024 txq = &priv->txq[txq_id];
1027 spin_lock_irqsave(&priv->lock, flags);
1029 idx = get_cmd_index(q, q->write_ptr, 0);
1031 /* Set up driver data for this TFD */
1032 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
1033 txq->txb[q->write_ptr].skb[0] = skb;
1035 /* Init first empty entry in queue's array of Tx/cmd buffers */
1036 out_cmd = txq->cmd[idx];
1037 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
1038 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
1039 memset(tx, 0, sizeof(*tx));
1042 * Set up the Tx-command (not MAC!) header.
1043 * Store the chosen Tx queue and TFD index within the sequence field;
1044 * after Tx, uCode's Tx response will return this value so driver can
1045 * locate the frame within the tx queue and do post-tx processing.
1047 out_cmd->hdr.cmd = REPLY_TX;
1048 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
1049 INDEX_TO_SEQ(q->write_ptr)));
1051 /* Copy MAC header from skb into command buffer */
1052 memcpy(tx->hdr, hdr, hdr_len);
1055 * Use the first empty entry in this queue's command buffer array
1056 * to contain the Tx command and MAC header concatenated together
1057 * (payload data will be in another buffer).
1058 * Size of this varies, due to varying MAC header length.
1059 * If end is not dword aligned, we'll have 2 extra bytes at the end
1060 * of the MAC header (device reads on dword boundaries).
1061 * We'll tell device about this padding later.
1063 len = sizeof(struct iwl3945_tx_cmd) +
1064 sizeof(struct iwl_cmd_header) + hdr_len;
1067 len = (len + 3) & ~3;
1074 /* Physical address of this Tx command's header (not MAC header!),
1075 * within command buffer array. */
1076 txcmd_phys = pci_map_single(priv->pci_dev,
1077 out_cmd, sizeof(struct iwl_cmd),
1079 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1080 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1081 /* Add buffer containing Tx command and MAC(!) header to TFD's
1083 txcmd_phys += offsetof(struct iwl_cmd, hdr);
1085 /* Add buffer containing Tx command and MAC(!) header to TFD's
1087 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1088 txcmd_phys, len, 1, 0);
1090 if (info->control.hw_key)
1091 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
1093 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1094 * if any (802.11 null frames have no payload). */
1095 len = skb->len - hdr_len;
1097 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1098 len, PCI_DMA_TODEVICE);
1099 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1104 /* Total # bytes to be transmitted */
1105 len = (u16)skb->len;
1106 tx->len = cpu_to_le16(len);
1108 /* TODO need this for burst mode later on */
1109 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
1111 /* set is_hcca to 0; it probably will never be implemented */
1112 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
1114 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1115 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
1117 if (!ieee80211_has_morefrags(hdr->frame_control)) {
1118 txq->need_update = 1;
1120 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
1123 txq->need_update = 0;
1126 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
1128 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
1129 ieee80211_hdrlen(fc));
1131 /* Tell device the write index *just past* this latest filled TFD */
1132 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
1133 rc = iwl_txq_update_write_ptr(priv, txq);
1134 spin_unlock_irqrestore(&priv->lock, flags);
1139 if ((iwl_queue_space(q) < q->high_mark)
1140 && priv->mac80211_registered) {
1141 if (wait_write_ptr) {
1142 spin_lock_irqsave(&priv->lock, flags);
1143 txq->need_update = 1;
1144 iwl_txq_update_write_ptr(priv, txq);
1145 spin_unlock_irqrestore(&priv->lock, flags);
1148 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
1154 spin_unlock_irqrestore(&priv->lock, flags);
1159 static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
1161 unsigned long flags;
1163 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
1166 IWL_DEBUG_RF_KILL(priv, "Manual SW RF KILL set to: RADIO %s\n",
1167 disable_radio ? "OFF" : "ON");
1169 if (disable_radio) {
1170 iwl_scan_cancel(priv);
1171 /* FIXME: This is a workaround for AP */
1172 if (priv->iw_mode != NL80211_IFTYPE_AP) {
1173 spin_lock_irqsave(&priv->lock, flags);
1174 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
1175 CSR_UCODE_SW_BIT_RFKILL);
1176 spin_unlock_irqrestore(&priv->lock, flags);
1177 iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
1178 set_bit(STATUS_RF_KILL_SW, &priv->status);
1183 spin_lock_irqsave(&priv->lock, flags);
1184 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
1186 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1187 spin_unlock_irqrestore(&priv->lock, flags);
1192 spin_lock_irqsave(&priv->lock, flags);
1193 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1194 if (!iwl_grab_nic_access(priv))
1195 iwl_release_nic_access(priv);
1196 spin_unlock_irqrestore(&priv->lock, flags);
1198 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
1199 IWL_DEBUG_RF_KILL(priv, "Can not turn radio back on - "
1200 "disabled by HW switch\n");
1205 queue_work(priv->workqueue, &priv->restart);
1209 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
1211 #include "iwl-spectrum.h"
1213 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
1214 #define BEACON_TIME_MASK_HIGH 0xFF000000
1215 #define TIME_UNIT 1024
1218 * extended beacon time format
1219 * time in usec will be changed into a 32-bit value in 8:24 format
1220 * the high 1 byte is the beacon counts
1221 * the lower 3 bytes is the time in usec within one beacon interval
1224 static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
1228 u32 interval = beacon_interval * 1024;
1230 if (!interval || !usec)
1233 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1234 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1236 return (quot << 24) + rem;
1239 /* base is usually what we get from ucode with each received frame,
1240 * the same as HW timer counter counting down
1243 static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
1245 u32 base_low = base & BEACON_TIME_MASK_LOW;
1246 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1247 u32 interval = beacon_interval * TIME_UNIT;
1248 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1249 (addon & BEACON_TIME_MASK_HIGH);
1251 if (base_low > addon_low)
1252 res += base_low - addon_low;
1253 else if (base_low < addon_low) {
1254 res += interval + base_low - addon_low;
1259 return cpu_to_le32(res);
1262 static int iwl3945_get_measurement(struct iwl_priv *priv,
1263 struct ieee80211_measurement_params *params,
1266 struct iwl_spectrum_cmd spectrum;
1267 struct iwl_rx_packet *res;
1268 struct iwl_host_cmd cmd = {
1269 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1270 .data = (void *)&spectrum,
1271 .meta.flags = CMD_WANT_SKB,
1273 u32 add_time = le64_to_cpu(params->start_time);
1275 int spectrum_resp_status;
1276 int duration = le16_to_cpu(params->duration);
1278 if (iwl_is_associated(priv))
1280 iwl3945_usecs_to_beacons(
1281 le64_to_cpu(params->start_time) - priv->last_tsf,
1282 le16_to_cpu(priv->rxon_timing.beacon_interval));
1284 memset(&spectrum, 0, sizeof(spectrum));
1286 spectrum.channel_count = cpu_to_le16(1);
1288 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1289 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1290 cmd.len = sizeof(spectrum);
1291 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1293 if (iwl_is_associated(priv))
1294 spectrum.start_time =
1295 iwl3945_add_beacon_time(priv->last_beacon_time,
1297 le16_to_cpu(priv->rxon_timing.beacon_interval));
1299 spectrum.start_time = 0;
1301 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1302 spectrum.channels[0].channel = params->channel;
1303 spectrum.channels[0].type = type;
1304 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
1305 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1306 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1308 rc = iwl_send_cmd_sync(priv, &cmd);
1312 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
1313 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1314 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
1318 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1319 switch (spectrum_resp_status) {
1320 case 0: /* Command will be handled */
1321 if (res->u.spectrum.id != 0xff) {
1322 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
1323 res->u.spectrum.id);
1324 priv->measurement_status &= ~MEASUREMENT_READY;
1326 priv->measurement_status |= MEASUREMENT_ACTIVE;
1330 case 1: /* Command will not be handled */
1335 dev_kfree_skb_any(cmd.meta.u.skb);
1341 static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
1342 struct iwl_rx_mem_buffer *rxb)
1344 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1345 struct iwl_alive_resp *palive;
1346 struct delayed_work *pwork;
1348 palive = &pkt->u.alive_frame;
1350 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
1352 palive->is_valid, palive->ver_type,
1353 palive->ver_subtype);
1355 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1356 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
1357 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1358 sizeof(struct iwl_alive_resp));
1359 pwork = &priv->init_alive_start;
1361 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
1362 memcpy(&priv->card_alive, &pkt->u.alive_frame,
1363 sizeof(struct iwl_alive_resp));
1364 pwork = &priv->alive_start;
1365 iwl3945_disable_events(priv);
1368 /* We delay the ALIVE response by 5ms to
1369 * give the HW RF Kill time to activate... */
1370 if (palive->is_valid == UCODE_VALID_OK)
1371 queue_delayed_work(priv->workqueue, pwork,
1372 msecs_to_jiffies(5));
1374 IWL_WARN(priv, "uCode did not respond OK.\n");
1377 static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
1378 struct iwl_rx_mem_buffer *rxb)
1380 #ifdef CONFIG_IWLWIFI_DEBUG
1381 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1384 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
1388 static void iwl3945_bg_beacon_update(struct work_struct *work)
1390 struct iwl_priv *priv =
1391 container_of(work, struct iwl_priv, beacon_update);
1392 struct sk_buff *beacon;
1394 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
1395 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
1398 IWL_ERR(priv, "update beacon failed\n");
1402 mutex_lock(&priv->mutex);
1403 /* new beacon skb is allocated every time; dispose previous.*/
1404 if (priv->ibss_beacon)
1405 dev_kfree_skb(priv->ibss_beacon);
1407 priv->ibss_beacon = beacon;
1408 mutex_unlock(&priv->mutex);
1410 iwl3945_send_beacon_cmd(priv);
1413 static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
1414 struct iwl_rx_mem_buffer *rxb)
1416 #ifdef CONFIG_IWLWIFI_DEBUG
1417 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1418 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
1419 u8 rate = beacon->beacon_notify_hdr.rate;
1421 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
1422 "tsf %d %d rate %d\n",
1423 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1424 beacon->beacon_notify_hdr.failure_frame,
1425 le32_to_cpu(beacon->ibss_mgr_status),
1426 le32_to_cpu(beacon->high_tsf),
1427 le32_to_cpu(beacon->low_tsf), rate);
1430 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
1431 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1432 queue_work(priv->workqueue, &priv->beacon_update);
1435 /* Handle notification from uCode that card's power state is changing
1436 * due to software, hardware, or critical temperature RFKILL */
1437 static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
1438 struct iwl_rx_mem_buffer *rxb)
1440 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1441 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1442 unsigned long status = priv->status;
1444 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
1445 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1446 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1448 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
1449 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1451 if (flags & HW_CARD_DISABLED)
1452 set_bit(STATUS_RF_KILL_HW, &priv->status);
1454 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1457 if (flags & SW_CARD_DISABLED)
1458 set_bit(STATUS_RF_KILL_SW, &priv->status);
1460 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1462 iwl_scan_cancel(priv);
1464 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1465 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1466 (test_bit(STATUS_RF_KILL_SW, &status) !=
1467 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1468 queue_work(priv->workqueue, &priv->rf_kill);
1470 wake_up_interruptible(&priv->wait_command_queue);
1474 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
1476 * Setup the RX handlers for each of the reply types sent from the uCode
1479 * This function chains into the hardware specific files for them to setup
1480 * any hardware specific handlers as well.
1482 static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
1484 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1485 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
1486 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
1487 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
1488 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
1489 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
1490 iwl_rx_pm_debug_statistics_notif;
1491 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
1494 * The same handler is used for both the REPLY to a discrete
1495 * statistics request from the host as well as for the periodic
1496 * statistics notifications (after received beacons) from the uCode.
1498 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1499 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
1501 iwl_setup_spectrum_handlers(priv);
1502 iwl_setup_rx_scan_handlers(priv);
1503 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
1505 /* Set up hardware specific Rx handlers */
1506 iwl3945_hw_rx_handler_setup(priv);
1510 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1511 * When FW advances 'R' index, all entries between old and new 'R' index
1512 * need to be reclaimed.
1514 static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
1515 int txq_id, int index)
1517 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1518 struct iwl_queue *q = &txq->q;
1521 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
1522 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
1523 "is out of range [0-%d] %d %d.\n", txq_id,
1524 index, q->n_bd, q->write_ptr, q->read_ptr);
1528 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1529 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1531 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
1532 q->write_ptr, q->read_ptr);
1533 queue_work(priv->workqueue, &priv->restart);
1542 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
1543 * @rxb: Rx buffer to reclaim
1545 * If an Rx buffer has an async callback associated with it the callback
1546 * will be executed. The attached skb (if present) will only be freed
1547 * if the callback returns 1
1549 static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
1550 struct iwl_rx_mem_buffer *rxb)
1552 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1553 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1554 int txq_id = SEQ_TO_QUEUE(sequence);
1555 int index = SEQ_TO_INDEX(sequence);
1556 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
1558 struct iwl_cmd *cmd;
1560 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1561 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1563 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1564 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1565 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1569 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1570 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
1572 /* Input error checking is done when commands are added to queue. */
1573 if (cmd->meta.flags & CMD_WANT_SKB) {
1574 cmd->meta.source->u.skb = rxb->skb;
1576 } else if (cmd->meta.u.callback &&
1577 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1580 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
1582 if (!(cmd->meta.flags & CMD_ASYNC)) {
1583 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1584 wake_up_interruptible(&priv->wait_command_queue);
1588 /************************** RX-FUNCTIONS ****************************/
1590 * Rx theory of operation
1592 * The host allocates 32 DMA target addresses and passes the host address
1593 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1597 * The host/firmware share two index registers for managing the Rx buffers.
1599 * The READ index maps to the first position that the firmware may be writing
1600 * to -- the driver can read up to (but not including) this position and get
1602 * The READ index is managed by the firmware once the card is enabled.
1604 * The WRITE index maps to the last position the driver has read from -- the
1605 * position preceding WRITE is the last slot the firmware can place a packet.
1607 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1610 * During initialization, the host sets up the READ queue position to the first
1611 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1613 * When the firmware places a packet in a buffer, it will advance the READ index
1614 * and fire the RX interrupt. The driver can then query the READ index and
1615 * process as many packets as possible, moving the WRITE index forward as it
1616 * resets the Rx queue buffers with new memory.
1618 * The management in the driver is as follows:
1619 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1620 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
1621 * to replenish the iwl->rxq->rx_free.
1622 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
1623 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1624 * 'processed' and 'read' driver indexes as well)
1625 * + A received packet is processed and handed to the kernel network stack,
1626 * detached from the iwl->rxq. The driver 'processed' index is updated.
1627 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1628 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1629 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1630 * were enough free buffers and RX_STALLED is set it is cleared.
1635 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
1636 * iwl3945_rx_queue_restock
1637 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
1638 * queue, updates firmware pointers, and updates
1639 * the WRITE index. If insufficient rx_free buffers
1640 * are available, schedules iwl3945_rx_replenish
1642 * -- enable interrupts --
1643 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
1644 * READ INDEX, detaching the SKB from the pool.
1645 * Moves the packet buffer from queue to rx_used.
1646 * Calls iwl3945_rx_queue_restock to refill any empty
1653 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
1655 static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
1656 dma_addr_t dma_addr)
1658 return cpu_to_le32((u32)dma_addr);
1662 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
1664 * If there are slots in the RX queue that need to be restocked,
1665 * and we have free pre-allocated buffers, fill the ranks as much
1666 * as we can, pulling from rx_free.
1668 * This moves the 'write' index forward to catch up with 'processed', and
1669 * also updates the memory address in the firmware to reference the new
1672 static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
1674 struct iwl_rx_queue *rxq = &priv->rxq;
1675 struct list_head *element;
1676 struct iwl_rx_mem_buffer *rxb;
1677 unsigned long flags;
1680 spin_lock_irqsave(&rxq->lock, flags);
1681 write = rxq->write & ~0x7;
1682 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
1683 /* Get next free Rx buffer, remove from free list */
1684 element = rxq->rx_free.next;
1685 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
1688 /* Point to Rx buffer via next RBD in circular buffer */
1689 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
1690 rxq->queue[rxq->write] = rxb;
1691 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1694 spin_unlock_irqrestore(&rxq->lock, flags);
1695 /* If the pre-allocated buffer pool is dropping low, schedule to
1697 if (rxq->free_count <= RX_LOW_WATERMARK)
1698 queue_work(priv->workqueue, &priv->rx_replenish);
1701 /* If we've added more space for the firmware to place data, tell it.
1702 * Increment device's write pointer in multiples of 8. */
1703 if ((write != (rxq->write & ~0x7))
1704 || (abs(rxq->write - rxq->read) > 7)) {
1705 spin_lock_irqsave(&rxq->lock, flags);
1706 rxq->need_update = 1;
1707 spin_unlock_irqrestore(&rxq->lock, flags);
1708 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
1717 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
1719 * When moving to rx_free an SKB is allocated for the slot.
1721 * Also restock the Rx queue via iwl3945_rx_queue_restock.
1722 * This is called as a scheduled work item (except for during initialization)
1724 static void iwl3945_rx_allocate(struct iwl_priv *priv)
1726 struct iwl_rx_queue *rxq = &priv->rxq;
1727 struct list_head *element;
1728 struct iwl_rx_mem_buffer *rxb;
1729 unsigned long flags;
1730 spin_lock_irqsave(&rxq->lock, flags);
1731 while (!list_empty(&rxq->rx_used)) {
1732 element = rxq->rx_used.next;
1733 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
1735 /* Alloc a new receive buffer */
1737 alloc_skb(priv->hw_params.rx_buf_size,
1738 __GFP_NOWARN | GFP_ATOMIC);
1740 if (net_ratelimit())
1741 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
1742 /* We don't reschedule replenish work here -- we will
1743 * call the restock method and if it still needs
1744 * more buffers it will schedule replenish */
1748 /* If radiotap head is required, reserve some headroom here.
1749 * The physical head count is a variable rx_stats->phy_count.
1750 * We reserve 4 bytes here. Plus these extra bytes, the
1751 * headroom of the physical head should be enough for the
1752 * radiotap head that iwl3945 supported. See iwl3945_rt.
1754 skb_reserve(rxb->skb, 4);
1756 priv->alloc_rxb_skb++;
1759 /* Get physical address of RB/SKB */
1760 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1762 priv->hw_params.rx_buf_size,
1763 PCI_DMA_FROMDEVICE);
1764 list_add_tail(&rxb->list, &rxq->rx_free);
1767 spin_unlock_irqrestore(&rxq->lock, flags);
1771 * this should be called while priv->lock is locked
1773 static void __iwl3945_rx_replenish(void *data)
1775 struct iwl_priv *priv = data;
1777 iwl3945_rx_allocate(priv);
1778 iwl3945_rx_queue_restock(priv);
1782 void iwl3945_rx_replenish(void *data)
1784 struct iwl_priv *priv = data;
1785 unsigned long flags;
1787 iwl3945_rx_allocate(priv);
1789 spin_lock_irqsave(&priv->lock, flags);
1790 iwl3945_rx_queue_restock(priv);
1791 spin_unlock_irqrestore(&priv->lock, flags);
1794 /* Convert linear signal-to-noise ratio into dB */
1795 static u8 ratio2dB[100] = {
1796 /* 0 1 2 3 4 5 6 7 8 9 */
1797 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1798 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1799 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1800 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1801 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1802 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1803 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1804 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1805 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1806 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1809 /* Calculates a relative dB value from a ratio of linear
1810 * (i.e. not dB) signal levels.
1811 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
1812 int iwl3945_calc_db_from_ratio(int sig_ratio)
1814 /* 1000:1 or higher just report as 60 dB */
1815 if (sig_ratio >= 1000)
1818 /* 100:1 or higher, divide by 10 and use table,
1819 * add 20 dB to make up for divide by 10 */
1820 if (sig_ratio >= 100)
1821 return 20 + (int)ratio2dB[sig_ratio/10];
1823 /* We shouldn't see this */
1827 /* Use table for ratios 1:1 - 99:1 */
1828 return (int)ratio2dB[sig_ratio];
1831 #define PERFECT_RSSI (-20) /* dBm */
1832 #define WORST_RSSI (-95) /* dBm */
1833 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1835 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
1836 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1837 * about formulas used below. */
1838 int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
1841 int degradation = PERFECT_RSSI - rssi_dbm;
1843 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1844 * as indicator; formula is (signal dbm - noise dbm).
1845 * SNR at or above 40 is a great signal (100%).
1846 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1847 * Weakest usable signal is usually 10 - 15 dB SNR. */
1849 if (rssi_dbm - noise_dbm >= 40)
1851 else if (rssi_dbm < noise_dbm)
1853 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1855 /* Else use just the signal level.
1856 * This formula is a least squares fit of data points collected and
1857 * compared with a reference system that had a percentage (%) display
1858 * for signal quality. */
1860 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1861 (15 * RSSI_RANGE + 62 * degradation)) /
1862 (RSSI_RANGE * RSSI_RANGE);
1866 else if (sig_qual < 1)
1873 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
1875 * Uses the priv->rx_handlers callback function array to invoke
1876 * the appropriate handlers, including command responses,
1877 * frame-received notifications, and other notifications.
1879 static void iwl3945_rx_handle(struct iwl_priv *priv)
1881 struct iwl_rx_mem_buffer *rxb;
1882 struct iwl_rx_packet *pkt;
1883 struct iwl_rx_queue *rxq = &priv->rxq;
1886 unsigned long flags;
1890 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1891 * buffer that the driver may process (last buffer filled by ucode). */
1892 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
1895 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
1897 /* Rx interrupt, but nothing sent from uCode */
1899 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
1902 rxb = rxq->queue[i];
1904 /* If an RXB doesn't have a Rx queue slot associated with it,
1905 * then a bug has been introduced in the queue refilling
1906 * routines -- catch it here */
1907 BUG_ON(rxb == NULL);
1909 rxq->queue[i] = NULL;
1911 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
1912 priv->hw_params.rx_buf_size,
1913 PCI_DMA_FROMDEVICE);
1914 pkt = (struct iwl_rx_packet *)rxb->skb->data;
1916 /* Reclaim a command buffer only if this packet is a response
1917 * to a (driver-originated) command.
1918 * If the packet (e.g. Rx frame) originated from uCode,
1919 * there is no command buffer to reclaim.
1920 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1921 * but apparently a few don't get set; catch them here. */
1922 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1923 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1924 (pkt->hdr.cmd != REPLY_TX);
1926 /* Based on type of command response or notification,
1927 * handle those that need handling via function in
1928 * rx_handlers table. See iwl3945_setup_rx_handlers() */
1929 if (priv->rx_handlers[pkt->hdr.cmd]) {
1930 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
1931 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1932 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1933 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1935 /* No handling needed */
1936 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
1937 "r %d i %d No handler needed for %s, 0x%02x\n",
1938 r, i, get_cmd_string(pkt->hdr.cmd),
1943 /* Invoke any callbacks, transfer the skb to caller, and
1944 * fire off the (possibly) blocking iwl_send_cmd()
1945 * as we reclaim the driver command queue */
1946 if (rxb && rxb->skb)
1947 iwl3945_tx_cmd_complete(priv, rxb);
1949 IWL_WARN(priv, "Claim null rxb?\n");
1952 /* For now we just don't re-use anything. We can tweak this
1953 * later to try and re-use notification packets and SKBs that
1954 * fail to Rx correctly */
1955 if (rxb->skb != NULL) {
1956 priv->alloc_rxb_skb--;
1957 dev_kfree_skb_any(rxb->skb);
1961 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1962 priv->hw_params.rx_buf_size,
1963 PCI_DMA_FROMDEVICE);
1964 spin_lock_irqsave(&rxq->lock, flags);
1965 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1966 spin_unlock_irqrestore(&rxq->lock, flags);
1967 i = (i + 1) & RX_QUEUE_MASK;
1968 /* If there are a lot of unused frames,
1969 * restock the Rx queue so ucode won't assert. */
1974 __iwl3945_rx_replenish(priv);
1980 /* Backtrack one entry */
1982 iwl3945_rx_queue_restock(priv);
1985 /* call this function to flush any scheduled tasklet */
1986 static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1988 /* wait to make sure we flush pending tasklet*/
1989 synchronize_irq(priv->pci_dev->irq);
1990 tasklet_kill(&priv->irq_tasklet);
1993 static const char *desc_lookup(int i)
2001 return "BAD_CHECKSUM";
2003 return "NMI_INTERRUPT";
2007 return "FATAL_ERROR";
2013 #define ERROR_START_OFFSET (1 * sizeof(u32))
2014 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
2016 static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
2019 u32 desc, time, count, base, data1;
2020 u32 blink1, blink2, ilink1, ilink2;
2023 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
2025 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
2026 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
2030 rc = iwl_grab_nic_access(priv);
2032 IWL_WARN(priv, "Can not read from adapter at this time.\n");
2036 count = iwl_read_targ_mem(priv, base);
2038 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
2039 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2040 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2041 priv->status, count);
2044 IWL_ERR(priv, "Desc Time asrtPC blink2 "
2045 "ilink1 nmiPC Line\n");
2046 for (i = ERROR_START_OFFSET;
2047 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2048 i += ERROR_ELEM_SIZE) {
2049 desc = iwl_read_targ_mem(priv, base + i);
2051 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
2053 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
2055 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
2057 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
2059 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
2061 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
2064 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2065 desc_lookup(desc), desc, time, blink1, blink2,
2066 ilink1, ilink2, data1);
2069 iwl_release_nic_access(priv);
2073 #define EVENT_START_OFFSET (6 * sizeof(u32))
2076 * iwl3945_print_event_log - Dump error event log to syslog
2078 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
2080 static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
2081 u32 num_events, u32 mode)
2084 u32 base; /* SRAM byte address of event log header */
2085 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2086 u32 ptr; /* SRAM byte address of log data */
2087 u32 ev, time, data; /* event log data */
2089 if (num_events == 0)
2092 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2095 event_size = 2 * sizeof(u32);
2097 event_size = 3 * sizeof(u32);
2099 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2101 /* "time" is actually "data" for mode 0 (no timestamp).
2102 * place event id # at far right for easier visual parsing. */
2103 for (i = 0; i < num_events; i++) {
2104 ev = iwl_read_targ_mem(priv, ptr);
2106 time = iwl_read_targ_mem(priv, ptr);
2110 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2112 data = iwl_read_targ_mem(priv, ptr);
2114 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
2119 static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
2122 u32 base; /* SRAM byte address of event log header */
2123 u32 capacity; /* event log capacity in # entries */
2124 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2125 u32 num_wraps; /* # times uCode wrapped to top of log */
2126 u32 next_entry; /* index of next entry to be written by uCode */
2127 u32 size; /* # entries that we'll print */
2129 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2130 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
2131 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
2135 rc = iwl_grab_nic_access(priv);
2137 IWL_WARN(priv, "Can not read from adapter at this time.\n");
2141 /* event log header */
2142 capacity = iwl_read_targ_mem(priv, base);
2143 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2144 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2145 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
2147 size = num_wraps ? capacity : next_entry;
2149 /* bail out if nothing in log */
2151 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
2152 iwl_release_nic_access(priv);
2156 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
2159 /* if uCode has wrapped back to top of log, start at the oldest entry,
2160 * i.e the next one that uCode would fill. */
2162 iwl3945_print_event_log(priv, next_entry,
2163 capacity - next_entry, mode);
2165 /* (then/else) start at top of log */
2166 iwl3945_print_event_log(priv, 0, next_entry, mode);
2168 iwl_release_nic_access(priv);
2171 static void iwl3945_error_recovery(struct iwl_priv *priv)
2173 unsigned long flags;
2175 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2176 sizeof(priv->staging_rxon));
2177 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2178 iwl3945_commit_rxon(priv);
2180 iwl3945_add_station(priv, priv->bssid, 1, 0);
2182 spin_lock_irqsave(&priv->lock, flags);
2183 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
2184 priv->error_recovering = 0;
2185 spin_unlock_irqrestore(&priv->lock, flags);
2188 static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2190 u32 inta, handled = 0;
2192 unsigned long flags;
2193 #ifdef CONFIG_IWLWIFI_DEBUG
2197 spin_lock_irqsave(&priv->lock, flags);
2199 /* Ack/clear/reset pending uCode interrupts.
2200 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2201 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
2202 inta = iwl_read32(priv, CSR_INT);
2203 iwl_write32(priv, CSR_INT, inta);
2205 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2206 * Any new interrupts that happen after this, either while we're
2207 * in this tasklet, or later, will show up in next ISR/tasklet. */
2208 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2209 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
2211 #ifdef CONFIG_IWLWIFI_DEBUG
2212 if (priv->debug_level & IWL_DL_ISR) {
2213 /* just for debug */
2214 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2215 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
2216 inta, inta_mask, inta_fh);
2220 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2221 * atomic, make sure that inta covers all the interrupts that
2222 * we've discovered, even if FH interrupt came in just after
2223 * reading CSR_INT. */
2224 if (inta_fh & CSR39_FH_INT_RX_MASK)
2225 inta |= CSR_INT_BIT_FH_RX;
2226 if (inta_fh & CSR39_FH_INT_TX_MASK)
2227 inta |= CSR_INT_BIT_FH_TX;
2229 /* Now service all interrupt bits discovered above. */
2230 if (inta & CSR_INT_BIT_HW_ERR) {
2231 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
2233 /* Tell the device to stop sending interrupts */
2234 iwl_disable_interrupts(priv);
2236 iwl_irq_handle_error(priv);
2238 handled |= CSR_INT_BIT_HW_ERR;
2240 spin_unlock_irqrestore(&priv->lock, flags);
2245 #ifdef CONFIG_IWLWIFI_DEBUG
2246 if (priv->debug_level & (IWL_DL_ISR)) {
2247 /* NIC fires this, but we don't use it, redundant with WAKEUP */
2248 if (inta & CSR_INT_BIT_SCD)
2249 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
2250 "the frame/frames.\n");
2252 /* Alive notification via Rx interrupt will do the real work */
2253 if (inta & CSR_INT_BIT_ALIVE)
2254 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
2257 /* Safely ignore these bits for debug checks below */
2258 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
2260 /* Error detected by uCode */
2261 if (inta & CSR_INT_BIT_SW_ERR) {
2262 IWL_ERR(priv, "Microcode SW error detected. "
2263 "Restarting 0x%X.\n", inta);
2264 iwl_irq_handle_error(priv);
2265 handled |= CSR_INT_BIT_SW_ERR;
2268 /* uCode wakes up after power-down sleep */
2269 if (inta & CSR_INT_BIT_WAKEUP) {
2270 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
2271 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
2272 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2273 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2274 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2275 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2276 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2277 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
2279 handled |= CSR_INT_BIT_WAKEUP;
2282 /* All uCode command responses, including Tx command responses,
2283 * Rx "responses" (frame-received notification), and other
2284 * notifications from uCode come through here*/
2285 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
2286 iwl3945_rx_handle(priv);
2287 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2290 if (inta & CSR_INT_BIT_FH_TX) {
2291 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
2293 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2294 if (!iwl_grab_nic_access(priv)) {
2295 iwl_write_direct32(priv, FH39_TCSR_CREDIT
2296 (FH39_SRVC_CHNL), 0x0);
2297 iwl_release_nic_access(priv);
2299 handled |= CSR_INT_BIT_FH_TX;
2302 if (inta & ~handled)
2303 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
2305 if (inta & ~CSR_INI_SET_MASK) {
2306 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
2307 inta & ~CSR_INI_SET_MASK);
2308 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
2311 /* Re-enable all interrupts */
2312 /* only Re-enable if disabled by irq */
2313 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2314 iwl_enable_interrupts(priv);
2316 #ifdef CONFIG_IWLWIFI_DEBUG
2317 if (priv->debug_level & (IWL_DL_ISR)) {
2318 inta = iwl_read32(priv, CSR_INT);
2319 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2320 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2321 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
2322 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2325 spin_unlock_irqrestore(&priv->lock, flags);
2328 static irqreturn_t iwl3945_isr(int irq, void *data)
2330 struct iwl_priv *priv = data;
2331 u32 inta, inta_mask;
2336 spin_lock(&priv->lock);
2338 /* Disable (but don't clear!) interrupts here to avoid
2339 * back-to-back ISRs and sporadic interrupts from our NIC.
2340 * If we have something to service, the tasklet will re-enable ints.
2341 * If we *don't* have something, we'll re-enable before leaving here. */
2342 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
2343 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
2345 /* Discover which interrupts are active/pending */
2346 inta = iwl_read32(priv, CSR_INT);
2347 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2349 /* Ignore interrupt if there's nothing in NIC to service.
2350 * This may be due to IRQ shared with another device,
2351 * or due to sporadic interrupts thrown from our NIC. */
2352 if (!inta && !inta_fh) {
2353 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
2357 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
2358 /* Hardware disappeared */
2359 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
2363 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
2364 inta, inta_mask, inta_fh);
2366 inta &= ~CSR_INT_BIT_SCD;
2368 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
2369 if (likely(inta || inta_fh))
2370 tasklet_schedule(&priv->irq_tasklet);
2372 spin_unlock(&priv->lock);
2377 /* re-enable interrupts here since we don't have anything to service. */
2378 /* only Re-enable if disabled by irq */
2379 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2380 iwl_enable_interrupts(priv);
2381 spin_unlock(&priv->lock);
2385 static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
2386 enum ieee80211_band band,
2387 u8 is_active, u8 n_probes,
2388 struct iwl3945_scan_channel *scan_ch)
2390 const struct ieee80211_channel *channels = NULL;
2391 const struct ieee80211_supported_band *sband;
2392 const struct iwl_channel_info *ch_info;
2393 u16 passive_dwell = 0;
2394 u16 active_dwell = 0;
2397 sband = iwl_get_hw_mode(priv, band);
2401 channels = sband->channels;
2403 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2404 passive_dwell = iwl_get_passive_dwell_time(priv, band);
2406 if (passive_dwell <= active_dwell)
2407 passive_dwell = active_dwell + 1;
2409 for (i = 0, added = 0; i < sband->n_channels; i++) {
2410 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2413 scan_ch->channel = channels[i].hw_value;
2415 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
2416 if (!is_channel_valid(ch_info)) {
2417 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
2422 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2423 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
2424 /* If passive , set up for auto-switch
2425 * and use long active_dwell time.
2427 if (!is_active || is_channel_passive(ch_info) ||
2428 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2429 scan_ch->type = 0; /* passive */
2430 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2431 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2433 scan_ch->type = 1; /* active */
2436 /* Set direct probe bits. These may be used both for active
2437 * scan channels (probes gets sent right away),
2438 * or for passive channels (probes get se sent only after
2439 * hearing clear Rx packet).*/
2440 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2442 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
2444 /* uCode v1 does not allow setting direct probe bits on
2445 * passive channel. */
2446 if ((scan_ch->type & 1) && n_probes)
2447 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
2450 /* Set txpower levels to defaults */
2451 scan_ch->tpc.dsp_atten = 110;
2452 /* scan_pwr_info->tpc.dsp_atten; */
2454 /*scan_pwr_info->tpc.tx_gain; */
2455 if (band == IEEE80211_BAND_5GHZ)
2456 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2458 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2459 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
2461 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
2465 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
2467 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2468 (scan_ch->type & 1) ?
2469 active_dwell : passive_dwell);
2475 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
2479 static void iwl3945_init_hw_rates(struct iwl_priv *priv,
2480 struct ieee80211_rate *rates)
2484 for (i = 0; i < IWL_RATE_COUNT; i++) {
2485 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2486 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2487 rates[i].hw_value_short = i;
2489 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
2491 * If CCK != 1M then set short preamble rate flag.
2493 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
2494 0 : IEEE80211_RATE_SHORT_PREAMBLE;
2499 /******************************************************************************
2501 * uCode download functions
2503 ******************************************************************************/
2505 static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
2507 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2508 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2509 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2510 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2511 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2512 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
2516 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
2517 * looking at all data.
2519 static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
2526 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
2528 rc = iwl_grab_nic_access(priv);
2532 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
2533 IWL39_RTC_INST_LOWER_BOUND);
2536 for (; len > 0; len -= sizeof(u32), image++) {
2537 /* read data comes through single port, auto-incr addr */
2538 /* NOTE: Use the debugless read so we don't flood kernel log
2539 * if IWL_DL_IO is set */
2540 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2541 if (val != le32_to_cpu(*image)) {
2542 IWL_ERR(priv, "uCode INST section is invalid at "
2543 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2544 save_len - len, val, le32_to_cpu(*image));
2552 iwl_release_nic_access(priv);
2555 IWL_DEBUG_INFO(priv,
2556 "ucode image in INSTRUCTION memory is good\n");
2563 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
2564 * using sample data 100 bytes apart. If these sample points are good,
2565 * it's a pretty good bet that everything between them is good, too.
2567 static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
2574 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
2576 rc = iwl_grab_nic_access(priv);
2580 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2581 /* read data comes through single port, auto-incr addr */
2582 /* NOTE: Use the debugless read so we don't flood kernel log
2583 * if IWL_DL_IO is set */
2584 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
2585 i + IWL39_RTC_INST_LOWER_BOUND);
2586 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2587 if (val != le32_to_cpu(*image)) {
2588 #if 0 /* Enable this if you want to see details */
2589 IWL_ERR(priv, "uCode INST section is invalid at "
2590 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2600 iwl_release_nic_access(priv);
2607 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
2608 * and verify its contents
2610 static int iwl3945_verify_ucode(struct iwl_priv *priv)
2617 image = (__le32 *)priv->ucode_boot.v_addr;
2618 len = priv->ucode_boot.len;
2619 rc = iwl3945_verify_inst_sparse(priv, image, len);
2621 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
2625 /* Try initialize */
2626 image = (__le32 *)priv->ucode_init.v_addr;
2627 len = priv->ucode_init.len;
2628 rc = iwl3945_verify_inst_sparse(priv, image, len);
2630 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
2634 /* Try runtime/protocol */
2635 image = (__le32 *)priv->ucode_code.v_addr;
2636 len = priv->ucode_code.len;
2637 rc = iwl3945_verify_inst_sparse(priv, image, len);
2639 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
2643 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
2645 /* Since nothing seems to match, show first several data entries in
2646 * instruction SRAM, so maybe visual inspection will give a clue.
2647 * Selection of bootstrap image (vs. other images) is arbitrary. */
2648 image = (__le32 *)priv->ucode_boot.v_addr;
2649 len = priv->ucode_boot.len;
2650 rc = iwl3945_verify_inst_full(priv, image, len);
2655 static void iwl3945_nic_start(struct iwl_priv *priv)
2657 /* Remove all resets to allow NIC to operate */
2658 iwl_write32(priv, CSR_RESET, 0);
2662 * iwl3945_read_ucode - Read uCode images from disk file.
2664 * Copy into buffers for card to fetch via bus-mastering
2666 static int iwl3945_read_ucode(struct iwl_priv *priv)
2668 struct iwl_ucode *ucode;
2669 int ret = -EINVAL, index;
2670 const struct firmware *ucode_raw;
2671 /* firmware file name contains uCode/driver compatibility version */
2672 const char *name_pre = priv->cfg->fw_name_pre;
2673 const unsigned int api_max = priv->cfg->ucode_api_max;
2674 const unsigned int api_min = priv->cfg->ucode_api_min;
2678 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
2680 /* Ask kernel firmware_class module to get the boot firmware off disk.
2681 * request_firmware() is synchronous, file is in memory on return. */
2682 for (index = api_max; index >= api_min; index--) {
2683 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2684 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2686 IWL_ERR(priv, "%s firmware file req failed: %d\n",
2693 if (index < api_max)
2694 IWL_ERR(priv, "Loaded firmware %s, "
2695 "which is deprecated. "
2696 " Please use API v%u instead.\n",
2698 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2699 "(%zd bytes) from disk\n",
2700 buf, ucode_raw->size);
2708 /* Make sure that we got at least our header! */
2709 if (ucode_raw->size < sizeof(*ucode)) {
2710 IWL_ERR(priv, "File size way too small!\n");
2715 /* Data from ucode file: header followed by uCode images */
2716 ucode = (void *)ucode_raw->data;
2718 priv->ucode_ver = le32_to_cpu(ucode->ver);
2719 api_ver = IWL_UCODE_API(priv->ucode_ver);
2720 inst_size = le32_to_cpu(ucode->inst_size);
2721 data_size = le32_to_cpu(ucode->data_size);
2722 init_size = le32_to_cpu(ucode->init_size);
2723 init_data_size = le32_to_cpu(ucode->init_data_size);
2724 boot_size = le32_to_cpu(ucode->boot_size);
2726 /* api_ver should match the api version forming part of the
2727 * firmware filename ... but we don't check for that and only rely
2728 * on the API version read from firware header from here on forward */
2730 if (api_ver < api_min || api_ver > api_max) {
2731 IWL_ERR(priv, "Driver unable to support your firmware API. "
2732 "Driver supports v%u, firmware is v%u.\n",
2734 priv->ucode_ver = 0;
2738 if (api_ver != api_max)
2739 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
2740 "got %u. New firmware can be obtained "
2741 "from http://www.intellinuxwireless.org.\n",
2744 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2745 IWL_UCODE_MAJOR(priv->ucode_ver),
2746 IWL_UCODE_MINOR(priv->ucode_ver),
2747 IWL_UCODE_API(priv->ucode_ver),
2748 IWL_UCODE_SERIAL(priv->ucode_ver));
2750 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
2752 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2754 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2756 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2758 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2760 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2764 /* Verify size of file vs. image size info in file's header */
2765 if (ucode_raw->size < sizeof(*ucode) +
2766 inst_size + data_size + init_size +
2767 init_data_size + boot_size) {
2769 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2775 /* Verify that uCode images will fit in card's SRAM */
2776 if (inst_size > IWL39_MAX_INST_SIZE) {
2777 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
2783 if (data_size > IWL39_MAX_DATA_SIZE) {
2784 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
2789 if (init_size > IWL39_MAX_INST_SIZE) {
2790 IWL_DEBUG_INFO(priv,
2791 "uCode init instr len %d too large to fit in\n",
2796 if (init_data_size > IWL39_MAX_DATA_SIZE) {
2797 IWL_DEBUG_INFO(priv,
2798 "uCode init data len %d too large to fit in\n",
2803 if (boot_size > IWL39_MAX_BSM_SIZE) {
2804 IWL_DEBUG_INFO(priv,
2805 "uCode boot instr len %d too large to fit in\n",
2811 /* Allocate ucode buffers for card's bus-master loading ... */
2813 /* Runtime instructions and 2 copies of data:
2814 * 1) unmodified from disk
2815 * 2) backup cache for save/restore during power-downs */
2816 priv->ucode_code.len = inst_size;
2817 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
2819 priv->ucode_data.len = data_size;
2820 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
2822 priv->ucode_data_backup.len = data_size;
2823 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2825 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
2826 !priv->ucode_data_backup.v_addr)
2829 /* Initialization instructions and data */
2830 if (init_size && init_data_size) {
2831 priv->ucode_init.len = init_size;
2832 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
2834 priv->ucode_init_data.len = init_data_size;
2835 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2837 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2841 /* Bootstrap (instructions only, no data) */
2843 priv->ucode_boot.len = boot_size;
2844 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
2846 if (!priv->ucode_boot.v_addr)
2850 /* Copy images into buffers for card's bus-master reads ... */
2852 /* Runtime instructions (first block of data in file) */
2853 src = &ucode->data[0];
2854 len = priv->ucode_code.len;
2855 IWL_DEBUG_INFO(priv,
2856 "Copying (but not loading) uCode instr len %zd\n", len);
2857 memcpy(priv->ucode_code.v_addr, src, len);
2858 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
2859 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2861 /* Runtime data (2nd block)
2862 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
2863 src = &ucode->data[inst_size];
2864 len = priv->ucode_data.len;
2865 IWL_DEBUG_INFO(priv,
2866 "Copying (but not loading) uCode data len %zd\n", len);
2867 memcpy(priv->ucode_data.v_addr, src, len);
2868 memcpy(priv->ucode_data_backup.v_addr, src, len);
2870 /* Initialization instructions (3rd block) */
2872 src = &ucode->data[inst_size + data_size];
2873 len = priv->ucode_init.len;
2874 IWL_DEBUG_INFO(priv,
2875 "Copying (but not loading) init instr len %zd\n", len);
2876 memcpy(priv->ucode_init.v_addr, src, len);
2879 /* Initialization data (4th block) */
2880 if (init_data_size) {
2881 src = &ucode->data[inst_size + data_size + init_size];
2882 len = priv->ucode_init_data.len;
2883 IWL_DEBUG_INFO(priv,
2884 "Copying (but not loading) init data len %zd\n", len);
2885 memcpy(priv->ucode_init_data.v_addr, src, len);
2888 /* Bootstrap instructions (5th block) */
2889 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2890 len = priv->ucode_boot.len;
2891 IWL_DEBUG_INFO(priv,
2892 "Copying (but not loading) boot instr len %zd\n", len);
2893 memcpy(priv->ucode_boot.v_addr, src, len);
2895 /* We have our copies now, allow OS release its copies */
2896 release_firmware(ucode_raw);
2900 IWL_ERR(priv, "failed to allocate pci memory\n");
2902 iwl3945_dealloc_ucode_pci(priv);
2905 release_firmware(ucode_raw);
2913 * iwl3945_set_ucode_ptrs - Set uCode address location
2915 * Tell initialization uCode where to find runtime uCode.
2917 * BSM registers initially contain pointers to initialization uCode.
2918 * We need to replace them to load runtime uCode inst and data,
2919 * and to save runtime data when powering down.
2921 static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
2926 unsigned long flags;
2928 /* bits 31:0 for 3945 */
2929 pinst = priv->ucode_code.p_addr;
2930 pdata = priv->ucode_data_backup.p_addr;
2932 spin_lock_irqsave(&priv->lock, flags);
2933 rc = iwl_grab_nic_access(priv);
2935 spin_unlock_irqrestore(&priv->lock, flags);
2939 /* Tell bootstrap uCode where to find image to load */
2940 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2941 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2942 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
2943 priv->ucode_data.len);
2945 /* Inst byte count must be last to set up, bit 31 signals uCode
2946 * that all new ptr/size info is in place */
2947 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
2948 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2950 iwl_release_nic_access(priv);
2952 spin_unlock_irqrestore(&priv->lock, flags);
2954 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
2960 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
2962 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2964 * Tell "initialize" uCode to go ahead and load the runtime uCode.
2966 static void iwl3945_init_alive_start(struct iwl_priv *priv)
2968 /* Check alive response for "valid" sign from uCode */
2969 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2970 /* We had an error bringing up the hardware, so take it
2971 * all the way back down so we can try again */
2972 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
2976 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2977 * This is a paranoid check, because we would not have gotten the
2978 * "initialize" alive if code weren't properly loaded. */
2979 if (iwl3945_verify_ucode(priv)) {
2980 /* Runtime instruction load was bad;
2981 * take it all the way back down so we can try again */
2982 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
2986 /* Send pointers to protocol/runtime uCode image ... init code will
2987 * load and launch runtime uCode, which will send us another "Alive"
2989 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
2990 if (iwl3945_set_ucode_ptrs(priv)) {
2991 /* Runtime instruction load won't happen;
2992 * take it all the way back down so we can try again */
2993 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
2999 queue_work(priv->workqueue, &priv->restart);
3004 static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
3005 struct sk_buff *skb);
3008 * iwl3945_alive_start - called after REPLY_ALIVE notification received
3009 * from protocol/runtime uCode (initialization uCode's
3010 * Alive gets handled by iwl3945_init_alive_start()).
3012 static void iwl3945_alive_start(struct iwl_priv *priv)
3015 int thermal_spin = 0;
3018 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
3020 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
3021 /* We had an error bringing up the hardware, so take it
3022 * all the way back down so we can try again */
3023 IWL_DEBUG_INFO(priv, "Alive failed.\n");
3027 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
3028 * This is a paranoid check, because we would not have gotten the
3029 * "runtime" alive if code weren't properly loaded. */
3030 if (iwl3945_verify_ucode(priv)) {
3031 /* Runtime instruction load was bad;
3032 * take it all the way back down so we can try again */
3033 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
3037 iwl3945_clear_stations_table(priv);
3039 rc = iwl_grab_nic_access(priv);
3041 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
3045 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
3046 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
3047 iwl_release_nic_access(priv);
3050 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3051 /* if RFKILL is not on, then wait for thermal
3052 * sensor in adapter to kick in */
3053 while (iwl3945_hw_get_temperature(priv) == 0) {
3059 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
3062 set_bit(STATUS_RF_KILL_HW, &priv->status);
3064 /* After the ALIVE response, we can send commands to 3945 uCode */
3065 set_bit(STATUS_ALIVE, &priv->status);
3067 /* Clear out the uCode error bit if it is set */
3068 clear_bit(STATUS_FW_ERROR, &priv->status);
3070 if (iwl_is_rfkill(priv))
3073 ieee80211_wake_queues(priv->hw);
3075 priv->active_rate = priv->rates_mask;
3076 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
3078 iwl_power_update_mode(priv, false);
3080 if (iwl_is_associated(priv)) {
3081 struct iwl3945_rxon_cmd *active_rxon =
3082 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
3084 memcpy(&priv->staging_rxon, &priv->active_rxon,
3085 sizeof(priv->staging_rxon));
3086 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3088 /* Initialize our rx_config data */
3089 iwl_connection_init_rx_config(priv, priv->iw_mode);
3092 /* Configure Bluetooth device coexistence support */
3093 iwl_send_bt_config(priv);
3095 /* Configure the adapter for unassociated operation */
3096 iwl3945_commit_rxon(priv);
3098 iwl3945_reg_txpower_periodic(priv);
3100 iwl3945_led_register(priv);
3102 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
3103 set_bit(STATUS_READY, &priv->status);
3104 wake_up_interruptible(&priv->wait_command_queue);
3106 if (priv->error_recovering)
3107 iwl3945_error_recovery(priv);
3109 /* reassociate for ADHOC mode */
3110 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3111 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3114 iwl3945_mac_beacon_update(priv->hw, beacon);
3120 queue_work(priv->workqueue, &priv->restart);
3123 static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
3125 static void __iwl3945_down(struct iwl_priv *priv)
3127 unsigned long flags;
3128 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3129 struct ieee80211_conf *conf = NULL;
3131 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
3133 conf = ieee80211_get_hw_conf(priv->hw);
3136 set_bit(STATUS_EXIT_PENDING, &priv->status);
3138 iwl3945_led_unregister(priv);
3139 iwl3945_clear_stations_table(priv);
3141 /* Unblock any waiting calls */
3142 wake_up_interruptible_all(&priv->wait_command_queue);
3144 /* Wipe out the EXIT_PENDING status bit if we are not actually
3145 * exiting the module */
3147 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3149 /* stop and reset the on-board processor */
3150 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
3152 /* tell the device to stop sending interrupts */
3153 spin_lock_irqsave(&priv->lock, flags);
3154 iwl_disable_interrupts(priv);
3155 spin_unlock_irqrestore(&priv->lock, flags);
3156 iwl_synchronize_irq(priv);
3158 if (priv->mac80211_registered)
3159 ieee80211_stop_queues(priv->hw);
3161 /* If we have not previously called iwl3945_init() then
3162 * clear all bits but the RF Kill and SUSPEND bits and return */
3163 if (!iwl_is_init(priv)) {
3164 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3166 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3168 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3169 STATUS_GEO_CONFIGURED |
3170 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3172 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3173 STATUS_EXIT_PENDING;
3177 /* ...otherwise clear out all the status bits but the RF Kill and
3178 * SUSPEND bits and continue taking the NIC down. */
3179 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3181 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3183 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3184 STATUS_GEO_CONFIGURED |
3185 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3187 test_bit(STATUS_FW_ERROR, &priv->status) <<
3189 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3190 STATUS_EXIT_PENDING;
3192 priv->cfg->ops->lib->apm_ops.reset(priv);
3193 spin_lock_irqsave(&priv->lock, flags);
3194 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
3195 spin_unlock_irqrestore(&priv->lock, flags);
3197 iwl3945_hw_txq_ctx_stop(priv);
3198 iwl3945_hw_rxq_stop(priv);
3200 spin_lock_irqsave(&priv->lock, flags);
3201 if (!iwl_grab_nic_access(priv)) {
3202 iwl_write_prph(priv, APMG_CLK_DIS_REG,
3203 APMG_CLK_VAL_DMA_CLK_RQT);
3204 iwl_release_nic_access(priv);
3206 spin_unlock_irqrestore(&priv->lock, flags);
3210 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3211 priv->cfg->ops->lib->apm_ops.stop(priv);
3213 priv->cfg->ops->lib->apm_ops.reset(priv);
3216 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
3218 if (priv->ibss_beacon)
3219 dev_kfree_skb(priv->ibss_beacon);
3220 priv->ibss_beacon = NULL;
3222 /* clear out any free frames */
3223 iwl3945_clear_free_frames(priv);
3226 static void iwl3945_down(struct iwl_priv *priv)
3228 mutex_lock(&priv->mutex);
3229 __iwl3945_down(priv);
3230 mutex_unlock(&priv->mutex);
3232 iwl3945_cancel_deferred_work(priv);
3235 #define MAX_HW_RESTARTS 5
3237 static int __iwl3945_up(struct iwl_priv *priv)
3241 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3242 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
3246 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
3247 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
3252 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
3253 IWL_ERR(priv, "ucode not available for device bring up\n");
3257 /* If platform's RF_KILL switch is NOT set to KILL */
3258 if (iwl_read32(priv, CSR_GP_CNTRL) &
3259 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3260 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3262 set_bit(STATUS_RF_KILL_HW, &priv->status);
3263 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
3264 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
3269 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
3271 rc = iwl3945_hw_nic_init(priv);
3273 IWL_ERR(priv, "Unable to int nic\n");
3277 /* make sure rfkill handshake bits are cleared */
3278 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3279 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
3280 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3282 /* clear (again), then enable host interrupts */
3283 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
3284 iwl_enable_interrupts(priv);
3286 /* really make sure rfkill handshake bits are cleared */
3287 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3288 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3290 /* Copy original ucode data image from disk into backup cache.
3291 * This will be used to initialize the on-board processor's
3292 * data SRAM for a clean start when the runtime program first loads. */
3293 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
3294 priv->ucode_data.len);
3296 /* We return success when we resume from suspend and rf_kill is on. */
3297 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3300 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3302 iwl3945_clear_stations_table(priv);
3304 /* load bootstrap state machine,
3305 * load bootstrap program into processor's memory,
3306 * prepare to load the "initialize" uCode */
3307 priv->cfg->ops->lib->load_ucode(priv);
3311 "Unable to set up bootstrap uCode: %d\n", rc);
3315 /* start card; "initialize" will load runtime ucode */
3316 iwl3945_nic_start(priv);
3318 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
3323 set_bit(STATUS_EXIT_PENDING, &priv->status);
3324 __iwl3945_down(priv);
3325 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3327 /* tried to restart and config the device for as long as our
3328 * patience could withstand */
3329 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
3334 /*****************************************************************************
3336 * Workqueue callbacks
3338 *****************************************************************************/
3340 static void iwl3945_bg_init_alive_start(struct work_struct *data)
3342 struct iwl_priv *priv =
3343 container_of(data, struct iwl_priv, init_alive_start.work);
3345 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3348 mutex_lock(&priv->mutex);
3349 iwl3945_init_alive_start(priv);
3350 mutex_unlock(&priv->mutex);
3353 static void iwl3945_bg_alive_start(struct work_struct *data)
3355 struct iwl_priv *priv =
3356 container_of(data, struct iwl_priv, alive_start.work);
3358 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3361 mutex_lock(&priv->mutex);
3362 iwl3945_alive_start(priv);
3363 mutex_unlock(&priv->mutex);
3366 static void iwl3945_rfkill_poll(struct work_struct *data)
3368 struct iwl_priv *priv =
3369 container_of(data, struct iwl_priv, rfkill_poll.work);
3370 unsigned long status = priv->status;
3372 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3373 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3375 set_bit(STATUS_RF_KILL_HW, &priv->status);
3377 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3378 queue_work(priv->workqueue, &priv->rf_kill);
3380 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3381 round_jiffies_relative(2 * HZ));
3385 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
3386 static void iwl3945_bg_request_scan(struct work_struct *data)
3388 struct iwl_priv *priv =
3389 container_of(data, struct iwl_priv, request_scan);
3390 struct iwl_host_cmd cmd = {
3391 .id = REPLY_SCAN_CMD,
3392 .len = sizeof(struct iwl3945_scan_cmd),
3393 .meta.flags = CMD_SIZE_HUGE,
3396 struct iwl3945_scan_cmd *scan;
3397 struct ieee80211_conf *conf = NULL;
3399 enum ieee80211_band band;
3400 DECLARE_SSID_BUF(ssid);
3402 conf = ieee80211_get_hw_conf(priv->hw);
3404 mutex_lock(&priv->mutex);
3406 if (!iwl_is_ready(priv)) {
3407 IWL_WARN(priv, "request scan called when driver not ready.\n");
3411 /* Make sure the scan wasn't canceled before this queued work
3412 * was given the chance to run... */
3413 if (!test_bit(STATUS_SCANNING, &priv->status))
3416 /* This should never be called or scheduled if there is currently
3417 * a scan active in the hardware. */
3418 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
3419 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3420 "Ignoring second request.\n");
3425 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3426 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
3430 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3432 "Scan request while abort pending. Queuing.\n");
3436 if (iwl_is_rfkill(priv)) {
3437 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
3441 if (!test_bit(STATUS_READY, &priv->status)) {
3443 "Scan request while uninitialized. Queuing.\n");
3447 if (!priv->scan_bands) {
3448 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
3453 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
3454 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
3461 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
3463 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3464 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3466 if (iwl_is_associated(priv)) {
3469 u32 suspend_time = 100;
3470 u32 scan_suspend_time = 100;
3471 unsigned long flags;
3473 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
3475 spin_lock_irqsave(&priv->lock, flags);
3476 interval = priv->beacon_int;
3477 spin_unlock_irqrestore(&priv->lock, flags);
3479 scan->suspend_time = 0;
3480 scan->max_out_time = cpu_to_le32(200 * 1024);
3482 interval = suspend_time;
3484 * suspend time format:
3485 * 0-19: beacon interval in usec (time before exec.)
3487 * 24-31: number of beacons (suspend between channels)
3490 extra = (suspend_time / interval) << 24;
3491 scan_suspend_time = 0xFF0FFFFF &
3492 (extra | ((suspend_time % interval) * 1024));
3494 scan->suspend_time = cpu_to_le32(scan_suspend_time);
3495 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
3496 scan_suspend_time, interval);
3499 /* We should add the ability for user to lock to PASSIVE ONLY */
3500 if (priv->one_direct_scan) {
3501 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3502 print_ssid(ssid, priv->direct_ssid,
3503 priv->direct_ssid_len));
3504 scan->direct_scan[0].id = WLAN_EID_SSID;
3505 scan->direct_scan[0].len = priv->direct_ssid_len;
3506 memcpy(scan->direct_scan[0].ssid,
3507 priv->direct_ssid, priv->direct_ssid_len);
3510 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
3512 /* We don't build a direct scan probe request; the uCode will do
3513 * that based on the direct_mask added to each channel entry */
3514 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
3515 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
3516 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3518 /* flags + rate selection */
3520 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
3521 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3522 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3523 scan->good_CRC_th = 0;
3524 band = IEEE80211_BAND_2GHZ;
3525 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
3526 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3527 scan->good_CRC_th = IWL_GOOD_CRC_TH;
3528 band = IEEE80211_BAND_5GHZ;
3530 IWL_WARN(priv, "Invalid scan band count\n");
3534 scan->tx_cmd.len = cpu_to_le16(
3535 iwl_fill_probe_req(priv, band,
3536 (struct ieee80211_mgmt *)scan->data,
3537 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3539 /* select Rx antennas */
3540 scan->flags |= iwl3945_get_antenna_flags(priv);
3542 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
3543 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3545 scan->channel_count =
3546 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3548 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
3550 if (scan->channel_count == 0) {
3551 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
3555 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
3556 scan->channel_count * sizeof(struct iwl3945_scan_channel);
3558 scan->len = cpu_to_le16(cmd.len);
3560 set_bit(STATUS_SCAN_HW, &priv->status);
3561 rc = iwl_send_cmd_sync(priv, &cmd);
3565 queue_delayed_work(priv->workqueue, &priv->scan_check,
3566 IWL_SCAN_CHECK_WATCHDOG);
3568 mutex_unlock(&priv->mutex);
3572 /* can not perform scan make sure we clear scanning
3573 * bits from status so next scan request can be performed.
3574 * if we dont clear scanning status bit here all next scan
3577 clear_bit(STATUS_SCAN_HW, &priv->status);
3578 clear_bit(STATUS_SCANNING, &priv->status);
3580 /* inform mac80211 scan aborted */
3581 queue_work(priv->workqueue, &priv->scan_completed);
3582 mutex_unlock(&priv->mutex);
3585 static void iwl3945_bg_up(struct work_struct *data)
3587 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
3589 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3592 mutex_lock(&priv->mutex);
3594 mutex_unlock(&priv->mutex);
3595 iwl_rfkill_set_hw_state(priv);
3598 static void iwl3945_bg_restart(struct work_struct *data)
3600 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
3602 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3606 queue_work(priv->workqueue, &priv->up);
3609 static void iwl3945_bg_rx_replenish(struct work_struct *data)
3611 struct iwl_priv *priv =
3612 container_of(data, struct iwl_priv, rx_replenish);
3614 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3617 mutex_lock(&priv->mutex);
3618 iwl3945_rx_replenish(priv);
3619 mutex_unlock(&priv->mutex);
3622 #define IWL_DELAY_NEXT_SCAN (HZ*2)
3624 static void iwl3945_post_associate(struct iwl_priv *priv)
3627 struct ieee80211_conf *conf = NULL;
3629 if (priv->iw_mode == NL80211_IFTYPE_AP) {
3630 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
3635 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
3636 priv->assoc_id, priv->active_rxon.bssid_addr);
3638 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3641 if (!priv->vif || !priv->is_open)
3644 iwl_scan_cancel_timeout(priv, 200);
3646 conf = ieee80211_get_hw_conf(priv->hw);
3648 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3649 iwl3945_commit_rxon(priv);
3651 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
3652 iwl3945_setup_rxon_timing(priv);
3653 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3654 sizeof(priv->rxon_timing), &priv->rxon_timing);
3656 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3657 "Attempting to continue.\n");
3659 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
3661 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
3663 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
3664 priv->assoc_id, priv->beacon_int);
3666 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
3667 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3669 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3671 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
3672 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
3673 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
3675 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
3677 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
3678 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
3682 iwl3945_commit_rxon(priv);
3684 switch (priv->iw_mode) {
3685 case NL80211_IFTYPE_STATION:
3686 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
3689 case NL80211_IFTYPE_ADHOC:
3692 iwl3945_add_station(priv, priv->bssid, 0, 0);
3693 iwl3945_sync_sta(priv, IWL_STA_ID,
3694 (priv->band == IEEE80211_BAND_5GHZ) ?
3695 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3697 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3698 iwl3945_send_beacon_cmd(priv);
3703 IWL_ERR(priv, "%s Should not be called in %d mode\n",
3704 __func__, priv->iw_mode);
3708 iwl3945_activate_qos(priv, 0);
3710 /* we have just associated, don't start scan too early */
3711 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
3714 static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
3716 /*****************************************************************************
3718 * mac80211 entry point functions
3720 *****************************************************************************/
3722 #define UCODE_READY_TIMEOUT (2 * HZ)
3724 static int iwl3945_mac_start(struct ieee80211_hw *hw)
3726 struct iwl_priv *priv = hw->priv;
3729 IWL_DEBUG_MAC80211(priv, "enter\n");
3731 /* we should be verifying the device is ready to be opened */
3732 mutex_lock(&priv->mutex);
3734 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
3735 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3736 * ucode filename and max sizes are card-specific. */
3738 if (!priv->ucode_code.len) {
3739 ret = iwl3945_read_ucode(priv);
3741 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
3742 mutex_unlock(&priv->mutex);
3743 goto out_release_irq;
3747 ret = __iwl3945_up(priv);
3749 mutex_unlock(&priv->mutex);
3751 iwl_rfkill_set_hw_state(priv);
3754 goto out_release_irq;
3756 IWL_DEBUG_INFO(priv, "Start UP work.\n");
3758 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3761 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3762 * mac80211 will not be run successfully. */
3763 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3764 test_bit(STATUS_READY, &priv->status),
3765 UCODE_READY_TIMEOUT);
3767 if (!test_bit(STATUS_READY, &priv->status)) {
3769 "Wait for START_ALIVE timeout after %dms.\n",
3770 jiffies_to_msecs(UCODE_READY_TIMEOUT));
3772 goto out_release_irq;
3776 /* ucode is running and will send rfkill notifications,
3777 * no need to poll the killswitch state anymore */
3778 cancel_delayed_work(&priv->rfkill_poll);
3781 IWL_DEBUG_MAC80211(priv, "leave\n");
3786 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
3790 static void iwl3945_mac_stop(struct ieee80211_hw *hw)
3792 struct iwl_priv *priv = hw->priv;
3794 IWL_DEBUG_MAC80211(priv, "enter\n");
3796 if (!priv->is_open) {
3797 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
3803 if (iwl_is_ready_rf(priv)) {
3804 /* stop mac, cancel any scan request and clear
3805 * RXON_FILTER_ASSOC_MSK BIT
3807 mutex_lock(&priv->mutex);
3808 iwl_scan_cancel_timeout(priv, 100);
3809 mutex_unlock(&priv->mutex);
3814 flush_workqueue(priv->workqueue);
3816 /* start polling the killswitch state again */
3817 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3818 round_jiffies_relative(2 * HZ));
3820 IWL_DEBUG_MAC80211(priv, "leave\n");
3823 static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3825 struct iwl_priv *priv = hw->priv;
3827 IWL_DEBUG_MAC80211(priv, "enter\n");
3829 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
3830 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
3832 if (iwl3945_tx_skb(priv, skb))
3833 dev_kfree_skb_any(skb);
3835 IWL_DEBUG_MAC80211(priv, "leave\n");
3836 return NETDEV_TX_OK;
3839 static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
3840 struct ieee80211_if_init_conf *conf)
3842 struct iwl_priv *priv = hw->priv;
3843 unsigned long flags;
3845 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
3848 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
3852 spin_lock_irqsave(&priv->lock, flags);
3853 priv->vif = conf->vif;
3854 priv->iw_mode = conf->type;
3856 spin_unlock_irqrestore(&priv->lock, flags);
3858 mutex_lock(&priv->mutex);
3860 if (conf->mac_addr) {
3861 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
3862 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3865 if (iwl_is_ready(priv))
3866 iwl3945_set_mode(priv, conf->type);
3868 mutex_unlock(&priv->mutex);
3870 IWL_DEBUG_MAC80211(priv, "leave\n");
3875 * iwl3945_mac_config - mac80211 config callback
3877 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3878 * be set inappropriately and the driver currently sets the hardware up to
3879 * use it whenever needed.
3881 static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
3883 struct iwl_priv *priv = hw->priv;
3884 const struct iwl_channel_info *ch_info;
3885 struct ieee80211_conf *conf = &hw->conf;
3886 unsigned long flags;
3889 mutex_lock(&priv->mutex);
3890 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3891 conf->channel->hw_value);
3893 if (!iwl_is_ready(priv)) {
3894 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
3899 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
3900 test_bit(STATUS_SCANNING, &priv->status))) {
3901 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
3902 set_bit(STATUS_CONF_PENDING, &priv->status);
3903 mutex_unlock(&priv->mutex);
3907 spin_lock_irqsave(&priv->lock, flags);
3909 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3910 conf->channel->hw_value);
3911 if (!is_channel_valid(ch_info)) {
3912 IWL_DEBUG_SCAN(priv,
3913 "Channel %d [%d] is INVALID for this band.\n",
3914 conf->channel->hw_value, conf->channel->band);
3915 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
3916 spin_unlock_irqrestore(&priv->lock, flags);
3921 iwl_set_rxon_channel(priv, conf->channel);
3923 iwl_set_flags_for_band(priv, conf->channel->band);
3925 /* The list of supported rates and rate mask can be different
3926 * for each phymode; since the phymode may have changed, reset
3927 * the rate mask to what mac80211 lists */
3930 spin_unlock_irqrestore(&priv->lock, flags);
3932 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
3933 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
3934 iwl3945_hw_channel_switch(priv, conf->channel);
3939 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
3941 if (!conf->radio_enabled) {
3942 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
3946 if (iwl_is_rfkill(priv)) {
3947 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
3954 if (memcmp(&priv->active_rxon,
3955 &priv->staging_rxon, sizeof(priv->staging_rxon)))
3956 iwl3945_commit_rxon(priv);
3958 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
3960 IWL_DEBUG_MAC80211(priv, "leave\n");
3963 clear_bit(STATUS_CONF_PENDING, &priv->status);
3964 mutex_unlock(&priv->mutex);
3968 static void iwl3945_config_ap(struct iwl_priv *priv)
3972 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3975 /* The following should be done only at AP bring up */
3976 if (!(iwl_is_associated(priv))) {
3978 /* RXON - unassoc (to set timing command) */
3979 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3980 iwl3945_commit_rxon(priv);
3983 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
3984 iwl3945_setup_rxon_timing(priv);
3985 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3986 sizeof(priv->rxon_timing),
3987 &priv->rxon_timing);
3989 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3990 "Attempting to continue.\n");
3992 /* FIXME: what should be the assoc_id for AP? */
3993 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
3994 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
3995 priv->staging_rxon.flags |=
3996 RXON_FLG_SHORT_PREAMBLE_MSK;
3998 priv->staging_rxon.flags &=
3999 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4001 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
4002 if (priv->assoc_capability &
4003 WLAN_CAPABILITY_SHORT_SLOT_TIME)
4004 priv->staging_rxon.flags |=
4005 RXON_FLG_SHORT_SLOT_MSK;
4007 priv->staging_rxon.flags &=
4008 ~RXON_FLG_SHORT_SLOT_MSK;
4010 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
4011 priv->staging_rxon.flags &=
4012 ~RXON_FLG_SHORT_SLOT_MSK;
4014 /* restore RXON assoc */
4015 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
4016 iwl3945_commit_rxon(priv);
4017 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
4019 iwl3945_send_beacon_cmd(priv);
4021 /* FIXME - we need to add code here to detect a totally new
4022 * configuration, reset the AP, unassoc, rxon timing, assoc,
4023 * clear sta table, add BCAST sta... */
4026 static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
4027 struct ieee80211_vif *vif,
4028 struct ieee80211_if_conf *conf)
4030 struct iwl_priv *priv = hw->priv;
4036 if (priv->vif != vif) {
4037 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
4041 /* handle this temporarily here */
4042 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
4043 conf->changed & IEEE80211_IFCC_BEACON) {
4044 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
4047 mutex_lock(&priv->mutex);
4048 rc = iwl3945_mac_beacon_update(hw, beacon);
4049 mutex_unlock(&priv->mutex);
4054 if (!iwl_is_alive(priv))
4057 mutex_lock(&priv->mutex);
4060 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
4063 * very dubious code was here; the probe filtering flag is never set:
4065 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4066 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
4069 if (priv->iw_mode == NL80211_IFTYPE_AP) {
4071 conf->bssid = priv->mac_addr;
4072 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
4073 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
4076 if (priv->ibss_beacon)
4077 dev_kfree_skb(priv->ibss_beacon);
4079 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
4082 if (iwl_is_rfkill(priv))
4085 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4086 !is_multicast_ether_addr(conf->bssid)) {
4087 /* If there is currently a HW scan going on in the background
4088 * then we need to cancel it else the RXON below will fail. */
4089 if (iwl_scan_cancel_timeout(priv, 100)) {
4090 IWL_WARN(priv, "Aborted scan still in progress "
4092 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
4093 mutex_unlock(&priv->mutex);
4096 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
4098 /* TODO: Audit driver for usage of these members and see
4099 * if mac80211 deprecates them (priv->bssid looks like it
4100 * shouldn't be there, but I haven't scanned the IBSS code
4101 * to verify) - jpk */
4102 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4104 if (priv->iw_mode == NL80211_IFTYPE_AP)
4105 iwl3945_config_ap(priv);
4107 rc = iwl3945_commit_rxon(priv);
4108 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
4109 iwl3945_add_station(priv,
4110 priv->active_rxon.bssid_addr, 1, 0);
4114 iwl_scan_cancel_timeout(priv, 100);
4115 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4116 iwl3945_commit_rxon(priv);
4120 IWL_DEBUG_MAC80211(priv, "leave\n");
4121 mutex_unlock(&priv->mutex);
4126 static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
4127 struct ieee80211_if_init_conf *conf)
4129 struct iwl_priv *priv = hw->priv;
4131 IWL_DEBUG_MAC80211(priv, "enter\n");
4133 mutex_lock(&priv->mutex);
4135 if (iwl_is_ready_rf(priv)) {
4136 iwl_scan_cancel_timeout(priv, 100);
4137 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4138 iwl3945_commit_rxon(priv);
4140 if (priv->vif == conf->vif) {
4142 memset(priv->bssid, 0, ETH_ALEN);
4144 mutex_unlock(&priv->mutex);
4146 IWL_DEBUG_MAC80211(priv, "leave\n");
4149 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4151 static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4152 struct ieee80211_vif *vif,
4153 struct ieee80211_bss_conf *bss_conf,
4156 struct iwl_priv *priv = hw->priv;
4158 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
4160 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
4161 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
4162 bss_conf->use_short_preamble);
4163 if (bss_conf->use_short_preamble)
4164 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
4166 priv->staging_rxon.flags &=
4167 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4170 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
4171 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4172 bss_conf->use_cts_prot);
4173 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
4174 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
4176 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
4179 if (changes & BSS_CHANGED_ASSOC) {
4180 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
4181 /* This should never happen as this function should
4182 * never be called from interrupt context. */
4183 if (WARN_ON_ONCE(in_interrupt()))
4185 if (bss_conf->assoc) {
4186 priv->assoc_id = bss_conf->aid;
4187 priv->beacon_int = bss_conf->beacon_int;
4188 priv->timestamp = bss_conf->timestamp;
4189 priv->assoc_capability = bss_conf->assoc_capability;
4190 priv->power_data.dtim_period = bss_conf->dtim_period;
4191 priv->next_scan_jiffies = jiffies +
4192 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4193 mutex_lock(&priv->mutex);
4194 iwl3945_post_associate(priv);
4195 mutex_unlock(&priv->mutex);
4198 IWL_DEBUG_MAC80211(priv,
4199 "DISASSOC %d\n", bss_conf->assoc);
4201 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
4202 IWL_DEBUG_MAC80211(priv,
4203 "Associated Changes %d\n", changes);
4204 iwl3945_send_rxon_assoc(priv);
4209 static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4210 struct ieee80211_vif *vif,
4211 struct ieee80211_sta *sta,
4212 struct ieee80211_key_conf *key)
4214 struct iwl_priv *priv = hw->priv;
4219 IWL_DEBUG_MAC80211(priv, "enter\n");
4221 if (iwl3945_mod_params.sw_crypto) {
4222 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
4226 addr = sta ? sta->addr : iwl_bcast_addr;
4227 sta_id = iwl3945_hw_find_station(priv, addr);
4228 if (sta_id == IWL_INVALID_STATION) {
4229 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
4234 mutex_lock(&priv->mutex);
4236 iwl_scan_cancel_timeout(priv, 100);
4240 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
4242 iwl_set_rxon_hwcrypto(priv, 1);
4243 iwl3945_commit_rxon(priv);
4244 key->hw_key_idx = sta_id;
4245 IWL_DEBUG_MAC80211(priv,
4246 "set_key success, using hwcrypto\n");
4247 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
4251 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4253 iwl_set_rxon_hwcrypto(priv, 0);
4254 iwl3945_commit_rxon(priv);
4255 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
4262 IWL_DEBUG_MAC80211(priv, "leave\n");
4263 mutex_unlock(&priv->mutex);
4268 static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
4269 const struct ieee80211_tx_queue_params *params)
4271 struct iwl_priv *priv = hw->priv;
4272 unsigned long flags;
4275 IWL_DEBUG_MAC80211(priv, "enter\n");
4277 if (!iwl_is_ready_rf(priv)) {
4278 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4282 if (queue >= AC_NUM) {
4283 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
4287 q = AC_NUM - 1 - queue;
4289 spin_lock_irqsave(&priv->lock, flags);
4291 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4292 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4293 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4294 priv->qos_data.def_qos_parm.ac[q].edca_txop =
4295 cpu_to_le16((params->txop * 32));
4297 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4298 priv->qos_data.qos_active = 1;
4300 spin_unlock_irqrestore(&priv->lock, flags);
4302 mutex_lock(&priv->mutex);
4303 if (priv->iw_mode == NL80211_IFTYPE_AP)
4304 iwl3945_activate_qos(priv, 1);
4305 else if (priv->assoc_id && iwl_is_associated(priv))
4306 iwl3945_activate_qos(priv, 0);
4308 mutex_unlock(&priv->mutex);
4310 IWL_DEBUG_MAC80211(priv, "leave\n");
4314 static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
4315 struct ieee80211_tx_queue_stats *stats)
4317 struct iwl_priv *priv = hw->priv;
4319 struct iwl_tx_queue *txq;
4320 struct iwl_queue *q;
4321 unsigned long flags;
4323 IWL_DEBUG_MAC80211(priv, "enter\n");
4325 if (!iwl_is_ready_rf(priv)) {
4326 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4330 spin_lock_irqsave(&priv->lock, flags);
4332 for (i = 0; i < AC_NUM; i++) {
4333 txq = &priv->txq[i];
4335 avail = iwl_queue_space(q);
4337 stats[i].len = q->n_window - avail;
4338 stats[i].limit = q->n_window - q->high_mark;
4339 stats[i].count = q->n_window;
4342 spin_unlock_irqrestore(&priv->lock, flags);
4344 IWL_DEBUG_MAC80211(priv, "leave\n");
4349 static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
4351 struct iwl_priv *priv = hw->priv;
4352 unsigned long flags;
4354 mutex_lock(&priv->mutex);
4355 IWL_DEBUG_MAC80211(priv, "enter\n");
4357 iwl_reset_qos(priv);
4359 spin_lock_irqsave(&priv->lock, flags);
4361 priv->assoc_capability = 0;
4363 /* new association get rid of ibss beacon skb */
4364 if (priv->ibss_beacon)
4365 dev_kfree_skb(priv->ibss_beacon);
4367 priv->ibss_beacon = NULL;
4369 priv->beacon_int = priv->hw->conf.beacon_int;
4370 priv->timestamp = 0;
4371 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
4372 priv->beacon_int = 0;
4374 spin_unlock_irqrestore(&priv->lock, flags);
4376 if (!iwl_is_ready_rf(priv)) {
4377 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
4378 mutex_unlock(&priv->mutex);
4382 /* we are restarting association process
4383 * clear RXON_FILTER_ASSOC_MSK bit
4385 if (priv->iw_mode != NL80211_IFTYPE_AP) {
4386 iwl_scan_cancel_timeout(priv, 100);
4387 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4388 iwl3945_commit_rxon(priv);
4391 /* Per mac80211.h: This is only used in IBSS mode... */
4392 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
4394 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
4395 mutex_unlock(&priv->mutex);
4401 mutex_unlock(&priv->mutex);
4403 IWL_DEBUG_MAC80211(priv, "leave\n");
4407 static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
4409 struct iwl_priv *priv = hw->priv;
4410 unsigned long flags;
4412 IWL_DEBUG_MAC80211(priv, "enter\n");
4414 if (!iwl_is_ready_rf(priv)) {
4415 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4419 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
4420 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
4424 spin_lock_irqsave(&priv->lock, flags);
4426 if (priv->ibss_beacon)
4427 dev_kfree_skb(priv->ibss_beacon);
4429 priv->ibss_beacon = skb;
4433 IWL_DEBUG_MAC80211(priv, "leave\n");
4434 spin_unlock_irqrestore(&priv->lock, flags);
4436 iwl_reset_qos(priv);
4438 iwl3945_post_associate(priv);
4444 /*****************************************************************************
4448 *****************************************************************************/
4450 #ifdef CONFIG_IWLWIFI_DEBUG
4453 * The following adds a new attribute to the sysfs representation
4454 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4455 * used for controlling the debug level.
4457 * See the level definitions in iwl for details.
4459 static ssize_t show_debug_level(struct device *d,
4460 struct device_attribute *attr, char *buf)
4462 struct iwl_priv *priv = d->driver_data;
4464 return sprintf(buf, "0x%08X\n", priv->debug_level);
4466 static ssize_t store_debug_level(struct device *d,
4467 struct device_attribute *attr,
4468 const char *buf, size_t count)
4470 struct iwl_priv *priv = d->driver_data;
4474 ret = strict_strtoul(buf, 0, &val);
4476 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
4478 priv->debug_level = val;
4480 return strnlen(buf, count);
4483 static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4484 show_debug_level, store_debug_level);
4486 #endif /* CONFIG_IWLWIFI_DEBUG */
4488 static ssize_t show_temperature(struct device *d,
4489 struct device_attribute *attr, char *buf)
4491 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4493 if (!iwl_is_alive(priv))
4496 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
4499 static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4501 static ssize_t show_tx_power(struct device *d,
4502 struct device_attribute *attr, char *buf)
4504 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4505 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
4508 static ssize_t store_tx_power(struct device *d,
4509 struct device_attribute *attr,
4510 const char *buf, size_t count)
4512 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4513 char *p = (char *)buf;
4516 val = simple_strtoul(p, &p, 10);
4518 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
4520 iwl3945_hw_reg_set_txpower(priv, val);
4525 static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4527 static ssize_t show_flags(struct device *d,
4528 struct device_attribute *attr, char *buf)
4530 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4532 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
4535 static ssize_t store_flags(struct device *d,
4536 struct device_attribute *attr,
4537 const char *buf, size_t count)
4539 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4540 u32 flags = simple_strtoul(buf, NULL, 0);
4542 mutex_lock(&priv->mutex);
4543 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
4544 /* Cancel any currently running scans... */
4545 if (iwl_scan_cancel_timeout(priv, 100))
4546 IWL_WARN(priv, "Could not cancel scan.\n");
4548 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
4550 priv->staging_rxon.flags = cpu_to_le32(flags);
4551 iwl3945_commit_rxon(priv);
4554 mutex_unlock(&priv->mutex);
4559 static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4561 static ssize_t show_filter_flags(struct device *d,
4562 struct device_attribute *attr, char *buf)
4564 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4566 return sprintf(buf, "0x%04X\n",
4567 le32_to_cpu(priv->active_rxon.filter_flags));
4570 static ssize_t store_filter_flags(struct device *d,
4571 struct device_attribute *attr,
4572 const char *buf, size_t count)
4574 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4575 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4577 mutex_lock(&priv->mutex);
4578 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
4579 /* Cancel any currently running scans... */
4580 if (iwl_scan_cancel_timeout(priv, 100))
4581 IWL_WARN(priv, "Could not cancel scan.\n");
4583 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
4584 "0x%04X\n", filter_flags);
4585 priv->staging_rxon.filter_flags =
4586 cpu_to_le32(filter_flags);
4587 iwl3945_commit_rxon(priv);
4590 mutex_unlock(&priv->mutex);
4595 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4596 store_filter_flags);
4598 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
4600 static ssize_t show_measurement(struct device *d,
4601 struct device_attribute *attr, char *buf)
4603 struct iwl_priv *priv = dev_get_drvdata(d);
4604 struct iwl_spectrum_notification measure_report;
4605 u32 size = sizeof(measure_report), len = 0, ofs = 0;
4606 u8 *data = (u8 *)&measure_report;
4607 unsigned long flags;
4609 spin_lock_irqsave(&priv->lock, flags);
4610 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4611 spin_unlock_irqrestore(&priv->lock, flags);
4614 memcpy(&measure_report, &priv->measure_report, size);
4615 priv->measurement_status = 0;
4616 spin_unlock_irqrestore(&priv->lock, flags);
4618 while (size && (PAGE_SIZE - len)) {
4619 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4620 PAGE_SIZE - len, 1);
4622 if (PAGE_SIZE - len)
4626 size -= min(size, 16U);
4632 static ssize_t store_measurement(struct device *d,
4633 struct device_attribute *attr,
4634 const char *buf, size_t count)
4636 struct iwl_priv *priv = dev_get_drvdata(d);
4637 struct ieee80211_measurement_params params = {
4638 .channel = le16_to_cpu(priv->active_rxon.channel),
4639 .start_time = cpu_to_le64(priv->last_tsf),
4640 .duration = cpu_to_le16(1),
4642 u8 type = IWL_MEASURE_BASIC;
4648 strncpy(buffer, buf, min(sizeof(buffer), count));
4649 channel = simple_strtoul(p, NULL, 0);
4651 params.channel = channel;
4654 while (*p && *p != ' ')
4657 type = simple_strtoul(p + 1, NULL, 0);
4660 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
4661 "channel %d (for '%s')\n", type, params.channel, buf);
4662 iwl3945_get_measurement(priv, ¶ms, type);
4667 static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4668 show_measurement, store_measurement);
4669 #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
4671 static ssize_t store_retry_rate(struct device *d,
4672 struct device_attribute *attr,
4673 const char *buf, size_t count)
4675 struct iwl_priv *priv = dev_get_drvdata(d);
4677 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4678 if (priv->retry_rate <= 0)
4679 priv->retry_rate = 1;
4684 static ssize_t show_retry_rate(struct device *d,
4685 struct device_attribute *attr, char *buf)
4687 struct iwl_priv *priv = dev_get_drvdata(d);
4688 return sprintf(buf, "%d", priv->retry_rate);
4691 static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4695 static ssize_t store_power_level(struct device *d,
4696 struct device_attribute *attr,
4697 const char *buf, size_t count)
4699 struct iwl_priv *priv = dev_get_drvdata(d);
4704 mutex_lock(&priv->mutex);
4706 if (!iwl_is_ready(priv)) {
4711 ret = strict_strtoul(buf, 10, &mode);
4715 ret = iwl_power_set_user_mode(priv, mode);
4717 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4723 mutex_unlock(&priv->mutex);
4727 static ssize_t show_power_level(struct device *d,
4728 struct device_attribute *attr, char *buf)
4730 struct iwl_priv *priv = dev_get_drvdata(d);
4731 int mode = priv->power_data.user_power_setting;
4732 int system = priv->power_data.system_power_setting;
4733 int level = priv->power_data.power_mode;
4737 case IWL_POWER_SYS_AUTO:
4738 p += sprintf(p, "SYSTEM:auto");
4740 case IWL_POWER_SYS_AC:
4741 p += sprintf(p, "SYSTEM:ac");
4743 case IWL_POWER_SYS_BATTERY:
4744 p += sprintf(p, "SYSTEM:battery");
4748 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4750 p += sprintf(p, "\tINDEX:%d", level);
4751 p += sprintf(p, "\n");
4755 static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4756 show_power_level, store_power_level);
4758 #define MAX_WX_STRING 80
4760 /* Values are in microsecond */
4761 static const s32 timeout_duration[] = {
4768 static const s32 period_duration[] = {
4776 static ssize_t show_channels(struct device *d,
4777 struct device_attribute *attr, char *buf)
4779 /* all this shit doesn't belong into sysfs anyway */
4783 static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4785 static ssize_t show_statistics(struct device *d,
4786 struct device_attribute *attr, char *buf)
4788 struct iwl_priv *priv = dev_get_drvdata(d);
4789 u32 size = sizeof(struct iwl3945_notif_statistics);
4790 u32 len = 0, ofs = 0;
4791 u8 *data = (u8 *)&priv->statistics_39;
4794 if (!iwl_is_alive(priv))
4797 mutex_lock(&priv->mutex);
4798 rc = iwl_send_statistics_request(priv, 0);
4799 mutex_unlock(&priv->mutex);
4803 "Error sending statistics request: 0x%08X\n", rc);
4807 while (size && (PAGE_SIZE - len)) {
4808 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4809 PAGE_SIZE - len, 1);
4811 if (PAGE_SIZE - len)
4815 size -= min(size, 16U);
4821 static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4823 static ssize_t show_antenna(struct device *d,
4824 struct device_attribute *attr, char *buf)
4826 struct iwl_priv *priv = dev_get_drvdata(d);
4828 if (!iwl_is_alive(priv))
4831 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
4834 static ssize_t store_antenna(struct device *d,
4835 struct device_attribute *attr,
4836 const char *buf, size_t count)
4838 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
4844 if (sscanf(buf, "%1i", &ant) != 1) {
4845 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
4849 if ((ant >= 0) && (ant <= 2)) {
4850 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
4851 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
4853 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
4859 static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4861 static ssize_t show_status(struct device *d,
4862 struct device_attribute *attr, char *buf)
4864 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4865 if (!iwl_is_alive(priv))
4867 return sprintf(buf, "0x%08x\n", (int)priv->status);
4870 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4872 static ssize_t dump_error_log(struct device *d,
4873 struct device_attribute *attr,
4874 const char *buf, size_t count)
4876 char *p = (char *)buf;
4879 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
4881 return strnlen(buf, count);
4884 static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4886 static ssize_t dump_event_log(struct device *d,
4887 struct device_attribute *attr,
4888 const char *buf, size_t count)
4890 char *p = (char *)buf;
4893 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
4895 return strnlen(buf, count);
4898 static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4900 /*****************************************************************************
4902 * driver setup and tear down
4904 *****************************************************************************/
4906 static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
4908 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
4910 init_waitqueue_head(&priv->wait_command_queue);
4912 INIT_WORK(&priv->up, iwl3945_bg_up);
4913 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4914 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
4915 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
4916 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
4917 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4918 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
4919 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
4920 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4921 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4922 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4923 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
4925 iwl3945_hw_setup_deferred_work(priv);
4927 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
4928 iwl3945_irq_tasklet, (unsigned long)priv);
4931 static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
4933 iwl3945_hw_cancel_deferred_work(priv);
4935 cancel_delayed_work_sync(&priv->init_alive_start);
4936 cancel_delayed_work(&priv->scan_check);
4937 cancel_delayed_work(&priv->alive_start);
4938 cancel_work_sync(&priv->beacon_update);
4941 static struct attribute *iwl3945_sysfs_entries[] = {
4942 &dev_attr_antenna.attr,
4943 &dev_attr_channels.attr,
4944 &dev_attr_dump_errors.attr,
4945 &dev_attr_dump_events.attr,
4946 &dev_attr_flags.attr,
4947 &dev_attr_filter_flags.attr,
4948 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
4949 &dev_attr_measurement.attr,
4951 &dev_attr_power_level.attr,
4952 &dev_attr_retry_rate.attr,
4953 &dev_attr_statistics.attr,
4954 &dev_attr_status.attr,
4955 &dev_attr_temperature.attr,
4956 &dev_attr_tx_power.attr,
4957 #ifdef CONFIG_IWLWIFI_DEBUG
4958 &dev_attr_debug_level.attr,
4963 static struct attribute_group iwl3945_attribute_group = {
4964 .name = NULL, /* put in device directory */
4965 .attrs = iwl3945_sysfs_entries,
4968 static struct ieee80211_ops iwl3945_hw_ops = {
4969 .tx = iwl3945_mac_tx,
4970 .start = iwl3945_mac_start,
4971 .stop = iwl3945_mac_stop,
4972 .add_interface = iwl3945_mac_add_interface,
4973 .remove_interface = iwl3945_mac_remove_interface,
4974 .config = iwl3945_mac_config,
4975 .config_interface = iwl3945_mac_config_interface,
4976 .configure_filter = iwl_configure_filter,
4977 .set_key = iwl3945_mac_set_key,
4978 .get_tx_stats = iwl3945_mac_get_tx_stats,
4979 .conf_tx = iwl3945_mac_conf_tx,
4980 .reset_tsf = iwl3945_mac_reset_tsf,
4981 .bss_info_changed = iwl3945_bss_info_changed,
4982 .hw_scan = iwl_mac_hw_scan
4985 static int iwl3945_init_drv(struct iwl_priv *priv)
4988 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
4990 priv->retry_rate = 1;
4991 priv->ibss_beacon = NULL;
4993 spin_lock_init(&priv->lock);
4994 spin_lock_init(&priv->power_data.lock);
4995 spin_lock_init(&priv->sta_lock);
4996 spin_lock_init(&priv->hcmd_lock);
4998 INIT_LIST_HEAD(&priv->free_frames);
5000 mutex_init(&priv->mutex);
5002 /* Clear the driver's (not device's) station table */
5003 iwl3945_clear_stations_table(priv);
5005 priv->data_retry_limit = -1;
5006 priv->ieee_channels = NULL;
5007 priv->ieee_rates = NULL;
5008 priv->band = IEEE80211_BAND_2GHZ;
5010 priv->iw_mode = NL80211_IFTYPE_STATION;
5012 iwl_reset_qos(priv);
5014 priv->qos_data.qos_active = 0;
5015 priv->qos_data.qos_cap.val = 0;
5017 priv->rates_mask = IWL_RATES_MASK;
5018 /* If power management is turned on, default to CAM mode */
5019 priv->power_mode = IWL_POWER_MODE_CAM;
5020 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
5022 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
5023 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
5028 ret = iwl_init_channel_map(priv);
5030 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
5034 /* Set up txpower settings in driver for all channels */
5035 if (iwl3945_txpower_set_from_eeprom(priv)) {
5037 goto err_free_channel_map;
5040 ret = iwlcore_init_geos(priv);
5042 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
5043 goto err_free_channel_map;
5045 iwl3945_init_hw_rates(priv, priv->ieee_rates);
5047 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5048 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5049 &priv->bands[IEEE80211_BAND_2GHZ];
5050 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5051 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5052 &priv->bands[IEEE80211_BAND_5GHZ];
5056 err_free_channel_map:
5057 iwl_free_channel_map(priv);
5062 static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5065 struct iwl_priv *priv;
5066 struct ieee80211_hw *hw;
5067 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
5068 struct iwl3945_eeprom *eeprom;
5069 unsigned long flags;
5071 /***********************
5072 * 1. Allocating HW data
5073 * ********************/
5075 /* mac80211 allocates memory for this device instance, including
5076 * space for this driver's private structure */
5077 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
5079 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
5084 SET_IEEE80211_DEV(hw, &pdev->dev);
5086 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5087 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
5089 "invalid queues_num, should be between %d and %d\n",
5090 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
5096 * Disabling hardware scan means that mac80211 will perform scans
5097 * "the hard way", rather than using device's scan.
5099 if (iwl3945_mod_params.disable_hw_scan) {
5100 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
5101 iwl3945_hw_ops.hw_scan = NULL;
5105 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
5107 priv->pci_dev = pdev;
5109 #ifdef CONFIG_IWLWIFI_DEBUG
5110 priv->debug_level = iwl3945_mod_params.debug;
5111 atomic_set(&priv->restrict_refcnt, 0);
5113 hw->rate_control_algorithm = "iwl-3945-rs";
5114 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
5116 /* Tell mac80211 our characteristics */
5117 hw->flags = IEEE80211_HW_SIGNAL_DBM |
5118 IEEE80211_HW_NOISE_DBM;
5120 hw->wiphy->interface_modes =
5121 BIT(NL80211_IFTYPE_STATION) |
5122 BIT(NL80211_IFTYPE_ADHOC);
5124 hw->wiphy->custom_regulatory = true;
5126 hw->wiphy->max_scan_ssids = 1;
5128 /* 4 EDCA QOS priorities */
5131 /***************************
5132 * 2. Initializing PCI bus
5133 * *************************/
5134 if (pci_enable_device(pdev)) {
5136 goto out_ieee80211_free_hw;
5139 pci_set_master(pdev);
5141 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5143 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5145 IWL_WARN(priv, "No suitable DMA available.\n");
5146 goto out_pci_disable_device;
5149 pci_set_drvdata(pdev, priv);
5150 err = pci_request_regions(pdev, DRV_NAME);
5152 goto out_pci_disable_device;
5154 /***********************
5155 * 3. Read REV Register
5156 * ********************/
5157 priv->hw_base = pci_iomap(pdev, 0, 0);
5158 if (!priv->hw_base) {
5160 goto out_pci_release_regions;
5163 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
5164 (unsigned long long) pci_resource_len(pdev, 0));
5165 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
5167 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5168 * PCI Tx retries from interfering with C3 CPU state */
5169 pci_write_config_byte(pdev, 0x41, 0x00);
5172 err = priv->cfg->ops->lib->apm_ops.init(priv);
5174 IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
5178 /***********************
5180 * ********************/
5182 /* Read the EEPROM */
5183 err = iwl_eeprom_init(priv);
5185 IWL_ERR(priv, "Unable to init EEPROM\n");
5186 goto out_remove_sysfs;
5188 /* MAC Address location in EEPROM same for 3945/4965 */
5189 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5190 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
5191 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
5192 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5194 /***********************
5195 * 5. Setup HW Constants
5196 * ********************/
5197 /* Device-specific setup */
5198 if (iwl3945_hw_set_hw_params(priv)) {
5199 IWL_ERR(priv, "failed to set hw settings\n");
5203 /***********************
5205 * ********************/
5207 err = iwl3945_init_drv(priv);
5209 IWL_ERR(priv, "initializing driver failed\n");
5213 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5216 /***********************************
5217 * 7. Initialize Module Parameters
5218 * **********************************/
5220 /* Initialize module parameter values here */
5221 /* Disable radio (SW RF KILL) via parameter when loading driver */
5222 if (iwl3945_mod_params.disable) {
5223 set_bit(STATUS_RF_KILL_SW, &priv->status);
5224 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
5228 /***********************
5230 * ********************/
5232 spin_lock_irqsave(&priv->lock, flags);
5233 iwl_disable_interrupts(priv);
5234 spin_unlock_irqrestore(&priv->lock, flags);
5236 pci_enable_msi(priv->pci_dev);
5238 err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
5241 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5242 goto out_disable_msi;
5245 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5247 IWL_ERR(priv, "failed to create sysfs device attributes\n");
5248 goto out_release_irq;
5251 iwl_set_rxon_channel(priv,
5252 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
5253 iwl3945_setup_deferred_work(priv);
5254 iwl3945_setup_rx_handlers(priv);
5256 /*********************************
5257 * 9. Setup and Register mac80211
5258 * *******************************/
5260 err = ieee80211_register_hw(priv->hw);
5262 IWL_ERR(priv, "Failed to register network device: %d\n", err);
5263 goto out_remove_sysfs;
5266 priv->hw->conf.beacon_int = 100;
5267 priv->mac80211_registered = 1;
5269 err = iwl_rfkill_init(priv);
5271 IWL_ERR(priv, "Unable to initialize RFKILL system. "
5272 "Ignoring error: %d\n", err);
5274 /* Start monitoring the killswitch */
5275 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5281 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5283 iwlcore_free_geos(priv);
5286 free_irq(priv->pci_dev->irq, priv);
5287 destroy_workqueue(priv->workqueue);
5288 priv->workqueue = NULL;
5289 iwl3945_unset_hw_params(priv);
5291 pci_disable_msi(priv->pci_dev);
5293 pci_iounmap(pdev, priv->hw_base);
5294 out_pci_release_regions:
5295 pci_release_regions(pdev);
5296 out_pci_disable_device:
5297 pci_disable_device(pdev);
5298 pci_set_drvdata(pdev, NULL);
5299 out_ieee80211_free_hw:
5300 ieee80211_free_hw(priv->hw);
5305 static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
5307 struct iwl_priv *priv = pci_get_drvdata(pdev);
5308 unsigned long flags;
5313 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
5315 set_bit(STATUS_EXIT_PENDING, &priv->status);
5317 if (priv->mac80211_registered) {
5318 ieee80211_unregister_hw(priv->hw);
5319 priv->mac80211_registered = 0;
5324 /* make sure we flush any pending irq or
5325 * tasklet for the driver
5327 spin_lock_irqsave(&priv->lock, flags);
5328 iwl_disable_interrupts(priv);
5329 spin_unlock_irqrestore(&priv->lock, flags);
5331 iwl_synchronize_irq(priv);
5333 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5335 iwl_rfkill_unregister(priv);
5336 cancel_delayed_work(&priv->rfkill_poll);
5338 iwl3945_dealloc_ucode_pci(priv);
5341 iwl_rx_queue_free(priv, &priv->rxq);
5342 iwl3945_hw_txq_ctx_free(priv);
5344 iwl3945_unset_hw_params(priv);
5345 iwl3945_clear_stations_table(priv);
5347 /*netif_stop_queue(dev); */
5348 flush_workqueue(priv->workqueue);
5350 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
5351 * priv->workqueue... so we can't take down the workqueue
5353 destroy_workqueue(priv->workqueue);
5354 priv->workqueue = NULL;
5356 free_irq(pdev->irq, priv);
5357 pci_disable_msi(pdev);
5359 pci_iounmap(pdev, priv->hw_base);
5360 pci_release_regions(pdev);
5361 pci_disable_device(pdev);
5362 pci_set_drvdata(pdev, NULL);
5364 iwl_free_channel_map(priv);
5365 iwlcore_free_geos(priv);
5367 if (priv->ibss_beacon)
5368 dev_kfree_skb(priv->ibss_beacon);
5370 ieee80211_free_hw(priv->hw);
5375 static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5377 struct iwl_priv *priv = pci_get_drvdata(pdev);
5379 if (priv->is_open) {
5380 set_bit(STATUS_IN_SUSPEND, &priv->status);
5381 iwl3945_mac_stop(priv->hw);
5384 pci_save_state(pdev);
5385 pci_disable_device(pdev);
5386 pci_set_power_state(pdev, PCI_D3hot);
5391 static int iwl3945_pci_resume(struct pci_dev *pdev)
5393 struct iwl_priv *priv = pci_get_drvdata(pdev);
5396 pci_set_power_state(pdev, PCI_D0);
5397 ret = pci_enable_device(pdev);
5400 pci_restore_state(pdev);
5403 iwl3945_mac_start(priv->hw);
5405 clear_bit(STATUS_IN_SUSPEND, &priv->status);
5409 #endif /* CONFIG_PM */
5411 /*****************************************************************************
5413 * driver and module entry point
5415 *****************************************************************************/
5417 static struct pci_driver iwl3945_driver = {
5419 .id_table = iwl3945_hw_card_ids,
5420 .probe = iwl3945_pci_probe,
5421 .remove = __devexit_p(iwl3945_pci_remove),
5423 .suspend = iwl3945_pci_suspend,
5424 .resume = iwl3945_pci_resume,
5428 static int __init iwl3945_init(void)
5432 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5433 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
5435 ret = iwl3945_rate_control_register();
5437 printk(KERN_ERR DRV_NAME
5438 "Unable to register rate control algorithm: %d\n", ret);
5442 ret = pci_register_driver(&iwl3945_driver);
5444 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
5445 goto error_register;
5451 iwl3945_rate_control_unregister();
5455 static void __exit iwl3945_exit(void)
5457 pci_unregister_driver(&iwl3945_driver);
5458 iwl3945_rate_control_unregister();
5461 MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
5463 module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
5464 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
5465 module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
5466 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
5467 module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5468 MODULE_PARM_DESC(swcrypto,
5469 "using software crypto (default 1 [software])\n");
5470 module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
5471 MODULE_PARM_DESC(debug, "debug output mask");
5472 module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
5473 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5475 module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
5476 MODULE_PARM_DESC(queues_num, "number of hw queues.");
5478 module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5479 MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5481 module_exit(iwl3945_exit);
5482 module_init(iwl3945_init);