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 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
334 if (!iwl_is_alive(priv))
337 /* always get timestamp with Rx frame */
338 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
341 staging_rxon->flags &=
342 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
343 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
345 rc = iwl_check_rxon_cmd(priv);
347 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
351 /* If we don't need to send a full RXON, we can use
352 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
353 * and other flags for the current radio configuration. */
354 if (!iwl_full_rxon_required(priv)) {
355 rc = iwl3945_send_rxon_assoc(priv);
357 IWL_ERR(priv, "Error setting RXON_ASSOC "
358 "configuration (%d).\n", rc);
362 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
367 /* If we are currently associated and the new config requires
368 * an RXON_ASSOC and the new config wants the associated mask enabled,
369 * we must clear the associated from the active configuration
370 * before we apply the new config */
371 if (iwl_is_associated(priv) && new_assoc) {
372 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
373 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
376 * reserved4 and 5 could have been filled by the iwlcore code.
377 * Let's clear them before pushing to the 3945.
379 active_rxon->reserved4 = 0;
380 active_rxon->reserved5 = 0;
381 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
382 sizeof(struct iwl3945_rxon_cmd),
385 /* If the mask clearing failed then we set
386 * active_rxon back to what it was previously */
388 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
389 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
390 "configuration (%d).\n", rc);
395 IWL_DEBUG_INFO(priv, "Sending RXON\n"
396 "* with%s RXON_FILTER_ASSOC_MSK\n"
399 (new_assoc ? "" : "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 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
412 /* Apply the new configuration */
413 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
414 sizeof(struct iwl3945_rxon_cmd),
417 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
421 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
423 iwl3945_clear_stations_table(priv);
425 /* If we issue a new RXON command which required a tune then we must
426 * send a new TXPOWER command or we won't be able to Tx any frames */
427 rc = priv->cfg->ops->lib->send_tx_power(priv);
429 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
433 /* Add the broadcast address so we can send broadcast frames */
434 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
435 IWL_INVALID_STATION) {
436 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
440 /* If we have set the ASSOC_MSK and we are in BSS mode then
441 * add the IWL_AP_ID to the station rate table */
442 if (iwl_is_associated(priv) &&
443 (priv->iw_mode == NL80211_IFTYPE_STATION))
444 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
446 == IWL_INVALID_STATION) {
447 IWL_ERR(priv, "Error adding AP address for transmit\n");
451 /* Init the hardware's rate fallback order based on the band */
452 rc = iwl3945_init_hw_rate_table(priv);
454 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
461 static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
462 struct ieee80211_key_conf *keyconf,
466 __le16 key_flags = 0;
469 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
470 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
472 if (sta_id == priv->hw_params.bcast_sta_id)
473 key_flags |= STA_KEY_MULTICAST_MSK;
475 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
476 keyconf->hw_key_idx = keyconf->keyidx;
477 key_flags &= ~STA_KEY_FLG_INVALID;
479 spin_lock_irqsave(&priv->sta_lock, flags);
480 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
481 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
482 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
485 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
488 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
489 == STA_KEY_FLG_NO_ENC)
490 priv->stations[sta_id].sta.key.key_offset =
491 iwl_get_free_ucode_key_index(priv);
492 /* else, we are overriding an existing key => no need to allocated room
495 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
496 "no space for a new key");
498 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
499 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
500 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
502 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
504 ret = iwl_send_add_sta(priv,
505 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, CMD_ASYNC);
507 spin_unlock_irqrestore(&priv->sta_lock, flags);
512 static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
513 struct ieee80211_key_conf *keyconf,
519 static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
520 struct ieee80211_key_conf *keyconf,
526 static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
530 spin_lock_irqsave(&priv->sta_lock, flags);
531 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
532 memset(&priv->stations_39[sta_id].sta.key, 0,
533 sizeof(struct iwl4965_keyinfo));
534 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
535 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
536 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
537 spin_unlock_irqrestore(&priv->sta_lock, flags);
539 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
540 iwl_send_add_sta(priv,
541 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
545 int iwl3945_set_dynamic_key(struct iwl_priv *priv,
546 struct ieee80211_key_conf *keyconf, u8 sta_id)
550 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
552 switch (keyconf->alg) {
554 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
557 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
560 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
563 IWL_ERR(priv,"Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
567 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
568 keyconf->alg, keyconf->keylen, keyconf->keyidx,
574 static int iwl3945_remove_static_key(struct iwl_priv *priv)
576 int ret = -EOPNOTSUPP;
581 static int iwl3945_set_static_key(struct iwl_priv *priv,
582 struct ieee80211_key_conf *key)
584 if (key->alg == ALG_WEP)
587 IWL_ERR(priv, "Static key invalid: alg %d\n", key->alg);
591 static void iwl3945_clear_free_frames(struct iwl_priv *priv)
593 struct list_head *element;
595 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
598 while (!list_empty(&priv->free_frames)) {
599 element = priv->free_frames.next;
601 kfree(list_entry(element, struct iwl3945_frame, list));
602 priv->frames_count--;
605 if (priv->frames_count) {
606 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
608 priv->frames_count = 0;
612 static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
614 struct iwl3945_frame *frame;
615 struct list_head *element;
616 if (list_empty(&priv->free_frames)) {
617 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
619 IWL_ERR(priv, "Could not allocate frame!\n");
623 priv->frames_count++;
627 element = priv->free_frames.next;
629 return list_entry(element, struct iwl3945_frame, list);
632 static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
634 memset(frame, 0, sizeof(*frame));
635 list_add(&frame->list, &priv->free_frames);
638 unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
639 struct ieee80211_hdr *hdr,
643 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
644 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
645 (priv->iw_mode != NL80211_IFTYPE_AP)))
648 if (priv->ibss_beacon->len > left)
651 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
653 return priv->ibss_beacon->len;
656 static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
658 struct iwl3945_frame *frame;
659 unsigned int frame_size;
663 frame = iwl3945_get_free_frame(priv);
666 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
671 rate = iwl_rate_get_lowest_plcp(priv);
673 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
675 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
678 iwl3945_free_frame(priv, frame);
683 static void iwl3945_unset_hw_params(struct iwl_priv *priv)
685 if (priv->shared_virt)
686 pci_free_consistent(priv->pci_dev,
687 sizeof(struct iwl3945_shared),
692 #define MAX_UCODE_BEACON_INTERVAL 1024
693 #define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
695 static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
698 u16 beacon_factor = 0;
701 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
702 / MAX_UCODE_BEACON_INTERVAL;
703 new_val = beacon_val / beacon_factor;
705 return cpu_to_le16(new_val);
708 static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
710 u64 interval_tm_unit;
713 struct ieee80211_conf *conf = NULL;
716 conf = ieee80211_get_hw_conf(priv->hw);
718 spin_lock_irqsave(&priv->lock, flags);
719 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
720 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
722 tsf = priv->timestamp;
724 beacon_int = priv->beacon_int;
725 spin_unlock_irqrestore(&priv->lock, flags);
727 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
728 if (beacon_int == 0) {
729 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
730 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
732 priv->rxon_timing.beacon_interval =
733 cpu_to_le16(beacon_int);
734 priv->rxon_timing.beacon_interval =
735 iwl3945_adjust_beacon_interval(
736 le16_to_cpu(priv->rxon_timing.beacon_interval));
739 priv->rxon_timing.atim_window = 0;
741 priv->rxon_timing.beacon_interval =
742 iwl3945_adjust_beacon_interval(conf->beacon_int);
743 /* TODO: we need to get atim_window from upper stack
744 * for now we set to 0 */
745 priv->rxon_timing.atim_window = 0;
749 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
750 result = do_div(tsf, interval_tm_unit);
751 priv->rxon_timing.beacon_init_val =
752 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
754 IWL_DEBUG_ASSOC(priv,
755 "beacon interval %d beacon timer %d beacon tim %d\n",
756 le16_to_cpu(priv->rxon_timing.beacon_interval),
757 le32_to_cpu(priv->rxon_timing.beacon_init_val),
758 le16_to_cpu(priv->rxon_timing.atim_window));
761 static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
763 if (mode == NL80211_IFTYPE_ADHOC) {
764 const struct iwl_channel_info *ch_info;
766 ch_info = iwl_get_channel_info(priv,
768 le16_to_cpu(priv->staging_rxon.channel));
770 if (!ch_info || !is_channel_ibss(ch_info)) {
771 IWL_ERR(priv, "channel %d not IBSS channel\n",
772 le16_to_cpu(priv->staging_rxon.channel));
777 iwl_connection_init_rx_config(priv, mode);
779 iwl3945_clear_stations_table(priv);
781 /* don't commit rxon if rf-kill is on*/
782 if (!iwl_is_ready_rf(priv))
785 cancel_delayed_work(&priv->scan_check);
786 if (iwl_scan_cancel_timeout(priv, 100)) {
787 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
788 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
792 iwl3945_commit_rxon(priv);
797 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
798 struct ieee80211_tx_info *info,
800 struct sk_buff *skb_frag,
803 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
804 struct iwl3945_hw_key *keyinfo =
805 &priv->stations_39[sta_id].keyinfo;
807 switch (keyinfo->alg) {
809 tx->sec_ctl = TX_CMD_SEC_CCM;
810 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
811 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
818 tx->sec_ctl = TX_CMD_SEC_WEP |
819 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
821 if (keyinfo->keylen == 13)
822 tx->sec_ctl |= TX_CMD_SEC_KEY128;
824 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
826 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
827 "with key %d\n", info->control.hw_key->hw_key_idx);
831 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
837 * handle build REPLY_TX command notification.
839 static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
841 struct ieee80211_tx_info *info,
842 struct ieee80211_hdr *hdr, u8 std_id)
844 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
845 __le32 tx_flags = tx->tx_flags;
846 __le16 fc = hdr->frame_control;
847 u8 rc_flags = info->control.rates[0].flags;
849 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
850 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
851 tx_flags |= TX_CMD_FLG_ACK_MSK;
852 if (ieee80211_is_mgmt(fc))
853 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
854 if (ieee80211_is_probe_resp(fc) &&
855 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
856 tx_flags |= TX_CMD_FLG_TSF_MSK;
858 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
859 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
863 if (ieee80211_has_morefrags(fc))
864 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
866 if (ieee80211_is_data_qos(fc)) {
867 u8 *qc = ieee80211_get_qos_ctl(hdr);
868 tx->tid_tspec = qc[0] & 0xf;
869 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
871 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
874 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
875 tx_flags |= TX_CMD_FLG_RTS_MSK;
876 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
877 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
878 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
879 tx_flags |= TX_CMD_FLG_CTS_MSK;
882 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
883 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
885 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
886 if (ieee80211_is_mgmt(fc)) {
887 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
888 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
890 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
892 tx->timeout.pm_frame_timeout = 0;
893 #ifdef CONFIG_IWL3945_LEDS
894 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
899 tx->tx_flags = tx_flags;
900 tx->next_frame_len = 0;
904 * iwl3945_get_sta_id - Find station's index within station table
906 static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
909 u16 fc = le16_to_cpu(hdr->frame_control);
911 /* If this frame is broadcast or management, use broadcast station id */
912 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
913 is_multicast_ether_addr(hdr->addr1))
914 return priv->hw_params.bcast_sta_id;
916 switch (priv->iw_mode) {
918 /* If we are a client station in a BSS network, use the special
919 * AP station entry (that's the only station we communicate with) */
920 case NL80211_IFTYPE_STATION:
923 /* If we are an AP, then find the station, or use BCAST */
924 case NL80211_IFTYPE_AP:
925 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
926 if (sta_id != IWL_INVALID_STATION)
928 return priv->hw_params.bcast_sta_id;
930 /* If this frame is going out to an IBSS network, find the station,
931 * or create a new station table entry */
932 case NL80211_IFTYPE_ADHOC: {
933 /* Create new station table entry */
934 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
935 if (sta_id != IWL_INVALID_STATION)
938 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
940 if (sta_id != IWL_INVALID_STATION)
943 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
944 "Defaulting to broadcast...\n",
946 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
947 return priv->hw_params.bcast_sta_id;
949 /* If we are in monitor mode, use BCAST. This is required for
950 * packet injection. */
951 case NL80211_IFTYPE_MONITOR:
952 return priv->hw_params.bcast_sta_id;
955 IWL_WARN(priv, "Unknown mode of operation: %d\n",
957 return priv->hw_params.bcast_sta_id;
962 * start REPLY_TX command process
964 static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
966 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
967 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
968 struct iwl3945_tx_cmd *tx;
969 struct iwl_tx_queue *txq = NULL;
970 struct iwl_queue *q = NULL;
971 struct iwl_cmd *out_cmd = NULL;
972 dma_addr_t phys_addr;
973 dma_addr_t txcmd_phys;
974 int txq_id = skb_get_queue_mapping(skb);
975 u16 len, idx, len_org, hdr_len;
982 u8 wait_write_ptr = 0;
987 spin_lock_irqsave(&priv->lock, flags);
988 if (iwl_is_rfkill(priv)) {
989 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
993 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
994 IWL_ERR(priv, "ERROR: No TX rate available.\n");
998 unicast = !is_multicast_ether_addr(hdr->addr1);
1001 fc = hdr->frame_control;
1003 #ifdef CONFIG_IWLWIFI_DEBUG
1004 if (ieee80211_is_auth(fc))
1005 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
1006 else if (ieee80211_is_assoc_req(fc))
1007 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
1008 else if (ieee80211_is_reassoc_req(fc))
1009 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
1012 /* drop all data frame if we are not associated */
1013 if (ieee80211_is_data(fc) &&
1014 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
1015 (!iwl_is_associated(priv) ||
1016 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
1017 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
1021 spin_unlock_irqrestore(&priv->lock, flags);
1023 hdr_len = ieee80211_hdrlen(fc);
1025 /* Find (or create) index into station table for destination station */
1026 sta_id = iwl3945_get_sta_id(priv, hdr);
1027 if (sta_id == IWL_INVALID_STATION) {
1028 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
1033 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
1035 if (ieee80211_is_data_qos(fc)) {
1036 qc = ieee80211_get_qos_ctl(hdr);
1037 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1038 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
1040 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1042 cpu_to_le16(IEEE80211_SCTL_FRAG));
1046 /* Descriptor for chosen Tx queue */
1047 txq = &priv->txq[txq_id];
1050 spin_lock_irqsave(&priv->lock, flags);
1052 idx = get_cmd_index(q, q->write_ptr, 0);
1054 /* Set up driver data for this TFD */
1055 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
1056 txq->txb[q->write_ptr].skb[0] = skb;
1058 /* Init first empty entry in queue's array of Tx/cmd buffers */
1059 out_cmd = txq->cmd[idx];
1060 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
1061 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
1062 memset(tx, 0, sizeof(*tx));
1065 * Set up the Tx-command (not MAC!) header.
1066 * Store the chosen Tx queue and TFD index within the sequence field;
1067 * after Tx, uCode's Tx response will return this value so driver can
1068 * locate the frame within the tx queue and do post-tx processing.
1070 out_cmd->hdr.cmd = REPLY_TX;
1071 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
1072 INDEX_TO_SEQ(q->write_ptr)));
1074 /* Copy MAC header from skb into command buffer */
1075 memcpy(tx->hdr, hdr, hdr_len);
1078 * Use the first empty entry in this queue's command buffer array
1079 * to contain the Tx command and MAC header concatenated together
1080 * (payload data will be in another buffer).
1081 * Size of this varies, due to varying MAC header length.
1082 * If end is not dword aligned, we'll have 2 extra bytes at the end
1083 * of the MAC header (device reads on dword boundaries).
1084 * We'll tell device about this padding later.
1086 len = sizeof(struct iwl3945_tx_cmd) +
1087 sizeof(struct iwl_cmd_header) + hdr_len;
1090 len = (len + 3) & ~3;
1097 /* Physical address of this Tx command's header (not MAC header!),
1098 * within command buffer array. */
1099 txcmd_phys = pci_map_single(priv->pci_dev,
1100 out_cmd, sizeof(struct iwl_cmd),
1102 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1103 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1104 /* Add buffer containing Tx command and MAC(!) header to TFD's
1106 txcmd_phys += offsetof(struct iwl_cmd, hdr);
1108 /* Add buffer containing Tx command and MAC(!) header to TFD's
1110 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1111 txcmd_phys, len, 1, 0);
1113 if (info->control.hw_key)
1114 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
1116 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1117 * if any (802.11 null frames have no payload). */
1118 len = skb->len - hdr_len;
1120 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1121 len, PCI_DMA_TODEVICE);
1122 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1127 /* Total # bytes to be transmitted */
1128 len = (u16)skb->len;
1129 tx->len = cpu_to_le16(len);
1131 /* TODO need this for burst mode later on */
1132 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
1134 /* set is_hcca to 0; it probably will never be implemented */
1135 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
1137 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1138 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
1140 if (!ieee80211_has_morefrags(hdr->frame_control)) {
1141 txq->need_update = 1;
1143 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
1146 txq->need_update = 0;
1149 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
1151 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
1152 ieee80211_hdrlen(fc));
1154 /* Tell device the write index *just past* this latest filled TFD */
1155 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
1156 rc = iwl_txq_update_write_ptr(priv, txq);
1157 spin_unlock_irqrestore(&priv->lock, flags);
1162 if ((iwl_queue_space(q) < q->high_mark)
1163 && priv->mac80211_registered) {
1164 if (wait_write_ptr) {
1165 spin_lock_irqsave(&priv->lock, flags);
1166 txq->need_update = 1;
1167 iwl_txq_update_write_ptr(priv, txq);
1168 spin_unlock_irqrestore(&priv->lock, flags);
1171 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
1177 spin_unlock_irqrestore(&priv->lock, flags);
1182 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
1184 #include "iwl-spectrum.h"
1186 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
1187 #define BEACON_TIME_MASK_HIGH 0xFF000000
1188 #define TIME_UNIT 1024
1191 * extended beacon time format
1192 * time in usec will be changed into a 32-bit value in 8:24 format
1193 * the high 1 byte is the beacon counts
1194 * the lower 3 bytes is the time in usec within one beacon interval
1197 static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
1201 u32 interval = beacon_interval * 1024;
1203 if (!interval || !usec)
1206 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1207 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1209 return (quot << 24) + rem;
1212 /* base is usually what we get from ucode with each received frame,
1213 * the same as HW timer counter counting down
1216 static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
1218 u32 base_low = base & BEACON_TIME_MASK_LOW;
1219 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1220 u32 interval = beacon_interval * TIME_UNIT;
1221 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1222 (addon & BEACON_TIME_MASK_HIGH);
1224 if (base_low > addon_low)
1225 res += base_low - addon_low;
1226 else if (base_low < addon_low) {
1227 res += interval + base_low - addon_low;
1232 return cpu_to_le32(res);
1235 static int iwl3945_get_measurement(struct iwl_priv *priv,
1236 struct ieee80211_measurement_params *params,
1239 struct iwl_spectrum_cmd spectrum;
1240 struct iwl_rx_packet *res;
1241 struct iwl_host_cmd cmd = {
1242 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1243 .data = (void *)&spectrum,
1244 .meta.flags = CMD_WANT_SKB,
1246 u32 add_time = le64_to_cpu(params->start_time);
1248 int spectrum_resp_status;
1249 int duration = le16_to_cpu(params->duration);
1251 if (iwl_is_associated(priv))
1253 iwl3945_usecs_to_beacons(
1254 le64_to_cpu(params->start_time) - priv->last_tsf,
1255 le16_to_cpu(priv->rxon_timing.beacon_interval));
1257 memset(&spectrum, 0, sizeof(spectrum));
1259 spectrum.channel_count = cpu_to_le16(1);
1261 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1262 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1263 cmd.len = sizeof(spectrum);
1264 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1266 if (iwl_is_associated(priv))
1267 spectrum.start_time =
1268 iwl3945_add_beacon_time(priv->last_beacon_time,
1270 le16_to_cpu(priv->rxon_timing.beacon_interval));
1272 spectrum.start_time = 0;
1274 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1275 spectrum.channels[0].channel = params->channel;
1276 spectrum.channels[0].type = type;
1277 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
1278 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1279 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1281 rc = iwl_send_cmd_sync(priv, &cmd);
1285 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
1286 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1287 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
1291 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1292 switch (spectrum_resp_status) {
1293 case 0: /* Command will be handled */
1294 if (res->u.spectrum.id != 0xff) {
1295 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
1296 res->u.spectrum.id);
1297 priv->measurement_status &= ~MEASUREMENT_READY;
1299 priv->measurement_status |= MEASUREMENT_ACTIVE;
1303 case 1: /* Command will not be handled */
1308 dev_kfree_skb_any(cmd.meta.u.skb);
1314 static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
1315 struct iwl_rx_mem_buffer *rxb)
1317 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1318 struct iwl_alive_resp *palive;
1319 struct delayed_work *pwork;
1321 palive = &pkt->u.alive_frame;
1323 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
1325 palive->is_valid, palive->ver_type,
1326 palive->ver_subtype);
1328 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1329 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
1330 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1331 sizeof(struct iwl_alive_resp));
1332 pwork = &priv->init_alive_start;
1334 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
1335 memcpy(&priv->card_alive, &pkt->u.alive_frame,
1336 sizeof(struct iwl_alive_resp));
1337 pwork = &priv->alive_start;
1338 iwl3945_disable_events(priv);
1341 /* We delay the ALIVE response by 5ms to
1342 * give the HW RF Kill time to activate... */
1343 if (palive->is_valid == UCODE_VALID_OK)
1344 queue_delayed_work(priv->workqueue, pwork,
1345 msecs_to_jiffies(5));
1347 IWL_WARN(priv, "uCode did not respond OK.\n");
1350 static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
1351 struct iwl_rx_mem_buffer *rxb)
1353 #ifdef CONFIG_IWLWIFI_DEBUG
1354 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1357 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
1361 static void iwl3945_bg_beacon_update(struct work_struct *work)
1363 struct iwl_priv *priv =
1364 container_of(work, struct iwl_priv, beacon_update);
1365 struct sk_buff *beacon;
1367 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
1368 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
1371 IWL_ERR(priv, "update beacon failed\n");
1375 mutex_lock(&priv->mutex);
1376 /* new beacon skb is allocated every time; dispose previous.*/
1377 if (priv->ibss_beacon)
1378 dev_kfree_skb(priv->ibss_beacon);
1380 priv->ibss_beacon = beacon;
1381 mutex_unlock(&priv->mutex);
1383 iwl3945_send_beacon_cmd(priv);
1386 static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
1387 struct iwl_rx_mem_buffer *rxb)
1389 #ifdef CONFIG_IWLWIFI_DEBUG
1390 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1391 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
1392 u8 rate = beacon->beacon_notify_hdr.rate;
1394 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
1395 "tsf %d %d rate %d\n",
1396 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1397 beacon->beacon_notify_hdr.failure_frame,
1398 le32_to_cpu(beacon->ibss_mgr_status),
1399 le32_to_cpu(beacon->high_tsf),
1400 le32_to_cpu(beacon->low_tsf), rate);
1403 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
1404 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1405 queue_work(priv->workqueue, &priv->beacon_update);
1408 /* Handle notification from uCode that card's power state is changing
1409 * due to software, hardware, or critical temperature RFKILL */
1410 static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
1411 struct iwl_rx_mem_buffer *rxb)
1413 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1414 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1415 unsigned long status = priv->status;
1417 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
1418 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1419 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1421 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
1422 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1424 if (flags & HW_CARD_DISABLED)
1425 set_bit(STATUS_RF_KILL_HW, &priv->status);
1427 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1430 if (flags & SW_CARD_DISABLED)
1431 set_bit(STATUS_RF_KILL_SW, &priv->status);
1433 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1435 iwl_scan_cancel(priv);
1437 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1438 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1439 (test_bit(STATUS_RF_KILL_SW, &status) !=
1440 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1441 queue_work(priv->workqueue, &priv->rf_kill);
1443 wake_up_interruptible(&priv->wait_command_queue);
1447 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
1449 * Setup the RX handlers for each of the reply types sent from the uCode
1452 * This function chains into the hardware specific files for them to setup
1453 * any hardware specific handlers as well.
1455 static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
1457 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1458 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
1459 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
1460 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
1461 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
1462 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
1463 iwl_rx_pm_debug_statistics_notif;
1464 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
1467 * The same handler is used for both the REPLY to a discrete
1468 * statistics request from the host as well as for the periodic
1469 * statistics notifications (after received beacons) from the uCode.
1471 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1472 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
1474 iwl_setup_spectrum_handlers(priv);
1475 iwl_setup_rx_scan_handlers(priv);
1476 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
1478 /* Set up hardware specific Rx handlers */
1479 iwl3945_hw_rx_handler_setup(priv);
1483 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1484 * When FW advances 'R' index, all entries between old and new 'R' index
1485 * need to be reclaimed.
1487 static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
1488 int txq_id, int index)
1490 struct iwl_tx_queue *txq = &priv->txq[txq_id];
1491 struct iwl_queue *q = &txq->q;
1494 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
1495 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
1496 "is out of range [0-%d] %d %d.\n", txq_id,
1497 index, q->n_bd, q->write_ptr, q->read_ptr);
1501 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1502 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1504 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
1505 q->write_ptr, q->read_ptr);
1506 queue_work(priv->workqueue, &priv->restart);
1515 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
1516 * @rxb: Rx buffer to reclaim
1518 * If an Rx buffer has an async callback associated with it the callback
1519 * will be executed. The attached skb (if present) will only be freed
1520 * if the callback returns 1
1522 static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
1523 struct iwl_rx_mem_buffer *rxb)
1525 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1526 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1527 int txq_id = SEQ_TO_QUEUE(sequence);
1528 int index = SEQ_TO_INDEX(sequence);
1529 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
1531 struct iwl_cmd *cmd;
1533 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1534 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1536 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1537 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1538 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1542 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1543 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
1545 /* Input error checking is done when commands are added to queue. */
1546 if (cmd->meta.flags & CMD_WANT_SKB) {
1547 cmd->meta.source->u.skb = rxb->skb;
1549 } else if (cmd->meta.u.callback &&
1550 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1553 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
1555 if (!(cmd->meta.flags & CMD_ASYNC)) {
1556 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1557 wake_up_interruptible(&priv->wait_command_queue);
1561 /************************** RX-FUNCTIONS ****************************/
1563 * Rx theory of operation
1565 * The host allocates 32 DMA target addresses and passes the host address
1566 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1570 * The host/firmware share two index registers for managing the Rx buffers.
1572 * The READ index maps to the first position that the firmware may be writing
1573 * to -- the driver can read up to (but not including) this position and get
1575 * The READ index is managed by the firmware once the card is enabled.
1577 * The WRITE index maps to the last position the driver has read from -- the
1578 * position preceding WRITE is the last slot the firmware can place a packet.
1580 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1583 * During initialization, the host sets up the READ queue position to the first
1584 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1586 * When the firmware places a packet in a buffer, it will advance the READ index
1587 * and fire the RX interrupt. The driver can then query the READ index and
1588 * process as many packets as possible, moving the WRITE index forward as it
1589 * resets the Rx queue buffers with new memory.
1591 * The management in the driver is as follows:
1592 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1593 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
1594 * to replenish the iwl->rxq->rx_free.
1595 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
1596 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1597 * 'processed' and 'read' driver indexes as well)
1598 * + A received packet is processed and handed to the kernel network stack,
1599 * detached from the iwl->rxq. The driver 'processed' index is updated.
1600 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1601 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1602 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1603 * were enough free buffers and RX_STALLED is set it is cleared.
1608 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
1609 * iwl3945_rx_queue_restock
1610 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
1611 * queue, updates firmware pointers, and updates
1612 * the WRITE index. If insufficient rx_free buffers
1613 * are available, schedules iwl3945_rx_replenish
1615 * -- enable interrupts --
1616 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
1617 * READ INDEX, detaching the SKB from the pool.
1618 * Moves the packet buffer from queue to rx_used.
1619 * Calls iwl3945_rx_queue_restock to refill any empty
1626 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
1628 static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
1629 dma_addr_t dma_addr)
1631 return cpu_to_le32((u32)dma_addr);
1635 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
1637 * If there are slots in the RX queue that need to be restocked,
1638 * and we have free pre-allocated buffers, fill the ranks as much
1639 * as we can, pulling from rx_free.
1641 * This moves the 'write' index forward to catch up with 'processed', and
1642 * also updates the memory address in the firmware to reference the new
1645 static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
1647 struct iwl_rx_queue *rxq = &priv->rxq;
1648 struct list_head *element;
1649 struct iwl_rx_mem_buffer *rxb;
1650 unsigned long flags;
1653 spin_lock_irqsave(&rxq->lock, flags);
1654 write = rxq->write & ~0x7;
1655 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
1656 /* Get next free Rx buffer, remove from free list */
1657 element = rxq->rx_free.next;
1658 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
1661 /* Point to Rx buffer via next RBD in circular buffer */
1662 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
1663 rxq->queue[rxq->write] = rxb;
1664 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1667 spin_unlock_irqrestore(&rxq->lock, flags);
1668 /* If the pre-allocated buffer pool is dropping low, schedule to
1670 if (rxq->free_count <= RX_LOW_WATERMARK)
1671 queue_work(priv->workqueue, &priv->rx_replenish);
1674 /* If we've added more space for the firmware to place data, tell it.
1675 * Increment device's write pointer in multiples of 8. */
1676 if ((write != (rxq->write & ~0x7))
1677 || (abs(rxq->write - rxq->read) > 7)) {
1678 spin_lock_irqsave(&rxq->lock, flags);
1679 rxq->need_update = 1;
1680 spin_unlock_irqrestore(&rxq->lock, flags);
1681 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
1690 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
1692 * When moving to rx_free an SKB is allocated for the slot.
1694 * Also restock the Rx queue via iwl3945_rx_queue_restock.
1695 * This is called as a scheduled work item (except for during initialization)
1697 static void iwl3945_rx_allocate(struct iwl_priv *priv)
1699 struct iwl_rx_queue *rxq = &priv->rxq;
1700 struct list_head *element;
1701 struct iwl_rx_mem_buffer *rxb;
1702 unsigned long flags;
1703 spin_lock_irqsave(&rxq->lock, flags);
1704 while (!list_empty(&rxq->rx_used)) {
1705 element = rxq->rx_used.next;
1706 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
1708 /* Alloc a new receive buffer */
1710 alloc_skb(priv->hw_params.rx_buf_size,
1711 __GFP_NOWARN | GFP_ATOMIC);
1713 if (net_ratelimit())
1714 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
1715 /* We don't reschedule replenish work here -- we will
1716 * call the restock method and if it still needs
1717 * more buffers it will schedule replenish */
1721 /* If radiotap head is required, reserve some headroom here.
1722 * The physical head count is a variable rx_stats->phy_count.
1723 * We reserve 4 bytes here. Plus these extra bytes, the
1724 * headroom of the physical head should be enough for the
1725 * radiotap head that iwl3945 supported. See iwl3945_rt.
1727 skb_reserve(rxb->skb, 4);
1729 priv->alloc_rxb_skb++;
1732 /* Get physical address of RB/SKB */
1733 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1735 priv->hw_params.rx_buf_size,
1736 PCI_DMA_FROMDEVICE);
1737 list_add_tail(&rxb->list, &rxq->rx_free);
1740 spin_unlock_irqrestore(&rxq->lock, flags);
1744 * this should be called while priv->lock is locked
1746 static void __iwl3945_rx_replenish(void *data)
1748 struct iwl_priv *priv = data;
1750 iwl3945_rx_allocate(priv);
1751 iwl3945_rx_queue_restock(priv);
1755 void iwl3945_rx_replenish(void *data)
1757 struct iwl_priv *priv = data;
1758 unsigned long flags;
1760 iwl3945_rx_allocate(priv);
1762 spin_lock_irqsave(&priv->lock, flags);
1763 iwl3945_rx_queue_restock(priv);
1764 spin_unlock_irqrestore(&priv->lock, flags);
1767 /* Convert linear signal-to-noise ratio into dB */
1768 static u8 ratio2dB[100] = {
1769 /* 0 1 2 3 4 5 6 7 8 9 */
1770 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1771 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1772 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1773 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1774 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1775 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1776 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1777 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1778 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1779 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1782 /* Calculates a relative dB value from a ratio of linear
1783 * (i.e. not dB) signal levels.
1784 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
1785 int iwl3945_calc_db_from_ratio(int sig_ratio)
1787 /* 1000:1 or higher just report as 60 dB */
1788 if (sig_ratio >= 1000)
1791 /* 100:1 or higher, divide by 10 and use table,
1792 * add 20 dB to make up for divide by 10 */
1793 if (sig_ratio >= 100)
1794 return 20 + (int)ratio2dB[sig_ratio/10];
1796 /* We shouldn't see this */
1800 /* Use table for ratios 1:1 - 99:1 */
1801 return (int)ratio2dB[sig_ratio];
1804 #define PERFECT_RSSI (-20) /* dBm */
1805 #define WORST_RSSI (-95) /* dBm */
1806 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1808 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
1809 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1810 * about formulas used below. */
1811 int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
1814 int degradation = PERFECT_RSSI - rssi_dbm;
1816 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1817 * as indicator; formula is (signal dbm - noise dbm).
1818 * SNR at or above 40 is a great signal (100%).
1819 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1820 * Weakest usable signal is usually 10 - 15 dB SNR. */
1822 if (rssi_dbm - noise_dbm >= 40)
1824 else if (rssi_dbm < noise_dbm)
1826 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1828 /* Else use just the signal level.
1829 * This formula is a least squares fit of data points collected and
1830 * compared with a reference system that had a percentage (%) display
1831 * for signal quality. */
1833 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1834 (15 * RSSI_RANGE + 62 * degradation)) /
1835 (RSSI_RANGE * RSSI_RANGE);
1839 else if (sig_qual < 1)
1846 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
1848 * Uses the priv->rx_handlers callback function array to invoke
1849 * the appropriate handlers, including command responses,
1850 * frame-received notifications, and other notifications.
1852 static void iwl3945_rx_handle(struct iwl_priv *priv)
1854 struct iwl_rx_mem_buffer *rxb;
1855 struct iwl_rx_packet *pkt;
1856 struct iwl_rx_queue *rxq = &priv->rxq;
1859 unsigned long flags;
1863 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1864 * buffer that the driver may process (last buffer filled by ucode). */
1865 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
1868 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
1870 /* Rx interrupt, but nothing sent from uCode */
1872 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
1875 rxb = rxq->queue[i];
1877 /* If an RXB doesn't have a Rx queue slot associated with it,
1878 * then a bug has been introduced in the queue refilling
1879 * routines -- catch it here */
1880 BUG_ON(rxb == NULL);
1882 rxq->queue[i] = NULL;
1884 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
1885 priv->hw_params.rx_buf_size,
1886 PCI_DMA_FROMDEVICE);
1887 pkt = (struct iwl_rx_packet *)rxb->skb->data;
1889 /* Reclaim a command buffer only if this packet is a response
1890 * to a (driver-originated) command.
1891 * If the packet (e.g. Rx frame) originated from uCode,
1892 * there is no command buffer to reclaim.
1893 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1894 * but apparently a few don't get set; catch them here. */
1895 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1896 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1897 (pkt->hdr.cmd != REPLY_TX);
1899 /* Based on type of command response or notification,
1900 * handle those that need handling via function in
1901 * rx_handlers table. See iwl3945_setup_rx_handlers() */
1902 if (priv->rx_handlers[pkt->hdr.cmd]) {
1903 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
1904 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1905 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1906 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1908 /* No handling needed */
1909 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
1910 "r %d i %d No handler needed for %s, 0x%02x\n",
1911 r, i, get_cmd_string(pkt->hdr.cmd),
1916 /* Invoke any callbacks, transfer the skb to caller, and
1917 * fire off the (possibly) blocking iwl_send_cmd()
1918 * as we reclaim the driver command queue */
1919 if (rxb && rxb->skb)
1920 iwl3945_tx_cmd_complete(priv, rxb);
1922 IWL_WARN(priv, "Claim null rxb?\n");
1925 /* For now we just don't re-use anything. We can tweak this
1926 * later to try and re-use notification packets and SKBs that
1927 * fail to Rx correctly */
1928 if (rxb->skb != NULL) {
1929 priv->alloc_rxb_skb--;
1930 dev_kfree_skb_any(rxb->skb);
1934 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1935 priv->hw_params.rx_buf_size,
1936 PCI_DMA_FROMDEVICE);
1937 spin_lock_irqsave(&rxq->lock, flags);
1938 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1939 spin_unlock_irqrestore(&rxq->lock, flags);
1940 i = (i + 1) & RX_QUEUE_MASK;
1941 /* If there are a lot of unused frames,
1942 * restock the Rx queue so ucode won't assert. */
1947 __iwl3945_rx_replenish(priv);
1953 /* Backtrack one entry */
1955 iwl3945_rx_queue_restock(priv);
1958 /* call this function to flush any scheduled tasklet */
1959 static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1961 /* wait to make sure we flush pending tasklet*/
1962 synchronize_irq(priv->pci_dev->irq);
1963 tasklet_kill(&priv->irq_tasklet);
1966 static const char *desc_lookup(int i)
1974 return "BAD_CHECKSUM";
1976 return "NMI_INTERRUPT";
1980 return "FATAL_ERROR";
1986 #define ERROR_START_OFFSET (1 * sizeof(u32))
1987 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
1989 static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
1992 u32 desc, time, count, base, data1;
1993 u32 blink1, blink2, ilink1, ilink2;
1996 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1998 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
1999 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
2003 rc = iwl_grab_nic_access(priv);
2005 IWL_WARN(priv, "Can not read from adapter at this time.\n");
2009 count = iwl_read_targ_mem(priv, base);
2011 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
2012 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2013 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2014 priv->status, count);
2017 IWL_ERR(priv, "Desc Time asrtPC blink2 "
2018 "ilink1 nmiPC Line\n");
2019 for (i = ERROR_START_OFFSET;
2020 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2021 i += ERROR_ELEM_SIZE) {
2022 desc = iwl_read_targ_mem(priv, base + i);
2024 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
2026 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
2028 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
2030 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
2032 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
2034 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
2037 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2038 desc_lookup(desc), desc, time, blink1, blink2,
2039 ilink1, ilink2, data1);
2042 iwl_release_nic_access(priv);
2046 #define EVENT_START_OFFSET (6 * sizeof(u32))
2049 * iwl3945_print_event_log - Dump error event log to syslog
2051 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
2053 static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
2054 u32 num_events, u32 mode)
2057 u32 base; /* SRAM byte address of event log header */
2058 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2059 u32 ptr; /* SRAM byte address of log data */
2060 u32 ev, time, data; /* event log data */
2062 if (num_events == 0)
2065 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2068 event_size = 2 * sizeof(u32);
2070 event_size = 3 * sizeof(u32);
2072 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2074 /* "time" is actually "data" for mode 0 (no timestamp).
2075 * place event id # at far right for easier visual parsing. */
2076 for (i = 0; i < num_events; i++) {
2077 ev = iwl_read_targ_mem(priv, ptr);
2079 time = iwl_read_targ_mem(priv, ptr);
2083 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2085 data = iwl_read_targ_mem(priv, ptr);
2087 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
2092 static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
2095 u32 base; /* SRAM byte address of event log header */
2096 u32 capacity; /* event log capacity in # entries */
2097 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2098 u32 num_wraps; /* # times uCode wrapped to top of log */
2099 u32 next_entry; /* index of next entry to be written by uCode */
2100 u32 size; /* # entries that we'll print */
2102 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2103 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
2104 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
2108 rc = iwl_grab_nic_access(priv);
2110 IWL_WARN(priv, "Can not read from adapter at this time.\n");
2114 /* event log header */
2115 capacity = iwl_read_targ_mem(priv, base);
2116 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2117 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2118 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
2120 size = num_wraps ? capacity : next_entry;
2122 /* bail out if nothing in log */
2124 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
2125 iwl_release_nic_access(priv);
2129 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
2132 /* if uCode has wrapped back to top of log, start at the oldest entry,
2133 * i.e the next one that uCode would fill. */
2135 iwl3945_print_event_log(priv, next_entry,
2136 capacity - next_entry, mode);
2138 /* (then/else) start at top of log */
2139 iwl3945_print_event_log(priv, 0, next_entry, mode);
2141 iwl_release_nic_access(priv);
2144 static void iwl3945_error_recovery(struct iwl_priv *priv)
2146 unsigned long flags;
2148 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2149 sizeof(priv->staging_rxon));
2150 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2151 iwl3945_commit_rxon(priv);
2153 iwl3945_add_station(priv, priv->bssid, 1, 0);
2155 spin_lock_irqsave(&priv->lock, flags);
2156 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
2157 priv->error_recovering = 0;
2158 spin_unlock_irqrestore(&priv->lock, flags);
2161 static void iwl3945_irq_tasklet(struct iwl_priv *priv)
2163 u32 inta, handled = 0;
2165 unsigned long flags;
2166 #ifdef CONFIG_IWLWIFI_DEBUG
2170 spin_lock_irqsave(&priv->lock, flags);
2172 /* Ack/clear/reset pending uCode interrupts.
2173 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2174 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
2175 inta = iwl_read32(priv, CSR_INT);
2176 iwl_write32(priv, CSR_INT, inta);
2178 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2179 * Any new interrupts that happen after this, either while we're
2180 * in this tasklet, or later, will show up in next ISR/tasklet. */
2181 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2182 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
2184 #ifdef CONFIG_IWLWIFI_DEBUG
2185 if (priv->debug_level & IWL_DL_ISR) {
2186 /* just for debug */
2187 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2188 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
2189 inta, inta_mask, inta_fh);
2193 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2194 * atomic, make sure that inta covers all the interrupts that
2195 * we've discovered, even if FH interrupt came in just after
2196 * reading CSR_INT. */
2197 if (inta_fh & CSR39_FH_INT_RX_MASK)
2198 inta |= CSR_INT_BIT_FH_RX;
2199 if (inta_fh & CSR39_FH_INT_TX_MASK)
2200 inta |= CSR_INT_BIT_FH_TX;
2202 /* Now service all interrupt bits discovered above. */
2203 if (inta & CSR_INT_BIT_HW_ERR) {
2204 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
2206 /* Tell the device to stop sending interrupts */
2207 iwl_disable_interrupts(priv);
2209 iwl_irq_handle_error(priv);
2211 handled |= CSR_INT_BIT_HW_ERR;
2213 spin_unlock_irqrestore(&priv->lock, flags);
2218 #ifdef CONFIG_IWLWIFI_DEBUG
2219 if (priv->debug_level & (IWL_DL_ISR)) {
2220 /* NIC fires this, but we don't use it, redundant with WAKEUP */
2221 if (inta & CSR_INT_BIT_SCD)
2222 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
2223 "the frame/frames.\n");
2225 /* Alive notification via Rx interrupt will do the real work */
2226 if (inta & CSR_INT_BIT_ALIVE)
2227 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
2230 /* Safely ignore these bits for debug checks below */
2231 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
2233 /* Error detected by uCode */
2234 if (inta & CSR_INT_BIT_SW_ERR) {
2235 IWL_ERR(priv, "Microcode SW error detected. "
2236 "Restarting 0x%X.\n", inta);
2237 iwl_irq_handle_error(priv);
2238 handled |= CSR_INT_BIT_SW_ERR;
2241 /* uCode wakes up after power-down sleep */
2242 if (inta & CSR_INT_BIT_WAKEUP) {
2243 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
2244 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
2245 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2246 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2247 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2248 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2249 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2250 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
2252 handled |= CSR_INT_BIT_WAKEUP;
2255 /* All uCode command responses, including Tx command responses,
2256 * Rx "responses" (frame-received notification), and other
2257 * notifications from uCode come through here*/
2258 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
2259 iwl3945_rx_handle(priv);
2260 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2263 if (inta & CSR_INT_BIT_FH_TX) {
2264 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
2266 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2267 if (!iwl_grab_nic_access(priv)) {
2268 iwl_write_direct32(priv, FH39_TCSR_CREDIT
2269 (FH39_SRVC_CHNL), 0x0);
2270 iwl_release_nic_access(priv);
2272 handled |= CSR_INT_BIT_FH_TX;
2275 if (inta & ~handled)
2276 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
2278 if (inta & ~CSR_INI_SET_MASK) {
2279 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
2280 inta & ~CSR_INI_SET_MASK);
2281 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
2284 /* Re-enable all interrupts */
2285 /* only Re-enable if disabled by irq */
2286 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2287 iwl_enable_interrupts(priv);
2289 #ifdef CONFIG_IWLWIFI_DEBUG
2290 if (priv->debug_level & (IWL_DL_ISR)) {
2291 inta = iwl_read32(priv, CSR_INT);
2292 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2293 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2294 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
2295 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2298 spin_unlock_irqrestore(&priv->lock, flags);
2301 static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
2302 enum ieee80211_band band,
2303 u8 is_active, u8 n_probes,
2304 struct iwl3945_scan_channel *scan_ch)
2306 const struct ieee80211_channel *channels = NULL;
2307 const struct ieee80211_supported_band *sband;
2308 const struct iwl_channel_info *ch_info;
2309 u16 passive_dwell = 0;
2310 u16 active_dwell = 0;
2313 sband = iwl_get_hw_mode(priv, band);
2317 channels = sband->channels;
2319 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2320 passive_dwell = iwl_get_passive_dwell_time(priv, band);
2322 if (passive_dwell <= active_dwell)
2323 passive_dwell = active_dwell + 1;
2325 for (i = 0, added = 0; i < sband->n_channels; i++) {
2326 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2329 scan_ch->channel = channels[i].hw_value;
2331 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
2332 if (!is_channel_valid(ch_info)) {
2333 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
2338 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2339 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
2340 /* If passive , set up for auto-switch
2341 * and use long active_dwell time.
2343 if (!is_active || is_channel_passive(ch_info) ||
2344 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2345 scan_ch->type = 0; /* passive */
2346 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2347 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2349 scan_ch->type = 1; /* active */
2352 /* Set direct probe bits. These may be used both for active
2353 * scan channels (probes gets sent right away),
2354 * or for passive channels (probes get se sent only after
2355 * hearing clear Rx packet).*/
2356 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2358 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
2360 /* uCode v1 does not allow setting direct probe bits on
2361 * passive channel. */
2362 if ((scan_ch->type & 1) && n_probes)
2363 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
2366 /* Set txpower levels to defaults */
2367 scan_ch->tpc.dsp_atten = 110;
2368 /* scan_pwr_info->tpc.dsp_atten; */
2370 /*scan_pwr_info->tpc.tx_gain; */
2371 if (band == IEEE80211_BAND_5GHZ)
2372 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2374 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2375 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
2377 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
2381 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
2383 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2384 (scan_ch->type & 1) ?
2385 active_dwell : passive_dwell);
2391 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
2395 static void iwl3945_init_hw_rates(struct iwl_priv *priv,
2396 struct ieee80211_rate *rates)
2400 for (i = 0; i < IWL_RATE_COUNT; i++) {
2401 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2402 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2403 rates[i].hw_value_short = i;
2405 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
2407 * If CCK != 1M then set short preamble rate flag.
2409 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
2410 0 : IEEE80211_RATE_SHORT_PREAMBLE;
2415 /******************************************************************************
2417 * uCode download functions
2419 ******************************************************************************/
2421 static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
2423 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2424 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2425 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2426 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2427 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2428 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
2432 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
2433 * looking at all data.
2435 static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
2442 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
2444 rc = iwl_grab_nic_access(priv);
2448 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
2449 IWL39_RTC_INST_LOWER_BOUND);
2452 for (; len > 0; len -= sizeof(u32), image++) {
2453 /* read data comes through single port, auto-incr addr */
2454 /* NOTE: Use the debugless read so we don't flood kernel log
2455 * if IWL_DL_IO is set */
2456 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2457 if (val != le32_to_cpu(*image)) {
2458 IWL_ERR(priv, "uCode INST section is invalid at "
2459 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2460 save_len - len, val, le32_to_cpu(*image));
2468 iwl_release_nic_access(priv);
2471 IWL_DEBUG_INFO(priv,
2472 "ucode image in INSTRUCTION memory is good\n");
2479 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
2480 * using sample data 100 bytes apart. If these sample points are good,
2481 * it's a pretty good bet that everything between them is good, too.
2483 static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
2490 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
2492 rc = iwl_grab_nic_access(priv);
2496 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2497 /* read data comes through single port, auto-incr addr */
2498 /* NOTE: Use the debugless read so we don't flood kernel log
2499 * if IWL_DL_IO is set */
2500 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
2501 i + IWL39_RTC_INST_LOWER_BOUND);
2502 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2503 if (val != le32_to_cpu(*image)) {
2504 #if 0 /* Enable this if you want to see details */
2505 IWL_ERR(priv, "uCode INST section is invalid at "
2506 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2516 iwl_release_nic_access(priv);
2523 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
2524 * and verify its contents
2526 static int iwl3945_verify_ucode(struct iwl_priv *priv)
2533 image = (__le32 *)priv->ucode_boot.v_addr;
2534 len = priv->ucode_boot.len;
2535 rc = iwl3945_verify_inst_sparse(priv, image, len);
2537 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
2541 /* Try initialize */
2542 image = (__le32 *)priv->ucode_init.v_addr;
2543 len = priv->ucode_init.len;
2544 rc = iwl3945_verify_inst_sparse(priv, image, len);
2546 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
2550 /* Try runtime/protocol */
2551 image = (__le32 *)priv->ucode_code.v_addr;
2552 len = priv->ucode_code.len;
2553 rc = iwl3945_verify_inst_sparse(priv, image, len);
2555 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
2559 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
2561 /* Since nothing seems to match, show first several data entries in
2562 * instruction SRAM, so maybe visual inspection will give a clue.
2563 * Selection of bootstrap image (vs. other images) is arbitrary. */
2564 image = (__le32 *)priv->ucode_boot.v_addr;
2565 len = priv->ucode_boot.len;
2566 rc = iwl3945_verify_inst_full(priv, image, len);
2571 static void iwl3945_nic_start(struct iwl_priv *priv)
2573 /* Remove all resets to allow NIC to operate */
2574 iwl_write32(priv, CSR_RESET, 0);
2578 * iwl3945_read_ucode - Read uCode images from disk file.
2580 * Copy into buffers for card to fetch via bus-mastering
2582 static int iwl3945_read_ucode(struct iwl_priv *priv)
2584 struct iwl_ucode *ucode;
2585 int ret = -EINVAL, index;
2586 const struct firmware *ucode_raw;
2587 /* firmware file name contains uCode/driver compatibility version */
2588 const char *name_pre = priv->cfg->fw_name_pre;
2589 const unsigned int api_max = priv->cfg->ucode_api_max;
2590 const unsigned int api_min = priv->cfg->ucode_api_min;
2594 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
2596 /* Ask kernel firmware_class module to get the boot firmware off disk.
2597 * request_firmware() is synchronous, file is in memory on return. */
2598 for (index = api_max; index >= api_min; index--) {
2599 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2600 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2602 IWL_ERR(priv, "%s firmware file req failed: %d\n",
2609 if (index < api_max)
2610 IWL_ERR(priv, "Loaded firmware %s, "
2611 "which is deprecated. "
2612 " Please use API v%u instead.\n",
2614 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2615 "(%zd bytes) from disk\n",
2616 buf, ucode_raw->size);
2624 /* Make sure that we got at least our header! */
2625 if (ucode_raw->size < sizeof(*ucode)) {
2626 IWL_ERR(priv, "File size way too small!\n");
2631 /* Data from ucode file: header followed by uCode images */
2632 ucode = (void *)ucode_raw->data;
2634 priv->ucode_ver = le32_to_cpu(ucode->ver);
2635 api_ver = IWL_UCODE_API(priv->ucode_ver);
2636 inst_size = le32_to_cpu(ucode->inst_size);
2637 data_size = le32_to_cpu(ucode->data_size);
2638 init_size = le32_to_cpu(ucode->init_size);
2639 init_data_size = le32_to_cpu(ucode->init_data_size);
2640 boot_size = le32_to_cpu(ucode->boot_size);
2642 /* api_ver should match the api version forming part of the
2643 * firmware filename ... but we don't check for that and only rely
2644 * on the API version read from firware header from here on forward */
2646 if (api_ver < api_min || api_ver > api_max) {
2647 IWL_ERR(priv, "Driver unable to support your firmware API. "
2648 "Driver supports v%u, firmware is v%u.\n",
2650 priv->ucode_ver = 0;
2654 if (api_ver != api_max)
2655 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
2656 "got %u. New firmware can be obtained "
2657 "from http://www.intellinuxwireless.org.\n",
2660 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2661 IWL_UCODE_MAJOR(priv->ucode_ver),
2662 IWL_UCODE_MINOR(priv->ucode_ver),
2663 IWL_UCODE_API(priv->ucode_ver),
2664 IWL_UCODE_SERIAL(priv->ucode_ver));
2666 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
2668 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2670 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2672 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2674 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2676 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2680 /* Verify size of file vs. image size info in file's header */
2681 if (ucode_raw->size < sizeof(*ucode) +
2682 inst_size + data_size + init_size +
2683 init_data_size + boot_size) {
2685 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2691 /* Verify that uCode images will fit in card's SRAM */
2692 if (inst_size > IWL39_MAX_INST_SIZE) {
2693 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
2699 if (data_size > IWL39_MAX_DATA_SIZE) {
2700 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
2705 if (init_size > IWL39_MAX_INST_SIZE) {
2706 IWL_DEBUG_INFO(priv,
2707 "uCode init instr len %d too large to fit in\n",
2712 if (init_data_size > IWL39_MAX_DATA_SIZE) {
2713 IWL_DEBUG_INFO(priv,
2714 "uCode init data len %d too large to fit in\n",
2719 if (boot_size > IWL39_MAX_BSM_SIZE) {
2720 IWL_DEBUG_INFO(priv,
2721 "uCode boot instr len %d too large to fit in\n",
2727 /* Allocate ucode buffers for card's bus-master loading ... */
2729 /* Runtime instructions and 2 copies of data:
2730 * 1) unmodified from disk
2731 * 2) backup cache for save/restore during power-downs */
2732 priv->ucode_code.len = inst_size;
2733 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
2735 priv->ucode_data.len = data_size;
2736 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
2738 priv->ucode_data_backup.len = data_size;
2739 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2741 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
2742 !priv->ucode_data_backup.v_addr)
2745 /* Initialization instructions and data */
2746 if (init_size && init_data_size) {
2747 priv->ucode_init.len = init_size;
2748 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
2750 priv->ucode_init_data.len = init_data_size;
2751 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2753 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2757 /* Bootstrap (instructions only, no data) */
2759 priv->ucode_boot.len = boot_size;
2760 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
2762 if (!priv->ucode_boot.v_addr)
2766 /* Copy images into buffers for card's bus-master reads ... */
2768 /* Runtime instructions (first block of data in file) */
2769 src = &ucode->data[0];
2770 len = priv->ucode_code.len;
2771 IWL_DEBUG_INFO(priv,
2772 "Copying (but not loading) uCode instr len %zd\n", len);
2773 memcpy(priv->ucode_code.v_addr, src, len);
2774 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
2775 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2777 /* Runtime data (2nd block)
2778 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
2779 src = &ucode->data[inst_size];
2780 len = priv->ucode_data.len;
2781 IWL_DEBUG_INFO(priv,
2782 "Copying (but not loading) uCode data len %zd\n", len);
2783 memcpy(priv->ucode_data.v_addr, src, len);
2784 memcpy(priv->ucode_data_backup.v_addr, src, len);
2786 /* Initialization instructions (3rd block) */
2788 src = &ucode->data[inst_size + data_size];
2789 len = priv->ucode_init.len;
2790 IWL_DEBUG_INFO(priv,
2791 "Copying (but not loading) init instr len %zd\n", len);
2792 memcpy(priv->ucode_init.v_addr, src, len);
2795 /* Initialization data (4th block) */
2796 if (init_data_size) {
2797 src = &ucode->data[inst_size + data_size + init_size];
2798 len = priv->ucode_init_data.len;
2799 IWL_DEBUG_INFO(priv,
2800 "Copying (but not loading) init data len %zd\n", len);
2801 memcpy(priv->ucode_init_data.v_addr, src, len);
2804 /* Bootstrap instructions (5th block) */
2805 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2806 len = priv->ucode_boot.len;
2807 IWL_DEBUG_INFO(priv,
2808 "Copying (but not loading) boot instr len %zd\n", len);
2809 memcpy(priv->ucode_boot.v_addr, src, len);
2811 /* We have our copies now, allow OS release its copies */
2812 release_firmware(ucode_raw);
2816 IWL_ERR(priv, "failed to allocate pci memory\n");
2818 iwl3945_dealloc_ucode_pci(priv);
2821 release_firmware(ucode_raw);
2829 * iwl3945_set_ucode_ptrs - Set uCode address location
2831 * Tell initialization uCode where to find runtime uCode.
2833 * BSM registers initially contain pointers to initialization uCode.
2834 * We need to replace them to load runtime uCode inst and data,
2835 * and to save runtime data when powering down.
2837 static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
2842 unsigned long flags;
2844 /* bits 31:0 for 3945 */
2845 pinst = priv->ucode_code.p_addr;
2846 pdata = priv->ucode_data_backup.p_addr;
2848 spin_lock_irqsave(&priv->lock, flags);
2849 rc = iwl_grab_nic_access(priv);
2851 spin_unlock_irqrestore(&priv->lock, flags);
2855 /* Tell bootstrap uCode where to find image to load */
2856 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2857 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2858 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
2859 priv->ucode_data.len);
2861 /* Inst byte count must be last to set up, bit 31 signals uCode
2862 * that all new ptr/size info is in place */
2863 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
2864 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2866 iwl_release_nic_access(priv);
2868 spin_unlock_irqrestore(&priv->lock, flags);
2870 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
2876 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
2878 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2880 * Tell "initialize" uCode to go ahead and load the runtime uCode.
2882 static void iwl3945_init_alive_start(struct iwl_priv *priv)
2884 /* Check alive response for "valid" sign from uCode */
2885 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2886 /* We had an error bringing up the hardware, so take it
2887 * all the way back down so we can try again */
2888 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
2892 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2893 * This is a paranoid check, because we would not have gotten the
2894 * "initialize" alive if code weren't properly loaded. */
2895 if (iwl3945_verify_ucode(priv)) {
2896 /* Runtime instruction load was bad;
2897 * take it all the way back down so we can try again */
2898 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
2902 /* Send pointers to protocol/runtime uCode image ... init code will
2903 * load and launch runtime uCode, which will send us another "Alive"
2905 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
2906 if (iwl3945_set_ucode_ptrs(priv)) {
2907 /* Runtime instruction load won't happen;
2908 * take it all the way back down so we can try again */
2909 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
2915 queue_work(priv->workqueue, &priv->restart);
2920 static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
2921 struct sk_buff *skb);
2924 * iwl3945_alive_start - called after REPLY_ALIVE notification received
2925 * from protocol/runtime uCode (initialization uCode's
2926 * Alive gets handled by iwl3945_init_alive_start()).
2928 static void iwl3945_alive_start(struct iwl_priv *priv)
2931 int thermal_spin = 0;
2934 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
2936 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2937 /* We had an error bringing up the hardware, so take it
2938 * all the way back down so we can try again */
2939 IWL_DEBUG_INFO(priv, "Alive failed.\n");
2943 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2944 * This is a paranoid check, because we would not have gotten the
2945 * "runtime" alive if code weren't properly loaded. */
2946 if (iwl3945_verify_ucode(priv)) {
2947 /* Runtime instruction load was bad;
2948 * take it all the way back down so we can try again */
2949 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
2953 iwl3945_clear_stations_table(priv);
2955 rc = iwl_grab_nic_access(priv);
2957 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
2961 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
2962 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
2963 iwl_release_nic_access(priv);
2966 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2967 /* if RFKILL is not on, then wait for thermal
2968 * sensor in adapter to kick in */
2969 while (iwl3945_hw_get_temperature(priv) == 0) {
2975 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
2978 set_bit(STATUS_RF_KILL_HW, &priv->status);
2980 /* After the ALIVE response, we can send commands to 3945 uCode */
2981 set_bit(STATUS_ALIVE, &priv->status);
2983 /* Clear out the uCode error bit if it is set */
2984 clear_bit(STATUS_FW_ERROR, &priv->status);
2986 if (iwl_is_rfkill(priv))
2989 ieee80211_wake_queues(priv->hw);
2991 priv->active_rate = priv->rates_mask;
2992 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2994 iwl_power_update_mode(priv, false);
2996 if (iwl_is_associated(priv)) {
2997 struct iwl3945_rxon_cmd *active_rxon =
2998 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
3000 memcpy(&priv->staging_rxon, &priv->active_rxon,
3001 sizeof(priv->staging_rxon));
3002 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3004 /* Initialize our rx_config data */
3005 iwl_connection_init_rx_config(priv, priv->iw_mode);
3008 /* Configure Bluetooth device coexistence support */
3009 iwl_send_bt_config(priv);
3011 /* Configure the adapter for unassociated operation */
3012 iwl3945_commit_rxon(priv);
3014 iwl3945_reg_txpower_periodic(priv);
3016 iwl3945_led_register(priv);
3018 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
3019 set_bit(STATUS_READY, &priv->status);
3020 wake_up_interruptible(&priv->wait_command_queue);
3022 if (priv->error_recovering)
3023 iwl3945_error_recovery(priv);
3025 /* reassociate for ADHOC mode */
3026 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3027 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3030 iwl3945_mac_beacon_update(priv->hw, beacon);
3036 queue_work(priv->workqueue, &priv->restart);
3039 static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
3041 static void __iwl3945_down(struct iwl_priv *priv)
3043 unsigned long flags;
3044 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3045 struct ieee80211_conf *conf = NULL;
3047 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
3049 conf = ieee80211_get_hw_conf(priv->hw);
3052 set_bit(STATUS_EXIT_PENDING, &priv->status);
3054 iwl3945_led_unregister(priv);
3055 iwl3945_clear_stations_table(priv);
3057 /* Unblock any waiting calls */
3058 wake_up_interruptible_all(&priv->wait_command_queue);
3060 /* Wipe out the EXIT_PENDING status bit if we are not actually
3061 * exiting the module */
3063 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3065 /* stop and reset the on-board processor */
3066 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
3068 /* tell the device to stop sending interrupts */
3069 spin_lock_irqsave(&priv->lock, flags);
3070 iwl_disable_interrupts(priv);
3071 spin_unlock_irqrestore(&priv->lock, flags);
3072 iwl_synchronize_irq(priv);
3074 if (priv->mac80211_registered)
3075 ieee80211_stop_queues(priv->hw);
3077 /* If we have not previously called iwl3945_init() then
3078 * clear all bits but the RF Kill and SUSPEND bits and return */
3079 if (!iwl_is_init(priv)) {
3080 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3082 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3084 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3085 STATUS_GEO_CONFIGURED |
3086 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3088 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3089 STATUS_EXIT_PENDING;
3093 /* ...otherwise clear out all the status bits but the RF Kill and
3094 * SUSPEND bits and continue taking the NIC down. */
3095 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3097 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3099 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3100 STATUS_GEO_CONFIGURED |
3101 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3103 test_bit(STATUS_FW_ERROR, &priv->status) <<
3105 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3106 STATUS_EXIT_PENDING;
3108 priv->cfg->ops->lib->apm_ops.reset(priv);
3109 spin_lock_irqsave(&priv->lock, flags);
3110 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
3111 spin_unlock_irqrestore(&priv->lock, flags);
3113 iwl3945_hw_txq_ctx_stop(priv);
3114 iwl3945_hw_rxq_stop(priv);
3116 spin_lock_irqsave(&priv->lock, flags);
3117 if (!iwl_grab_nic_access(priv)) {
3118 iwl_write_prph(priv, APMG_CLK_DIS_REG,
3119 APMG_CLK_VAL_DMA_CLK_RQT);
3120 iwl_release_nic_access(priv);
3122 spin_unlock_irqrestore(&priv->lock, flags);
3126 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3127 priv->cfg->ops->lib->apm_ops.stop(priv);
3129 priv->cfg->ops->lib->apm_ops.reset(priv);
3132 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
3134 if (priv->ibss_beacon)
3135 dev_kfree_skb(priv->ibss_beacon);
3136 priv->ibss_beacon = NULL;
3138 /* clear out any free frames */
3139 iwl3945_clear_free_frames(priv);
3142 static void iwl3945_down(struct iwl_priv *priv)
3144 mutex_lock(&priv->mutex);
3145 __iwl3945_down(priv);
3146 mutex_unlock(&priv->mutex);
3148 iwl3945_cancel_deferred_work(priv);
3151 #define MAX_HW_RESTARTS 5
3153 static int __iwl3945_up(struct iwl_priv *priv)
3157 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3158 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
3162 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
3163 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
3168 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
3169 IWL_ERR(priv, "ucode not available for device bring up\n");
3173 /* If platform's RF_KILL switch is NOT set to KILL */
3174 if (iwl_read32(priv, CSR_GP_CNTRL) &
3175 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3176 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3178 set_bit(STATUS_RF_KILL_HW, &priv->status);
3179 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
3180 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
3185 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
3187 rc = iwl3945_hw_nic_init(priv);
3189 IWL_ERR(priv, "Unable to int nic\n");
3193 /* make sure rfkill handshake bits are cleared */
3194 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3195 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
3196 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3198 /* clear (again), then enable host interrupts */
3199 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
3200 iwl_enable_interrupts(priv);
3202 /* really make sure rfkill handshake bits are cleared */
3203 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3204 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3206 /* Copy original ucode data image from disk into backup cache.
3207 * This will be used to initialize the on-board processor's
3208 * data SRAM for a clean start when the runtime program first loads. */
3209 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
3210 priv->ucode_data.len);
3212 /* We return success when we resume from suspend and rf_kill is on. */
3213 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3216 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3218 iwl3945_clear_stations_table(priv);
3220 /* load bootstrap state machine,
3221 * load bootstrap program into processor's memory,
3222 * prepare to load the "initialize" uCode */
3223 priv->cfg->ops->lib->load_ucode(priv);
3227 "Unable to set up bootstrap uCode: %d\n", rc);
3231 /* start card; "initialize" will load runtime ucode */
3232 iwl3945_nic_start(priv);
3234 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
3239 set_bit(STATUS_EXIT_PENDING, &priv->status);
3240 __iwl3945_down(priv);
3241 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3243 /* tried to restart and config the device for as long as our
3244 * patience could withstand */
3245 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
3250 /*****************************************************************************
3252 * Workqueue callbacks
3254 *****************************************************************************/
3256 static void iwl3945_bg_init_alive_start(struct work_struct *data)
3258 struct iwl_priv *priv =
3259 container_of(data, struct iwl_priv, init_alive_start.work);
3261 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3264 mutex_lock(&priv->mutex);
3265 iwl3945_init_alive_start(priv);
3266 mutex_unlock(&priv->mutex);
3269 static void iwl3945_bg_alive_start(struct work_struct *data)
3271 struct iwl_priv *priv =
3272 container_of(data, struct iwl_priv, alive_start.work);
3274 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3277 mutex_lock(&priv->mutex);
3278 iwl3945_alive_start(priv);
3279 mutex_unlock(&priv->mutex);
3282 static void iwl3945_rfkill_poll(struct work_struct *data)
3284 struct iwl_priv *priv =
3285 container_of(data, struct iwl_priv, rfkill_poll.work);
3286 unsigned long status = priv->status;
3288 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3289 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3291 set_bit(STATUS_RF_KILL_HW, &priv->status);
3293 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3294 queue_work(priv->workqueue, &priv->rf_kill);
3296 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3297 round_jiffies_relative(2 * HZ));
3301 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
3302 static void iwl3945_bg_request_scan(struct work_struct *data)
3304 struct iwl_priv *priv =
3305 container_of(data, struct iwl_priv, request_scan);
3306 struct iwl_host_cmd cmd = {
3307 .id = REPLY_SCAN_CMD,
3308 .len = sizeof(struct iwl3945_scan_cmd),
3309 .meta.flags = CMD_SIZE_HUGE,
3312 struct iwl3945_scan_cmd *scan;
3313 struct ieee80211_conf *conf = NULL;
3315 enum ieee80211_band band;
3316 DECLARE_SSID_BUF(ssid);
3318 conf = ieee80211_get_hw_conf(priv->hw);
3320 mutex_lock(&priv->mutex);
3322 if (!iwl_is_ready(priv)) {
3323 IWL_WARN(priv, "request scan called when driver not ready.\n");
3327 /* Make sure the scan wasn't canceled before this queued work
3328 * was given the chance to run... */
3329 if (!test_bit(STATUS_SCANNING, &priv->status))
3332 /* This should never be called or scheduled if there is currently
3333 * a scan active in the hardware. */
3334 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
3335 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3336 "Ignoring second request.\n");
3341 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3342 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
3346 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3348 "Scan request while abort pending. Queuing.\n");
3352 if (iwl_is_rfkill(priv)) {
3353 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
3357 if (!test_bit(STATUS_READY, &priv->status)) {
3359 "Scan request while uninitialized. Queuing.\n");
3363 if (!priv->scan_bands) {
3364 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
3369 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
3370 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
3377 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
3379 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3380 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3382 if (iwl_is_associated(priv)) {
3385 u32 suspend_time = 100;
3386 u32 scan_suspend_time = 100;
3387 unsigned long flags;
3389 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
3391 spin_lock_irqsave(&priv->lock, flags);
3392 interval = priv->beacon_int;
3393 spin_unlock_irqrestore(&priv->lock, flags);
3395 scan->suspend_time = 0;
3396 scan->max_out_time = cpu_to_le32(200 * 1024);
3398 interval = suspend_time;
3400 * suspend time format:
3401 * 0-19: beacon interval in usec (time before exec.)
3403 * 24-31: number of beacons (suspend between channels)
3406 extra = (suspend_time / interval) << 24;
3407 scan_suspend_time = 0xFF0FFFFF &
3408 (extra | ((suspend_time % interval) * 1024));
3410 scan->suspend_time = cpu_to_le32(scan_suspend_time);
3411 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
3412 scan_suspend_time, interval);
3415 /* We should add the ability for user to lock to PASSIVE ONLY */
3416 if (priv->one_direct_scan) {
3417 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3418 print_ssid(ssid, priv->direct_ssid,
3419 priv->direct_ssid_len));
3420 scan->direct_scan[0].id = WLAN_EID_SSID;
3421 scan->direct_scan[0].len = priv->direct_ssid_len;
3422 memcpy(scan->direct_scan[0].ssid,
3423 priv->direct_ssid, priv->direct_ssid_len);
3426 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
3428 /* We don't build a direct scan probe request; the uCode will do
3429 * that based on the direct_mask added to each channel entry */
3430 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
3431 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
3432 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3434 /* flags + rate selection */
3436 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
3437 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3438 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3439 scan->good_CRC_th = 0;
3440 band = IEEE80211_BAND_2GHZ;
3441 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
3442 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3443 scan->good_CRC_th = IWL_GOOD_CRC_TH;
3444 band = IEEE80211_BAND_5GHZ;
3446 IWL_WARN(priv, "Invalid scan band count\n");
3450 scan->tx_cmd.len = cpu_to_le16(
3451 iwl_fill_probe_req(priv, band,
3452 (struct ieee80211_mgmt *)scan->data,
3453 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3455 /* select Rx antennas */
3456 scan->flags |= iwl3945_get_antenna_flags(priv);
3458 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
3459 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3461 scan->channel_count =
3462 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3464 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
3466 if (scan->channel_count == 0) {
3467 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
3471 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
3472 scan->channel_count * sizeof(struct iwl3945_scan_channel);
3474 scan->len = cpu_to_le16(cmd.len);
3476 set_bit(STATUS_SCAN_HW, &priv->status);
3477 rc = iwl_send_cmd_sync(priv, &cmd);
3481 queue_delayed_work(priv->workqueue, &priv->scan_check,
3482 IWL_SCAN_CHECK_WATCHDOG);
3484 mutex_unlock(&priv->mutex);
3488 /* can not perform scan make sure we clear scanning
3489 * bits from status so next scan request can be performed.
3490 * if we dont clear scanning status bit here all next scan
3493 clear_bit(STATUS_SCAN_HW, &priv->status);
3494 clear_bit(STATUS_SCANNING, &priv->status);
3496 /* inform mac80211 scan aborted */
3497 queue_work(priv->workqueue, &priv->scan_completed);
3498 mutex_unlock(&priv->mutex);
3501 static void iwl3945_bg_up(struct work_struct *data)
3503 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
3505 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3508 mutex_lock(&priv->mutex);
3510 mutex_unlock(&priv->mutex);
3511 iwl_rfkill_set_hw_state(priv);
3514 static void iwl3945_bg_restart(struct work_struct *data)
3516 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
3518 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3522 queue_work(priv->workqueue, &priv->up);
3525 static void iwl3945_bg_rx_replenish(struct work_struct *data)
3527 struct iwl_priv *priv =
3528 container_of(data, struct iwl_priv, rx_replenish);
3530 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3533 mutex_lock(&priv->mutex);
3534 iwl3945_rx_replenish(priv);
3535 mutex_unlock(&priv->mutex);
3538 #define IWL_DELAY_NEXT_SCAN (HZ*2)
3540 static void iwl3945_post_associate(struct iwl_priv *priv)
3543 struct ieee80211_conf *conf = NULL;
3545 if (priv->iw_mode == NL80211_IFTYPE_AP) {
3546 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
3551 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
3552 priv->assoc_id, priv->active_rxon.bssid_addr);
3554 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3557 if (!priv->vif || !priv->is_open)
3560 iwl_scan_cancel_timeout(priv, 200);
3562 conf = ieee80211_get_hw_conf(priv->hw);
3564 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3565 iwl3945_commit_rxon(priv);
3567 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
3568 iwl3945_setup_rxon_timing(priv);
3569 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3570 sizeof(priv->rxon_timing), &priv->rxon_timing);
3572 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3573 "Attempting to continue.\n");
3575 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
3577 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
3579 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
3580 priv->assoc_id, priv->beacon_int);
3582 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
3583 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3585 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3587 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
3588 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
3589 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
3591 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
3593 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
3594 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
3598 iwl3945_commit_rxon(priv);
3600 switch (priv->iw_mode) {
3601 case NL80211_IFTYPE_STATION:
3602 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
3605 case NL80211_IFTYPE_ADHOC:
3608 iwl3945_add_station(priv, priv->bssid, 0, 0);
3609 iwl3945_sync_sta(priv, IWL_STA_ID,
3610 (priv->band == IEEE80211_BAND_5GHZ) ?
3611 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3613 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3614 iwl3945_send_beacon_cmd(priv);
3619 IWL_ERR(priv, "%s Should not be called in %d mode\n",
3620 __func__, priv->iw_mode);
3624 iwl_activate_qos(priv, 0);
3626 /* we have just associated, don't start scan too early */
3627 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
3630 static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
3632 /*****************************************************************************
3634 * mac80211 entry point functions
3636 *****************************************************************************/
3638 #define UCODE_READY_TIMEOUT (2 * HZ)
3640 static int iwl3945_mac_start(struct ieee80211_hw *hw)
3642 struct iwl_priv *priv = hw->priv;
3645 IWL_DEBUG_MAC80211(priv, "enter\n");
3647 /* we should be verifying the device is ready to be opened */
3648 mutex_lock(&priv->mutex);
3650 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
3651 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3652 * ucode filename and max sizes are card-specific. */
3654 if (!priv->ucode_code.len) {
3655 ret = iwl3945_read_ucode(priv);
3657 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
3658 mutex_unlock(&priv->mutex);
3659 goto out_release_irq;
3663 ret = __iwl3945_up(priv);
3665 mutex_unlock(&priv->mutex);
3667 iwl_rfkill_set_hw_state(priv);
3670 goto out_release_irq;
3672 IWL_DEBUG_INFO(priv, "Start UP work.\n");
3674 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3677 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3678 * mac80211 will not be run successfully. */
3679 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3680 test_bit(STATUS_READY, &priv->status),
3681 UCODE_READY_TIMEOUT);
3683 if (!test_bit(STATUS_READY, &priv->status)) {
3685 "Wait for START_ALIVE timeout after %dms.\n",
3686 jiffies_to_msecs(UCODE_READY_TIMEOUT));
3688 goto out_release_irq;
3692 /* ucode is running and will send rfkill notifications,
3693 * no need to poll the killswitch state anymore */
3694 cancel_delayed_work(&priv->rfkill_poll);
3697 IWL_DEBUG_MAC80211(priv, "leave\n");
3702 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
3706 static void iwl3945_mac_stop(struct ieee80211_hw *hw)
3708 struct iwl_priv *priv = hw->priv;
3710 IWL_DEBUG_MAC80211(priv, "enter\n");
3712 if (!priv->is_open) {
3713 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
3719 if (iwl_is_ready_rf(priv)) {
3720 /* stop mac, cancel any scan request and clear
3721 * RXON_FILTER_ASSOC_MSK BIT
3723 mutex_lock(&priv->mutex);
3724 iwl_scan_cancel_timeout(priv, 100);
3725 mutex_unlock(&priv->mutex);
3730 flush_workqueue(priv->workqueue);
3732 /* start polling the killswitch state again */
3733 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3734 round_jiffies_relative(2 * HZ));
3736 IWL_DEBUG_MAC80211(priv, "leave\n");
3739 static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3741 struct iwl_priv *priv = hw->priv;
3743 IWL_DEBUG_MAC80211(priv, "enter\n");
3745 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
3746 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
3748 if (iwl3945_tx_skb(priv, skb))
3749 dev_kfree_skb_any(skb);
3751 IWL_DEBUG_MAC80211(priv, "leave\n");
3752 return NETDEV_TX_OK;
3755 static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
3756 struct ieee80211_if_init_conf *conf)
3758 struct iwl_priv *priv = hw->priv;
3759 unsigned long flags;
3761 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
3764 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
3768 spin_lock_irqsave(&priv->lock, flags);
3769 priv->vif = conf->vif;
3770 priv->iw_mode = conf->type;
3772 spin_unlock_irqrestore(&priv->lock, flags);
3774 mutex_lock(&priv->mutex);
3776 if (conf->mac_addr) {
3777 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
3778 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3781 if (iwl_is_ready(priv))
3782 iwl3945_set_mode(priv, conf->type);
3784 mutex_unlock(&priv->mutex);
3786 IWL_DEBUG_MAC80211(priv, "leave\n");
3791 * iwl3945_mac_config - mac80211 config callback
3793 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3794 * be set inappropriately and the driver currently sets the hardware up to
3795 * use it whenever needed.
3797 static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
3799 struct iwl_priv *priv = hw->priv;
3800 const struct iwl_channel_info *ch_info;
3801 struct ieee80211_conf *conf = &hw->conf;
3802 unsigned long flags;
3805 mutex_lock(&priv->mutex);
3806 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3807 conf->channel->hw_value);
3809 if (!iwl_is_ready(priv)) {
3810 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
3815 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
3816 test_bit(STATUS_SCANNING, &priv->status))) {
3817 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
3818 set_bit(STATUS_CONF_PENDING, &priv->status);
3819 mutex_unlock(&priv->mutex);
3823 spin_lock_irqsave(&priv->lock, flags);
3825 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3826 conf->channel->hw_value);
3827 if (!is_channel_valid(ch_info)) {
3828 IWL_DEBUG_SCAN(priv,
3829 "Channel %d [%d] is INVALID for this band.\n",
3830 conf->channel->hw_value, conf->channel->band);
3831 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
3832 spin_unlock_irqrestore(&priv->lock, flags);
3837 iwl_set_rxon_channel(priv, conf->channel);
3839 iwl_set_flags_for_band(priv, conf->channel->band);
3841 /* The list of supported rates and rate mask can be different
3842 * for each phymode; since the phymode may have changed, reset
3843 * the rate mask to what mac80211 lists */
3846 spin_unlock_irqrestore(&priv->lock, flags);
3848 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
3849 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
3850 iwl3945_hw_channel_switch(priv, conf->channel);
3855 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
3856 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - waiting for uCode\n");
3860 if (!conf->radio_enabled) {
3861 iwl_radio_kill_sw_disable_radio(priv);
3862 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
3866 if (iwl_is_rfkill(priv)) {
3867 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
3874 if (memcmp(&priv->active_rxon,
3875 &priv->staging_rxon, sizeof(priv->staging_rxon)))
3876 iwl3945_commit_rxon(priv);
3878 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
3880 IWL_DEBUG_MAC80211(priv, "leave\n");
3883 clear_bit(STATUS_CONF_PENDING, &priv->status);
3884 mutex_unlock(&priv->mutex);
3888 static void iwl3945_config_ap(struct iwl_priv *priv)
3892 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3895 /* The following should be done only at AP bring up */
3896 if (!(iwl_is_associated(priv))) {
3898 /* RXON - unassoc (to set timing command) */
3899 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3900 iwl3945_commit_rxon(priv);
3903 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
3904 iwl3945_setup_rxon_timing(priv);
3905 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3906 sizeof(priv->rxon_timing),
3907 &priv->rxon_timing);
3909 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3910 "Attempting to continue.\n");
3912 /* FIXME: what should be the assoc_id for AP? */
3913 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
3914 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
3915 priv->staging_rxon.flags |=
3916 RXON_FLG_SHORT_PREAMBLE_MSK;
3918 priv->staging_rxon.flags &=
3919 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3921 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
3922 if (priv->assoc_capability &
3923 WLAN_CAPABILITY_SHORT_SLOT_TIME)
3924 priv->staging_rxon.flags |=
3925 RXON_FLG_SHORT_SLOT_MSK;
3927 priv->staging_rxon.flags &=
3928 ~RXON_FLG_SHORT_SLOT_MSK;
3930 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
3931 priv->staging_rxon.flags &=
3932 ~RXON_FLG_SHORT_SLOT_MSK;
3934 /* restore RXON assoc */
3935 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
3936 iwl3945_commit_rxon(priv);
3937 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
3939 iwl3945_send_beacon_cmd(priv);
3941 /* FIXME - we need to add code here to detect a totally new
3942 * configuration, reset the AP, unassoc, rxon timing, assoc,
3943 * clear sta table, add BCAST sta... */
3946 static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3947 struct ieee80211_vif *vif,
3948 struct ieee80211_if_conf *conf)
3950 struct iwl_priv *priv = hw->priv;
3956 if (priv->vif != vif) {
3957 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
3961 /* handle this temporarily here */
3962 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
3963 conf->changed & IEEE80211_IFCC_BEACON) {
3964 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3967 mutex_lock(&priv->mutex);
3968 rc = iwl3945_mac_beacon_update(hw, beacon);
3969 mutex_unlock(&priv->mutex);
3974 if (!iwl_is_alive(priv))
3977 mutex_lock(&priv->mutex);
3980 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
3983 * very dubious code was here; the probe filtering flag is never set:
3985 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3986 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
3989 if (priv->iw_mode == NL80211_IFTYPE_AP) {
3991 conf->bssid = priv->mac_addr;
3992 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
3993 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
3996 if (priv->ibss_beacon)
3997 dev_kfree_skb(priv->ibss_beacon);
3999 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
4002 if (iwl_is_rfkill(priv))
4005 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4006 !is_multicast_ether_addr(conf->bssid)) {
4007 /* If there is currently a HW scan going on in the background
4008 * then we need to cancel it else the RXON below will fail. */
4009 if (iwl_scan_cancel_timeout(priv, 100)) {
4010 IWL_WARN(priv, "Aborted scan still in progress "
4012 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
4013 mutex_unlock(&priv->mutex);
4016 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
4018 /* TODO: Audit driver for usage of these members and see
4019 * if mac80211 deprecates them (priv->bssid looks like it
4020 * shouldn't be there, but I haven't scanned the IBSS code
4021 * to verify) - jpk */
4022 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4024 if (priv->iw_mode == NL80211_IFTYPE_AP)
4025 iwl3945_config_ap(priv);
4027 rc = iwl3945_commit_rxon(priv);
4028 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
4029 iwl3945_add_station(priv,
4030 priv->active_rxon.bssid_addr, 1, 0);
4034 iwl_scan_cancel_timeout(priv, 100);
4035 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4036 iwl3945_commit_rxon(priv);
4040 IWL_DEBUG_MAC80211(priv, "leave\n");
4041 mutex_unlock(&priv->mutex);
4046 static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
4047 struct ieee80211_if_init_conf *conf)
4049 struct iwl_priv *priv = hw->priv;
4051 IWL_DEBUG_MAC80211(priv, "enter\n");
4053 mutex_lock(&priv->mutex);
4055 if (iwl_is_ready_rf(priv)) {
4056 iwl_scan_cancel_timeout(priv, 100);
4057 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4058 iwl3945_commit_rxon(priv);
4060 if (priv->vif == conf->vif) {
4062 memset(priv->bssid, 0, ETH_ALEN);
4064 mutex_unlock(&priv->mutex);
4066 IWL_DEBUG_MAC80211(priv, "leave\n");
4069 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4071 static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4072 struct ieee80211_vif *vif,
4073 struct ieee80211_bss_conf *bss_conf,
4076 struct iwl_priv *priv = hw->priv;
4078 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
4080 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
4081 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
4082 bss_conf->use_short_preamble);
4083 if (bss_conf->use_short_preamble)
4084 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
4086 priv->staging_rxon.flags &=
4087 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4090 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
4091 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4092 bss_conf->use_cts_prot);
4093 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
4094 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
4096 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
4099 if (changes & BSS_CHANGED_ASSOC) {
4100 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
4101 /* This should never happen as this function should
4102 * never be called from interrupt context. */
4103 if (WARN_ON_ONCE(in_interrupt()))
4105 if (bss_conf->assoc) {
4106 priv->assoc_id = bss_conf->aid;
4107 priv->beacon_int = bss_conf->beacon_int;
4108 priv->timestamp = bss_conf->timestamp;
4109 priv->assoc_capability = bss_conf->assoc_capability;
4110 priv->power_data.dtim_period = bss_conf->dtim_period;
4111 priv->next_scan_jiffies = jiffies +
4112 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4113 mutex_lock(&priv->mutex);
4114 iwl3945_post_associate(priv);
4115 mutex_unlock(&priv->mutex);
4118 IWL_DEBUG_MAC80211(priv,
4119 "DISASSOC %d\n", bss_conf->assoc);
4121 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
4122 IWL_DEBUG_MAC80211(priv,
4123 "Associated Changes %d\n", changes);
4124 iwl3945_send_rxon_assoc(priv);
4129 static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4130 struct ieee80211_vif *vif,
4131 struct ieee80211_sta *sta,
4132 struct ieee80211_key_conf *key)
4134 struct iwl_priv *priv = hw->priv;
4137 u8 sta_id = IWL_INVALID_STATION;
4140 IWL_DEBUG_MAC80211(priv, "enter\n");
4142 if (iwl3945_mod_params.sw_crypto) {
4143 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
4147 addr = sta ? sta->addr : iwl_bcast_addr;
4148 static_key = !iwl_is_associated(priv);
4151 sta_id = iwl3945_hw_find_station(priv, addr);
4152 if (sta_id == IWL_INVALID_STATION) {
4153 IWL_DEBUG_MAC80211(priv, "leave - %pMnot in station map.\n",
4159 mutex_lock(&priv->mutex);
4160 iwl_scan_cancel_timeout(priv, 100);
4161 mutex_unlock(&priv->mutex);
4166 ret = iwl3945_set_static_key(priv, key);
4168 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
4169 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
4173 ret = iwl3945_remove_static_key(priv);
4175 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4176 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
4182 IWL_DEBUG_MAC80211(priv, "leave\n");
4187 static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
4188 const struct ieee80211_tx_queue_params *params)
4190 struct iwl_priv *priv = hw->priv;
4191 unsigned long flags;
4194 IWL_DEBUG_MAC80211(priv, "enter\n");
4196 if (!iwl_is_ready_rf(priv)) {
4197 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4201 if (queue >= AC_NUM) {
4202 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
4206 q = AC_NUM - 1 - queue;
4208 spin_lock_irqsave(&priv->lock, flags);
4210 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4211 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4212 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4213 priv->qos_data.def_qos_parm.ac[q].edca_txop =
4214 cpu_to_le16((params->txop * 32));
4216 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4217 priv->qos_data.qos_active = 1;
4219 spin_unlock_irqrestore(&priv->lock, flags);
4221 mutex_lock(&priv->mutex);
4222 if (priv->iw_mode == NL80211_IFTYPE_AP)
4223 iwl_activate_qos(priv, 1);
4224 else if (priv->assoc_id && iwl_is_associated(priv))
4225 iwl_activate_qos(priv, 0);
4227 mutex_unlock(&priv->mutex);
4229 IWL_DEBUG_MAC80211(priv, "leave\n");
4233 static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
4234 struct ieee80211_tx_queue_stats *stats)
4236 struct iwl_priv *priv = hw->priv;
4238 struct iwl_tx_queue *txq;
4239 struct iwl_queue *q;
4240 unsigned long flags;
4242 IWL_DEBUG_MAC80211(priv, "enter\n");
4244 if (!iwl_is_ready_rf(priv)) {
4245 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4249 spin_lock_irqsave(&priv->lock, flags);
4251 for (i = 0; i < AC_NUM; i++) {
4252 txq = &priv->txq[i];
4254 avail = iwl_queue_space(q);
4256 stats[i].len = q->n_window - avail;
4257 stats[i].limit = q->n_window - q->high_mark;
4258 stats[i].count = q->n_window;
4261 spin_unlock_irqrestore(&priv->lock, flags);
4263 IWL_DEBUG_MAC80211(priv, "leave\n");
4268 static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
4270 struct iwl_priv *priv = hw->priv;
4271 unsigned long flags;
4273 mutex_lock(&priv->mutex);
4274 IWL_DEBUG_MAC80211(priv, "enter\n");
4276 iwl_reset_qos(priv);
4278 spin_lock_irqsave(&priv->lock, flags);
4280 priv->assoc_capability = 0;
4282 /* new association get rid of ibss beacon skb */
4283 if (priv->ibss_beacon)
4284 dev_kfree_skb(priv->ibss_beacon);
4286 priv->ibss_beacon = NULL;
4288 priv->beacon_int = priv->hw->conf.beacon_int;
4289 priv->timestamp = 0;
4290 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
4291 priv->beacon_int = 0;
4293 spin_unlock_irqrestore(&priv->lock, flags);
4295 if (!iwl_is_ready_rf(priv)) {
4296 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
4297 mutex_unlock(&priv->mutex);
4301 /* we are restarting association process
4302 * clear RXON_FILTER_ASSOC_MSK bit
4304 if (priv->iw_mode != NL80211_IFTYPE_AP) {
4305 iwl_scan_cancel_timeout(priv, 100);
4306 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4307 iwl3945_commit_rxon(priv);
4310 /* Per mac80211.h: This is only used in IBSS mode... */
4311 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
4313 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
4314 mutex_unlock(&priv->mutex);
4320 mutex_unlock(&priv->mutex);
4322 IWL_DEBUG_MAC80211(priv, "leave\n");
4326 static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
4328 struct iwl_priv *priv = hw->priv;
4329 unsigned long flags;
4332 IWL_DEBUG_MAC80211(priv, "enter\n");
4334 if (!iwl_is_ready_rf(priv)) {
4335 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
4339 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
4340 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
4344 spin_lock_irqsave(&priv->lock, flags);
4346 if (priv->ibss_beacon)
4347 dev_kfree_skb(priv->ibss_beacon);
4349 priv->ibss_beacon = skb;
4352 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
4353 priv->timestamp = le64_to_cpu(timestamp);
4355 IWL_DEBUG_MAC80211(priv, "leave\n");
4356 spin_unlock_irqrestore(&priv->lock, flags);
4358 iwl_reset_qos(priv);
4360 iwl3945_post_associate(priv);
4366 /*****************************************************************************
4370 *****************************************************************************/
4372 #ifdef CONFIG_IWLWIFI_DEBUG
4375 * The following adds a new attribute to the sysfs representation
4376 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4377 * used for controlling the debug level.
4379 * See the level definitions in iwl for details.
4381 static ssize_t show_debug_level(struct device *d,
4382 struct device_attribute *attr, char *buf)
4384 struct iwl_priv *priv = d->driver_data;
4386 return sprintf(buf, "0x%08X\n", priv->debug_level);
4388 static ssize_t store_debug_level(struct device *d,
4389 struct device_attribute *attr,
4390 const char *buf, size_t count)
4392 struct iwl_priv *priv = d->driver_data;
4396 ret = strict_strtoul(buf, 0, &val);
4398 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
4400 priv->debug_level = val;
4402 return strnlen(buf, count);
4405 static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4406 show_debug_level, store_debug_level);
4408 #endif /* CONFIG_IWLWIFI_DEBUG */
4410 static ssize_t show_temperature(struct device *d,
4411 struct device_attribute *attr, char *buf)
4413 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4415 if (!iwl_is_alive(priv))
4418 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
4421 static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4423 static ssize_t show_tx_power(struct device *d,
4424 struct device_attribute *attr, char *buf)
4426 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4427 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
4430 static ssize_t store_tx_power(struct device *d,
4431 struct device_attribute *attr,
4432 const char *buf, size_t count)
4434 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4435 char *p = (char *)buf;
4438 val = simple_strtoul(p, &p, 10);
4440 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
4442 iwl3945_hw_reg_set_txpower(priv, val);
4447 static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4449 static ssize_t show_flags(struct device *d,
4450 struct device_attribute *attr, char *buf)
4452 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4454 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
4457 static ssize_t store_flags(struct device *d,
4458 struct device_attribute *attr,
4459 const char *buf, size_t count)
4461 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4462 u32 flags = simple_strtoul(buf, NULL, 0);
4464 mutex_lock(&priv->mutex);
4465 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
4466 /* Cancel any currently running scans... */
4467 if (iwl_scan_cancel_timeout(priv, 100))
4468 IWL_WARN(priv, "Could not cancel scan.\n");
4470 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
4472 priv->staging_rxon.flags = cpu_to_le32(flags);
4473 iwl3945_commit_rxon(priv);
4476 mutex_unlock(&priv->mutex);
4481 static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4483 static ssize_t show_filter_flags(struct device *d,
4484 struct device_attribute *attr, char *buf)
4486 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4488 return sprintf(buf, "0x%04X\n",
4489 le32_to_cpu(priv->active_rxon.filter_flags));
4492 static ssize_t store_filter_flags(struct device *d,
4493 struct device_attribute *attr,
4494 const char *buf, size_t count)
4496 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4497 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4499 mutex_lock(&priv->mutex);
4500 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
4501 /* Cancel any currently running scans... */
4502 if (iwl_scan_cancel_timeout(priv, 100))
4503 IWL_WARN(priv, "Could not cancel scan.\n");
4505 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
4506 "0x%04X\n", filter_flags);
4507 priv->staging_rxon.filter_flags =
4508 cpu_to_le32(filter_flags);
4509 iwl3945_commit_rxon(priv);
4512 mutex_unlock(&priv->mutex);
4517 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4518 store_filter_flags);
4520 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
4522 static ssize_t show_measurement(struct device *d,
4523 struct device_attribute *attr, char *buf)
4525 struct iwl_priv *priv = dev_get_drvdata(d);
4526 struct iwl_spectrum_notification measure_report;
4527 u32 size = sizeof(measure_report), len = 0, ofs = 0;
4528 u8 *data = (u8 *)&measure_report;
4529 unsigned long flags;
4531 spin_lock_irqsave(&priv->lock, flags);
4532 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4533 spin_unlock_irqrestore(&priv->lock, flags);
4536 memcpy(&measure_report, &priv->measure_report, size);
4537 priv->measurement_status = 0;
4538 spin_unlock_irqrestore(&priv->lock, flags);
4540 while (size && (PAGE_SIZE - len)) {
4541 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4542 PAGE_SIZE - len, 1);
4544 if (PAGE_SIZE - len)
4548 size -= min(size, 16U);
4554 static ssize_t store_measurement(struct device *d,
4555 struct device_attribute *attr,
4556 const char *buf, size_t count)
4558 struct iwl_priv *priv = dev_get_drvdata(d);
4559 struct ieee80211_measurement_params params = {
4560 .channel = le16_to_cpu(priv->active_rxon.channel),
4561 .start_time = cpu_to_le64(priv->last_tsf),
4562 .duration = cpu_to_le16(1),
4564 u8 type = IWL_MEASURE_BASIC;
4570 strncpy(buffer, buf, min(sizeof(buffer), count));
4571 channel = simple_strtoul(p, NULL, 0);
4573 params.channel = channel;
4576 while (*p && *p != ' ')
4579 type = simple_strtoul(p + 1, NULL, 0);
4582 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
4583 "channel %d (for '%s')\n", type, params.channel, buf);
4584 iwl3945_get_measurement(priv, ¶ms, type);
4589 static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4590 show_measurement, store_measurement);
4591 #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
4593 static ssize_t store_retry_rate(struct device *d,
4594 struct device_attribute *attr,
4595 const char *buf, size_t count)
4597 struct iwl_priv *priv = dev_get_drvdata(d);
4599 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4600 if (priv->retry_rate <= 0)
4601 priv->retry_rate = 1;
4606 static ssize_t show_retry_rate(struct device *d,
4607 struct device_attribute *attr, char *buf)
4609 struct iwl_priv *priv = dev_get_drvdata(d);
4610 return sprintf(buf, "%d", priv->retry_rate);
4613 static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4617 static ssize_t store_power_level(struct device *d,
4618 struct device_attribute *attr,
4619 const char *buf, size_t count)
4621 struct iwl_priv *priv = dev_get_drvdata(d);
4626 mutex_lock(&priv->mutex);
4628 if (!iwl_is_ready(priv)) {
4633 ret = strict_strtoul(buf, 10, &mode);
4637 ret = iwl_power_set_user_mode(priv, mode);
4639 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4645 mutex_unlock(&priv->mutex);
4649 static ssize_t show_power_level(struct device *d,
4650 struct device_attribute *attr, char *buf)
4652 struct iwl_priv *priv = dev_get_drvdata(d);
4653 int mode = priv->power_data.user_power_setting;
4654 int system = priv->power_data.system_power_setting;
4655 int level = priv->power_data.power_mode;
4659 case IWL_POWER_SYS_AUTO:
4660 p += sprintf(p, "SYSTEM:auto");
4662 case IWL_POWER_SYS_AC:
4663 p += sprintf(p, "SYSTEM:ac");
4665 case IWL_POWER_SYS_BATTERY:
4666 p += sprintf(p, "SYSTEM:battery");
4670 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4672 p += sprintf(p, "\tINDEX:%d", level);
4673 p += sprintf(p, "\n");
4677 static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4678 show_power_level, store_power_level);
4680 #define MAX_WX_STRING 80
4682 /* Values are in microsecond */
4683 static const s32 timeout_duration[] = {
4690 static const s32 period_duration[] = {
4698 static ssize_t show_channels(struct device *d,
4699 struct device_attribute *attr, char *buf)
4701 /* all this shit doesn't belong into sysfs anyway */
4705 static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4707 static ssize_t show_statistics(struct device *d,
4708 struct device_attribute *attr, char *buf)
4710 struct iwl_priv *priv = dev_get_drvdata(d);
4711 u32 size = sizeof(struct iwl3945_notif_statistics);
4712 u32 len = 0, ofs = 0;
4713 u8 *data = (u8 *)&priv->statistics_39;
4716 if (!iwl_is_alive(priv))
4719 mutex_lock(&priv->mutex);
4720 rc = iwl_send_statistics_request(priv, 0);
4721 mutex_unlock(&priv->mutex);
4725 "Error sending statistics request: 0x%08X\n", rc);
4729 while (size && (PAGE_SIZE - len)) {
4730 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4731 PAGE_SIZE - len, 1);
4733 if (PAGE_SIZE - len)
4737 size -= min(size, 16U);
4743 static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4745 static ssize_t show_antenna(struct device *d,
4746 struct device_attribute *attr, char *buf)
4748 struct iwl_priv *priv = dev_get_drvdata(d);
4750 if (!iwl_is_alive(priv))
4753 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
4756 static ssize_t store_antenna(struct device *d,
4757 struct device_attribute *attr,
4758 const char *buf, size_t count)
4760 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
4766 if (sscanf(buf, "%1i", &ant) != 1) {
4767 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
4771 if ((ant >= 0) && (ant <= 2)) {
4772 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
4773 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
4775 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
4781 static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4783 static ssize_t show_status(struct device *d,
4784 struct device_attribute *attr, char *buf)
4786 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
4787 if (!iwl_is_alive(priv))
4789 return sprintf(buf, "0x%08x\n", (int)priv->status);
4792 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4794 static ssize_t dump_error_log(struct device *d,
4795 struct device_attribute *attr,
4796 const char *buf, size_t count)
4798 char *p = (char *)buf;
4801 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
4803 return strnlen(buf, count);
4806 static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4808 static ssize_t dump_event_log(struct device *d,
4809 struct device_attribute *attr,
4810 const char *buf, size_t count)
4812 char *p = (char *)buf;
4815 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
4817 return strnlen(buf, count);
4820 static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4822 /*****************************************************************************
4824 * driver setup and tear down
4826 *****************************************************************************/
4828 static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
4830 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
4832 init_waitqueue_head(&priv->wait_command_queue);
4834 INIT_WORK(&priv->up, iwl3945_bg_up);
4835 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4836 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
4837 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
4838 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
4839 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4840 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
4841 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
4842 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4843 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4844 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4845 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
4847 iwl3945_hw_setup_deferred_work(priv);
4849 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
4850 iwl3945_irq_tasklet, (unsigned long)priv);
4853 static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
4855 iwl3945_hw_cancel_deferred_work(priv);
4857 cancel_delayed_work_sync(&priv->init_alive_start);
4858 cancel_delayed_work(&priv->scan_check);
4859 cancel_delayed_work(&priv->alive_start);
4860 cancel_work_sync(&priv->beacon_update);
4863 static struct attribute *iwl3945_sysfs_entries[] = {
4864 &dev_attr_antenna.attr,
4865 &dev_attr_channels.attr,
4866 &dev_attr_dump_errors.attr,
4867 &dev_attr_dump_events.attr,
4868 &dev_attr_flags.attr,
4869 &dev_attr_filter_flags.attr,
4870 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
4871 &dev_attr_measurement.attr,
4873 &dev_attr_power_level.attr,
4874 &dev_attr_retry_rate.attr,
4875 &dev_attr_statistics.attr,
4876 &dev_attr_status.attr,
4877 &dev_attr_temperature.attr,
4878 &dev_attr_tx_power.attr,
4879 #ifdef CONFIG_IWLWIFI_DEBUG
4880 &dev_attr_debug_level.attr,
4885 static struct attribute_group iwl3945_attribute_group = {
4886 .name = NULL, /* put in device directory */
4887 .attrs = iwl3945_sysfs_entries,
4890 static struct ieee80211_ops iwl3945_hw_ops = {
4891 .tx = iwl3945_mac_tx,
4892 .start = iwl3945_mac_start,
4893 .stop = iwl3945_mac_stop,
4894 .add_interface = iwl3945_mac_add_interface,
4895 .remove_interface = iwl3945_mac_remove_interface,
4896 .config = iwl3945_mac_config,
4897 .config_interface = iwl3945_mac_config_interface,
4898 .configure_filter = iwl_configure_filter,
4899 .set_key = iwl3945_mac_set_key,
4900 .get_tx_stats = iwl3945_mac_get_tx_stats,
4901 .conf_tx = iwl3945_mac_conf_tx,
4902 .reset_tsf = iwl3945_mac_reset_tsf,
4903 .bss_info_changed = iwl3945_bss_info_changed,
4904 .hw_scan = iwl_mac_hw_scan
4907 static int iwl3945_init_drv(struct iwl_priv *priv)
4910 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
4912 priv->retry_rate = 1;
4913 priv->ibss_beacon = NULL;
4915 spin_lock_init(&priv->lock);
4916 spin_lock_init(&priv->power_data.lock);
4917 spin_lock_init(&priv->sta_lock);
4918 spin_lock_init(&priv->hcmd_lock);
4920 INIT_LIST_HEAD(&priv->free_frames);
4922 mutex_init(&priv->mutex);
4924 /* Clear the driver's (not device's) station table */
4925 iwl3945_clear_stations_table(priv);
4927 priv->data_retry_limit = -1;
4928 priv->ieee_channels = NULL;
4929 priv->ieee_rates = NULL;
4930 priv->band = IEEE80211_BAND_2GHZ;
4932 priv->iw_mode = NL80211_IFTYPE_STATION;
4934 iwl_reset_qos(priv);
4936 priv->qos_data.qos_active = 0;
4937 priv->qos_data.qos_cap.val = 0;
4939 priv->rates_mask = IWL_RATES_MASK;
4940 /* If power management is turned on, default to CAM mode */
4941 priv->power_mode = IWL_POWER_MODE_CAM;
4942 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
4944 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
4945 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
4950 ret = iwl_init_channel_map(priv);
4952 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4956 /* Set up txpower settings in driver for all channels */
4957 if (iwl3945_txpower_set_from_eeprom(priv)) {
4959 goto err_free_channel_map;
4962 ret = iwlcore_init_geos(priv);
4964 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
4965 goto err_free_channel_map;
4967 iwl3945_init_hw_rates(priv, priv->ieee_rates);
4971 err_free_channel_map:
4972 iwl_free_channel_map(priv);
4977 static int iwl3945_setup_mac(struct iwl_priv *priv)
4980 struct ieee80211_hw *hw = priv->hw;
4982 hw->rate_control_algorithm = "iwl-3945-rs";
4983 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
4985 /* Tell mac80211 our characteristics */
4986 hw->flags = IEEE80211_HW_SIGNAL_DBM |
4987 IEEE80211_HW_NOISE_DBM;
4989 hw->wiphy->interface_modes =
4990 BIT(NL80211_IFTYPE_STATION) |
4991 BIT(NL80211_IFTYPE_ADHOC);
4993 hw->wiphy->custom_regulatory = true;
4995 /* Default value; 4 EDCA QOS priorities */
4998 hw->conf.beacon_int = 100;
5000 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5001 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5002 &priv->bands[IEEE80211_BAND_2GHZ];
5004 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5005 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5006 &priv->bands[IEEE80211_BAND_5GHZ];
5008 ret = ieee80211_register_hw(priv->hw);
5010 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
5013 priv->mac80211_registered = 1;
5018 static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5021 struct iwl_priv *priv;
5022 struct ieee80211_hw *hw;
5023 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
5024 struct iwl3945_eeprom *eeprom;
5025 unsigned long flags;
5027 /***********************
5028 * 1. Allocating HW data
5029 * ********************/
5031 /* mac80211 allocates memory for this device instance, including
5032 * space for this driver's private structure */
5033 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
5035 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
5040 SET_IEEE80211_DEV(hw, &pdev->dev);
5042 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5043 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
5045 "invalid queues_num, should be between %d and %d\n",
5046 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
5048 goto out_ieee80211_free_hw;
5052 * Disabling hardware scan means that mac80211 will perform scans
5053 * "the hard way", rather than using device's scan.
5055 if (iwl3945_mod_params.disable_hw_scan) {
5056 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
5057 iwl3945_hw_ops.hw_scan = NULL;
5061 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
5063 priv->pci_dev = pdev;
5065 #ifdef CONFIG_IWLWIFI_DEBUG
5066 priv->debug_level = iwl3945_mod_params.debug;
5067 atomic_set(&priv->restrict_refcnt, 0);
5070 /***************************
5071 * 2. Initializing PCI bus
5072 * *************************/
5073 if (pci_enable_device(pdev)) {
5075 goto out_ieee80211_free_hw;
5078 pci_set_master(pdev);
5080 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5082 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5084 IWL_WARN(priv, "No suitable DMA available.\n");
5085 goto out_pci_disable_device;
5088 pci_set_drvdata(pdev, priv);
5089 err = pci_request_regions(pdev, DRV_NAME);
5091 goto out_pci_disable_device;
5093 /***********************
5094 * 3. Read REV Register
5095 * ********************/
5096 priv->hw_base = pci_iomap(pdev, 0, 0);
5097 if (!priv->hw_base) {
5099 goto out_pci_release_regions;
5102 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
5103 (unsigned long long) pci_resource_len(pdev, 0));
5104 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
5106 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5107 * PCI Tx retries from interfering with C3 CPU state */
5108 pci_write_config_byte(pdev, 0x41, 0x00);
5111 err = priv->cfg->ops->lib->apm_ops.init(priv);
5113 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
5117 /***********************
5119 * ********************/
5121 /* Read the EEPROM */
5122 err = iwl_eeprom_init(priv);
5124 IWL_ERR(priv, "Unable to init EEPROM\n");
5127 /* MAC Address location in EEPROM same for 3945/4965 */
5128 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5129 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
5130 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
5131 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5133 /***********************
5134 * 5. Setup HW Constants
5135 * ********************/
5136 /* Device-specific setup */
5137 if (iwl3945_hw_set_hw_params(priv)) {
5138 IWL_ERR(priv, "failed to set hw settings\n");
5139 goto out_eeprom_free;
5142 /***********************
5144 * ********************/
5146 err = iwl3945_init_drv(priv);
5148 IWL_ERR(priv, "initializing driver failed\n");
5149 goto out_unset_hw_params;
5152 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5155 /***********************************
5156 * 7. Initialize Module Parameters
5157 * **********************************/
5159 /* Initialize module parameter values here */
5160 /* Disable radio (SW RF KILL) via parameter when loading driver */
5161 if (iwl3945_mod_params.disable) {
5162 set_bit(STATUS_RF_KILL_SW, &priv->status);
5163 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
5167 /***********************
5169 * ********************/
5171 spin_lock_irqsave(&priv->lock, flags);
5172 iwl_disable_interrupts(priv);
5173 spin_unlock_irqrestore(&priv->lock, flags);
5175 pci_enable_msi(priv->pci_dev);
5177 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
5180 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5181 goto out_disable_msi;
5184 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5186 IWL_ERR(priv, "failed to create sysfs device attributes\n");
5187 goto out_release_irq;
5190 iwl_set_rxon_channel(priv,
5191 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
5192 iwl3945_setup_deferred_work(priv);
5193 iwl3945_setup_rx_handlers(priv);
5195 /*********************************
5196 * 9. Setup and Register mac80211
5197 * *******************************/
5199 iwl_enable_interrupts(priv);
5201 err = iwl3945_setup_mac(priv);
5203 goto out_remove_sysfs;
5205 err = iwl_rfkill_init(priv);
5207 IWL_ERR(priv, "Unable to initialize RFKILL system. "
5208 "Ignoring error: %d\n", err);
5210 iwl_rfkill_set_hw_state(priv);
5212 /* Start monitoring the killswitch */
5213 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5219 destroy_workqueue(priv->workqueue);
5220 priv->workqueue = NULL;
5221 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5223 free_irq(priv->pci_dev->irq, priv);
5225 pci_disable_msi(priv->pci_dev);
5226 iwlcore_free_geos(priv);
5227 iwl_free_channel_map(priv);
5228 out_unset_hw_params:
5229 iwl3945_unset_hw_params(priv);
5231 iwl_eeprom_free(priv);
5233 pci_iounmap(pdev, priv->hw_base);
5234 out_pci_release_regions:
5235 pci_release_regions(pdev);
5236 out_pci_disable_device:
5237 pci_set_drvdata(pdev, NULL);
5238 pci_disable_device(pdev);
5239 out_ieee80211_free_hw:
5240 ieee80211_free_hw(priv->hw);
5245 static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
5247 struct iwl_priv *priv = pci_get_drvdata(pdev);
5248 unsigned long flags;
5253 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
5255 set_bit(STATUS_EXIT_PENDING, &priv->status);
5257 if (priv->mac80211_registered) {
5258 ieee80211_unregister_hw(priv->hw);
5259 priv->mac80211_registered = 0;
5264 /* make sure we flush any pending irq or
5265 * tasklet for the driver
5267 spin_lock_irqsave(&priv->lock, flags);
5268 iwl_disable_interrupts(priv);
5269 spin_unlock_irqrestore(&priv->lock, flags);
5271 iwl_synchronize_irq(priv);
5273 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5275 iwl_rfkill_unregister(priv);
5276 cancel_delayed_work(&priv->rfkill_poll);
5278 iwl3945_dealloc_ucode_pci(priv);
5281 iwl_rx_queue_free(priv, &priv->rxq);
5282 iwl3945_hw_txq_ctx_free(priv);
5284 iwl3945_unset_hw_params(priv);
5285 iwl3945_clear_stations_table(priv);
5287 /*netif_stop_queue(dev); */
5288 flush_workqueue(priv->workqueue);
5290 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
5291 * priv->workqueue... so we can't take down the workqueue
5293 destroy_workqueue(priv->workqueue);
5294 priv->workqueue = NULL;
5296 free_irq(pdev->irq, priv);
5297 pci_disable_msi(pdev);
5299 pci_iounmap(pdev, priv->hw_base);
5300 pci_release_regions(pdev);
5301 pci_disable_device(pdev);
5302 pci_set_drvdata(pdev, NULL);
5304 iwl_free_channel_map(priv);
5305 iwlcore_free_geos(priv);
5307 if (priv->ibss_beacon)
5308 dev_kfree_skb(priv->ibss_beacon);
5310 ieee80211_free_hw(priv->hw);
5315 static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5317 struct iwl_priv *priv = pci_get_drvdata(pdev);
5319 if (priv->is_open) {
5320 set_bit(STATUS_IN_SUSPEND, &priv->status);
5321 iwl3945_mac_stop(priv->hw);
5324 pci_save_state(pdev);
5325 pci_disable_device(pdev);
5326 pci_set_power_state(pdev, PCI_D3hot);
5331 static int iwl3945_pci_resume(struct pci_dev *pdev)
5333 struct iwl_priv *priv = pci_get_drvdata(pdev);
5336 pci_set_power_state(pdev, PCI_D0);
5337 ret = pci_enable_device(pdev);
5340 pci_restore_state(pdev);
5343 iwl3945_mac_start(priv->hw);
5345 clear_bit(STATUS_IN_SUSPEND, &priv->status);
5349 #endif /* CONFIG_PM */
5351 /*****************************************************************************
5353 * driver and module entry point
5355 *****************************************************************************/
5357 static struct pci_driver iwl3945_driver = {
5359 .id_table = iwl3945_hw_card_ids,
5360 .probe = iwl3945_pci_probe,
5361 .remove = __devexit_p(iwl3945_pci_remove),
5363 .suspend = iwl3945_pci_suspend,
5364 .resume = iwl3945_pci_resume,
5368 static int __init iwl3945_init(void)
5372 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5373 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
5375 ret = iwl3945_rate_control_register();
5377 printk(KERN_ERR DRV_NAME
5378 "Unable to register rate control algorithm: %d\n", ret);
5382 ret = pci_register_driver(&iwl3945_driver);
5384 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
5385 goto error_register;
5391 iwl3945_rate_control_unregister();
5395 static void __exit iwl3945_exit(void)
5397 pci_unregister_driver(&iwl3945_driver);
5398 iwl3945_rate_control_unregister();
5401 MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
5403 module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
5404 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
5405 module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
5406 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
5407 module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5408 MODULE_PARM_DESC(swcrypto,
5409 "using software crypto (default 1 [software])\n");
5410 module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
5411 MODULE_PARM_DESC(debug, "debug output mask");
5412 module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
5413 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5415 module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
5416 MODULE_PARM_DESC(queues_num, "number of hw queues.");
5418 module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5419 MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5421 module_exit(iwl3945_exit);
5422 module_init(iwl3945_init);