1 /******************************************************************************
3 * Copyright(c) 2003 - 2007 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/ieee80211_radiotap.h>
45 #include <net/mac80211.h>
47 #include <asm/div64.h>
50 #include "iwl-helpers.h"
52 #ifdef CONFIG_IWL4965_DEBUG
53 u32 iwl4965_debug_level;
56 static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
57 struct iwl4965_tx_queue *txq);
59 /******************************************************************************
63 ******************************************************************************/
65 /* module parameters */
66 static int iwl4965_param_disable_hw_scan;
67 static int iwl4965_param_debug;
68 static int iwl4965_param_disable; /* def: enable radio */
69 static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */
70 int iwl4965_param_hwcrypto; /* def: using software encryption */
71 static int iwl4965_param_qos_enable = 1;
72 int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES;
75 * module name, copyright, version, etc.
76 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
79 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
81 #ifdef CONFIG_IWL4965_DEBUG
87 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
93 #define IWLWIFI_VERSION "1.1.19k" VD VS
94 #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation"
95 #define DRV_VERSION IWLWIFI_VERSION
97 /* Change firmware file name, using "-" and incrementing number,
98 * *only* when uCode interface or architecture changes so that it
99 * is not compatible with earlier drivers.
100 * This number will also appear in << 8 position of 1st dword of uCode file */
101 #define IWL4965_UCODE_API "-1"
103 MODULE_DESCRIPTION(DRV_DESCRIPTION);
104 MODULE_VERSION(DRV_VERSION);
105 MODULE_AUTHOR(DRV_COPYRIGHT);
106 MODULE_LICENSE("GPL");
108 __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
110 u16 fc = le16_to_cpu(hdr->frame_control);
111 int hdr_len = ieee80211_get_hdrlen(fc);
113 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
114 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
118 static const struct ieee80211_hw_mode *iwl4965_get_hw_mode(
119 struct iwl4965_priv *priv, int mode)
123 for (i = 0; i < 3; i++)
124 if (priv->modes[i].mode == mode)
125 return &priv->modes[i];
130 static int iwl4965_is_empty_essid(const char *essid, int essid_len)
132 /* Single white space is for Linksys APs */
133 if (essid_len == 1 && essid[0] == ' ')
136 /* Otherwise, if the entire essid is 0, we assume it is hidden */
139 if (essid[essid_len] != '\0')
146 static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
148 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
149 const char *s = essid;
152 if (iwl4965_is_empty_essid(essid, essid_len)) {
153 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
157 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
158 while (essid_len--) {
170 static void iwl4965_print_hex_dump(int level, void *p, u32 len)
172 #ifdef CONFIG_IWL4965_DEBUG
173 if (!(iwl4965_debug_level & level))
176 print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
181 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
184 * Theory of operation
186 * A queue is a circular buffers with 'Read' and 'Write' pointers.
187 * 2 empty entries always kept in the buffer to protect from overflow.
189 * For Tx queue, there are low mark and high mark limits. If, after queuing
190 * the packet for Tx, free space become < low mark, Tx queue stopped. When
191 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
194 * The IWL operates with six queues, one receive queue in the device's
195 * sram, one transmit queue for sending commands to the device firmware,
196 * and four transmit queues for data.
197 ***************************************************/
199 static int iwl4965_queue_space(const struct iwl4965_queue *q)
201 int s = q->read_ptr - q->write_ptr;
203 if (q->read_ptr > q->write_ptr)
208 /* keep some reserve to not confuse empty and full situations */
215 /* XXX: n_bd must be power-of-two size */
216 static inline int iwl4965_queue_inc_wrap(int index, int n_bd)
218 return ++index & (n_bd - 1);
221 /* XXX: n_bd must be power-of-two size */
222 static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
224 return --index & (n_bd - 1);
227 static inline int x2_queue_used(const struct iwl4965_queue *q, int i)
229 return q->write_ptr > q->read_ptr ?
230 (i >= q->read_ptr && i < q->write_ptr) :
231 !(i < q->read_ptr && i >= q->write_ptr);
234 static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge)
239 return index & (q->n_window - 1);
242 static int iwl4965_queue_init(struct iwl4965_priv *priv, struct iwl4965_queue *q,
243 int count, int slots_num, u32 id)
246 q->n_window = slots_num;
249 /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap
250 * and iwl4965_queue_dec_wrap are broken. */
251 BUG_ON(!is_power_of_2(count));
253 /* slots_num must be power-of-two size, otherwise
254 * get_cmd_index is broken. */
255 BUG_ON(!is_power_of_2(slots_num));
257 q->low_mark = q->n_window / 4;
261 q->high_mark = q->n_window / 8;
262 if (q->high_mark < 2)
265 q->write_ptr = q->read_ptr = 0;
270 static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv,
271 struct iwl4965_tx_queue *txq, u32 id)
273 struct pci_dev *dev = priv->pci_dev;
275 if (id != IWL_CMD_QUEUE_NUM) {
276 txq->txb = kmalloc(sizeof(txq->txb[0]) *
277 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
279 IWL_ERROR("kmalloc for auxiliary BD "
280 "structures failed\n");
286 txq->bd = pci_alloc_consistent(dev,
287 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
291 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
292 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
309 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
311 int iwl4965_tx_queue_init(struct iwl4965_priv *priv,
312 struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id)
314 struct pci_dev *dev = priv->pci_dev;
319 * Alloc buffer array for commands (Tx or other types of commands).
320 * For the command queue (#4), allocate command space + one big
321 * command for scan, since scan command is very huge; the system will
322 * not have two scans at the same time, so only one is needed.
323 * For normal Tx queues (all other queues), no super-size command
326 len = sizeof(struct iwl4965_cmd) * slots_num;
327 if (txq_id == IWL_CMD_QUEUE_NUM)
328 len += IWL_MAX_SCAN_SIZE;
329 txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
333 /* Alloc driver data array and TFD circular buffer */
334 rc = iwl4965_tx_queue_alloc(priv, txq, txq_id);
336 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
340 txq->need_update = 0;
342 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
343 * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */
344 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
346 /* Initialize queue's high/low-water marks, and head/tail indexes */
347 iwl4965_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
349 /* Tell device where to find queue */
350 iwl4965_hw_tx_queue_init(priv, txq);
356 * iwl4965_tx_queue_free - Deallocate DMA queue.
357 * @txq: Transmit queue to deallocate.
359 * Empty queue by removing and destroying all BD's.
360 * Free all buffers. txq itself is not freed.
363 void iwl4965_tx_queue_free(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq)
365 struct iwl4965_queue *q = &txq->q;
366 struct pci_dev *dev = priv->pci_dev;
372 /* first, empty all BD's */
373 for (; q->write_ptr != q->read_ptr;
374 q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd))
375 iwl4965_hw_txq_free_tfd(priv, txq);
377 len = sizeof(struct iwl4965_cmd) * q->n_window;
378 if (q->id == IWL_CMD_QUEUE_NUM)
379 len += IWL_MAX_SCAN_SIZE;
381 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
383 /* free buffers belonging to queue itself */
385 pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) *
386 txq->q.n_bd, txq->bd, txq->q.dma_addr);
393 /* 0 fill whole structure */
394 memset(txq, 0, sizeof(*txq));
397 const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
399 /*************** STATION TABLE MANAGEMENT ****
400 * mac80211 should be examined to determine if sta_info is duplicating
401 * the functionality provided here
404 /**************************************************************/
406 #if 0 /* temporary disable till we add real remove station */
407 static u8 iwl4965_remove_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap)
409 int index = IWL_INVALID_STATION;
413 spin_lock_irqsave(&priv->sta_lock, flags);
417 else if (is_broadcast_ether_addr(addr))
418 index = priv->hw_setting.bcast_sta_id;
420 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
421 if (priv->stations[i].used &&
422 !compare_ether_addr(priv->stations[i].sta.sta.addr,
428 if (unlikely(index == IWL_INVALID_STATION))
431 if (priv->stations[index].used) {
432 priv->stations[index].used = 0;
433 priv->num_stations--;
436 BUG_ON(priv->num_stations < 0);
439 spin_unlock_irqrestore(&priv->sta_lock, flags);
444 static void iwl4965_clear_stations_table(struct iwl4965_priv *priv)
448 spin_lock_irqsave(&priv->sta_lock, flags);
450 priv->num_stations = 0;
451 memset(priv->stations, 0, sizeof(priv->stations));
453 spin_unlock_irqrestore(&priv->sta_lock, flags);
456 u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr, int is_ap, u8 flags)
459 int index = IWL_INVALID_STATION;
460 struct iwl4965_station_entry *station;
461 unsigned long flags_spin;
462 DECLARE_MAC_BUF(mac);
464 spin_lock_irqsave(&priv->sta_lock, flags_spin);
467 else if (is_broadcast_ether_addr(addr))
468 index = priv->hw_setting.bcast_sta_id;
470 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
471 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
477 if (!priv->stations[i].used &&
478 index == IWL_INVALID_STATION)
483 /* These two conditions have the same outcome, but keep them separate
484 since they have different meanings */
485 if (unlikely(index == IWL_INVALID_STATION)) {
486 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
490 if (priv->stations[index].used &&
491 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
492 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
497 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
498 station = &priv->stations[index];
500 priv->num_stations++;
502 memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd));
503 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
504 station->sta.mode = 0;
505 station->sta.sta.sta_id = index;
506 station->sta.station_flags = 0;
508 #ifdef CONFIG_IWL4965_HT
509 /* BCAST station and IBSS stations do not work in HT mode */
510 if (index != priv->hw_setting.bcast_sta_id &&
511 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
512 iwl4965_set_ht_add_station(priv, index);
513 #endif /*CONFIG_IWL4965_HT*/
515 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
516 iwl4965_send_add_station(priv, &station->sta, flags);
521 /*************** DRIVER STATUS FUNCTIONS *****/
523 static inline int iwl4965_is_ready(struct iwl4965_priv *priv)
525 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
526 * set but EXIT_PENDING is not */
527 return test_bit(STATUS_READY, &priv->status) &&
528 test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
529 !test_bit(STATUS_EXIT_PENDING, &priv->status);
532 static inline int iwl4965_is_alive(struct iwl4965_priv *priv)
534 return test_bit(STATUS_ALIVE, &priv->status);
537 static inline int iwl4965_is_init(struct iwl4965_priv *priv)
539 return test_bit(STATUS_INIT, &priv->status);
542 static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv)
544 return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
545 test_bit(STATUS_RF_KILL_SW, &priv->status);
548 static inline int iwl4965_is_ready_rf(struct iwl4965_priv *priv)
551 if (iwl4965_is_rfkill(priv))
554 return iwl4965_is_ready(priv);
557 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
559 #define IWL_CMD(x) case x : return #x
561 static const char *get_cmd_string(u8 cmd)
564 IWL_CMD(REPLY_ALIVE);
565 IWL_CMD(REPLY_ERROR);
567 IWL_CMD(REPLY_RXON_ASSOC);
568 IWL_CMD(REPLY_QOS_PARAM);
569 IWL_CMD(REPLY_RXON_TIMING);
570 IWL_CMD(REPLY_ADD_STA);
571 IWL_CMD(REPLY_REMOVE_STA);
572 IWL_CMD(REPLY_REMOVE_ALL_STA);
574 IWL_CMD(REPLY_RATE_SCALE);
575 IWL_CMD(REPLY_LEDS_CMD);
576 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
577 IWL_CMD(RADAR_NOTIFICATION);
578 IWL_CMD(REPLY_QUIET_CMD);
579 IWL_CMD(REPLY_CHANNEL_SWITCH);
580 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
581 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
582 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
583 IWL_CMD(POWER_TABLE_CMD);
584 IWL_CMD(PM_SLEEP_NOTIFICATION);
585 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
586 IWL_CMD(REPLY_SCAN_CMD);
587 IWL_CMD(REPLY_SCAN_ABORT_CMD);
588 IWL_CMD(SCAN_START_NOTIFICATION);
589 IWL_CMD(SCAN_RESULTS_NOTIFICATION);
590 IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
591 IWL_CMD(BEACON_NOTIFICATION);
592 IWL_CMD(REPLY_TX_BEACON);
593 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
594 IWL_CMD(QUIET_NOTIFICATION);
595 IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
596 IWL_CMD(MEASURE_ABORT_NOTIFICATION);
597 IWL_CMD(REPLY_BT_CONFIG);
598 IWL_CMD(REPLY_STATISTICS_CMD);
599 IWL_CMD(STATISTICS_NOTIFICATION);
600 IWL_CMD(REPLY_CARD_STATE_CMD);
601 IWL_CMD(CARD_STATE_NOTIFICATION);
602 IWL_CMD(MISSED_BEACONS_NOTIFICATION);
603 IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
604 IWL_CMD(SENSITIVITY_CMD);
605 IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
606 IWL_CMD(REPLY_RX_PHY_CMD);
607 IWL_CMD(REPLY_RX_MPDU_CMD);
608 IWL_CMD(REPLY_4965_RX);
609 IWL_CMD(REPLY_COMPRESSED_BA);
616 #define HOST_COMPLETE_TIMEOUT (HZ / 2)
619 * iwl4965_enqueue_hcmd - enqueue a uCode command
620 * @priv: device private data point
621 * @cmd: a point to the ucode command structure
623 * The function returns < 0 values to indicate the operation is
624 * failed. On success, it turns the index (> 0) of command in the
627 static int iwl4965_enqueue_hcmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
629 struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
630 struct iwl4965_queue *q = &txq->q;
631 struct iwl4965_tfd_frame *tfd;
633 struct iwl4965_cmd *out_cmd;
635 u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
636 dma_addr_t phys_addr;
640 /* If any of the command structures end up being larger than
641 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
642 * we will need to increase the size of the TFD entries */
643 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
644 !(cmd->meta.flags & CMD_SIZE_HUGE));
646 if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
647 IWL_ERROR("No space for Tx\n");
651 spin_lock_irqsave(&priv->hcmd_lock, flags);
653 tfd = &txq->bd[q->write_ptr];
654 memset(tfd, 0, sizeof(*tfd));
656 control_flags = (u32 *) tfd;
658 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
659 out_cmd = &txq->cmd[idx];
661 out_cmd->hdr.cmd = cmd->id;
662 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
663 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
665 /* At this point, the out_cmd now has all of the incoming cmd
668 out_cmd->hdr.flags = 0;
669 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
670 INDEX_TO_SEQ(q->write_ptr));
671 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
672 out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
674 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
675 offsetof(struct iwl4965_cmd, hdr);
676 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
678 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
679 "%d bytes at %d[%d]:%d\n",
680 get_cmd_string(out_cmd->hdr.cmd),
681 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
682 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
684 txq->need_update = 1;
685 ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0);
686 q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
687 iwl4965_tx_queue_update_write_ptr(priv, txq);
689 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
690 return ret ? ret : idx;
693 static int iwl4965_send_cmd_async(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
697 BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
699 /* An asynchronous command can not expect an SKB to be set. */
700 BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
702 /* An asynchronous command MUST have a callback. */
703 BUG_ON(!cmd->meta.u.callback);
705 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
708 ret = iwl4965_enqueue_hcmd(priv, cmd);
710 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
711 get_cmd_string(cmd->id), ret);
717 static int iwl4965_send_cmd_sync(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
721 static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
723 BUG_ON(cmd->meta.flags & CMD_ASYNC);
725 /* A synchronous command can not have a callback set. */
726 BUG_ON(cmd->meta.u.callback != NULL);
728 if (atomic_xchg(&entry, 1)) {
729 IWL_ERROR("Error sending %s: Already sending a host command\n",
730 get_cmd_string(cmd->id));
734 set_bit(STATUS_HCMD_ACTIVE, &priv->status);
736 if (cmd->meta.flags & CMD_WANT_SKB)
737 cmd->meta.source = &cmd->meta;
739 cmd_idx = iwl4965_enqueue_hcmd(priv, cmd);
742 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
743 get_cmd_string(cmd->id), ret);
747 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
748 !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
749 HOST_COMPLETE_TIMEOUT);
751 if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
752 IWL_ERROR("Error sending %s: time out after %dms.\n",
753 get_cmd_string(cmd->id),
754 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
756 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
762 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
763 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
764 get_cmd_string(cmd->id));
768 if (test_bit(STATUS_FW_ERROR, &priv->status)) {
769 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
770 get_cmd_string(cmd->id));
774 if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
775 IWL_ERROR("Error: Response NULL in '%s'\n",
776 get_cmd_string(cmd->id));
785 if (cmd->meta.flags & CMD_WANT_SKB) {
786 struct iwl4965_cmd *qcmd;
788 /* Cancel the CMD_WANT_SKB flag for the cmd in the
789 * TX cmd queue. Otherwise in case the cmd comes
790 * in later, it will possibly set an invalid
791 * address (cmd->meta.source). */
792 qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
793 qcmd->meta.flags &= ~CMD_WANT_SKB;
796 if (cmd->meta.u.skb) {
797 dev_kfree_skb_any(cmd->meta.u.skb);
798 cmd->meta.u.skb = NULL;
801 atomic_set(&entry, 0);
805 int iwl4965_send_cmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
807 if (cmd->meta.flags & CMD_ASYNC)
808 return iwl4965_send_cmd_async(priv, cmd);
810 return iwl4965_send_cmd_sync(priv, cmd);
813 int iwl4965_send_cmd_pdu(struct iwl4965_priv *priv, u8 id, u16 len, const void *data)
815 struct iwl4965_host_cmd cmd = {
821 return iwl4965_send_cmd_sync(priv, &cmd);
824 static int __must_check iwl4965_send_cmd_u32(struct iwl4965_priv *priv, u8 id, u32 val)
826 struct iwl4965_host_cmd cmd = {
832 return iwl4965_send_cmd_sync(priv, &cmd);
835 int iwl4965_send_statistics_request(struct iwl4965_priv *priv)
837 return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
841 * iwl4965_rxon_add_station - add station into station table.
843 * there is only one AP station with id= IWL_AP_ID
844 * NOTE: mutex must be held before calling this fnction
846 static int iwl4965_rxon_add_station(struct iwl4965_priv *priv,
847 const u8 *addr, int is_ap)
851 sta_id = iwl4965_add_station_flags(priv, addr, is_ap, 0);
852 iwl4965_add_station(priv, addr, is_ap);
858 * iwl4965_set_rxon_channel - Set the phymode and channel values in staging RXON
859 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
860 * @channel: Any channel valid for the requested phymode
862 * In addition to setting the staging RXON, priv->phymode is also set.
864 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
865 * in the staging RXON flag structure based on the phymode
867 static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, u8 phymode,
870 if (!iwl4965_get_channel_info(priv, phymode, channel)) {
871 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
876 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
877 (priv->phymode == phymode))
880 priv->staging_rxon.channel = cpu_to_le16(channel);
881 if (phymode == MODE_IEEE80211A)
882 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
884 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
886 priv->phymode = phymode;
888 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode);
894 * iwl4965_check_rxon_cmd - validate RXON structure is valid
896 * NOTE: This is really only useful during development and can eventually
897 * be #ifdef'd out once the driver is stable and folks aren't actively
900 static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon)
905 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
906 error |= le32_to_cpu(rxon->flags &
907 (RXON_FLG_TGJ_NARROW_BAND_MSK |
908 RXON_FLG_RADAR_DETECT_MSK));
910 IWL_WARNING("check 24G fields %d | %d\n",
913 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
914 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
916 IWL_WARNING("check 52 fields %d | %d\n",
918 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
920 IWL_WARNING("check 52 CCK %d | %d\n",
923 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
925 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
927 /* make sure basic rates 6Mbps and 1Mbps are supported */
928 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
929 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
931 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
933 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
935 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
937 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
938 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
940 IWL_WARNING("check CCK and short slot %d | %d\n",
943 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
944 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
946 IWL_WARNING("check CCK & auto detect %d | %d\n",
949 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
950 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
952 IWL_WARNING("check TGG and auto detect %d | %d\n",
956 IWL_WARNING("Tuning to channel %d\n",
957 le16_to_cpu(rxon->channel));
960 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
967 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
968 * @priv: staging_rxon is compared to active_rxon
970 * If the RXON structure is changing enough to require a new tune,
971 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
972 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
974 static int iwl4965_full_rxon_required(struct iwl4965_priv *priv)
977 /* These items are only settable from the full RXON command */
978 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
979 compare_ether_addr(priv->staging_rxon.bssid_addr,
980 priv->active_rxon.bssid_addr) ||
981 compare_ether_addr(priv->staging_rxon.node_addr,
982 priv->active_rxon.node_addr) ||
983 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
984 priv->active_rxon.wlap_bssid_addr) ||
985 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
986 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
987 (priv->staging_rxon.air_propagation !=
988 priv->active_rxon.air_propagation) ||
989 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
990 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
991 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
992 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
993 (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
994 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
997 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
998 * be updated with the RXON_ASSOC command -- however only some
999 * flag transitions are allowed using RXON_ASSOC */
1001 /* Check if we are not switching bands */
1002 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
1003 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
1006 /* Check if we are switching association toggle */
1007 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
1008 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
1014 static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv)
1017 struct iwl4965_rx_packet *res = NULL;
1018 struct iwl4965_rxon_assoc_cmd rxon_assoc;
1019 struct iwl4965_host_cmd cmd = {
1020 .id = REPLY_RXON_ASSOC,
1021 .len = sizeof(rxon_assoc),
1022 .meta.flags = CMD_WANT_SKB,
1023 .data = &rxon_assoc,
1025 const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon;
1026 const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon;
1028 if ((rxon1->flags == rxon2->flags) &&
1029 (rxon1->filter_flags == rxon2->filter_flags) &&
1030 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1031 (rxon1->ofdm_ht_single_stream_basic_rates ==
1032 rxon2->ofdm_ht_single_stream_basic_rates) &&
1033 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1034 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1035 (rxon1->rx_chain == rxon2->rx_chain) &&
1036 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1037 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1041 rxon_assoc.flags = priv->staging_rxon.flags;
1042 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1043 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1044 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1045 rxon_assoc.reserved = 0;
1046 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1047 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1048 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1049 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1050 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1052 rc = iwl4965_send_cmd_sync(priv, &cmd);
1056 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
1057 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1058 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1062 priv->alloc_rxb_skb--;
1063 dev_kfree_skb_any(cmd.meta.u.skb);
1069 * iwl4965_commit_rxon - commit staging_rxon to hardware
1071 * The RXON command in staging_rxon is committed to the hardware and
1072 * the active_rxon structure is updated with the new data. This
1073 * function correctly transitions out of the RXON_ASSOC_MSK state if
1074 * a HW tune is required based on the RXON structure changes.
1076 static int iwl4965_commit_rxon(struct iwl4965_priv *priv)
1078 /* cast away the const for active_rxon in this function */
1079 struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
1080 DECLARE_MAC_BUF(mac);
1083 if (!iwl4965_is_alive(priv))
1086 /* always get timestamp with Rx frame */
1087 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
1089 rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
1091 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1095 /* If we don't need to send a full RXON, we can use
1096 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
1097 * and other flags for the current radio configuration. */
1098 if (!iwl4965_full_rxon_required(priv)) {
1099 rc = iwl4965_send_rxon_assoc(priv);
1101 IWL_ERROR("Error setting RXON_ASSOC "
1102 "configuration (%d).\n", rc);
1106 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1111 /* station table will be cleared */
1112 priv->assoc_station_added = 0;
1114 #ifdef CONFIG_IWL4965_SENSITIVITY
1115 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1116 if (!priv->error_recovering)
1117 priv->start_calib = 0;
1119 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
1120 #endif /* CONFIG_IWL4965_SENSITIVITY */
1122 /* If we are currently associated and the new config requires
1123 * an RXON_ASSOC and the new config wants the associated mask enabled,
1124 * we must clear the associated from the active configuration
1125 * before we apply the new config */
1126 if (iwl4965_is_associated(priv) &&
1127 (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
1128 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1129 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1131 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1132 sizeof(struct iwl4965_rxon_cmd),
1133 &priv->active_rxon);
1135 /* If the mask clearing failed then we set
1136 * active_rxon back to what it was previously */
1138 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
1139 IWL_ERROR("Error clearing ASSOC_MSK on current "
1140 "configuration (%d).\n", rc);
1145 IWL_DEBUG_INFO("Sending RXON\n"
1146 "* with%s RXON_FILTER_ASSOC_MSK\n"
1149 ((priv->staging_rxon.filter_flags &
1150 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
1151 le16_to_cpu(priv->staging_rxon.channel),
1152 print_mac(mac, priv->staging_rxon.bssid_addr));
1154 /* Apply the new configuration */
1155 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1156 sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
1158 IWL_ERROR("Error setting new configuration (%d).\n", rc);
1162 iwl4965_clear_stations_table(priv);
1164 #ifdef CONFIG_IWL4965_SENSITIVITY
1165 if (!priv->error_recovering)
1166 priv->start_calib = 0;
1168 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1169 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
1170 #endif /* CONFIG_IWL4965_SENSITIVITY */
1172 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1174 /* If we issue a new RXON command which required a tune then we must
1175 * send a new TXPOWER command or we won't be able to Tx any frames */
1176 rc = iwl4965_hw_reg_send_txpower(priv);
1178 IWL_ERROR("Error setting Tx power (%d).\n", rc);
1182 /* Add the broadcast address so we can send broadcast frames */
1183 if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) ==
1184 IWL_INVALID_STATION) {
1185 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1189 /* If we have set the ASSOC_MSK and we are in BSS mode then
1190 * add the IWL_AP_ID to the station rate table */
1191 if (iwl4965_is_associated(priv) &&
1192 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
1193 if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
1194 == IWL_INVALID_STATION) {
1195 IWL_ERROR("Error adding AP address for transmit.\n");
1198 priv->assoc_station_added = 1;
1204 static int iwl4965_send_bt_config(struct iwl4965_priv *priv)
1206 struct iwl4965_bt_cmd bt_cmd = {
1214 return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1215 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
1218 static int iwl4965_send_scan_abort(struct iwl4965_priv *priv)
1221 struct iwl4965_rx_packet *res;
1222 struct iwl4965_host_cmd cmd = {
1223 .id = REPLY_SCAN_ABORT_CMD,
1224 .meta.flags = CMD_WANT_SKB,
1227 /* If there isn't a scan actively going on in the hardware
1228 * then we are in between scan bands and not actually
1229 * actively scanning, so don't send the abort command */
1230 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1231 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1235 rc = iwl4965_send_cmd_sync(priv, &cmd);
1237 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1241 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
1242 if (res->u.status != CAN_ABORT_STATUS) {
1243 /* The scan abort will return 1 for success or
1244 * 2 for "failure". A failure condition can be
1245 * due to simply not being in an active scan which
1246 * can occur if we send the scan abort before we
1247 * the microcode has notified us that a scan is
1249 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
1250 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1251 clear_bit(STATUS_SCAN_HW, &priv->status);
1254 dev_kfree_skb_any(cmd.meta.u.skb);
1259 static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv,
1260 struct iwl4965_cmd *cmd,
1261 struct sk_buff *skb)
1269 * Use: Sets the device's internal card state to enable, disable, or halt
1271 * When in the 'enable' state the card operates as normal.
1272 * When in the 'disable' state, the card enters into a low power mode.
1273 * When in the 'halt' state, the card is shut down and must be fully
1274 * restarted to come back on.
1276 static int iwl4965_send_card_state(struct iwl4965_priv *priv, u32 flags, u8 meta_flag)
1278 struct iwl4965_host_cmd cmd = {
1279 .id = REPLY_CARD_STATE_CMD,
1282 .meta.flags = meta_flag,
1285 if (meta_flag & CMD_ASYNC)
1286 cmd.meta.u.callback = iwl4965_card_state_sync_callback;
1288 return iwl4965_send_cmd(priv, &cmd);
1291 static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv,
1292 struct iwl4965_cmd *cmd, struct sk_buff *skb)
1294 struct iwl4965_rx_packet *res = NULL;
1297 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1301 res = (struct iwl4965_rx_packet *)skb->data;
1302 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1303 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1308 switch (res->u.add_sta.status) {
1309 case ADD_STA_SUCCESS_MSK:
1315 /* We didn't cache the SKB; let the caller free it */
1319 int iwl4965_send_add_station(struct iwl4965_priv *priv,
1320 struct iwl4965_addsta_cmd *sta, u8 flags)
1322 struct iwl4965_rx_packet *res = NULL;
1324 struct iwl4965_host_cmd cmd = {
1325 .id = REPLY_ADD_STA,
1326 .len = sizeof(struct iwl4965_addsta_cmd),
1327 .meta.flags = flags,
1331 if (flags & CMD_ASYNC)
1332 cmd.meta.u.callback = iwl4965_add_sta_sync_callback;
1334 cmd.meta.flags |= CMD_WANT_SKB;
1336 rc = iwl4965_send_cmd(priv, &cmd);
1338 if (rc || (flags & CMD_ASYNC))
1341 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
1342 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1343 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1349 switch (res->u.add_sta.status) {
1350 case ADD_STA_SUCCESS_MSK:
1351 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1355 IWL_WARNING("REPLY_ADD_STA failed\n");
1360 priv->alloc_rxb_skb--;
1361 dev_kfree_skb_any(cmd.meta.u.skb);
1366 static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv,
1367 struct ieee80211_key_conf *keyconf,
1370 unsigned long flags;
1371 __le16 key_flags = 0;
1373 switch (keyconf->alg) {
1375 key_flags |= STA_KEY_FLG_CCMP;
1376 key_flags |= cpu_to_le16(
1377 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1378 key_flags &= ~STA_KEY_FLG_INVALID;
1385 spin_lock_irqsave(&priv->sta_lock, flags);
1386 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1387 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
1388 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
1391 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
1393 priv->stations[sta_id].sta.key.key_flags = key_flags;
1394 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1395 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1397 spin_unlock_irqrestore(&priv->sta_lock, flags);
1399 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1400 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
1404 static int iwl4965_clear_sta_key_info(struct iwl4965_priv *priv, u8 sta_id)
1406 unsigned long flags;
1408 spin_lock_irqsave(&priv->sta_lock, flags);
1409 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key));
1410 memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo));
1411 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
1412 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1413 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1414 spin_unlock_irqrestore(&priv->sta_lock, flags);
1416 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1417 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
1421 static void iwl4965_clear_free_frames(struct iwl4965_priv *priv)
1423 struct list_head *element;
1425 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1426 priv->frames_count);
1428 while (!list_empty(&priv->free_frames)) {
1429 element = priv->free_frames.next;
1431 kfree(list_entry(element, struct iwl4965_frame, list));
1432 priv->frames_count--;
1435 if (priv->frames_count) {
1436 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1437 priv->frames_count);
1438 priv->frames_count = 0;
1442 static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv)
1444 struct iwl4965_frame *frame;
1445 struct list_head *element;
1446 if (list_empty(&priv->free_frames)) {
1447 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1449 IWL_ERROR("Could not allocate frame!\n");
1453 priv->frames_count++;
1457 element = priv->free_frames.next;
1459 return list_entry(element, struct iwl4965_frame, list);
1462 static void iwl4965_free_frame(struct iwl4965_priv *priv, struct iwl4965_frame *frame)
1464 memset(frame, 0, sizeof(*frame));
1465 list_add(&frame->list, &priv->free_frames);
1468 unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv,
1469 struct ieee80211_hdr *hdr,
1470 const u8 *dest, int left)
1473 if (!iwl4965_is_associated(priv) || !priv->ibss_beacon ||
1474 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
1475 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
1478 if (priv->ibss_beacon->len > left)
1481 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1483 return priv->ibss_beacon->len;
1486 int iwl4965_rate_index_from_plcp(int plcp)
1490 /* 4965 HT rate format */
1491 if (plcp & RATE_MCS_HT_MSK) {
1494 if (i >= IWL_RATE_MIMO_6M_PLCP)
1495 i = i - IWL_RATE_MIMO_6M_PLCP;
1497 i += IWL_FIRST_OFDM_RATE;
1498 /* skip 9M not supported in ht*/
1499 if (i >= IWL_RATE_9M_INDEX)
1501 if ((i >= IWL_FIRST_OFDM_RATE) &&
1502 (i <= IWL_LAST_OFDM_RATE))
1505 /* 4965 legacy rate format, search for match in table */
1507 for (i = 0; i < ARRAY_SIZE(iwl4965_rates); i++)
1508 if (iwl4965_rates[i].plcp == (plcp &0xFF))
1514 static u8 iwl4965_rate_get_lowest_plcp(int rate_mask)
1518 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
1519 i = iwl4965_rates[i].next_ieee) {
1520 if (rate_mask & (1 << i))
1521 return iwl4965_rates[i].plcp;
1524 return IWL_RATE_INVALID;
1527 static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv)
1529 struct iwl4965_frame *frame;
1530 unsigned int frame_size;
1534 frame = iwl4965_get_free_frame(priv);
1537 IWL_ERROR("Could not obtain free frame buffer for beacon "
1542 if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
1543 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic &
1545 if (rate == IWL_INVALID_RATE)
1546 rate = IWL_RATE_6M_PLCP;
1548 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
1549 if (rate == IWL_INVALID_RATE)
1550 rate = IWL_RATE_1M_PLCP;
1553 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
1555 rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
1558 iwl4965_free_frame(priv, frame);
1563 /******************************************************************************
1565 * EEPROM related functions
1567 ******************************************************************************/
1569 static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac)
1571 memcpy(mac, priv->eeprom.mac_address, 6);
1575 * iwl4965_eeprom_init - read EEPROM contents
1577 * Load the EEPROM from adapter into priv->eeprom
1579 * NOTE: This routine uses the non-debug IO access functions.
1581 int iwl4965_eeprom_init(struct iwl4965_priv *priv)
1583 u16 *e = (u16 *)&priv->eeprom;
1584 u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP);
1586 int sz = sizeof(priv->eeprom);
1591 /* The EEPROM structure has several padding buffers within it
1592 * and when adding new EEPROM maps is subject to programmer errors
1593 * which may be very difficult to identify without explicitly
1594 * checking the resulting size of the eeprom map. */
1595 BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
1597 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
1598 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
1602 rc = iwl4965_eeprom_acquire_semaphore(priv);
1604 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
1608 /* eeprom is an array of 16bit values */
1609 for (addr = 0; addr < sz; addr += sizeof(u16)) {
1610 _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1);
1611 _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
1613 for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
1614 i += IWL_EEPROM_ACCESS_DELAY) {
1615 r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG);
1616 if (r & CSR_EEPROM_REG_READ_VALID_MSK)
1618 udelay(IWL_EEPROM_ACCESS_DELAY);
1621 if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
1622 IWL_ERROR("Time out reading EEPROM[%d]", addr);
1626 e[addr / 2] = le16_to_cpu(r >> 16);
1631 iwl4965_eeprom_release_semaphore(priv);
1635 /******************************************************************************
1637 * Misc. internal state and helper functions
1639 ******************************************************************************/
1640 #ifdef CONFIG_IWL4965_DEBUG
1643 * iwl4965_report_frame - dump frame to syslog during debug sessions
1645 * You may hack this function to show different aspects of received frames,
1646 * including selective frame dumps.
1647 * group100 parameter selects whether to show 1 out of 100 good frames.
1649 * TODO: This was originally written for 3945, need to audit for
1650 * proper operation with 4965.
1652 void iwl4965_report_frame(struct iwl4965_priv *priv,
1653 struct iwl4965_rx_packet *pkt,
1654 struct ieee80211_hdr *header, int group100)
1657 u32 print_summary = 0;
1658 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
1675 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
1676 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
1677 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
1678 u8 *data = IWL_RX_DATA(pkt);
1681 fc = le16_to_cpu(header->frame_control);
1682 seq_ctl = le16_to_cpu(header->seq_ctrl);
1685 channel = le16_to_cpu(rx_hdr->channel);
1686 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
1687 rate_sym = rx_hdr->rate;
1688 length = le16_to_cpu(rx_hdr->len);
1690 /* end-of-frame status and timestamp */
1691 status = le32_to_cpu(rx_end->status);
1692 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
1693 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
1694 tsf = le64_to_cpu(rx_end->timestamp);
1696 /* signal statistics */
1697 rssi = rx_stats->rssi;
1698 agc = rx_stats->agc;
1699 sig_avg = le16_to_cpu(rx_stats->sig_avg);
1700 noise_diff = le16_to_cpu(rx_stats->noise_diff);
1702 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
1704 /* if data frame is to us and all is good,
1705 * (optionally) print summary for only 1 out of every 100 */
1706 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
1707 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
1710 print_summary = 1; /* print each frame */
1711 else if (priv->framecnt_to_us < 100) {
1712 priv->framecnt_to_us++;
1715 priv->framecnt_to_us = 0;
1720 /* print summary for all other frames */
1724 if (print_summary) {
1729 title = "100Frames";
1730 else if (fc & IEEE80211_FCTL_RETRY)
1732 else if (ieee80211_is_assoc_response(fc))
1734 else if (ieee80211_is_reassoc_response(fc))
1736 else if (ieee80211_is_probe_response(fc)) {
1738 print_dump = 1; /* dump frame contents */
1739 } else if (ieee80211_is_beacon(fc)) {
1741 print_dump = 1; /* dump frame contents */
1742 } else if (ieee80211_is_atim(fc))
1744 else if (ieee80211_is_auth(fc))
1746 else if (ieee80211_is_deauth(fc))
1748 else if (ieee80211_is_disassoc(fc))
1753 rate = iwl4965_rate_index_from_plcp(rate_sym);
1757 rate = iwl4965_rates[rate].ieee / 2;
1759 /* print frame summary.
1760 * MAC addresses show just the last byte (for brevity),
1761 * but you can hack it to show more, if you'd like to. */
1763 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
1764 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
1765 title, fc, header->addr1[5],
1766 length, rssi, channel, rate);
1768 /* src/dst addresses assume managed mode */
1769 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
1770 "src=0x%02x, rssi=%u, tim=%lu usec, "
1771 "phy=0x%02x, chnl=%d\n",
1772 title, fc, header->addr1[5],
1773 header->addr3[5], rssi,
1774 tsf_low - priv->scan_start_tsf,
1775 phy_flags, channel);
1779 iwl4965_print_hex_dump(IWL_DL_RX, data, length);
1783 static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv)
1785 if (priv->hw_setting.shared_virt)
1786 pci_free_consistent(priv->pci_dev,
1787 sizeof(struct iwl4965_shared),
1788 priv->hw_setting.shared_virt,
1789 priv->hw_setting.shared_phys);
1793 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1795 * return : set the bit for each supported rate insert in ie
1797 static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
1798 u16 basic_rate, int *left)
1800 u16 ret_rates = 0, bit;
1805 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1806 if (bit & supported_rate) {
1808 rates[*cnt] = iwl4965_rates[i].ieee |
1809 ((bit & basic_rate) ? 0x80 : 0x00);
1813 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
1821 #ifdef CONFIG_IWL4965_HT
1822 void static iwl4965_set_ht_capab(struct ieee80211_hw *hw,
1823 struct ieee80211_ht_capability *ht_cap,
1828 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1830 static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv,
1831 struct ieee80211_mgmt *frame,
1832 int left, int is_direct)
1836 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
1838 /* Make sure there is enough space for the probe request,
1839 * two mandatory IEs and the data */
1845 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1846 memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN);
1847 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
1848 memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN);
1849 frame->seq_ctrl = 0;
1851 /* fill in our indirect SSID IE */
1858 pos = &(frame->u.probe_req.variable[0]);
1859 *pos++ = WLAN_EID_SSID;
1862 /* fill in our direct SSID IE... */
1865 left -= 2 + priv->essid_len;
1868 /* ... fill it in... */
1869 *pos++ = WLAN_EID_SSID;
1870 *pos++ = priv->essid_len;
1871 memcpy(pos, priv->essid, priv->essid_len);
1872 pos += priv->essid_len;
1873 len += 2 + priv->essid_len;
1876 /* fill in supported rate */
1882 /* ... fill it in... */
1883 *pos++ = WLAN_EID_SUPP_RATES;
1886 /* exclude 60M rate */
1887 active_rates = priv->rates_mask;
1888 active_rates &= ~IWL_RATE_60M_MASK;
1890 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
1892 cck_rates = IWL_CCK_RATES_MASK & active_rates;
1893 ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
1894 active_rate_basic, &left);
1895 active_rates &= ~ret_rates;
1897 ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
1898 active_rate_basic, &left);
1899 active_rates &= ~ret_rates;
1903 if (active_rates == 0)
1906 /* fill in supported extended rate */
1911 /* ... fill it in... */
1912 *pos++ = WLAN_EID_EXT_SUPP_RATES;
1914 iwl4965_supported_rate_to_ie(pos, active_rates,
1915 active_rate_basic, &left);
1919 #ifdef CONFIG_IWL4965_HT
1920 if (is_direct && priv->is_ht_enabled) {
1921 u8 use_wide_chan = 1;
1923 if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ)
1926 *pos++ = WLAN_EID_HT_CAPABILITY;
1927 *pos++ = sizeof(struct ieee80211_ht_capability);
1928 iwl4965_set_ht_capab(NULL, (struct ieee80211_ht_capability *)pos,
1930 len += 2 + sizeof(struct ieee80211_ht_capability);
1932 #endif /*CONFIG_IWL4965_HT */
1941 #ifdef CONFIG_IWL4965_QOS
1942 static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv,
1943 struct iwl4965_qosparam_cmd *qos)
1946 return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM,
1947 sizeof(struct iwl4965_qosparam_cmd), qos);
1950 static void iwl4965_reset_qos(struct iwl4965_priv *priv)
1956 unsigned long flags;
1959 spin_lock_irqsave(&priv->lock, flags);
1960 priv->qos_data.qos_active = 0;
1962 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
1963 if (priv->qos_data.qos_enable)
1964 priv->qos_data.qos_active = 1;
1965 if (!(priv->active_rate & 0xfff0)) {
1969 } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
1970 if (priv->qos_data.qos_enable)
1971 priv->qos_data.qos_active = 1;
1972 } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
1977 if (priv->qos_data.qos_active)
1980 priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
1981 priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
1982 priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
1983 priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
1984 priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
1986 if (priv->qos_data.qos_active) {
1988 priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
1989 priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
1990 priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
1991 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
1992 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
1995 priv->qos_data.def_qos_parm.ac[i].cw_min =
1996 cpu_to_le16((cw_min + 1) / 2 - 1);
1997 priv->qos_data.def_qos_parm.ac[i].cw_max =
1998 cpu_to_le16(cw_max);
1999 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2001 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2004 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2006 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2009 priv->qos_data.def_qos_parm.ac[i].cw_min =
2010 cpu_to_le16((cw_min + 1) / 4 - 1);
2011 priv->qos_data.def_qos_parm.ac[i].cw_max =
2012 cpu_to_le16((cw_max + 1) / 2 - 1);
2013 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2014 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2016 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2019 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2022 for (i = 1; i < 4; i++) {
2023 priv->qos_data.def_qos_parm.ac[i].cw_min =
2024 cpu_to_le16(cw_min);
2025 priv->qos_data.def_qos_parm.ac[i].cw_max =
2026 cpu_to_le16(cw_max);
2027 priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
2028 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
2029 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2032 IWL_DEBUG_QOS("set QoS to default \n");
2034 spin_unlock_irqrestore(&priv->lock, flags);
2037 static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force)
2039 unsigned long flags;
2041 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2044 if (!priv->qos_data.qos_enable)
2047 spin_lock_irqsave(&priv->lock, flags);
2048 priv->qos_data.def_qos_parm.qos_flags = 0;
2050 if (priv->qos_data.qos_cap.q_AP.queue_request &&
2051 !priv->qos_data.qos_cap.q_AP.txop_request)
2052 priv->qos_data.def_qos_parm.qos_flags |=
2053 QOS_PARAM_FLG_TXOP_TYPE_MSK;
2054 if (priv->qos_data.qos_active)
2055 priv->qos_data.def_qos_parm.qos_flags |=
2056 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
2058 #ifdef CONFIG_IWL4965_HT
2059 if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht)
2060 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
2061 #endif /* CONFIG_IWL4965_HT */
2063 spin_unlock_irqrestore(&priv->lock, flags);
2065 if (force || iwl4965_is_associated(priv)) {
2066 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
2067 priv->qos_data.qos_active,
2068 priv->qos_data.def_qos_parm.qos_flags);
2070 iwl4965_send_qos_params_command(priv,
2071 &(priv->qos_data.def_qos_parm));
2075 #endif /* CONFIG_IWL4965_QOS */
2077 * Power management (not Tx power!) functions
2079 #define MSEC_TO_USEC 1024
2081 #define NOSLP __constant_cpu_to_le16(0), 0, 0
2082 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
2083 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
2084 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
2085 __constant_cpu_to_le32(X1), \
2086 __constant_cpu_to_le32(X2), \
2087 __constant_cpu_to_le32(X3), \
2088 __constant_cpu_to_le32(X4)}
2091 /* default power management (not Tx power) table values */
2093 static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = {
2094 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2095 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
2096 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
2097 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
2098 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
2099 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
2103 static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = {
2104 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2105 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
2106 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
2107 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
2108 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
2109 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
2110 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
2111 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
2112 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
2113 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
2116 int iwl4965_power_init_handle(struct iwl4965_priv *priv)
2119 struct iwl4965_power_mgr *pow_data;
2120 int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC;
2123 IWL_DEBUG_POWER("Initialize power \n");
2125 pow_data = &(priv->power_data);
2127 memset(pow_data, 0, sizeof(*pow_data));
2129 pow_data->active_index = IWL_POWER_RANGE_0;
2130 pow_data->dtim_val = 0xffff;
2132 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
2133 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
2135 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
2139 struct iwl4965_powertable_cmd *cmd;
2141 IWL_DEBUG_POWER("adjust power command flags\n");
2143 for (i = 0; i < IWL_POWER_AC; i++) {
2144 cmd = &pow_data->pwr_range_0[i].cmd;
2147 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
2149 cmd->flags |= IWL_POWER_PCI_PM_MSK;
2155 static int iwl4965_update_power_cmd(struct iwl4965_priv *priv,
2156 struct iwl4965_powertable_cmd *cmd, u32 mode)
2161 struct iwl4965_power_vec_entry *range;
2163 struct iwl4965_power_mgr *pow_data;
2165 if (mode > IWL_POWER_INDEX_5) {
2166 IWL_DEBUG_POWER("Error invalid power mode \n");
2169 pow_data = &(priv->power_data);
2171 if (pow_data->active_index == IWL_POWER_RANGE_0)
2172 range = &pow_data->pwr_range_0[0];
2174 range = &pow_data->pwr_range_1[1];
2176 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd));
2178 #ifdef IWL_MAC80211_DISABLE
2179 if (priv->assoc_network != NULL) {
2180 unsigned long flags;
2182 period = priv->assoc_network->tim.tim_period;
2184 #endif /*IWL_MAC80211_DISABLE */
2185 skip = range[mode].no_dtim;
2194 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
2196 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
2197 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
2198 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
2201 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
2202 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
2203 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
2206 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
2207 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
2208 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
2209 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
2210 le32_to_cpu(cmd->sleep_interval[0]),
2211 le32_to_cpu(cmd->sleep_interval[1]),
2212 le32_to_cpu(cmd->sleep_interval[2]),
2213 le32_to_cpu(cmd->sleep_interval[3]),
2214 le32_to_cpu(cmd->sleep_interval[4]));
2219 static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode)
2221 u32 uninitialized_var(final_mode);
2223 struct iwl4965_powertable_cmd cmd;
2225 /* If on battery, set to 3,
2226 * if plugged into AC power, set to CAM ("continuously aware mode"),
2227 * else user level */
2229 case IWL_POWER_BATTERY:
2230 final_mode = IWL_POWER_INDEX_3;
2233 final_mode = IWL_POWER_MODE_CAM;
2240 cmd.keep_alive_beacons = 0;
2242 iwl4965_update_power_cmd(priv, &cmd, final_mode);
2244 rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
2246 if (final_mode == IWL_POWER_MODE_CAM)
2247 clear_bit(STATUS_POWER_PMI, &priv->status);
2249 set_bit(STATUS_POWER_PMI, &priv->status);
2254 int iwl4965_is_network_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
2256 /* Filter incoming packets to determine if they are targeted toward
2257 * this network, discarding packets coming from ourselves */
2258 switch (priv->iw_mode) {
2259 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
2260 /* packets from our adapter are dropped (echo) */
2261 if (!compare_ether_addr(header->addr2, priv->mac_addr))
2263 /* {broad,multi}cast packets to our IBSS go through */
2264 if (is_multicast_ether_addr(header->addr1))
2265 return !compare_ether_addr(header->addr3, priv->bssid);
2266 /* packets to our adapter go through */
2267 return !compare_ether_addr(header->addr1, priv->mac_addr);
2268 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
2269 /* packets from our adapter are dropped (echo) */
2270 if (!compare_ether_addr(header->addr3, priv->mac_addr))
2272 /* {broad,multi}cast packets to our BSS go through */
2273 if (is_multicast_ether_addr(header->addr1))
2274 return !compare_ether_addr(header->addr2, priv->bssid);
2275 /* packets to our adapter go through */
2276 return !compare_ether_addr(header->addr1, priv->mac_addr);
2282 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2284 static const char *iwl4965_get_tx_fail_reason(u32 status)
2286 switch (status & TX_STATUS_MSK) {
2287 case TX_STATUS_SUCCESS:
2289 TX_STATUS_ENTRY(SHORT_LIMIT);
2290 TX_STATUS_ENTRY(LONG_LIMIT);
2291 TX_STATUS_ENTRY(FIFO_UNDERRUN);
2292 TX_STATUS_ENTRY(MGMNT_ABORT);
2293 TX_STATUS_ENTRY(NEXT_FRAG);
2294 TX_STATUS_ENTRY(LIFE_EXPIRE);
2295 TX_STATUS_ENTRY(DEST_PS);
2296 TX_STATUS_ENTRY(ABORTED);
2297 TX_STATUS_ENTRY(BT_RETRY);
2298 TX_STATUS_ENTRY(STA_INVALID);
2299 TX_STATUS_ENTRY(FRAG_DROPPED);
2300 TX_STATUS_ENTRY(TID_DISABLE);
2301 TX_STATUS_ENTRY(FRAME_FLUSHED);
2302 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
2303 TX_STATUS_ENTRY(TX_LOCKED);
2304 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
2311 * iwl4965_scan_cancel - Cancel any currently executing HW scan
2313 * NOTE: priv->mutex is not required before calling this function
2315 static int iwl4965_scan_cancel(struct iwl4965_priv *priv)
2317 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
2318 clear_bit(STATUS_SCANNING, &priv->status);
2322 if (test_bit(STATUS_SCANNING, &priv->status)) {
2323 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2324 IWL_DEBUG_SCAN("Queuing scan abort.\n");
2325 set_bit(STATUS_SCAN_ABORTING, &priv->status);
2326 queue_work(priv->workqueue, &priv->abort_scan);
2329 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2331 return test_bit(STATUS_SCANNING, &priv->status);
2338 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
2339 * @ms: amount of time to wait (in milliseconds) for scan to abort
2341 * NOTE: priv->mutex must be held before calling this function
2343 static int iwl4965_scan_cancel_timeout(struct iwl4965_priv *priv, unsigned long ms)
2345 unsigned long now = jiffies;
2348 ret = iwl4965_scan_cancel(priv);
2350 mutex_unlock(&priv->mutex);
2351 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
2352 test_bit(STATUS_SCANNING, &priv->status))
2354 mutex_lock(&priv->mutex);
2356 return test_bit(STATUS_SCANNING, &priv->status);
2362 static void iwl4965_sequence_reset(struct iwl4965_priv *priv)
2364 /* Reset ieee stats */
2366 /* We don't reset the net_device_stats (ieee->stats) on
2369 priv->last_seq_num = -1;
2370 priv->last_frag_num = -1;
2371 priv->last_packet_time = 0;
2373 iwl4965_scan_cancel(priv);
2376 #define MAX_UCODE_BEACON_INTERVAL 4096
2377 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2379 static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
2382 u16 beacon_factor = 0;
2385 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
2386 / MAX_UCODE_BEACON_INTERVAL;
2387 new_val = beacon_val / beacon_factor;
2389 return cpu_to_le16(new_val);
2392 static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv)
2394 u64 interval_tm_unit;
2396 unsigned long flags;
2397 struct ieee80211_conf *conf = NULL;
2400 conf = ieee80211_get_hw_conf(priv->hw);
2402 spin_lock_irqsave(&priv->lock, flags);
2403 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
2404 priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
2406 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
2408 tsf = priv->timestamp1;
2409 tsf = ((tsf << 32) | priv->timestamp0);
2411 beacon_int = priv->beacon_int;
2412 spin_unlock_irqrestore(&priv->lock, flags);
2414 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
2415 if (beacon_int == 0) {
2416 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
2417 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
2419 priv->rxon_timing.beacon_interval =
2420 cpu_to_le16(beacon_int);
2421 priv->rxon_timing.beacon_interval =
2422 iwl4965_adjust_beacon_interval(
2423 le16_to_cpu(priv->rxon_timing.beacon_interval));
2426 priv->rxon_timing.atim_window = 0;
2428 priv->rxon_timing.beacon_interval =
2429 iwl4965_adjust_beacon_interval(conf->beacon_int);
2430 /* TODO: we need to get atim_window from upper stack
2431 * for now we set to 0 */
2432 priv->rxon_timing.atim_window = 0;
2436 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
2437 result = do_div(tsf, interval_tm_unit);
2438 priv->rxon_timing.beacon_init_val =
2439 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
2442 ("beacon interval %d beacon timer %d beacon tim %d\n",
2443 le16_to_cpu(priv->rxon_timing.beacon_interval),
2444 le32_to_cpu(priv->rxon_timing.beacon_init_val),
2445 le16_to_cpu(priv->rxon_timing.atim_window));
2448 static int iwl4965_scan_initiate(struct iwl4965_priv *priv)
2450 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2451 IWL_ERROR("APs don't scan.\n");
2455 if (!iwl4965_is_ready_rf(priv)) {
2456 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2460 if (test_bit(STATUS_SCANNING, &priv->status)) {
2461 IWL_DEBUG_SCAN("Scan already in progress.\n");
2465 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2466 IWL_DEBUG_SCAN("Scan request while abort pending. "
2471 IWL_DEBUG_INFO("Starting scan...\n");
2472 priv->scan_bands = 2;
2473 set_bit(STATUS_SCANNING, &priv->status);
2474 priv->scan_start = jiffies;
2475 priv->scan_pass_start = priv->scan_start;
2477 queue_work(priv->workqueue, &priv->request_scan);
2482 static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv *priv, int hw_decrypt)
2484 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
2487 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
2489 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
2494 static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode)
2496 if (phymode == MODE_IEEE80211A) {
2497 priv->staging_rxon.flags &=
2498 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
2499 | RXON_FLG_CCK_MSK);
2500 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2502 /* Copied from iwl4965_bg_post_associate() */
2503 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2504 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2506 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2508 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2509 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2511 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
2512 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
2513 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
2518 * initialize rxon structure with default values from eeprom
2520 static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv)
2522 const struct iwl4965_channel_info *ch_info;
2524 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2526 switch (priv->iw_mode) {
2527 case IEEE80211_IF_TYPE_AP:
2528 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2531 case IEEE80211_IF_TYPE_STA:
2532 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
2533 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
2536 case IEEE80211_IF_TYPE_IBSS:
2537 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
2538 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
2539 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
2540 RXON_FILTER_ACCEPT_GRP_MSK;
2543 case IEEE80211_IF_TYPE_MNTR:
2544 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
2545 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
2546 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
2551 /* TODO: Figure out when short_preamble would be set and cache from
2553 if (!hw_to_local(priv->hw)->short_preamble)
2554 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2556 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2559 ch_info = iwl4965_get_channel_info(priv, priv->phymode,
2560 le16_to_cpu(priv->staging_rxon.channel));
2563 ch_info = &priv->channel_info[0];
2566 * in some case A channels are all non IBSS
2567 * in this case force B/G channel
2569 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2570 !(is_channel_ibss(ch_info)))
2571 ch_info = &priv->channel_info[0];
2573 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
2574 if (is_channel_a_band(ch_info))
2575 priv->phymode = MODE_IEEE80211A;
2577 priv->phymode = MODE_IEEE80211G;
2579 iwl4965_set_flags_for_phymode(priv, priv->phymode);
2581 priv->staging_rxon.ofdm_basic_rates =
2582 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2583 priv->staging_rxon.cck_basic_rates =
2584 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2586 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
2587 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
2588 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2589 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
2590 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
2591 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
2592 iwl4965_set_rxon_chain(priv);
2595 static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode)
2597 if (!iwl4965_is_ready_rf(priv))
2600 if (mode == IEEE80211_IF_TYPE_IBSS) {
2601 const struct iwl4965_channel_info *ch_info;
2603 ch_info = iwl4965_get_channel_info(priv,
2605 le16_to_cpu(priv->staging_rxon.channel));
2607 if (!ch_info || !is_channel_ibss(ch_info)) {
2608 IWL_ERROR("channel %d not IBSS channel\n",
2609 le16_to_cpu(priv->staging_rxon.channel));
2614 cancel_delayed_work(&priv->scan_check);
2615 if (iwl4965_scan_cancel_timeout(priv, 100)) {
2616 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2617 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2621 priv->iw_mode = mode;
2623 iwl4965_connection_init_rx_config(priv);
2624 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2626 iwl4965_clear_stations_table(priv);
2628 iwl4965_commit_rxon(priv);
2633 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv,
2634 struct ieee80211_tx_control *ctl,
2635 struct iwl4965_cmd *cmd,
2636 struct sk_buff *skb_frag,
2639 struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
2641 switch (keyinfo->alg) {
2643 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
2644 memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
2645 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2650 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
2653 memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
2656 memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
2661 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2662 (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2664 if (keyinfo->keylen == 13)
2665 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
2667 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2669 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2670 "with key %d\n", ctl->key_idx);
2674 printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
2680 * handle build REPLY_TX command notification.
2682 static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv,
2683 struct iwl4965_cmd *cmd,
2684 struct ieee80211_tx_control *ctrl,
2685 struct ieee80211_hdr *hdr,
2686 int is_unicast, u8 std_id)
2689 u16 fc = le16_to_cpu(hdr->frame_control);
2690 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2692 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2693 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
2694 tx_flags |= TX_CMD_FLG_ACK_MSK;
2695 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2696 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2697 if (ieee80211_is_probe_response(fc) &&
2698 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2699 tx_flags |= TX_CMD_FLG_TSF_MSK;
2701 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2702 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2705 cmd->cmd.tx.sta_id = std_id;
2706 if (ieee80211_get_morefrag(hdr))
2707 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2709 qc = ieee80211_get_qos_ctrl(hdr);
2711 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
2712 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2714 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2716 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
2717 tx_flags |= TX_CMD_FLG_RTS_MSK;
2718 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2719 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
2720 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2721 tx_flags |= TX_CMD_FLG_CTS_MSK;
2724 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2725 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2727 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2728 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2729 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
2730 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
2731 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
2733 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
2735 cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2737 cmd->cmd.tx.driver_txop = 0;
2738 cmd->cmd.tx.tx_flags = tx_flags;
2739 cmd->cmd.tx.next_frame_len = 0;
2742 static int iwl4965_get_sta_id(struct iwl4965_priv *priv,
2743 struct ieee80211_hdr *hdr)
2746 u16 fc = le16_to_cpu(hdr->frame_control);
2747 DECLARE_MAC_BUF(mac);
2749 /* If this frame is broadcast or not data then use the broadcast
2751 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2752 is_multicast_ether_addr(hdr->addr1))
2753 return priv->hw_setting.bcast_sta_id;
2755 switch (priv->iw_mode) {
2757 /* If this frame is part of a BSS network (we're a station), then
2758 * we use the AP's station id */
2759 case IEEE80211_IF_TYPE_STA:
2762 /* If we are an AP, then find the station, or use BCAST */
2763 case IEEE80211_IF_TYPE_AP:
2764 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
2765 if (sta_id != IWL_INVALID_STATION)
2767 return priv->hw_setting.bcast_sta_id;
2769 /* If this frame is part of a IBSS network, then we use the
2770 * target specific station id */
2771 case IEEE80211_IF_TYPE_IBSS:
2772 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
2773 if (sta_id != IWL_INVALID_STATION)
2776 sta_id = iwl4965_add_station_flags(priv, hdr->addr1, 0, CMD_ASYNC);
2778 if (sta_id != IWL_INVALID_STATION)
2781 IWL_DEBUG_DROP("Station %s not in station map. "
2782 "Defaulting to broadcast...\n",
2783 print_mac(mac, hdr->addr1));
2784 iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
2785 return priv->hw_setting.bcast_sta_id;
2788 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
2789 return priv->hw_setting.bcast_sta_id;
2794 * start REPLY_TX command process
2796 static int iwl4965_tx_skb(struct iwl4965_priv *priv,
2797 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2799 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2800 struct iwl4965_tfd_frame *tfd;
2802 int txq_id = ctl->queue;
2803 struct iwl4965_tx_queue *txq = NULL;
2804 struct iwl4965_queue *q = NULL;
2805 dma_addr_t phys_addr;
2806 dma_addr_t txcmd_phys;
2807 struct iwl4965_cmd *out_cmd = NULL;
2808 u16 len, idx, len_org;
2809 u8 id, hdr_len, unicast;
2814 u8 wait_write_ptr = 0;
2815 unsigned long flags;
2818 spin_lock_irqsave(&priv->lock, flags);
2819 if (iwl4965_is_rfkill(priv)) {
2820 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2824 if (!priv->interface_id) {
2825 IWL_DEBUG_DROP("Dropping - !priv->interface_id\n");
2829 if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) {
2830 IWL_ERROR("ERROR: No TX rate available.\n");
2834 unicast = !is_multicast_ether_addr(hdr->addr1);
2837 fc = le16_to_cpu(hdr->frame_control);
2839 #ifdef CONFIG_IWL4965_DEBUG
2840 if (ieee80211_is_auth(fc))
2841 IWL_DEBUG_TX("Sending AUTH frame\n");
2842 else if (ieee80211_is_assoc_request(fc))
2843 IWL_DEBUG_TX("Sending ASSOC frame\n");
2844 else if (ieee80211_is_reassoc_request(fc))
2845 IWL_DEBUG_TX("Sending REASSOC frame\n");
2848 if (!iwl4965_is_associated(priv) &&
2849 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
2850 IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n");
2854 spin_unlock_irqrestore(&priv->lock, flags);
2856 hdr_len = ieee80211_get_hdrlen(fc);
2857 sta_id = iwl4965_get_sta_id(priv, hdr);
2858 if (sta_id == IWL_INVALID_STATION) {
2859 DECLARE_MAC_BUF(mac);
2861 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2862 print_mac(mac, hdr->addr1));
2866 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2868 qc = ieee80211_get_qos_ctrl(hdr);
2870 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2871 seq_number = priv->stations[sta_id].tid[tid].seq_number &
2873 hdr->seq_ctrl = cpu_to_le16(seq_number) |
2875 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
2877 #ifdef CONFIG_IWL4965_HT
2878 #ifdef CONFIG_IWL4965_HT_AGG
2879 /* aggregation is on for this <sta,tid> */
2880 if (ctl->flags & IEEE80211_TXCTL_HT_MPDU_AGG)
2881 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
2882 #endif /* CONFIG_IWL4965_HT_AGG */
2883 #endif /* CONFIG_IWL4965_HT */
2885 txq = &priv->txq[txq_id];
2888 spin_lock_irqsave(&priv->lock, flags);
2890 tfd = &txq->bd[q->write_ptr];
2891 memset(tfd, 0, sizeof(*tfd));
2892 control_flags = (u32 *) tfd;
2893 idx = get_cmd_index(q, q->write_ptr, 0);
2895 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info));
2896 txq->txb[q->write_ptr].skb[0] = skb;
2897 memcpy(&(txq->txb[q->write_ptr].status.control),
2898 ctl, sizeof(struct ieee80211_tx_control));
2899 out_cmd = &txq->cmd[idx];
2900 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
2901 memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
2902 out_cmd->hdr.cmd = REPLY_TX;
2903 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
2904 INDEX_TO_SEQ(q->write_ptr)));
2905 /* copy frags header */
2906 memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
2908 /* hdr = (struct ieee80211_hdr *)out_cmd->cmd.tx.hdr; */
2909 len = priv->hw_setting.tx_cmd_len +
2910 sizeof(struct iwl4965_cmd_header) + hdr_len;
2913 len = (len + 3) & ~3;
2920 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx +
2921 offsetof(struct iwl4965_cmd, hdr);
2923 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
2925 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
2926 iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
2928 /* 802.11 null functions have no payload... */
2929 len = skb->len - hdr_len;
2931 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
2932 len, PCI_DMA_TODEVICE);
2933 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
2937 out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
2939 len = (u16)skb->len;
2940 out_cmd->cmd.tx.len = cpu_to_le16(len);
2942 /* TODO need this for burst mode later on */
2943 iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
2945 /* set is_hcca to 0; it probably will never be implemented */
2946 iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
2948 iwl4965_tx_cmd(priv, out_cmd, sta_id, txcmd_phys,
2949 hdr, hdr_len, ctl, NULL);
2951 if (!ieee80211_get_morefrag(hdr)) {
2952 txq->need_update = 1;
2954 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2955 priv->stations[sta_id].tid[tid].seq_number = seq_number;
2959 txq->need_update = 0;
2962 iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
2963 sizeof(out_cmd->cmd.tx));
2965 iwl4965_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
2966 ieee80211_get_hdrlen(fc));
2968 iwl4965_tx_queue_update_wr_ptr(priv, txq, len);
2970 q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
2971 rc = iwl4965_tx_queue_update_write_ptr(priv, txq);
2972 spin_unlock_irqrestore(&priv->lock, flags);
2977 if ((iwl4965_queue_space(q) < q->high_mark)
2978 && priv->mac80211_registered) {
2979 if (wait_write_ptr) {
2980 spin_lock_irqsave(&priv->lock, flags);
2981 txq->need_update = 1;
2982 iwl4965_tx_queue_update_write_ptr(priv, txq);
2983 spin_unlock_irqrestore(&priv->lock, flags);
2986 ieee80211_stop_queue(priv->hw, ctl->queue);
2992 spin_unlock_irqrestore(&priv->lock, flags);
2997 static void iwl4965_set_rate(struct iwl4965_priv *priv)
2999 const struct ieee80211_hw_mode *hw = NULL;
3000 struct ieee80211_rate *rate;
3003 hw = iwl4965_get_hw_mode(priv, priv->phymode);
3005 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
3009 priv->active_rate = 0;
3010 priv->active_rate_basic = 0;
3012 IWL_DEBUG_RATE("Setting rates for 802.11%c\n",
3013 hw->mode == MODE_IEEE80211A ?
3014 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g'));
3016 for (i = 0; i < hw->num_rates; i++) {
3017 rate = &(hw->rates[i]);
3018 if ((rate->val < IWL_RATE_COUNT) &&
3019 (rate->flags & IEEE80211_RATE_SUPPORTED)) {
3020 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
3021 rate->val, iwl4965_rates[rate->val].plcp,
3022 (rate->flags & IEEE80211_RATE_BASIC) ?
3024 priv->active_rate |= (1 << rate->val);
3025 if (rate->flags & IEEE80211_RATE_BASIC)
3026 priv->active_rate_basic |= (1 << rate->val);
3028 IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
3029 rate->val, iwl4965_rates[rate->val].plcp);
3032 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
3033 priv->active_rate, priv->active_rate_basic);
3036 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
3037 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
3040 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
3041 priv->staging_rxon.cck_basic_rates =
3042 ((priv->active_rate_basic &
3043 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
3045 priv->staging_rxon.cck_basic_rates =
3046 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
3048 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
3049 priv->staging_rxon.ofdm_basic_rates =
3050 ((priv->active_rate_basic &
3051 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
3052 IWL_FIRST_OFDM_RATE) & 0xFF;
3054 priv->staging_rxon.ofdm_basic_rates =
3055 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
3058 static void iwl4965_radio_kill_sw(struct iwl4965_priv *priv, int disable_radio)
3060 unsigned long flags;
3062 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
3065 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
3066 disable_radio ? "OFF" : "ON");
3068 if (disable_radio) {
3069 iwl4965_scan_cancel(priv);
3070 /* FIXME: This is a workaround for AP */
3071 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3072 spin_lock_irqsave(&priv->lock, flags);
3073 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
3074 CSR_UCODE_SW_BIT_RFKILL);
3075 spin_unlock_irqrestore(&priv->lock, flags);
3076 iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
3077 set_bit(STATUS_RF_KILL_SW, &priv->status);
3082 spin_lock_irqsave(&priv->lock, flags);
3083 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3085 clear_bit(STATUS_RF_KILL_SW, &priv->status);
3086 spin_unlock_irqrestore(&priv->lock, flags);
3091 spin_lock_irqsave(&priv->lock, flags);
3092 iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
3093 if (!iwl4965_grab_nic_access(priv))
3094 iwl4965_release_nic_access(priv);
3095 spin_unlock_irqrestore(&priv->lock, flags);
3097 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
3098 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
3099 "disabled by HW switch\n");
3103 queue_work(priv->workqueue, &priv->restart);
3107 void iwl4965_set_decrypted_flag(struct iwl4965_priv *priv, struct sk_buff *skb,
3108 u32 decrypt_res, struct ieee80211_rx_status *stats)
3111 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
3113 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
3116 if (!(fc & IEEE80211_FCTL_PROTECTED))
3119 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
3120 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
3121 case RX_RES_STATUS_SEC_TYPE_TKIP:
3122 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3123 RX_RES_STATUS_BAD_ICV_MIC)
3124 stats->flag |= RX_FLAG_MMIC_ERROR;
3125 case RX_RES_STATUS_SEC_TYPE_WEP:
3126 case RX_RES_STATUS_SEC_TYPE_CCMP:
3127 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3128 RX_RES_STATUS_DECRYPT_OK) {
3129 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
3130 stats->flag |= RX_FLAG_DECRYPTED;
3139 void iwl4965_handle_data_packet_monitor(struct iwl4965_priv *priv,
3140 struct iwl4965_rx_mem_buffer *rxb,
3141 void *data, short len,
3142 struct ieee80211_rx_status *stats,
3145 struct iwl4965_rt_rx_hdr *iwl4965_rt;
3147 /* First cache any information we need before we overwrite
3148 * the information provided in the skb from the hardware */
3149 s8 signal = stats->ssi;
3151 int rate = stats->rate;
3152 u64 tsf = stats->mactime;
3153 __le16 phy_flags_hw = cpu_to_le16(phy_flags);
3155 /* We received data from the HW, so stop the watchdog */
3156 if (len > IWL_RX_BUF_SIZE - sizeof(*iwl4965_rt)) {
3157 IWL_DEBUG_DROP("Dropping too large packet in monitor\n");
3161 /* copy the frame data to write after where the radiotap header goes */
3162 iwl4965_rt = (void *)rxb->skb->data;
3163 memmove(iwl4965_rt->payload, data, len);
3165 iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
3166 iwl4965_rt->rt_hdr.it_pad = 0; /* always good to zero */
3168 /* total header + data */
3169 iwl4965_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl4965_rt));
3171 /* Set the size of the skb to the size of the frame */
3172 skb_put(rxb->skb, sizeof(*iwl4965_rt) + len);
3174 /* Big bitfield of all the fields we provide in radiotap */
3175 iwl4965_rt->rt_hdr.it_present =
3176 cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
3177 (1 << IEEE80211_RADIOTAP_FLAGS) |
3178 (1 << IEEE80211_RADIOTAP_RATE) |
3179 (1 << IEEE80211_RADIOTAP_CHANNEL) |
3180 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
3181 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
3182 (1 << IEEE80211_RADIOTAP_ANTENNA));
3184 /* Zero the flags, we'll add to them as we go */
3185 iwl4965_rt->rt_flags = 0;
3187 iwl4965_rt->rt_tsf = cpu_to_le64(tsf);
3189 /* Convert to dBm */
3190 iwl4965_rt->rt_dbmsignal = signal;
3191 iwl4965_rt->rt_dbmnoise = noise;
3193 /* Convert the channel frequency and set the flags */
3194 iwl4965_rt->rt_channelMHz = cpu_to_le16(stats->freq);
3195 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
3196 iwl4965_rt->rt_chbitmask =
3197 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
3198 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
3199 iwl4965_rt->rt_chbitmask =
3200 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
3202 iwl4965_rt->rt_chbitmask =
3203 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ));
3205 rate = iwl4965_rate_index_from_plcp(rate);
3207 iwl4965_rt->rt_rate = 0;
3209 iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee;
3211 /* antenna number */
3212 iwl4965_rt->rt_antenna =
3213 le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
3215 /* set the preamble flag if we have it */
3216 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
3217 iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
3219 IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
3221 stats->flag |= RX_FLAG_RADIOTAP;
3222 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
3227 #define IWL_PACKET_RETRY_TIME HZ
3229 int iwl4965_is_duplicate_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
3231 u16 sc = le16_to_cpu(header->seq_ctrl);
3232 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
3233 u16 frag = sc & IEEE80211_SCTL_FRAG;
3234 u16 *last_seq, *last_frag;
3235 unsigned long *last_time;
3237 switch (priv->iw_mode) {
3238 case IEEE80211_IF_TYPE_IBSS:{
3239 struct list_head *p;
3240 struct iwl4965_ibss_seq *entry = NULL;
3241 u8 *mac = header->addr2;
3242 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
3244 __list_for_each(p, &priv->ibss_mac_hash[index]) {
3245 entry = list_entry(p, struct iwl4965_ibss_seq, list);
3246 if (!compare_ether_addr(entry->mac, mac))
3249 if (p == &priv->ibss_mac_hash[index]) {
3250 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
3252 IWL_ERROR("Cannot malloc new mac entry\n");
3255 memcpy(entry->mac, mac, ETH_ALEN);
3256 entry->seq_num = seq;
3257 entry->frag_num = frag;
3258 entry->packet_time = jiffies;
3259 list_add(&entry->list, &priv->ibss_mac_hash[index]);
3262 last_seq = &entry->seq_num;
3263 last_frag = &entry->frag_num;
3264 last_time = &entry->packet_time;
3267 case IEEE80211_IF_TYPE_STA:
3268 last_seq = &priv->last_seq_num;
3269 last_frag = &priv->last_frag_num;
3270 last_time = &priv->last_packet_time;
3275 if ((*last_seq == seq) &&
3276 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
3277 if (*last_frag == frag)
3279 if (*last_frag + 1 != frag)
3280 /* out-of-order fragment */
3286 *last_time = jiffies;
3293 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3295 #include "iwl-spectrum.h"
3297 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
3298 #define BEACON_TIME_MASK_HIGH 0xFF000000
3299 #define TIME_UNIT 1024
3302 * extended beacon time format
3303 * time in usec will be changed into a 32-bit value in 8:24 format
3304 * the high 1 byte is the beacon counts
3305 * the lower 3 bytes is the time in usec within one beacon interval
3308 static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
3312 u32 interval = beacon_interval * 1024;
3314 if (!interval || !usec)
3317 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
3318 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
3320 return (quot << 24) + rem;
3323 /* base is usually what we get from ucode with each received frame,
3324 * the same as HW timer counter counting down
3327 static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
3329 u32 base_low = base & BEACON_TIME_MASK_LOW;
3330 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
3331 u32 interval = beacon_interval * TIME_UNIT;
3332 u32 res = (base & BEACON_TIME_MASK_HIGH) +
3333 (addon & BEACON_TIME_MASK_HIGH);
3335 if (base_low > addon_low)
3336 res += base_low - addon_low;
3337 else if (base_low < addon_low) {
3338 res += interval + base_low - addon_low;
3343 return cpu_to_le32(res);
3346 static int iwl4965_get_measurement(struct iwl4965_priv *priv,
3347 struct ieee80211_measurement_params *params,
3350 struct iwl4965_spectrum_cmd spectrum;
3351 struct iwl4965_rx_packet *res;
3352 struct iwl4965_host_cmd cmd = {
3353 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
3354 .data = (void *)&spectrum,
3355 .meta.flags = CMD_WANT_SKB,
3357 u32 add_time = le64_to_cpu(params->start_time);
3359 int spectrum_resp_status;
3360 int duration = le16_to_cpu(params->duration);
3362 if (iwl4965_is_associated(priv))
3364 iwl4965_usecs_to_beacons(
3365 le64_to_cpu(params->start_time) - priv->last_tsf,
3366 le16_to_cpu(priv->rxon_timing.beacon_interval));
3368 memset(&spectrum, 0, sizeof(spectrum));
3370 spectrum.channel_count = cpu_to_le16(1);
3372 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
3373 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
3374 cmd.len = sizeof(spectrum);
3375 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
3377 if (iwl4965_is_associated(priv))
3378 spectrum.start_time =
3379 iwl4965_add_beacon_time(priv->last_beacon_time,
3381 le16_to_cpu(priv->rxon_timing.beacon_interval));
3383 spectrum.start_time = 0;
3385 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
3386 spectrum.channels[0].channel = params->channel;
3387 spectrum.channels[0].type = type;
3388 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
3389 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
3390 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
3392 rc = iwl4965_send_cmd_sync(priv, &cmd);
3396 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
3397 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
3398 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
3402 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
3403 switch (spectrum_resp_status) {
3404 case 0: /* Command will be handled */
3405 if (res->u.spectrum.id != 0xff) {
3407 ("Replaced existing measurement: %d\n",
3408 res->u.spectrum.id);
3409 priv->measurement_status &= ~MEASUREMENT_READY;
3411 priv->measurement_status |= MEASUREMENT_ACTIVE;
3415 case 1: /* Command will not be handled */
3420 dev_kfree_skb_any(cmd.meta.u.skb);
3426 static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv,
3427 struct iwl4965_tx_info *tx_sta)
3430 tx_sta->status.ack_signal = 0;
3431 tx_sta->status.excessive_retries = 0;
3432 tx_sta->status.queue_length = 0;
3433 tx_sta->status.queue_number = 0;
3436 ieee80211_tx_status_irqsafe(priv->hw,
3437 tx_sta->skb[0], &(tx_sta->status));
3439 ieee80211_tx_status(priv->hw,
3440 tx_sta->skb[0], &(tx_sta->status));
3442 tx_sta->skb[0] = NULL;
3446 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries no more used by NIC.
3448 * When FW advances 'R' index, all entries between old and
3449 * new 'R' index need to be reclaimed. As result, some free space
3450 * forms. If there is enough free space (> low mark), wake Tx queue.
3452 int iwl4965_tx_queue_reclaim(struct iwl4965_priv *priv, int txq_id, int index)
3454 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
3455 struct iwl4965_queue *q = &txq->q;
3458 if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
3459 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3460 "is out of range [0-%d] %d %d.\n", txq_id,
3461 index, q->n_bd, q->write_ptr, q->read_ptr);
3465 for (index = iwl4965_queue_inc_wrap(index, q->n_bd);
3466 q->read_ptr != index;
3467 q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) {
3468 if (txq_id != IWL_CMD_QUEUE_NUM) {
3469 iwl4965_txstatus_to_ieee(priv,
3470 &(txq->txb[txq->q.read_ptr]));
3471 iwl4965_hw_txq_free_tfd(priv, txq);
3472 } else if (nfreed > 1) {
3473 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
3474 q->write_ptr, q->read_ptr);
3475 queue_work(priv->workqueue, &priv->restart);
3480 if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
3481 (txq_id != IWL_CMD_QUEUE_NUM) &&
3482 priv->mac80211_registered)
3483 ieee80211_wake_queue(priv->hw, txq_id);
3489 static int iwl4965_is_tx_success(u32 status)
3491 status &= TX_STATUS_MSK;
3492 return (status == TX_STATUS_SUCCESS)
3493 || (status == TX_STATUS_DIRECT_DONE);
3496 /******************************************************************************
3498 * Generic RX handler implementations
3500 ******************************************************************************/
3501 #ifdef CONFIG_IWL4965_HT
3502 #ifdef CONFIG_IWL4965_HT_AGG
3504 static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv,
3505 struct ieee80211_hdr *hdr)
3507 if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
3510 u8 *da = ieee80211_get_DA(hdr);
3511 return iwl4965_hw_find_station(priv, da);
3515 static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
3516 struct iwl4965_priv *priv, int txq_id, int idx)
3518 if (priv->txq[txq_id].txb[idx].skb[0])
3519 return (struct ieee80211_hdr *)priv->txq[txq_id].
3520 txb[idx].skb[0]->data;
3524 static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
3526 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
3527 tx_resp->frame_count);
3528 return le32_to_cpu(*scd_ssn) & MAX_SN;
3531 static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv,
3532 struct iwl4965_ht_agg *agg,
3533 struct iwl4965_tx_resp *tx_resp,
3537 __le32 *frame_status = &tx_resp->status;
3538 struct ieee80211_tx_status *tx_status = NULL;
3539 struct ieee80211_hdr *hdr = NULL;
3544 if (agg->wait_for_ba)
3545 IWL_DEBUG_TX_REPLY("got tx repsons w/o back\n");
3547 agg->frame_count = tx_resp->frame_count;
3548 agg->start_idx = start_idx;
3549 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3550 agg->bitmap0 = agg->bitmap1 = 0;
3552 if (agg->frame_count == 1) {
3553 struct iwl4965_tx_queue *txq ;
3554 status = le32_to_cpu(frame_status[0]);
3556 txq_id = agg->txq_id;
3557 txq = &priv->txq[txq_id];
3558 /* FIXME: code repetition */
3559 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d \n",
3560 agg->frame_count, agg->start_idx);
3562 tx_status = &(priv->txq[txq_id].txb[txq->q.read_ptr].status);
3563 tx_status->retry_count = tx_resp->failure_frame;
3564 tx_status->queue_number = status & 0xff;
3565 tx_status->queue_length = tx_resp->bt_kill_count;
3566 tx_status->queue_length |= tx_resp->failure_rts;
3568 tx_status->flags = iwl4965_is_tx_success(status)?
3569 IEEE80211_TX_STATUS_ACK : 0;
3570 tx_status->control.tx_rate =
3571 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags);
3572 /* FIXME: code repetition end */
3574 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3575 status & 0xff, tx_resp->failure_frame);
3576 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
3577 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
3579 agg->wait_for_ba = 0;
3582 int start = agg->start_idx;
3584 for (i = 0; i < agg->frame_count; i++) {
3586 status = le32_to_cpu(frame_status[i]);
3588 idx = SEQ_TO_INDEX(seq);
3589 txq_id = SEQ_TO_QUEUE(seq);
3591 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3592 AGG_TX_STATE_ABORT_MSK))
3595 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3596 agg->frame_count, txq_id, idx);
3598 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
3600 sc = le16_to_cpu(hdr->seq_ctrl);
3601 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3602 IWL_ERROR("BUG_ON idx doesn't match seq control"
3603 " idx=%d, seq_idx=%d, seq=%d\n",
3609 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3610 i, idx, SEQ_TO_SN(sc));
3614 sh = (start - idx) + 0xff;
3615 bitmap = bitmap << sh;
3618 } else if (sh < -64)
3619 sh = 0xff - (start - idx);
3623 bitmap = bitmap << sh;
3626 bitmap |= (1 << sh);
3627 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3628 start, (u32)(bitmap & 0xFFFFFFFF));
3631 agg->bitmap0 = bitmap & 0xFFFFFFFF;
3632 agg->bitmap1 = bitmap >> 32;
3633 agg->start_idx = start;
3634 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3635 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%x\n",
3636 agg->frame_count, agg->start_idx,
3640 agg->wait_for_ba = 1;
3647 static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv,
3648 struct iwl4965_rx_mem_buffer *rxb)
3650 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3651 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3652 int txq_id = SEQ_TO_QUEUE(sequence);
3653 int index = SEQ_TO_INDEX(sequence);
3654 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
3655 struct ieee80211_tx_status *tx_status;
3656 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3657 u32 status = le32_to_cpu(tx_resp->status);
3658 #ifdef CONFIG_IWL4965_HT
3659 #ifdef CONFIG_IWL4965_HT_AGG
3664 if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
3665 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3666 "is out of range [0-%d] %d %d\n", txq_id,
3667 index, txq->q.n_bd, txq->q.write_ptr,
3672 #ifdef CONFIG_IWL4965_HT
3673 #ifdef CONFIG_IWL4965_HT_AGG
3674 if (txq->sched_retry) {
3675 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
3676 struct ieee80211_hdr *hdr =
3677 iwl4965_tx_queue_get_hdr(priv, txq_id, index);
3678 struct iwl4965_ht_agg *agg = NULL;
3679 __le16 *qc = ieee80211_get_qos_ctrl(hdr);
3682 IWL_ERROR("BUG_ON qc is null!!!!\n");
3686 tid = le16_to_cpu(*qc) & 0xf;
3688 sta_id = iwl4965_get_ra_sta_id(priv, hdr);
3689 if (unlikely(sta_id == IWL_INVALID_STATION)) {
3690 IWL_ERROR("Station not known for\n");
3694 agg = &priv->stations[sta_id].tid[tid].agg;
3696 iwl4965_tx_status_reply_tx(priv, agg, tx_resp, index);
3698 if ((tx_resp->frame_count == 1) &&
3699 !iwl4965_is_tx_success(status)) {
3700 /* TODO: send BAR */
3703 if ((txq->q.read_ptr != (scd_ssn & 0xff))) {
3704 index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
3705 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3706 "%d index %d\n", scd_ssn , index);
3707 iwl4965_tx_queue_reclaim(priv, txq_id, index);
3710 #endif /* CONFIG_IWL4965_HT_AGG */
3711 #endif /* CONFIG_IWL4965_HT */
3712 tx_status = &(txq->txb[txq->q.read_ptr].status);
3714 tx_status->retry_count = tx_resp->failure_frame;
3715 tx_status->queue_number = status;
3716 tx_status->queue_length = tx_resp->bt_kill_count;
3717 tx_status->queue_length |= tx_resp->failure_rts;
3720 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
3722 tx_status->control.tx_rate =
3723 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags);
3725 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3726 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
3727 status, le32_to_cpu(tx_resp->rate_n_flags),
3728 tx_resp->failure_frame);
3730 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3732 iwl4965_tx_queue_reclaim(priv, txq_id, index);
3733 #ifdef CONFIG_IWL4965_HT
3734 #ifdef CONFIG_IWL4965_HT_AGG
3736 #endif /* CONFIG_IWL4965_HT_AGG */
3737 #endif /* CONFIG_IWL4965_HT */
3739 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3740 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3744 static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv,
3745 struct iwl4965_rx_mem_buffer *rxb)
3747 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3748 struct iwl4965_alive_resp *palive;
3749 struct delayed_work *pwork;
3751 palive = &pkt->u.alive_frame;
3753 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3755 palive->is_valid, palive->ver_type,
3756 palive->ver_subtype);
3758 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
3759 IWL_DEBUG_INFO("Initialization Alive received.\n");
3760 memcpy(&priv->card_alive_init,
3761 &pkt->u.alive_frame,
3762 sizeof(struct iwl4965_init_alive_resp));
3763 pwork = &priv->init_alive_start;
3765 IWL_DEBUG_INFO("Runtime Alive received.\n");
3766 memcpy(&priv->card_alive, &pkt->u.alive_frame,
3767 sizeof(struct iwl4965_alive_resp));
3768 pwork = &priv->alive_start;
3771 /* We delay the ALIVE response by 5ms to
3772 * give the HW RF Kill time to activate... */
3773 if (palive->is_valid == UCODE_VALID_OK)
3774 queue_delayed_work(priv->workqueue, pwork,
3775 msecs_to_jiffies(5));
3777 IWL_WARNING("uCode did not respond OK.\n");
3780 static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv,
3781 struct iwl4965_rx_mem_buffer *rxb)
3783 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3785 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
3789 static void iwl4965_rx_reply_error(struct iwl4965_priv *priv,
3790 struct iwl4965_rx_mem_buffer *rxb)
3792 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3794 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3795 "seq 0x%04X ser 0x%08X\n",
3796 le32_to_cpu(pkt->u.err_resp.error_type),
3797 get_cmd_string(pkt->u.err_resp.cmd_id),
3798 pkt->u.err_resp.cmd_id,
3799 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
3800 le32_to_cpu(pkt->u.err_resp.error_info));
3803 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3805 static void iwl4965_rx_csa(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
3807 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3808 struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon;
3809 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
3810 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3811 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
3812 rxon->channel = csa->channel;
3813 priv->staging_rxon.channel = csa->channel;
3816 static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv,
3817 struct iwl4965_rx_mem_buffer *rxb)
3819 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3820 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3821 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
3823 if (!report->state) {
3824 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
3825 "Spectrum Measure Notification: Start\n");
3829 memcpy(&priv->measure_report, report, sizeof(*report));
3830 priv->measurement_status |= MEASUREMENT_READY;
3834 static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv,
3835 struct iwl4965_rx_mem_buffer *rxb)
3837 #ifdef CONFIG_IWL4965_DEBUG
3838 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3839 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
3840 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3841 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
3845 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv,
3846 struct iwl4965_rx_mem_buffer *rxb)
3848 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3849 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3850 "notification for %s:\n",
3851 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
3852 iwl4965_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
3855 static void iwl4965_bg_beacon_update(struct work_struct *work)
3857 struct iwl4965_priv *priv =
3858 container_of(work, struct iwl4965_priv, beacon_update);
3859 struct sk_buff *beacon;
3861 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3862 beacon = ieee80211_beacon_get(priv->hw, priv->interface_id, NULL);
3865 IWL_ERROR("update beacon failed\n");
3869 mutex_lock(&priv->mutex);
3870 /* new beacon skb is allocated every time; dispose previous.*/
3871 if (priv->ibss_beacon)
3872 dev_kfree_skb(priv->ibss_beacon);
3874 priv->ibss_beacon = beacon;
3875 mutex_unlock(&priv->mutex);
3877 iwl4965_send_beacon_cmd(priv);
3880 static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv,
3881 struct iwl4965_rx_mem_buffer *rxb)
3883 #ifdef CONFIG_IWL4965_DEBUG
3884 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3885 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
3886 u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
3888 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3889 "tsf %d %d rate %d\n",
3890 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
3891 beacon->beacon_notify_hdr.failure_frame,
3892 le32_to_cpu(beacon->ibss_mgr_status),
3893 le32_to_cpu(beacon->high_tsf),
3894 le32_to_cpu(beacon->low_tsf), rate);
3897 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
3898 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
3899 queue_work(priv->workqueue, &priv->beacon_update);
3902 /* Service response to REPLY_SCAN_CMD (0x80) */
3903 static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv,
3904 struct iwl4965_rx_mem_buffer *rxb)
3906 #ifdef CONFIG_IWL4965_DEBUG
3907 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3908 struct iwl4965_scanreq_notification *notif =
3909 (struct iwl4965_scanreq_notification *)pkt->u.raw;
3911 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
3915 /* Service SCAN_START_NOTIFICATION (0x82) */
3916 static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv,
3917 struct iwl4965_rx_mem_buffer *rxb)
3919 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3920 struct iwl4965_scanstart_notification *notif =
3921 (struct iwl4965_scanstart_notification *)pkt->u.raw;
3922 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
3923 IWL_DEBUG_SCAN("Scan start: "
3925 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3927 notif->band ? "bg" : "a",
3929 notif->tsf_low, notif->status, notif->beacon_timer);
3932 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3933 static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv,
3934 struct iwl4965_rx_mem_buffer *rxb)
3936 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3937 struct iwl4965_scanresults_notification *notif =
3938 (struct iwl4965_scanresults_notification *)pkt->u.raw;
3940 IWL_DEBUG_SCAN("Scan ch.res: "
3942 "(TSF: 0x%08X:%08X) - %d "
3943 "elapsed=%lu usec (%dms since last)\n",
3945 notif->band ? "bg" : "a",
3946 le32_to_cpu(notif->tsf_high),
3947 le32_to_cpu(notif->tsf_low),
3948 le32_to_cpu(notif->statistics[0]),
3949 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
3950 jiffies_to_msecs(elapsed_jiffies
3951 (priv->last_scan_jiffies, jiffies)));
3953 priv->last_scan_jiffies = jiffies;
3956 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3957 static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv,
3958 struct iwl4965_rx_mem_buffer *rxb)
3960 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3961 struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
3963 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3964 scan_notif->scanned_channels,
3965 scan_notif->tsf_low,
3966 scan_notif->tsf_high, scan_notif->status);
3968 /* The HW is no longer scanning */
3969 clear_bit(STATUS_SCAN_HW, &priv->status);
3971 /* The scan completion notification came in, so kill that timer... */
3972 cancel_delayed_work(&priv->scan_check);
3974 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3975 (priv->scan_bands == 2) ? "2.4" : "5.2",
3976 jiffies_to_msecs(elapsed_jiffies
3977 (priv->scan_pass_start, jiffies)));
3979 /* Remove this scanned band from the list
3980 * of pending bands to scan */
3983 /* If a request to abort was given, or the scan did not succeed
3984 * then we reset the scan state machine and terminate,
3985 * re-queuing another scan if one has been requested */
3986 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3987 IWL_DEBUG_INFO("Aborted scan completed.\n");
3988 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
3990 /* If there are more bands on this scan pass reschedule */
3991 if (priv->scan_bands > 0)
3995 priv->last_scan_jiffies = jiffies;
3996 IWL_DEBUG_INFO("Setting scan to off\n");
3998 clear_bit(STATUS_SCANNING, &priv->status);
4000 IWL_DEBUG_INFO("Scan took %dms\n",
4001 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
4003 queue_work(priv->workqueue, &priv->scan_completed);
4008 priv->scan_pass_start = jiffies;
4009 queue_work(priv->workqueue, &priv->request_scan);
4012 /* Handle notification from uCode that card's power state is changing
4013 * due to software, hardware, or critical temperature RFKILL */
4014 static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv,
4015 struct iwl4965_rx_mem_buffer *rxb)
4017 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4018 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
4019 unsigned long status = priv->status;
4021 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
4022 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
4023 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
4025 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
4026 RF_CARD_DISABLED)) {
4028 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
4029 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
4031 if (!iwl4965_grab_nic_access(priv)) {
4032 iwl4965_write_direct32(
4033 priv, HBUS_TARG_MBX_C,
4034 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
4036 iwl4965_release_nic_access(priv);
4039 if (!(flags & RXON_CARD_DISABLED)) {
4040 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
4041 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
4042 if (!iwl4965_grab_nic_access(priv)) {
4043 iwl4965_write_direct32(
4044 priv, HBUS_TARG_MBX_C,
4045 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
4047 iwl4965_release_nic_access(priv);
4051 if (flags & RF_CARD_DISABLED) {
4052 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
4053 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
4054 iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
4055 if (!iwl4965_grab_nic_access(priv))
4056 iwl4965_release_nic_access(priv);
4060 if (flags & HW_CARD_DISABLED)
4061 set_bit(STATUS_RF_KILL_HW, &priv->status);
4063 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4066 if (flags & SW_CARD_DISABLED)
4067 set_bit(STATUS_RF_KILL_SW, &priv->status);
4069 clear_bit(STATUS_RF_KILL_SW, &priv->status);
4071 if (!(flags & RXON_CARD_DISABLED))
4072 iwl4965_scan_cancel(priv);
4074 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
4075 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
4076 (test_bit(STATUS_RF_KILL_SW, &status) !=
4077 test_bit(STATUS_RF_KILL_SW, &priv->status)))
4078 queue_work(priv->workqueue, &priv->rf_kill);
4080 wake_up_interruptible(&priv->wait_command_queue);
4084 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
4086 * Setup the RX handlers for each of the reply types sent from the uCode
4089 * This function chains into the hardware specific files for them to setup
4090 * any hardware specific handlers as well.
4092 static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv)
4094 priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
4095 priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
4096 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
4097 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
4098 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
4099 iwl4965_rx_spectrum_measure_notif;
4100 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
4101 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
4102 iwl4965_rx_pm_debug_statistics_notif;
4103 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
4106 * The same handler is used for both the REPLY to a discrete
4107 * statistics request from the host as well as for the periodic
4108 * statistics notifications (after received beacons) from the uCode.
4110 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
4111 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
4113 priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
4114 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
4115 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
4116 iwl4965_rx_scan_results_notif;
4117 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
4118 iwl4965_rx_scan_complete_notif;
4119 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
4120 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
4122 /* Set up hardware specific Rx handlers */
4123 iwl4965_hw_rx_handler_setup(priv);
4127 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
4128 * @rxb: Rx buffer to reclaim
4130 * If an Rx buffer has an async callback associated with it the callback
4131 * will be executed. The attached skb (if present) will only be freed
4132 * if the callback returns 1
4134 static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv,
4135 struct iwl4965_rx_mem_buffer *rxb)
4137 struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
4138 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
4139 int txq_id = SEQ_TO_QUEUE(sequence);
4140 int index = SEQ_TO_INDEX(sequence);
4141 int huge = sequence & SEQ_HUGE_FRAME;
4143 struct iwl4965_cmd *cmd;
4145 /* If a Tx command is being handled and it isn't in the actual
4146 * command queue then there a command routing bug has been introduced
4147 * in the queue management code. */
4148 if (txq_id != IWL_CMD_QUEUE_NUM)
4149 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
4150 txq_id, pkt->hdr.cmd);
4151 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
4153 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
4154 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
4156 /* Input error checking is done when commands are added to queue. */
4157 if (cmd->meta.flags & CMD_WANT_SKB) {
4158 cmd->meta.source->u.skb = rxb->skb;
4160 } else if (cmd->meta.u.callback &&
4161 !cmd->meta.u.callback(priv, cmd, rxb->skb))
4164 iwl4965_tx_queue_reclaim(priv, txq_id, index);
4166 if (!(cmd->meta.flags & CMD_ASYNC)) {
4167 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4168 wake_up_interruptible(&priv->wait_command_queue);
4172 /************************** RX-FUNCTIONS ****************************/
4174 * Rx theory of operation
4176 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
4177 * each of which point to Receive Buffers to be filled by 4965. These get
4178 * used not only for Rx frames, but for any command response or notification
4179 * from the 4965. The driver and 4965 manage the Rx buffers by means
4180 * of indexes into the circular buffer.
4183 * The host/firmware share two index registers for managing the Rx buffers.
4185 * The READ index maps to the first position that the firmware may be writing
4186 * to -- the driver can read up to (but not including) this position and get
4188 * The READ index is managed by the firmware once the card is enabled.
4190 * The WRITE index maps to the last position the driver has read from -- the
4191 * position preceding WRITE is the last slot the firmware can place a packet.
4193 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4196 * During initialization, the host sets up the READ queue position to the first
4197 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4199 * When the firmware places a packet in a buffer, it will advance the READ index
4200 * and fire the RX interrupt. The driver can then query the READ index and
4201 * process as many packets as possible, moving the WRITE index forward as it
4202 * resets the Rx queue buffers with new memory.
4204 * The management in the driver is as follows:
4205 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
4206 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4207 * to replenish the iwl->rxq->rx_free.
4208 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
4209 * iwl->rxq is replenished and the READ INDEX is updated (updating the
4210 * 'processed' and 'read' driver indexes as well)
4211 * + A received packet is processed and handed to the kernel network stack,
4212 * detached from the iwl->rxq. The driver 'processed' index is updated.
4213 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
4214 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
4215 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
4216 * were enough free buffers and RX_STALLED is set it is cleared.
4221 * iwl4965_rx_queue_alloc() Allocates rx_free
4222 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
4223 * iwl4965_rx_queue_restock
4224 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
4225 * queue, updates firmware pointers, and updates
4226 * the WRITE index. If insufficient rx_free buffers
4227 * are available, schedules iwl4965_rx_replenish
4229 * -- enable interrupts --
4230 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
4231 * READ INDEX, detaching the SKB from the pool.
4232 * Moves the packet buffer from queue to rx_used.
4233 * Calls iwl4965_rx_queue_restock to refill any empty
4240 * iwl4965_rx_queue_space - Return number of free slots available in queue.
4242 static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q)
4244 int s = q->read - q->write;
4247 /* keep some buffer to not confuse full and empty queue */
4255 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
4257 int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv *priv, struct iwl4965_rx_queue *q)
4261 unsigned long flags;
4263 spin_lock_irqsave(&q->lock, flags);
4265 if (q->need_update == 0)
4268 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4269 reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
4271 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4272 iwl4965_set_bit(priv, CSR_GP_CNTRL,
4273 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4277 rc = iwl4965_grab_nic_access(priv);
4281 iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
4283 iwl4965_release_nic_access(priv);
4285 iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
4291 spin_unlock_irqrestore(&q->lock, flags);
4296 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
4298 static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv,
4299 dma_addr_t dma_addr)
4301 return cpu_to_le32((u32)(dma_addr >> 8));
4306 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
4308 * If there are slots in the RX queue that need to be restocked,
4309 * and we have free pre-allocated buffers, fill the ranks as much
4310 * as we can, pulling from rx_free.
4312 * This moves the 'write' index forward to catch up with 'processed', and
4313 * also updates the memory address in the firmware to reference the new
4316 static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv)
4318 struct iwl4965_rx_queue *rxq = &priv->rxq;
4319 struct list_head *element;
4320 struct iwl4965_rx_mem_buffer *rxb;
4321 unsigned long flags;
4324 spin_lock_irqsave(&rxq->lock, flags);
4325 write = rxq->write & ~0x7;
4326 while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
4327 element = rxq->rx_free.next;
4328 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
4330 rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr);
4331 rxq->queue[rxq->write] = rxb;
4332 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
4335 spin_unlock_irqrestore(&rxq->lock, flags);
4336 /* If the pre-allocated buffer pool is dropping low, schedule to
4338 if (rxq->free_count <= RX_LOW_WATERMARK)
4339 queue_work(priv->workqueue, &priv->rx_replenish);
4342 /* If we've added more space for the firmware to place data, tell it */
4343 if ((write != (rxq->write & ~0x7))
4344 || (abs(rxq->write - rxq->read) > 7)) {
4345 spin_lock_irqsave(&rxq->lock, flags);
4346 rxq->need_update = 1;
4347 spin_unlock_irqrestore(&rxq->lock, flags);
4348 rc = iwl4965_rx_queue_update_write_ptr(priv, rxq);
4357 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
4359 * When moving to rx_free an SKB is allocated for the slot.
4361 * Also restock the Rx queue via iwl4965_rx_queue_restock.
4362 * This is called as a scheduled work item (except for during initialization)
4364 void iwl4965_rx_replenish(void *data)
4366 struct iwl4965_priv *priv = data;
4367 struct iwl4965_rx_queue *rxq = &priv->rxq;
4368 struct list_head *element;
4369 struct iwl4965_rx_mem_buffer *rxb;
4370 unsigned long flags;
4371 spin_lock_irqsave(&rxq->lock, flags);
4372 while (!list_empty(&rxq->rx_used)) {
4373 element = rxq->rx_used.next;
4374 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
4376 alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC);
4378 if (net_ratelimit())
4379 printk(KERN_CRIT DRV_NAME
4380 ": Can not allocate SKB buffers\n");
4381 /* We don't reschedule replenish work here -- we will
4382 * call the restock method and if it still needs
4383 * more buffers it will schedule replenish */
4386 priv->alloc_rxb_skb++;
4389 pci_map_single(priv->pci_dev, rxb->skb->data,
4390 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4391 list_add_tail(&rxb->list, &rxq->rx_free);
4394 spin_unlock_irqrestore(&rxq->lock, flags);
4396 spin_lock_irqsave(&priv->lock, flags);
4397 iwl4965_rx_queue_restock(priv);
4398 spin_unlock_irqrestore(&priv->lock, flags);
4401 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4402 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
4403 * This free routine walks the list of POOL entries and if SKB is set to
4404 * non NULL it is unmapped and freed
4406 static void iwl4965_rx_queue_free(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
4409 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4410 if (rxq->pool[i].skb != NULL) {
4411 pci_unmap_single(priv->pci_dev,
4412 rxq->pool[i].dma_addr,
4413 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4414 dev_kfree_skb(rxq->pool[i].skb);
4418 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
4423 int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv)
4425 struct iwl4965_rx_queue *rxq = &priv->rxq;
4426 struct pci_dev *dev = priv->pci_dev;
4429 spin_lock_init(&rxq->lock);
4430 INIT_LIST_HEAD(&rxq->rx_free);
4431 INIT_LIST_HEAD(&rxq->rx_used);
4432 rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
4435 /* Fill the rx_used queue with _all_ of the Rx buffers */
4436 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4437 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4438 /* Set us so that we have processed and used all buffers, but have
4439 * not restocked the Rx queue with fresh buffers */
4440 rxq->read = rxq->write = 0;
4441 rxq->free_count = 0;
4442 rxq->need_update = 0;
4446 void iwl4965_rx_queue_reset(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
4448 unsigned long flags;
4450 spin_lock_irqsave(&rxq->lock, flags);
4451 INIT_LIST_HEAD(&rxq->rx_free);
4452 INIT_LIST_HEAD(&rxq->rx_used);
4453 /* Fill the rx_used queue with _all_ of the Rx buffers */
4454 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
4455 /* In the reset function, these buffers may have been allocated
4456 * to an SKB, so we need to unmap and free potential storage */
4457 if (rxq->pool[i].skb != NULL) {
4458 pci_unmap_single(priv->pci_dev,
4459 rxq->pool[i].dma_addr,
4460 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4461 priv->alloc_rxb_skb--;
4462 dev_kfree_skb(rxq->pool[i].skb);
4463 rxq->pool[i].skb = NULL;
4465 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4468 /* Set us so that we have processed and used all buffers, but have
4469 * not restocked the Rx queue with fresh buffers */
4470 rxq->read = rxq->write = 0;
4471 rxq->free_count = 0;
4472 spin_unlock_irqrestore(&rxq->lock, flags);
4475 /* Convert linear signal-to-noise ratio into dB */
4476 static u8 ratio2dB[100] = {
4477 /* 0 1 2 3 4 5 6 7 8 9 */
4478 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4479 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4480 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4481 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4482 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4483 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4484 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4485 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4486 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4487 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4490 /* Calculates a relative dB value from a ratio of linear
4491 * (i.e. not dB) signal levels.
4492 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4493 int iwl4965_calc_db_from_ratio(int sig_ratio)
4495 /* 1000:1 or higher just report as 60 dB */
4496 if (sig_ratio >= 1000)
4499 /* 100:1 or higher, divide by 10 and use table,
4500 * add 20 dB to make up for divide by 10 */
4501 if (sig_ratio >= 100)
4502 return (20 + (int)ratio2dB[sig_ratio/10]);
4504 /* We shouldn't see this */
4508 /* Use table for ratios 1:1 - 99:1 */
4509 return (int)ratio2dB[sig_ratio];
4512 #define PERFECT_RSSI (-20) /* dBm */
4513 #define WORST_RSSI (-95) /* dBm */
4514 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4516 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
4517 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4518 * about formulas used below. */
4519 int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
4522 int degradation = PERFECT_RSSI - rssi_dbm;
4524 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4525 * as indicator; formula is (signal dbm - noise dbm).
4526 * SNR at or above 40 is a great signal (100%).
4527 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4528 * Weakest usable signal is usually 10 - 15 dB SNR. */
4530 if (rssi_dbm - noise_dbm >= 40)
4532 else if (rssi_dbm < noise_dbm)
4534 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
4536 /* Else use just the signal level.
4537 * This formula is a least squares fit of data points collected and
4538 * compared with a reference system that had a percentage (%) display
4539 * for signal quality. */
4541 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
4542 (15 * RSSI_RANGE + 62 * degradation)) /
4543 (RSSI_RANGE * RSSI_RANGE);
4547 else if (sig_qual < 1)
4554 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
4556 * Uses the priv->rx_handlers callback function array to invoke
4557 * the appropriate handlers, including command responses,
4558 * frame-received notifications, and other notifications.
4560 static void iwl4965_rx_handle(struct iwl4965_priv *priv)
4562 struct iwl4965_rx_mem_buffer *rxb;
4563 struct iwl4965_rx_packet *pkt;
4564 struct iwl4965_rx_queue *rxq = &priv->rxq;
4567 unsigned long flags;
4569 r = iwl4965_hw_get_rx_read(priv);
4572 /* Rx interrupt, but nothing sent from uCode */
4574 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
4577 rxb = rxq->queue[i];
4579 /* If an RXB doesn't have a Rx queue slot associated with it,
4580 * then a bug has been introduced in the queue refilling
4581 * routines -- catch it here */
4582 BUG_ON(rxb == NULL);
4584 rxq->queue[i] = NULL;
4586 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
4588 PCI_DMA_FROMDEVICE);
4589 pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
4591 /* Reclaim a command buffer only if this packet is a response
4592 * to a (driver-originated) command.
4593 * If the packet (e.g. Rx frame) originated from uCode,
4594 * there is no command buffer to reclaim.
4595 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4596 * but apparently a few don't get set; catch them here. */
4597 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
4598 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
4599 (pkt->hdr.cmd != REPLY_4965_RX) &&
4600 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
4601 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
4602 (pkt->hdr.cmd != REPLY_TX);
4604 /* Based on type of command response or notification,
4605 * handle those that need handling via function in
4606 * rx_handlers table. See iwl4965_setup_rx_handlers() */
4607 if (priv->rx_handlers[pkt->hdr.cmd]) {
4608 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4609 "r = %d, i = %d, %s, 0x%02x\n", r, i,
4610 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
4611 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
4613 /* No handling needed */
4614 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4615 "r %d i %d No handler needed for %s, 0x%02x\n",
4616 r, i, get_cmd_string(pkt->hdr.cmd),
4621 /* Invoke any callbacks, transfer the skb to caller, and
4622 * fire off the (possibly) blocking iwl4965_send_cmd()
4623 * as we reclaim the driver command queue */
4624 if (rxb && rxb->skb)
4625 iwl4965_tx_cmd_complete(priv, rxb);
4627 IWL_WARNING("Claim null rxb?\n");
4630 /* For now we just don't re-use anything. We can tweak this
4631 * later to try and re-use notification packets and SKBs that
4632 * fail to Rx correctly */
4633 if (rxb->skb != NULL) {
4634 priv->alloc_rxb_skb--;
4635 dev_kfree_skb_any(rxb->skb);
4639 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
4640 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4641 spin_lock_irqsave(&rxq->lock, flags);
4642 list_add_tail(&rxb->list, &priv->rxq.rx_used);
4643 spin_unlock_irqrestore(&rxq->lock, flags);
4644 i = (i + 1) & RX_QUEUE_MASK;
4647 /* Backtrack one entry */
4649 iwl4965_rx_queue_restock(priv);
4652 static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
4653 struct iwl4965_tx_queue *txq)
4657 int txq_id = txq->q.id;
4659 if (txq->need_update == 0)
4662 /* if we're trying to save power */
4663 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4664 /* wake up nic if it's powered down ...
4665 * uCode will wake up, and interrupt us again, so next
4666 * time we'll skip this part. */
4667 reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
4669 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4670 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
4671 iwl4965_set_bit(priv, CSR_GP_CNTRL,
4672 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4676 /* restore this queue's parameters in nic hardware. */
4677 rc = iwl4965_grab_nic_access(priv);
4680 iwl4965_write_direct32(priv, HBUS_TARG_WRPTR,
4681 txq->q.write_ptr | (txq_id << 8));
4682 iwl4965_release_nic_access(priv);
4684 /* else not in power-save mode, uCode will never sleep when we're
4685 * trying to tx (during RFKILL, we're not trying to tx). */
4687 iwl4965_write32(priv, HBUS_TARG_WRPTR,
4688 txq->q.write_ptr | (txq_id << 8));
4690 txq->need_update = 0;
4695 #ifdef CONFIG_IWL4965_DEBUG
4696 static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon)
4698 DECLARE_MAC_BUF(mac);
4700 IWL_DEBUG_RADIO("RX CONFIG:\n");
4701 iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
4702 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
4703 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
4704 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4705 le32_to_cpu(rxon->filter_flags));
4706 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
4707 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4708 rxon->ofdm_basic_rates);
4709 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
4710 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4711 print_mac(mac, rxon->node_addr));
4712 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4713 print_mac(mac, rxon->bssid_addr));
4714 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
4718 static void iwl4965_enable_interrupts(struct iwl4965_priv *priv)
4720 IWL_DEBUG_ISR("Enabling interrupts\n");
4721 set_bit(STATUS_INT_ENABLED, &priv->status);
4722 iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
4725 static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv)
4727 clear_bit(STATUS_INT_ENABLED, &priv->status);
4729 /* disable interrupts from uCode/NIC to host */
4730 iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
4732 /* acknowledge/clear/reset any interrupts still pending
4733 * from uCode or flow handler (Rx/Tx DMA) */
4734 iwl4965_write32(priv, CSR_INT, 0xffffffff);
4735 iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
4736 IWL_DEBUG_ISR("Disabled interrupts\n");
4739 static const char *desc_lookup(int i)
4747 return "BAD_CHECKSUM";
4749 return "NMI_INTERRUPT";
4753 return "FATAL_ERROR";
4759 #define ERROR_START_OFFSET (1 * sizeof(u32))
4760 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4762 static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv)
4765 u32 desc, time, count, base, data1;
4766 u32 blink1, blink2, ilink1, ilink2;
4769 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
4771 if (!iwl4965_hw_valid_rtc_data_addr(base)) {
4772 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
4776 rc = iwl4965_grab_nic_access(priv);
4778 IWL_WARNING("Can not read from adapter at this time.\n");
4782 count = iwl4965_read_targ_mem(priv, base);
4784 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
4785 IWL_ERROR("Start IWL Error Log Dump:\n");
4786 IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
4787 priv->status, priv->config, count);
4790 desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32));
4791 blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32));
4792 blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32));
4793 ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32));
4794 ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32));
4795 data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32));
4796 data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32));
4797 line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32));
4798 time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32));
4800 IWL_ERROR("Desc Time "
4801 "data1 data2 line\n");
4802 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4803 desc_lookup(desc), desc, time, data1, data2, line);
4804 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4805 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
4808 iwl4965_release_nic_access(priv);
4811 #define EVENT_START_OFFSET (4 * sizeof(u32))
4814 * iwl4965_print_event_log - Dump error event log to syslog
4816 * NOTE: Must be called with iwl4965_grab_nic_access() already obtained!
4818 static void iwl4965_print_event_log(struct iwl4965_priv *priv, u32 start_idx,
4819 u32 num_events, u32 mode)
4822 u32 base; /* SRAM byte address of event log header */
4823 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
4824 u32 ptr; /* SRAM byte address of log data */
4825 u32 ev, time, data; /* event log data */
4827 if (num_events == 0)
4830 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4833 event_size = 2 * sizeof(u32);
4835 event_size = 3 * sizeof(u32);
4837 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
4839 /* "time" is actually "data" for mode 0 (no timestamp).
4840 * place event id # at far right for easier visual parsing. */
4841 for (i = 0; i < num_events; i++) {
4842 ev = iwl4965_read_targ_mem(priv, ptr);
4844 time = iwl4965_read_targ_mem(priv, ptr);
4847 IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
4849 data = iwl4965_read_targ_mem(priv, ptr);
4851 IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
4856 static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv)
4859 u32 base; /* SRAM byte address of event log header */
4860 u32 capacity; /* event log capacity in # entries */
4861 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
4862 u32 num_wraps; /* # times uCode wrapped to top of log */
4863 u32 next_entry; /* index of next entry to be written by uCode */
4864 u32 size; /* # entries that we'll print */
4866 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4867 if (!iwl4965_hw_valid_rtc_data_addr(base)) {
4868 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
4872 rc = iwl4965_grab_nic_access(priv);
4874 IWL_WARNING("Can not read from adapter at this time.\n");
4878 /* event log header */
4879 capacity = iwl4965_read_targ_mem(priv, base);
4880 mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32)));
4881 num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32)));
4882 next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32)));
4884 size = num_wraps ? capacity : next_entry;
4886 /* bail out if nothing in log */
4888 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4889 iwl4965_release_nic_access(priv);
4893 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4896 /* if uCode has wrapped back to top of log, start at the oldest entry,
4897 * i.e the next one that uCode would fill. */
4899 iwl4965_print_event_log(priv, next_entry,
4900 capacity - next_entry, mode);
4902 /* (then/else) start at top of log */
4903 iwl4965_print_event_log(priv, 0, next_entry, mode);
4905 iwl4965_release_nic_access(priv);
4909 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
4911 static void iwl4965_irq_handle_error(struct iwl4965_priv *priv)
4913 /* Set the FW error flag -- cleared on iwl4965_down */
4914 set_bit(STATUS_FW_ERROR, &priv->status);
4916 /* Cancel currently queued command. */
4917 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4919 #ifdef CONFIG_IWL4965_DEBUG
4920 if (iwl4965_debug_level & IWL_DL_FW_ERRORS) {
4921 iwl4965_dump_nic_error_log(priv);
4922 iwl4965_dump_nic_event_log(priv);
4923 iwl4965_print_rx_config_cmd(&priv->staging_rxon);
4927 wake_up_interruptible(&priv->wait_command_queue);
4929 /* Keep the restart process from trying to send host
4930 * commands by clearing the INIT status bit */
4931 clear_bit(STATUS_READY, &priv->status);
4933 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4934 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
4935 "Restarting adapter due to uCode error.\n");
4937 if (iwl4965_is_associated(priv)) {
4938 memcpy(&priv->recovery_rxon, &priv->active_rxon,
4939 sizeof(priv->recovery_rxon));
4940 priv->error_recovering = 1;
4942 queue_work(priv->workqueue, &priv->restart);
4946 static void iwl4965_error_recovery(struct iwl4965_priv *priv)
4948 unsigned long flags;
4950 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
4951 sizeof(priv->staging_rxon));
4952 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4953 iwl4965_commit_rxon(priv);
4955 iwl4965_rxon_add_station(priv, priv->bssid, 1);
4957 spin_lock_irqsave(&priv->lock, flags);
4958 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
4959 priv->error_recovering = 0;
4960 spin_unlock_irqrestore(&priv->lock, flags);
4963 static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
4965 u32 inta, handled = 0;
4967 unsigned long flags;
4968 #ifdef CONFIG_IWL4965_DEBUG
4972 spin_lock_irqsave(&priv->lock, flags);
4974 /* Ack/clear/reset pending uCode interrupts.
4975 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4976 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4977 inta = iwl4965_read32(priv, CSR_INT);
4978 iwl4965_write32(priv, CSR_INT, inta);
4980 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4981 * Any new interrupts that happen after this, either while we're
4982 * in this tasklet, or later, will show up in next ISR/tasklet. */
4983 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
4984 iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh);
4986 #ifdef CONFIG_IWL4965_DEBUG
4987 if (iwl4965_debug_level & IWL_DL_ISR) {
4988 /* just for debug */
4989 inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
4990 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4991 inta, inta_mask, inta_fh);
4995 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4996 * atomic, make sure that inta covers all the interrupts that
4997 * we've discovered, even if FH interrupt came in just after
4998 * reading CSR_INT. */
4999 if (inta_fh & CSR_FH_INT_RX_MASK)
5000 inta |= CSR_INT_BIT_FH_RX;
5001 if (inta_fh & CSR_FH_INT_TX_MASK)
5002 inta |= CSR_INT_BIT_FH_TX;
5004 /* Now service all interrupt bits discovered above. */
5005 if (inta & CSR_INT_BIT_HW_ERR) {
5006 IWL_ERROR("Microcode HW error detected. Restarting.\n");
5008 /* Tell the device to stop sending interrupts */
5009 iwl4965_disable_interrupts(priv);
5011 iwl4965_irq_handle_error(priv);
5013 handled |= CSR_INT_BIT_HW_ERR;
5015 spin_unlock_irqrestore(&priv->lock, flags);
5020 #ifdef CONFIG_IWL4965_DEBUG
5021 if (iwl4965_debug_level & (IWL_DL_ISR)) {
5022 /* NIC fires this, but we don't use it, redundant with WAKEUP */
5023 if (inta & CSR_INT_BIT_MAC_CLK_ACTV)
5024 IWL_DEBUG_ISR("Microcode started or stopped.\n");
5026 /* Alive notification via Rx interrupt will do the real work */
5027 if (inta & CSR_INT_BIT_ALIVE)
5028 IWL_DEBUG_ISR("Alive interrupt\n");
5031 /* Safely ignore these bits for debug checks below */
5032 inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE);
5034 /* HW RF KILL switch toggled */
5035 if (inta & CSR_INT_BIT_RF_KILL) {
5037 if (!(iwl4965_read32(priv, CSR_GP_CNTRL) &
5038 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
5041 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
5042 "RF_KILL bit toggled to %s.\n",
5043 hw_rf_kill ? "disable radio":"enable radio");
5045 /* Queue restart only if RF_KILL switch was set to "kill"
5046 * when we loaded driver, and is now set to "enable".
5047 * After we're Alive, RF_KILL gets handled by
5048 * iwl_rx_card_state_notif() */
5049 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
5050 clear_bit(STATUS_RF_KILL_HW, &priv->status);
5051 queue_work(priv->workqueue, &priv->restart);
5054 handled |= CSR_INT_BIT_RF_KILL;
5057 /* Chip got too hot and stopped itself */
5058 if (inta & CSR_INT_BIT_CT_KILL) {
5059 IWL_ERROR("Microcode CT kill error detected.\n");
5060 handled |= CSR_INT_BIT_CT_KILL;
5063 /* Error detected by uCode */
5064 if (inta & CSR_INT_BIT_SW_ERR) {
5065 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
5067 iwl4965_irq_handle_error(priv);
5068 handled |= CSR_INT_BIT_SW_ERR;
5071 /* uCode wakes up after power-down sleep */
5072 if (inta & CSR_INT_BIT_WAKEUP) {
5073 IWL_DEBUG_ISR("Wakeup interrupt\n");
5074 iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq);
5075 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]);
5076 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]);
5077 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]);
5078 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]);
5079 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]);
5080 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]);
5082 handled |= CSR_INT_BIT_WAKEUP;
5085 /* All uCode command responses, including Tx command responses,
5086 * Rx "responses" (frame-received notification), and other
5087 * notifications from uCode come through here*/
5088 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
5089 iwl4965_rx_handle(priv);
5090 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
5093 if (inta & CSR_INT_BIT_FH_TX) {
5094 IWL_DEBUG_ISR("Tx interrupt\n");
5095 handled |= CSR_INT_BIT_FH_TX;
5098 if (inta & ~handled)
5099 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
5101 if (inta & ~CSR_INI_SET_MASK) {
5102 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
5103 inta & ~CSR_INI_SET_MASK);
5104 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
5107 /* Re-enable all interrupts */
5108 iwl4965_enable_interrupts(priv);
5110 #ifdef CONFIG_IWL4965_DEBUG
5111 if (iwl4965_debug_level & (IWL_DL_ISR)) {
5112 inta = iwl4965_read32(priv, CSR_INT);
5113 inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
5114 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
5115 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
5116 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
5119 spin_unlock_irqrestore(&priv->lock, flags);
5122 static irqreturn_t iwl4965_isr(int irq, void *data)
5124 struct iwl4965_priv *priv = data;
5125 u32 inta, inta_mask;
5130 spin_lock(&priv->lock);
5132 /* Disable (but don't clear!) interrupts here to avoid
5133 * back-to-back ISRs and sporadic interrupts from our NIC.
5134 * If we have something to service, the tasklet will re-enable ints.
5135 * If we *don't* have something, we'll re-enable before leaving here. */
5136 inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */
5137 iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
5139 /* Discover which interrupts are active/pending */
5140 inta = iwl4965_read32(priv, CSR_INT);
5141 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
5143 /* Ignore interrupt if there's nothing in NIC to service.
5144 * This may be due to IRQ shared with another device,
5145 * or due to sporadic interrupts thrown from our NIC. */
5146 if (!inta && !inta_fh) {
5147 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
5151 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
5152 /* Hardware disappeared. It might have already raised
5154 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
5158 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
5159 inta, inta_mask, inta_fh);
5161 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
5162 tasklet_schedule(&priv->irq_tasklet);
5165 spin_unlock(&priv->lock);
5169 /* re-enable interrupts here since we don't have anything to service. */
5170 iwl4965_enable_interrupts(priv);
5171 spin_unlock(&priv->lock);
5175 /************************** EEPROM BANDS ****************************
5177 * The iwl4965_eeprom_band definitions below provide the mapping from the
5178 * EEPROM contents to the specific channel number supported for each
5181 * For example, iwl4965_priv->eeprom.band_3_channels[4] from the band_3
5182 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
5183 * The specific geography and calibration information for that channel
5184 * is contained in the eeprom map itself.
5186 * During init, we copy the eeprom information and channel map
5187 * information into priv->channel_info_24/52 and priv->channel_map_24/52
5189 * channel_map_24/52 provides the index in the channel_info array for a
5190 * given channel. We have to have two separate maps as there is channel
5191 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
5194 * A value of 0xff stored in the channel_map indicates that the channel
5195 * is not supported by the hardware at all.
5197 * A value of 0xfe in the channel_map indicates that the channel is not
5198 * valid for Tx with the current hardware. This means that
5199 * while the system can tune and receive on a given channel, it may not
5200 * be able to associate or transmit any frames on that
5201 * channel. There is no corresponding channel information for that
5204 *********************************************************************/
5207 static const u8 iwl4965_eeprom_band_1[14] = {
5208 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
5212 static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */
5213 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
5216 static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */
5217 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
5220 static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */
5221 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
5224 static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */
5225 145, 149, 153, 157, 161, 165
5228 static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */
5232 static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */
5233 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
5236 static void iwl4965_init_band_reference(const struct iwl4965_priv *priv,
5238 int *eeprom_ch_count,
5239 const struct iwl4965_eeprom_channel
5241 const u8 **eeprom_ch_index)
5244 case 1: /* 2.4GHz band */
5245 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1);
5246 *eeprom_ch_info = priv->eeprom.band_1_channels;
5247 *eeprom_ch_index = iwl4965_eeprom_band_1;
5249 case 2: /* 4.9GHz band */
5250 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2);
5251 *eeprom_ch_info = priv->eeprom.band_2_channels;
5252 *eeprom_ch_index = iwl4965_eeprom_band_2;
5254 case 3: /* 5.2GHz band */
5255 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3);
5256 *eeprom_ch_info = priv->eeprom.band_3_channels;
5257 *eeprom_ch_index = iwl4965_eeprom_band_3;
5259 case 4: /* 5.5GHz band */
5260 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4);
5261 *eeprom_ch_info = priv->eeprom.band_4_channels;
5262 *eeprom_ch_index = iwl4965_eeprom_band_4;
5264 case 5: /* 5.7GHz band */
5265 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5);
5266 *eeprom_ch_info = priv->eeprom.band_5_channels;
5267 *eeprom_ch_index = iwl4965_eeprom_band_5;
5269 case 6: /* 2.4GHz FAT channels */
5270 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6);
5271 *eeprom_ch_info = priv->eeprom.band_24_channels;
5272 *eeprom_ch_index = iwl4965_eeprom_band_6;
5274 case 7: /* 5 GHz FAT channels */
5275 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7);
5276 *eeprom_ch_info = priv->eeprom.band_52_channels;
5277 *eeprom_ch_index = iwl4965_eeprom_band_7;
5285 const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv,
5286 int phymode, u16 channel)
5291 case MODE_IEEE80211A:
5292 for (i = 14; i < priv->channel_count; i++) {
5293 if (priv->channel_info[i].channel == channel)
5294 return &priv->channel_info[i];
5298 case MODE_IEEE80211B:
5299 case MODE_IEEE80211G:
5300 if (channel >= 1 && channel <= 14)
5301 return &priv->channel_info[channel - 1];
5309 #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
5312 static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
5314 int eeprom_ch_count = 0;
5315 const u8 *eeprom_ch_index = NULL;
5316 const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL;
5318 struct iwl4965_channel_info *ch_info;
5320 if (priv->channel_count) {
5321 IWL_DEBUG_INFO("Channel map already initialized.\n");
5325 if (priv->eeprom.version < 0x2f) {
5326 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
5327 priv->eeprom.version);
5331 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
5333 priv->channel_count =
5334 ARRAY_SIZE(iwl4965_eeprom_band_1) +
5335 ARRAY_SIZE(iwl4965_eeprom_band_2) +
5336 ARRAY_SIZE(iwl4965_eeprom_band_3) +
5337 ARRAY_SIZE(iwl4965_eeprom_band_4) +
5338 ARRAY_SIZE(iwl4965_eeprom_band_5);
5340 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
5342 priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) *
5343 priv->channel_count, GFP_KERNEL);
5344 if (!priv->channel_info) {
5345 IWL_ERROR("Could not allocate channel_info\n");
5346 priv->channel_count = 0;
5350 ch_info = priv->channel_info;
5352 /* Loop through the 5 EEPROM bands adding them in order to the
5353 * channel map we maintain (that contains additional information than
5354 * what just in the EEPROM) */
5355 for (band = 1; band <= 5; band++) {
5357 iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
5358 &eeprom_ch_info, &eeprom_ch_index);
5360 /* Loop through each band adding each of the channels */
5361 for (ch = 0; ch < eeprom_ch_count; ch++) {
5362 ch_info->channel = eeprom_ch_index[ch];
5363 ch_info->phymode = (band == 1) ? MODE_IEEE80211B :
5366 /* permanently store EEPROM's channel regulatory flags
5367 * and max power in channel info database. */
5368 ch_info->eeprom = eeprom_ch_info[ch];
5370 /* Copy the run-time flags so they are there even on
5371 * invalid channels */
5372 ch_info->flags = eeprom_ch_info[ch].flags;
5374 if (!(is_channel_valid(ch_info))) {
5375 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
5379 is_channel_a_band(ch_info) ?
5385 /* Initialize regulatory-based run-time data */
5386 ch_info->max_power_avg = ch_info->curr_txpow =
5387 eeprom_ch_info[ch].max_power_avg;
5388 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
5389 ch_info->min_power = 0;
5391 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
5392 " %ddBm): Ad-Hoc %ssupported\n",
5394 is_channel_a_band(ch_info) ?
5396 CHECK_AND_PRINT(IBSS),
5397 CHECK_AND_PRINT(ACTIVE),
5398 CHECK_AND_PRINT(RADAR),
5399 CHECK_AND_PRINT(WIDE),
5400 CHECK_AND_PRINT(NARROW),
5401 CHECK_AND_PRINT(DFS),
5402 eeprom_ch_info[ch].flags,
5403 eeprom_ch_info[ch].max_power_avg,
5404 ((eeprom_ch_info[ch].
5405 flags & EEPROM_CHANNEL_IBSS)
5406 && !(eeprom_ch_info[ch].
5407 flags & EEPROM_CHANNEL_RADAR))
5410 /* Set the user_txpower_limit to the highest power
5411 * supported by any channel */
5412 if (eeprom_ch_info[ch].max_power_avg >
5413 priv->user_txpower_limit)
5414 priv->user_txpower_limit =
5415 eeprom_ch_info[ch].max_power_avg;
5421 for (band = 6; band <= 7; band++) {
5423 u8 fat_extension_chan;
5425 iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
5426 &eeprom_ch_info, &eeprom_ch_index);
5428 phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A;
5429 /* Loop through each band adding each of the channels */
5430 for (ch = 0; ch < eeprom_ch_count; ch++) {
5433 ((eeprom_ch_index[ch] == 5) ||
5434 (eeprom_ch_index[ch] == 6) ||
5435 (eeprom_ch_index[ch] == 7)))
5436 fat_extension_chan = HT_IE_EXT_CHANNEL_MAX;
5438 fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE;
5440 iwl4965_set_fat_chan_info(priv, phymode,
5441 eeprom_ch_index[ch],
5442 &(eeprom_ch_info[ch]),
5443 fat_extension_chan);
5445 iwl4965_set_fat_chan_info(priv, phymode,
5446 (eeprom_ch_index[ch] + 4),
5447 &(eeprom_ch_info[ch]),
5448 HT_IE_EXT_CHANNEL_BELOW);
5455 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
5456 * sending probe req. This should be set long enough to hear probe responses
5457 * from more than one AP. */
5458 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
5459 #define IWL_ACTIVE_DWELL_TIME_52 (10)
5461 /* For faster active scanning, scan will move to the next channel if fewer than
5462 * PLCP_QUIET_THRESH packets are heard on this channel within
5463 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
5464 * time if it's a quiet channel (nothing responded to our probe, and there's
5465 * no other traffic).
5466 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
5467 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
5468 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
5470 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
5471 * Must be set longer than active dwell time.
5472 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
5473 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
5474 #define IWL_PASSIVE_DWELL_TIME_52 (10)
5475 #define IWL_PASSIVE_DWELL_BASE (100)
5476 #define IWL_CHANNEL_TUNE_TIME 5
5478 static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv, int phymode)
5480 if (phymode == MODE_IEEE80211A)
5481 return IWL_ACTIVE_DWELL_TIME_52;
5483 return IWL_ACTIVE_DWELL_TIME_24;
5486 static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, int phymode)
5488 u16 active = iwl4965_get_active_dwell_time(priv, phymode);
5489 u16 passive = (phymode != MODE_IEEE80211A) ?
5490 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
5491 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
5493 if (iwl4965_is_associated(priv)) {
5494 /* If we're associated, we clamp the maximum passive
5495 * dwell time to be 98% of the beacon interval (minus
5496 * 2 * channel tune time) */
5497 passive = priv->beacon_int;
5498 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
5499 passive = IWL_PASSIVE_DWELL_BASE;
5500 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
5503 if (passive <= active)
5504 passive = active + 1;
5509 static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode,
5510 u8 is_active, u8 direct_mask,
5511 struct iwl4965_scan_channel *scan_ch)
5513 const struct ieee80211_channel *channels = NULL;
5514 const struct ieee80211_hw_mode *hw_mode;
5515 const struct iwl4965_channel_info *ch_info;
5516 u16 passive_dwell = 0;
5517 u16 active_dwell = 0;
5520 hw_mode = iwl4965_get_hw_mode(priv, phymode);
5524 channels = hw_mode->channels;
5526 active_dwell = iwl4965_get_active_dwell_time(priv, phymode);
5527 passive_dwell = iwl4965_get_passive_dwell_time(priv, phymode);
5529 for (i = 0, added = 0; i < hw_mode->num_channels; i++) {
5530 if (channels[i].chan ==
5531 le16_to_cpu(priv->active_rxon.channel)) {
5532 if (iwl4965_is_associated(priv)) {
5534 ("Skipping current channel %d\n",
5535 le16_to_cpu(priv->active_rxon.channel));
5538 } else if (priv->only_active_channel)
5541 scan_ch->channel = channels[i].chan;
5543 ch_info = iwl4965_get_channel_info(priv, phymode,
5545 if (!is_channel_valid(ch_info)) {
5546 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5551 if (!is_active || is_channel_passive(ch_info) ||
5552 !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN))
5553 scan_ch->type = 0; /* passive */
5555 scan_ch->type = 1; /* active */
5557 if (scan_ch->type & 1)
5558 scan_ch->type |= (direct_mask << 1);
5560 if (is_channel_narrow(ch_info))
5561 scan_ch->type |= (1 << 7);
5563 scan_ch->active_dwell = cpu_to_le16(active_dwell);
5564 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
5566 /* Set txpower levels to defaults */
5567 scan_ch->tpc.dsp_atten = 110;
5568 /* scan_pwr_info->tpc.dsp_atten; */
5570 /*scan_pwr_info->tpc.tx_gain; */
5571 if (phymode == MODE_IEEE80211A)
5572 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
5574 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
5575 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
5577 * scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3;
5581 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
5583 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
5584 (scan_ch->type & 1) ?
5585 active_dwell : passive_dwell);
5591 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
5595 static void iwl4965_reset_channel_flag(struct iwl4965_priv *priv)
5598 for (i = 0; i < 3; i++) {
5599 struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i];
5600 for (j = 0; j < hw_mode->num_channels; j++)
5601 hw_mode->channels[j].flag = hw_mode->channels[j].val;
5605 static void iwl4965_init_hw_rates(struct iwl4965_priv *priv,
5606 struct ieee80211_rate *rates)
5610 for (i = 0; i < IWL_RATE_COUNT; i++) {
5611 rates[i].rate = iwl4965_rates[i].ieee * 5;
5612 rates[i].val = i; /* Rate scaling will work on indexes */
5614 rates[i].flags = IEEE80211_RATE_SUPPORTED;
5615 /* Only OFDM have the bits-per-symbol set */
5616 if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE))
5617 rates[i].flags |= IEEE80211_RATE_OFDM;
5620 * If CCK 1M then set rate flag to CCK else CCK_2
5621 * which is CCK | PREAMBLE2
5623 rates[i].flags |= (iwl4965_rates[i].plcp == 10) ?
5624 IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2;
5627 /* Set up which ones are basic rates... */
5628 if (IWL_BASIC_RATES_MASK & (1 << i))
5629 rates[i].flags |= IEEE80211_RATE_BASIC;
5634 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
5636 static int iwl4965_init_geos(struct iwl4965_priv *priv)
5638 struct iwl4965_channel_info *ch;
5639 struct ieee80211_hw_mode *modes;
5640 struct ieee80211_channel *channels;
5641 struct ieee80211_channel *geo_ch;
5642 struct ieee80211_rate *rates;
5654 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5655 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5659 modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count,
5664 channels = kzalloc(sizeof(struct ieee80211_channel) *
5665 priv->channel_count, GFP_KERNEL);
5671 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
5684 /* 5.2GHz channels start after the 2.4GHz channels */
5685 modes[A].mode = MODE_IEEE80211A;
5686 modes[A].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
5687 modes[A].rates = rates;
5688 modes[A].num_rates = 8; /* just OFDM */
5689 modes[A].rates = &rates[4];
5690 modes[A].num_channels = 0;
5692 modes[B].mode = MODE_IEEE80211B;
5693 modes[B].channels = channels;
5694 modes[B].rates = rates;
5695 modes[B].num_rates = 4; /* just CCK */
5696 modes[B].num_channels = 0;
5698 modes[G].mode = MODE_IEEE80211G;
5699 modes[G].channels = channels;
5700 modes[G].rates = rates;
5701 modes[G].num_rates = 12; /* OFDM & CCK */
5702 modes[G].num_channels = 0;
5704 modes[G_11N].mode = MODE_IEEE80211G;
5705 modes[G_11N].channels = channels;
5706 modes[G_11N].num_rates = 13; /* OFDM & CCK */
5707 modes[G_11N].rates = rates;
5708 modes[G_11N].num_channels = 0;
5710 modes[A_11N].mode = MODE_IEEE80211A;
5711 modes[A_11N].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
5712 modes[A_11N].rates = &rates[4];
5713 modes[A_11N].num_rates = 9; /* just OFDM */
5714 modes[A_11N].num_channels = 0;
5716 priv->ieee_channels = channels;
5717 priv->ieee_rates = rates;
5719 iwl4965_init_hw_rates(priv, rates);
5721 for (i = 0, geo_ch = channels; i < priv->channel_count; i++) {
5722 ch = &priv->channel_info[i];
5724 if (!is_channel_valid(ch)) {
5725 IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
5727 ch->channel, is_channel_a_band(ch) ?
5732 if (is_channel_a_band(ch)) {
5733 geo_ch = &modes[A].channels[modes[A].num_channels++];
5734 modes[A_11N].num_channels++;
5736 geo_ch = &modes[B].channels[modes[B].num_channels++];
5737 modes[G].num_channels++;
5738 modes[G_11N].num_channels++;
5741 geo_ch->freq = ieee80211chan2mhz(ch->channel);
5742 geo_ch->chan = ch->channel;
5743 geo_ch->power_level = ch->max_power_avg;
5744 geo_ch->antenna_max = 0xff;
5746 if (is_channel_valid(ch)) {
5747 geo_ch->flag = IEEE80211_CHAN_W_SCAN;
5748 if (ch->flags & EEPROM_CHANNEL_IBSS)
5749 geo_ch->flag |= IEEE80211_CHAN_W_IBSS;
5751 if (ch->flags & EEPROM_CHANNEL_ACTIVE)
5752 geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN;
5754 if (ch->flags & EEPROM_CHANNEL_RADAR)
5755 geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT;
5757 if (ch->max_power_avg > priv->max_channel_txpower_limit)
5758 priv->max_channel_txpower_limit =
5762 geo_ch->val = geo_ch->flag;
5765 if ((modes[A].num_channels == 0) && priv->is_abg) {
5766 printk(KERN_INFO DRV_NAME
5767 ": Incorrectly detected BG card as ABG. Please send "
5768 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5769 priv->pci_dev->device, priv->pci_dev->subsystem_device);
5773 printk(KERN_INFO DRV_NAME
5774 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5775 modes[G].num_channels, modes[A].num_channels);
5778 * NOTE: We register these in preference of order -- the
5779 * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
5780 * a phymode based on rates or AP capabilities but seems to
5781 * configure it purely on if the channel being configured
5782 * is supported by a mode -- and the first match is taken
5785 if (modes[G].num_channels)
5786 ieee80211_register_hwmode(priv->hw, &modes[G]);
5787 if (modes[B].num_channels)
5788 ieee80211_register_hwmode(priv->hw, &modes[B]);
5789 if (modes[A].num_channels)
5790 ieee80211_register_hwmode(priv->hw, &modes[A]);
5792 priv->modes = modes;
5793 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5798 /******************************************************************************
5800 * uCode download functions
5802 ******************************************************************************/
5804 static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv)
5806 if (priv->ucode_code.v_addr != NULL) {
5807 pci_free_consistent(priv->pci_dev,
5808 priv->ucode_code.len,
5809 priv->ucode_code.v_addr,
5810 priv->ucode_code.p_addr);
5811 priv->ucode_code.v_addr = NULL;
5813 if (priv->ucode_data.v_addr != NULL) {
5814 pci_free_consistent(priv->pci_dev,
5815 priv->ucode_data.len,
5816 priv->ucode_data.v_addr,
5817 priv->ucode_data.p_addr);
5818 priv->ucode_data.v_addr = NULL;
5820 if (priv->ucode_data_backup.v_addr != NULL) {
5821 pci_free_consistent(priv->pci_dev,
5822 priv->ucode_data_backup.len,
5823 priv->ucode_data_backup.v_addr,
5824 priv->ucode_data_backup.p_addr);
5825 priv->ucode_data_backup.v_addr = NULL;
5827 if (priv->ucode_init.v_addr != NULL) {
5828 pci_free_consistent(priv->pci_dev,
5829 priv->ucode_init.len,
5830 priv->ucode_init.v_addr,
5831 priv->ucode_init.p_addr);
5832 priv->ucode_init.v_addr = NULL;
5834 if (priv->ucode_init_data.v_addr != NULL) {
5835 pci_free_consistent(priv->pci_dev,
5836 priv->ucode_init_data.len,
5837 priv->ucode_init_data.v_addr,
5838 priv->ucode_init_data.p_addr);
5839 priv->ucode_init_data.v_addr = NULL;
5841 if (priv->ucode_boot.v_addr != NULL) {
5842 pci_free_consistent(priv->pci_dev,
5843 priv->ucode_boot.len,
5844 priv->ucode_boot.v_addr,
5845 priv->ucode_boot.p_addr);
5846 priv->ucode_boot.v_addr = NULL;
5851 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
5852 * looking at all data.
5854 static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 * image,
5862 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5864 rc = iwl4965_grab_nic_access(priv);
5868 iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
5871 for (; len > 0; len -= sizeof(u32), image++) {
5872 /* read data comes through single port, auto-incr addr */
5873 /* NOTE: Use the debugless read so we don't flood kernel log
5874 * if IWL_DL_IO is set */
5875 val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
5876 if (val != le32_to_cpu(*image)) {
5877 IWL_ERROR("uCode INST section is invalid at "
5878 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5879 save_len - len, val, le32_to_cpu(*image));
5887 iwl4965_release_nic_access(priv);
5891 ("ucode image in INSTRUCTION memory is good\n");
5898 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
5899 * using sample data 100 bytes apart. If these sample points are good,
5900 * it's a pretty good bet that everything between them is good, too.
5902 static int iwl4965_verify_inst_sparse(struct iwl4965_priv *priv, __le32 *image, u32 len)
5909 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5911 rc = iwl4965_grab_nic_access(priv);
5915 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
5916 /* read data comes through single port, auto-incr addr */
5917 /* NOTE: Use the debugless read so we don't flood kernel log
5918 * if IWL_DL_IO is set */
5919 iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR,
5920 i + RTC_INST_LOWER_BOUND);
5921 val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
5922 if (val != le32_to_cpu(*image)) {
5923 #if 0 /* Enable this if you want to see details */
5924 IWL_ERROR("uCode INST section is invalid at "
5925 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5935 iwl4965_release_nic_access(priv);
5942 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
5943 * and verify its contents
5945 static int iwl4965_verify_ucode(struct iwl4965_priv *priv)
5952 image = (__le32 *)priv->ucode_boot.v_addr;
5953 len = priv->ucode_boot.len;
5954 rc = iwl4965_verify_inst_sparse(priv, image, len);
5956 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5960 /* Try initialize */
5961 image = (__le32 *)priv->ucode_init.v_addr;
5962 len = priv->ucode_init.len;
5963 rc = iwl4965_verify_inst_sparse(priv, image, len);
5965 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5969 /* Try runtime/protocol */
5970 image = (__le32 *)priv->ucode_code.v_addr;
5971 len = priv->ucode_code.len;
5972 rc = iwl4965_verify_inst_sparse(priv, image, len);
5974 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5978 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5980 /* Since nothing seems to match, show first several data entries in
5981 * instruction SRAM, so maybe visual inspection will give a clue.
5982 * Selection of bootstrap image (vs. other images) is arbitrary. */
5983 image = (__le32 *)priv->ucode_boot.v_addr;
5984 len = priv->ucode_boot.len;
5985 rc = iwl4965_verify_inst_full(priv, image, len);
5991 /* check contents of special bootstrap uCode SRAM */
5992 static int iwl4965_verify_bsm(struct iwl4965_priv *priv)
5994 __le32 *image = priv->ucode_boot.v_addr;
5995 u32 len = priv->ucode_boot.len;
5999 IWL_DEBUG_INFO("Begin verify bsm\n");
6001 /* verify BSM SRAM contents */
6002 val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG);
6003 for (reg = BSM_SRAM_LOWER_BOUND;
6004 reg < BSM_SRAM_LOWER_BOUND + len;
6005 reg += sizeof(u32), image ++) {
6006 val = iwl4965_read_prph(priv, reg);
6007 if (val != le32_to_cpu(*image)) {
6008 IWL_ERROR("BSM uCode verification failed at "
6009 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
6010 BSM_SRAM_LOWER_BOUND,
6011 reg - BSM_SRAM_LOWER_BOUND, len,
6012 val, le32_to_cpu(*image));
6017 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
6023 * iwl4965_load_bsm - Load bootstrap instructions
6027 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
6028 * in special SRAM that does not power down during RFKILL. When powering back
6029 * up after power-saving sleeps (or during initial uCode load), the BSM loads
6030 * the bootstrap program into the on-board processor, and starts it.
6032 * The bootstrap program loads (via DMA) instructions and data for a new
6033 * program from host DRAM locations indicated by the host driver in the
6034 * BSM_DRAM_* registers. Once the new program is loaded, it starts
6037 * When initializing the NIC, the host driver points the BSM to the
6038 * "initialize" uCode image. This uCode sets up some internal data, then
6039 * notifies host via "initialize alive" that it is complete.
6041 * The host then replaces the BSM_DRAM_* pointer values to point to the
6042 * normal runtime uCode instructions and a backup uCode data cache buffer
6043 * (filled initially with starting data values for the on-board processor),
6044 * then triggers the "initialize" uCode to load and launch the runtime uCode,
6045 * which begins normal operation.
6047 * When doing a power-save shutdown, runtime uCode saves data SRAM into
6048 * the backup data cache in DRAM before SRAM is powered down.
6050 * When powering back up, the BSM loads the bootstrap program. This reloads
6051 * the runtime uCode instructions and the backup data cache into SRAM,
6052 * and re-launches the runtime uCode from where it left off.
6054 static int iwl4965_load_bsm(struct iwl4965_priv *priv)
6056 __le32 *image = priv->ucode_boot.v_addr;
6057 u32 len = priv->ucode_boot.len;
6067 IWL_DEBUG_INFO("Begin load bsm\n");
6069 /* make sure bootstrap program is no larger than BSM's SRAM size */
6070 if (len > IWL_MAX_BSM_SIZE)
6073 /* Tell bootstrap uCode where to find the "Initialize" uCode
6074 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
6075 * NOTE: iwl4965_initialize_alive_start() will replace these values,
6076 * after the "initialize" uCode has run, to point to
6077 * runtime/protocol instructions and backup data cache. */
6078 pinst = priv->ucode_init.p_addr >> 4;
6079 pdata = priv->ucode_init_data.p_addr >> 4;
6080 inst_len = priv->ucode_init.len;
6081 data_len = priv->ucode_init_data.len;
6083 rc = iwl4965_grab_nic_access(priv);
6087 iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
6088 iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
6089 iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
6090 iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
6092 /* Fill BSM memory with bootstrap instructions */
6093 for (reg_offset = BSM_SRAM_LOWER_BOUND;
6094 reg_offset < BSM_SRAM_LOWER_BOUND + len;
6095 reg_offset += sizeof(u32), image++)
6096 _iwl4965_write_prph(priv, reg_offset,
6097 le32_to_cpu(*image));
6099 rc = iwl4965_verify_bsm(priv);
6101 iwl4965_release_nic_access(priv);
6105 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
6106 iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
6107 iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG,
6108 RTC_INST_LOWER_BOUND);
6109 iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
6111 /* Load bootstrap code into instruction SRAM now,
6112 * to prepare to load "initialize" uCode */
6113 iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
6114 BSM_WR_CTRL_REG_BIT_START);
6116 /* Wait for load of bootstrap uCode to finish */
6117 for (i = 0; i < 100; i++) {
6118 done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG);
6119 if (!(done & BSM_WR_CTRL_REG_BIT_START))
6124 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
6126 IWL_ERROR("BSM write did not complete!\n");
6130 /* Enable future boot loads whenever power management unit triggers it
6131 * (e.g. when powering back up after power-save shutdown) */
6132 iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
6133 BSM_WR_CTRL_REG_BIT_START_EN);
6135 iwl4965_release_nic_access(priv);
6140 static void iwl4965_nic_start(struct iwl4965_priv *priv)
6142 /* Remove all resets to allow NIC to operate */
6143 iwl4965_write32(priv, CSR_RESET, 0);
6146 static int iwl4965_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc)
6148 desc->v_addr = pci_alloc_consistent(pci_dev, desc->len, &desc->p_addr);
6149 return (desc->v_addr != NULL) ? 0 : -ENOMEM;
6153 * iwl4965_read_ucode - Read uCode images from disk file.
6155 * Copy into buffers for card to fetch via bus-mastering
6157 static int iwl4965_read_ucode(struct iwl4965_priv *priv)
6159 struct iwl4965_ucode *ucode;
6161 const struct firmware *ucode_raw;
6162 const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode";
6165 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
6167 /* Ask kernel firmware_class module to get the boot firmware off disk.
6168 * request_firmware() is synchronous, file is in memory on return. */
6169 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
6171 IWL_ERROR("%s firmware file req failed: Reason %d\n",
6176 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
6177 name, ucode_raw->size);
6179 /* Make sure that we got at least our header! */
6180 if (ucode_raw->size < sizeof(*ucode)) {
6181 IWL_ERROR("File size way too small!\n");
6186 /* Data from ucode file: header followed by uCode images */
6187 ucode = (void *)ucode_raw->data;
6189 ver = le32_to_cpu(ucode->ver);
6190 inst_size = le32_to_cpu(ucode->inst_size);
6191 data_size = le32_to_cpu(ucode->data_size);
6192 init_size = le32_to_cpu(ucode->init_size);
6193 init_data_size = le32_to_cpu(ucode->init_data_size);
6194 boot_size = le32_to_cpu(ucode->boot_size);
6196 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
6197 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
6199 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
6201 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
6203 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
6205 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
6208 /* Verify size of file vs. image size info in file's header */
6209 if (ucode_raw->size < sizeof(*ucode) +
6210 inst_size + data_size + init_size +
6211 init_data_size + boot_size) {
6213 IWL_DEBUG_INFO("uCode file size %d too small\n",
6214 (int)ucode_raw->size);
6219 /* Verify that uCode images will fit in card's SRAM */
6220 if (inst_size > IWL_MAX_INST_SIZE) {
6221 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
6227 if (data_size > IWL_MAX_DATA_SIZE) {
6228 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
6233 if (init_size > IWL_MAX_INST_SIZE) {
6235 ("uCode init instr len %d too large to fit in\n",
6240 if (init_data_size > IWL_MAX_DATA_SIZE) {
6242 ("uCode init data len %d too large to fit in\n",
6247 if (boot_size > IWL_MAX_BSM_SIZE) {
6249 ("uCode boot instr len %d too large to fit in\n",
6255 /* Allocate ucode buffers for card's bus-master loading ... */
6257 /* Runtime instructions and 2 copies of data:
6258 * 1) unmodified from disk
6259 * 2) backup cache for save/restore during power-downs */
6260 priv->ucode_code.len = inst_size;
6261 iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
6263 priv->ucode_data.len = data_size;
6264 iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
6266 priv->ucode_data_backup.len = data_size;
6267 iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
6269 /* Initialization instructions and data */
6270 if (init_size && init_data_size) {
6271 priv->ucode_init.len = init_size;
6272 iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
6274 priv->ucode_init_data.len = init_data_size;
6275 iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
6277 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
6281 /* Bootstrap (instructions only, no data) */
6283 priv->ucode_boot.len = boot_size;
6284 iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
6286 if (!priv->ucode_boot.v_addr)
6290 /* Copy images into buffers for card's bus-master reads ... */
6292 /* Runtime instructions (first block of data in file) */
6293 src = &ucode->data[0];
6294 len = priv->ucode_code.len;
6295 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
6296 memcpy(priv->ucode_code.v_addr, src, len);
6297 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
6298 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
6300 /* Runtime data (2nd block)
6301 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
6302 src = &ucode->data[inst_size];
6303 len = priv->ucode_data.len;
6304 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
6305 memcpy(priv->ucode_data.v_addr, src, len);
6306 memcpy(priv->ucode_data_backup.v_addr, src, len);
6308 /* Initialization instructions (3rd block) */
6310 src = &ucode->data[inst_size + data_size];
6311 len = priv->ucode_init.len;
6312 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
6314 memcpy(priv->ucode_init.v_addr, src, len);
6317 /* Initialization data (4th block) */
6318 if (init_data_size) {
6319 src = &ucode->data[inst_size + data_size + init_size];
6320 len = priv->ucode_init_data.len;
6321 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
6323 memcpy(priv->ucode_init_data.v_addr, src, len);
6326 /* Bootstrap instructions (5th block) */
6327 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
6328 len = priv->ucode_boot.len;
6329 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
6330 memcpy(priv->ucode_boot.v_addr, src, len);
6332 /* We have our copies now, allow OS release its copies */
6333 release_firmware(ucode_raw);
6337 IWL_ERROR("failed to allocate pci memory\n");
6339 iwl4965_dealloc_ucode_pci(priv);
6342 release_firmware(ucode_raw);
6350 * iwl4965_set_ucode_ptrs - Set uCode address location
6352 * Tell initialization uCode where to find runtime uCode.
6354 * BSM registers initially contain pointers to initialization uCode.
6355 * We need to replace them to load runtime uCode inst and data,
6356 * and to save runtime data when powering down.
6358 static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv)
6363 unsigned long flags;
6365 /* bits 35:4 for 4965 */
6366 pinst = priv->ucode_code.p_addr >> 4;
6367 pdata = priv->ucode_data_backup.p_addr >> 4;
6369 spin_lock_irqsave(&priv->lock, flags);
6370 rc = iwl4965_grab_nic_access(priv);
6372 spin_unlock_irqrestore(&priv->lock, flags);
6376 /* Tell bootstrap uCode where to find image to load */
6377 iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
6378 iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
6379 iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
6380 priv->ucode_data.len);
6382 /* Inst bytecount must be last to set up, bit 31 signals uCode
6383 * that all new ptr/size info is in place */
6384 iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
6385 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
6387 iwl4965_release_nic_access(priv);
6389 spin_unlock_irqrestore(&priv->lock, flags);
6391 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
6397 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
6399 * Called after REPLY_ALIVE notification received from "initialize" uCode.
6401 * The 4965 "initialize" ALIVE reply contains calibration data for:
6402 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
6403 * (3945 does not contain this data).
6405 * Tell "initialize" uCode to go ahead and load the runtime uCode.
6407 static void iwl4965_init_alive_start(struct iwl4965_priv *priv)
6409 /* Check alive response for "valid" sign from uCode */
6410 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
6411 /* We had an error bringing up the hardware, so take it
6412 * all the way back down so we can try again */
6413 IWL_DEBUG_INFO("Initialize Alive failed.\n");
6417 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
6418 * This is a paranoid check, because we would not have gotten the
6419 * "initialize" alive if code weren't properly loaded. */
6420 if (iwl4965_verify_ucode(priv)) {
6421 /* Runtime instruction load was bad;
6422 * take it all the way back down so we can try again */
6423 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
6427 /* Calculate temperature */
6428 priv->temperature = iwl4965_get_temperature(priv);
6430 /* Send pointers to protocol/runtime uCode image ... init code will
6431 * load and launch runtime uCode, which will send us another "Alive"
6433 IWL_DEBUG_INFO("Initialization Alive received.\n");
6434 if (iwl4965_set_ucode_ptrs(priv)) {
6435 /* Runtime instruction load won't happen;
6436 * take it all the way back down so we can try again */
6437 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
6443 queue_work(priv->workqueue, &priv->restart);
6448 * iwl4965_alive_start - called after REPLY_ALIVE notification received
6449 * from protocol/runtime uCode (initialization uCode's
6450 * Alive gets handled by iwl4965_init_alive_start()).
6452 static void iwl4965_alive_start(struct iwl4965_priv *priv)
6456 IWL_DEBUG_INFO("Runtime Alive received.\n");
6458 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
6459 /* We had an error bringing up the hardware, so take it
6460 * all the way back down so we can try again */
6461 IWL_DEBUG_INFO("Alive failed.\n");
6465 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
6466 * This is a paranoid check, because we would not have gotten the
6467 * "runtime" alive if code weren't properly loaded. */
6468 if (iwl4965_verify_ucode(priv)) {
6469 /* Runtime instruction load was bad;
6470 * take it all the way back down so we can try again */
6471 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
6475 iwl4965_clear_stations_table(priv);
6477 rc = iwl4965_alive_notify(priv);
6479 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
6484 /* After the ALIVE response, we can send host commands to 4965 uCode */
6485 set_bit(STATUS_ALIVE, &priv->status);
6487 /* Clear out the uCode error bit if it is set */
6488 clear_bit(STATUS_FW_ERROR, &priv->status);
6490 rc = iwl4965_init_channel_map(priv);
6492 IWL_ERROR("initializing regulatory failed: %d\n", rc);
6496 iwl4965_init_geos(priv);
6498 if (iwl4965_is_rfkill(priv))
6501 if (!priv->mac80211_registered) {
6502 /* Unlock so any user space entry points can call back into
6503 * the driver without a deadlock... */
6504 mutex_unlock(&priv->mutex);
6505 iwl4965_rate_control_register(priv->hw);
6506 rc = ieee80211_register_hw(priv->hw);
6507 priv->hw->conf.beacon_int = 100;
6508 mutex_lock(&priv->mutex);
6511 iwl4965_rate_control_unregister(priv->hw);
6512 IWL_ERROR("Failed to register network "
6513 "device (error %d)\n", rc);
6517 priv->mac80211_registered = 1;
6519 iwl4965_reset_channel_flag(priv);
6521 ieee80211_start_queues(priv->hw);
6523 priv->active_rate = priv->rates_mask;
6524 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
6526 iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
6528 if (iwl4965_is_associated(priv)) {
6529 struct iwl4965_rxon_cmd *active_rxon =
6530 (struct iwl4965_rxon_cmd *)(&priv->active_rxon);
6532 memcpy(&priv->staging_rxon, &priv->active_rxon,
6533 sizeof(priv->staging_rxon));
6534 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6536 /* Initialize our rx_config data */
6537 iwl4965_connection_init_rx_config(priv);
6538 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
6541 /* Configure Bluetooth device coexistence support */
6542 iwl4965_send_bt_config(priv);
6544 /* Configure the adapter for unassociated operation */
6545 iwl4965_commit_rxon(priv);
6547 /* At this point, the NIC is initialized and operational */
6548 priv->notif_missed_beacons = 0;
6549 set_bit(STATUS_READY, &priv->status);
6551 iwl4965_rf_kill_ct_config(priv);
6552 IWL_DEBUG_INFO("ALIVE processing complete.\n");
6554 if (priv->error_recovering)
6555 iwl4965_error_recovery(priv);
6560 queue_work(priv->workqueue, &priv->restart);
6563 static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv);
6565 static void __iwl4965_down(struct iwl4965_priv *priv)
6567 unsigned long flags;
6568 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
6569 struct ieee80211_conf *conf = NULL;
6571 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
6573 conf = ieee80211_get_hw_conf(priv->hw);
6576 set_bit(STATUS_EXIT_PENDING, &priv->status);
6578 iwl4965_clear_stations_table(priv);
6580 /* Unblock any waiting calls */
6581 wake_up_interruptible_all(&priv->wait_command_queue);
6583 /* Wipe out the EXIT_PENDING status bit if we are not actually
6584 * exiting the module */
6586 clear_bit(STATUS_EXIT_PENDING, &priv->status);
6588 /* stop and reset the on-board processor */
6589 iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
6591 /* tell the device to stop sending interrupts */
6592 iwl4965_disable_interrupts(priv);
6594 if (priv->mac80211_registered)
6595 ieee80211_stop_queues(priv->hw);
6597 /* If we have not previously called iwl4965_init() then
6598 * clear all bits but the RF Kill and SUSPEND bits and return */
6599 if (!iwl4965_is_init(priv)) {
6600 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6602 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6604 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6609 /* ...otherwise clear out all the status bits but the RF Kill and
6610 * SUSPEND bits and continue taking the NIC down. */
6611 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6613 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6615 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6617 test_bit(STATUS_FW_ERROR, &priv->status) <<
6620 spin_lock_irqsave(&priv->lock, flags);
6621 iwl4965_clear_bit(priv, CSR_GP_CNTRL,
6622 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
6623 spin_unlock_irqrestore(&priv->lock, flags);
6625 iwl4965_hw_txq_ctx_stop(priv);
6626 iwl4965_hw_rxq_stop(priv);
6628 spin_lock_irqsave(&priv->lock, flags);
6629 if (!iwl4965_grab_nic_access(priv)) {
6630 iwl4965_write_prph(priv, APMG_CLK_DIS_REG,
6631 APMG_CLK_VAL_DMA_CLK_RQT);
6632 iwl4965_release_nic_access(priv);
6634 spin_unlock_irqrestore(&priv->lock, flags);
6638 iwl4965_hw_nic_stop_master(priv);
6639 iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
6640 iwl4965_hw_nic_reset(priv);
6643 memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp));
6645 if (priv->ibss_beacon)
6646 dev_kfree_skb(priv->ibss_beacon);
6647 priv->ibss_beacon = NULL;
6649 /* clear out any free frames */
6650 iwl4965_clear_free_frames(priv);
6653 static void iwl4965_down(struct iwl4965_priv *priv)
6655 mutex_lock(&priv->mutex);
6656 __iwl4965_down(priv);
6657 mutex_unlock(&priv->mutex);
6659 iwl4965_cancel_deferred_work(priv);
6662 #define MAX_HW_RESTARTS 5
6664 static int __iwl4965_up(struct iwl4965_priv *priv)
6666 DECLARE_MAC_BUF(mac);
6670 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6671 IWL_WARNING("Exit pending; will not bring the NIC up\n");
6675 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
6676 IWL_WARNING("Radio disabled by SW RF kill (module "
6681 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
6682 IWL_ERROR("ucode not available for device bringup\n");
6686 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
6688 rc = iwl4965_hw_nic_init(priv);
6690 IWL_ERROR("Unable to int nic\n");
6694 /* make sure rfkill handshake bits are cleared */
6695 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6696 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
6697 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
6699 /* clear (again), then enable host interrupts */
6700 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
6701 iwl4965_enable_interrupts(priv);
6703 /* really make sure rfkill handshake bits are cleared */
6704 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6705 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6707 /* Copy original ucode data image from disk into backup cache.
6708 * This will be used to initialize the on-board processor's
6709 * data SRAM for a clean start when the runtime program first loads. */
6710 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
6711 priv->ucode_data.len);
6713 /* If platform's RF_KILL switch is set to KILL,
6714 * wait for BIT_INT_RF_KILL interrupt before loading uCode
6715 * and getting things started */
6716 if (!(iwl4965_read32(priv, CSR_GP_CNTRL) &
6717 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
6720 if (test_bit(STATUS_RF_KILL_HW, &priv->status) || hw_rf_kill) {
6721 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
6725 for (i = 0; i < MAX_HW_RESTARTS; i++) {
6727 iwl4965_clear_stations_table(priv);
6729 /* load bootstrap state machine,
6730 * load bootstrap program into processor's memory,
6731 * prepare to load the "initialize" uCode */
6732 rc = iwl4965_load_bsm(priv);
6735 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
6739 /* start card; "initialize" will load runtime ucode */
6740 iwl4965_nic_start(priv);
6742 /* MAC Address location in EEPROM is same for 3945/4965 */
6743 get_eeprom_mac(priv, priv->mac_addr);
6744 IWL_DEBUG_INFO("MAC address: %s\n",
6745 print_mac(mac, priv->mac_addr));
6747 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
6749 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
6754 set_bit(STATUS_EXIT_PENDING, &priv->status);
6755 __iwl4965_down(priv);
6757 /* tried to restart and config the device for as long as our
6758 * patience could withstand */
6759 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
6764 /*****************************************************************************
6766 * Workqueue callbacks
6768 *****************************************************************************/
6770 static void iwl4965_bg_init_alive_start(struct work_struct *data)
6772 struct iwl4965_priv *priv =
6773 container_of(data, struct iwl4965_priv, init_alive_start.work);
6775 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6778 mutex_lock(&priv->mutex);
6779 iwl4965_init_alive_start(priv);
6780 mutex_unlock(&priv->mutex);
6783 static void iwl4965_bg_alive_start(struct work_struct *data)
6785 struct iwl4965_priv *priv =
6786 container_of(data, struct iwl4965_priv, alive_start.work);
6788 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6791 mutex_lock(&priv->mutex);
6792 iwl4965_alive_start(priv);
6793 mutex_unlock(&priv->mutex);
6796 static void iwl4965_bg_rf_kill(struct work_struct *work)
6798 struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill);
6800 wake_up_interruptible(&priv->wait_command_queue);
6802 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6805 mutex_lock(&priv->mutex);
6807 if (!iwl4965_is_rfkill(priv)) {
6808 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
6809 "HW and/or SW RF Kill no longer active, restarting "
6811 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
6812 queue_work(priv->workqueue, &priv->restart);
6815 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
6816 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6817 "disabled by SW switch\n");
6819 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6820 "Kill switch must be turned off for "
6821 "wireless networking to work.\n");
6823 mutex_unlock(&priv->mutex);
6826 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6828 static void iwl4965_bg_scan_check(struct work_struct *data)
6830 struct iwl4965_priv *priv =
6831 container_of(data, struct iwl4965_priv, scan_check.work);
6833 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6836 mutex_lock(&priv->mutex);
6837 if (test_bit(STATUS_SCANNING, &priv->status) ||
6838 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6839 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
6840 "Scan completion watchdog resetting adapter (%dms)\n",
6841 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
6843 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
6844 iwl4965_send_scan_abort(priv);
6846 mutex_unlock(&priv->mutex);
6849 static void iwl4965_bg_request_scan(struct work_struct *data)
6851 struct iwl4965_priv *priv =
6852 container_of(data, struct iwl4965_priv, request_scan);
6853 struct iwl4965_host_cmd cmd = {
6854 .id = REPLY_SCAN_CMD,
6855 .len = sizeof(struct iwl4965_scan_cmd),
6856 .meta.flags = CMD_SIZE_HUGE,
6859 struct iwl4965_scan_cmd *scan;
6860 struct ieee80211_conf *conf = NULL;
6864 conf = ieee80211_get_hw_conf(priv->hw);
6866 mutex_lock(&priv->mutex);
6868 if (!iwl4965_is_ready(priv)) {
6869 IWL_WARNING("request scan called when driver not ready.\n");
6873 /* Make sure the scan wasn't cancelled before this queued work
6874 * was given the chance to run... */
6875 if (!test_bit(STATUS_SCANNING, &priv->status))
6878 /* This should never be called or scheduled if there is currently
6879 * a scan active in the hardware. */
6880 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
6881 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6882 "Ignoring second request.\n");
6887 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6888 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6892 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6893 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6897 if (iwl4965_is_rfkill(priv)) {
6898 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6902 if (!test_bit(STATUS_READY, &priv->status)) {
6903 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6907 if (!priv->scan_bands) {
6908 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6913 priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
6914 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
6921 memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
6923 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
6924 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
6926 if (iwl4965_is_associated(priv)) {
6929 u32 suspend_time = 100;
6930 u32 scan_suspend_time = 100;
6931 unsigned long flags;
6933 IWL_DEBUG_INFO("Scanning while associated...\n");
6935 spin_lock_irqsave(&priv->lock, flags);
6936 interval = priv->beacon_int;
6937 spin_unlock_irqrestore(&priv->lock, flags);
6939 scan->suspend_time = 0;
6940 scan->max_out_time = cpu_to_le32(200 * 1024);
6942 interval = suspend_time;
6944 extra = (suspend_time / interval) << 22;
6945 scan_suspend_time = (extra |
6946 ((suspend_time % interval) * 1024));
6947 scan->suspend_time = cpu_to_le32(scan_suspend_time);
6948 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6949 scan_suspend_time, interval);
6952 /* We should add the ability for user to lock to PASSIVE ONLY */
6953 if (priv->one_direct_scan) {
6955 ("Kicking off one direct scan for '%s'\n",
6956 iwl4965_escape_essid(priv->direct_ssid,
6957 priv->direct_ssid_len));
6958 scan->direct_scan[0].id = WLAN_EID_SSID;
6959 scan->direct_scan[0].len = priv->direct_ssid_len;
6960 memcpy(scan->direct_scan[0].ssid,
6961 priv->direct_ssid, priv->direct_ssid_len);
6963 } else if (!iwl4965_is_associated(priv) && priv->essid_len) {
6964 scan->direct_scan[0].id = WLAN_EID_SSID;
6965 scan->direct_scan[0].len = priv->essid_len;
6966 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
6971 /* We don't build a direct scan probe request; the uCode will do
6972 * that based on the direct_mask added to each channel entry */
6973 scan->tx_cmd.len = cpu_to_le16(
6974 iwl4965_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
6975 IWL_MAX_SCAN_SIZE - sizeof(scan), 0));
6976 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
6977 scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
6978 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
6980 /* flags + rate selection */
6982 scan->tx_cmd.tx_flags |= cpu_to_le32(0x200);
6984 switch (priv->scan_bands) {
6986 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
6987 scan->tx_cmd.rate_n_flags =
6988 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
6989 RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
6991 scan->good_CRC_th = 0;
6992 phymode = MODE_IEEE80211G;
6996 scan->tx_cmd.rate_n_flags =
6997 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
6998 RATE_MCS_ANT_B_MSK);
6999 scan->good_CRC_th = IWL_GOOD_CRC_TH;
7000 phymode = MODE_IEEE80211A;
7004 IWL_WARNING("Invalid scan band count\n");
7008 /* select Rx chains */
7010 /* Force use of chains B and C (0x6) for scan Rx.
7011 * Avoid A (0x1) because of its off-channel reception on A-band.
7012 * MIMO is not used here, but value is required to make uCode happy. */
7013 scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
7014 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
7015 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
7016 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
7018 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
7019 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
7023 ("Initiating direct scan for %s.\n",
7024 iwl4965_escape_essid(priv->essid, priv->essid_len));
7026 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
7028 scan->channel_count =
7029 iwl4965_get_channels_for_scan(
7030 priv, phymode, 1, /* active */
7032 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
7034 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
7035 scan->channel_count * sizeof(struct iwl4965_scan_channel);
7037 scan->len = cpu_to_le16(cmd.len);
7039 set_bit(STATUS_SCAN_HW, &priv->status);
7040 rc = iwl4965_send_cmd_sync(priv, &cmd);
7044 queue_delayed_work(priv->workqueue, &priv->scan_check,
7045 IWL_SCAN_CHECK_WATCHDOG);
7047 mutex_unlock(&priv->mutex);
7051 /* inform mac80211 scan aborted */
7052 queue_work(priv->workqueue, &priv->scan_completed);
7053 mutex_unlock(&priv->mutex);
7056 static void iwl4965_bg_up(struct work_struct *data)
7058 struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up);
7060 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7063 mutex_lock(&priv->mutex);
7065 mutex_unlock(&priv->mutex);
7068 static void iwl4965_bg_restart(struct work_struct *data)
7070 struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart);
7072 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7076 queue_work(priv->workqueue, &priv->up);
7079 static void iwl4965_bg_rx_replenish(struct work_struct *data)
7081 struct iwl4965_priv *priv =
7082 container_of(data, struct iwl4965_priv, rx_replenish);
7084 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7087 mutex_lock(&priv->mutex);
7088 iwl4965_rx_replenish(priv);
7089 mutex_unlock(&priv->mutex);
7092 static void iwl4965_bg_post_associate(struct work_struct *data)
7094 struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv,
7095 post_associate.work);
7098 struct ieee80211_conf *conf = NULL;
7099 DECLARE_MAC_BUF(mac);
7101 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7102 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
7106 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
7108 print_mac(mac, priv->active_rxon.bssid_addr));
7111 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7114 mutex_lock(&priv->mutex);
7116 if (!priv->interface_id || !priv->is_open) {
7117 mutex_unlock(&priv->mutex);
7120 iwl4965_scan_cancel_timeout(priv, 200);
7122 conf = ieee80211_get_hw_conf(priv->hw);
7124 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7125 iwl4965_commit_rxon(priv);
7127 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
7128 iwl4965_setup_rxon_timing(priv);
7129 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
7130 sizeof(priv->rxon_timing), &priv->rxon_timing);
7132 IWL_WARNING("REPLY_RXON_TIMING failed - "
7133 "Attempting to continue.\n");
7135 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
7137 #ifdef CONFIG_IWL4965_HT
7138 if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht)
7139 iwl4965_set_rxon_ht(priv, &priv->current_assoc_ht);
7141 priv->active_rate_ht[0] = 0;
7142 priv->active_rate_ht[1] = 0;
7143 priv->current_channel_width = IWL_CHANNEL_WIDTH_20MHZ;
7145 #endif /* CONFIG_IWL4965_HT*/
7146 iwl4965_set_rxon_chain(priv);
7147 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7149 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
7150 priv->assoc_id, priv->beacon_int);
7152 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7153 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
7155 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
7157 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7158 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
7159 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
7161 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
7163 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7164 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
7168 iwl4965_commit_rxon(priv);
7170 switch (priv->iw_mode) {
7171 case IEEE80211_IF_TYPE_STA:
7172 iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
7175 case IEEE80211_IF_TYPE_IBSS:
7177 /* clear out the station table */
7178 iwl4965_clear_stations_table(priv);
7180 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
7181 iwl4965_rxon_add_station(priv, priv->bssid, 0);
7182 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
7183 iwl4965_send_beacon_cmd(priv);
7188 IWL_ERROR("%s Should not be called in %d mode\n",
7189 __FUNCTION__, priv->iw_mode);
7193 iwl4965_sequence_reset(priv);
7195 #ifdef CONFIG_IWL4965_SENSITIVITY
7196 /* Enable Rx differential gain and sensitivity calibrations */
7197 iwl4965_chain_noise_reset(priv);
7198 priv->start_calib = 1;
7199 #endif /* CONFIG_IWL4965_SENSITIVITY */
7201 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7202 priv->assoc_station_added = 1;
7204 #ifdef CONFIG_IWL4965_QOS
7205 iwl4965_activate_qos(priv, 0);
7206 #endif /* CONFIG_IWL4965_QOS */
7207 mutex_unlock(&priv->mutex);
7210 static void iwl4965_bg_abort_scan(struct work_struct *work)
7212 struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan);
7214 if (!iwl4965_is_ready(priv))
7217 mutex_lock(&priv->mutex);
7219 set_bit(STATUS_SCAN_ABORTING, &priv->status);
7220 iwl4965_send_scan_abort(priv);
7222 mutex_unlock(&priv->mutex);
7225 static void iwl4965_bg_scan_completed(struct work_struct *work)
7227 struct iwl4965_priv *priv =
7228 container_of(work, struct iwl4965_priv, scan_completed);
7230 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
7232 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7235 ieee80211_scan_completed(priv->hw);
7237 /* Since setting the TXPOWER may have been deferred while
7238 * performing the scan, fire one off */
7239 mutex_lock(&priv->mutex);
7240 iwl4965_hw_reg_send_txpower(priv);
7241 mutex_unlock(&priv->mutex);
7244 /*****************************************************************************
7246 * mac80211 entry point functions
7248 *****************************************************************************/
7250 static int iwl4965_mac_start(struct ieee80211_hw *hw)
7252 struct iwl4965_priv *priv = hw->priv;
7254 IWL_DEBUG_MAC80211("enter\n");
7256 /* we should be verifying the device is ready to be opened */
7257 mutex_lock(&priv->mutex);
7261 if (!iwl4965_is_rfkill(priv))
7262 ieee80211_start_queues(priv->hw);
7264 mutex_unlock(&priv->mutex);
7265 IWL_DEBUG_MAC80211("leave\n");
7269 static void iwl4965_mac_stop(struct ieee80211_hw *hw)
7271 struct iwl4965_priv *priv = hw->priv;
7273 IWL_DEBUG_MAC80211("enter\n");
7276 mutex_lock(&priv->mutex);
7277 /* stop mac, cancel any scan request and clear
7278 * RXON_FILTER_ASSOC_MSK BIT
7281 iwl4965_scan_cancel_timeout(priv, 100);
7282 cancel_delayed_work(&priv->post_associate);
7283 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7284 iwl4965_commit_rxon(priv);
7285 mutex_unlock(&priv->mutex);
7287 IWL_DEBUG_MAC80211("leave\n");
7290 static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
7291 struct ieee80211_tx_control *ctl)
7293 struct iwl4965_priv *priv = hw->priv;
7295 IWL_DEBUG_MAC80211("enter\n");
7297 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
7298 IWL_DEBUG_MAC80211("leave - monitor\n");
7302 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
7305 if (iwl4965_tx_skb(priv, skb, ctl))
7306 dev_kfree_skb_any(skb);
7308 IWL_DEBUG_MAC80211("leave\n");
7312 static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
7313 struct ieee80211_if_init_conf *conf)
7315 struct iwl4965_priv *priv = hw->priv;
7316 unsigned long flags;
7317 DECLARE_MAC_BUF(mac);
7319 IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type);
7321 if (priv->interface_id) {
7322 IWL_DEBUG_MAC80211("leave - interface_id != 0\n");
7326 spin_lock_irqsave(&priv->lock, flags);
7327 priv->interface_id = conf->if_id;
7329 spin_unlock_irqrestore(&priv->lock, flags);
7331 mutex_lock(&priv->mutex);
7333 if (conf->mac_addr) {
7334 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
7335 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
7337 iwl4965_set_mode(priv, conf->type);
7339 IWL_DEBUG_MAC80211("leave\n");
7340 mutex_unlock(&priv->mutex);
7346 * iwl4965_mac_config - mac80211 config callback
7348 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
7349 * be set inappropriately and the driver currently sets the hardware up to
7350 * use it whenever needed.
7352 static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
7354 struct iwl4965_priv *priv = hw->priv;
7355 const struct iwl4965_channel_info *ch_info;
7356 unsigned long flags;
7358 mutex_lock(&priv->mutex);
7359 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel);
7361 if (!iwl4965_is_ready(priv)) {
7362 IWL_DEBUG_MAC80211("leave - not ready\n");
7363 mutex_unlock(&priv->mutex);
7367 /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only
7368 * what is exposed through include/ declarations */
7369 if (unlikely(!iwl4965_param_disable_hw_scan &&
7370 test_bit(STATUS_SCANNING, &priv->status))) {
7371 IWL_DEBUG_MAC80211("leave - scanning\n");
7372 mutex_unlock(&priv->mutex);
7376 spin_lock_irqsave(&priv->lock, flags);
7378 ch_info = iwl4965_get_channel_info(priv, conf->phymode, conf->channel);
7379 if (!is_channel_valid(ch_info)) {
7380 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
7381 conf->channel, conf->phymode);
7382 IWL_DEBUG_MAC80211("leave - invalid channel\n");
7383 spin_unlock_irqrestore(&priv->lock, flags);
7384 mutex_unlock(&priv->mutex);
7388 #ifdef CONFIG_IWL4965_HT
7389 /* if we are switching fron ht to 2.4 clear flags
7390 * from any ht related info since 2.4 does not
7392 if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel)
7393 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
7394 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
7397 priv->staging_rxon.flags = 0;
7398 #endif /* CONFIG_IWL4965_HT */
7400 iwl4965_set_rxon_channel(priv, conf->phymode, conf->channel);
7402 iwl4965_set_flags_for_phymode(priv, conf->phymode);
7404 /* The list of supported rates and rate mask can be different
7405 * for each phymode; since the phymode may have changed, reset
7406 * the rate mask to what mac80211 lists */
7407 iwl4965_set_rate(priv);
7409 spin_unlock_irqrestore(&priv->lock, flags);
7411 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
7412 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
7413 iwl4965_hw_channel_switch(priv, conf->channel);
7414 mutex_unlock(&priv->mutex);
7419 iwl4965_radio_kill_sw(priv, !conf->radio_enabled);
7421 if (!conf->radio_enabled) {
7422 IWL_DEBUG_MAC80211("leave - radio disabled\n");
7423 mutex_unlock(&priv->mutex);
7427 if (iwl4965_is_rfkill(priv)) {
7428 IWL_DEBUG_MAC80211("leave - RF kill\n");
7429 mutex_unlock(&priv->mutex);
7433 iwl4965_set_rate(priv);
7435 if (memcmp(&priv->active_rxon,
7436 &priv->staging_rxon, sizeof(priv->staging_rxon)))
7437 iwl4965_commit_rxon(priv);
7439 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
7441 IWL_DEBUG_MAC80211("leave\n");
7443 mutex_unlock(&priv->mutex);
7448 static void iwl4965_config_ap(struct iwl4965_priv *priv)
7452 if (priv->status & STATUS_EXIT_PENDING)
7455 /* The following should be done only at AP bring up */
7456 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
7458 /* RXON - unassoc (to set timing command) */
7459 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7460 iwl4965_commit_rxon(priv);
7463 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
7464 iwl4965_setup_rxon_timing(priv);
7465 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
7466 sizeof(priv->rxon_timing), &priv->rxon_timing);
7468 IWL_WARNING("REPLY_RXON_TIMING failed - "
7469 "Attempting to continue.\n");
7471 iwl4965_set_rxon_chain(priv);
7473 /* FIXME: what should be the assoc_id for AP? */
7474 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7475 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7476 priv->staging_rxon.flags |=
7477 RXON_FLG_SHORT_PREAMBLE_MSK;
7479 priv->staging_rxon.flags &=
7480 ~RXON_FLG_SHORT_PREAMBLE_MSK;
7482 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7483 if (priv->assoc_capability &
7484 WLAN_CAPABILITY_SHORT_SLOT_TIME)
7485 priv->staging_rxon.flags |=
7486 RXON_FLG_SHORT_SLOT_MSK;
7488 priv->staging_rxon.flags &=
7489 ~RXON_FLG_SHORT_SLOT_MSK;
7491 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7492 priv->staging_rxon.flags &=
7493 ~RXON_FLG_SHORT_SLOT_MSK;
7495 /* restore RXON assoc */
7496 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
7497 iwl4965_commit_rxon(priv);
7498 #ifdef CONFIG_IWL4965_QOS
7499 iwl4965_activate_qos(priv, 1);
7501 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
7503 iwl4965_send_beacon_cmd(priv);
7505 /* FIXME - we need to add code here to detect a totally new
7506 * configuration, reset the AP, unassoc, rxon timing, assoc,
7507 * clear sta table, add BCAST sta... */
7510 static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, int if_id,
7511 struct ieee80211_if_conf *conf)
7513 struct iwl4965_priv *priv = hw->priv;
7514 DECLARE_MAC_BUF(mac);
7515 unsigned long flags;
7521 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
7522 (!conf->beacon || !conf->ssid_len)) {
7524 ("Leaving in AP mode because HostAPD is not ready.\n");
7528 mutex_lock(&priv->mutex);
7530 IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id);
7532 IWL_DEBUG_MAC80211("bssid: %s\n",
7533 print_mac(mac, conf->bssid));
7536 * very dubious code was here; the probe filtering flag is never set:
7538 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
7539 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
7541 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
7542 IWL_DEBUG_MAC80211("leave - scanning\n");
7543 mutex_unlock(&priv->mutex);
7547 if (priv->interface_id != if_id) {
7548 IWL_DEBUG_MAC80211("leave - interface_id != if_id\n");
7549 mutex_unlock(&priv->mutex);
7553 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7555 conf->bssid = priv->mac_addr;
7556 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
7557 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
7558 print_mac(mac, conf->bssid));
7560 if (priv->ibss_beacon)
7561 dev_kfree_skb(priv->ibss_beacon);
7563 priv->ibss_beacon = conf->beacon;
7566 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
7567 !is_multicast_ether_addr(conf->bssid)) {
7568 /* If there is currently a HW scan going on in the background
7569 * then we need to cancel it else the RXON below will fail. */
7570 if (iwl4965_scan_cancel_timeout(priv, 100)) {
7571 IWL_WARNING("Aborted scan still in progress "
7573 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
7574 mutex_unlock(&priv->mutex);
7577 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
7579 /* TODO: Audit driver for usage of these members and see
7580 * if mac80211 deprecates them (priv->bssid looks like it
7581 * shouldn't be there, but I haven't scanned the IBSS code
7582 * to verify) - jpk */
7583 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
7585 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
7586 iwl4965_config_ap(priv);
7588 rc = iwl4965_commit_rxon(priv);
7589 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
7590 iwl4965_rxon_add_station(
7591 priv, priv->active_rxon.bssid_addr, 1);
7595 iwl4965_scan_cancel_timeout(priv, 100);
7596 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7597 iwl4965_commit_rxon(priv);
7600 spin_lock_irqsave(&priv->lock, flags);
7601 if (!conf->ssid_len)
7602 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7604 memcpy(priv->essid, conf->ssid, conf->ssid_len);
7606 priv->essid_len = conf->ssid_len;
7607 spin_unlock_irqrestore(&priv->lock, flags);
7609 IWL_DEBUG_MAC80211("leave\n");
7610 mutex_unlock(&priv->mutex);
7615 static void iwl4965_configure_filter(struct ieee80211_hw *hw,
7616 unsigned int changed_flags,
7617 unsigned int *total_flags,
7618 int mc_count, struct dev_addr_list *mc_list)
7622 * see also iwl4965_connection_init_rx_config
7627 static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
7628 struct ieee80211_if_init_conf *conf)
7630 struct iwl4965_priv *priv = hw->priv;
7632 IWL_DEBUG_MAC80211("enter\n");
7634 mutex_lock(&priv->mutex);
7636 iwl4965_scan_cancel_timeout(priv, 100);
7637 cancel_delayed_work(&priv->post_associate);
7638 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7639 iwl4965_commit_rxon(priv);
7641 if (priv->interface_id == conf->if_id) {
7642 priv->interface_id = 0;
7643 memset(priv->bssid, 0, ETH_ALEN);
7644 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7645 priv->essid_len = 0;
7647 mutex_unlock(&priv->mutex);
7649 IWL_DEBUG_MAC80211("leave\n");
7652 static void iwl4965_mac_erp_ie_changed(struct ieee80211_hw *hw,
7653 u8 changes, int cts_protection, int preamble)
7655 struct iwl4965_priv *priv = hw->priv;
7657 if (changes & IEEE80211_ERP_CHANGE_PREAMBLE) {
7658 if (preamble == WLAN_ERP_PREAMBLE_SHORT)
7659 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
7661 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
7664 if (changes & IEEE80211_ERP_CHANGE_PROTECTION) {
7665 if (cts_protection && (priv->phymode != MODE_IEEE80211A))
7666 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
7668 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
7671 if (iwl4965_is_associated(priv))
7672 iwl4965_send_rxon_assoc(priv);
7675 #define IWL_DELAY_NEXT_SCAN (HZ*2)
7676 static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
7679 unsigned long flags;
7680 struct iwl4965_priv *priv = hw->priv;
7682 IWL_DEBUG_MAC80211("enter\n");
7684 mutex_lock(&priv->mutex);
7685 spin_lock_irqsave(&priv->lock, flags);
7687 if (!iwl4965_is_ready_rf(priv)) {
7689 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7693 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
7695 IWL_ERROR("ERROR: APs don't scan\n");
7699 /* if we just finished scan ask for delay */
7700 if (priv->last_scan_jiffies &&
7701 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
7707 IWL_DEBUG_SCAN("direct scan for "
7709 iwl4965_escape_essid(ssid, len), (int)len);
7711 priv->one_direct_scan = 1;
7712 priv->direct_ssid_len = (u8)
7713 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
7714 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
7716 priv->one_direct_scan = 0;
7718 rc = iwl4965_scan_initiate(priv);
7720 IWL_DEBUG_MAC80211("leave\n");
7723 spin_unlock_irqrestore(&priv->lock, flags);
7724 mutex_unlock(&priv->mutex);
7729 static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
7730 const u8 *local_addr, const u8 *addr,
7731 struct ieee80211_key_conf *key)
7733 struct iwl4965_priv *priv = hw->priv;
7734 DECLARE_MAC_BUF(mac);
7738 IWL_DEBUG_MAC80211("enter\n");
7740 if (!iwl4965_param_hwcrypto) {
7741 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7745 if (is_zero_ether_addr(addr))
7746 /* only support pairwise keys */
7749 sta_id = iwl4965_hw_find_station(priv, addr);
7750 if (sta_id == IWL_INVALID_STATION) {
7751 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7752 print_mac(mac, addr));
7756 mutex_lock(&priv->mutex);
7758 iwl4965_scan_cancel_timeout(priv, 100);
7762 rc = iwl4965_update_sta_key_info(priv, key, sta_id);
7764 iwl4965_set_rxon_hwcrypto(priv, 1);
7765 iwl4965_commit_rxon(priv);
7766 key->hw_key_idx = sta_id;
7767 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7768 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
7772 rc = iwl4965_clear_sta_key_info(priv, sta_id);
7774 iwl4965_set_rxon_hwcrypto(priv, 0);
7775 iwl4965_commit_rxon(priv);
7776 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7783 IWL_DEBUG_MAC80211("leave\n");
7784 mutex_unlock(&priv->mutex);
7789 static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
7790 const struct ieee80211_tx_queue_params *params)
7792 struct iwl4965_priv *priv = hw->priv;
7793 #ifdef CONFIG_IWL4965_QOS
7794 unsigned long flags;
7796 #endif /* CONFIG_IWL4965_QOS */
7798 IWL_DEBUG_MAC80211("enter\n");
7800 if (!iwl4965_is_ready_rf(priv)) {
7801 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7805 if (queue >= AC_NUM) {
7806 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
7810 #ifdef CONFIG_IWL4965_QOS
7811 if (!priv->qos_data.qos_enable) {
7812 priv->qos_data.qos_active = 0;
7813 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7816 q = AC_NUM - 1 - queue;
7818 spin_lock_irqsave(&priv->lock, flags);
7820 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
7821 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
7822 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
7823 priv->qos_data.def_qos_parm.ac[q].edca_txop =
7824 cpu_to_le16((params->burst_time * 100));
7826 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
7827 priv->qos_data.qos_active = 1;
7829 spin_unlock_irqrestore(&priv->lock, flags);
7831 mutex_lock(&priv->mutex);
7832 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
7833 iwl4965_activate_qos(priv, 1);
7834 else if (priv->assoc_id && iwl4965_is_associated(priv))
7835 iwl4965_activate_qos(priv, 0);
7837 mutex_unlock(&priv->mutex);
7839 #endif /*CONFIG_IWL4965_QOS */
7841 IWL_DEBUG_MAC80211("leave\n");
7845 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
7846 struct ieee80211_tx_queue_stats *stats)
7848 struct iwl4965_priv *priv = hw->priv;
7850 struct iwl4965_tx_queue *txq;
7851 struct iwl4965_queue *q;
7852 unsigned long flags;
7854 IWL_DEBUG_MAC80211("enter\n");
7856 if (!iwl4965_is_ready_rf(priv)) {
7857 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7861 spin_lock_irqsave(&priv->lock, flags);
7863 for (i = 0; i < AC_NUM; i++) {
7864 txq = &priv->txq[i];
7866 avail = iwl4965_queue_space(q);
7868 stats->data[i].len = q->n_window - avail;
7869 stats->data[i].limit = q->n_window - q->high_mark;
7870 stats->data[i].count = q->n_window;
7873 spin_unlock_irqrestore(&priv->lock, flags);
7875 IWL_DEBUG_MAC80211("leave\n");
7880 static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
7881 struct ieee80211_low_level_stats *stats)
7883 IWL_DEBUG_MAC80211("enter\n");
7884 IWL_DEBUG_MAC80211("leave\n");
7889 static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
7891 IWL_DEBUG_MAC80211("enter\n");
7892 IWL_DEBUG_MAC80211("leave\n");
7897 static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
7899 struct iwl4965_priv *priv = hw->priv;
7900 unsigned long flags;
7902 mutex_lock(&priv->mutex);
7903 IWL_DEBUG_MAC80211("enter\n");
7905 priv->lq_mngr.lq_ready = 0;
7906 #ifdef CONFIG_IWL4965_HT
7907 spin_lock_irqsave(&priv->lock, flags);
7908 memset(&priv->current_assoc_ht, 0, sizeof(struct sta_ht_info));
7909 spin_unlock_irqrestore(&priv->lock, flags);
7910 #ifdef CONFIG_IWL4965_HT_AGG
7911 /* if (priv->lq_mngr.agg_ctrl.granted_ba)
7912 iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);*/
7914 memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl4965_agg_control));
7915 priv->lq_mngr.agg_ctrl.tid_traffic_load_threshold = 10;
7916 priv->lq_mngr.agg_ctrl.ba_timeout = 5000;
7917 priv->lq_mngr.agg_ctrl.auto_agg = 1;
7919 if (priv->lq_mngr.agg_ctrl.auto_agg)
7920 priv->lq_mngr.agg_ctrl.requested_ba = TID_ALL_ENABLED;
7921 #endif /*CONFIG_IWL4965_HT_AGG */
7922 #endif /* CONFIG_IWL4965_HT */
7924 #ifdef CONFIG_IWL4965_QOS
7925 iwl4965_reset_qos(priv);
7928 cancel_delayed_work(&priv->post_associate);
7930 spin_lock_irqsave(&priv->lock, flags);
7932 priv->assoc_capability = 0;
7933 priv->call_post_assoc_from_beacon = 0;
7934 priv->assoc_station_added = 0;
7936 /* new association get rid of ibss beacon skb */
7937 if (priv->ibss_beacon)
7938 dev_kfree_skb(priv->ibss_beacon);
7940 priv->ibss_beacon = NULL;
7942 priv->beacon_int = priv->hw->conf.beacon_int;
7943 priv->timestamp1 = 0;
7944 priv->timestamp0 = 0;
7945 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
7946 priv->beacon_int = 0;
7948 spin_unlock_irqrestore(&priv->lock, flags);
7950 /* we are restarting association process
7951 * clear RXON_FILTER_ASSOC_MSK bit
7953 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
7954 iwl4965_scan_cancel_timeout(priv, 100);
7955 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7956 iwl4965_commit_rxon(priv);
7959 /* Per mac80211.h: This is only used in IBSS mode... */
7960 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7962 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7963 mutex_unlock(&priv->mutex);
7967 if (!iwl4965_is_ready_rf(priv)) {
7968 IWL_DEBUG_MAC80211("leave - not ready\n");
7969 mutex_unlock(&priv->mutex);
7973 priv->only_active_channel = 0;
7975 iwl4965_set_rate(priv);
7977 mutex_unlock(&priv->mutex);
7979 IWL_DEBUG_MAC80211("leave\n");
7983 static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
7984 struct ieee80211_tx_control *control)
7986 struct iwl4965_priv *priv = hw->priv;
7987 unsigned long flags;
7989 mutex_lock(&priv->mutex);
7990 IWL_DEBUG_MAC80211("enter\n");
7992 if (!iwl4965_is_ready_rf(priv)) {
7993 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7994 mutex_unlock(&priv->mutex);
7998 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7999 IWL_DEBUG_MAC80211("leave - not IBSS\n");
8000 mutex_unlock(&priv->mutex);
8004 spin_lock_irqsave(&priv->lock, flags);
8006 if (priv->ibss_beacon)
8007 dev_kfree_skb(priv->ibss_beacon);
8009 priv->ibss_beacon = skb;
8013 IWL_DEBUG_MAC80211("leave\n");
8014 spin_unlock_irqrestore(&priv->lock, flags);
8016 #ifdef CONFIG_IWL4965_QOS
8017 iwl4965_reset_qos(priv);
8020 queue_work(priv->workqueue, &priv->post_associate.work);
8022 mutex_unlock(&priv->mutex);
8027 #ifdef CONFIG_IWL4965_HT
8030 u16 advanced_coding_cap :1;
8031 u16 supported_chan_width_set :1;
8032 u16 mimo_power_save_mode :2;
8038 u16 beam_forming :1;
8040 u16 maximal_amsdu_size :1;
8041 u16 cck_mode_at_40MHz :1;
8042 u16 psmp_support :1;
8043 u16 stbc_ctrl_frame_support :1;
8044 u16 sig_txop_protection_support :1;
8047 } __attribute__ ((packed));
8049 union ht_param_info{
8051 u8 max_rx_ampdu_factor :2;
8056 } __attribute__ ((packed));
8058 union ht_exra_param_info {
8060 u8 ext_chan_offset :2;
8061 u8 tx_chan_width :1;
8063 u8 controlled_access_only :1;
8064 u8 service_interval_granularity :3;
8067 } __attribute__ ((packed));
8069 union ht_operation_mode{
8076 } __attribute__ ((packed));
8079 static int sta_ht_info_init(struct ieee80211_ht_capability *ht_cap,
8080 struct ieee80211_ht_additional_info *ht_extra,
8081 struct sta_ht_info *ht_info_ap,
8082 struct sta_ht_info *ht_info)
8084 union ht_cap_info cap;
8085 union ht_operation_mode op_mode;
8086 union ht_param_info param_info;
8087 union ht_exra_param_info extra_param_info;
8089 IWL_DEBUG_MAC80211("enter: \n");
8092 IWL_DEBUG_MAC80211("leave: ht_info is NULL\n");
8097 cap.val = (u16) le16_to_cpu(ht_cap->capabilities_info);
8098 param_info.val = ht_cap->mac_ht_params_info;
8101 ht_info->sgf |= 0x1;
8103 ht_info->sgf |= 0x2;
8104 ht_info->is_green_field = cap.green_field;
8105 ht_info->max_amsdu_size = cap.maximal_amsdu_size;
8106 ht_info->supported_chan_width = cap.supported_chan_width_set;
8107 ht_info->tx_mimo_ps_mode = cap.mimo_power_save_mode;
8108 memcpy(ht_info->supp_rates, ht_cap->supported_mcs_set, 16);
8110 ht_info->ampdu_factor = param_info.max_rx_ampdu_factor;
8111 ht_info->mpdu_density = param_info.mpdu_density;
8113 IWL_DEBUG_MAC80211("SISO mask 0x%X MIMO mask 0x%X \n",
8114 ht_cap->supported_mcs_set[0],
8115 ht_cap->supported_mcs_set[1]);
8118 ht_info->control_channel = ht_info_ap->control_channel;
8119 ht_info->extension_chan_offset =
8120 ht_info_ap->extension_chan_offset;
8121 ht_info->tx_chan_width = ht_info_ap->tx_chan_width;
8122 ht_info->operating_mode = ht_info_ap->operating_mode;
8126 extra_param_info.val = ht_extra->ht_param;
8127 ht_info->control_channel = ht_extra->control_chan;
8128 ht_info->extension_chan_offset =
8129 extra_param_info.ext_chan_offset;
8130 ht_info->tx_chan_width = extra_param_info.tx_chan_width;
8132 le16_to_cpu(ht_extra->operation_mode);
8133 ht_info->operating_mode = op_mode.op_mode;
8134 IWL_DEBUG_MAC80211("control channel %d\n",
8135 ht_extra->control_chan);
8140 IWL_DEBUG_MAC80211("leave\n");
8144 static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw,
8145 struct ieee80211_ht_capability *ht_cap,
8146 struct ieee80211_ht_additional_info *ht_extra)
8148 struct iwl4965_priv *priv = hw->priv;
8151 IWL_DEBUG_MAC80211("enter: \n");
8153 rs = sta_ht_info_init(ht_cap, ht_extra, NULL, &priv->current_assoc_ht);
8154 iwl4965_set_rxon_chain(priv);
8156 if (priv && priv->assoc_id &&
8157 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
8158 unsigned long flags;
8160 spin_lock_irqsave(&priv->lock, flags);
8161 if (priv->beacon_int)
8162 queue_work(priv->workqueue, &priv->post_associate.work);
8164 priv->call_post_assoc_from_beacon = 1;
8165 spin_unlock_irqrestore(&priv->lock, flags);
8168 IWL_DEBUG_MAC80211("leave: control channel %d\n",
8169 ht_extra->control_chan);
8174 static void iwl4965_set_ht_capab(struct ieee80211_hw *hw,
8175 struct ieee80211_ht_capability *ht_cap,
8178 union ht_cap_info cap;
8179 union ht_param_info param_info;
8181 memset(&cap, 0, sizeof(union ht_cap_info));
8182 memset(¶m_info, 0, sizeof(union ht_param_info));
8184 cap.maximal_amsdu_size = HT_IE_MAX_AMSDU_SIZE_4K;
8185 cap.green_field = 1;
8188 cap.supported_chan_width_set = use_wide_chan;
8189 cap.mimo_power_save_mode = 0x3;
8191 param_info.max_rx_ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
8192 param_info.mpdu_density = CFG_HT_MPDU_DENSITY_DEF;
8193 ht_cap->capabilities_info = (__le16) cpu_to_le16(cap.val);
8194 ht_cap->mac_ht_params_info = (u8) param_info.val;
8196 ht_cap->supported_mcs_set[0] = 0xff;
8197 ht_cap->supported_mcs_set[1] = 0xff;
8198 ht_cap->supported_mcs_set[4] =
8199 (cap.supported_chan_width_set) ? 0x1: 0x0;
8202 static void iwl4965_mac_get_ht_capab(struct ieee80211_hw *hw,
8203 struct ieee80211_ht_capability *ht_cap)
8205 u8 use_wide_channel = 1;
8206 struct iwl4965_priv *priv = hw->priv;
8208 IWL_DEBUG_MAC80211("enter: \n");
8209 if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ)
8210 use_wide_channel = 0;
8212 /* no fat tx allowed on 2.4GHZ */
8213 if (priv->phymode != MODE_IEEE80211A)
8214 use_wide_channel = 0;
8216 iwl4965_set_ht_capab(hw, ht_cap, use_wide_channel);
8217 IWL_DEBUG_MAC80211("leave: \n");
8219 #endif /*CONFIG_IWL4965_HT*/
8221 /*****************************************************************************
8225 *****************************************************************************/
8227 #ifdef CONFIG_IWL4965_DEBUG
8230 * The following adds a new attribute to the sysfs representation
8231 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
8232 * used for controlling the debug level.
8234 * See the level definitions in iwl for details.
8237 static ssize_t show_debug_level(struct device_driver *d, char *buf)
8239 return sprintf(buf, "0x%08X\n", iwl4965_debug_level);
8241 static ssize_t store_debug_level(struct device_driver *d,
8242 const char *buf, size_t count)
8244 char *p = (char *)buf;
8247 val = simple_strtoul(p, &p, 0);
8249 printk(KERN_INFO DRV_NAME
8250 ": %s is not in hex or decimal form.\n", buf);
8252 iwl4965_debug_level = val;
8254 return strnlen(buf, count);
8257 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
8258 show_debug_level, store_debug_level);
8260 #endif /* CONFIG_IWL4965_DEBUG */
8262 static ssize_t show_rf_kill(struct device *d,
8263 struct device_attribute *attr, char *buf)
8266 * 0 - RF kill not enabled
8267 * 1 - SW based RF kill active (sysfs)
8268 * 2 - HW based RF kill active
8269 * 3 - Both HW and SW based RF kill active
8271 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8272 int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
8273 (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
8275 return sprintf(buf, "%i\n", val);
8278 static ssize_t store_rf_kill(struct device *d,
8279 struct device_attribute *attr,
8280 const char *buf, size_t count)
8282 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8284 mutex_lock(&priv->mutex);
8285 iwl4965_radio_kill_sw(priv, buf[0] == '1');
8286 mutex_unlock(&priv->mutex);
8291 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
8293 static ssize_t show_temperature(struct device *d,
8294 struct device_attribute *attr, char *buf)
8296 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8298 if (!iwl4965_is_alive(priv))
8301 return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
8304 static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
8306 static ssize_t show_rs_window(struct device *d,
8307 struct device_attribute *attr,
8310 struct iwl4965_priv *priv = d->driver_data;
8311 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
8313 static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
8315 static ssize_t show_tx_power(struct device *d,
8316 struct device_attribute *attr, char *buf)
8318 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8319 return sprintf(buf, "%d\n", priv->user_txpower_limit);
8322 static ssize_t store_tx_power(struct device *d,
8323 struct device_attribute *attr,
8324 const char *buf, size_t count)
8326 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8327 char *p = (char *)buf;
8330 val = simple_strtoul(p, &p, 10);
8332 printk(KERN_INFO DRV_NAME
8333 ": %s is not in decimal form.\n", buf);
8335 iwl4965_hw_reg_set_txpower(priv, val);
8340 static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
8342 static ssize_t show_flags(struct device *d,
8343 struct device_attribute *attr, char *buf)
8345 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8347 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
8350 static ssize_t store_flags(struct device *d,
8351 struct device_attribute *attr,
8352 const char *buf, size_t count)
8354 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8355 u32 flags = simple_strtoul(buf, NULL, 0);
8357 mutex_lock(&priv->mutex);
8358 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
8359 /* Cancel any currently running scans... */
8360 if (iwl4965_scan_cancel_timeout(priv, 100))
8361 IWL_WARNING("Could not cancel scan.\n");
8363 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
8365 priv->staging_rxon.flags = cpu_to_le32(flags);
8366 iwl4965_commit_rxon(priv);
8369 mutex_unlock(&priv->mutex);
8374 static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
8376 static ssize_t show_filter_flags(struct device *d,
8377 struct device_attribute *attr, char *buf)
8379 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8381 return sprintf(buf, "0x%04X\n",
8382 le32_to_cpu(priv->active_rxon.filter_flags));
8385 static ssize_t store_filter_flags(struct device *d,
8386 struct device_attribute *attr,
8387 const char *buf, size_t count)
8389 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8390 u32 filter_flags = simple_strtoul(buf, NULL, 0);
8392 mutex_lock(&priv->mutex);
8393 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
8394 /* Cancel any currently running scans... */
8395 if (iwl4965_scan_cancel_timeout(priv, 100))
8396 IWL_WARNING("Could not cancel scan.\n");
8398 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
8399 "0x%04X\n", filter_flags);
8400 priv->staging_rxon.filter_flags =
8401 cpu_to_le32(filter_flags);
8402 iwl4965_commit_rxon(priv);
8405 mutex_unlock(&priv->mutex);
8410 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
8411 store_filter_flags);
8413 static ssize_t show_tune(struct device *d,
8414 struct device_attribute *attr, char *buf)
8416 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8418 return sprintf(buf, "0x%04X\n",
8419 (priv->phymode << 8) |
8420 le16_to_cpu(priv->active_rxon.channel));
8423 static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode);
8425 static ssize_t store_tune(struct device *d,
8426 struct device_attribute *attr,
8427 const char *buf, size_t count)
8429 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8430 char *p = (char *)buf;
8431 u16 tune = simple_strtoul(p, &p, 0);
8432 u8 phymode = (tune >> 8) & 0xff;
8433 u16 channel = tune & 0xff;
8435 IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel);
8437 mutex_lock(&priv->mutex);
8438 if ((le16_to_cpu(priv->staging_rxon.channel) != channel) ||
8439 (priv->phymode != phymode)) {
8440 const struct iwl4965_channel_info *ch_info;
8442 ch_info = iwl4965_get_channel_info(priv, phymode, channel);
8444 IWL_WARNING("Requested invalid phymode/channel "
8445 "combination: %d %d\n", phymode, channel);
8446 mutex_unlock(&priv->mutex);
8450 /* Cancel any currently running scans... */
8451 if (iwl4965_scan_cancel_timeout(priv, 100))
8452 IWL_WARNING("Could not cancel scan.\n");
8454 IWL_DEBUG_INFO("Committing phymode and "
8455 "rxon.channel = %d %d\n",
8458 iwl4965_set_rxon_channel(priv, phymode, channel);
8459 iwl4965_set_flags_for_phymode(priv, phymode);
8461 iwl4965_set_rate(priv);
8462 iwl4965_commit_rxon(priv);
8465 mutex_unlock(&priv->mutex);
8470 static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune);
8472 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
8474 static ssize_t show_measurement(struct device *d,
8475 struct device_attribute *attr, char *buf)
8477 struct iwl4965_priv *priv = dev_get_drvdata(d);
8478 struct iwl4965_spectrum_notification measure_report;
8479 u32 size = sizeof(measure_report), len = 0, ofs = 0;
8480 u8 *data = (u8 *) & measure_report;
8481 unsigned long flags;
8483 spin_lock_irqsave(&priv->lock, flags);
8484 if (!(priv->measurement_status & MEASUREMENT_READY)) {
8485 spin_unlock_irqrestore(&priv->lock, flags);
8488 memcpy(&measure_report, &priv->measure_report, size);
8489 priv->measurement_status = 0;
8490 spin_unlock_irqrestore(&priv->lock, flags);
8492 while (size && (PAGE_SIZE - len)) {
8493 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8494 PAGE_SIZE - len, 1);
8496 if (PAGE_SIZE - len)
8500 size -= min(size, 16U);
8506 static ssize_t store_measurement(struct device *d,
8507 struct device_attribute *attr,
8508 const char *buf, size_t count)
8510 struct iwl4965_priv *priv = dev_get_drvdata(d);
8511 struct ieee80211_measurement_params params = {
8512 .channel = le16_to_cpu(priv->active_rxon.channel),
8513 .start_time = cpu_to_le64(priv->last_tsf),
8514 .duration = cpu_to_le16(1),
8516 u8 type = IWL_MEASURE_BASIC;
8522 strncpy(buffer, buf, min(sizeof(buffer), count));
8523 channel = simple_strtoul(p, NULL, 0);
8525 params.channel = channel;
8528 while (*p && *p != ' ')
8531 type = simple_strtoul(p + 1, NULL, 0);
8534 IWL_DEBUG_INFO("Invoking measurement of type %d on "
8535 "channel %d (for '%s')\n", type, params.channel, buf);
8536 iwl4965_get_measurement(priv, ¶ms, type);
8541 static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
8542 show_measurement, store_measurement);
8543 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
8545 static ssize_t store_retry_rate(struct device *d,
8546 struct device_attribute *attr,
8547 const char *buf, size_t count)
8549 struct iwl4965_priv *priv = dev_get_drvdata(d);
8551 priv->retry_rate = simple_strtoul(buf, NULL, 0);
8552 if (priv->retry_rate <= 0)
8553 priv->retry_rate = 1;
8558 static ssize_t show_retry_rate(struct device *d,
8559 struct device_attribute *attr, char *buf)
8561 struct iwl4965_priv *priv = dev_get_drvdata(d);
8562 return sprintf(buf, "%d", priv->retry_rate);
8565 static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
8568 static ssize_t store_power_level(struct device *d,
8569 struct device_attribute *attr,
8570 const char *buf, size_t count)
8572 struct iwl4965_priv *priv = dev_get_drvdata(d);
8576 mode = simple_strtoul(buf, NULL, 0);
8577 mutex_lock(&priv->mutex);
8579 if (!iwl4965_is_ready(priv)) {
8584 if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
8585 mode = IWL_POWER_AC;
8587 mode |= IWL_POWER_ENABLED;
8589 if (mode != priv->power_mode) {
8590 rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode));
8592 IWL_DEBUG_MAC80211("failed setting power mode.\n");
8595 priv->power_mode = mode;
8601 mutex_unlock(&priv->mutex);
8605 #define MAX_WX_STRING 80
8607 /* Values are in microsecond */
8608 static const s32 timeout_duration[] = {
8615 static const s32 period_duration[] = {
8623 static ssize_t show_power_level(struct device *d,
8624 struct device_attribute *attr, char *buf)
8626 struct iwl4965_priv *priv = dev_get_drvdata(d);
8627 int level = IWL_POWER_LEVEL(priv->power_mode);
8630 p += sprintf(p, "%d ", level);
8632 case IWL_POWER_MODE_CAM:
8634 p += sprintf(p, "(AC)");
8636 case IWL_POWER_BATTERY:
8637 p += sprintf(p, "(BATTERY)");
8641 "(Timeout %dms, Period %dms)",
8642 timeout_duration[level - 1] / 1000,
8643 period_duration[level - 1] / 1000);
8646 if (!(priv->power_mode & IWL_POWER_ENABLED))
8647 p += sprintf(p, " OFF\n");
8649 p += sprintf(p, " \n");
8651 return (p - buf + 1);
8655 static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
8658 static ssize_t show_channels(struct device *d,
8659 struct device_attribute *attr, char *buf)
8661 struct iwl4965_priv *priv = dev_get_drvdata(d);
8663 struct ieee80211_channel *channels = NULL;
8664 const struct ieee80211_hw_mode *hw_mode = NULL;
8667 if (!iwl4965_is_ready(priv))
8670 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211G);
8672 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211B);
8674 channels = hw_mode->channels;
8675 count = hw_mode->num_channels;
8680 "Displaying %d channels in 2.4GHz band "
8681 "(802.11bg):\n", count);
8683 for (i = 0; i < count; i++)
8684 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8686 channels[i].power_level,
8688 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8689 " (IEEE 802.11h required)" : "",
8690 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8693 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8696 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8697 "active/passive" : "passive only");
8699 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211A);
8701 channels = hw_mode->channels;
8702 count = hw_mode->num_channels;
8708 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
8709 "(802.11a):\n", count);
8711 for (i = 0; i < count; i++)
8712 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8714 channels[i].power_level,
8716 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8717 " (IEEE 802.11h required)" : "",
8718 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8721 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8724 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8725 "active/passive" : "passive only");
8730 static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
8732 static ssize_t show_statistics(struct device *d,
8733 struct device_attribute *attr, char *buf)
8735 struct iwl4965_priv *priv = dev_get_drvdata(d);
8736 u32 size = sizeof(struct iwl4965_notif_statistics);
8737 u32 len = 0, ofs = 0;
8738 u8 *data = (u8 *) & priv->statistics;
8741 if (!iwl4965_is_alive(priv))
8744 mutex_lock(&priv->mutex);
8745 rc = iwl4965_send_statistics_request(priv);
8746 mutex_unlock(&priv->mutex);
8750 "Error sending statistics request: 0x%08X\n", rc);
8754 while (size && (PAGE_SIZE - len)) {
8755 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8756 PAGE_SIZE - len, 1);
8758 if (PAGE_SIZE - len)
8762 size -= min(size, 16U);
8768 static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
8770 static ssize_t show_antenna(struct device *d,
8771 struct device_attribute *attr, char *buf)
8773 struct iwl4965_priv *priv = dev_get_drvdata(d);
8775 if (!iwl4965_is_alive(priv))
8778 return sprintf(buf, "%d\n", priv->antenna);
8781 static ssize_t store_antenna(struct device *d,
8782 struct device_attribute *attr,
8783 const char *buf, size_t count)
8786 struct iwl4965_priv *priv = dev_get_drvdata(d);
8791 if (sscanf(buf, "%1i", &ant) != 1) {
8792 IWL_DEBUG_INFO("not in hex or decimal form.\n");
8796 if ((ant >= 0) && (ant <= 2)) {
8797 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
8798 priv->antenna = (enum iwl4965_antenna)ant;
8800 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
8806 static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
8808 static ssize_t show_status(struct device *d,
8809 struct device_attribute *attr, char *buf)
8811 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8812 if (!iwl4965_is_alive(priv))
8814 return sprintf(buf, "0x%08x\n", (int)priv->status);
8817 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
8819 static ssize_t dump_error_log(struct device *d,
8820 struct device_attribute *attr,
8821 const char *buf, size_t count)
8823 char *p = (char *)buf;
8826 iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data);
8828 return strnlen(buf, count);
8831 static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
8833 static ssize_t dump_event_log(struct device *d,
8834 struct device_attribute *attr,
8835 const char *buf, size_t count)
8837 char *p = (char *)buf;
8840 iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data);
8842 return strnlen(buf, count);
8845 static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
8847 /*****************************************************************************
8849 * driver setup and teardown
8851 *****************************************************************************/
8853 static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv)
8855 priv->workqueue = create_workqueue(DRV_NAME);
8857 init_waitqueue_head(&priv->wait_command_queue);
8859 INIT_WORK(&priv->up, iwl4965_bg_up);
8860 INIT_WORK(&priv->restart, iwl4965_bg_restart);
8861 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
8862 INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
8863 INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
8864 INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
8865 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
8866 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
8867 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
8868 INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start);
8869 INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start);
8870 INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
8872 iwl4965_hw_setup_deferred_work(priv);
8874 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
8875 iwl4965_irq_tasklet, (unsigned long)priv);
8878 static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv)
8880 iwl4965_hw_cancel_deferred_work(priv);
8882 cancel_delayed_work_sync(&priv->init_alive_start);
8883 cancel_delayed_work(&priv->scan_check);
8884 cancel_delayed_work(&priv->alive_start);
8885 cancel_delayed_work(&priv->post_associate);
8886 cancel_work_sync(&priv->beacon_update);
8889 static struct attribute *iwl4965_sysfs_entries[] = {
8890 &dev_attr_antenna.attr,
8891 &dev_attr_channels.attr,
8892 &dev_attr_dump_errors.attr,
8893 &dev_attr_dump_events.attr,
8894 &dev_attr_flags.attr,
8895 &dev_attr_filter_flags.attr,
8896 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
8897 &dev_attr_measurement.attr,
8899 &dev_attr_power_level.attr,
8900 &dev_attr_retry_rate.attr,
8901 &dev_attr_rf_kill.attr,
8902 &dev_attr_rs_window.attr,
8903 &dev_attr_statistics.attr,
8904 &dev_attr_status.attr,
8905 &dev_attr_temperature.attr,
8906 &dev_attr_tune.attr,
8907 &dev_attr_tx_power.attr,
8912 static struct attribute_group iwl4965_attribute_group = {
8913 .name = NULL, /* put in device directory */
8914 .attrs = iwl4965_sysfs_entries,
8917 static struct ieee80211_ops iwl4965_hw_ops = {
8918 .tx = iwl4965_mac_tx,
8919 .start = iwl4965_mac_start,
8920 .stop = iwl4965_mac_stop,
8921 .add_interface = iwl4965_mac_add_interface,
8922 .remove_interface = iwl4965_mac_remove_interface,
8923 .config = iwl4965_mac_config,
8924 .config_interface = iwl4965_mac_config_interface,
8925 .configure_filter = iwl4965_configure_filter,
8926 .set_key = iwl4965_mac_set_key,
8927 .get_stats = iwl4965_mac_get_stats,
8928 .get_tx_stats = iwl4965_mac_get_tx_stats,
8929 .conf_tx = iwl4965_mac_conf_tx,
8930 .get_tsf = iwl4965_mac_get_tsf,
8931 .reset_tsf = iwl4965_mac_reset_tsf,
8932 .beacon_update = iwl4965_mac_beacon_update,
8933 .erp_ie_changed = iwl4965_mac_erp_ie_changed,
8934 #ifdef CONFIG_IWL4965_HT
8935 .conf_ht = iwl4965_mac_conf_ht,
8936 .get_ht_capab = iwl4965_mac_get_ht_capab,
8937 #ifdef CONFIG_IWL4965_HT_AGG
8938 .ht_tx_agg_start = iwl4965_mac_ht_tx_agg_start,
8939 .ht_tx_agg_stop = iwl4965_mac_ht_tx_agg_stop,
8940 .ht_rx_agg_start = iwl4965_mac_ht_rx_agg_start,
8941 .ht_rx_agg_stop = iwl4965_mac_ht_rx_agg_stop,
8942 #endif /* CONFIG_IWL4965_HT_AGG */
8943 #endif /* CONFIG_IWL4965_HT */
8944 .hw_scan = iwl4965_mac_hw_scan
8947 static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
8950 struct iwl4965_priv *priv;
8951 struct ieee80211_hw *hw;
8954 if (iwl4965_param_disable_hw_scan) {
8955 IWL_DEBUG_INFO("Disabling hw_scan\n");
8956 iwl4965_hw_ops.hw_scan = NULL;
8959 if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) ||
8960 (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) {
8961 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
8962 IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES);
8967 /* mac80211 allocates memory for this device instance, including
8968 * space for this driver's private structure */
8969 hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops);
8971 IWL_ERROR("Can not allocate network device\n");
8975 SET_IEEE80211_DEV(hw, &pdev->dev);
8977 hw->rate_control_algorithm = "iwl-4965-rs";
8979 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
8983 priv->pci_dev = pdev;
8984 priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna;
8985 #ifdef CONFIG_IWL4965_DEBUG
8986 iwl4965_debug_level = iwl4965_param_debug;
8987 atomic_set(&priv->restrict_refcnt, 0);
8989 priv->retry_rate = 1;
8991 priv->ibss_beacon = NULL;
8993 /* Tell mac80211 and its clients (e.g. Wireless Extensions)
8994 * the range of signal quality values that we'll provide.
8995 * Negative values for level/noise indicate that we'll provide dBm.
8996 * For WE, at least, non-0 values here *enable* display of values
8997 * in app (iwconfig). */
8998 hw->max_rssi = -20; /* signal level, negative indicates dBm */
8999 hw->max_noise = -20; /* noise level, negative indicates dBm */
9000 hw->max_signal = 100; /* link quality indication (%) */
9002 /* Tell mac80211 our Tx characteristics */
9003 hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
9006 #ifdef CONFIG_IWL4965_HT
9007 #ifdef CONFIG_IWL4965_HT_AGG
9009 #endif /* CONFIG_IWL4965_HT_AGG */
9010 #endif /* CONFIG_IWL4965_HT */
9012 spin_lock_init(&priv->lock);
9013 spin_lock_init(&priv->power_data.lock);
9014 spin_lock_init(&priv->sta_lock);
9015 spin_lock_init(&priv->hcmd_lock);
9016 spin_lock_init(&priv->lq_mngr.lock);
9018 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
9019 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
9021 INIT_LIST_HEAD(&priv->free_frames);
9023 mutex_init(&priv->mutex);
9024 if (pci_enable_device(pdev)) {
9026 goto out_ieee80211_free_hw;
9029 pci_set_master(pdev);
9031 iwl4965_clear_stations_table(priv);
9033 priv->data_retry_limit = -1;
9034 priv->ieee_channels = NULL;
9035 priv->ieee_rates = NULL;
9038 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
9040 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
9042 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
9043 goto out_pci_disable_device;
9046 pci_set_drvdata(pdev, priv);
9047 err = pci_request_regions(pdev, DRV_NAME);
9049 goto out_pci_disable_device;
9050 /* We disable the RETRY_TIMEOUT register (0x41) to keep
9051 * PCI Tx retries from interfering with C3 CPU state */
9052 pci_write_config_byte(pdev, 0x41, 0x00);
9053 priv->hw_base = pci_iomap(pdev, 0, 0);
9054 if (!priv->hw_base) {
9056 goto out_pci_release_regions;
9059 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
9060 (unsigned long long) pci_resource_len(pdev, 0));
9061 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
9063 /* Initialize module parameter values here */
9065 if (iwl4965_param_disable) {
9066 set_bit(STATUS_RF_KILL_SW, &priv->status);
9067 IWL_DEBUG_INFO("Radio disabled.\n");
9070 priv->iw_mode = IEEE80211_IF_TYPE_STA;
9073 priv->use_ant_b_for_management_frame = 1; /* start with ant B */
9074 priv->is_ht_enabled = 1;
9075 priv->channel_width = IWL_CHANNEL_WIDTH_40MHZ;
9076 priv->valid_antenna = 0x7; /* assume all 3 connected */
9077 priv->ps_mode = IWL_MIMO_PS_NONE;
9079 iwl4965_set_rxon_chain(priv);
9081 printk(KERN_INFO DRV_NAME
9082 ": Detected Intel Wireless WiFi Link 4965AGN\n");
9084 /* Device-specific setup */
9085 if (iwl4965_hw_set_hw_setting(priv)) {
9086 IWL_ERROR("failed to set hw settings\n");
9087 mutex_unlock(&priv->mutex);
9091 #ifdef CONFIG_IWL4965_QOS
9092 if (iwl4965_param_qos_enable)
9093 priv->qos_data.qos_enable = 1;
9095 iwl4965_reset_qos(priv);
9097 priv->qos_data.qos_active = 0;
9098 priv->qos_data.qos_cap.val = 0;
9099 #endif /* CONFIG_IWL4965_QOS */
9101 iwl4965_set_rxon_channel(priv, MODE_IEEE80211G, 6);
9102 iwl4965_setup_deferred_work(priv);
9103 iwl4965_setup_rx_handlers(priv);
9105 priv->rates_mask = IWL_RATES_MASK;
9106 /* If power management is turned on, default to AC mode */
9107 priv->power_mode = IWL_POWER_AC;
9108 priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
9110 iwl4965_disable_interrupts(priv);
9112 pci_enable_msi(pdev);
9114 err = request_irq(pdev->irq, iwl4965_isr, IRQF_SHARED, DRV_NAME, priv);
9116 IWL_ERROR("Error allocating IRQ %d\n", pdev->irq);
9117 goto out_disable_msi;
9120 mutex_lock(&priv->mutex);
9122 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
9124 IWL_ERROR("failed to create sysfs device attributes\n");
9125 mutex_unlock(&priv->mutex);
9126 goto out_release_irq;
9129 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
9130 * ucode filename and max sizes are card-specific. */
9131 err = iwl4965_read_ucode(priv);
9133 IWL_ERROR("Could not read microcode: %d\n", err);
9134 mutex_unlock(&priv->mutex);
9138 mutex_unlock(&priv->mutex);
9140 IWL_DEBUG_INFO("Queueing UP work.\n");
9142 queue_work(priv->workqueue, &priv->up);
9147 iwl4965_dealloc_ucode_pci(priv);
9149 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
9152 free_irq(pdev->irq, priv);
9155 pci_disable_msi(pdev);
9156 destroy_workqueue(priv->workqueue);
9157 priv->workqueue = NULL;
9158 iwl4965_unset_hw_setting(priv);
9161 pci_iounmap(pdev, priv->hw_base);
9162 out_pci_release_regions:
9163 pci_release_regions(pdev);
9164 out_pci_disable_device:
9165 pci_disable_device(pdev);
9166 pci_set_drvdata(pdev, NULL);
9167 out_ieee80211_free_hw:
9168 ieee80211_free_hw(priv->hw);
9173 static void iwl4965_pci_remove(struct pci_dev *pdev)
9175 struct iwl4965_priv *priv = pci_get_drvdata(pdev);
9176 struct list_head *p, *q;
9182 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
9184 set_bit(STATUS_EXIT_PENDING, &priv->status);
9188 /* Free MAC hash list for ADHOC */
9189 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
9190 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
9192 kfree(list_entry(p, struct iwl4965_ibss_seq, list));
9196 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
9198 iwl4965_dealloc_ucode_pci(priv);
9201 iwl4965_rx_queue_free(priv, &priv->rxq);
9202 iwl4965_hw_txq_ctx_free(priv);
9204 iwl4965_unset_hw_setting(priv);
9205 iwl4965_clear_stations_table(priv);
9207 if (priv->mac80211_registered) {
9208 ieee80211_unregister_hw(priv->hw);
9209 iwl4965_rate_control_unregister(priv->hw);
9212 /*netif_stop_queue(dev); */
9213 flush_workqueue(priv->workqueue);
9215 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
9216 * priv->workqueue... so we can't take down the workqueue
9218 destroy_workqueue(priv->workqueue);
9219 priv->workqueue = NULL;
9221 free_irq(pdev->irq, priv);
9222 pci_disable_msi(pdev);
9223 pci_iounmap(pdev, priv->hw_base);
9224 pci_release_regions(pdev);
9225 pci_disable_device(pdev);
9226 pci_set_drvdata(pdev, NULL);
9228 kfree(priv->channel_info);
9230 kfree(priv->ieee_channels);
9231 kfree(priv->ieee_rates);
9233 if (priv->ibss_beacon)
9234 dev_kfree_skb(priv->ibss_beacon);
9236 ieee80211_free_hw(priv->hw);
9241 static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
9243 struct iwl4965_priv *priv = pci_get_drvdata(pdev);
9245 set_bit(STATUS_IN_SUSPEND, &priv->status);
9247 /* Take down the device; powers it off, etc. */
9250 if (priv->mac80211_registered)
9251 ieee80211_stop_queues(priv->hw);
9253 pci_save_state(pdev);
9254 pci_disable_device(pdev);
9255 pci_set_power_state(pdev, PCI_D3hot);
9260 static void iwl4965_resume(struct iwl4965_priv *priv)
9262 unsigned long flags;
9264 /* The following it a temporary work around due to the
9265 * suspend / resume not fully initializing the NIC correctly.
9266 * Without all of the following, resume will not attempt to take
9267 * down the NIC (it shouldn't really need to) and will just try
9268 * and bring the NIC back up. However that fails during the
9269 * ucode verification process. This then causes iwl4965_down to be
9270 * called *after* iwl4965_hw_nic_init() has succeeded -- which
9271 * then lets the next init sequence succeed. So, we've
9272 * replicated all of that NIC init code here... */
9274 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
9276 iwl4965_hw_nic_init(priv);
9278 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
9279 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
9280 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
9281 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
9282 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
9283 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
9285 /* tell the device to stop sending interrupts */
9286 iwl4965_disable_interrupts(priv);
9288 spin_lock_irqsave(&priv->lock, flags);
9289 iwl4965_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
9291 if (!iwl4965_grab_nic_access(priv)) {
9292 iwl4965_write_prph(priv, APMG_CLK_DIS_REG,
9293 APMG_CLK_VAL_DMA_CLK_RQT);
9294 iwl4965_release_nic_access(priv);
9296 spin_unlock_irqrestore(&priv->lock, flags);
9300 iwl4965_hw_nic_reset(priv);
9302 /* Bring the device back up */
9303 clear_bit(STATUS_IN_SUSPEND, &priv->status);
9304 queue_work(priv->workqueue, &priv->up);
9307 static int iwl4965_pci_resume(struct pci_dev *pdev)
9309 struct iwl4965_priv *priv = pci_get_drvdata(pdev);
9312 printk(KERN_INFO "Coming out of suspend...\n");
9314 pci_set_power_state(pdev, PCI_D0);
9315 err = pci_enable_device(pdev);
9316 pci_restore_state(pdev);
9319 * Suspend/Resume resets the PCI configuration space, so we have to
9320 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
9321 * from interfering with C3 CPU state. pci_restore_state won't help
9322 * here since it only restores the first 64 bytes pci config header.
9324 pci_write_config_byte(pdev, 0x41, 0x00);
9326 iwl4965_resume(priv);
9331 #endif /* CONFIG_PM */
9333 /*****************************************************************************
9335 * driver and module entry point
9337 *****************************************************************************/
9339 static struct pci_driver iwl4965_driver = {
9341 .id_table = iwl4965_hw_card_ids,
9342 .probe = iwl4965_pci_probe,
9343 .remove = __devexit_p(iwl4965_pci_remove),
9345 .suspend = iwl4965_pci_suspend,
9346 .resume = iwl4965_pci_resume,
9350 static int __init iwl4965_init(void)
9354 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
9355 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
9356 ret = pci_register_driver(&iwl4965_driver);
9358 IWL_ERROR("Unable to initialize PCI module\n");
9361 #ifdef CONFIG_IWL4965_DEBUG
9362 ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level);
9364 IWL_ERROR("Unable to create driver sysfs file\n");
9365 pci_unregister_driver(&iwl4965_driver);
9373 static void __exit iwl4965_exit(void)
9375 #ifdef CONFIG_IWL4965_DEBUG
9376 driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level);
9378 pci_unregister_driver(&iwl4965_driver);
9381 module_param_named(antenna, iwl4965_param_antenna, int, 0444);
9382 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
9383 module_param_named(disable, iwl4965_param_disable, int, 0444);
9384 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
9385 module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444);
9386 MODULE_PARM_DESC(hwcrypto,
9387 "using hardware crypto engine (default 0 [software])\n");
9388 module_param_named(debug, iwl4965_param_debug, int, 0444);
9389 MODULE_PARM_DESC(debug, "debug output mask");
9390 module_param_named(disable_hw_scan, iwl4965_param_disable_hw_scan, int, 0444);
9391 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
9393 module_param_named(queues_num, iwl4965_param_queues_num, int, 0444);
9394 MODULE_PARM_DESC(queues_num, "number of hw queues.");
9397 module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444);
9398 MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
9400 module_exit(iwl4965_exit);
9401 module_init(iwl4965_init);