1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/delay.h>
37 #include <linux/skbuff.h>
38 #include <linux/netdevice.h>
39 #include <linux/wireless.h>
40 #include <linux/firmware.h>
41 #include <linux/etherdevice.h>
42 #include <linux/if_arp.h>
44 #include <net/mac80211.h>
46 #include <asm/div64.h>
48 #include "iwl-eeprom.h"
52 #include "iwl-helpers.h"
54 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
55 struct iwl4965_tx_queue *txq);
57 /******************************************************************************
61 ******************************************************************************/
64 * module name, copyright, version, etc.
65 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
68 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
70 #ifdef CONFIG_IWLWIFI_DEBUG
76 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
82 #define DRV_VERSION IWLWIFI_VERSION VD VS
85 MODULE_DESCRIPTION(DRV_DESCRIPTION);
86 MODULE_VERSION(DRV_VERSION);
87 MODULE_AUTHOR(DRV_COPYRIGHT);
88 MODULE_LICENSE("GPL");
90 __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
92 u16 fc = le16_to_cpu(hdr->frame_control);
93 int hdr_len = ieee80211_get_hdrlen(fc);
95 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
96 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
100 static const struct ieee80211_supported_band *iwl4965_get_hw_mode(
101 struct iwl_priv *priv, enum ieee80211_band band)
103 return priv->hw->wiphy->bands[band];
106 static int iwl4965_is_empty_essid(const char *essid, int essid_len)
108 /* Single white space is for Linksys APs */
109 if (essid_len == 1 && essid[0] == ' ')
112 /* Otherwise, if the entire essid is 0, we assume it is hidden */
115 if (essid[essid_len] != '\0')
122 static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
124 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
125 const char *s = essid;
128 if (iwl4965_is_empty_essid(essid, essid_len)) {
129 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
133 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
134 while (essid_len--) {
146 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
149 * Theory of operation
151 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
152 * of buffer descriptors, each of which points to one or more data buffers for
153 * the device to read from or fill. Driver and device exchange status of each
154 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
155 * entries in each circular buffer, to protect against confusing empty and full
158 * The device reads or writes the data in the queues via the device's several
159 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
161 * For Tx queue, there are low mark and high mark limits. If, after queuing
162 * the packet for Tx, free space become < low mark, Tx queue stopped. When
163 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
166 * The 4965 operates with up to 17 queues: One receive queue, one transmit
167 * queue (#4) for sending commands to the device firmware, and 15 other
168 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
170 * See more detailed info in iwl-4965-hw.h.
171 ***************************************************/
173 int iwl4965_queue_space(const struct iwl4965_queue *q)
175 int s = q->read_ptr - q->write_ptr;
177 if (q->read_ptr > q->write_ptr)
182 /* keep some reserve to not confuse empty and full situations */
190 static inline int x2_queue_used(const struct iwl4965_queue *q, int i)
192 return q->write_ptr > q->read_ptr ?
193 (i >= q->read_ptr && i < q->write_ptr) :
194 !(i < q->read_ptr && i >= q->write_ptr);
197 static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge)
199 /* This is for scan command, the big buffer at end of command array */
201 return q->n_window; /* must be power of 2 */
203 /* Otherwise, use normal size buffers */
204 return index & (q->n_window - 1);
208 * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
210 static int iwl4965_queue_init(struct iwl_priv *priv, struct iwl4965_queue *q,
211 int count, int slots_num, u32 id)
214 q->n_window = slots_num;
217 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
218 * and iwl_queue_dec_wrap are broken. */
219 BUG_ON(!is_power_of_2(count));
221 /* slots_num must be power-of-two size, otherwise
222 * get_cmd_index is broken. */
223 BUG_ON(!is_power_of_2(slots_num));
225 q->low_mark = q->n_window / 4;
229 q->high_mark = q->n_window / 8;
230 if (q->high_mark < 2)
233 q->write_ptr = q->read_ptr = 0;
239 * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
241 static int iwl4965_tx_queue_alloc(struct iwl_priv *priv,
242 struct iwl4965_tx_queue *txq, u32 id)
244 struct pci_dev *dev = priv->pci_dev;
246 /* Driver private data, only for Tx (not command) queues,
247 * not shared with device. */
248 if (id != IWL_CMD_QUEUE_NUM) {
249 txq->txb = kmalloc(sizeof(txq->txb[0]) *
250 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
252 IWL_ERROR("kmalloc for auxiliary BD "
253 "structures failed\n");
259 /* Circular buffer of transmit frame descriptors (TFDs),
260 * shared with device */
261 txq->bd = pci_alloc_consistent(dev,
262 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
266 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
267 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
284 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
286 int iwl4965_tx_queue_init(struct iwl_priv *priv,
287 struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id)
289 struct pci_dev *dev = priv->pci_dev;
294 * Alloc buffer array for commands (Tx or other types of commands).
295 * For the command queue (#4), allocate command space + one big
296 * command for scan, since scan command is very huge; the system will
297 * not have two scans at the same time, so only one is needed.
298 * For normal Tx queues (all other queues), no super-size command
301 len = sizeof(struct iwl_cmd) * slots_num;
302 if (txq_id == IWL_CMD_QUEUE_NUM)
303 len += IWL_MAX_SCAN_SIZE;
304 txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
308 /* Alloc driver data array and TFD circular buffer */
309 rc = iwl4965_tx_queue_alloc(priv, txq, txq_id);
311 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
315 txq->need_update = 0;
317 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
318 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
319 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
321 /* Initialize queue's high/low-water marks, and head/tail indexes */
322 iwl4965_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
324 /* Tell device where to find queue */
325 iwl4965_hw_tx_queue_init(priv, txq);
331 * iwl4965_tx_queue_free - Deallocate DMA queue.
332 * @txq: Transmit queue to deallocate.
334 * Empty queue by removing and destroying all BD's.
336 * 0-fill, but do not free "txq" descriptor structure.
338 void iwl4965_tx_queue_free(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
340 struct iwl4965_queue *q = &txq->q;
341 struct pci_dev *dev = priv->pci_dev;
347 /* first, empty all BD's */
348 for (; q->write_ptr != q->read_ptr;
349 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
350 iwl4965_hw_txq_free_tfd(priv, txq);
352 len = sizeof(struct iwl_cmd) * q->n_window;
353 if (q->id == IWL_CMD_QUEUE_NUM)
354 len += IWL_MAX_SCAN_SIZE;
356 /* De-alloc array of command/tx buffers */
357 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
359 /* De-alloc circular buffer of TFDs */
361 pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) *
362 txq->q.n_bd, txq->bd, txq->q.dma_addr);
364 /* De-alloc array of per-TFD driver data */
370 /* 0-fill queue descriptor structure */
371 memset(txq, 0, sizeof(*txq));
374 const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
376 /*************** STATION TABLE MANAGEMENT ****
377 * mac80211 should be examined to determine if sta_info is duplicating
378 * the functionality provided here
381 /**************************************************************/
383 #if 0 /* temporary disable till we add real remove station */
385 * iwl4965_remove_station - Remove driver's knowledge of station.
387 * NOTE: This does not remove station from device's station table.
389 static u8 iwl4965_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
391 int index = IWL_INVALID_STATION;
395 spin_lock_irqsave(&priv->sta_lock, flags);
399 else if (is_broadcast_ether_addr(addr))
400 index = priv->hw_setting.bcast_sta_id;
402 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
403 if (priv->stations[i].used &&
404 !compare_ether_addr(priv->stations[i].sta.sta.addr,
410 if (unlikely(index == IWL_INVALID_STATION))
413 if (priv->stations[index].used) {
414 priv->stations[index].used = 0;
415 priv->num_stations--;
418 BUG_ON(priv->num_stations < 0);
421 spin_unlock_irqrestore(&priv->sta_lock, flags);
427 * iwl4965_add_station_flags - Add station to tables in driver and device
429 u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr,
430 int is_ap, u8 flags, void *ht_data)
433 int index = IWL_INVALID_STATION;
434 struct iwl4965_station_entry *station;
435 unsigned long flags_spin;
436 DECLARE_MAC_BUF(mac);
438 spin_lock_irqsave(&priv->sta_lock, flags_spin);
441 else if (is_broadcast_ether_addr(addr))
442 index = priv->hw_setting.bcast_sta_id;
444 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
445 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
451 if (!priv->stations[i].used &&
452 index == IWL_INVALID_STATION)
457 /* These two conditions have the same outcome, but keep them separate
458 since they have different meanings */
459 if (unlikely(index == IWL_INVALID_STATION)) {
460 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
464 if (priv->stations[index].used &&
465 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
466 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
471 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
472 station = &priv->stations[index];
474 priv->num_stations++;
476 /* Set up the REPLY_ADD_STA command to send to device */
477 memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd));
478 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
479 station->sta.mode = 0;
480 station->sta.sta.sta_id = index;
481 station->sta.station_flags = 0;
483 #ifdef CONFIG_IWL4965_HT
484 /* BCAST station and IBSS stations do not work in HT mode */
485 if (index != priv->hw_setting.bcast_sta_id &&
486 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
487 iwl4965_set_ht_add_station(priv, index,
488 (struct ieee80211_ht_info *) ht_data);
489 #endif /*CONFIG_IWL4965_HT*/
491 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
493 /* Add station to device's station table */
494 iwl4965_send_add_station(priv, &station->sta, flags);
501 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
504 * iwl4965_enqueue_hcmd - enqueue a uCode command
505 * @priv: device private data point
506 * @cmd: a point to the ucode command structure
508 * The function returns < 0 values to indicate the operation is
509 * failed. On success, it turns the index (> 0) of command in the
512 int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
514 struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
515 struct iwl4965_queue *q = &txq->q;
516 struct iwl4965_tfd_frame *tfd;
518 struct iwl_cmd *out_cmd;
520 u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
521 dma_addr_t phys_addr;
525 /* If any of the command structures end up being larger than
526 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
527 * we will need to increase the size of the TFD entries */
528 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
529 !(cmd->meta.flags & CMD_SIZE_HUGE));
531 if (iwl_is_rfkill(priv)) {
532 IWL_DEBUG_INFO("Not sending command - RF KILL");
536 if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
537 IWL_ERROR("No space for Tx\n");
541 spin_lock_irqsave(&priv->hcmd_lock, flags);
543 tfd = &txq->bd[q->write_ptr];
544 memset(tfd, 0, sizeof(*tfd));
546 control_flags = (u32 *) tfd;
548 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
549 out_cmd = &txq->cmd[idx];
551 out_cmd->hdr.cmd = cmd->id;
552 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
553 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
555 /* At this point, the out_cmd now has all of the incoming cmd
558 out_cmd->hdr.flags = 0;
559 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
560 INDEX_TO_SEQ(q->write_ptr));
561 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
562 out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
564 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
565 offsetof(struct iwl_cmd, hdr);
566 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
568 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
569 "%d bytes at %d[%d]:%d\n",
570 get_cmd_string(out_cmd->hdr.cmd),
571 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
572 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
574 txq->need_update = 1;
576 /* Set up entry in queue's byte count circular buffer */
577 ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0);
579 /* Increment and update queue's write index */
580 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
581 iwl4965_tx_queue_update_write_ptr(priv, txq);
583 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
584 return ret ? ret : idx;
587 static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
589 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
592 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
594 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
598 int iwl4965_send_statistics_request(struct iwl_priv *priv)
601 return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
602 sizeof(flags), &flags);
606 * iwl4965_rxon_add_station - add station into station table.
608 * there is only one AP station with id= IWL_AP_ID
609 * NOTE: mutex must be held before calling this fnction
611 static int iwl4965_rxon_add_station(struct iwl_priv *priv,
612 const u8 *addr, int is_ap)
616 /* Add station to device's station table */
617 #ifdef CONFIG_IWL4965_HT
618 struct ieee80211_conf *conf = &priv->hw->conf;
619 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
622 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
623 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
624 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
627 #endif /* CONFIG_IWL4965_HT */
628 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
631 /* Set up default rate scaling table in device's station table */
632 iwl4965_add_station(priv, addr, is_ap);
638 * iwl4965_check_rxon_cmd - validate RXON structure is valid
640 * NOTE: This is really only useful during development and can eventually
641 * be #ifdef'd out once the driver is stable and folks aren't actively
644 static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon)
649 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
650 error |= le32_to_cpu(rxon->flags &
651 (RXON_FLG_TGJ_NARROW_BAND_MSK |
652 RXON_FLG_RADAR_DETECT_MSK));
654 IWL_WARNING("check 24G fields %d | %d\n",
657 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
658 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
660 IWL_WARNING("check 52 fields %d | %d\n",
662 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
664 IWL_WARNING("check 52 CCK %d | %d\n",
667 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
669 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
671 /* make sure basic rates 6Mbps and 1Mbps are supported */
672 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
673 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
675 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
677 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
679 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
681 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
682 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
684 IWL_WARNING("check CCK and short slot %d | %d\n",
687 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
688 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
690 IWL_WARNING("check CCK & auto detect %d | %d\n",
693 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
694 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
696 IWL_WARNING("check TGG and auto detect %d | %d\n",
700 IWL_WARNING("Tuning to channel %d\n",
701 le16_to_cpu(rxon->channel));
704 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
711 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
712 * @priv: staging_rxon is compared to active_rxon
714 * If the RXON structure is changing enough to require a new tune,
715 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
716 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
718 static int iwl4965_full_rxon_required(struct iwl_priv *priv)
721 /* These items are only settable from the full RXON command */
722 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
723 compare_ether_addr(priv->staging_rxon.bssid_addr,
724 priv->active_rxon.bssid_addr) ||
725 compare_ether_addr(priv->staging_rxon.node_addr,
726 priv->active_rxon.node_addr) ||
727 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
728 priv->active_rxon.wlap_bssid_addr) ||
729 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
730 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
731 (priv->staging_rxon.air_propagation !=
732 priv->active_rxon.air_propagation) ||
733 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
734 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
735 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
736 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
737 (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
738 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
741 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
742 * be updated with the RXON_ASSOC command -- however only some
743 * flag transitions are allowed using RXON_ASSOC */
745 /* Check if we are not switching bands */
746 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
747 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
750 /* Check if we are switching association toggle */
751 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
752 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
758 static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
761 struct iwl4965_rx_packet *res = NULL;
762 struct iwl4965_rxon_assoc_cmd rxon_assoc;
763 struct iwl_host_cmd cmd = {
764 .id = REPLY_RXON_ASSOC,
765 .len = sizeof(rxon_assoc),
766 .meta.flags = CMD_WANT_SKB,
769 const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon;
770 const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon;
772 if ((rxon1->flags == rxon2->flags) &&
773 (rxon1->filter_flags == rxon2->filter_flags) &&
774 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
775 (rxon1->ofdm_ht_single_stream_basic_rates ==
776 rxon2->ofdm_ht_single_stream_basic_rates) &&
777 (rxon1->ofdm_ht_dual_stream_basic_rates ==
778 rxon2->ofdm_ht_dual_stream_basic_rates) &&
779 (rxon1->rx_chain == rxon2->rx_chain) &&
780 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
781 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
785 rxon_assoc.flags = priv->staging_rxon.flags;
786 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
787 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
788 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
789 rxon_assoc.reserved = 0;
790 rxon_assoc.ofdm_ht_single_stream_basic_rates =
791 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
792 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
793 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
794 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
796 rc = iwl_send_cmd_sync(priv, &cmd);
800 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
801 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
802 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
806 priv->alloc_rxb_skb--;
807 dev_kfree_skb_any(cmd.meta.u.skb);
813 * iwl4965_commit_rxon - commit staging_rxon to hardware
815 * The RXON command in staging_rxon is committed to the hardware and
816 * the active_rxon structure is updated with the new data. This
817 * function correctly transitions out of the RXON_ASSOC_MSK state if
818 * a HW tune is required based on the RXON structure changes.
820 static int iwl4965_commit_rxon(struct iwl_priv *priv)
822 /* cast away the const for active_rxon in this function */
823 struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
824 DECLARE_MAC_BUF(mac);
827 if (!iwl_is_alive(priv))
830 /* always get timestamp with Rx frame */
831 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
833 rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
835 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
839 /* If we don't need to send a full RXON, we can use
840 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
841 * and other flags for the current radio configuration. */
842 if (!iwl4965_full_rxon_required(priv)) {
843 rc = iwl4965_send_rxon_assoc(priv);
845 IWL_ERROR("Error setting RXON_ASSOC "
846 "configuration (%d).\n", rc);
850 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
855 /* station table will be cleared */
856 priv->assoc_station_added = 0;
858 #ifdef CONFIG_IWL4965_SENSITIVITY
859 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
860 if (!priv->error_recovering)
861 priv->start_calib = 0;
863 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
864 #endif /* CONFIG_IWL4965_SENSITIVITY */
866 /* If we are currently associated and the new config requires
867 * an RXON_ASSOC and the new config wants the associated mask enabled,
868 * we must clear the associated from the active configuration
869 * before we apply the new config */
870 if (iwl_is_associated(priv) &&
871 (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
872 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
873 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
875 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
876 sizeof(struct iwl4965_rxon_cmd),
879 /* If the mask clearing failed then we set
880 * active_rxon back to what it was previously */
882 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
883 IWL_ERROR("Error clearing ASSOC_MSK on current "
884 "configuration (%d).\n", rc);
889 IWL_DEBUG_INFO("Sending RXON\n"
890 "* with%s RXON_FILTER_ASSOC_MSK\n"
893 ((priv->staging_rxon.filter_flags &
894 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
895 le16_to_cpu(priv->staging_rxon.channel),
896 print_mac(mac, priv->staging_rxon.bssid_addr));
898 iwl4965_set_rxon_hwcrypto(priv, priv->cfg->mod_params->hw_crypto);
899 /* Apply the new configuration */
900 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
901 sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
903 IWL_ERROR("Error setting new configuration (%d).\n", rc);
907 iwlcore_clear_stations_table(priv);
909 #ifdef CONFIG_IWL4965_SENSITIVITY
910 if (!priv->error_recovering)
911 priv->start_calib = 0;
913 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
914 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
915 #endif /* CONFIG_IWL4965_SENSITIVITY */
917 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
919 /* If we issue a new RXON command which required a tune then we must
920 * send a new TXPOWER command or we won't be able to Tx any frames */
921 rc = iwl4965_hw_reg_send_txpower(priv);
923 IWL_ERROR("Error setting Tx power (%d).\n", rc);
927 /* Add the broadcast address so we can send broadcast frames */
928 if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) ==
929 IWL_INVALID_STATION) {
930 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
934 /* If we have set the ASSOC_MSK and we are in BSS mode then
935 * add the IWL_AP_ID to the station rate table */
936 if (iwl_is_associated(priv) &&
937 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
938 if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
939 == IWL_INVALID_STATION) {
940 IWL_ERROR("Error adding AP address for transmit.\n");
943 priv->assoc_station_added = 1;
949 static int iwl4965_send_bt_config(struct iwl_priv *priv)
951 struct iwl4965_bt_cmd bt_cmd = {
959 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
960 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
963 static int iwl4965_send_scan_abort(struct iwl_priv *priv)
966 struct iwl4965_rx_packet *res;
967 struct iwl_host_cmd cmd = {
968 .id = REPLY_SCAN_ABORT_CMD,
969 .meta.flags = CMD_WANT_SKB,
972 /* If there isn't a scan actively going on in the hardware
973 * then we are in between scan bands and not actually
974 * actively scanning, so don't send the abort command */
975 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
976 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
980 rc = iwl_send_cmd_sync(priv, &cmd);
982 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
986 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
987 if (res->u.status != CAN_ABORT_STATUS) {
988 /* The scan abort will return 1 for success or
989 * 2 for "failure". A failure condition can be
990 * due to simply not being in an active scan which
991 * can occur if we send the scan abort before we
992 * the microcode has notified us that a scan is
994 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
995 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
996 clear_bit(STATUS_SCAN_HW, &priv->status);
999 dev_kfree_skb_any(cmd.meta.u.skb);
1004 static int iwl4965_card_state_sync_callback(struct iwl_priv *priv,
1005 struct iwl_cmd *cmd,
1006 struct sk_buff *skb)
1014 * Use: Sets the device's internal card state to enable, disable, or halt
1016 * When in the 'enable' state the card operates as normal.
1017 * When in the 'disable' state, the card enters into a low power mode.
1018 * When in the 'halt' state, the card is shut down and must be fully
1019 * restarted to come back on.
1021 static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
1023 struct iwl_host_cmd cmd = {
1024 .id = REPLY_CARD_STATE_CMD,
1027 .meta.flags = meta_flag,
1030 if (meta_flag & CMD_ASYNC)
1031 cmd.meta.u.callback = iwl4965_card_state_sync_callback;
1033 return iwl_send_cmd(priv, &cmd);
1036 static int iwl4965_add_sta_sync_callback(struct iwl_priv *priv,
1037 struct iwl_cmd *cmd, struct sk_buff *skb)
1039 struct iwl4965_rx_packet *res = NULL;
1042 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1046 res = (struct iwl4965_rx_packet *)skb->data;
1047 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1048 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1053 switch (res->u.add_sta.status) {
1054 case ADD_STA_SUCCESS_MSK:
1060 /* We didn't cache the SKB; let the caller free it */
1064 int iwl4965_send_add_station(struct iwl_priv *priv,
1065 struct iwl4965_addsta_cmd *sta, u8 flags)
1067 struct iwl4965_rx_packet *res = NULL;
1069 struct iwl_host_cmd cmd = {
1070 .id = REPLY_ADD_STA,
1071 .len = sizeof(struct iwl4965_addsta_cmd),
1072 .meta.flags = flags,
1076 if (flags & CMD_ASYNC)
1077 cmd.meta.u.callback = iwl4965_add_sta_sync_callback;
1079 cmd.meta.flags |= CMD_WANT_SKB;
1081 rc = iwl_send_cmd(priv, &cmd);
1083 if (rc || (flags & CMD_ASYNC))
1086 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
1087 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1088 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1094 switch (res->u.add_sta.status) {
1095 case ADD_STA_SUCCESS_MSK:
1096 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1100 IWL_WARNING("REPLY_ADD_STA failed\n");
1105 priv->alloc_rxb_skb--;
1106 dev_kfree_skb_any(cmd.meta.u.skb);
1111 static int iwl4965_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
1112 struct ieee80211_key_conf *keyconf,
1115 unsigned long flags;
1116 __le16 key_flags = 0;
1118 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
1119 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1121 if (sta_id == priv->hw_setting.bcast_sta_id)
1122 key_flags |= STA_KEY_MULTICAST_MSK;
1124 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1125 keyconf->hw_key_idx = keyconf->keyidx;
1127 key_flags &= ~STA_KEY_FLG_INVALID;
1129 spin_lock_irqsave(&priv->sta_lock, flags);
1130 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1131 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
1133 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
1136 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
1139 priv->stations[sta_id].sta.key.key_offset
1140 = (sta_id % STA_KEY_MAX_NUM);/*FIXME*/
1141 priv->stations[sta_id].sta.key.key_flags = key_flags;
1142 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1143 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1145 spin_unlock_irqrestore(&priv->sta_lock, flags);
1147 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1148 return iwl4965_send_add_station(priv,
1149 &priv->stations[sta_id].sta, CMD_ASYNC);
1152 static int iwl4965_set_tkip_dynamic_key_info(struct iwl_priv *priv,
1153 struct ieee80211_key_conf *keyconf,
1156 unsigned long flags;
1159 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1160 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1161 keyconf->hw_key_idx = keyconf->keyidx;
1163 spin_lock_irqsave(&priv->sta_lock, flags);
1165 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1166 priv->stations[sta_id].keyinfo.conf = keyconf;
1167 priv->stations[sta_id].keyinfo.keylen = 16;
1169 /* This copy is acutally not needed: we get the key with each TX */
1170 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
1172 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
1174 spin_unlock_irqrestore(&priv->sta_lock, flags);
1179 static int iwl4965_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
1181 unsigned long flags;
1183 spin_lock_irqsave(&priv->sta_lock, flags);
1184 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key));
1185 memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo));
1186 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
1187 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1188 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1189 spin_unlock_irqrestore(&priv->sta_lock, flags);
1191 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1192 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
1196 static int iwl4965_set_dynamic_key(struct iwl_priv *priv,
1197 struct ieee80211_key_conf *key, u8 sta_id)
1203 ret = iwl4965_set_ccmp_dynamic_key_info(priv, key, sta_id);
1206 ret = iwl4965_set_tkip_dynamic_key_info(priv, key, sta_id);
1212 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, key->alg);
1219 static int iwl4965_remove_static_key(struct iwl_priv *priv)
1221 int ret = -EOPNOTSUPP;
1226 static int iwl4965_set_static_key(struct iwl_priv *priv,
1227 struct ieee80211_key_conf *key)
1229 if (key->alg == ALG_WEP)
1232 IWL_ERROR("Static key invalid: alg %d\n", key->alg);
1236 static void iwl4965_clear_free_frames(struct iwl_priv *priv)
1238 struct list_head *element;
1240 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1241 priv->frames_count);
1243 while (!list_empty(&priv->free_frames)) {
1244 element = priv->free_frames.next;
1246 kfree(list_entry(element, struct iwl4965_frame, list));
1247 priv->frames_count--;
1250 if (priv->frames_count) {
1251 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1252 priv->frames_count);
1253 priv->frames_count = 0;
1257 static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl_priv *priv)
1259 struct iwl4965_frame *frame;
1260 struct list_head *element;
1261 if (list_empty(&priv->free_frames)) {
1262 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1264 IWL_ERROR("Could not allocate frame!\n");
1268 priv->frames_count++;
1272 element = priv->free_frames.next;
1274 return list_entry(element, struct iwl4965_frame, list);
1277 static void iwl4965_free_frame(struct iwl_priv *priv, struct iwl4965_frame *frame)
1279 memset(frame, 0, sizeof(*frame));
1280 list_add(&frame->list, &priv->free_frames);
1283 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
1284 struct ieee80211_hdr *hdr,
1285 const u8 *dest, int left)
1288 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
1289 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
1290 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
1293 if (priv->ibss_beacon->len > left)
1296 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1298 return priv->ibss_beacon->len;
1301 static u8 iwl4965_rate_get_lowest_plcp(int rate_mask)
1305 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
1306 i = iwl4965_rates[i].next_ieee) {
1307 if (rate_mask & (1 << i))
1308 return iwl4965_rates[i].plcp;
1311 return IWL_RATE_INVALID;
1314 static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
1316 struct iwl4965_frame *frame;
1317 unsigned int frame_size;
1321 frame = iwl4965_get_free_frame(priv);
1324 IWL_ERROR("Could not obtain free frame buffer for beacon "
1329 if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
1330 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic &
1332 if (rate == IWL_INVALID_RATE)
1333 rate = IWL_RATE_6M_PLCP;
1335 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
1336 if (rate == IWL_INVALID_RATE)
1337 rate = IWL_RATE_1M_PLCP;
1340 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
1342 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
1345 iwl4965_free_frame(priv, frame);
1350 /******************************************************************************
1352 * Misc. internal state and helper functions
1354 ******************************************************************************/
1356 static void iwl4965_unset_hw_setting(struct iwl_priv *priv)
1358 if (priv->hw_setting.shared_virt)
1359 pci_free_consistent(priv->pci_dev,
1360 sizeof(struct iwl4965_shared),
1361 priv->hw_setting.shared_virt,
1362 priv->hw_setting.shared_phys);
1366 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1368 * return : set the bit for each supported rate insert in ie
1370 static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
1371 u16 basic_rate, int *left)
1373 u16 ret_rates = 0, bit;
1378 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1379 if (bit & supported_rate) {
1381 rates[*cnt] = iwl4965_rates[i].ieee |
1382 ((bit & basic_rate) ? 0x80 : 0x00);
1386 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
1395 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1397 static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
1398 enum ieee80211_band band,
1399 struct ieee80211_mgmt *frame,
1400 int left, int is_direct)
1404 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
1405 #ifdef CONFIG_IWL4965_HT
1406 const struct ieee80211_supported_band *sband =
1407 iwl4965_get_hw_mode(priv, band);
1408 #endif /* CONFIG_IWL4965_HT */
1410 /* Make sure there is enough space for the probe request,
1411 * two mandatory IEs and the data */
1417 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1418 memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN);
1419 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
1420 memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN);
1421 frame->seq_ctrl = 0;
1423 /* fill in our indirect SSID IE */
1430 pos = &(frame->u.probe_req.variable[0]);
1431 *pos++ = WLAN_EID_SSID;
1434 /* fill in our direct SSID IE... */
1437 left -= 2 + priv->essid_len;
1440 /* ... fill it in... */
1441 *pos++ = WLAN_EID_SSID;
1442 *pos++ = priv->essid_len;
1443 memcpy(pos, priv->essid, priv->essid_len);
1444 pos += priv->essid_len;
1445 len += 2 + priv->essid_len;
1448 /* fill in supported rate */
1454 /* ... fill it in... */
1455 *pos++ = WLAN_EID_SUPP_RATES;
1458 /* exclude 60M rate */
1459 active_rates = priv->rates_mask;
1460 active_rates &= ~IWL_RATE_60M_MASK;
1462 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
1464 cck_rates = IWL_CCK_RATES_MASK & active_rates;
1465 ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
1466 active_rate_basic, &left);
1467 active_rates &= ~ret_rates;
1469 ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
1470 active_rate_basic, &left);
1471 active_rates &= ~ret_rates;
1475 if (active_rates == 0)
1478 /* fill in supported extended rate */
1483 /* ... fill it in... */
1484 *pos++ = WLAN_EID_EXT_SUPP_RATES;
1486 iwl4965_supported_rate_to_ie(pos, active_rates,
1487 active_rate_basic, &left);
1491 #ifdef CONFIG_IWL4965_HT
1492 if (sband && sband->ht_info.ht_supported) {
1493 struct ieee80211_ht_cap *ht_cap;
1495 *pos++ = WLAN_EID_HT_CAPABILITY;
1496 *pos++ = sizeof(struct ieee80211_ht_cap);
1497 ht_cap = (struct ieee80211_ht_cap *)pos;
1498 ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
1499 memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
1500 ht_cap->ampdu_params_info =(sband->ht_info.ampdu_factor &
1501 IEEE80211_HT_CAP_AMPDU_FACTOR) |
1502 ((sband->ht_info.ampdu_density << 2) &
1503 IEEE80211_HT_CAP_AMPDU_DENSITY);
1504 len += 2 + sizeof(struct ieee80211_ht_cap);
1506 #endif /*CONFIG_IWL4965_HT */
1515 static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
1516 struct iwl4965_qosparam_cmd *qos)
1519 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
1520 sizeof(struct iwl4965_qosparam_cmd), qos);
1523 static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
1525 unsigned long flags;
1527 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1530 if (!priv->qos_data.qos_enable)
1533 spin_lock_irqsave(&priv->lock, flags);
1534 priv->qos_data.def_qos_parm.qos_flags = 0;
1536 if (priv->qos_data.qos_cap.q_AP.queue_request &&
1537 !priv->qos_data.qos_cap.q_AP.txop_request)
1538 priv->qos_data.def_qos_parm.qos_flags |=
1539 QOS_PARAM_FLG_TXOP_TYPE_MSK;
1540 if (priv->qos_data.qos_active)
1541 priv->qos_data.def_qos_parm.qos_flags |=
1542 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
1544 #ifdef CONFIG_IWL4965_HT
1545 if (priv->current_ht_config.is_ht)
1546 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
1547 #endif /* CONFIG_IWL4965_HT */
1549 spin_unlock_irqrestore(&priv->lock, flags);
1551 if (force || iwl_is_associated(priv)) {
1552 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
1553 priv->qos_data.qos_active,
1554 priv->qos_data.def_qos_parm.qos_flags);
1556 iwl4965_send_qos_params_command(priv,
1557 &(priv->qos_data.def_qos_parm));
1562 * Power management (not Tx power!) functions
1564 #define MSEC_TO_USEC 1024
1566 #define NOSLP __constant_cpu_to_le16(0), 0, 0
1567 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1568 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1569 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1570 __constant_cpu_to_le32(X1), \
1571 __constant_cpu_to_le32(X2), \
1572 __constant_cpu_to_le32(X3), \
1573 __constant_cpu_to_le32(X4)}
1576 /* default power management (not Tx power) table values */
1578 static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = {
1579 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1580 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1581 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1582 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1583 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1584 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1588 static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = {
1589 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1590 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1591 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1592 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1593 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1594 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1595 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1596 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1597 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1598 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1601 int iwl4965_power_init_handle(struct iwl_priv *priv)
1604 struct iwl4965_power_mgr *pow_data;
1605 int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC;
1608 IWL_DEBUG_POWER("Initialize power \n");
1610 pow_data = &(priv->power_data);
1612 memset(pow_data, 0, sizeof(*pow_data));
1614 pow_data->active_index = IWL_POWER_RANGE_0;
1615 pow_data->dtim_val = 0xffff;
1617 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
1618 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
1620 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
1624 struct iwl4965_powertable_cmd *cmd;
1626 IWL_DEBUG_POWER("adjust power command flags\n");
1628 for (i = 0; i < IWL_POWER_AC; i++) {
1629 cmd = &pow_data->pwr_range_0[i].cmd;
1632 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
1634 cmd->flags |= IWL_POWER_PCI_PM_MSK;
1640 static int iwl4965_update_power_cmd(struct iwl_priv *priv,
1641 struct iwl4965_powertable_cmd *cmd, u32 mode)
1646 struct iwl4965_power_vec_entry *range;
1648 struct iwl4965_power_mgr *pow_data;
1650 if (mode > IWL_POWER_INDEX_5) {
1651 IWL_DEBUG_POWER("Error invalid power mode \n");
1654 pow_data = &(priv->power_data);
1656 if (pow_data->active_index == IWL_POWER_RANGE_0)
1657 range = &pow_data->pwr_range_0[0];
1659 range = &pow_data->pwr_range_1[1];
1661 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd));
1663 #ifdef IWL_MAC80211_DISABLE
1664 if (priv->assoc_network != NULL) {
1665 unsigned long flags;
1667 period = priv->assoc_network->tim.tim_period;
1669 #endif /*IWL_MAC80211_DISABLE */
1670 skip = range[mode].no_dtim;
1679 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
1681 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
1682 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
1683 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
1686 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
1687 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
1688 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
1691 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
1692 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
1693 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
1694 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1695 le32_to_cpu(cmd->sleep_interval[0]),
1696 le32_to_cpu(cmd->sleep_interval[1]),
1697 le32_to_cpu(cmd->sleep_interval[2]),
1698 le32_to_cpu(cmd->sleep_interval[3]),
1699 le32_to_cpu(cmd->sleep_interval[4]));
1704 static int iwl4965_send_power_mode(struct iwl_priv *priv, u32 mode)
1706 u32 uninitialized_var(final_mode);
1708 struct iwl4965_powertable_cmd cmd;
1710 /* If on battery, set to 3,
1711 * if plugged into AC power, set to CAM ("continuously aware mode"),
1712 * else user level */
1714 case IWL_POWER_BATTERY:
1715 final_mode = IWL_POWER_INDEX_3;
1718 final_mode = IWL_POWER_MODE_CAM;
1725 cmd.keep_alive_beacons = 0;
1727 iwl4965_update_power_cmd(priv, &cmd, final_mode);
1729 rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
1731 if (final_mode == IWL_POWER_MODE_CAM)
1732 clear_bit(STATUS_POWER_PMI, &priv->status);
1734 set_bit(STATUS_POWER_PMI, &priv->status);
1739 int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
1741 /* Filter incoming packets to determine if they are targeted toward
1742 * this network, discarding packets coming from ourselves */
1743 switch (priv->iw_mode) {
1744 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
1745 /* packets from our adapter are dropped (echo) */
1746 if (!compare_ether_addr(header->addr2, priv->mac_addr))
1748 /* {broad,multi}cast packets to our IBSS go through */
1749 if (is_multicast_ether_addr(header->addr1))
1750 return !compare_ether_addr(header->addr3, priv->bssid);
1751 /* packets to our adapter go through */
1752 return !compare_ether_addr(header->addr1, priv->mac_addr);
1753 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
1754 /* packets from our adapter are dropped (echo) */
1755 if (!compare_ether_addr(header->addr3, priv->mac_addr))
1757 /* {broad,multi}cast packets to our BSS go through */
1758 if (is_multicast_ether_addr(header->addr1))
1759 return !compare_ether_addr(header->addr2, priv->bssid);
1760 /* packets to our adapter go through */
1761 return !compare_ether_addr(header->addr1, priv->mac_addr);
1769 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1771 static const char *iwl4965_get_tx_fail_reason(u32 status)
1773 switch (status & TX_STATUS_MSK) {
1774 case TX_STATUS_SUCCESS:
1776 TX_STATUS_ENTRY(SHORT_LIMIT);
1777 TX_STATUS_ENTRY(LONG_LIMIT);
1778 TX_STATUS_ENTRY(FIFO_UNDERRUN);
1779 TX_STATUS_ENTRY(MGMNT_ABORT);
1780 TX_STATUS_ENTRY(NEXT_FRAG);
1781 TX_STATUS_ENTRY(LIFE_EXPIRE);
1782 TX_STATUS_ENTRY(DEST_PS);
1783 TX_STATUS_ENTRY(ABORTED);
1784 TX_STATUS_ENTRY(BT_RETRY);
1785 TX_STATUS_ENTRY(STA_INVALID);
1786 TX_STATUS_ENTRY(FRAG_DROPPED);
1787 TX_STATUS_ENTRY(TID_DISABLE);
1788 TX_STATUS_ENTRY(FRAME_FLUSHED);
1789 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
1790 TX_STATUS_ENTRY(TX_LOCKED);
1791 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
1798 * iwl4965_scan_cancel - Cancel any currently executing HW scan
1800 * NOTE: priv->mutex is not required before calling this function
1802 static int iwl4965_scan_cancel(struct iwl_priv *priv)
1804 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1805 clear_bit(STATUS_SCANNING, &priv->status);
1809 if (test_bit(STATUS_SCANNING, &priv->status)) {
1810 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1811 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1812 set_bit(STATUS_SCAN_ABORTING, &priv->status);
1813 queue_work(priv->workqueue, &priv->abort_scan);
1816 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1818 return test_bit(STATUS_SCANNING, &priv->status);
1825 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
1826 * @ms: amount of time to wait (in milliseconds) for scan to abort
1828 * NOTE: priv->mutex must be held before calling this function
1830 static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
1832 unsigned long now = jiffies;
1835 ret = iwl4965_scan_cancel(priv);
1837 mutex_unlock(&priv->mutex);
1838 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
1839 test_bit(STATUS_SCANNING, &priv->status))
1841 mutex_lock(&priv->mutex);
1843 return test_bit(STATUS_SCANNING, &priv->status);
1849 static void iwl4965_sequence_reset(struct iwl_priv *priv)
1851 /* Reset ieee stats */
1853 /* We don't reset the net_device_stats (ieee->stats) on
1856 priv->last_seq_num = -1;
1857 priv->last_frag_num = -1;
1858 priv->last_packet_time = 0;
1860 iwl4965_scan_cancel(priv);
1863 #define MAX_UCODE_BEACON_INTERVAL 4096
1864 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1866 static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
1869 u16 beacon_factor = 0;
1872 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
1873 / MAX_UCODE_BEACON_INTERVAL;
1874 new_val = beacon_val / beacon_factor;
1876 return cpu_to_le16(new_val);
1879 static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
1881 u64 interval_tm_unit;
1883 unsigned long flags;
1884 struct ieee80211_conf *conf = NULL;
1887 conf = ieee80211_get_hw_conf(priv->hw);
1889 spin_lock_irqsave(&priv->lock, flags);
1890 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
1891 priv->rxon_timing.timestamp.dw[0] =
1892 cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
1894 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
1896 tsf = priv->timestamp;
1898 beacon_int = priv->beacon_int;
1899 spin_unlock_irqrestore(&priv->lock, flags);
1901 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
1902 if (beacon_int == 0) {
1903 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
1904 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
1906 priv->rxon_timing.beacon_interval =
1907 cpu_to_le16(beacon_int);
1908 priv->rxon_timing.beacon_interval =
1909 iwl4965_adjust_beacon_interval(
1910 le16_to_cpu(priv->rxon_timing.beacon_interval));
1913 priv->rxon_timing.atim_window = 0;
1915 priv->rxon_timing.beacon_interval =
1916 iwl4965_adjust_beacon_interval(conf->beacon_int);
1917 /* TODO: we need to get atim_window from upper stack
1918 * for now we set to 0 */
1919 priv->rxon_timing.atim_window = 0;
1923 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
1924 result = do_div(tsf, interval_tm_unit);
1925 priv->rxon_timing.beacon_init_val =
1926 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
1929 ("beacon interval %d beacon timer %d beacon tim %d\n",
1930 le16_to_cpu(priv->rxon_timing.beacon_interval),
1931 le32_to_cpu(priv->rxon_timing.beacon_init_val),
1932 le16_to_cpu(priv->rxon_timing.atim_window));
1935 static int iwl4965_scan_initiate(struct iwl_priv *priv)
1937 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
1938 IWL_ERROR("APs don't scan.\n");
1942 if (!iwl_is_ready_rf(priv)) {
1943 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1947 if (test_bit(STATUS_SCANNING, &priv->status)) {
1948 IWL_DEBUG_SCAN("Scan already in progress.\n");
1952 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1953 IWL_DEBUG_SCAN("Scan request while abort pending. "
1958 IWL_DEBUG_INFO("Starting scan...\n");
1959 priv->scan_bands = 2;
1960 set_bit(STATUS_SCANNING, &priv->status);
1961 priv->scan_start = jiffies;
1962 priv->scan_pass_start = priv->scan_start;
1964 queue_work(priv->workqueue, &priv->request_scan);
1970 static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
1971 enum ieee80211_band band)
1973 if (band == IEEE80211_BAND_5GHZ) {
1974 priv->staging_rxon.flags &=
1975 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
1976 | RXON_FLG_CCK_MSK);
1977 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1979 /* Copied from iwl4965_bg_post_associate() */
1980 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
1981 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1983 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1985 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
1986 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1988 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1989 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
1990 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
1995 * initialize rxon structure with default values from eeprom
1997 static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
1999 const struct iwl_channel_info *ch_info;
2001 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2003 switch (priv->iw_mode) {
2004 case IEEE80211_IF_TYPE_AP:
2005 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2008 case IEEE80211_IF_TYPE_STA:
2009 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
2010 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
2013 case IEEE80211_IF_TYPE_IBSS:
2014 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
2015 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
2016 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
2017 RXON_FILTER_ACCEPT_GRP_MSK;
2020 case IEEE80211_IF_TYPE_MNTR:
2021 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
2022 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
2023 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
2026 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
2031 /* TODO: Figure out when short_preamble would be set and cache from
2033 if (!hw_to_local(priv->hw)->short_preamble)
2034 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2036 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2039 ch_info = iwl_get_channel_info(priv, priv->band,
2040 le16_to_cpu(priv->staging_rxon.channel));
2043 ch_info = &priv->channel_info[0];
2046 * in some case A channels are all non IBSS
2047 * in this case force B/G channel
2049 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2050 !(is_channel_ibss(ch_info)))
2051 ch_info = &priv->channel_info[0];
2053 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
2054 priv->band = ch_info->band;
2056 iwl4965_set_flags_for_phymode(priv, priv->band);
2058 priv->staging_rxon.ofdm_basic_rates =
2059 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2060 priv->staging_rxon.cck_basic_rates =
2061 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2063 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
2064 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
2065 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2066 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
2067 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
2068 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
2069 iwl4965_set_rxon_chain(priv);
2072 static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
2074 if (mode == IEEE80211_IF_TYPE_IBSS) {
2075 const struct iwl_channel_info *ch_info;
2077 ch_info = iwl_get_channel_info(priv,
2079 le16_to_cpu(priv->staging_rxon.channel));
2081 if (!ch_info || !is_channel_ibss(ch_info)) {
2082 IWL_ERROR("channel %d not IBSS channel\n",
2083 le16_to_cpu(priv->staging_rxon.channel));
2088 priv->iw_mode = mode;
2090 iwl4965_connection_init_rx_config(priv);
2091 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2093 iwlcore_clear_stations_table(priv);
2095 /* dont commit rxon if rf-kill is on*/
2096 if (!iwl_is_ready_rf(priv))
2099 cancel_delayed_work(&priv->scan_check);
2100 if (iwl4965_scan_cancel_timeout(priv, 100)) {
2101 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2102 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2106 iwl4965_commit_rxon(priv);
2111 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
2112 struct ieee80211_tx_control *ctl,
2113 struct iwl_cmd *cmd,
2114 struct sk_buff *skb_frag,
2117 struct iwl4965_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
2119 switch (keyinfo->alg) {
2121 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
2122 memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
2123 if (ctl->flags & IEEE80211_TXCTL_AMPDU)
2124 cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
2125 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2129 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
2130 ieee80211_get_tkip_key(keyinfo->conf, skb_frag,
2131 IEEE80211_TKIP_P2_KEY, cmd->cmd.tx.key);
2132 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
2136 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2137 (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2139 if (keyinfo->keylen == 13)
2140 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
2142 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2144 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2145 "with key %d\n", ctl->key_idx);
2149 printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
2155 * handle build REPLY_TX command notification.
2157 static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv,
2158 struct iwl_cmd *cmd,
2159 struct ieee80211_tx_control *ctrl,
2160 struct ieee80211_hdr *hdr,
2161 int is_unicast, u8 std_id)
2164 u16 fc = le16_to_cpu(hdr->frame_control);
2165 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2167 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2168 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
2169 tx_flags |= TX_CMD_FLG_ACK_MSK;
2170 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2171 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2172 if (ieee80211_is_probe_response(fc) &&
2173 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2174 tx_flags |= TX_CMD_FLG_TSF_MSK;
2176 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2177 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2180 if (ieee80211_is_back_request(fc))
2181 tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
2184 cmd->cmd.tx.sta_id = std_id;
2185 if (ieee80211_get_morefrag(hdr))
2186 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2188 qc = ieee80211_get_qos_ctrl(hdr);
2190 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
2191 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2193 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2195 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
2196 tx_flags |= TX_CMD_FLG_RTS_MSK;
2197 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2198 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
2199 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2200 tx_flags |= TX_CMD_FLG_CTS_MSK;
2203 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2204 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2206 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2207 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2208 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
2209 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
2210 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
2212 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
2214 cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2217 cmd->cmd.tx.driver_txop = 0;
2218 cmd->cmd.tx.tx_flags = tx_flags;
2219 cmd->cmd.tx.next_frame_len = 0;
2221 static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len)
2223 /* 0 - mgmt, 1 - cnt, 2 - data */
2224 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
2225 priv->tx_stats[idx].cnt++;
2226 priv->tx_stats[idx].bytes += len;
2229 * iwl4965_get_sta_id - Find station's index within station table
2231 * If new IBSS station, create new entry in station table
2233 static int iwl4965_get_sta_id(struct iwl_priv *priv,
2234 struct ieee80211_hdr *hdr)
2237 u16 fc = le16_to_cpu(hdr->frame_control);
2238 DECLARE_MAC_BUF(mac);
2240 /* If this frame is broadcast or management, use broadcast station id */
2241 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2242 is_multicast_ether_addr(hdr->addr1))
2243 return priv->hw_setting.bcast_sta_id;
2245 switch (priv->iw_mode) {
2247 /* If we are a client station in a BSS network, use the special
2248 * AP station entry (that's the only station we communicate with) */
2249 case IEEE80211_IF_TYPE_STA:
2252 /* If we are an AP, then find the station, or use BCAST */
2253 case IEEE80211_IF_TYPE_AP:
2254 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
2255 if (sta_id != IWL_INVALID_STATION)
2257 return priv->hw_setting.bcast_sta_id;
2259 /* If this frame is going out to an IBSS network, find the station,
2260 * or create a new station table entry */
2261 case IEEE80211_IF_TYPE_IBSS:
2262 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
2263 if (sta_id != IWL_INVALID_STATION)
2266 /* Create new station table entry */
2267 sta_id = iwl4965_add_station_flags(priv, hdr->addr1,
2268 0, CMD_ASYNC, NULL);
2270 if (sta_id != IWL_INVALID_STATION)
2273 IWL_DEBUG_DROP("Station %s not in station map. "
2274 "Defaulting to broadcast...\n",
2275 print_mac(mac, hdr->addr1));
2276 iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
2277 return priv->hw_setting.bcast_sta_id;
2280 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
2281 return priv->hw_setting.bcast_sta_id;
2286 * start REPLY_TX command process
2288 static int iwl4965_tx_skb(struct iwl_priv *priv,
2289 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2291 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2292 struct iwl4965_tfd_frame *tfd;
2294 int txq_id = ctl->queue;
2295 struct iwl4965_tx_queue *txq = NULL;
2296 struct iwl4965_queue *q = NULL;
2297 dma_addr_t phys_addr;
2298 dma_addr_t txcmd_phys;
2299 dma_addr_t scratch_phys;
2300 struct iwl_cmd *out_cmd = NULL;
2301 u16 len, idx, len_org;
2302 u8 id, hdr_len, unicast;
2307 u8 wait_write_ptr = 0;
2308 unsigned long flags;
2311 spin_lock_irqsave(&priv->lock, flags);
2312 if (iwl_is_rfkill(priv)) {
2313 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2318 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2322 if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) {
2323 IWL_ERROR("ERROR: No TX rate available.\n");
2327 unicast = !is_multicast_ether_addr(hdr->addr1);
2330 fc = le16_to_cpu(hdr->frame_control);
2332 #ifdef CONFIG_IWLWIFI_DEBUG
2333 if (ieee80211_is_auth(fc))
2334 IWL_DEBUG_TX("Sending AUTH frame\n");
2335 else if (ieee80211_is_assoc_request(fc))
2336 IWL_DEBUG_TX("Sending ASSOC frame\n");
2337 else if (ieee80211_is_reassoc_request(fc))
2338 IWL_DEBUG_TX("Sending REASSOC frame\n");
2341 /* drop all data frame if we are not associated */
2342 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
2343 (!iwl_is_associated(priv) ||
2344 ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) ||
2345 !priv->assoc_station_added)) {
2346 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
2350 spin_unlock_irqrestore(&priv->lock, flags);
2352 hdr_len = ieee80211_get_hdrlen(fc);
2354 /* Find (or create) index into station table for destination station */
2355 sta_id = iwl4965_get_sta_id(priv, hdr);
2356 if (sta_id == IWL_INVALID_STATION) {
2357 DECLARE_MAC_BUF(mac);
2359 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2360 print_mac(mac, hdr->addr1));
2364 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2366 qc = ieee80211_get_qos_ctrl(hdr);
2368 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2369 seq_number = priv->stations[sta_id].tid[tid].seq_number &
2371 hdr->seq_ctrl = cpu_to_le16(seq_number) |
2373 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
2375 #ifdef CONFIG_IWL4965_HT
2376 /* aggregation is on for this <sta,tid> */
2377 if (ctl->flags & IEEE80211_TXCTL_AMPDU)
2378 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
2379 priv->stations[sta_id].tid[tid].tfds_in_queue++;
2380 #endif /* CONFIG_IWL4965_HT */
2383 /* Descriptor for chosen Tx queue */
2384 txq = &priv->txq[txq_id];
2387 spin_lock_irqsave(&priv->lock, flags);
2389 /* Set up first empty TFD within this queue's circular TFD buffer */
2390 tfd = &txq->bd[q->write_ptr];
2391 memset(tfd, 0, sizeof(*tfd));
2392 control_flags = (u32 *) tfd;
2393 idx = get_cmd_index(q, q->write_ptr, 0);
2395 /* Set up driver data for this TFD */
2396 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info));
2397 txq->txb[q->write_ptr].skb[0] = skb;
2398 memcpy(&(txq->txb[q->write_ptr].status.control),
2399 ctl, sizeof(struct ieee80211_tx_control));
2401 /* Set up first empty entry in queue's array of Tx/cmd buffers */
2402 out_cmd = &txq->cmd[idx];
2403 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
2404 memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
2407 * Set up the Tx-command (not MAC!) header.
2408 * Store the chosen Tx queue and TFD index within the sequence field;
2409 * after Tx, uCode's Tx response will return this value so driver can
2410 * locate the frame within the tx queue and do post-tx processing.
2412 out_cmd->hdr.cmd = REPLY_TX;
2413 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
2414 INDEX_TO_SEQ(q->write_ptr)));
2416 /* Copy MAC header from skb into command buffer */
2417 memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
2420 * Use the first empty entry in this queue's command buffer array
2421 * to contain the Tx command and MAC header concatenated together
2422 * (payload data will be in another buffer).
2423 * Size of this varies, due to varying MAC header length.
2424 * If end is not dword aligned, we'll have 2 extra bytes at the end
2425 * of the MAC header (device reads on dword boundaries).
2426 * We'll tell device about this padding later.
2428 len = priv->hw_setting.tx_cmd_len +
2429 sizeof(struct iwl_cmd_header) + hdr_len;
2432 len = (len + 3) & ~3;
2439 /* Physical address of this Tx command's header (not MAC header!),
2440 * within command buffer array. */
2441 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx +
2442 offsetof(struct iwl_cmd, hdr);
2444 /* Add buffer containing Tx command and MAC(!) header to TFD's
2446 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
2448 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
2449 iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, sta_id);
2451 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2452 * if any (802.11 null frames have no payload). */
2453 len = skb->len - hdr_len;
2455 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
2456 len, PCI_DMA_TODEVICE);
2457 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
2460 /* Tell 4965 about any 2-byte padding after MAC header */
2462 out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
2464 /* Total # bytes to be transmitted */
2465 len = (u16)skb->len;
2466 out_cmd->cmd.tx.len = cpu_to_le16(len);
2468 /* TODO need this for burst mode later on */
2469 iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
2471 /* set is_hcca to 0; it probably will never be implemented */
2472 iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
2474 iwl_update_tx_stats(priv, fc, len);
2476 scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
2477 offsetof(struct iwl4965_tx_cmd, scratch);
2478 out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys);
2479 out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
2481 if (!ieee80211_get_morefrag(hdr)) {
2482 txq->need_update = 1;
2484 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2485 priv->stations[sta_id].tid[tid].seq_number = seq_number;
2489 txq->need_update = 0;
2492 iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
2493 sizeof(out_cmd->cmd.tx));
2495 iwl_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
2496 ieee80211_get_hdrlen(fc));
2498 /* Set up entry for this TFD in Tx byte-count array */
2499 iwl4965_tx_queue_update_wr_ptr(priv, txq, len);
2501 /* Tell device the write index *just past* this latest filled TFD */
2502 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
2503 rc = iwl4965_tx_queue_update_write_ptr(priv, txq);
2504 spin_unlock_irqrestore(&priv->lock, flags);
2509 if ((iwl4965_queue_space(q) < q->high_mark)
2510 && priv->mac80211_registered) {
2511 if (wait_write_ptr) {
2512 spin_lock_irqsave(&priv->lock, flags);
2513 txq->need_update = 1;
2514 iwl4965_tx_queue_update_write_ptr(priv, txq);
2515 spin_unlock_irqrestore(&priv->lock, flags);
2518 ieee80211_stop_queue(priv->hw, ctl->queue);
2524 spin_unlock_irqrestore(&priv->lock, flags);
2529 static void iwl4965_set_rate(struct iwl_priv *priv)
2531 const struct ieee80211_supported_band *hw = NULL;
2532 struct ieee80211_rate *rate;
2535 hw = iwl4965_get_hw_mode(priv, priv->band);
2537 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2541 priv->active_rate = 0;
2542 priv->active_rate_basic = 0;
2544 for (i = 0; i < hw->n_bitrates; i++) {
2545 rate = &(hw->bitrates[i]);
2546 if (rate->hw_value < IWL_RATE_COUNT)
2547 priv->active_rate |= (1 << rate->hw_value);
2550 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2551 priv->active_rate, priv->active_rate_basic);
2554 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2555 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2558 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
2559 priv->staging_rxon.cck_basic_rates =
2560 ((priv->active_rate_basic &
2561 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
2563 priv->staging_rxon.cck_basic_rates =
2564 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2566 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
2567 priv->staging_rxon.ofdm_basic_rates =
2568 ((priv->active_rate_basic &
2569 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
2570 IWL_FIRST_OFDM_RATE) & 0xFF;
2572 priv->staging_rxon.ofdm_basic_rates =
2573 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2576 void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
2578 unsigned long flags;
2580 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
2583 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2584 disable_radio ? "OFF" : "ON");
2586 if (disable_radio) {
2587 iwl4965_scan_cancel(priv);
2588 /* FIXME: This is a workaround for AP */
2589 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
2590 spin_lock_irqsave(&priv->lock, flags);
2591 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
2592 CSR_UCODE_SW_BIT_RFKILL);
2593 spin_unlock_irqrestore(&priv->lock, flags);
2594 /* call the host command only if no hw rf-kill set */
2595 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
2596 iwl4965_send_card_state(priv,
2597 CARD_STATE_CMD_DISABLE,
2599 set_bit(STATUS_RF_KILL_SW, &priv->status);
2601 /* make sure mac80211 stop sending Tx frame */
2602 if (priv->mac80211_registered)
2603 ieee80211_stop_queues(priv->hw);
2608 spin_lock_irqsave(&priv->lock, flags);
2609 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2611 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2612 spin_unlock_irqrestore(&priv->lock, flags);
2617 spin_lock_irqsave(&priv->lock, flags);
2618 iwl_read32(priv, CSR_UCODE_DRV_GP1);
2619 if (!iwl_grab_nic_access(priv))
2620 iwl_release_nic_access(priv);
2621 spin_unlock_irqrestore(&priv->lock, flags);
2623 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
2624 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2625 "disabled by HW switch\n");
2629 queue_work(priv->workqueue, &priv->restart);
2633 void iwl4965_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
2634 u32 decrypt_res, struct ieee80211_rx_status *stats)
2637 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
2639 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2642 if (!(fc & IEEE80211_FCTL_PROTECTED))
2645 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2646 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2647 case RX_RES_STATUS_SEC_TYPE_TKIP:
2648 /* The uCode has got a bad phase 1 Key, pushes the packet.
2649 * Decryption will be done in SW. */
2650 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2651 RX_RES_STATUS_BAD_KEY_TTAK)
2654 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2655 RX_RES_STATUS_BAD_ICV_MIC)
2656 stats->flag |= RX_FLAG_MMIC_ERROR;
2657 case RX_RES_STATUS_SEC_TYPE_WEP:
2658 case RX_RES_STATUS_SEC_TYPE_CCMP:
2659 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2660 RX_RES_STATUS_DECRYPT_OK) {
2661 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2662 stats->flag |= RX_FLAG_DECRYPTED;
2672 #define IWL_PACKET_RETRY_TIME HZ
2674 int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
2676 u16 sc = le16_to_cpu(header->seq_ctrl);
2677 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2678 u16 frag = sc & IEEE80211_SCTL_FRAG;
2679 u16 *last_seq, *last_frag;
2680 unsigned long *last_time;
2682 switch (priv->iw_mode) {
2683 case IEEE80211_IF_TYPE_IBSS:{
2684 struct list_head *p;
2685 struct iwl4965_ibss_seq *entry = NULL;
2686 u8 *mac = header->addr2;
2687 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
2689 __list_for_each(p, &priv->ibss_mac_hash[index]) {
2690 entry = list_entry(p, struct iwl4965_ibss_seq, list);
2691 if (!compare_ether_addr(entry->mac, mac))
2694 if (p == &priv->ibss_mac_hash[index]) {
2695 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
2697 IWL_ERROR("Cannot malloc new mac entry\n");
2700 memcpy(entry->mac, mac, ETH_ALEN);
2701 entry->seq_num = seq;
2702 entry->frag_num = frag;
2703 entry->packet_time = jiffies;
2704 list_add(&entry->list, &priv->ibss_mac_hash[index]);
2707 last_seq = &entry->seq_num;
2708 last_frag = &entry->frag_num;
2709 last_time = &entry->packet_time;
2712 case IEEE80211_IF_TYPE_STA:
2713 last_seq = &priv->last_seq_num;
2714 last_frag = &priv->last_frag_num;
2715 last_time = &priv->last_packet_time;
2720 if ((*last_seq == seq) &&
2721 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
2722 if (*last_frag == frag)
2724 if (*last_frag + 1 != frag)
2725 /* out-of-order fragment */
2731 *last_time = jiffies;
2738 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2740 #include "iwl-spectrum.h"
2742 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2743 #define BEACON_TIME_MASK_HIGH 0xFF000000
2744 #define TIME_UNIT 1024
2747 * extended beacon time format
2748 * time in usec will be changed into a 32-bit value in 8:24 format
2749 * the high 1 byte is the beacon counts
2750 * the lower 3 bytes is the time in usec within one beacon interval
2753 static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
2757 u32 interval = beacon_interval * 1024;
2759 if (!interval || !usec)
2762 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
2763 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
2765 return (quot << 24) + rem;
2768 /* base is usually what we get from ucode with each received frame,
2769 * the same as HW timer counter counting down
2772 static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
2774 u32 base_low = base & BEACON_TIME_MASK_LOW;
2775 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
2776 u32 interval = beacon_interval * TIME_UNIT;
2777 u32 res = (base & BEACON_TIME_MASK_HIGH) +
2778 (addon & BEACON_TIME_MASK_HIGH);
2780 if (base_low > addon_low)
2781 res += base_low - addon_low;
2782 else if (base_low < addon_low) {
2783 res += interval + base_low - addon_low;
2788 return cpu_to_le32(res);
2791 static int iwl4965_get_measurement(struct iwl_priv *priv,
2792 struct ieee80211_measurement_params *params,
2795 struct iwl4965_spectrum_cmd spectrum;
2796 struct iwl4965_rx_packet *res;
2797 struct iwl_host_cmd cmd = {
2798 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
2799 .data = (void *)&spectrum,
2800 .meta.flags = CMD_WANT_SKB,
2802 u32 add_time = le64_to_cpu(params->start_time);
2804 int spectrum_resp_status;
2805 int duration = le16_to_cpu(params->duration);
2807 if (iwl_is_associated(priv))
2809 iwl4965_usecs_to_beacons(
2810 le64_to_cpu(params->start_time) - priv->last_tsf,
2811 le16_to_cpu(priv->rxon_timing.beacon_interval));
2813 memset(&spectrum, 0, sizeof(spectrum));
2815 spectrum.channel_count = cpu_to_le16(1);
2817 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
2818 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
2819 cmd.len = sizeof(spectrum);
2820 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
2822 if (iwl_is_associated(priv))
2823 spectrum.start_time =
2824 iwl4965_add_beacon_time(priv->last_beacon_time,
2826 le16_to_cpu(priv->rxon_timing.beacon_interval));
2828 spectrum.start_time = 0;
2830 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
2831 spectrum.channels[0].channel = params->channel;
2832 spectrum.channels[0].type = type;
2833 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
2834 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
2835 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
2837 rc = iwl_send_cmd_sync(priv, &cmd);
2841 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
2842 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
2843 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2847 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
2848 switch (spectrum_resp_status) {
2849 case 0: /* Command will be handled */
2850 if (res->u.spectrum.id != 0xff) {
2852 ("Replaced existing measurement: %d\n",
2853 res->u.spectrum.id);
2854 priv->measurement_status &= ~MEASUREMENT_READY;
2856 priv->measurement_status |= MEASUREMENT_ACTIVE;
2860 case 1: /* Command will not be handled */
2865 dev_kfree_skb_any(cmd.meta.u.skb);
2871 static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv,
2872 struct iwl4965_tx_info *tx_sta)
2875 tx_sta->status.ack_signal = 0;
2876 tx_sta->status.excessive_retries = 0;
2877 tx_sta->status.queue_length = 0;
2878 tx_sta->status.queue_number = 0;
2881 ieee80211_tx_status_irqsafe(priv->hw,
2882 tx_sta->skb[0], &(tx_sta->status));
2884 ieee80211_tx_status(priv->hw,
2885 tx_sta->skb[0], &(tx_sta->status));
2887 tx_sta->skb[0] = NULL;
2891 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2893 * When FW advances 'R' index, all entries between old and new 'R' index
2894 * need to be reclaimed. As result, some free space forms. If there is
2895 * enough free space (> low mark), wake the stack that feeds us.
2897 int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
2899 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
2900 struct iwl4965_queue *q = &txq->q;
2903 if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
2904 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
2905 "is out of range [0-%d] %d %d.\n", txq_id,
2906 index, q->n_bd, q->write_ptr, q->read_ptr);
2910 for (index = iwl_queue_inc_wrap(index, q->n_bd);
2911 q->read_ptr != index;
2912 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
2913 if (txq_id != IWL_CMD_QUEUE_NUM) {
2914 iwl4965_txstatus_to_ieee(priv,
2915 &(txq->txb[txq->q.read_ptr]));
2916 iwl4965_hw_txq_free_tfd(priv, txq);
2917 } else if (nfreed > 1) {
2918 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
2919 q->write_ptr, q->read_ptr);
2920 queue_work(priv->workqueue, &priv->restart);
2925 /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
2926 (txq_id != IWL_CMD_QUEUE_NUM) &&
2927 priv->mac80211_registered)
2928 ieee80211_wake_queue(priv->hw, txq_id); */
2934 static int iwl4965_is_tx_success(u32 status)
2936 status &= TX_STATUS_MSK;
2937 return (status == TX_STATUS_SUCCESS)
2938 || (status == TX_STATUS_DIRECT_DONE);
2941 /******************************************************************************
2943 * Generic RX handler implementations
2945 ******************************************************************************/
2946 #ifdef CONFIG_IWL4965_HT
2948 static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv,
2949 struct ieee80211_hdr *hdr)
2951 if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
2954 u8 *da = ieee80211_get_DA(hdr);
2955 return iwl4965_hw_find_station(priv, da);
2959 static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
2960 struct iwl_priv *priv, int txq_id, int idx)
2962 if (priv->txq[txq_id].txb[idx].skb[0])
2963 return (struct ieee80211_hdr *)priv->txq[txq_id].
2964 txb[idx].skb[0]->data;
2968 static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
2970 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
2971 tx_resp->frame_count);
2972 return le32_to_cpu(*scd_ssn) & MAX_SN;
2977 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
2979 static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
2980 struct iwl4965_ht_agg *agg,
2981 struct iwl4965_tx_resp_agg *tx_resp,
2985 struct agg_tx_status *frame_status = &tx_resp->status;
2986 struct ieee80211_tx_status *tx_status = NULL;
2987 struct ieee80211_hdr *hdr = NULL;
2992 if (agg->wait_for_ba)
2993 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
2995 agg->frame_count = tx_resp->frame_count;
2996 agg->start_idx = start_idx;
2997 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3000 /* # frames attempted by Tx command */
3001 if (agg->frame_count == 1) {
3002 /* Only one frame was attempted; no block-ack will arrive */
3003 status = le16_to_cpu(frame_status[0].status);
3004 seq = le16_to_cpu(frame_status[0].sequence);
3005 idx = SEQ_TO_INDEX(seq);
3006 txq_id = SEQ_TO_QUEUE(seq);
3008 /* FIXME: code repetition */
3009 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3010 agg->frame_count, agg->start_idx, idx);
3012 tx_status = &(priv->txq[txq_id].txb[idx].status);
3013 tx_status->retry_count = tx_resp->failure_frame;
3014 tx_status->queue_number = status & 0xff;
3015 tx_status->queue_length = tx_resp->failure_rts;
3016 tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU;
3017 tx_status->flags = iwl4965_is_tx_success(status)?
3018 IEEE80211_TX_STATUS_ACK : 0;
3019 iwl4965_hwrate_to_tx_control(priv,
3020 le32_to_cpu(tx_resp->rate_n_flags),
3021 &tx_status->control);
3022 /* FIXME: code repetition end */
3024 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3025 status & 0xff, tx_resp->failure_frame);
3026 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
3027 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
3029 agg->wait_for_ba = 0;
3031 /* Two or more frames were attempted; expect block-ack */
3033 int start = agg->start_idx;
3035 /* Construct bit-map of pending frames within Tx window */
3036 for (i = 0; i < agg->frame_count; i++) {
3038 status = le16_to_cpu(frame_status[i].status);
3039 seq = le16_to_cpu(frame_status[i].sequence);
3040 idx = SEQ_TO_INDEX(seq);
3041 txq_id = SEQ_TO_QUEUE(seq);
3043 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3044 AGG_TX_STATE_ABORT_MSK))
3047 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3048 agg->frame_count, txq_id, idx);
3050 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
3052 sc = le16_to_cpu(hdr->seq_ctrl);
3053 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3054 IWL_ERROR("BUG_ON idx doesn't match seq control"
3055 " idx=%d, seq_idx=%d, seq=%d\n",
3061 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3062 i, idx, SEQ_TO_SN(sc));
3066 sh = (start - idx) + 0xff;
3067 bitmap = bitmap << sh;
3070 } else if (sh < -64)
3071 sh = 0xff - (start - idx);
3075 bitmap = bitmap << sh;
3078 bitmap |= (1 << sh);
3079 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3080 start, (u32)(bitmap & 0xFFFFFFFF));
3083 agg->bitmap = bitmap;
3084 agg->start_idx = start;
3085 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3086 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
3087 agg->frame_count, agg->start_idx,
3088 (unsigned long long)agg->bitmap);
3091 agg->wait_for_ba = 1;
3098 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3100 static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
3101 struct iwl4965_rx_mem_buffer *rxb)
3103 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3104 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3105 int txq_id = SEQ_TO_QUEUE(sequence);
3106 int index = SEQ_TO_INDEX(sequence);
3107 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
3108 struct ieee80211_tx_status *tx_status;
3109 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3110 u32 status = le32_to_cpu(tx_resp->status);
3111 #ifdef CONFIG_IWL4965_HT
3112 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
3113 struct ieee80211_hdr *hdr;
3117 if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
3118 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3119 "is out of range [0-%d] %d %d\n", txq_id,
3120 index, txq->q.n_bd, txq->q.write_ptr,
3125 #ifdef CONFIG_IWL4965_HT
3126 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index);
3127 qc = ieee80211_get_qos_ctrl(hdr);
3130 tid = le16_to_cpu(*qc) & 0xf;
3132 sta_id = iwl4965_get_ra_sta_id(priv, hdr);
3133 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
3134 IWL_ERROR("Station not known\n");
3138 if (txq->sched_retry) {
3139 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
3140 struct iwl4965_ht_agg *agg = NULL;
3145 agg = &priv->stations[sta_id].tid[tid].agg;
3147 iwl4965_tx_status_reply_tx(priv, agg,
3148 (struct iwl4965_tx_resp_agg *)tx_resp, index);
3150 if ((tx_resp->frame_count == 1) &&
3151 !iwl4965_is_tx_success(status)) {
3152 /* TODO: send BAR */
3155 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
3157 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
3158 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3159 "%d index %d\n", scd_ssn , index);
3160 freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
3161 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3163 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
3164 txq_id >= 0 && priv->mac80211_registered &&
3165 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
3166 ieee80211_wake_queue(priv->hw, txq_id);
3168 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
3171 #endif /* CONFIG_IWL4965_HT */
3172 tx_status = &(txq->txb[txq->q.read_ptr].status);
3174 tx_status->retry_count = tx_resp->failure_frame;
3175 tx_status->queue_number = status;
3176 tx_status->queue_length = tx_resp->bt_kill_count;
3177 tx_status->queue_length |= tx_resp->failure_rts;
3179 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
3180 iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
3181 &tx_status->control);
3183 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3184 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
3185 status, le32_to_cpu(tx_resp->rate_n_flags),
3186 tx_resp->failure_frame);
3188 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3190 int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
3191 #ifdef CONFIG_IWL4965_HT
3192 if (tid != MAX_TID_COUNT)
3193 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3194 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
3196 priv->mac80211_registered)
3197 ieee80211_wake_queue(priv->hw, txq_id);
3198 if (tid != MAX_TID_COUNT)
3199 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
3202 #ifdef CONFIG_IWL4965_HT
3204 #endif /* CONFIG_IWL4965_HT */
3206 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3207 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3211 static void iwl4965_rx_reply_alive(struct iwl_priv *priv,
3212 struct iwl4965_rx_mem_buffer *rxb)
3214 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3215 struct iwl4965_alive_resp *palive;
3216 struct delayed_work *pwork;
3218 palive = &pkt->u.alive_frame;
3220 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3222 palive->is_valid, palive->ver_type,
3223 palive->ver_subtype);
3225 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
3226 IWL_DEBUG_INFO("Initialization Alive received.\n");
3227 memcpy(&priv->card_alive_init,
3228 &pkt->u.alive_frame,
3229 sizeof(struct iwl4965_init_alive_resp));
3230 pwork = &priv->init_alive_start;
3232 IWL_DEBUG_INFO("Runtime Alive received.\n");
3233 memcpy(&priv->card_alive, &pkt->u.alive_frame,
3234 sizeof(struct iwl4965_alive_resp));
3235 pwork = &priv->alive_start;
3238 /* We delay the ALIVE response by 5ms to
3239 * give the HW RF Kill time to activate... */
3240 if (palive->is_valid == UCODE_VALID_OK)
3241 queue_delayed_work(priv->workqueue, pwork,
3242 msecs_to_jiffies(5));
3244 IWL_WARNING("uCode did not respond OK.\n");
3247 static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv,
3248 struct iwl4965_rx_mem_buffer *rxb)
3250 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3252 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
3256 static void iwl4965_rx_reply_error(struct iwl_priv *priv,
3257 struct iwl4965_rx_mem_buffer *rxb)
3259 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3261 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3262 "seq 0x%04X ser 0x%08X\n",
3263 le32_to_cpu(pkt->u.err_resp.error_type),
3264 get_cmd_string(pkt->u.err_resp.cmd_id),
3265 pkt->u.err_resp.cmd_id,
3266 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
3267 le32_to_cpu(pkt->u.err_resp.error_info));
3270 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3272 static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
3274 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3275 struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon;
3276 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
3277 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3278 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
3279 rxon->channel = csa->channel;
3280 priv->staging_rxon.channel = csa->channel;
3283 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
3284 struct iwl4965_rx_mem_buffer *rxb)
3286 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3287 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3288 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
3290 if (!report->state) {
3291 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
3292 "Spectrum Measure Notification: Start\n");
3296 memcpy(&priv->measure_report, report, sizeof(*report));
3297 priv->measurement_status |= MEASUREMENT_READY;
3301 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
3302 struct iwl4965_rx_mem_buffer *rxb)
3304 #ifdef CONFIG_IWLWIFI_DEBUG
3305 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3306 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
3307 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3308 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
3312 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
3313 struct iwl4965_rx_mem_buffer *rxb)
3315 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3316 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3317 "notification for %s:\n",
3318 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
3319 iwl_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
3322 static void iwl4965_bg_beacon_update(struct work_struct *work)
3324 struct iwl_priv *priv =
3325 container_of(work, struct iwl_priv, beacon_update);
3326 struct sk_buff *beacon;
3328 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3329 beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL);
3332 IWL_ERROR("update beacon failed\n");
3336 mutex_lock(&priv->mutex);
3337 /* new beacon skb is allocated every time; dispose previous.*/
3338 if (priv->ibss_beacon)
3339 dev_kfree_skb(priv->ibss_beacon);
3341 priv->ibss_beacon = beacon;
3342 mutex_unlock(&priv->mutex);
3344 iwl4965_send_beacon_cmd(priv);
3347 static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
3348 struct iwl4965_rx_mem_buffer *rxb)
3350 #ifdef CONFIG_IWLWIFI_DEBUG
3351 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3352 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
3353 u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
3355 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3356 "tsf %d %d rate %d\n",
3357 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
3358 beacon->beacon_notify_hdr.failure_frame,
3359 le32_to_cpu(beacon->ibss_mgr_status),
3360 le32_to_cpu(beacon->high_tsf),
3361 le32_to_cpu(beacon->low_tsf), rate);
3364 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
3365 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
3366 queue_work(priv->workqueue, &priv->beacon_update);
3369 /* Service response to REPLY_SCAN_CMD (0x80) */
3370 static void iwl4965_rx_reply_scan(struct iwl_priv *priv,
3371 struct iwl4965_rx_mem_buffer *rxb)
3373 #ifdef CONFIG_IWLWIFI_DEBUG
3374 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3375 struct iwl4965_scanreq_notification *notif =
3376 (struct iwl4965_scanreq_notification *)pkt->u.raw;
3378 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
3382 /* Service SCAN_START_NOTIFICATION (0x82) */
3383 static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv,
3384 struct iwl4965_rx_mem_buffer *rxb)
3386 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3387 struct iwl4965_scanstart_notification *notif =
3388 (struct iwl4965_scanstart_notification *)pkt->u.raw;
3389 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
3390 IWL_DEBUG_SCAN("Scan start: "
3392 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3394 notif->band ? "bg" : "a",
3396 notif->tsf_low, notif->status, notif->beacon_timer);
3399 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3400 static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv,
3401 struct iwl4965_rx_mem_buffer *rxb)
3403 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3404 struct iwl4965_scanresults_notification *notif =
3405 (struct iwl4965_scanresults_notification *)pkt->u.raw;
3407 IWL_DEBUG_SCAN("Scan ch.res: "
3409 "(TSF: 0x%08X:%08X) - %d "
3410 "elapsed=%lu usec (%dms since last)\n",
3412 notif->band ? "bg" : "a",
3413 le32_to_cpu(notif->tsf_high),
3414 le32_to_cpu(notif->tsf_low),
3415 le32_to_cpu(notif->statistics[0]),
3416 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
3417 jiffies_to_msecs(elapsed_jiffies
3418 (priv->last_scan_jiffies, jiffies)));
3420 priv->last_scan_jiffies = jiffies;
3421 priv->next_scan_jiffies = 0;
3424 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3425 static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
3426 struct iwl4965_rx_mem_buffer *rxb)
3428 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3429 struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
3431 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3432 scan_notif->scanned_channels,
3433 scan_notif->tsf_low,
3434 scan_notif->tsf_high, scan_notif->status);
3436 /* The HW is no longer scanning */
3437 clear_bit(STATUS_SCAN_HW, &priv->status);
3439 /* The scan completion notification came in, so kill that timer... */
3440 cancel_delayed_work(&priv->scan_check);
3442 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3443 (priv->scan_bands == 2) ? "2.4" : "5.2",
3444 jiffies_to_msecs(elapsed_jiffies
3445 (priv->scan_pass_start, jiffies)));
3447 /* Remove this scanned band from the list
3448 * of pending bands to scan */
3451 /* If a request to abort was given, or the scan did not succeed
3452 * then we reset the scan state machine and terminate,
3453 * re-queuing another scan if one has been requested */
3454 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3455 IWL_DEBUG_INFO("Aborted scan completed.\n");
3456 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
3458 /* If there are more bands on this scan pass reschedule */
3459 if (priv->scan_bands > 0)
3463 priv->last_scan_jiffies = jiffies;
3464 priv->next_scan_jiffies = 0;
3465 IWL_DEBUG_INFO("Setting scan to off\n");
3467 clear_bit(STATUS_SCANNING, &priv->status);
3469 IWL_DEBUG_INFO("Scan took %dms\n",
3470 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
3472 queue_work(priv->workqueue, &priv->scan_completed);
3477 priv->scan_pass_start = jiffies;
3478 queue_work(priv->workqueue, &priv->request_scan);
3481 /* Handle notification from uCode that card's power state is changing
3482 * due to software, hardware, or critical temperature RFKILL */
3483 static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
3484 struct iwl4965_rx_mem_buffer *rxb)
3486 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3487 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
3488 unsigned long status = priv->status;
3490 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3491 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
3492 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
3494 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
3495 RF_CARD_DISABLED)) {
3497 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
3498 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3500 if (!iwl_grab_nic_access(priv)) {
3502 priv, HBUS_TARG_MBX_C,
3503 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
3505 iwl_release_nic_access(priv);
3508 if (!(flags & RXON_CARD_DISABLED)) {
3509 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
3510 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3511 if (!iwl_grab_nic_access(priv)) {
3513 priv, HBUS_TARG_MBX_C,
3514 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
3516 iwl_release_nic_access(priv);
3520 if (flags & RF_CARD_DISABLED) {
3521 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
3522 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
3523 iwl_read32(priv, CSR_UCODE_DRV_GP1);
3524 if (!iwl_grab_nic_access(priv))
3525 iwl_release_nic_access(priv);
3529 if (flags & HW_CARD_DISABLED)
3530 set_bit(STATUS_RF_KILL_HW, &priv->status);
3532 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3535 if (flags & SW_CARD_DISABLED)
3536 set_bit(STATUS_RF_KILL_SW, &priv->status);
3538 clear_bit(STATUS_RF_KILL_SW, &priv->status);
3540 if (!(flags & RXON_CARD_DISABLED))
3541 iwl4965_scan_cancel(priv);
3543 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
3544 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
3545 (test_bit(STATUS_RF_KILL_SW, &status) !=
3546 test_bit(STATUS_RF_KILL_SW, &priv->status)))
3547 queue_work(priv->workqueue, &priv->rf_kill);
3549 wake_up_interruptible(&priv->wait_command_queue);
3553 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
3555 * Setup the RX handlers for each of the reply types sent from the uCode
3558 * This function chains into the hardware specific files for them to setup
3559 * any hardware specific handlers as well.
3561 static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
3563 priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
3564 priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
3565 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
3566 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
3567 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
3568 iwl4965_rx_spectrum_measure_notif;
3569 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
3570 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
3571 iwl4965_rx_pm_debug_statistics_notif;
3572 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
3575 * The same handler is used for both the REPLY to a discrete
3576 * statistics request from the host as well as for the periodic
3577 * statistics notifications (after received beacons) from the uCode.
3579 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
3580 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
3582 priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
3583 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
3584 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
3585 iwl4965_rx_scan_results_notif;
3586 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
3587 iwl4965_rx_scan_complete_notif;
3588 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
3589 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
3591 /* Set up hardware specific Rx handlers */
3592 iwl4965_hw_rx_handler_setup(priv);
3596 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3597 * @rxb: Rx buffer to reclaim
3599 * If an Rx buffer has an async callback associated with it the callback
3600 * will be executed. The attached skb (if present) will only be freed
3601 * if the callback returns 1
3603 static void iwl4965_tx_cmd_complete(struct iwl_priv *priv,
3604 struct iwl4965_rx_mem_buffer *rxb)
3606 struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
3607 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3608 int txq_id = SEQ_TO_QUEUE(sequence);
3609 int index = SEQ_TO_INDEX(sequence);
3610 int huge = sequence & SEQ_HUGE_FRAME;
3612 struct iwl_cmd *cmd;
3614 /* If a Tx command is being handled and it isn't in the actual
3615 * command queue then there a command routing bug has been introduced
3616 * in the queue management code. */
3617 if (txq_id != IWL_CMD_QUEUE_NUM)
3618 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3619 txq_id, pkt->hdr.cmd);
3620 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
3622 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
3623 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
3625 /* Input error checking is done when commands are added to queue. */
3626 if (cmd->meta.flags & CMD_WANT_SKB) {
3627 cmd->meta.source->u.skb = rxb->skb;
3629 } else if (cmd->meta.u.callback &&
3630 !cmd->meta.u.callback(priv, cmd, rxb->skb))
3633 iwl4965_tx_queue_reclaim(priv, txq_id, index);
3635 if (!(cmd->meta.flags & CMD_ASYNC)) {
3636 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3637 wake_up_interruptible(&priv->wait_command_queue);
3641 /************************** RX-FUNCTIONS ****************************/
3643 * Rx theory of operation
3645 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
3646 * each of which point to Receive Buffers to be filled by 4965. These get
3647 * used not only for Rx frames, but for any command response or notification
3648 * from the 4965. The driver and 4965 manage the Rx buffers by means
3649 * of indexes into the circular buffer.
3652 * The host/firmware share two index registers for managing the Rx buffers.
3654 * The READ index maps to the first position that the firmware may be writing
3655 * to -- the driver can read up to (but not including) this position and get
3657 * The READ index is managed by the firmware once the card is enabled.
3659 * The WRITE index maps to the last position the driver has read from -- the
3660 * position preceding WRITE is the last slot the firmware can place a packet.
3662 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3665 * During initialization, the host sets up the READ queue position to the first
3666 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3668 * When the firmware places a packet in a buffer, it will advance the READ index
3669 * and fire the RX interrupt. The driver can then query the READ index and
3670 * process as many packets as possible, moving the WRITE index forward as it
3671 * resets the Rx queue buffers with new memory.
3673 * The management in the driver is as follows:
3674 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3675 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3676 * to replenish the iwl->rxq->rx_free.
3677 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
3678 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3679 * 'processed' and 'read' driver indexes as well)
3680 * + A received packet is processed and handed to the kernel network stack,
3681 * detached from the iwl->rxq. The driver 'processed' index is updated.
3682 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3683 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3684 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3685 * were enough free buffers and RX_STALLED is set it is cleared.
3690 * iwl4965_rx_queue_alloc() Allocates rx_free
3691 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
3692 * iwl4965_rx_queue_restock
3693 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
3694 * queue, updates firmware pointers, and updates
3695 * the WRITE index. If insufficient rx_free buffers
3696 * are available, schedules iwl4965_rx_replenish
3698 * -- enable interrupts --
3699 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
3700 * READ INDEX, detaching the SKB from the pool.
3701 * Moves the packet buffer from queue to rx_used.
3702 * Calls iwl4965_rx_queue_restock to refill any empty
3709 * iwl4965_rx_queue_space - Return number of free slots available in queue.
3711 static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q)
3713 int s = q->read - q->write;
3716 /* keep some buffer to not confuse full and empty queue */
3724 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3726 int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl4965_rx_queue *q)
3730 unsigned long flags;
3732 spin_lock_irqsave(&q->lock, flags);
3734 if (q->need_update == 0)
3737 /* If power-saving is in use, make sure device is awake */
3738 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
3739 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
3741 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
3742 iwl_set_bit(priv, CSR_GP_CNTRL,
3743 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
3747 rc = iwl_grab_nic_access(priv);
3751 /* Device expects a multiple of 8 */
3752 iwl_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
3754 iwl_release_nic_access(priv);
3756 /* Else device is assumed to be awake */
3758 /* Device expects a multiple of 8 */
3759 iwl_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
3765 spin_unlock_irqrestore(&q->lock, flags);
3770 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3772 static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl_priv *priv,
3773 dma_addr_t dma_addr)
3775 return cpu_to_le32((u32)(dma_addr >> 8));
3780 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
3782 * If there are slots in the RX queue that need to be restocked,
3783 * and we have free pre-allocated buffers, fill the ranks as much
3784 * as we can, pulling from rx_free.
3786 * This moves the 'write' index forward to catch up with 'processed', and
3787 * also updates the memory address in the firmware to reference the new
3790 static int iwl4965_rx_queue_restock(struct iwl_priv *priv)
3792 struct iwl4965_rx_queue *rxq = &priv->rxq;
3793 struct list_head *element;
3794 struct iwl4965_rx_mem_buffer *rxb;
3795 unsigned long flags;
3798 spin_lock_irqsave(&rxq->lock, flags);
3799 write = rxq->write & ~0x7;
3800 while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
3801 /* Get next free Rx buffer, remove from free list */
3802 element = rxq->rx_free.next;
3803 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
3806 /* Point to Rx buffer via next RBD in circular buffer */
3807 rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr);
3808 rxq->queue[rxq->write] = rxb;
3809 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
3812 spin_unlock_irqrestore(&rxq->lock, flags);
3813 /* If the pre-allocated buffer pool is dropping low, schedule to
3815 if (rxq->free_count <= RX_LOW_WATERMARK)
3816 queue_work(priv->workqueue, &priv->rx_replenish);
3819 /* If we've added more space for the firmware to place data, tell it.
3820 * Increment device's write pointer in multiples of 8. */
3821 if ((write != (rxq->write & ~0x7))
3822 || (abs(rxq->write - rxq->read) > 7)) {
3823 spin_lock_irqsave(&rxq->lock, flags);
3824 rxq->need_update = 1;
3825 spin_unlock_irqrestore(&rxq->lock, flags);
3826 rc = iwl4965_rx_queue_update_write_ptr(priv, rxq);
3835 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
3837 * When moving to rx_free an SKB is allocated for the slot.
3839 * Also restock the Rx queue via iwl4965_rx_queue_restock.
3840 * This is called as a scheduled work item (except for during initialization)
3842 static void iwl4965_rx_allocate(struct iwl_priv *priv)
3844 struct iwl4965_rx_queue *rxq = &priv->rxq;
3845 struct list_head *element;
3846 struct iwl4965_rx_mem_buffer *rxb;
3847 unsigned long flags;
3848 spin_lock_irqsave(&rxq->lock, flags);
3849 while (!list_empty(&rxq->rx_used)) {
3850 element = rxq->rx_used.next;
3851 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
3853 /* Alloc a new receive buffer */
3855 alloc_skb(priv->hw_setting.rx_buf_size,
3856 __GFP_NOWARN | GFP_ATOMIC);
3858 if (net_ratelimit())
3859 printk(KERN_CRIT DRV_NAME
3860 ": Can not allocate SKB buffers\n");
3861 /* We don't reschedule replenish work here -- we will
3862 * call the restock method and if it still needs
3863 * more buffers it will schedule replenish */
3866 priv->alloc_rxb_skb++;
3869 /* Get physical address of RB/SKB */
3871 pci_map_single(priv->pci_dev, rxb->skb->data,
3872 priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE);
3873 list_add_tail(&rxb->list, &rxq->rx_free);
3876 spin_unlock_irqrestore(&rxq->lock, flags);
3880 * this should be called while priv->lock is locked
3882 static void __iwl4965_rx_replenish(void *data)
3884 struct iwl_priv *priv = data;
3886 iwl4965_rx_allocate(priv);
3887 iwl4965_rx_queue_restock(priv);
3891 void iwl4965_rx_replenish(void *data)
3893 struct iwl_priv *priv = data;
3894 unsigned long flags;
3896 iwl4965_rx_allocate(priv);
3898 spin_lock_irqsave(&priv->lock, flags);
3899 iwl4965_rx_queue_restock(priv);
3900 spin_unlock_irqrestore(&priv->lock, flags);
3903 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3904 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3905 * This free routine walks the list of POOL entries and if SKB is set to
3906 * non NULL it is unmapped and freed
3908 static void iwl4965_rx_queue_free(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
3911 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
3912 if (rxq->pool[i].skb != NULL) {
3913 pci_unmap_single(priv->pci_dev,
3914 rxq->pool[i].dma_addr,
3915 priv->hw_setting.rx_buf_size,
3916 PCI_DMA_FROMDEVICE);
3917 dev_kfree_skb(rxq->pool[i].skb);
3921 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
3926 int iwl4965_rx_queue_alloc(struct iwl_priv *priv)
3928 struct iwl4965_rx_queue *rxq = &priv->rxq;
3929 struct pci_dev *dev = priv->pci_dev;
3932 spin_lock_init(&rxq->lock);
3933 INIT_LIST_HEAD(&rxq->rx_free);
3934 INIT_LIST_HEAD(&rxq->rx_used);
3936 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3937 rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
3941 /* Fill the rx_used queue with _all_ of the Rx buffers */
3942 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
3943 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3945 /* Set us so that we have processed and used all buffers, but have
3946 * not restocked the Rx queue with fresh buffers */
3947 rxq->read = rxq->write = 0;
3948 rxq->free_count = 0;
3949 rxq->need_update = 0;
3953 void iwl4965_rx_queue_reset(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
3955 unsigned long flags;
3957 spin_lock_irqsave(&rxq->lock, flags);
3958 INIT_LIST_HEAD(&rxq->rx_free);
3959 INIT_LIST_HEAD(&rxq->rx_used);
3960 /* Fill the rx_used queue with _all_ of the Rx buffers */
3961 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3962 /* In the reset function, these buffers may have been allocated
3963 * to an SKB, so we need to unmap and free potential storage */
3964 if (rxq->pool[i].skb != NULL) {
3965 pci_unmap_single(priv->pci_dev,
3966 rxq->pool[i].dma_addr,
3967 priv->hw_setting.rx_buf_size,
3968 PCI_DMA_FROMDEVICE);
3969 priv->alloc_rxb_skb--;
3970 dev_kfree_skb(rxq->pool[i].skb);
3971 rxq->pool[i].skb = NULL;
3973 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3976 /* Set us so that we have processed and used all buffers, but have
3977 * not restocked the Rx queue with fresh buffers */
3978 rxq->read = rxq->write = 0;
3979 rxq->free_count = 0;
3980 spin_unlock_irqrestore(&rxq->lock, flags);
3983 /* Convert linear signal-to-noise ratio into dB */
3984 static u8 ratio2dB[100] = {
3985 /* 0 1 2 3 4 5 6 7 8 9 */
3986 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3987 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3988 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3989 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3990 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3991 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
3992 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
3993 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
3994 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
3995 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
3998 /* Calculates a relative dB value from a ratio of linear
3999 * (i.e. not dB) signal levels.
4000 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4001 int iwl4965_calc_db_from_ratio(int sig_ratio)
4003 /* 1000:1 or higher just report as 60 dB */
4004 if (sig_ratio >= 1000)
4007 /* 100:1 or higher, divide by 10 and use table,
4008 * add 20 dB to make up for divide by 10 */
4009 if (sig_ratio >= 100)
4010 return (20 + (int)ratio2dB[sig_ratio/10]);
4012 /* We shouldn't see this */
4016 /* Use table for ratios 1:1 - 99:1 */
4017 return (int)ratio2dB[sig_ratio];
4020 #define PERFECT_RSSI (-20) /* dBm */
4021 #define WORST_RSSI (-95) /* dBm */
4022 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4024 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
4025 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4026 * about formulas used below. */
4027 int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
4030 int degradation = PERFECT_RSSI - rssi_dbm;
4032 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4033 * as indicator; formula is (signal dbm - noise dbm).
4034 * SNR at or above 40 is a great signal (100%).
4035 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4036 * Weakest usable signal is usually 10 - 15 dB SNR. */
4038 if (rssi_dbm - noise_dbm >= 40)
4040 else if (rssi_dbm < noise_dbm)
4042 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
4044 /* Else use just the signal level.
4045 * This formula is a least squares fit of data points collected and
4046 * compared with a reference system that had a percentage (%) display
4047 * for signal quality. */
4049 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
4050 (15 * RSSI_RANGE + 62 * degradation)) /
4051 (RSSI_RANGE * RSSI_RANGE);
4055 else if (sig_qual < 1)
4062 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
4064 * Uses the priv->rx_handlers callback function array to invoke
4065 * the appropriate handlers, including command responses,
4066 * frame-received notifications, and other notifications.
4068 static void iwl4965_rx_handle(struct iwl_priv *priv)
4070 struct iwl4965_rx_mem_buffer *rxb;
4071 struct iwl4965_rx_packet *pkt;
4072 struct iwl4965_rx_queue *rxq = &priv->rxq;
4075 unsigned long flags;
4079 /* uCode's read index (stored in shared DRAM) indicates the last Rx
4080 * buffer that the driver may process (last buffer filled by ucode). */
4081 r = iwl4965_hw_get_rx_read(priv);
4084 /* Rx interrupt, but nothing sent from uCode */
4086 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
4088 if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
4092 rxb = rxq->queue[i];
4094 /* If an RXB doesn't have a Rx queue slot associated with it,
4095 * then a bug has been introduced in the queue refilling
4096 * routines -- catch it here */
4097 BUG_ON(rxb == NULL);
4099 rxq->queue[i] = NULL;
4101 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
4102 priv->hw_setting.rx_buf_size,
4103 PCI_DMA_FROMDEVICE);
4104 pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
4106 /* Reclaim a command buffer only if this packet is a response
4107 * to a (driver-originated) command.
4108 * If the packet (e.g. Rx frame) originated from uCode,
4109 * there is no command buffer to reclaim.
4110 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4111 * but apparently a few don't get set; catch them here. */
4112 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
4113 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
4114 (pkt->hdr.cmd != REPLY_RX) &&
4115 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
4116 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
4117 (pkt->hdr.cmd != REPLY_TX);
4119 /* Based on type of command response or notification,
4120 * handle those that need handling via function in
4121 * rx_handlers table. See iwl4965_setup_rx_handlers() */
4122 if (priv->rx_handlers[pkt->hdr.cmd]) {
4123 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4124 "r = %d, i = %d, %s, 0x%02x\n", r, i,
4125 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
4126 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
4128 /* No handling needed */
4129 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4130 "r %d i %d No handler needed for %s, 0x%02x\n",
4131 r, i, get_cmd_string(pkt->hdr.cmd),
4136 /* Invoke any callbacks, transfer the skb to caller, and
4137 * fire off the (possibly) blocking iwl_send_cmd()
4138 * as we reclaim the driver command queue */
4139 if (rxb && rxb->skb)
4140 iwl4965_tx_cmd_complete(priv, rxb);
4142 IWL_WARNING("Claim null rxb?\n");
4145 /* For now we just don't re-use anything. We can tweak this
4146 * later to try and re-use notification packets and SKBs that
4147 * fail to Rx correctly */
4148 if (rxb->skb != NULL) {
4149 priv->alloc_rxb_skb--;
4150 dev_kfree_skb_any(rxb->skb);
4154 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
4155 priv->hw_setting.rx_buf_size,
4156 PCI_DMA_FROMDEVICE);
4157 spin_lock_irqsave(&rxq->lock, flags);
4158 list_add_tail(&rxb->list, &priv->rxq.rx_used);
4159 spin_unlock_irqrestore(&rxq->lock, flags);
4160 i = (i + 1) & RX_QUEUE_MASK;
4161 /* If there are a lot of unused frames,
4162 * restock the Rx queue so ucode wont assert. */
4167 __iwl4965_rx_replenish(priv);
4173 /* Backtrack one entry */
4175 iwl4965_rx_queue_restock(priv);
4179 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4181 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
4182 struct iwl4965_tx_queue *txq)
4186 int txq_id = txq->q.id;
4188 if (txq->need_update == 0)
4191 /* if we're trying to save power */
4192 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4193 /* wake up nic if it's powered down ...
4194 * uCode will wake up, and interrupt us again, so next
4195 * time we'll skip this part. */
4196 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
4198 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4199 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
4200 iwl_set_bit(priv, CSR_GP_CNTRL,
4201 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4205 /* restore this queue's parameters in nic hardware. */
4206 rc = iwl_grab_nic_access(priv);
4209 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
4210 txq->q.write_ptr | (txq_id << 8));
4211 iwl_release_nic_access(priv);
4213 /* else not in power-save mode, uCode will never sleep when we're
4214 * trying to tx (during RFKILL, we're not trying to tx). */
4216 iwl_write32(priv, HBUS_TARG_WRPTR,
4217 txq->q.write_ptr | (txq_id << 8));
4219 txq->need_update = 0;
4224 #ifdef CONFIG_IWLWIFI_DEBUG
4225 static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon)
4227 DECLARE_MAC_BUF(mac);
4229 IWL_DEBUG_RADIO("RX CONFIG:\n");
4230 iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
4231 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
4232 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
4233 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4234 le32_to_cpu(rxon->filter_flags));
4235 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
4236 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4237 rxon->ofdm_basic_rates);
4238 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
4239 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4240 print_mac(mac, rxon->node_addr));
4241 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4242 print_mac(mac, rxon->bssid_addr));
4243 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
4247 static void iwl4965_enable_interrupts(struct iwl_priv *priv)
4249 IWL_DEBUG_ISR("Enabling interrupts\n");
4250 set_bit(STATUS_INT_ENABLED, &priv->status);
4251 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
4254 /* call this function to flush any scheduled tasklet */
4255 static inline void iwl_synchronize_irq(struct iwl_priv *priv)
4257 /* wait to make sure we flush pedding tasklet*/
4258 synchronize_irq(priv->pci_dev->irq);
4259 tasklet_kill(&priv->irq_tasklet);
4262 static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
4264 clear_bit(STATUS_INT_ENABLED, &priv->status);
4266 /* disable interrupts from uCode/NIC to host */
4267 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
4269 /* acknowledge/clear/reset any interrupts still pending
4270 * from uCode or flow handler (Rx/Tx DMA) */
4271 iwl_write32(priv, CSR_INT, 0xffffffff);
4272 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
4273 IWL_DEBUG_ISR("Disabled interrupts\n");
4276 static const char *desc_lookup(int i)
4284 return "BAD_CHECKSUM";
4286 return "NMI_INTERRUPT";
4290 return "FATAL_ERROR";
4296 #define ERROR_START_OFFSET (1 * sizeof(u32))
4297 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4299 static void iwl4965_dump_nic_error_log(struct iwl_priv *priv)
4302 u32 desc, time, count, base, data1;
4303 u32 blink1, blink2, ilink1, ilink2;
4306 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
4308 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
4309 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
4313 rc = iwl_grab_nic_access(priv);
4315 IWL_WARNING("Can not read from adapter at this time.\n");
4319 count = iwl_read_targ_mem(priv, base);
4321 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
4322 IWL_ERROR("Start IWL Error Log Dump:\n");
4323 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
4326 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
4327 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
4328 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
4329 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
4330 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
4331 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
4332 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
4333 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
4334 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
4336 IWL_ERROR("Desc Time "
4337 "data1 data2 line\n");
4338 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4339 desc_lookup(desc), desc, time, data1, data2, line);
4340 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4341 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
4344 iwl_release_nic_access(priv);
4347 #define EVENT_START_OFFSET (4 * sizeof(u32))
4350 * iwl4965_print_event_log - Dump error event log to syslog
4352 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
4354 static void iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx,
4355 u32 num_events, u32 mode)
4358 u32 base; /* SRAM byte address of event log header */
4359 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
4360 u32 ptr; /* SRAM byte address of log data */
4361 u32 ev, time, data; /* event log data */
4363 if (num_events == 0)
4366 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4369 event_size = 2 * sizeof(u32);
4371 event_size = 3 * sizeof(u32);
4373 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
4375 /* "time" is actually "data" for mode 0 (no timestamp).
4376 * place event id # at far right for easier visual parsing. */
4377 for (i = 0; i < num_events; i++) {
4378 ev = iwl_read_targ_mem(priv, ptr);
4380 time = iwl_read_targ_mem(priv, ptr);
4383 IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
4385 data = iwl_read_targ_mem(priv, ptr);
4387 IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
4392 static void iwl4965_dump_nic_event_log(struct iwl_priv *priv)
4395 u32 base; /* SRAM byte address of event log header */
4396 u32 capacity; /* event log capacity in # entries */
4397 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
4398 u32 num_wraps; /* # times uCode wrapped to top of log */
4399 u32 next_entry; /* index of next entry to be written by uCode */
4400 u32 size; /* # entries that we'll print */
4402 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4403 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
4404 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
4408 rc = iwl_grab_nic_access(priv);
4410 IWL_WARNING("Can not read from adapter at this time.\n");
4414 /* event log header */
4415 capacity = iwl_read_targ_mem(priv, base);
4416 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
4417 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
4418 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
4420 size = num_wraps ? capacity : next_entry;
4422 /* bail out if nothing in log */
4424 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4425 iwl_release_nic_access(priv);
4429 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4432 /* if uCode has wrapped back to top of log, start at the oldest entry,
4433 * i.e the next one that uCode would fill. */
4435 iwl4965_print_event_log(priv, next_entry,
4436 capacity - next_entry, mode);
4438 /* (then/else) start at top of log */
4439 iwl4965_print_event_log(priv, 0, next_entry, mode);
4441 iwl_release_nic_access(priv);
4445 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
4447 static void iwl4965_irq_handle_error(struct iwl_priv *priv)
4449 /* Set the FW error flag -- cleared on iwl4965_down */
4450 set_bit(STATUS_FW_ERROR, &priv->status);
4452 /* Cancel currently queued command. */
4453 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4455 #ifdef CONFIG_IWLWIFI_DEBUG
4456 if (iwl_debug_level & IWL_DL_FW_ERRORS) {
4457 iwl4965_dump_nic_error_log(priv);
4458 iwl4965_dump_nic_event_log(priv);
4459 iwl4965_print_rx_config_cmd(&priv->staging_rxon);
4463 wake_up_interruptible(&priv->wait_command_queue);
4465 /* Keep the restart process from trying to send host
4466 * commands by clearing the INIT status bit */
4467 clear_bit(STATUS_READY, &priv->status);
4469 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4470 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
4471 "Restarting adapter due to uCode error.\n");
4473 if (iwl_is_associated(priv)) {
4474 memcpy(&priv->recovery_rxon, &priv->active_rxon,
4475 sizeof(priv->recovery_rxon));
4476 priv->error_recovering = 1;
4478 queue_work(priv->workqueue, &priv->restart);
4482 static void iwl4965_error_recovery(struct iwl_priv *priv)
4484 unsigned long flags;
4486 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
4487 sizeof(priv->staging_rxon));
4488 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4489 iwl4965_commit_rxon(priv);
4491 iwl4965_rxon_add_station(priv, priv->bssid, 1);
4493 spin_lock_irqsave(&priv->lock, flags);
4494 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
4495 priv->error_recovering = 0;
4496 spin_unlock_irqrestore(&priv->lock, flags);
4499 static void iwl4965_irq_tasklet(struct iwl_priv *priv)
4501 u32 inta, handled = 0;
4503 unsigned long flags;
4504 #ifdef CONFIG_IWLWIFI_DEBUG
4508 spin_lock_irqsave(&priv->lock, flags);
4510 /* Ack/clear/reset pending uCode interrupts.
4511 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4512 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4513 inta = iwl_read32(priv, CSR_INT);
4514 iwl_write32(priv, CSR_INT, inta);
4516 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4517 * Any new interrupts that happen after this, either while we're
4518 * in this tasklet, or later, will show up in next ISR/tasklet. */
4519 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
4520 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
4522 #ifdef CONFIG_IWLWIFI_DEBUG
4523 if (iwl_debug_level & IWL_DL_ISR) {
4524 /* just for debug */
4525 inta_mask = iwl_read32(priv, CSR_INT_MASK);
4526 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4527 inta, inta_mask, inta_fh);
4531 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4532 * atomic, make sure that inta covers all the interrupts that
4533 * we've discovered, even if FH interrupt came in just after
4534 * reading CSR_INT. */
4535 if (inta_fh & CSR49_FH_INT_RX_MASK)
4536 inta |= CSR_INT_BIT_FH_RX;
4537 if (inta_fh & CSR49_FH_INT_TX_MASK)
4538 inta |= CSR_INT_BIT_FH_TX;
4540 /* Now service all interrupt bits discovered above. */
4541 if (inta & CSR_INT_BIT_HW_ERR) {
4542 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4544 /* Tell the device to stop sending interrupts */
4545 iwl4965_disable_interrupts(priv);
4547 iwl4965_irq_handle_error(priv);
4549 handled |= CSR_INT_BIT_HW_ERR;
4551 spin_unlock_irqrestore(&priv->lock, flags);
4556 #ifdef CONFIG_IWLWIFI_DEBUG
4557 if (iwl_debug_level & (IWL_DL_ISR)) {
4558 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4559 if (inta & CSR_INT_BIT_SCD)
4560 IWL_DEBUG_ISR("Scheduler finished to transmit "
4561 "the frame/frames.\n");
4563 /* Alive notification via Rx interrupt will do the real work */
4564 if (inta & CSR_INT_BIT_ALIVE)
4565 IWL_DEBUG_ISR("Alive interrupt\n");
4568 /* Safely ignore these bits for debug checks below */
4569 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
4571 /* HW RF KILL switch toggled */
4572 if (inta & CSR_INT_BIT_RF_KILL) {
4574 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
4575 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
4578 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
4579 "RF_KILL bit toggled to %s.\n",
4580 hw_rf_kill ? "disable radio":"enable radio");
4582 /* Queue restart only if RF_KILL switch was set to "kill"
4583 * when we loaded driver, and is now set to "enable".
4584 * After we're Alive, RF_KILL gets handled by
4585 * iwl4965_rx_card_state_notif() */
4586 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
4587 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4588 queue_work(priv->workqueue, &priv->restart);
4591 handled |= CSR_INT_BIT_RF_KILL;
4594 /* Chip got too hot and stopped itself */
4595 if (inta & CSR_INT_BIT_CT_KILL) {
4596 IWL_ERROR("Microcode CT kill error detected.\n");
4597 handled |= CSR_INT_BIT_CT_KILL;
4600 /* Error detected by uCode */
4601 if (inta & CSR_INT_BIT_SW_ERR) {
4602 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4604 iwl4965_irq_handle_error(priv);
4605 handled |= CSR_INT_BIT_SW_ERR;
4608 /* uCode wakes up after power-down sleep */
4609 if (inta & CSR_INT_BIT_WAKEUP) {
4610 IWL_DEBUG_ISR("Wakeup interrupt\n");
4611 iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq);
4612 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]);
4613 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]);
4614 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]);
4615 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]);
4616 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]);
4617 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]);
4619 handled |= CSR_INT_BIT_WAKEUP;
4622 /* All uCode command responses, including Tx command responses,
4623 * Rx "responses" (frame-received notification), and other
4624 * notifications from uCode come through here*/
4625 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
4626 iwl4965_rx_handle(priv);
4627 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
4630 if (inta & CSR_INT_BIT_FH_TX) {
4631 IWL_DEBUG_ISR("Tx interrupt\n");
4632 handled |= CSR_INT_BIT_FH_TX;
4635 if (inta & ~handled)
4636 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
4638 if (inta & ~CSR_INI_SET_MASK) {
4639 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4640 inta & ~CSR_INI_SET_MASK);
4641 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
4644 /* Re-enable all interrupts */
4645 /* only Re-enable if diabled by irq */
4646 if (test_bit(STATUS_INT_ENABLED, &priv->status))
4647 iwl4965_enable_interrupts(priv);
4649 #ifdef CONFIG_IWLWIFI_DEBUG
4650 if (iwl_debug_level & (IWL_DL_ISR)) {
4651 inta = iwl_read32(priv, CSR_INT);
4652 inta_mask = iwl_read32(priv, CSR_INT_MASK);
4653 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
4654 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4655 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
4658 spin_unlock_irqrestore(&priv->lock, flags);
4661 static irqreturn_t iwl4965_isr(int irq, void *data)
4663 struct iwl_priv *priv = data;
4664 u32 inta, inta_mask;
4669 spin_lock(&priv->lock);
4671 /* Disable (but don't clear!) interrupts here to avoid
4672 * back-to-back ISRs and sporadic interrupts from our NIC.
4673 * If we have something to service, the tasklet will re-enable ints.
4674 * If we *don't* have something, we'll re-enable before leaving here. */
4675 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
4676 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
4678 /* Discover which interrupts are active/pending */
4679 inta = iwl_read32(priv, CSR_INT);
4680 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
4682 /* Ignore interrupt if there's nothing in NIC to service.
4683 * This may be due to IRQ shared with another device,
4684 * or due to sporadic interrupts thrown from our NIC. */
4685 if (!inta && !inta_fh) {
4686 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4690 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
4691 /* Hardware disappeared. It might have already raised
4693 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
4697 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4698 inta, inta_mask, inta_fh);
4700 inta &= ~CSR_INT_BIT_SCD;
4702 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
4703 if (likely(inta || inta_fh))
4704 tasklet_schedule(&priv->irq_tasklet);
4707 spin_unlock(&priv->lock);
4711 /* re-enable interrupts here since we don't have anything to service. */
4712 /* only Re-enable if diabled by irq */
4713 if (test_bit(STATUS_INT_ENABLED, &priv->status))
4714 iwl4965_enable_interrupts(priv);
4715 spin_unlock(&priv->lock);
4719 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4720 * sending probe req. This should be set long enough to hear probe responses
4721 * from more than one AP. */
4722 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
4723 #define IWL_ACTIVE_DWELL_TIME_52 (10)
4725 /* For faster active scanning, scan will move to the next channel if fewer than
4726 * PLCP_QUIET_THRESH packets are heard on this channel within
4727 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4728 * time if it's a quiet channel (nothing responded to our probe, and there's
4729 * no other traffic).
4730 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4731 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4732 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
4734 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4735 * Must be set longer than active dwell time.
4736 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4737 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4738 #define IWL_PASSIVE_DWELL_TIME_52 (10)
4739 #define IWL_PASSIVE_DWELL_BASE (100)
4740 #define IWL_CHANNEL_TUNE_TIME 5
4742 static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv,
4743 enum ieee80211_band band)
4745 if (band == IEEE80211_BAND_5GHZ)
4746 return IWL_ACTIVE_DWELL_TIME_52;
4748 return IWL_ACTIVE_DWELL_TIME_24;
4751 static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv,
4752 enum ieee80211_band band)
4754 u16 active = iwl4965_get_active_dwell_time(priv, band);
4755 u16 passive = (band != IEEE80211_BAND_5GHZ) ?
4756 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
4757 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
4759 if (iwl_is_associated(priv)) {
4760 /* If we're associated, we clamp the maximum passive
4761 * dwell time to be 98% of the beacon interval (minus
4762 * 2 * channel tune time) */
4763 passive = priv->beacon_int;
4764 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
4765 passive = IWL_PASSIVE_DWELL_BASE;
4766 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
4769 if (passive <= active)
4770 passive = active + 1;
4775 static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
4776 enum ieee80211_band band,
4777 u8 is_active, u8 direct_mask,
4778 struct iwl4965_scan_channel *scan_ch)
4780 const struct ieee80211_channel *channels = NULL;
4781 const struct ieee80211_supported_band *sband;
4782 const struct iwl_channel_info *ch_info;
4783 u16 passive_dwell = 0;
4784 u16 active_dwell = 0;
4787 sband = iwl4965_get_hw_mode(priv, band);
4791 channels = sband->channels;
4793 active_dwell = iwl4965_get_active_dwell_time(priv, band);
4794 passive_dwell = iwl4965_get_passive_dwell_time(priv, band);
4796 for (i = 0, added = 0; i < sband->n_channels; i++) {
4797 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
4800 if (ieee80211_frequency_to_channel(channels[i].center_freq) ==
4801 le16_to_cpu(priv->active_rxon.channel)) {
4802 if (iwl_is_associated(priv)) {
4804 ("Skipping current channel %d\n",
4805 le16_to_cpu(priv->active_rxon.channel));
4808 } else if (priv->only_active_channel)
4811 scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
4813 ch_info = iwl_get_channel_info(priv, band,
4815 if (!is_channel_valid(ch_info)) {
4816 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
4821 if (!is_active || is_channel_passive(ch_info) ||
4822 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
4823 scan_ch->type = 0; /* passive */
4825 scan_ch->type = 1; /* active */
4827 if (scan_ch->type & 1)
4828 scan_ch->type |= (direct_mask << 1);
4830 if (is_channel_narrow(ch_info))
4831 scan_ch->type |= (1 << 7);
4833 scan_ch->active_dwell = cpu_to_le16(active_dwell);
4834 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
4836 /* Set txpower levels to defaults */
4837 scan_ch->tpc.dsp_atten = 110;
4838 /* scan_pwr_info->tpc.dsp_atten; */
4840 /*scan_pwr_info->tpc.tx_gain; */
4841 if (band == IEEE80211_BAND_5GHZ)
4842 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
4844 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
4845 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4847 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4851 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4853 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
4854 (scan_ch->type & 1) ?
4855 active_dwell : passive_dwell);
4861 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
4865 static void iwl4965_init_hw_rates(struct iwl_priv *priv,
4866 struct ieee80211_rate *rates)
4870 for (i = 0; i < IWL_RATE_COUNT; i++) {
4871 rates[i].bitrate = iwl4965_rates[i].ieee * 5;
4872 rates[i].hw_value = i; /* Rate scaling will work on indexes */
4873 rates[i].hw_value_short = i;
4875 if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
4877 * If CCK != 1M then set short preamble rate flag.
4880 (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ?
4881 0 : IEEE80211_RATE_SHORT_PREAMBLE;
4887 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
4889 int iwl4965_init_geos(struct iwl_priv *priv)
4891 struct iwl_channel_info *ch;
4892 struct ieee80211_supported_band *sband;
4893 struct ieee80211_channel *channels;
4894 struct ieee80211_channel *geo_ch;
4895 struct ieee80211_rate *rates;
4898 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
4899 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
4900 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4901 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
4905 channels = kzalloc(sizeof(struct ieee80211_channel) *
4906 priv->channel_count, GFP_KERNEL);
4910 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
4917 /* 5.2GHz channels start after the 2.4GHz channels */
4918 sband = &priv->bands[IEEE80211_BAND_5GHZ];
4919 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
4921 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
4922 sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
4924 iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_5GHZ);
4926 sband = &priv->bands[IEEE80211_BAND_2GHZ];
4927 sband->channels = channels;
4929 sband->bitrates = rates;
4930 sband->n_bitrates = IWL_RATE_COUNT;
4932 iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_2GHZ);
4934 priv->ieee_channels = channels;
4935 priv->ieee_rates = rates;
4937 iwl4965_init_hw_rates(priv, rates);
4939 for (i = 0; i < priv->channel_count; i++) {
4940 ch = &priv->channel_info[i];
4942 /* FIXME: might be removed if scan is OK */
4943 if (!is_channel_valid(ch))
4946 if (is_channel_a_band(ch))
4947 sband = &priv->bands[IEEE80211_BAND_5GHZ];
4949 sband = &priv->bands[IEEE80211_BAND_2GHZ];
4951 geo_ch = &sband->channels[sband->n_channels++];
4953 geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
4954 geo_ch->max_power = ch->max_power_avg;
4955 geo_ch->max_antenna_gain = 0xff;
4956 geo_ch->hw_value = ch->channel;
4958 if (is_channel_valid(ch)) {
4959 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
4960 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
4962 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
4963 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
4965 if (ch->flags & EEPROM_CHANNEL_RADAR)
4966 geo_ch->flags |= IEEE80211_CHAN_RADAR;
4968 if (ch->max_power_avg > priv->max_channel_txpower_limit)
4969 priv->max_channel_txpower_limit =
4972 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
4975 /* Save flags for reg domain usage */
4976 geo_ch->orig_flags = geo_ch->flags;
4978 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4979 ch->channel, geo_ch->center_freq,
4980 is_channel_a_band(ch) ? "5.2" : "2.4",
4981 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
4982 "restricted" : "valid",
4986 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
4987 priv->cfg->sku & IWL_SKU_A) {
4988 printk(KERN_INFO DRV_NAME
4989 ": Incorrectly detected BG card as ABG. Please send "
4990 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
4991 priv->pci_dev->device, priv->pci_dev->subsystem_device);
4992 priv->cfg->sku &= ~IWL_SKU_A;
4995 printk(KERN_INFO DRV_NAME
4996 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
4997 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
4998 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
5000 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5001 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5002 &priv->bands[IEEE80211_BAND_2GHZ];
5003 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5004 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5005 &priv->bands[IEEE80211_BAND_5GHZ];
5007 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5013 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
5015 void iwl4965_free_geos(struct iwl_priv *priv)
5017 kfree(priv->ieee_channels);
5018 kfree(priv->ieee_rates);
5019 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
5022 /******************************************************************************
5024 * uCode download functions
5026 ******************************************************************************/
5028 static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
5030 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
5031 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
5032 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
5033 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
5034 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
5035 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
5039 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
5040 * looking at all data.
5042 static int iwl4965_verify_inst_full(struct iwl_priv *priv, __le32 *image,
5050 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5052 rc = iwl_grab_nic_access(priv);
5056 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
5059 for (; len > 0; len -= sizeof(u32), image++) {
5060 /* read data comes through single port, auto-incr addr */
5061 /* NOTE: Use the debugless read so we don't flood kernel log
5062 * if IWL_DL_IO is set */
5063 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
5064 if (val != le32_to_cpu(*image)) {
5065 IWL_ERROR("uCode INST section is invalid at "
5066 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5067 save_len - len, val, le32_to_cpu(*image));
5075 iwl_release_nic_access(priv);
5079 ("ucode image in INSTRUCTION memory is good\n");
5086 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
5087 * using sample data 100 bytes apart. If these sample points are good,
5088 * it's a pretty good bet that everything between them is good, too.
5090 static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
5097 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5099 rc = iwl_grab_nic_access(priv);
5103 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
5104 /* read data comes through single port, auto-incr addr */
5105 /* NOTE: Use the debugless read so we don't flood kernel log
5106 * if IWL_DL_IO is set */
5107 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
5108 i + RTC_INST_LOWER_BOUND);
5109 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
5110 if (val != le32_to_cpu(*image)) {
5111 #if 0 /* Enable this if you want to see details */
5112 IWL_ERROR("uCode INST section is invalid at "
5113 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5123 iwl_release_nic_access(priv);
5130 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
5131 * and verify its contents
5133 static int iwl4965_verify_ucode(struct iwl_priv *priv)
5140 image = (__le32 *)priv->ucode_boot.v_addr;
5141 len = priv->ucode_boot.len;
5142 rc = iwl4965_verify_inst_sparse(priv, image, len);
5144 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5148 /* Try initialize */
5149 image = (__le32 *)priv->ucode_init.v_addr;
5150 len = priv->ucode_init.len;
5151 rc = iwl4965_verify_inst_sparse(priv, image, len);
5153 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5157 /* Try runtime/protocol */
5158 image = (__le32 *)priv->ucode_code.v_addr;
5159 len = priv->ucode_code.len;
5160 rc = iwl4965_verify_inst_sparse(priv, image, len);
5162 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5166 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5168 /* Since nothing seems to match, show first several data entries in
5169 * instruction SRAM, so maybe visual inspection will give a clue.
5170 * Selection of bootstrap image (vs. other images) is arbitrary. */
5171 image = (__le32 *)priv->ucode_boot.v_addr;
5172 len = priv->ucode_boot.len;
5173 rc = iwl4965_verify_inst_full(priv, image, len);
5178 static void iwl4965_nic_start(struct iwl_priv *priv)
5180 /* Remove all resets to allow NIC to operate */
5181 iwl_write32(priv, CSR_RESET, 0);
5186 * iwl4965_read_ucode - Read uCode images from disk file.
5188 * Copy into buffers for card to fetch via bus-mastering
5190 static int iwl4965_read_ucode(struct iwl_priv *priv)
5192 struct iwl4965_ucode *ucode;
5194 const struct firmware *ucode_raw;
5195 const char *name = priv->cfg->fw_name;
5198 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
5200 /* Ask kernel firmware_class module to get the boot firmware off disk.
5201 * request_firmware() is synchronous, file is in memory on return. */
5202 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
5204 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5209 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5210 name, ucode_raw->size);
5212 /* Make sure that we got at least our header! */
5213 if (ucode_raw->size < sizeof(*ucode)) {
5214 IWL_ERROR("File size way too small!\n");
5219 /* Data from ucode file: header followed by uCode images */
5220 ucode = (void *)ucode_raw->data;
5222 ver = le32_to_cpu(ucode->ver);
5223 inst_size = le32_to_cpu(ucode->inst_size);
5224 data_size = le32_to_cpu(ucode->data_size);
5225 init_size = le32_to_cpu(ucode->init_size);
5226 init_data_size = le32_to_cpu(ucode->init_data_size);
5227 boot_size = le32_to_cpu(ucode->boot_size);
5229 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
5230 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
5232 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
5234 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
5236 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
5238 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
5241 /* Verify size of file vs. image size info in file's header */
5242 if (ucode_raw->size < sizeof(*ucode) +
5243 inst_size + data_size + init_size +
5244 init_data_size + boot_size) {
5246 IWL_DEBUG_INFO("uCode file size %d too small\n",
5247 (int)ucode_raw->size);
5252 /* Verify that uCode images will fit in card's SRAM */
5253 if (inst_size > IWL_MAX_INST_SIZE) {
5254 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5260 if (data_size > IWL_MAX_DATA_SIZE) {
5261 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5266 if (init_size > IWL_MAX_INST_SIZE) {
5268 ("uCode init instr len %d too large to fit in\n",
5273 if (init_data_size > IWL_MAX_DATA_SIZE) {
5275 ("uCode init data len %d too large to fit in\n",
5280 if (boot_size > IWL_MAX_BSM_SIZE) {
5282 ("uCode boot instr len %d too large to fit in\n",
5288 /* Allocate ucode buffers for card's bus-master loading ... */
5290 /* Runtime instructions and 2 copies of data:
5291 * 1) unmodified from disk
5292 * 2) backup cache for save/restore during power-downs */
5293 priv->ucode_code.len = inst_size;
5294 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
5296 priv->ucode_data.len = data_size;
5297 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
5299 priv->ucode_data_backup.len = data_size;
5300 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
5302 /* Initialization instructions and data */
5303 if (init_size && init_data_size) {
5304 priv->ucode_init.len = init_size;
5305 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
5307 priv->ucode_init_data.len = init_data_size;
5308 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
5310 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
5314 /* Bootstrap (instructions only, no data) */
5316 priv->ucode_boot.len = boot_size;
5317 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
5319 if (!priv->ucode_boot.v_addr)
5323 /* Copy images into buffers for card's bus-master reads ... */
5325 /* Runtime instructions (first block of data in file) */
5326 src = &ucode->data[0];
5327 len = priv->ucode_code.len;
5328 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
5329 memcpy(priv->ucode_code.v_addr, src, len);
5330 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5331 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
5333 /* Runtime data (2nd block)
5334 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
5335 src = &ucode->data[inst_size];
5336 len = priv->ucode_data.len;
5337 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
5338 memcpy(priv->ucode_data.v_addr, src, len);
5339 memcpy(priv->ucode_data_backup.v_addr, src, len);
5341 /* Initialization instructions (3rd block) */
5343 src = &ucode->data[inst_size + data_size];
5344 len = priv->ucode_init.len;
5345 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5347 memcpy(priv->ucode_init.v_addr, src, len);
5350 /* Initialization data (4th block) */
5351 if (init_data_size) {
5352 src = &ucode->data[inst_size + data_size + init_size];
5353 len = priv->ucode_init_data.len;
5354 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
5356 memcpy(priv->ucode_init_data.v_addr, src, len);
5359 /* Bootstrap instructions (5th block) */
5360 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
5361 len = priv->ucode_boot.len;
5362 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
5363 memcpy(priv->ucode_boot.v_addr, src, len);
5365 /* We have our copies now, allow OS release its copies */
5366 release_firmware(ucode_raw);
5370 IWL_ERROR("failed to allocate pci memory\n");
5372 iwl4965_dealloc_ucode_pci(priv);
5375 release_firmware(ucode_raw);
5383 * iwl4965_set_ucode_ptrs - Set uCode address location
5385 * Tell initialization uCode where to find runtime uCode.
5387 * BSM registers initially contain pointers to initialization uCode.
5388 * We need to replace them to load runtime uCode inst and data,
5389 * and to save runtime data when powering down.
5391 static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
5396 unsigned long flags;
5398 /* bits 35:4 for 4965 */
5399 pinst = priv->ucode_code.p_addr >> 4;
5400 pdata = priv->ucode_data_backup.p_addr >> 4;
5402 spin_lock_irqsave(&priv->lock, flags);
5403 rc = iwl_grab_nic_access(priv);
5405 spin_unlock_irqrestore(&priv->lock, flags);
5409 /* Tell bootstrap uCode where to find image to load */
5410 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
5411 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
5412 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
5413 priv->ucode_data.len);
5415 /* Inst bytecount must be last to set up, bit 31 signals uCode
5416 * that all new ptr/size info is in place */
5417 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
5418 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
5420 iwl_release_nic_access(priv);
5422 spin_unlock_irqrestore(&priv->lock, flags);
5424 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5430 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
5432 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5434 * The 4965 "initialize" ALIVE reply contains calibration data for:
5435 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
5436 * (3945 does not contain this data).
5438 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5440 static void iwl4965_init_alive_start(struct iwl_priv *priv)
5442 /* Check alive response for "valid" sign from uCode */
5443 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
5444 /* We had an error bringing up the hardware, so take it
5445 * all the way back down so we can try again */
5446 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5450 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5451 * This is a paranoid check, because we would not have gotten the
5452 * "initialize" alive if code weren't properly loaded. */
5453 if (iwl4965_verify_ucode(priv)) {
5454 /* Runtime instruction load was bad;
5455 * take it all the way back down so we can try again */
5456 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5460 /* Calculate temperature */
5461 priv->temperature = iwl4965_get_temperature(priv);
5463 /* Send pointers to protocol/runtime uCode image ... init code will
5464 * load and launch runtime uCode, which will send us another "Alive"
5466 IWL_DEBUG_INFO("Initialization Alive received.\n");
5467 if (iwl4965_set_ucode_ptrs(priv)) {
5468 /* Runtime instruction load won't happen;
5469 * take it all the way back down so we can try again */
5470 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5476 queue_work(priv->workqueue, &priv->restart);
5481 * iwl4965_alive_start - called after REPLY_ALIVE notification received
5482 * from protocol/runtime uCode (initialization uCode's
5483 * Alive gets handled by iwl4965_init_alive_start()).
5485 static void iwl4965_alive_start(struct iwl_priv *priv)
5489 IWL_DEBUG_INFO("Runtime Alive received.\n");
5491 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
5492 /* We had an error bringing up the hardware, so take it
5493 * all the way back down so we can try again */
5494 IWL_DEBUG_INFO("Alive failed.\n");
5498 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5499 * This is a paranoid check, because we would not have gotten the
5500 * "runtime" alive if code weren't properly loaded. */
5501 if (iwl4965_verify_ucode(priv)) {
5502 /* Runtime instruction load was bad;
5503 * take it all the way back down so we can try again */
5504 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5508 iwlcore_clear_stations_table(priv);
5510 ret = priv->cfg->ops->lib->alive_notify(priv);
5512 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
5517 /* After the ALIVE response, we can send host commands to 4965 uCode */
5518 set_bit(STATUS_ALIVE, &priv->status);
5520 /* Clear out the uCode error bit if it is set */
5521 clear_bit(STATUS_FW_ERROR, &priv->status);
5523 if (iwl_is_rfkill(priv))
5526 ieee80211_start_queues(priv->hw);
5528 priv->active_rate = priv->rates_mask;
5529 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
5531 iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
5533 if (iwl_is_associated(priv)) {
5534 struct iwl4965_rxon_cmd *active_rxon =
5535 (struct iwl4965_rxon_cmd *)(&priv->active_rxon);
5537 memcpy(&priv->staging_rxon, &priv->active_rxon,
5538 sizeof(priv->staging_rxon));
5539 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
5541 /* Initialize our rx_config data */
5542 iwl4965_connection_init_rx_config(priv);
5543 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
5546 /* Configure Bluetooth device coexistence support */
5547 iwl4965_send_bt_config(priv);
5549 /* Configure the adapter for unassociated operation */
5550 iwl4965_commit_rxon(priv);
5552 /* At this point, the NIC is initialized and operational */
5553 priv->notif_missed_beacons = 0;
5555 iwl4965_rf_kill_ct_config(priv);
5557 iwl_leds_register(priv);
5559 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5560 set_bit(STATUS_READY, &priv->status);
5561 wake_up_interruptible(&priv->wait_command_queue);
5563 if (priv->error_recovering)
5564 iwl4965_error_recovery(priv);
5566 iwlcore_low_level_notify(priv, IWLCORE_START_EVT);
5567 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
5571 queue_work(priv->workqueue, &priv->restart);
5574 static void iwl4965_cancel_deferred_work(struct iwl_priv *priv);
5576 static void __iwl4965_down(struct iwl_priv *priv)
5578 unsigned long flags;
5579 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
5580 struct ieee80211_conf *conf = NULL;
5582 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
5584 conf = ieee80211_get_hw_conf(priv->hw);
5587 set_bit(STATUS_EXIT_PENDING, &priv->status);
5589 iwl_leds_unregister(priv);
5591 iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT);
5593 iwlcore_clear_stations_table(priv);
5595 /* Unblock any waiting calls */
5596 wake_up_interruptible_all(&priv->wait_command_queue);
5598 /* Wipe out the EXIT_PENDING status bit if we are not actually
5599 * exiting the module */
5601 clear_bit(STATUS_EXIT_PENDING, &priv->status);
5603 /* stop and reset the on-board processor */
5604 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
5606 /* tell the device to stop sending interrupts */
5607 spin_lock_irqsave(&priv->lock, flags);
5608 iwl4965_disable_interrupts(priv);
5609 spin_unlock_irqrestore(&priv->lock, flags);
5610 iwl_synchronize_irq(priv);
5612 if (priv->mac80211_registered)
5613 ieee80211_stop_queues(priv->hw);
5615 /* If we have not previously called iwl4965_init() then
5616 * clear all bits but the RF Kill and SUSPEND bits and return */
5617 if (!iwl_is_init(priv)) {
5618 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
5620 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
5622 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
5623 STATUS_GEO_CONFIGURED |
5624 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5629 /* ...otherwise clear out all the status bits but the RF Kill and
5630 * SUSPEND bits and continue taking the NIC down. */
5631 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
5633 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
5635 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
5636 STATUS_GEO_CONFIGURED |
5637 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5639 test_bit(STATUS_FW_ERROR, &priv->status) <<
5642 spin_lock_irqsave(&priv->lock, flags);
5643 iwl_clear_bit(priv, CSR_GP_CNTRL,
5644 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
5645 spin_unlock_irqrestore(&priv->lock, flags);
5647 iwl4965_hw_txq_ctx_stop(priv);
5648 iwl4965_hw_rxq_stop(priv);
5650 spin_lock_irqsave(&priv->lock, flags);
5651 if (!iwl_grab_nic_access(priv)) {
5652 iwl_write_prph(priv, APMG_CLK_DIS_REG,
5653 APMG_CLK_VAL_DMA_CLK_RQT);
5654 iwl_release_nic_access(priv);
5656 spin_unlock_irqrestore(&priv->lock, flags);
5660 iwl4965_hw_nic_stop_master(priv);
5661 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
5662 iwl4965_hw_nic_reset(priv);
5665 memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp));
5667 if (priv->ibss_beacon)
5668 dev_kfree_skb(priv->ibss_beacon);
5669 priv->ibss_beacon = NULL;
5671 /* clear out any free frames */
5672 iwl4965_clear_free_frames(priv);
5675 static void iwl4965_down(struct iwl_priv *priv)
5677 mutex_lock(&priv->mutex);
5678 __iwl4965_down(priv);
5679 mutex_unlock(&priv->mutex);
5681 iwl4965_cancel_deferred_work(priv);
5684 #define MAX_HW_RESTARTS 5
5686 static int __iwl4965_up(struct iwl_priv *priv)
5691 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
5692 IWL_WARNING("Exit pending; will not bring the NIC up\n");
5696 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
5697 IWL_WARNING("Radio disabled by SW RF kill (module "
5699 iwl_rfkill_set_hw_state(priv);
5703 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
5704 IWL_ERROR("ucode not available for device bringup\n");
5708 /* If platform's RF_KILL switch is NOT set to KILL */
5709 if (iwl_read32(priv, CSR_GP_CNTRL) &
5710 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
5711 clear_bit(STATUS_RF_KILL_HW, &priv->status);
5713 set_bit(STATUS_RF_KILL_HW, &priv->status);
5714 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
5715 iwl_rfkill_set_hw_state(priv);
5716 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
5721 iwl_rfkill_set_hw_state(priv);
5722 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
5724 ret = priv->cfg->ops->lib->hw_nic_init(priv);
5726 IWL_ERROR("Unable to init nic\n");
5730 /* make sure rfkill handshake bits are cleared */
5731 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
5732 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
5733 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
5735 /* clear (again), then enable host interrupts */
5736 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
5737 iwl4965_enable_interrupts(priv);
5739 /* really make sure rfkill handshake bits are cleared */
5740 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
5741 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
5743 /* Copy original ucode data image from disk into backup cache.
5744 * This will be used to initialize the on-board processor's
5745 * data SRAM for a clean start when the runtime program first loads. */
5746 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
5747 priv->ucode_data.len);
5749 /* We return success when we resume from suspend and rf_kill is on. */
5750 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
5753 for (i = 0; i < MAX_HW_RESTARTS; i++) {
5755 iwlcore_clear_stations_table(priv);
5757 /* load bootstrap state machine,
5758 * load bootstrap program into processor's memory,
5759 * prepare to load the "initialize" uCode */
5760 ret = priv->cfg->ops->lib->load_ucode(priv);
5763 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
5767 /* start card; "initialize" will load runtime ucode */
5768 iwl4965_nic_start(priv);
5770 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
5775 set_bit(STATUS_EXIT_PENDING, &priv->status);
5776 __iwl4965_down(priv);
5778 /* tried to restart and config the device for as long as our
5779 * patience could withstand */
5780 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
5785 /*****************************************************************************
5787 * Workqueue callbacks
5789 *****************************************************************************/
5791 static void iwl4965_bg_init_alive_start(struct work_struct *data)
5793 struct iwl_priv *priv =
5794 container_of(data, struct iwl_priv, init_alive_start.work);
5796 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5799 mutex_lock(&priv->mutex);
5800 iwl4965_init_alive_start(priv);
5801 mutex_unlock(&priv->mutex);
5804 static void iwl4965_bg_alive_start(struct work_struct *data)
5806 struct iwl_priv *priv =
5807 container_of(data, struct iwl_priv, alive_start.work);
5809 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5812 mutex_lock(&priv->mutex);
5813 iwl4965_alive_start(priv);
5814 mutex_unlock(&priv->mutex);
5817 static void iwl4965_bg_rf_kill(struct work_struct *work)
5819 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
5821 wake_up_interruptible(&priv->wait_command_queue);
5823 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5826 mutex_lock(&priv->mutex);
5828 if (!iwl_is_rfkill(priv)) {
5829 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
5830 "HW and/or SW RF Kill no longer active, restarting "
5832 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
5833 queue_work(priv->workqueue, &priv->restart);
5835 /* make sure mac80211 stop sending Tx frame */
5836 if (priv->mac80211_registered)
5837 ieee80211_stop_queues(priv->hw);
5839 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
5840 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
5841 "disabled by SW switch\n");
5843 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
5844 "Kill switch must be turned off for "
5845 "wireless networking to work.\n");
5847 iwl_rfkill_set_hw_state(priv);
5849 mutex_unlock(&priv->mutex);
5852 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
5854 static void iwl4965_bg_scan_check(struct work_struct *data)
5856 struct iwl_priv *priv =
5857 container_of(data, struct iwl_priv, scan_check.work);
5859 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5862 mutex_lock(&priv->mutex);
5863 if (test_bit(STATUS_SCANNING, &priv->status) ||
5864 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
5865 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
5866 "Scan completion watchdog resetting adapter (%dms)\n",
5867 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
5869 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
5870 iwl4965_send_scan_abort(priv);
5872 mutex_unlock(&priv->mutex);
5875 static void iwl4965_bg_request_scan(struct work_struct *data)
5877 struct iwl_priv *priv =
5878 container_of(data, struct iwl_priv, request_scan);
5879 struct iwl_host_cmd cmd = {
5880 .id = REPLY_SCAN_CMD,
5881 .len = sizeof(struct iwl4965_scan_cmd),
5882 .meta.flags = CMD_SIZE_HUGE,
5884 struct iwl4965_scan_cmd *scan;
5885 struct ieee80211_conf *conf = NULL;
5887 enum ieee80211_band band;
5891 conf = ieee80211_get_hw_conf(priv->hw);
5893 mutex_lock(&priv->mutex);
5895 if (!iwl_is_ready(priv)) {
5896 IWL_WARNING("request scan called when driver not ready.\n");
5900 /* Make sure the scan wasn't cancelled before this queued work
5901 * was given the chance to run... */
5902 if (!test_bit(STATUS_SCANNING, &priv->status))
5905 /* This should never be called or scheduled if there is currently
5906 * a scan active in the hardware. */
5907 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
5908 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
5909 "Ignoring second request.\n");
5914 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
5915 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5919 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
5920 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5924 if (iwl_is_rfkill(priv)) {
5925 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5929 if (!test_bit(STATUS_READY, &priv->status)) {
5930 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
5934 if (!priv->scan_bands) {
5935 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
5940 priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
5941 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
5948 memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
5950 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
5951 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
5953 if (iwl_is_associated(priv)) {
5956 u32 suspend_time = 100;
5957 u32 scan_suspend_time = 100;
5958 unsigned long flags;
5960 IWL_DEBUG_INFO("Scanning while associated...\n");
5962 spin_lock_irqsave(&priv->lock, flags);
5963 interval = priv->beacon_int;
5964 spin_unlock_irqrestore(&priv->lock, flags);
5966 scan->suspend_time = 0;
5967 scan->max_out_time = cpu_to_le32(200 * 1024);
5969 interval = suspend_time;
5971 extra = (suspend_time / interval) << 22;
5972 scan_suspend_time = (extra |
5973 ((suspend_time % interval) * 1024));
5974 scan->suspend_time = cpu_to_le32(scan_suspend_time);
5975 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
5976 scan_suspend_time, interval);
5979 /* We should add the ability for user to lock to PASSIVE ONLY */
5980 if (priv->one_direct_scan) {
5982 ("Kicking off one direct scan for '%s'\n",
5983 iwl4965_escape_essid(priv->direct_ssid,
5984 priv->direct_ssid_len));
5985 scan->direct_scan[0].id = WLAN_EID_SSID;
5986 scan->direct_scan[0].len = priv->direct_ssid_len;
5987 memcpy(scan->direct_scan[0].ssid,
5988 priv->direct_ssid, priv->direct_ssid_len);
5990 } else if (!iwl_is_associated(priv) && priv->essid_len) {
5991 scan->direct_scan[0].id = WLAN_EID_SSID;
5992 scan->direct_scan[0].len = priv->essid_len;
5993 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
5999 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
6000 scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
6001 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
6004 switch (priv->scan_bands) {
6006 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
6007 scan->tx_cmd.rate_n_flags =
6008 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
6009 RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
6011 scan->good_CRC_th = 0;
6012 band = IEEE80211_BAND_2GHZ;
6016 scan->tx_cmd.rate_n_flags =
6017 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
6018 RATE_MCS_ANT_B_MSK);
6019 scan->good_CRC_th = IWL_GOOD_CRC_TH;
6020 band = IEEE80211_BAND_5GHZ;
6024 IWL_WARNING("Invalid scan band count\n");
6028 /* We don't build a direct scan probe request; the uCode will do
6029 * that based on the direct_mask added to each channel entry */
6030 cmd_len = iwl4965_fill_probe_req(priv, band,
6031 (struct ieee80211_mgmt *)scan->data,
6032 IWL_MAX_SCAN_SIZE - sizeof(*scan), 0);
6034 scan->tx_cmd.len = cpu_to_le16(cmd_len);
6035 /* select Rx chains */
6037 /* Force use of chains B and C (0x6) for scan Rx.
6038 * Avoid A (0x1) because of its off-channel reception on A-band.
6039 * MIMO is not used here, but value is required to make uCode happy. */
6040 scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
6041 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
6042 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
6043 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
6045 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
6046 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
6050 ("Initiating direct scan for %s.\n",
6051 iwl4965_escape_essid(priv->essid, priv->essid_len));
6052 scan->channel_count =
6053 iwl4965_get_channels_for_scan(
6054 priv, band, 1, /* active */
6056 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6058 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
6059 scan->channel_count =
6060 iwl4965_get_channels_for_scan(
6061 priv, band, 0, /* passive */
6063 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6066 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
6067 scan->channel_count * sizeof(struct iwl4965_scan_channel);
6069 scan->len = cpu_to_le16(cmd.len);
6071 set_bit(STATUS_SCAN_HW, &priv->status);
6072 ret = iwl_send_cmd_sync(priv, &cmd);
6076 queue_delayed_work(priv->workqueue, &priv->scan_check,
6077 IWL_SCAN_CHECK_WATCHDOG);
6079 mutex_unlock(&priv->mutex);
6083 /* inform mac80211 scan aborted */
6084 queue_work(priv->workqueue, &priv->scan_completed);
6085 mutex_unlock(&priv->mutex);
6088 static void iwl4965_bg_up(struct work_struct *data)
6090 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
6092 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6095 mutex_lock(&priv->mutex);
6097 mutex_unlock(&priv->mutex);
6100 static void iwl4965_bg_restart(struct work_struct *data)
6102 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
6104 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6108 queue_work(priv->workqueue, &priv->up);
6111 static void iwl4965_bg_rx_replenish(struct work_struct *data)
6113 struct iwl_priv *priv =
6114 container_of(data, struct iwl_priv, rx_replenish);
6116 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6119 mutex_lock(&priv->mutex);
6120 iwl4965_rx_replenish(priv);
6121 mutex_unlock(&priv->mutex);
6124 #define IWL_DELAY_NEXT_SCAN (HZ*2)
6126 static void iwl4965_bg_post_associate(struct work_struct *data)
6128 struct iwl_priv *priv = container_of(data, struct iwl_priv,
6129 post_associate.work);
6130 struct ieee80211_conf *conf = NULL;
6132 DECLARE_MAC_BUF(mac);
6134 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
6135 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
6139 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
6141 print_mac(mac, priv->active_rxon.bssid_addr));
6144 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6147 mutex_lock(&priv->mutex);
6149 if (!priv->vif || !priv->is_open) {
6150 mutex_unlock(&priv->mutex);
6153 iwl4965_scan_cancel_timeout(priv, 200);
6155 conf = ieee80211_get_hw_conf(priv->hw);
6157 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6158 iwl4965_commit_rxon(priv);
6160 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
6161 iwl4965_setup_rxon_timing(priv);
6162 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
6163 sizeof(priv->rxon_timing), &priv->rxon_timing);
6165 IWL_WARNING("REPLY_RXON_TIMING failed - "
6166 "Attempting to continue.\n");
6168 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
6170 #ifdef CONFIG_IWL4965_HT
6171 if (priv->current_ht_config.is_ht)
6172 iwl4965_set_rxon_ht(priv, &priv->current_ht_config);
6173 #endif /* CONFIG_IWL4965_HT*/
6174 iwl4965_set_rxon_chain(priv);
6175 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
6177 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6178 priv->assoc_id, priv->beacon_int);
6180 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6181 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
6183 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
6185 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
6186 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
6187 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
6189 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6191 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6192 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6196 iwl4965_commit_rxon(priv);
6198 switch (priv->iw_mode) {
6199 case IEEE80211_IF_TYPE_STA:
6200 iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
6203 case IEEE80211_IF_TYPE_IBSS:
6205 /* clear out the station table */
6206 iwlcore_clear_stations_table(priv);
6208 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
6209 iwl4965_rxon_add_station(priv, priv->bssid, 0);
6210 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
6211 iwl4965_send_beacon_cmd(priv);
6216 IWL_ERROR("%s Should not be called in %d mode\n",
6217 __FUNCTION__, priv->iw_mode);
6221 iwl4965_sequence_reset(priv);
6223 #ifdef CONFIG_IWL4965_SENSITIVITY
6224 /* Enable Rx differential gain and sensitivity calibrations */
6225 iwl4965_chain_noise_reset(priv);
6226 priv->start_calib = 1;
6227 #endif /* CONFIG_IWL4965_SENSITIVITY */
6229 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6230 priv->assoc_station_added = 1;
6232 iwl4965_activate_qos(priv, 0);
6234 /* we have just associated, don't start scan too early */
6235 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
6236 mutex_unlock(&priv->mutex);
6239 static void iwl4965_bg_abort_scan(struct work_struct *work)
6241 struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
6243 if (!iwl_is_ready(priv))
6246 mutex_lock(&priv->mutex);
6248 set_bit(STATUS_SCAN_ABORTING, &priv->status);
6249 iwl4965_send_scan_abort(priv);
6251 mutex_unlock(&priv->mutex);
6254 static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
6256 static void iwl4965_bg_scan_completed(struct work_struct *work)
6258 struct iwl_priv *priv =
6259 container_of(work, struct iwl_priv, scan_completed);
6261 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
6263 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6266 if (test_bit(STATUS_CONF_PENDING, &priv->status))
6267 iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
6269 ieee80211_scan_completed(priv->hw);
6271 /* Since setting the TXPOWER may have been deferred while
6272 * performing the scan, fire one off */
6273 mutex_lock(&priv->mutex);
6274 iwl4965_hw_reg_send_txpower(priv);
6275 mutex_unlock(&priv->mutex);
6278 /*****************************************************************************
6280 * mac80211 entry point functions
6282 *****************************************************************************/
6284 #define UCODE_READY_TIMEOUT (2 * HZ)
6286 static int iwl4965_mac_start(struct ieee80211_hw *hw)
6288 struct iwl_priv *priv = hw->priv;
6291 IWL_DEBUG_MAC80211("enter\n");
6293 if (pci_enable_device(priv->pci_dev)) {
6294 IWL_ERROR("Fail to pci_enable_device\n");
6297 pci_restore_state(priv->pci_dev);
6298 pci_enable_msi(priv->pci_dev);
6300 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
6303 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
6304 goto out_disable_msi;
6307 /* we should be verifying the device is ready to be opened */
6308 mutex_lock(&priv->mutex);
6310 memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd));
6311 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6312 * ucode filename and max sizes are card-specific. */
6314 if (!priv->ucode_code.len) {
6315 ret = iwl4965_read_ucode(priv);
6317 IWL_ERROR("Could not read microcode: %d\n", ret);
6318 mutex_unlock(&priv->mutex);
6319 goto out_release_irq;
6323 ret = __iwl4965_up(priv);
6325 mutex_unlock(&priv->mutex);
6328 goto out_release_irq;
6330 IWL_DEBUG_INFO("Start UP work done.\n");
6332 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
6335 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6336 * mac80211 will not be run successfully. */
6337 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
6338 test_bit(STATUS_READY, &priv->status),
6339 UCODE_READY_TIMEOUT);
6341 if (!test_bit(STATUS_READY, &priv->status)) {
6342 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
6343 jiffies_to_msecs(UCODE_READY_TIMEOUT));
6345 goto out_release_irq;
6350 IWL_DEBUG_MAC80211("leave\n");
6354 free_irq(priv->pci_dev->irq, priv);
6356 pci_disable_msi(priv->pci_dev);
6357 pci_disable_device(priv->pci_dev);
6359 IWL_DEBUG_MAC80211("leave - failed\n");
6363 static void iwl4965_mac_stop(struct ieee80211_hw *hw)
6365 struct iwl_priv *priv = hw->priv;
6367 IWL_DEBUG_MAC80211("enter\n");
6369 if (!priv->is_open) {
6370 IWL_DEBUG_MAC80211("leave - skip\n");
6376 if (iwl_is_ready_rf(priv)) {
6377 /* stop mac, cancel any scan request and clear
6378 * RXON_FILTER_ASSOC_MSK BIT
6380 mutex_lock(&priv->mutex);
6381 iwl4965_scan_cancel_timeout(priv, 100);
6382 cancel_delayed_work(&priv->post_associate);
6383 mutex_unlock(&priv->mutex);
6388 flush_workqueue(priv->workqueue);
6389 free_irq(priv->pci_dev->irq, priv);
6390 pci_disable_msi(priv->pci_dev);
6391 pci_save_state(priv->pci_dev);
6392 pci_disable_device(priv->pci_dev);
6394 IWL_DEBUG_MAC80211("leave\n");
6397 static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
6398 struct ieee80211_tx_control *ctl)
6400 struct iwl_priv *priv = hw->priv;
6402 IWL_DEBUG_MAC80211("enter\n");
6404 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
6405 IWL_DEBUG_MAC80211("leave - monitor\n");
6409 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
6410 ctl->tx_rate->bitrate);
6412 if (iwl4965_tx_skb(priv, skb, ctl))
6413 dev_kfree_skb_any(skb);
6415 IWL_DEBUG_MAC80211("leave\n");
6419 static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
6420 struct ieee80211_if_init_conf *conf)
6422 struct iwl_priv *priv = hw->priv;
6423 unsigned long flags;
6424 DECLARE_MAC_BUF(mac);
6426 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
6429 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6433 spin_lock_irqsave(&priv->lock, flags);
6434 priv->vif = conf->vif;
6436 spin_unlock_irqrestore(&priv->lock, flags);
6438 mutex_lock(&priv->mutex);
6440 if (conf->mac_addr) {
6441 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
6442 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
6445 if (iwl_is_ready(priv))
6446 iwl4965_set_mode(priv, conf->type);
6448 mutex_unlock(&priv->mutex);
6450 IWL_DEBUG_MAC80211("leave\n");
6455 * iwl4965_mac_config - mac80211 config callback
6457 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6458 * be set inappropriately and the driver currently sets the hardware up to
6459 * use it whenever needed.
6461 static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
6463 struct iwl_priv *priv = hw->priv;
6464 const struct iwl_channel_info *ch_info;
6465 unsigned long flags;
6468 mutex_lock(&priv->mutex);
6469 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
6471 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
6473 if (!iwl_is_ready(priv)) {
6474 IWL_DEBUG_MAC80211("leave - not ready\n");
6479 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
6480 test_bit(STATUS_SCANNING, &priv->status))) {
6481 IWL_DEBUG_MAC80211("leave - scanning\n");
6482 set_bit(STATUS_CONF_PENDING, &priv->status);
6483 mutex_unlock(&priv->mutex);
6487 spin_lock_irqsave(&priv->lock, flags);
6489 ch_info = iwl_get_channel_info(priv, conf->channel->band,
6490 ieee80211_frequency_to_channel(conf->channel->center_freq));
6491 if (!is_channel_valid(ch_info)) {
6492 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6493 spin_unlock_irqrestore(&priv->lock, flags);
6498 #ifdef CONFIG_IWL4965_HT
6499 /* if we are switching from ht to 2.4 clear flags
6500 * from any ht related info since 2.4 does not
6502 if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value)
6503 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6504 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
6507 priv->staging_rxon.flags = 0;
6508 #endif /* CONFIG_IWL4965_HT */
6510 iwlcore_set_rxon_channel(priv, conf->channel->band,
6511 ieee80211_frequency_to_channel(conf->channel->center_freq));
6513 iwl4965_set_flags_for_phymode(priv, conf->channel->band);
6515 /* The list of supported rates and rate mask can be different
6516 * for each band; since the band may have changed, reset
6517 * the rate mask to what mac80211 lists */
6518 iwl4965_set_rate(priv);
6520 spin_unlock_irqrestore(&priv->lock, flags);
6522 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6523 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
6524 iwl4965_hw_channel_switch(priv, conf->channel);
6529 if (priv->cfg->ops->lib->radio_kill_sw)
6530 priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled);
6532 if (!conf->radio_enabled) {
6533 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6537 if (iwl_is_rfkill(priv)) {
6538 IWL_DEBUG_MAC80211("leave - RF kill\n");
6543 iwl4965_set_rate(priv);
6545 if (memcmp(&priv->active_rxon,
6546 &priv->staging_rxon, sizeof(priv->staging_rxon)))
6547 iwl4965_commit_rxon(priv);
6549 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6551 IWL_DEBUG_MAC80211("leave\n");
6554 clear_bit(STATUS_CONF_PENDING, &priv->status);
6555 mutex_unlock(&priv->mutex);
6559 static void iwl4965_config_ap(struct iwl_priv *priv)
6563 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6566 /* The following should be done only at AP bring up */
6567 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
6569 /* RXON - unassoc (to set timing command) */
6570 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6571 iwl4965_commit_rxon(priv);
6574 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
6575 iwl4965_setup_rxon_timing(priv);
6576 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
6577 sizeof(priv->rxon_timing), &priv->rxon_timing);
6579 IWL_WARNING("REPLY_RXON_TIMING failed - "
6580 "Attempting to continue.\n");
6582 iwl4965_set_rxon_chain(priv);
6584 /* FIXME: what should be the assoc_id for AP? */
6585 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
6586 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6587 priv->staging_rxon.flags |=
6588 RXON_FLG_SHORT_PREAMBLE_MSK;
6590 priv->staging_rxon.flags &=
6591 ~RXON_FLG_SHORT_PREAMBLE_MSK;
6593 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
6594 if (priv->assoc_capability &
6595 WLAN_CAPABILITY_SHORT_SLOT_TIME)
6596 priv->staging_rxon.flags |=
6597 RXON_FLG_SHORT_SLOT_MSK;
6599 priv->staging_rxon.flags &=
6600 ~RXON_FLG_SHORT_SLOT_MSK;
6602 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6603 priv->staging_rxon.flags &=
6604 ~RXON_FLG_SHORT_SLOT_MSK;
6606 /* restore RXON assoc */
6607 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
6608 iwl4965_commit_rxon(priv);
6609 iwl4965_activate_qos(priv, 1);
6610 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
6612 iwl4965_send_beacon_cmd(priv);
6614 /* FIXME - we need to add code here to detect a totally new
6615 * configuration, reset the AP, unassoc, rxon timing, assoc,
6616 * clear sta table, add BCAST sta... */
6619 static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
6620 struct ieee80211_vif *vif,
6621 struct ieee80211_if_conf *conf)
6623 struct iwl_priv *priv = hw->priv;
6624 DECLARE_MAC_BUF(mac);
6625 unsigned long flags;
6631 if (priv->vif != vif) {
6632 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6633 mutex_unlock(&priv->mutex);
6637 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
6638 (!conf->beacon || !conf->ssid_len)) {
6640 ("Leaving in AP mode because HostAPD is not ready.\n");
6644 if (!iwl_is_alive(priv))
6647 mutex_lock(&priv->mutex);
6650 IWL_DEBUG_MAC80211("bssid: %s\n",
6651 print_mac(mac, conf->bssid));
6654 * very dubious code was here; the probe filtering flag is never set:
6656 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6657 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6660 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
6662 conf->bssid = priv->mac_addr;
6663 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
6664 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
6665 print_mac(mac, conf->bssid));
6667 if (priv->ibss_beacon)
6668 dev_kfree_skb(priv->ibss_beacon);
6670 priv->ibss_beacon = conf->beacon;
6673 if (iwl_is_rfkill(priv))
6676 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
6677 !is_multicast_ether_addr(conf->bssid)) {
6678 /* If there is currently a HW scan going on in the background
6679 * then we need to cancel it else the RXON below will fail. */
6680 if (iwl4965_scan_cancel_timeout(priv, 100)) {
6681 IWL_WARNING("Aborted scan still in progress "
6683 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6684 mutex_unlock(&priv->mutex);
6687 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
6689 /* TODO: Audit driver for usage of these members and see
6690 * if mac80211 deprecates them (priv->bssid looks like it
6691 * shouldn't be there, but I haven't scanned the IBSS code
6692 * to verify) - jpk */
6693 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
6695 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
6696 iwl4965_config_ap(priv);
6698 rc = iwl4965_commit_rxon(priv);
6699 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
6700 iwl4965_rxon_add_station(
6701 priv, priv->active_rxon.bssid_addr, 1);
6705 iwl4965_scan_cancel_timeout(priv, 100);
6706 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6707 iwl4965_commit_rxon(priv);
6711 spin_lock_irqsave(&priv->lock, flags);
6712 if (!conf->ssid_len)
6713 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
6715 memcpy(priv->essid, conf->ssid, conf->ssid_len);
6717 priv->essid_len = conf->ssid_len;
6718 spin_unlock_irqrestore(&priv->lock, flags);
6720 IWL_DEBUG_MAC80211("leave\n");
6721 mutex_unlock(&priv->mutex);
6726 static void iwl4965_configure_filter(struct ieee80211_hw *hw,
6727 unsigned int changed_flags,
6728 unsigned int *total_flags,
6729 int mc_count, struct dev_addr_list *mc_list)
6733 * see also iwl4965_connection_init_rx_config
6738 static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
6739 struct ieee80211_if_init_conf *conf)
6741 struct iwl_priv *priv = hw->priv;
6743 IWL_DEBUG_MAC80211("enter\n");
6745 mutex_lock(&priv->mutex);
6747 if (iwl_is_ready_rf(priv)) {
6748 iwl4965_scan_cancel_timeout(priv, 100);
6749 cancel_delayed_work(&priv->post_associate);
6750 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6751 iwl4965_commit_rxon(priv);
6753 if (priv->vif == conf->vif) {
6755 memset(priv->bssid, 0, ETH_ALEN);
6756 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
6757 priv->essid_len = 0;
6759 mutex_unlock(&priv->mutex);
6761 IWL_DEBUG_MAC80211("leave\n");
6766 #ifdef CONFIG_IWL4965_HT
6767 static void iwl4965_ht_conf(struct iwl_priv *priv,
6768 struct ieee80211_bss_conf *bss_conf)
6770 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
6771 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
6772 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
6774 IWL_DEBUG_MAC80211("enter: \n");
6776 iwl_conf->is_ht = bss_conf->assoc_ht;
6778 if (!iwl_conf->is_ht)
6781 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
6783 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
6784 iwl_conf->sgf |= 0x1;
6785 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
6786 iwl_conf->sgf |= 0x2;
6788 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
6789 iwl_conf->max_amsdu_size =
6790 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
6792 iwl_conf->supported_chan_width =
6793 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
6794 iwl_conf->extension_chan_offset =
6795 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
6796 /* If no above or below channel supplied disable FAT channel */
6797 if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
6798 iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
6799 iwl_conf->supported_chan_width = 0;
6801 iwl_conf->tx_mimo_ps_mode =
6802 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
6803 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
6805 iwl_conf->control_channel = ht_bss_conf->primary_channel;
6806 iwl_conf->tx_chan_width =
6807 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
6808 iwl_conf->ht_protection =
6809 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
6810 iwl_conf->non_GF_STA_present =
6811 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
6813 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
6814 IWL_DEBUG_MAC80211("leave\n");
6817 static inline void iwl4965_ht_conf(struct iwl_priv *priv,
6818 struct ieee80211_bss_conf *bss_conf)
6823 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6824 static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
6825 struct ieee80211_vif *vif,
6826 struct ieee80211_bss_conf *bss_conf,
6829 struct iwl_priv *priv = hw->priv;
6831 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
6833 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
6834 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
6835 bss_conf->use_short_preamble);
6836 if (bss_conf->use_short_preamble)
6837 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
6839 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
6842 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
6843 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
6844 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
6845 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
6847 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
6850 if (changes & BSS_CHANGED_HT) {
6851 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
6852 iwl4965_ht_conf(priv, bss_conf);
6853 iwl4965_set_rxon_chain(priv);
6856 if (changes & BSS_CHANGED_ASSOC) {
6857 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
6858 if (bss_conf->assoc) {
6859 priv->assoc_id = bss_conf->aid;
6860 priv->beacon_int = bss_conf->beacon_int;
6861 priv->timestamp = bss_conf->timestamp;
6862 priv->assoc_capability = bss_conf->assoc_capability;
6863 priv->next_scan_jiffies = jiffies +
6864 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
6865 queue_work(priv->workqueue, &priv->post_associate.work);
6868 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
6870 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
6871 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
6872 iwl4965_send_rxon_assoc(priv);
6877 static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
6880 unsigned long flags;
6881 struct iwl_priv *priv = hw->priv;
6883 IWL_DEBUG_MAC80211("enter\n");
6885 mutex_lock(&priv->mutex);
6886 spin_lock_irqsave(&priv->lock, flags);
6888 if (!iwl_is_ready_rf(priv)) {
6890 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6894 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
6896 IWL_ERROR("ERROR: APs don't scan\n");
6900 /* we don't schedule scan within next_scan_jiffies period */
6901 if (priv->next_scan_jiffies &&
6902 time_after(priv->next_scan_jiffies, jiffies)) {
6906 /* if we just finished scan ask for delay */
6907 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
6908 IWL_DELAY_NEXT_SCAN, jiffies)) {
6913 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6914 iwl4965_escape_essid(ssid, len), (int)len);
6916 priv->one_direct_scan = 1;
6917 priv->direct_ssid_len = (u8)
6918 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
6919 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
6921 priv->one_direct_scan = 0;
6923 rc = iwl4965_scan_initiate(priv);
6925 IWL_DEBUG_MAC80211("leave\n");
6928 spin_unlock_irqrestore(&priv->lock, flags);
6929 mutex_unlock(&priv->mutex);
6934 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
6935 struct ieee80211_key_conf *keyconf, const u8 *addr,
6936 u32 iv32, u16 *phase1key)
6938 struct iwl_priv *priv = hw->priv;
6939 u8 sta_id = IWL_INVALID_STATION;
6940 unsigned long flags;
6941 __le16 key_flags = 0;
6943 DECLARE_MAC_BUF(mac);
6945 IWL_DEBUG_MAC80211("enter\n");
6947 sta_id = iwl4965_hw_find_station(priv, addr);
6948 if (sta_id == IWL_INVALID_STATION) {
6949 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6950 print_mac(mac, addr));
6954 iwl4965_scan_cancel_timeout(priv, 100);
6956 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
6957 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
6958 key_flags &= ~STA_KEY_FLG_INVALID;
6960 if (sta_id == priv->hw_setting.bcast_sta_id)
6961 key_flags |= STA_KEY_MULTICAST_MSK;
6963 spin_lock_irqsave(&priv->sta_lock, flags);
6965 priv->stations[sta_id].sta.key.key_offset =
6966 (sta_id % STA_KEY_MAX_NUM);/* FIXME */
6967 priv->stations[sta_id].sta.key.key_flags = key_flags;
6968 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
6970 for (i = 0; i < 5; i++)
6971 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
6972 cpu_to_le16(phase1key[i]);
6974 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
6975 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
6977 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
6979 spin_unlock_irqrestore(&priv->sta_lock, flags);
6981 IWL_DEBUG_MAC80211("leave\n");
6984 static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6985 const u8 *local_addr, const u8 *addr,
6986 struct ieee80211_key_conf *key)
6988 struct iwl_priv *priv = hw->priv;
6989 DECLARE_MAC_BUF(mac);
6991 u8 sta_id = IWL_INVALID_STATION;
6994 IWL_DEBUG_MAC80211("enter\n");
6996 if (!priv->cfg->mod_params->hw_crypto) {
6997 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7001 if (is_zero_ether_addr(addr))
7002 /* only support pairwise keys */
7005 /* FIXME: need to differenciate between static and dynamic key
7006 * in the level of mac80211 */
7007 static_key = !iwl_is_associated(priv);
7010 sta_id = iwl4965_hw_find_station(priv, addr);
7011 if (sta_id == IWL_INVALID_STATION) {
7012 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7013 print_mac(mac, addr));
7018 iwl4965_scan_cancel_timeout(priv, 100);
7023 ret = iwl4965_set_static_key(priv, key);
7025 ret = iwl4965_set_dynamic_key(priv, key, sta_id);
7027 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
7031 ret = iwl4965_remove_static_key(priv);
7033 ret = iwl4965_clear_sta_key_info(priv, sta_id);
7035 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7041 IWL_DEBUG_MAC80211("leave\n");
7046 static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
7047 const struct ieee80211_tx_queue_params *params)
7049 struct iwl_priv *priv = hw->priv;
7050 unsigned long flags;
7053 IWL_DEBUG_MAC80211("enter\n");
7055 if (!iwl_is_ready_rf(priv)) {
7056 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7060 if (queue >= AC_NUM) {
7061 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
7065 if (!priv->qos_data.qos_enable) {
7066 priv->qos_data.qos_active = 0;
7067 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7070 q = AC_NUM - 1 - queue;
7072 spin_lock_irqsave(&priv->lock, flags);
7074 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
7075 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
7076 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
7077 priv->qos_data.def_qos_parm.ac[q].edca_txop =
7078 cpu_to_le16((params->txop * 32));
7080 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
7081 priv->qos_data.qos_active = 1;
7083 spin_unlock_irqrestore(&priv->lock, flags);
7085 mutex_lock(&priv->mutex);
7086 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
7087 iwl4965_activate_qos(priv, 1);
7088 else if (priv->assoc_id && iwl_is_associated(priv))
7089 iwl4965_activate_qos(priv, 0);
7091 mutex_unlock(&priv->mutex);
7093 IWL_DEBUG_MAC80211("leave\n");
7097 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
7098 struct ieee80211_tx_queue_stats *stats)
7100 struct iwl_priv *priv = hw->priv;
7102 struct iwl4965_tx_queue *txq;
7103 struct iwl4965_queue *q;
7104 unsigned long flags;
7106 IWL_DEBUG_MAC80211("enter\n");
7108 if (!iwl_is_ready_rf(priv)) {
7109 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7113 spin_lock_irqsave(&priv->lock, flags);
7115 for (i = 0; i < AC_NUM; i++) {
7116 txq = &priv->txq[i];
7118 avail = iwl4965_queue_space(q);
7120 stats->data[i].len = q->n_window - avail;
7121 stats->data[i].limit = q->n_window - q->high_mark;
7122 stats->data[i].count = q->n_window;
7125 spin_unlock_irqrestore(&priv->lock, flags);
7127 IWL_DEBUG_MAC80211("leave\n");
7132 static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
7133 struct ieee80211_low_level_stats *stats)
7135 IWL_DEBUG_MAC80211("enter\n");
7136 IWL_DEBUG_MAC80211("leave\n");
7141 static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
7143 IWL_DEBUG_MAC80211("enter\n");
7144 IWL_DEBUG_MAC80211("leave\n");
7149 static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
7151 struct iwl_priv *priv = hw->priv;
7152 unsigned long flags;
7154 mutex_lock(&priv->mutex);
7155 IWL_DEBUG_MAC80211("enter\n");
7157 priv->lq_mngr.lq_ready = 0;
7158 #ifdef CONFIG_IWL4965_HT
7159 spin_lock_irqsave(&priv->lock, flags);
7160 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
7161 spin_unlock_irqrestore(&priv->lock, flags);
7162 #endif /* CONFIG_IWL4965_HT */
7164 iwlcore_reset_qos(priv);
7166 cancel_delayed_work(&priv->post_associate);
7168 spin_lock_irqsave(&priv->lock, flags);
7170 priv->assoc_capability = 0;
7171 priv->assoc_station_added = 0;
7173 /* new association get rid of ibss beacon skb */
7174 if (priv->ibss_beacon)
7175 dev_kfree_skb(priv->ibss_beacon);
7177 priv->ibss_beacon = NULL;
7179 priv->beacon_int = priv->hw->conf.beacon_int;
7180 priv->timestamp = 0;
7181 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
7182 priv->beacon_int = 0;
7184 spin_unlock_irqrestore(&priv->lock, flags);
7186 if (!iwl_is_ready_rf(priv)) {
7187 IWL_DEBUG_MAC80211("leave - not ready\n");
7188 mutex_unlock(&priv->mutex);
7192 /* we are restarting association process
7193 * clear RXON_FILTER_ASSOC_MSK bit
7195 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
7196 iwl4965_scan_cancel_timeout(priv, 100);
7197 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7198 iwl4965_commit_rxon(priv);
7201 /* Per mac80211.h: This is only used in IBSS mode... */
7202 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7204 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7205 mutex_unlock(&priv->mutex);
7209 priv->only_active_channel = 0;
7211 iwl4965_set_rate(priv);
7213 mutex_unlock(&priv->mutex);
7215 IWL_DEBUG_MAC80211("leave\n");
7218 static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
7219 struct ieee80211_tx_control *control)
7221 struct iwl_priv *priv = hw->priv;
7222 unsigned long flags;
7224 mutex_lock(&priv->mutex);
7225 IWL_DEBUG_MAC80211("enter\n");
7227 if (!iwl_is_ready_rf(priv)) {
7228 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7229 mutex_unlock(&priv->mutex);
7233 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7234 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7235 mutex_unlock(&priv->mutex);
7239 spin_lock_irqsave(&priv->lock, flags);
7241 if (priv->ibss_beacon)
7242 dev_kfree_skb(priv->ibss_beacon);
7244 priv->ibss_beacon = skb;
7248 IWL_DEBUG_MAC80211("leave\n");
7249 spin_unlock_irqrestore(&priv->lock, flags);
7251 iwlcore_reset_qos(priv);
7253 queue_work(priv->workqueue, &priv->post_associate.work);
7255 mutex_unlock(&priv->mutex);
7260 /*****************************************************************************
7264 *****************************************************************************/
7266 #ifdef CONFIG_IWLWIFI_DEBUG
7269 * The following adds a new attribute to the sysfs representation
7270 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7271 * used for controlling the debug level.
7273 * See the level definitions in iwl for details.
7276 static ssize_t show_debug_level(struct device_driver *d, char *buf)
7278 return sprintf(buf, "0x%08X\n", iwl_debug_level);
7280 static ssize_t store_debug_level(struct device_driver *d,
7281 const char *buf, size_t count)
7283 char *p = (char *)buf;
7286 val = simple_strtoul(p, &p, 0);
7288 printk(KERN_INFO DRV_NAME
7289 ": %s is not in hex or decimal form.\n", buf);
7291 iwl_debug_level = val;
7293 return strnlen(buf, count);
7296 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
7297 show_debug_level, store_debug_level);
7299 #endif /* CONFIG_IWLWIFI_DEBUG */
7302 static ssize_t show_temperature(struct device *d,
7303 struct device_attribute *attr, char *buf)
7305 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7307 if (!iwl_is_alive(priv))
7310 return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
7313 static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
7315 static ssize_t show_rs_window(struct device *d,
7316 struct device_attribute *attr,
7319 struct iwl_priv *priv = d->driver_data;
7320 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
7322 static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
7324 static ssize_t show_tx_power(struct device *d,
7325 struct device_attribute *attr, char *buf)
7327 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7328 return sprintf(buf, "%d\n", priv->user_txpower_limit);
7331 static ssize_t store_tx_power(struct device *d,
7332 struct device_attribute *attr,
7333 const char *buf, size_t count)
7335 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7336 char *p = (char *)buf;
7339 val = simple_strtoul(p, &p, 10);
7341 printk(KERN_INFO DRV_NAME
7342 ": %s is not in decimal form.\n", buf);
7344 iwl4965_hw_reg_set_txpower(priv, val);
7349 static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
7351 static ssize_t show_flags(struct device *d,
7352 struct device_attribute *attr, char *buf)
7354 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7356 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
7359 static ssize_t store_flags(struct device *d,
7360 struct device_attribute *attr,
7361 const char *buf, size_t count)
7363 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7364 u32 flags = simple_strtoul(buf, NULL, 0);
7366 mutex_lock(&priv->mutex);
7367 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
7368 /* Cancel any currently running scans... */
7369 if (iwl4965_scan_cancel_timeout(priv, 100))
7370 IWL_WARNING("Could not cancel scan.\n");
7372 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7374 priv->staging_rxon.flags = cpu_to_le32(flags);
7375 iwl4965_commit_rxon(priv);
7378 mutex_unlock(&priv->mutex);
7383 static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
7385 static ssize_t show_filter_flags(struct device *d,
7386 struct device_attribute *attr, char *buf)
7388 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7390 return sprintf(buf, "0x%04X\n",
7391 le32_to_cpu(priv->active_rxon.filter_flags));
7394 static ssize_t store_filter_flags(struct device *d,
7395 struct device_attribute *attr,
7396 const char *buf, size_t count)
7398 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7399 u32 filter_flags = simple_strtoul(buf, NULL, 0);
7401 mutex_lock(&priv->mutex);
7402 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
7403 /* Cancel any currently running scans... */
7404 if (iwl4965_scan_cancel_timeout(priv, 100))
7405 IWL_WARNING("Could not cancel scan.\n");
7407 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7408 "0x%04X\n", filter_flags);
7409 priv->staging_rxon.filter_flags =
7410 cpu_to_le32(filter_flags);
7411 iwl4965_commit_rxon(priv);
7414 mutex_unlock(&priv->mutex);
7419 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
7420 store_filter_flags);
7422 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7424 static ssize_t show_measurement(struct device *d,
7425 struct device_attribute *attr, char *buf)
7427 struct iwl_priv *priv = dev_get_drvdata(d);
7428 struct iwl4965_spectrum_notification measure_report;
7429 u32 size = sizeof(measure_report), len = 0, ofs = 0;
7430 u8 *data = (u8 *) & measure_report;
7431 unsigned long flags;
7433 spin_lock_irqsave(&priv->lock, flags);
7434 if (!(priv->measurement_status & MEASUREMENT_READY)) {
7435 spin_unlock_irqrestore(&priv->lock, flags);
7438 memcpy(&measure_report, &priv->measure_report, size);
7439 priv->measurement_status = 0;
7440 spin_unlock_irqrestore(&priv->lock, flags);
7442 while (size && (PAGE_SIZE - len)) {
7443 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
7444 PAGE_SIZE - len, 1);
7446 if (PAGE_SIZE - len)
7450 size -= min(size, 16U);
7456 static ssize_t store_measurement(struct device *d,
7457 struct device_attribute *attr,
7458 const char *buf, size_t count)
7460 struct iwl_priv *priv = dev_get_drvdata(d);
7461 struct ieee80211_measurement_params params = {
7462 .channel = le16_to_cpu(priv->active_rxon.channel),
7463 .start_time = cpu_to_le64(priv->last_tsf),
7464 .duration = cpu_to_le16(1),
7466 u8 type = IWL_MEASURE_BASIC;
7472 strncpy(buffer, buf, min(sizeof(buffer), count));
7473 channel = simple_strtoul(p, NULL, 0);
7475 params.channel = channel;
7478 while (*p && *p != ' ')
7481 type = simple_strtoul(p + 1, NULL, 0);
7484 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7485 "channel %d (for '%s')\n", type, params.channel, buf);
7486 iwl4965_get_measurement(priv, ¶ms, type);
7491 static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
7492 show_measurement, store_measurement);
7493 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
7495 static ssize_t store_retry_rate(struct device *d,
7496 struct device_attribute *attr,
7497 const char *buf, size_t count)
7499 struct iwl_priv *priv = dev_get_drvdata(d);
7501 priv->retry_rate = simple_strtoul(buf, NULL, 0);
7502 if (priv->retry_rate <= 0)
7503 priv->retry_rate = 1;
7508 static ssize_t show_retry_rate(struct device *d,
7509 struct device_attribute *attr, char *buf)
7511 struct iwl_priv *priv = dev_get_drvdata(d);
7512 return sprintf(buf, "%d", priv->retry_rate);
7515 static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
7518 static ssize_t store_power_level(struct device *d,
7519 struct device_attribute *attr,
7520 const char *buf, size_t count)
7522 struct iwl_priv *priv = dev_get_drvdata(d);
7526 mode = simple_strtoul(buf, NULL, 0);
7527 mutex_lock(&priv->mutex);
7529 if (!iwl_is_ready(priv)) {
7534 if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
7535 mode = IWL_POWER_AC;
7537 mode |= IWL_POWER_ENABLED;
7539 if (mode != priv->power_mode) {
7540 rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode));
7542 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7545 priv->power_mode = mode;
7551 mutex_unlock(&priv->mutex);
7555 #define MAX_WX_STRING 80
7557 /* Values are in microsecond */
7558 static const s32 timeout_duration[] = {
7565 static const s32 period_duration[] = {
7573 static ssize_t show_power_level(struct device *d,
7574 struct device_attribute *attr, char *buf)
7576 struct iwl_priv *priv = dev_get_drvdata(d);
7577 int level = IWL_POWER_LEVEL(priv->power_mode);
7580 p += sprintf(p, "%d ", level);
7582 case IWL_POWER_MODE_CAM:
7584 p += sprintf(p, "(AC)");
7586 case IWL_POWER_BATTERY:
7587 p += sprintf(p, "(BATTERY)");
7591 "(Timeout %dms, Period %dms)",
7592 timeout_duration[level - 1] / 1000,
7593 period_duration[level - 1] / 1000);
7596 if (!(priv->power_mode & IWL_POWER_ENABLED))
7597 p += sprintf(p, " OFF\n");
7599 p += sprintf(p, " \n");
7601 return (p - buf + 1);
7605 static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
7608 static ssize_t show_channels(struct device *d,
7609 struct device_attribute *attr, char *buf)
7611 /* all this shit doesn't belong into sysfs anyway */
7615 static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
7617 static ssize_t show_statistics(struct device *d,
7618 struct device_attribute *attr, char *buf)
7620 struct iwl_priv *priv = dev_get_drvdata(d);
7621 u32 size = sizeof(struct iwl4965_notif_statistics);
7622 u32 len = 0, ofs = 0;
7623 u8 *data = (u8 *) & priv->statistics;
7626 if (!iwl_is_alive(priv))
7629 mutex_lock(&priv->mutex);
7630 rc = iwl4965_send_statistics_request(priv);
7631 mutex_unlock(&priv->mutex);
7635 "Error sending statistics request: 0x%08X\n", rc);
7639 while (size && (PAGE_SIZE - len)) {
7640 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
7641 PAGE_SIZE - len, 1);
7643 if (PAGE_SIZE - len)
7647 size -= min(size, 16U);
7653 static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
7655 static ssize_t show_antenna(struct device *d,
7656 struct device_attribute *attr, char *buf)
7658 struct iwl_priv *priv = dev_get_drvdata(d);
7660 if (!iwl_is_alive(priv))
7663 return sprintf(buf, "%d\n", priv->antenna);
7666 static ssize_t store_antenna(struct device *d,
7667 struct device_attribute *attr,
7668 const char *buf, size_t count)
7671 struct iwl_priv *priv = dev_get_drvdata(d);
7676 if (sscanf(buf, "%1i", &ant) != 1) {
7677 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7681 if ((ant >= 0) && (ant <= 2)) {
7682 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
7683 priv->antenna = (enum iwl4965_antenna)ant;
7685 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
7691 static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
7693 static ssize_t show_status(struct device *d,
7694 struct device_attribute *attr, char *buf)
7696 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7697 if (!iwl_is_alive(priv))
7699 return sprintf(buf, "0x%08x\n", (int)priv->status);
7702 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
7704 static ssize_t dump_error_log(struct device *d,
7705 struct device_attribute *attr,
7706 const char *buf, size_t count)
7708 char *p = (char *)buf;
7711 iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data);
7713 return strnlen(buf, count);
7716 static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
7718 static ssize_t dump_event_log(struct device *d,
7719 struct device_attribute *attr,
7720 const char *buf, size_t count)
7722 char *p = (char *)buf;
7725 iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data);
7727 return strnlen(buf, count);
7730 static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
7732 /*****************************************************************************
7734 * driver setup and teardown
7736 *****************************************************************************/
7738 static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
7740 priv->workqueue = create_workqueue(DRV_NAME);
7742 init_waitqueue_head(&priv->wait_command_queue);
7744 INIT_WORK(&priv->up, iwl4965_bg_up);
7745 INIT_WORK(&priv->restart, iwl4965_bg_restart);
7746 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
7747 INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
7748 INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
7749 INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
7750 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
7751 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
7752 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
7753 INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start);
7754 INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start);
7755 INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
7757 iwl4965_hw_setup_deferred_work(priv);
7759 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
7760 iwl4965_irq_tasklet, (unsigned long)priv);
7763 static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
7765 iwl4965_hw_cancel_deferred_work(priv);
7767 cancel_delayed_work_sync(&priv->init_alive_start);
7768 cancel_delayed_work(&priv->scan_check);
7769 cancel_delayed_work(&priv->alive_start);
7770 cancel_delayed_work(&priv->post_associate);
7771 cancel_work_sync(&priv->beacon_update);
7774 static struct attribute *iwl4965_sysfs_entries[] = {
7775 &dev_attr_antenna.attr,
7776 &dev_attr_channels.attr,
7777 &dev_attr_dump_errors.attr,
7778 &dev_attr_dump_events.attr,
7779 &dev_attr_flags.attr,
7780 &dev_attr_filter_flags.attr,
7781 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7782 &dev_attr_measurement.attr,
7784 &dev_attr_power_level.attr,
7785 &dev_attr_retry_rate.attr,
7786 &dev_attr_rs_window.attr,
7787 &dev_attr_statistics.attr,
7788 &dev_attr_status.attr,
7789 &dev_attr_temperature.attr,
7790 &dev_attr_tx_power.attr,
7795 static struct attribute_group iwl4965_attribute_group = {
7796 .name = NULL, /* put in device directory */
7797 .attrs = iwl4965_sysfs_entries,
7800 static struct ieee80211_ops iwl4965_hw_ops = {
7801 .tx = iwl4965_mac_tx,
7802 .start = iwl4965_mac_start,
7803 .stop = iwl4965_mac_stop,
7804 .add_interface = iwl4965_mac_add_interface,
7805 .remove_interface = iwl4965_mac_remove_interface,
7806 .config = iwl4965_mac_config,
7807 .config_interface = iwl4965_mac_config_interface,
7808 .configure_filter = iwl4965_configure_filter,
7809 .set_key = iwl4965_mac_set_key,
7810 .update_tkip_key = iwl4965_mac_update_tkip_key,
7811 .get_stats = iwl4965_mac_get_stats,
7812 .get_tx_stats = iwl4965_mac_get_tx_stats,
7813 .conf_tx = iwl4965_mac_conf_tx,
7814 .get_tsf = iwl4965_mac_get_tsf,
7815 .reset_tsf = iwl4965_mac_reset_tsf,
7816 .beacon_update = iwl4965_mac_beacon_update,
7817 .bss_info_changed = iwl4965_bss_info_changed,
7818 #ifdef CONFIG_IWL4965_HT
7819 .ampdu_action = iwl4965_mac_ampdu_action,
7820 #endif /* CONFIG_IWL4965_HT */
7821 .hw_scan = iwl4965_mac_hw_scan
7824 static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7827 struct iwl_priv *priv;
7828 struct ieee80211_hw *hw;
7829 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
7830 unsigned long flags;
7831 DECLARE_MAC_BUF(mac);
7833 /************************
7834 * 1. Allocating HW data
7835 ************************/
7837 /* Disabling hardware scan means that mac80211 will perform scans
7838 * "the hard way", rather than using device's scan. */
7839 if (cfg->mod_params->disable_hw_scan) {
7840 IWL_DEBUG_INFO("Disabling hw_scan\n");
7841 iwl4965_hw_ops.hw_scan = NULL;
7844 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
7850 /* At this point both hw and priv are allocated. */
7852 SET_IEEE80211_DEV(hw, &pdev->dev);
7854 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7856 priv->pci_dev = pdev;
7858 #ifdef CONFIG_IWLWIFI_DEBUG
7859 iwl_debug_level = priv->cfg->mod_params->debug;
7860 atomic_set(&priv->restrict_refcnt, 0);
7863 /**************************
7864 * 2. Initializing PCI bus
7865 **************************/
7866 if (pci_enable_device(pdev)) {
7868 goto out_ieee80211_free_hw;
7871 pci_set_master(pdev);
7873 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
7875 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
7877 printk(KERN_WARNING DRV_NAME
7878 ": No suitable DMA available.\n");
7879 goto out_pci_disable_device;
7882 err = pci_request_regions(pdev, DRV_NAME);
7884 goto out_pci_disable_device;
7886 pci_set_drvdata(pdev, priv);
7888 /* We disable the RETRY_TIMEOUT register (0x41) to keep
7889 * PCI Tx retries from interfering with C3 CPU state */
7890 pci_write_config_byte(pdev, 0x41, 0x00);
7892 /***********************
7893 * 3. Read REV register
7894 ***********************/
7895 priv->hw_base = pci_iomap(pdev, 0, 0);
7896 if (!priv->hw_base) {
7898 goto out_pci_release_regions;
7901 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
7902 (unsigned long long) pci_resource_len(pdev, 0));
7903 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
7905 printk(KERN_INFO DRV_NAME
7906 ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name);
7912 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
7913 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
7915 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
7916 err = iwl_poll_bit(priv, CSR_GP_CNTRL,
7917 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
7918 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
7920 IWL_DEBUG_INFO("Failed to init the card\n");
7923 /* Read the EEPROM */
7924 err = iwl_eeprom_init(priv);
7926 IWL_ERROR("Unable to init EEPROM\n");
7929 /* MAC Address location in EEPROM same for 3945/4965 */
7930 iwl_eeprom_get_mac(priv, priv->mac_addr);
7931 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
7932 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
7934 /************************
7935 * 5. Setup HW constants
7936 ************************/
7937 /* Device-specific setup */
7938 if (iwl4965_hw_set_hw_setting(priv)) {
7939 IWL_ERROR("failed to set hw settings\n");
7943 /*******************
7945 *******************/
7947 err = iwl_setup(priv);
7949 goto out_unset_hw_settings;
7950 /* At this point both hw and priv are initialized. */
7952 /**********************************
7953 * 7. Initialize module parameters
7954 **********************************/
7956 /* Disable radio (SW RF KILL) via parameter when loading driver */
7957 if (priv->cfg->mod_params->disable) {
7958 set_bit(STATUS_RF_KILL_SW, &priv->status);
7959 IWL_DEBUG_INFO("Radio disabled.\n");
7962 if (priv->cfg->mod_params->enable_qos)
7963 priv->qos_data.qos_enable = 1;
7965 /********************
7967 ********************/
7968 spin_lock_irqsave(&priv->lock, flags);
7969 iwl4965_disable_interrupts(priv);
7970 spin_unlock_irqrestore(&priv->lock, flags);
7972 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
7974 IWL_ERROR("failed to create sysfs device attributes\n");
7975 goto out_unset_hw_settings;
7978 err = iwl_dbgfs_register(priv, DRV_NAME);
7980 IWL_ERROR("failed to create debugfs files\n");
7981 goto out_remove_sysfs;
7984 iwl4965_setup_deferred_work(priv);
7985 iwl4965_setup_rx_handlers(priv);
7987 /********************
7989 ********************/
7990 pci_save_state(pdev);
7991 pci_disable_device(pdev);
7993 /* notify iwlcore to init */
7994 iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT);
7998 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
7999 out_unset_hw_settings:
8000 iwl4965_unset_hw_setting(priv);
8002 pci_iounmap(pdev, priv->hw_base);
8003 out_pci_release_regions:
8004 pci_release_regions(pdev);
8005 pci_set_drvdata(pdev, NULL);
8006 out_pci_disable_device:
8007 pci_disable_device(pdev);
8008 out_ieee80211_free_hw:
8009 ieee80211_free_hw(priv->hw);
8014 static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
8016 struct iwl_priv *priv = pci_get_drvdata(pdev);
8017 struct list_head *p, *q;
8019 unsigned long flags;
8024 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8026 if (priv->mac80211_registered) {
8027 ieee80211_unregister_hw(priv->hw);
8028 priv->mac80211_registered = 0;
8031 set_bit(STATUS_EXIT_PENDING, &priv->status);
8035 /* make sure we flush any pending irq or
8036 * tasklet for the driver
8038 spin_lock_irqsave(&priv->lock, flags);
8039 iwl4965_disable_interrupts(priv);
8040 spin_unlock_irqrestore(&priv->lock, flags);
8042 iwl_synchronize_irq(priv);
8044 /* Free MAC hash list for ADHOC */
8045 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
8046 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
8048 kfree(list_entry(p, struct iwl4965_ibss_seq, list));
8052 iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT);
8053 iwl_dbgfs_unregister(priv);
8054 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
8056 iwl4965_dealloc_ucode_pci(priv);
8059 iwl4965_rx_queue_free(priv, &priv->rxq);
8060 iwl4965_hw_txq_ctx_free(priv);
8062 iwl4965_unset_hw_setting(priv);
8063 iwlcore_clear_stations_table(priv);
8066 /*netif_stop_queue(dev); */
8067 flush_workqueue(priv->workqueue);
8069 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
8070 * priv->workqueue... so we can't take down the workqueue
8072 destroy_workqueue(priv->workqueue);
8073 priv->workqueue = NULL;
8075 pci_iounmap(pdev, priv->hw_base);
8076 pci_release_regions(pdev);
8077 pci_disable_device(pdev);
8078 pci_set_drvdata(pdev, NULL);
8080 iwl_free_channel_map(priv);
8081 iwl4965_free_geos(priv);
8083 if (priv->ibss_beacon)
8084 dev_kfree_skb(priv->ibss_beacon);
8086 ieee80211_free_hw(priv->hw);
8091 static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
8093 struct iwl_priv *priv = pci_get_drvdata(pdev);
8095 if (priv->is_open) {
8096 set_bit(STATUS_IN_SUSPEND, &priv->status);
8097 iwl4965_mac_stop(priv->hw);
8101 pci_set_power_state(pdev, PCI_D3hot);
8106 static int iwl4965_pci_resume(struct pci_dev *pdev)
8108 struct iwl_priv *priv = pci_get_drvdata(pdev);
8110 pci_set_power_state(pdev, PCI_D0);
8113 iwl4965_mac_start(priv->hw);
8115 clear_bit(STATUS_IN_SUSPEND, &priv->status);
8119 #endif /* CONFIG_PM */
8121 /*****************************************************************************
8123 * driver and module entry point
8125 *****************************************************************************/
8127 static struct pci_driver iwl4965_driver = {
8129 .id_table = iwl4965_hw_card_ids,
8130 .probe = iwl4965_pci_probe,
8131 .remove = __devexit_p(iwl4965_pci_remove),
8133 .suspend = iwl4965_pci_suspend,
8134 .resume = iwl4965_pci_resume,
8138 static int __init iwl4965_init(void)
8142 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
8143 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
8145 ret = iwl4965_rate_control_register();
8147 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
8151 ret = pci_register_driver(&iwl4965_driver);
8153 IWL_ERROR("Unable to initialize PCI module\n");
8154 goto error_register;
8156 #ifdef CONFIG_IWLWIFI_DEBUG
8157 ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level);
8159 IWL_ERROR("Unable to create driver sysfs file\n");
8166 #ifdef CONFIG_IWLWIFI_DEBUG
8168 pci_unregister_driver(&iwl4965_driver);
8171 iwl4965_rate_control_unregister();
8175 static void __exit iwl4965_exit(void)
8177 #ifdef CONFIG_IWLWIFI_DEBUG
8178 driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level);
8180 pci_unregister_driver(&iwl4965_driver);
8181 iwl4965_rate_control_unregister();
8184 module_exit(iwl4965_exit);
8185 module_init(iwl4965_init);