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_IWL3945_DEBUG
53 u32 iwl3945_debug_level;
56 static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
57 struct iwl3945_tx_queue *txq);
59 /******************************************************************************
63 ******************************************************************************/
65 /* module parameters */
66 static int iwl3945_param_disable_hw_scan;
67 static int iwl3945_param_debug;
68 static int iwl3945_param_disable; /* def: enable radio */
69 static int iwl3945_param_antenna; /* def: 0 = both antennas (use diversity) */
70 int iwl3945_param_hwcrypto; /* def: using software encryption */
71 static int iwl3945_param_qos_enable = 1;
72 int iwl3945_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 \
80 "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
82 #ifdef CONFIG_IWL3945_DEBUG
88 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
94 #define IWLWIFI_VERSION "1.1.19k" VD VS
95 #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation"
96 #define DRV_VERSION IWLWIFI_VERSION
98 /* Change firmware file name, using "-" and incrementing number,
99 * *only* when uCode interface or architecture changes so that it
100 * is not compatible with earlier drivers.
101 * This number will also appear in << 8 position of 1st dword of uCode file */
102 #define IWL3945_UCODE_API "-1"
104 MODULE_DESCRIPTION(DRV_DESCRIPTION);
105 MODULE_VERSION(DRV_VERSION);
106 MODULE_AUTHOR(DRV_COPYRIGHT);
107 MODULE_LICENSE("GPL");
109 static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
111 u16 fc = le16_to_cpu(hdr->frame_control);
112 int hdr_len = ieee80211_get_hdrlen(fc);
114 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
115 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
119 static const struct ieee80211_hw_mode *iwl3945_get_hw_mode(
120 struct iwl3945_priv *priv, int mode)
124 for (i = 0; i < 3; i++)
125 if (priv->modes[i].mode == mode)
126 return &priv->modes[i];
131 static int iwl3945_is_empty_essid(const char *essid, int essid_len)
133 /* Single white space is for Linksys APs */
134 if (essid_len == 1 && essid[0] == ' ')
137 /* Otherwise, if the entire essid is 0, we assume it is hidden */
140 if (essid[essid_len] != '\0')
147 static const char *iwl3945_escape_essid(const char *essid, u8 essid_len)
149 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
150 const char *s = essid;
153 if (iwl3945_is_empty_essid(essid, essid_len)) {
154 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
158 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
159 while (essid_len--) {
171 static void iwl3945_print_hex_dump(int level, void *p, u32 len)
173 #ifdef CONFIG_IWL3945_DEBUG
174 if (!(iwl3945_debug_level & level))
177 print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
182 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
185 * Theory of operation
187 * A queue is a circular buffers with 'Read' and 'Write' pointers.
188 * 2 empty entries always kept in the buffer to protect from overflow.
190 * For Tx queue, there are low mark and high mark limits. If, after queuing
191 * the packet for Tx, free space become < low mark, Tx queue stopped. When
192 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
195 * The IWL operates with six queues, one receive queue in the device's
196 * sram, one transmit queue for sending commands to the device firmware,
197 * and four transmit queues for data.
198 ***************************************************/
200 static int iwl3945_queue_space(const struct iwl3945_queue *q)
202 int s = q->read_ptr - q->write_ptr;
204 if (q->read_ptr > q->write_ptr)
209 /* keep some reserve to not confuse empty and full situations */
216 /* XXX: n_bd must be power-of-two size */
217 static inline int iwl3945_queue_inc_wrap(int index, int n_bd)
219 return ++index & (n_bd - 1);
222 /* XXX: n_bd must be power-of-two size */
223 static inline int iwl3945_queue_dec_wrap(int index, int n_bd)
225 return --index & (n_bd - 1);
228 static inline int x2_queue_used(const struct iwl3945_queue *q, int i)
230 return q->write_ptr > q->read_ptr ?
231 (i >= q->read_ptr && i < q->write_ptr) :
232 !(i < q->read_ptr && i >= q->write_ptr);
235 static inline u8 get_cmd_index(struct iwl3945_queue *q, u32 index, int is_huge)
240 return index & (q->n_window - 1);
243 static int iwl3945_queue_init(struct iwl3945_priv *priv, struct iwl3945_queue *q,
244 int count, int slots_num, u32 id)
247 q->n_window = slots_num;
250 /* count must be power-of-two size, otherwise iwl3945_queue_inc_wrap
251 * and iwl3945_queue_dec_wrap are broken. */
252 BUG_ON(!is_power_of_2(count));
254 /* slots_num must be power-of-two size, otherwise
255 * get_cmd_index is broken. */
256 BUG_ON(!is_power_of_2(slots_num));
258 q->low_mark = q->n_window / 4;
262 q->high_mark = q->n_window / 8;
263 if (q->high_mark < 2)
266 q->write_ptr = q->read_ptr = 0;
271 static int iwl3945_tx_queue_alloc(struct iwl3945_priv *priv,
272 struct iwl3945_tx_queue *txq, u32 id)
274 struct pci_dev *dev = priv->pci_dev;
276 if (id != IWL_CMD_QUEUE_NUM) {
277 txq->txb = kmalloc(sizeof(txq->txb[0]) *
278 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
280 IWL_ERROR("kmalloc for auxiliary BD "
281 "structures failed\n");
287 txq->bd = pci_alloc_consistent(dev,
288 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
292 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
293 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
309 int iwl3945_tx_queue_init(struct iwl3945_priv *priv,
310 struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id)
312 struct pci_dev *dev = priv->pci_dev;
316 /* allocate command space + one big command for scan since scan
317 * command is very huge the system will not have two scan at the
319 len = sizeof(struct iwl3945_cmd) * slots_num;
320 if (txq_id == IWL_CMD_QUEUE_NUM)
321 len += IWL_MAX_SCAN_SIZE;
322 txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
326 rc = iwl3945_tx_queue_alloc(priv, txq, txq_id);
328 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
332 txq->need_update = 0;
334 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
335 * iwl3945_queue_inc_wrap and iwl3945_queue_dec_wrap are broken. */
336 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
337 iwl3945_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
339 iwl3945_hw_tx_queue_init(priv, txq);
345 * iwl3945_tx_queue_free - Deallocate DMA queue.
346 * @txq: Transmit queue to deallocate.
348 * Empty queue by removing and destroying all BD's.
349 * Free all buffers. txq itself is not freed.
352 void iwl3945_tx_queue_free(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq)
354 struct iwl3945_queue *q = &txq->q;
355 struct pci_dev *dev = priv->pci_dev;
361 /* first, empty all BD's */
362 for (; q->write_ptr != q->read_ptr;
363 q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd))
364 iwl3945_hw_txq_free_tfd(priv, txq);
366 len = sizeof(struct iwl3945_cmd) * q->n_window;
367 if (q->id == IWL_CMD_QUEUE_NUM)
368 len += IWL_MAX_SCAN_SIZE;
370 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
372 /* free buffers belonging to queue itself */
374 pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) *
375 txq->q.n_bd, txq->bd, txq->q.dma_addr);
382 /* 0 fill whole structure */
383 memset(txq, 0, sizeof(*txq));
386 const u8 iwl3945_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
388 /*************** STATION TABLE MANAGEMENT ****
389 * mac80211 should be examined to determine if sta_info is duplicating
390 * the functionality provided here
393 /**************************************************************/
394 #if 0 /* temporary disable till we add real remove station */
395 static u8 iwl3945_remove_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap)
397 int index = IWL_INVALID_STATION;
401 spin_lock_irqsave(&priv->sta_lock, flags);
405 else if (is_broadcast_ether_addr(addr))
406 index = priv->hw_setting.bcast_sta_id;
408 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
409 if (priv->stations[i].used &&
410 !compare_ether_addr(priv->stations[i].sta.sta.addr,
416 if (unlikely(index == IWL_INVALID_STATION))
419 if (priv->stations[index].used) {
420 priv->stations[index].used = 0;
421 priv->num_stations--;
424 BUG_ON(priv->num_stations < 0);
427 spin_unlock_irqrestore(&priv->sta_lock, flags);
431 static void iwl3945_clear_stations_table(struct iwl3945_priv *priv)
435 spin_lock_irqsave(&priv->sta_lock, flags);
437 priv->num_stations = 0;
438 memset(priv->stations, 0, sizeof(priv->stations));
440 spin_unlock_irqrestore(&priv->sta_lock, flags);
444 u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap, u8 flags)
447 int index = IWL_INVALID_STATION;
448 struct iwl3945_station_entry *station;
449 unsigned long flags_spin;
450 DECLARE_MAC_BUF(mac);
453 spin_lock_irqsave(&priv->sta_lock, flags_spin);
456 else if (is_broadcast_ether_addr(addr))
457 index = priv->hw_setting.bcast_sta_id;
459 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
460 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
466 if (!priv->stations[i].used &&
467 index == IWL_INVALID_STATION)
471 /* These two conditions has the same outcome but keep them separate
472 since they have different meaning */
473 if (unlikely(index == IWL_INVALID_STATION)) {
474 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
478 if (priv->stations[index].used &&
479 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
480 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
484 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
485 station = &priv->stations[index];
487 priv->num_stations++;
489 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
490 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
491 station->sta.mode = 0;
492 station->sta.sta.sta_id = index;
493 station->sta.station_flags = 0;
495 if (priv->phymode == MODE_IEEE80211A)
496 rate = IWL_RATE_6M_PLCP;
498 rate = IWL_RATE_1M_PLCP;
500 /* Turn on both antennas for the station... */
501 station->sta.rate_n_flags =
502 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
503 station->current_rate.rate_n_flags =
504 le16_to_cpu(station->sta.rate_n_flags);
506 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
507 iwl3945_send_add_station(priv, &station->sta, flags);
512 /*************** DRIVER STATUS FUNCTIONS *****/
514 static inline int iwl3945_is_ready(struct iwl3945_priv *priv)
516 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
517 * set but EXIT_PENDING is not */
518 return test_bit(STATUS_READY, &priv->status) &&
519 test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
520 !test_bit(STATUS_EXIT_PENDING, &priv->status);
523 static inline int iwl3945_is_alive(struct iwl3945_priv *priv)
525 return test_bit(STATUS_ALIVE, &priv->status);
528 static inline int iwl3945_is_init(struct iwl3945_priv *priv)
530 return test_bit(STATUS_INIT, &priv->status);
533 static inline int iwl3945_is_rfkill(struct iwl3945_priv *priv)
535 return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
536 test_bit(STATUS_RF_KILL_SW, &priv->status);
539 static inline int iwl3945_is_ready_rf(struct iwl3945_priv *priv)
542 if (iwl3945_is_rfkill(priv))
545 return iwl3945_is_ready(priv);
548 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
550 #define IWL_CMD(x) case x : return #x
552 static const char *get_cmd_string(u8 cmd)
555 IWL_CMD(REPLY_ALIVE);
556 IWL_CMD(REPLY_ERROR);
558 IWL_CMD(REPLY_RXON_ASSOC);
559 IWL_CMD(REPLY_QOS_PARAM);
560 IWL_CMD(REPLY_RXON_TIMING);
561 IWL_CMD(REPLY_ADD_STA);
562 IWL_CMD(REPLY_REMOVE_STA);
563 IWL_CMD(REPLY_REMOVE_ALL_STA);
564 IWL_CMD(REPLY_3945_RX);
566 IWL_CMD(REPLY_RATE_SCALE);
567 IWL_CMD(REPLY_LEDS_CMD);
568 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
569 IWL_CMD(RADAR_NOTIFICATION);
570 IWL_CMD(REPLY_QUIET_CMD);
571 IWL_CMD(REPLY_CHANNEL_SWITCH);
572 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
573 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
574 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
575 IWL_CMD(POWER_TABLE_CMD);
576 IWL_CMD(PM_SLEEP_NOTIFICATION);
577 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
578 IWL_CMD(REPLY_SCAN_CMD);
579 IWL_CMD(REPLY_SCAN_ABORT_CMD);
580 IWL_CMD(SCAN_START_NOTIFICATION);
581 IWL_CMD(SCAN_RESULTS_NOTIFICATION);
582 IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
583 IWL_CMD(BEACON_NOTIFICATION);
584 IWL_CMD(REPLY_TX_BEACON);
585 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
586 IWL_CMD(QUIET_NOTIFICATION);
587 IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
588 IWL_CMD(MEASURE_ABORT_NOTIFICATION);
589 IWL_CMD(REPLY_BT_CONFIG);
590 IWL_CMD(REPLY_STATISTICS_CMD);
591 IWL_CMD(STATISTICS_NOTIFICATION);
592 IWL_CMD(REPLY_CARD_STATE_CMD);
593 IWL_CMD(CARD_STATE_NOTIFICATION);
594 IWL_CMD(MISSED_BEACONS_NOTIFICATION);
601 #define HOST_COMPLETE_TIMEOUT (HZ / 2)
604 * iwl3945_enqueue_hcmd - enqueue a uCode command
605 * @priv: device private data point
606 * @cmd: a point to the ucode command structure
608 * The function returns < 0 values to indicate the operation is
609 * failed. On success, it turns the index (> 0) of command in the
612 static int iwl3945_enqueue_hcmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
614 struct iwl3945_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
615 struct iwl3945_queue *q = &txq->q;
616 struct iwl3945_tfd_frame *tfd;
618 struct iwl3945_cmd *out_cmd;
620 u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
621 dma_addr_t phys_addr;
627 /* If any of the command structures end up being larger than
628 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
629 * we will need to increase the size of the TFD entries */
630 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
631 !(cmd->meta.flags & CMD_SIZE_HUGE));
633 if (iwl3945_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
634 IWL_ERROR("No space for Tx\n");
638 spin_lock_irqsave(&priv->hcmd_lock, flags);
640 tfd = &txq->bd[q->write_ptr];
641 memset(tfd, 0, sizeof(*tfd));
643 control_flags = (u32 *) tfd;
645 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
646 out_cmd = &txq->cmd[idx];
648 out_cmd->hdr.cmd = cmd->id;
649 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
650 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
652 /* At this point, the out_cmd now has all of the incoming cmd
655 out_cmd->hdr.flags = 0;
656 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
657 INDEX_TO_SEQ(q->write_ptr));
658 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
659 out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
661 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
662 offsetof(struct iwl3945_cmd, hdr);
663 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
665 pad = U32_PAD(cmd->len);
666 count = TFD_CTL_COUNT_GET(*control_flags);
667 *control_flags = TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad);
669 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
670 "%d bytes at %d[%d]:%d\n",
671 get_cmd_string(out_cmd->hdr.cmd),
672 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
673 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
675 txq->need_update = 1;
676 q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd);
677 ret = iwl3945_tx_queue_update_write_ptr(priv, txq);
679 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
680 return ret ? ret : idx;
683 static int iwl3945_send_cmd_async(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
687 BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
689 /* An asynchronous command can not expect an SKB to be set. */
690 BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
692 /* An asynchronous command MUST have a callback. */
693 BUG_ON(!cmd->meta.u.callback);
695 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
698 ret = iwl3945_enqueue_hcmd(priv, cmd);
700 IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
701 get_cmd_string(cmd->id), ret);
707 static int iwl3945_send_cmd_sync(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
711 static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
713 BUG_ON(cmd->meta.flags & CMD_ASYNC);
715 /* A synchronous command can not have a callback set. */
716 BUG_ON(cmd->meta.u.callback != NULL);
718 if (atomic_xchg(&entry, 1)) {
719 IWL_ERROR("Error sending %s: Already sending a host command\n",
720 get_cmd_string(cmd->id));
724 set_bit(STATUS_HCMD_ACTIVE, &priv->status);
726 if (cmd->meta.flags & CMD_WANT_SKB)
727 cmd->meta.source = &cmd->meta;
729 cmd_idx = iwl3945_enqueue_hcmd(priv, cmd);
732 IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
733 get_cmd_string(cmd->id), ret);
737 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
738 !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
739 HOST_COMPLETE_TIMEOUT);
741 if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
742 IWL_ERROR("Error sending %s: time out after %dms.\n",
743 get_cmd_string(cmd->id),
744 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
746 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
752 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
753 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
754 get_cmd_string(cmd->id));
758 if (test_bit(STATUS_FW_ERROR, &priv->status)) {
759 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
760 get_cmd_string(cmd->id));
764 if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
765 IWL_ERROR("Error: Response NULL in '%s'\n",
766 get_cmd_string(cmd->id));
775 if (cmd->meta.flags & CMD_WANT_SKB) {
776 struct iwl3945_cmd *qcmd;
778 /* Cancel the CMD_WANT_SKB flag for the cmd in the
779 * TX cmd queue. Otherwise in case the cmd comes
780 * in later, it will possibly set an invalid
781 * address (cmd->meta.source). */
782 qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
783 qcmd->meta.flags &= ~CMD_WANT_SKB;
786 if (cmd->meta.u.skb) {
787 dev_kfree_skb_any(cmd->meta.u.skb);
788 cmd->meta.u.skb = NULL;
791 atomic_set(&entry, 0);
795 int iwl3945_send_cmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
797 if (cmd->meta.flags & CMD_ASYNC)
798 return iwl3945_send_cmd_async(priv, cmd);
800 return iwl3945_send_cmd_sync(priv, cmd);
803 int iwl3945_send_cmd_pdu(struct iwl3945_priv *priv, u8 id, u16 len, const void *data)
805 struct iwl3945_host_cmd cmd = {
811 return iwl3945_send_cmd_sync(priv, &cmd);
814 static int __must_check iwl3945_send_cmd_u32(struct iwl3945_priv *priv, u8 id, u32 val)
816 struct iwl3945_host_cmd cmd = {
822 return iwl3945_send_cmd_sync(priv, &cmd);
825 int iwl3945_send_statistics_request(struct iwl3945_priv *priv)
827 return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
831 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
832 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
833 * @channel: Any channel valid for the requested phymode
835 * In addition to setting the staging RXON, priv->phymode is also set.
837 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
838 * in the staging RXON flag structure based on the phymode
840 static int iwl3945_set_rxon_channel(struct iwl3945_priv *priv, u8 phymode, u16 channel)
842 if (!iwl3945_get_channel_info(priv, phymode, channel)) {
843 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
848 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
849 (priv->phymode == phymode))
852 priv->staging_rxon.channel = cpu_to_le16(channel);
853 if (phymode == MODE_IEEE80211A)
854 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
856 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
858 priv->phymode = phymode;
860 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode);
866 * iwl3945_check_rxon_cmd - validate RXON structure is valid
868 * NOTE: This is really only useful during development and can eventually
869 * be #ifdef'd out once the driver is stable and folks aren't actively
872 static int iwl3945_check_rxon_cmd(struct iwl3945_rxon_cmd *rxon)
877 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
878 error |= le32_to_cpu(rxon->flags &
879 (RXON_FLG_TGJ_NARROW_BAND_MSK |
880 RXON_FLG_RADAR_DETECT_MSK));
882 IWL_WARNING("check 24G fields %d | %d\n",
885 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
886 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
888 IWL_WARNING("check 52 fields %d | %d\n",
890 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
892 IWL_WARNING("check 52 CCK %d | %d\n",
895 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
897 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
899 /* make sure basic rates 6Mbps and 1Mbps are supported */
900 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
901 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
903 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
905 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
907 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
909 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
910 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
912 IWL_WARNING("check CCK and short slot %d | %d\n",
915 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
916 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
918 IWL_WARNING("check CCK & auto detect %d | %d\n",
921 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
922 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
924 IWL_WARNING("check TGG and auto detect %d | %d\n",
927 if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
928 error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
929 RXON_FLG_ANT_A_MSK)) == 0);
931 IWL_WARNING("check antenna %d %d\n", counter++, error);
934 IWL_WARNING("Tuning to channel %d\n",
935 le16_to_cpu(rxon->channel));
938 IWL_ERROR("Not a valid iwl3945_rxon_assoc_cmd field values\n");
945 * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
946 * @priv: staging_rxon is compared to active_rxon
948 * If the RXON structure is changing enough to require a new tune,
949 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
950 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
952 static int iwl3945_full_rxon_required(struct iwl3945_priv *priv)
955 /* These items are only settable from the full RXON command */
956 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
957 compare_ether_addr(priv->staging_rxon.bssid_addr,
958 priv->active_rxon.bssid_addr) ||
959 compare_ether_addr(priv->staging_rxon.node_addr,
960 priv->active_rxon.node_addr) ||
961 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
962 priv->active_rxon.wlap_bssid_addr) ||
963 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
964 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
965 (priv->staging_rxon.air_propagation !=
966 priv->active_rxon.air_propagation) ||
967 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
970 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
971 * be updated with the RXON_ASSOC command -- however only some
972 * flag transitions are allowed using RXON_ASSOC */
974 /* Check if we are not switching bands */
975 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
976 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
979 /* Check if we are switching association toggle */
980 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
981 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
987 static int iwl3945_send_rxon_assoc(struct iwl3945_priv *priv)
990 struct iwl3945_rx_packet *res = NULL;
991 struct iwl3945_rxon_assoc_cmd rxon_assoc;
992 struct iwl3945_host_cmd cmd = {
993 .id = REPLY_RXON_ASSOC,
994 .len = sizeof(rxon_assoc),
995 .meta.flags = CMD_WANT_SKB,
998 const struct iwl3945_rxon_cmd *rxon1 = &priv->staging_rxon;
999 const struct iwl3945_rxon_cmd *rxon2 = &priv->active_rxon;
1001 if ((rxon1->flags == rxon2->flags) &&
1002 (rxon1->filter_flags == rxon2->filter_flags) &&
1003 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1004 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1005 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1009 rxon_assoc.flags = priv->staging_rxon.flags;
1010 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1011 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1012 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1013 rxon_assoc.reserved = 0;
1015 rc = iwl3945_send_cmd_sync(priv, &cmd);
1019 res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
1020 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1021 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1025 priv->alloc_rxb_skb--;
1026 dev_kfree_skb_any(cmd.meta.u.skb);
1032 * iwl3945_commit_rxon - commit staging_rxon to hardware
1034 * The RXON command in staging_rxon is committed to the hardware and
1035 * the active_rxon structure is updated with the new data. This
1036 * function correctly transitions out of the RXON_ASSOC_MSK state if
1037 * a HW tune is required based on the RXON structure changes.
1039 static int iwl3945_commit_rxon(struct iwl3945_priv *priv)
1041 /* cast away the const for active_rxon in this function */
1042 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
1044 DECLARE_MAC_BUF(mac);
1046 if (!iwl3945_is_alive(priv))
1049 /* always get timestamp with Rx frame */
1050 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
1052 /* select antenna */
1053 priv->staging_rxon.flags &=
1054 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
1055 priv->staging_rxon.flags |= iwl3945_get_antenna_flags(priv);
1057 rc = iwl3945_check_rxon_cmd(&priv->staging_rxon);
1059 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1063 /* If we don't need to send a full RXON, we can use
1064 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
1065 * and other flags for the current radio configuration. */
1066 if (!iwl3945_full_rxon_required(priv)) {
1067 rc = iwl3945_send_rxon_assoc(priv);
1069 IWL_ERROR("Error setting RXON_ASSOC "
1070 "configuration (%d).\n", rc);
1074 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1079 /* If we are currently associated and the new config requires
1080 * an RXON_ASSOC and the new config wants the associated mask enabled,
1081 * we must clear the associated from the active configuration
1082 * before we apply the new config */
1083 if (iwl3945_is_associated(priv) &&
1084 (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
1085 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1086 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1088 rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
1089 sizeof(struct iwl3945_rxon_cmd),
1090 &priv->active_rxon);
1092 /* If the mask clearing failed then we set
1093 * active_rxon back to what it was previously */
1095 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
1096 IWL_ERROR("Error clearing ASSOC_MSK on current "
1097 "configuration (%d).\n", rc);
1102 IWL_DEBUG_INFO("Sending RXON\n"
1103 "* with%s RXON_FILTER_ASSOC_MSK\n"
1106 ((priv->staging_rxon.filter_flags &
1107 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
1108 le16_to_cpu(priv->staging_rxon.channel),
1109 print_mac(mac, priv->staging_rxon.bssid_addr));
1111 /* Apply the new configuration */
1112 rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
1113 sizeof(struct iwl3945_rxon_cmd), &priv->staging_rxon);
1115 IWL_ERROR("Error setting new configuration (%d).\n", rc);
1119 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1121 iwl3945_clear_stations_table(priv);
1123 /* If we issue a new RXON command which required a tune then we must
1124 * send a new TXPOWER command or we won't be able to Tx any frames */
1125 rc = iwl3945_hw_reg_send_txpower(priv);
1127 IWL_ERROR("Error setting Tx power (%d).\n", rc);
1131 /* Add the broadcast address so we can send broadcast frames */
1132 if (iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0) ==
1133 IWL_INVALID_STATION) {
1134 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1138 /* If we have set the ASSOC_MSK and we are in BSS mode then
1139 * add the IWL_AP_ID to the station rate table */
1140 if (iwl3945_is_associated(priv) &&
1141 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
1142 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0)
1143 == IWL_INVALID_STATION) {
1144 IWL_ERROR("Error adding AP address for transmit.\n");
1148 /* Init the hardware's rate fallback order based on the
1150 rc = iwl3945_init_hw_rate_table(priv);
1152 IWL_ERROR("Error setting HW rate table: %02X\n", rc);
1159 static int iwl3945_send_bt_config(struct iwl3945_priv *priv)
1161 struct iwl3945_bt_cmd bt_cmd = {
1169 return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1170 sizeof(struct iwl3945_bt_cmd), &bt_cmd);
1173 static int iwl3945_send_scan_abort(struct iwl3945_priv *priv)
1176 struct iwl3945_rx_packet *res;
1177 struct iwl3945_host_cmd cmd = {
1178 .id = REPLY_SCAN_ABORT_CMD,
1179 .meta.flags = CMD_WANT_SKB,
1182 /* If there isn't a scan actively going on in the hardware
1183 * then we are in between scan bands and not actually
1184 * actively scanning, so don't send the abort command */
1185 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1186 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1190 rc = iwl3945_send_cmd_sync(priv, &cmd);
1192 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1196 res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
1197 if (res->u.status != CAN_ABORT_STATUS) {
1198 /* The scan abort will return 1 for success or
1199 * 2 for "failure". A failure condition can be
1200 * due to simply not being in an active scan which
1201 * can occur if we send the scan abort before we
1202 * the microcode has notified us that a scan is
1204 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
1205 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1206 clear_bit(STATUS_SCAN_HW, &priv->status);
1209 dev_kfree_skb_any(cmd.meta.u.skb);
1214 static int iwl3945_card_state_sync_callback(struct iwl3945_priv *priv,
1215 struct iwl3945_cmd *cmd,
1216 struct sk_buff *skb)
1224 * Use: Sets the device's internal card state to enable, disable, or halt
1226 * When in the 'enable' state the card operates as normal.
1227 * When in the 'disable' state, the card enters into a low power mode.
1228 * When in the 'halt' state, the card is shut down and must be fully
1229 * restarted to come back on.
1231 static int iwl3945_send_card_state(struct iwl3945_priv *priv, u32 flags, u8 meta_flag)
1233 struct iwl3945_host_cmd cmd = {
1234 .id = REPLY_CARD_STATE_CMD,
1237 .meta.flags = meta_flag,
1240 if (meta_flag & CMD_ASYNC)
1241 cmd.meta.u.callback = iwl3945_card_state_sync_callback;
1243 return iwl3945_send_cmd(priv, &cmd);
1246 static int iwl3945_add_sta_sync_callback(struct iwl3945_priv *priv,
1247 struct iwl3945_cmd *cmd, struct sk_buff *skb)
1249 struct iwl3945_rx_packet *res = NULL;
1252 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1256 res = (struct iwl3945_rx_packet *)skb->data;
1257 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1258 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1263 switch (res->u.add_sta.status) {
1264 case ADD_STA_SUCCESS_MSK:
1270 /* We didn't cache the SKB; let the caller free it */
1274 int iwl3945_send_add_station(struct iwl3945_priv *priv,
1275 struct iwl3945_addsta_cmd *sta, u8 flags)
1277 struct iwl3945_rx_packet *res = NULL;
1279 struct iwl3945_host_cmd cmd = {
1280 .id = REPLY_ADD_STA,
1281 .len = sizeof(struct iwl3945_addsta_cmd),
1282 .meta.flags = flags,
1286 if (flags & CMD_ASYNC)
1287 cmd.meta.u.callback = iwl3945_add_sta_sync_callback;
1289 cmd.meta.flags |= CMD_WANT_SKB;
1291 rc = iwl3945_send_cmd(priv, &cmd);
1293 if (rc || (flags & CMD_ASYNC))
1296 res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
1297 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1298 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1304 switch (res->u.add_sta.status) {
1305 case ADD_STA_SUCCESS_MSK:
1306 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1310 IWL_WARNING("REPLY_ADD_STA failed\n");
1315 priv->alloc_rxb_skb--;
1316 dev_kfree_skb_any(cmd.meta.u.skb);
1321 static int iwl3945_update_sta_key_info(struct iwl3945_priv *priv,
1322 struct ieee80211_key_conf *keyconf,
1325 unsigned long flags;
1326 __le16 key_flags = 0;
1328 switch (keyconf->alg) {
1330 key_flags |= STA_KEY_FLG_CCMP;
1331 key_flags |= cpu_to_le16(
1332 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1333 key_flags &= ~STA_KEY_FLG_INVALID;
1340 spin_lock_irqsave(&priv->sta_lock, flags);
1341 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1342 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
1343 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
1346 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
1348 priv->stations[sta_id].sta.key.key_flags = key_flags;
1349 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1350 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1352 spin_unlock_irqrestore(&priv->sta_lock, flags);
1354 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1355 iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
1359 static int iwl3945_clear_sta_key_info(struct iwl3945_priv *priv, u8 sta_id)
1361 unsigned long flags;
1363 spin_lock_irqsave(&priv->sta_lock, flags);
1364 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
1365 memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl3945_keyinfo));
1366 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
1367 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1368 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1369 spin_unlock_irqrestore(&priv->sta_lock, flags);
1371 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1372 iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
1376 static void iwl3945_clear_free_frames(struct iwl3945_priv *priv)
1378 struct list_head *element;
1380 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1381 priv->frames_count);
1383 while (!list_empty(&priv->free_frames)) {
1384 element = priv->free_frames.next;
1386 kfree(list_entry(element, struct iwl3945_frame, list));
1387 priv->frames_count--;
1390 if (priv->frames_count) {
1391 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1392 priv->frames_count);
1393 priv->frames_count = 0;
1397 static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl3945_priv *priv)
1399 struct iwl3945_frame *frame;
1400 struct list_head *element;
1401 if (list_empty(&priv->free_frames)) {
1402 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1404 IWL_ERROR("Could not allocate frame!\n");
1408 priv->frames_count++;
1412 element = priv->free_frames.next;
1414 return list_entry(element, struct iwl3945_frame, list);
1417 static void iwl3945_free_frame(struct iwl3945_priv *priv, struct iwl3945_frame *frame)
1419 memset(frame, 0, sizeof(*frame));
1420 list_add(&frame->list, &priv->free_frames);
1423 unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv *priv,
1424 struct ieee80211_hdr *hdr,
1425 const u8 *dest, int left)
1428 if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
1429 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
1430 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
1433 if (priv->ibss_beacon->len > left)
1436 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1438 return priv->ibss_beacon->len;
1441 static int iwl3945_rate_index_from_plcp(int plcp)
1445 for (i = 0; i < IWL_RATE_COUNT; i++)
1446 if (iwl3945_rates[i].plcp == plcp)
1451 static u8 iwl3945_rate_get_lowest_plcp(int rate_mask)
1455 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
1456 i = iwl3945_rates[i].next_ieee) {
1457 if (rate_mask & (1 << i))
1458 return iwl3945_rates[i].plcp;
1461 return IWL_RATE_INVALID;
1464 static int iwl3945_send_beacon_cmd(struct iwl3945_priv *priv)
1466 struct iwl3945_frame *frame;
1467 unsigned int frame_size;
1471 frame = iwl3945_get_free_frame(priv);
1474 IWL_ERROR("Could not obtain free frame buffer for beacon "
1479 if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
1480 rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic &
1482 if (rate == IWL_INVALID_RATE)
1483 rate = IWL_RATE_6M_PLCP;
1485 rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
1486 if (rate == IWL_INVALID_RATE)
1487 rate = IWL_RATE_1M_PLCP;
1490 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
1492 rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
1495 iwl3945_free_frame(priv, frame);
1500 /******************************************************************************
1502 * EEPROM related functions
1504 ******************************************************************************/
1506 static void get_eeprom_mac(struct iwl3945_priv *priv, u8 *mac)
1508 memcpy(mac, priv->eeprom.mac_address, 6);
1512 * iwl3945_eeprom_init - read EEPROM contents
1514 * Load the EEPROM from adapter into priv->eeprom
1516 * NOTE: This routine uses the non-debug IO access functions.
1518 int iwl3945_eeprom_init(struct iwl3945_priv *priv)
1520 u16 *e = (u16 *)&priv->eeprom;
1521 u32 gp = iwl3945_read32(priv, CSR_EEPROM_GP);
1523 int sz = sizeof(priv->eeprom);
1528 /* The EEPROM structure has several padding buffers within it
1529 * and when adding new EEPROM maps is subject to programmer errors
1530 * which may be very difficult to identify without explicitly
1531 * checking the resulting size of the eeprom map. */
1532 BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
1534 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
1535 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
1539 rc = iwl3945_eeprom_acquire_semaphore(priv);
1541 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
1545 /* eeprom is an array of 16bit values */
1546 for (addr = 0; addr < sz; addr += sizeof(u16)) {
1547 _iwl3945_write32(priv, CSR_EEPROM_REG, addr << 1);
1548 _iwl3945_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
1550 for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
1551 i += IWL_EEPROM_ACCESS_DELAY) {
1552 r = _iwl3945_read_direct32(priv, CSR_EEPROM_REG);
1553 if (r & CSR_EEPROM_REG_READ_VALID_MSK)
1555 udelay(IWL_EEPROM_ACCESS_DELAY);
1558 if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
1559 IWL_ERROR("Time out reading EEPROM[%d]", addr);
1562 e[addr / 2] = le16_to_cpu(r >> 16);
1568 /******************************************************************************
1570 * Misc. internal state and helper functions
1572 ******************************************************************************/
1573 #ifdef CONFIG_IWL3945_DEBUG
1576 * iwl3945_report_frame - dump frame to syslog during debug sessions
1578 * You may hack this function to show different aspects of received frames,
1579 * including selective frame dumps.
1580 * group100 parameter selects whether to show 1 out of 100 good frames.
1582 void iwl3945_report_frame(struct iwl3945_priv *priv,
1583 struct iwl3945_rx_packet *pkt,
1584 struct ieee80211_hdr *header, int group100)
1587 u32 print_summary = 0;
1588 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
1605 struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
1606 struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
1607 struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
1608 u8 *data = IWL_RX_DATA(pkt);
1611 fc = le16_to_cpu(header->frame_control);
1612 seq_ctl = le16_to_cpu(header->seq_ctrl);
1615 channel = le16_to_cpu(rx_hdr->channel);
1616 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
1617 rate_sym = rx_hdr->rate;
1618 length = le16_to_cpu(rx_hdr->len);
1620 /* end-of-frame status and timestamp */
1621 status = le32_to_cpu(rx_end->status);
1622 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
1623 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
1624 tsf = le64_to_cpu(rx_end->timestamp);
1626 /* signal statistics */
1627 rssi = rx_stats->rssi;
1628 agc = rx_stats->agc;
1629 sig_avg = le16_to_cpu(rx_stats->sig_avg);
1630 noise_diff = le16_to_cpu(rx_stats->noise_diff);
1632 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
1634 /* if data frame is to us and all is good,
1635 * (optionally) print summary for only 1 out of every 100 */
1636 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
1637 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
1640 print_summary = 1; /* print each frame */
1641 else if (priv->framecnt_to_us < 100) {
1642 priv->framecnt_to_us++;
1645 priv->framecnt_to_us = 0;
1650 /* print summary for all other frames */
1654 if (print_summary) {
1659 title = "100Frames";
1660 else if (fc & IEEE80211_FCTL_RETRY)
1662 else if (ieee80211_is_assoc_response(fc))
1664 else if (ieee80211_is_reassoc_response(fc))
1666 else if (ieee80211_is_probe_response(fc)) {
1668 print_dump = 1; /* dump frame contents */
1669 } else if (ieee80211_is_beacon(fc)) {
1671 print_dump = 1; /* dump frame contents */
1672 } else if (ieee80211_is_atim(fc))
1674 else if (ieee80211_is_auth(fc))
1676 else if (ieee80211_is_deauth(fc))
1678 else if (ieee80211_is_disassoc(fc))
1683 rate = iwl3945_rate_index_from_plcp(rate_sym);
1687 rate = iwl3945_rates[rate].ieee / 2;
1689 /* print frame summary.
1690 * MAC addresses show just the last byte (for brevity),
1691 * but you can hack it to show more, if you'd like to. */
1693 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
1694 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
1695 title, fc, header->addr1[5],
1696 length, rssi, channel, rate);
1698 /* src/dst addresses assume managed mode */
1699 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
1700 "src=0x%02x, rssi=%u, tim=%lu usec, "
1701 "phy=0x%02x, chnl=%d\n",
1702 title, fc, header->addr1[5],
1703 header->addr3[5], rssi,
1704 tsf_low - priv->scan_start_tsf,
1705 phy_flags, channel);
1709 iwl3945_print_hex_dump(IWL_DL_RX, data, length);
1713 static void iwl3945_unset_hw_setting(struct iwl3945_priv *priv)
1715 if (priv->hw_setting.shared_virt)
1716 pci_free_consistent(priv->pci_dev,
1717 sizeof(struct iwl3945_shared),
1718 priv->hw_setting.shared_virt,
1719 priv->hw_setting.shared_phys);
1723 * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field
1725 * return : set the bit for each supported rate insert in ie
1727 static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate,
1728 u16 basic_rate, int *left)
1730 u16 ret_rates = 0, bit;
1735 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1736 if (bit & supported_rate) {
1738 rates[*cnt] = iwl3945_rates[i].ieee |
1739 ((bit & basic_rate) ? 0x80 : 0x00);
1743 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
1752 * iwl3945_fill_probe_req - fill in all required fields and IE for probe request
1754 static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv,
1755 struct ieee80211_mgmt *frame,
1756 int left, int is_direct)
1760 u16 active_rates, ret_rates, cck_rates;
1762 /* Make sure there is enough space for the probe request,
1763 * two mandatory IEs and the data */
1769 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1770 memcpy(frame->da, iwl3945_broadcast_addr, ETH_ALEN);
1771 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
1772 memcpy(frame->bssid, iwl3945_broadcast_addr, ETH_ALEN);
1773 frame->seq_ctrl = 0;
1775 /* fill in our indirect SSID IE */
1782 pos = &(frame->u.probe_req.variable[0]);
1783 *pos++ = WLAN_EID_SSID;
1786 /* fill in our direct SSID IE... */
1789 left -= 2 + priv->essid_len;
1792 /* ... fill it in... */
1793 *pos++ = WLAN_EID_SSID;
1794 *pos++ = priv->essid_len;
1795 memcpy(pos, priv->essid, priv->essid_len);
1796 pos += priv->essid_len;
1797 len += 2 + priv->essid_len;
1800 /* fill in supported rate */
1806 /* ... fill it in... */
1807 *pos++ = WLAN_EID_SUPP_RATES;
1810 priv->active_rate = priv->rates_mask;
1811 active_rates = priv->active_rate;
1812 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1814 cck_rates = IWL_CCK_RATES_MASK & active_rates;
1815 ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates,
1816 priv->active_rate_basic, &left);
1817 active_rates &= ~ret_rates;
1819 ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates,
1820 priv->active_rate_basic, &left);
1821 active_rates &= ~ret_rates;
1825 if (active_rates == 0)
1828 /* fill in supported extended rate */
1833 /* ... fill it in... */
1834 *pos++ = WLAN_EID_EXT_SUPP_RATES;
1836 iwl3945_supported_rate_to_ie(pos, active_rates,
1837 priv->active_rate_basic, &left);
1848 #ifdef CONFIG_IWL3945_QOS
1849 static int iwl3945_send_qos_params_command(struct iwl3945_priv *priv,
1850 struct iwl3945_qosparam_cmd *qos)
1853 return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM,
1854 sizeof(struct iwl3945_qosparam_cmd), qos);
1857 static void iwl3945_reset_qos(struct iwl3945_priv *priv)
1863 unsigned long flags;
1866 spin_lock_irqsave(&priv->lock, flags);
1867 priv->qos_data.qos_active = 0;
1869 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
1870 if (priv->qos_data.qos_enable)
1871 priv->qos_data.qos_active = 1;
1872 if (!(priv->active_rate & 0xfff0)) {
1876 } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
1877 if (priv->qos_data.qos_enable)
1878 priv->qos_data.qos_active = 1;
1879 } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
1884 if (priv->qos_data.qos_active)
1887 priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
1888 priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
1889 priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
1890 priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
1891 priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
1893 if (priv->qos_data.qos_active) {
1895 priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
1896 priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
1897 priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
1898 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
1899 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
1902 priv->qos_data.def_qos_parm.ac[i].cw_min =
1903 cpu_to_le16((cw_min + 1) / 2 - 1);
1904 priv->qos_data.def_qos_parm.ac[i].cw_max =
1905 cpu_to_le16(cw_max);
1906 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
1908 priv->qos_data.def_qos_parm.ac[i].edca_txop =
1911 priv->qos_data.def_qos_parm.ac[i].edca_txop =
1913 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
1916 priv->qos_data.def_qos_parm.ac[i].cw_min =
1917 cpu_to_le16((cw_min + 1) / 4 - 1);
1918 priv->qos_data.def_qos_parm.ac[i].cw_max =
1919 cpu_to_le16((cw_max + 1) / 2 - 1);
1920 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
1921 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
1923 priv->qos_data.def_qos_parm.ac[i].edca_txop =
1926 priv->qos_data.def_qos_parm.ac[i].edca_txop =
1929 for (i = 1; i < 4; i++) {
1930 priv->qos_data.def_qos_parm.ac[i].cw_min =
1931 cpu_to_le16(cw_min);
1932 priv->qos_data.def_qos_parm.ac[i].cw_max =
1933 cpu_to_le16(cw_max);
1934 priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
1935 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
1936 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
1939 IWL_DEBUG_QOS("set QoS to default \n");
1941 spin_unlock_irqrestore(&priv->lock, flags);
1944 static void iwl3945_activate_qos(struct iwl3945_priv *priv, u8 force)
1946 unsigned long flags;
1948 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1951 if (!priv->qos_data.qos_enable)
1954 spin_lock_irqsave(&priv->lock, flags);
1955 priv->qos_data.def_qos_parm.qos_flags = 0;
1957 if (priv->qos_data.qos_cap.q_AP.queue_request &&
1958 !priv->qos_data.qos_cap.q_AP.txop_request)
1959 priv->qos_data.def_qos_parm.qos_flags |=
1960 QOS_PARAM_FLG_TXOP_TYPE_MSK;
1962 if (priv->qos_data.qos_active)
1963 priv->qos_data.def_qos_parm.qos_flags |=
1964 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
1966 spin_unlock_irqrestore(&priv->lock, flags);
1968 if (force || iwl3945_is_associated(priv)) {
1969 IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n",
1970 priv->qos_data.qos_active);
1972 iwl3945_send_qos_params_command(priv,
1973 &(priv->qos_data.def_qos_parm));
1977 #endif /* CONFIG_IWL3945_QOS */
1979 * Power management (not Tx power!) functions
1981 #define MSEC_TO_USEC 1024
1983 #define NOSLP __constant_cpu_to_le32(0)
1984 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK
1985 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1986 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1987 __constant_cpu_to_le32(X1), \
1988 __constant_cpu_to_le32(X2), \
1989 __constant_cpu_to_le32(X3), \
1990 __constant_cpu_to_le32(X4)}
1993 /* default power management (not Tx power) table values */
1995 static struct iwl3945_power_vec_entry range_0[IWL_POWER_AC] = {
1996 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1997 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1998 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1999 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
2000 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
2001 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
2005 static struct iwl3945_power_vec_entry range_1[IWL_POWER_AC] = {
2006 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2007 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
2008 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
2009 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
2010 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
2011 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
2012 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
2013 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
2014 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
2015 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
2018 int iwl3945_power_init_handle(struct iwl3945_priv *priv)
2021 struct iwl3945_power_mgr *pow_data;
2022 int size = sizeof(struct iwl3945_power_vec_entry) * IWL_POWER_AC;
2025 IWL_DEBUG_POWER("Initialize power \n");
2027 pow_data = &(priv->power_data);
2029 memset(pow_data, 0, sizeof(*pow_data));
2031 pow_data->active_index = IWL_POWER_RANGE_0;
2032 pow_data->dtim_val = 0xffff;
2034 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
2035 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
2037 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
2041 struct iwl3945_powertable_cmd *cmd;
2043 IWL_DEBUG_POWER("adjust power command flags\n");
2045 for (i = 0; i < IWL_POWER_AC; i++) {
2046 cmd = &pow_data->pwr_range_0[i].cmd;
2049 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
2051 cmd->flags |= IWL_POWER_PCI_PM_MSK;
2057 static int iwl3945_update_power_cmd(struct iwl3945_priv *priv,
2058 struct iwl3945_powertable_cmd *cmd, u32 mode)
2063 struct iwl3945_power_vec_entry *range;
2065 struct iwl3945_power_mgr *pow_data;
2067 if (mode > IWL_POWER_INDEX_5) {
2068 IWL_DEBUG_POWER("Error invalid power mode \n");
2071 pow_data = &(priv->power_data);
2073 if (pow_data->active_index == IWL_POWER_RANGE_0)
2074 range = &pow_data->pwr_range_0[0];
2076 range = &pow_data->pwr_range_1[1];
2078 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
2080 #ifdef IWL_MAC80211_DISABLE
2081 if (priv->assoc_network != NULL) {
2082 unsigned long flags;
2084 period = priv->assoc_network->tim.tim_period;
2086 #endif /*IWL_MAC80211_DISABLE */
2087 skip = range[mode].no_dtim;
2096 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
2098 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
2099 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
2100 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
2103 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
2104 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
2105 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
2108 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
2109 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
2110 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
2111 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
2112 le32_to_cpu(cmd->sleep_interval[0]),
2113 le32_to_cpu(cmd->sleep_interval[1]),
2114 le32_to_cpu(cmd->sleep_interval[2]),
2115 le32_to_cpu(cmd->sleep_interval[3]),
2116 le32_to_cpu(cmd->sleep_interval[4]));
2121 static int iwl3945_send_power_mode(struct iwl3945_priv *priv, u32 mode)
2123 u32 uninitialized_var(final_mode);
2125 struct iwl3945_powertable_cmd cmd;
2127 /* If on battery, set to 3,
2128 * if plugged into AC power, set to CAM ("continuously aware mode"),
2129 * else user level */
2131 case IWL_POWER_BATTERY:
2132 final_mode = IWL_POWER_INDEX_3;
2135 final_mode = IWL_POWER_MODE_CAM;
2142 iwl3945_update_power_cmd(priv, &cmd, final_mode);
2144 rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
2146 if (final_mode == IWL_POWER_MODE_CAM)
2147 clear_bit(STATUS_POWER_PMI, &priv->status);
2149 set_bit(STATUS_POWER_PMI, &priv->status);
2154 int iwl3945_is_network_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
2156 /* Filter incoming packets to determine if they are targeted toward
2157 * this network, discarding packets coming from ourselves */
2158 switch (priv->iw_mode) {
2159 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
2160 /* packets from our adapter are dropped (echo) */
2161 if (!compare_ether_addr(header->addr2, priv->mac_addr))
2163 /* {broad,multi}cast packets to our IBSS go through */
2164 if (is_multicast_ether_addr(header->addr1))
2165 return !compare_ether_addr(header->addr3, priv->bssid);
2166 /* packets to our adapter go through */
2167 return !compare_ether_addr(header->addr1, priv->mac_addr);
2168 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
2169 /* packets from our adapter are dropped (echo) */
2170 if (!compare_ether_addr(header->addr3, priv->mac_addr))
2172 /* {broad,multi}cast packets to our BSS go through */
2173 if (is_multicast_ether_addr(header->addr1))
2174 return !compare_ether_addr(header->addr2, priv->bssid);
2175 /* packets to our adapter go through */
2176 return !compare_ether_addr(header->addr1, priv->mac_addr);
2182 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2184 static const char *iwl3945_get_tx_fail_reason(u32 status)
2186 switch (status & TX_STATUS_MSK) {
2187 case TX_STATUS_SUCCESS:
2189 TX_STATUS_ENTRY(SHORT_LIMIT);
2190 TX_STATUS_ENTRY(LONG_LIMIT);
2191 TX_STATUS_ENTRY(FIFO_UNDERRUN);
2192 TX_STATUS_ENTRY(MGMNT_ABORT);
2193 TX_STATUS_ENTRY(NEXT_FRAG);
2194 TX_STATUS_ENTRY(LIFE_EXPIRE);
2195 TX_STATUS_ENTRY(DEST_PS);
2196 TX_STATUS_ENTRY(ABORTED);
2197 TX_STATUS_ENTRY(BT_RETRY);
2198 TX_STATUS_ENTRY(STA_INVALID);
2199 TX_STATUS_ENTRY(FRAG_DROPPED);
2200 TX_STATUS_ENTRY(TID_DISABLE);
2201 TX_STATUS_ENTRY(FRAME_FLUSHED);
2202 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
2203 TX_STATUS_ENTRY(TX_LOCKED);
2204 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
2211 * iwl3945_scan_cancel - Cancel any currently executing HW scan
2213 * NOTE: priv->mutex is not required before calling this function
2215 static int iwl3945_scan_cancel(struct iwl3945_priv *priv)
2217 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
2218 clear_bit(STATUS_SCANNING, &priv->status);
2222 if (test_bit(STATUS_SCANNING, &priv->status)) {
2223 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2224 IWL_DEBUG_SCAN("Queuing scan abort.\n");
2225 set_bit(STATUS_SCAN_ABORTING, &priv->status);
2226 queue_work(priv->workqueue, &priv->abort_scan);
2229 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2231 return test_bit(STATUS_SCANNING, &priv->status);
2238 * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan
2239 * @ms: amount of time to wait (in milliseconds) for scan to abort
2241 * NOTE: priv->mutex must be held before calling this function
2243 static int iwl3945_scan_cancel_timeout(struct iwl3945_priv *priv, unsigned long ms)
2245 unsigned long now = jiffies;
2248 ret = iwl3945_scan_cancel(priv);
2250 mutex_unlock(&priv->mutex);
2251 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
2252 test_bit(STATUS_SCANNING, &priv->status))
2254 mutex_lock(&priv->mutex);
2256 return test_bit(STATUS_SCANNING, &priv->status);
2262 static void iwl3945_sequence_reset(struct iwl3945_priv *priv)
2264 /* Reset ieee stats */
2266 /* We don't reset the net_device_stats (ieee->stats) on
2269 priv->last_seq_num = -1;
2270 priv->last_frag_num = -1;
2271 priv->last_packet_time = 0;
2273 iwl3945_scan_cancel(priv);
2276 #define MAX_UCODE_BEACON_INTERVAL 1024
2277 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2279 static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
2282 u16 beacon_factor = 0;
2285 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
2286 / MAX_UCODE_BEACON_INTERVAL;
2287 new_val = beacon_val / beacon_factor;
2289 return cpu_to_le16(new_val);
2292 static void iwl3945_setup_rxon_timing(struct iwl3945_priv *priv)
2294 u64 interval_tm_unit;
2296 unsigned long flags;
2297 struct ieee80211_conf *conf = NULL;
2300 conf = ieee80211_get_hw_conf(priv->hw);
2302 spin_lock_irqsave(&priv->lock, flags);
2303 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
2304 priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
2306 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
2308 tsf = priv->timestamp1;
2309 tsf = ((tsf << 32) | priv->timestamp0);
2311 beacon_int = priv->beacon_int;
2312 spin_unlock_irqrestore(&priv->lock, flags);
2314 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
2315 if (beacon_int == 0) {
2316 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
2317 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
2319 priv->rxon_timing.beacon_interval =
2320 cpu_to_le16(beacon_int);
2321 priv->rxon_timing.beacon_interval =
2322 iwl3945_adjust_beacon_interval(
2323 le16_to_cpu(priv->rxon_timing.beacon_interval));
2326 priv->rxon_timing.atim_window = 0;
2328 priv->rxon_timing.beacon_interval =
2329 iwl3945_adjust_beacon_interval(conf->beacon_int);
2330 /* TODO: we need to get atim_window from upper stack
2331 * for now we set to 0 */
2332 priv->rxon_timing.atim_window = 0;
2336 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
2337 result = do_div(tsf, interval_tm_unit);
2338 priv->rxon_timing.beacon_init_val =
2339 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
2342 ("beacon interval %d beacon timer %d beacon tim %d\n",
2343 le16_to_cpu(priv->rxon_timing.beacon_interval),
2344 le32_to_cpu(priv->rxon_timing.beacon_init_val),
2345 le16_to_cpu(priv->rxon_timing.atim_window));
2348 static int iwl3945_scan_initiate(struct iwl3945_priv *priv)
2350 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2351 IWL_ERROR("APs don't scan.\n");
2355 if (!iwl3945_is_ready_rf(priv)) {
2356 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2360 if (test_bit(STATUS_SCANNING, &priv->status)) {
2361 IWL_DEBUG_SCAN("Scan already in progress.\n");
2365 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2366 IWL_DEBUG_SCAN("Scan request while abort pending. "
2371 IWL_DEBUG_INFO("Starting scan...\n");
2372 priv->scan_bands = 2;
2373 set_bit(STATUS_SCANNING, &priv->status);
2374 priv->scan_start = jiffies;
2375 priv->scan_pass_start = priv->scan_start;
2377 queue_work(priv->workqueue, &priv->request_scan);
2382 static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv *priv, int hw_decrypt)
2384 struct iwl3945_rxon_cmd *rxon = &priv->staging_rxon;
2387 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
2389 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
2394 static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode)
2396 if (phymode == MODE_IEEE80211A) {
2397 priv->staging_rxon.flags &=
2398 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
2399 | RXON_FLG_CCK_MSK);
2400 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2402 /* Copied from iwl3945_bg_post_associate() */
2403 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2404 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2406 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2408 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2409 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2411 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
2412 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
2413 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
2418 * initialize rxon structure with default values from eeprom
2420 static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2422 const struct iwl3945_channel_info *ch_info;
2424 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2426 switch (priv->iw_mode) {
2427 case IEEE80211_IF_TYPE_AP:
2428 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2431 case IEEE80211_IF_TYPE_STA:
2432 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
2433 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
2436 case IEEE80211_IF_TYPE_IBSS:
2437 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
2438 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
2439 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
2440 RXON_FILTER_ACCEPT_GRP_MSK;
2443 case IEEE80211_IF_TYPE_MNTR:
2444 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
2445 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
2446 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
2451 /* TODO: Figure out when short_preamble would be set and cache from
2453 if (!hw_to_local(priv->hw)->short_preamble)
2454 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2456 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2459 ch_info = iwl3945_get_channel_info(priv, priv->phymode,
2460 le16_to_cpu(priv->staging_rxon.channel));
2463 ch_info = &priv->channel_info[0];
2466 * in some case A channels are all non IBSS
2467 * in this case force B/G channel
2469 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2470 !(is_channel_ibss(ch_info)))
2471 ch_info = &priv->channel_info[0];
2473 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
2474 if (is_channel_a_band(ch_info))
2475 priv->phymode = MODE_IEEE80211A;
2477 priv->phymode = MODE_IEEE80211G;
2479 iwl3945_set_flags_for_phymode(priv, priv->phymode);
2481 priv->staging_rxon.ofdm_basic_rates =
2482 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2483 priv->staging_rxon.cck_basic_rates =
2484 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2487 static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
2489 if (!iwl3945_is_ready_rf(priv))
2492 if (mode == IEEE80211_IF_TYPE_IBSS) {
2493 const struct iwl3945_channel_info *ch_info;
2495 ch_info = iwl3945_get_channel_info(priv,
2497 le16_to_cpu(priv->staging_rxon.channel));
2499 if (!ch_info || !is_channel_ibss(ch_info)) {
2500 IWL_ERROR("channel %d not IBSS channel\n",
2501 le16_to_cpu(priv->staging_rxon.channel));
2506 cancel_delayed_work(&priv->scan_check);
2507 if (iwl3945_scan_cancel_timeout(priv, 100)) {
2508 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2509 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2513 priv->iw_mode = mode;
2515 iwl3945_connection_init_rx_config(priv);
2516 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2518 iwl3945_clear_stations_table(priv);
2520 iwl3945_commit_rxon(priv);
2525 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2526 struct ieee80211_tx_control *ctl,
2527 struct iwl3945_cmd *cmd,
2528 struct sk_buff *skb_frag,
2531 struct iwl3945_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
2533 switch (keyinfo->alg) {
2535 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
2536 memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
2537 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2542 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
2545 memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
2548 memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
2553 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2554 (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2556 if (keyinfo->keylen == 13)
2557 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
2559 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2561 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2562 "with key %d\n", ctl->key_idx);
2566 printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
2572 * handle build REPLY_TX command notification.
2574 static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
2575 struct iwl3945_cmd *cmd,
2576 struct ieee80211_tx_control *ctrl,
2577 struct ieee80211_hdr *hdr,
2578 int is_unicast, u8 std_id)
2581 u16 fc = le16_to_cpu(hdr->frame_control);
2582 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2584 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2585 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
2586 tx_flags |= TX_CMD_FLG_ACK_MSK;
2587 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2588 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2589 if (ieee80211_is_probe_response(fc) &&
2590 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2591 tx_flags |= TX_CMD_FLG_TSF_MSK;
2593 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2594 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2597 cmd->cmd.tx.sta_id = std_id;
2598 if (ieee80211_get_morefrag(hdr))
2599 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2601 qc = ieee80211_get_qos_ctrl(hdr);
2603 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
2604 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2606 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2608 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
2609 tx_flags |= TX_CMD_FLG_RTS_MSK;
2610 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2611 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
2612 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2613 tx_flags |= TX_CMD_FLG_CTS_MSK;
2616 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2617 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2619 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2620 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2621 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
2622 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
2623 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
2625 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
2627 cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2629 cmd->cmd.tx.driver_txop = 0;
2630 cmd->cmd.tx.tx_flags = tx_flags;
2631 cmd->cmd.tx.next_frame_len = 0;
2634 static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *hdr)
2637 u16 fc = le16_to_cpu(hdr->frame_control);
2639 /* If this frame is broadcast or not data then use the broadcast
2641 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2642 is_multicast_ether_addr(hdr->addr1))
2643 return priv->hw_setting.bcast_sta_id;
2645 switch (priv->iw_mode) {
2647 /* If this frame is part of a BSS network (we're a station), then
2648 * we use the AP's station id */
2649 case IEEE80211_IF_TYPE_STA:
2652 /* If we are an AP, then find the station, or use BCAST */
2653 case IEEE80211_IF_TYPE_AP:
2654 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
2655 if (sta_id != IWL_INVALID_STATION)
2657 return priv->hw_setting.bcast_sta_id;
2659 /* If this frame is part of a IBSS network, then we use the
2660 * target specific station id */
2661 case IEEE80211_IF_TYPE_IBSS: {
2662 DECLARE_MAC_BUF(mac);
2664 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
2665 if (sta_id != IWL_INVALID_STATION)
2668 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
2670 if (sta_id != IWL_INVALID_STATION)
2673 IWL_DEBUG_DROP("Station %s not in station map. "
2674 "Defaulting to broadcast...\n",
2675 print_mac(mac, hdr->addr1));
2676 iwl3945_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
2677 return priv->hw_setting.bcast_sta_id;
2680 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
2681 return priv->hw_setting.bcast_sta_id;
2686 * start REPLY_TX command process
2688 static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2689 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2691 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2692 struct iwl3945_tfd_frame *tfd;
2694 int txq_id = ctl->queue;
2695 struct iwl3945_tx_queue *txq = NULL;
2696 struct iwl3945_queue *q = NULL;
2697 dma_addr_t phys_addr;
2698 dma_addr_t txcmd_phys;
2699 struct iwl3945_cmd *out_cmd = NULL;
2700 u16 len, idx, len_org;
2701 u8 id, hdr_len, unicast;
2706 u8 wait_write_ptr = 0;
2707 unsigned long flags;
2710 spin_lock_irqsave(&priv->lock, flags);
2711 if (iwl3945_is_rfkill(priv)) {
2712 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2716 if (!priv->interface_id) {
2717 IWL_DEBUG_DROP("Dropping - !priv->interface_id\n");
2721 if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) {
2722 IWL_ERROR("ERROR: No TX rate available.\n");
2726 unicast = !is_multicast_ether_addr(hdr->addr1);
2729 fc = le16_to_cpu(hdr->frame_control);
2731 #ifdef CONFIG_IWL3945_DEBUG
2732 if (ieee80211_is_auth(fc))
2733 IWL_DEBUG_TX("Sending AUTH frame\n");
2734 else if (ieee80211_is_assoc_request(fc))
2735 IWL_DEBUG_TX("Sending ASSOC frame\n");
2736 else if (ieee80211_is_reassoc_request(fc))
2737 IWL_DEBUG_TX("Sending REASSOC frame\n");
2740 if (!iwl3945_is_associated(priv) &&
2741 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
2742 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
2746 spin_unlock_irqrestore(&priv->lock, flags);
2748 hdr_len = ieee80211_get_hdrlen(fc);
2749 sta_id = iwl3945_get_sta_id(priv, hdr);
2750 if (sta_id == IWL_INVALID_STATION) {
2751 DECLARE_MAC_BUF(mac);
2753 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2754 print_mac(mac, hdr->addr1));
2758 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2760 qc = ieee80211_get_qos_ctrl(hdr);
2762 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2763 seq_number = priv->stations[sta_id].tid[tid].seq_number &
2765 hdr->seq_ctrl = cpu_to_le16(seq_number) |
2767 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
2770 txq = &priv->txq[txq_id];
2773 spin_lock_irqsave(&priv->lock, flags);
2775 tfd = &txq->bd[q->write_ptr];
2776 memset(tfd, 0, sizeof(*tfd));
2777 control_flags = (u32 *) tfd;
2778 idx = get_cmd_index(q, q->write_ptr, 0);
2780 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info));
2781 txq->txb[q->write_ptr].skb[0] = skb;
2782 memcpy(&(txq->txb[q->write_ptr].status.control),
2783 ctl, sizeof(struct ieee80211_tx_control));
2784 out_cmd = &txq->cmd[idx];
2785 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
2786 memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
2787 out_cmd->hdr.cmd = REPLY_TX;
2788 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
2789 INDEX_TO_SEQ(q->write_ptr)));
2790 /* copy frags header */
2791 memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
2793 /* hdr = (struct ieee80211_hdr *)out_cmd->cmd.tx.hdr; */
2794 len = priv->hw_setting.tx_cmd_len +
2795 sizeof(struct iwl3945_cmd_header) + hdr_len;
2798 len = (len + 3) & ~3;
2805 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl3945_cmd) * idx +
2806 offsetof(struct iwl3945_cmd, hdr);
2808 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
2810 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
2811 iwl3945_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
2813 /* 802.11 null functions have no payload... */
2814 len = skb->len - hdr_len;
2816 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
2817 len, PCI_DMA_TODEVICE);
2818 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
2821 /* If there is no payload, then only one TFD is used */
2823 *control_flags = TFD_CTL_COUNT_SET(1);
2825 *control_flags = TFD_CTL_COUNT_SET(2) |
2826 TFD_CTL_PAD_SET(U32_PAD(len));
2828 len = (u16)skb->len;
2829 out_cmd->cmd.tx.len = cpu_to_le16(len);
2831 /* TODO need this for burst mode later on */
2832 iwl3945_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
2834 /* set is_hcca to 0; it probably will never be implemented */
2835 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
2837 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
2838 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
2840 if (!ieee80211_get_morefrag(hdr)) {
2841 txq->need_update = 1;
2843 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2844 priv->stations[sta_id].tid[tid].seq_number = seq_number;
2848 txq->need_update = 0;
2851 iwl3945_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
2852 sizeof(out_cmd->cmd.tx));
2854 iwl3945_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
2855 ieee80211_get_hdrlen(fc));
2857 q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd);
2858 rc = iwl3945_tx_queue_update_write_ptr(priv, txq);
2859 spin_unlock_irqrestore(&priv->lock, flags);
2864 if ((iwl3945_queue_space(q) < q->high_mark)
2865 && priv->mac80211_registered) {
2866 if (wait_write_ptr) {
2867 spin_lock_irqsave(&priv->lock, flags);
2868 txq->need_update = 1;
2869 iwl3945_tx_queue_update_write_ptr(priv, txq);
2870 spin_unlock_irqrestore(&priv->lock, flags);
2873 ieee80211_stop_queue(priv->hw, ctl->queue);
2879 spin_unlock_irqrestore(&priv->lock, flags);
2884 static void iwl3945_set_rate(struct iwl3945_priv *priv)
2886 const struct ieee80211_hw_mode *hw = NULL;
2887 struct ieee80211_rate *rate;
2890 hw = iwl3945_get_hw_mode(priv, priv->phymode);
2892 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2896 priv->active_rate = 0;
2897 priv->active_rate_basic = 0;
2899 IWL_DEBUG_RATE("Setting rates for 802.11%c\n",
2900 hw->mode == MODE_IEEE80211A ?
2901 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g'));
2903 for (i = 0; i < hw->num_rates; i++) {
2904 rate = &(hw->rates[i]);
2905 if ((rate->val < IWL_RATE_COUNT) &&
2906 (rate->flags & IEEE80211_RATE_SUPPORTED)) {
2907 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
2908 rate->val, iwl3945_rates[rate->val].plcp,
2909 (rate->flags & IEEE80211_RATE_BASIC) ?
2911 priv->active_rate |= (1 << rate->val);
2912 if (rate->flags & IEEE80211_RATE_BASIC)
2913 priv->active_rate_basic |= (1 << rate->val);
2915 IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
2916 rate->val, iwl3945_rates[rate->val].plcp);
2919 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2920 priv->active_rate, priv->active_rate_basic);
2923 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2924 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2927 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
2928 priv->staging_rxon.cck_basic_rates =
2929 ((priv->active_rate_basic &
2930 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
2932 priv->staging_rxon.cck_basic_rates =
2933 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2935 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
2936 priv->staging_rxon.ofdm_basic_rates =
2937 ((priv->active_rate_basic &
2938 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
2939 IWL_FIRST_OFDM_RATE) & 0xFF;
2941 priv->staging_rxon.ofdm_basic_rates =
2942 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2945 static void iwl3945_radio_kill_sw(struct iwl3945_priv *priv, int disable_radio)
2947 unsigned long flags;
2949 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
2952 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2953 disable_radio ? "OFF" : "ON");
2955 if (disable_radio) {
2956 iwl3945_scan_cancel(priv);
2957 /* FIXME: This is a workaround for AP */
2958 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
2959 spin_lock_irqsave(&priv->lock, flags);
2960 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
2961 CSR_UCODE_SW_BIT_RFKILL);
2962 spin_unlock_irqrestore(&priv->lock, flags);
2963 iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
2964 set_bit(STATUS_RF_KILL_SW, &priv->status);
2969 spin_lock_irqsave(&priv->lock, flags);
2970 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2972 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2973 spin_unlock_irqrestore(&priv->lock, flags);
2978 spin_lock_irqsave(&priv->lock, flags);
2979 iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
2980 if (!iwl3945_grab_nic_access(priv))
2981 iwl3945_release_nic_access(priv);
2982 spin_unlock_irqrestore(&priv->lock, flags);
2984 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
2985 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2986 "disabled by HW switch\n");
2990 queue_work(priv->workqueue, &priv->restart);
2994 void iwl3945_set_decrypted_flag(struct iwl3945_priv *priv, struct sk_buff *skb,
2995 u32 decrypt_res, struct ieee80211_rx_status *stats)
2998 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
3000 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
3003 if (!(fc & IEEE80211_FCTL_PROTECTED))
3006 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
3007 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
3008 case RX_RES_STATUS_SEC_TYPE_TKIP:
3009 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3010 RX_RES_STATUS_BAD_ICV_MIC)
3011 stats->flag |= RX_FLAG_MMIC_ERROR;
3012 case RX_RES_STATUS_SEC_TYPE_WEP:
3013 case RX_RES_STATUS_SEC_TYPE_CCMP:
3014 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3015 RX_RES_STATUS_DECRYPT_OK) {
3016 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
3017 stats->flag |= RX_FLAG_DECRYPTED;
3026 void iwl3945_handle_data_packet_monitor(struct iwl3945_priv *priv,
3027 struct iwl3945_rx_mem_buffer *rxb,
3028 void *data, short len,
3029 struct ieee80211_rx_status *stats,
3032 struct iwl3945_rt_rx_hdr *iwl3945_rt;
3034 /* First cache any information we need before we overwrite
3035 * the information provided in the skb from the hardware */
3036 s8 signal = stats->ssi;
3038 int rate = stats->rate;
3039 u64 tsf = stats->mactime;
3040 __le16 phy_flags_hw = cpu_to_le16(phy_flags);
3042 /* We received data from the HW, so stop the watchdog */
3043 if (len > IWL_RX_BUF_SIZE - sizeof(*iwl3945_rt)) {
3044 IWL_DEBUG_DROP("Dropping too large packet in monitor\n");
3048 /* copy the frame data to write after where the radiotap header goes */
3049 iwl3945_rt = (void *)rxb->skb->data;
3050 memmove(iwl3945_rt->payload, data, len);
3052 iwl3945_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
3053 iwl3945_rt->rt_hdr.it_pad = 0; /* always good to zero */
3055 /* total header + data */
3056 iwl3945_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl3945_rt));
3058 /* Set the size of the skb to the size of the frame */
3059 skb_put(rxb->skb, sizeof(*iwl3945_rt) + len);
3061 /* Big bitfield of all the fields we provide in radiotap */
3062 iwl3945_rt->rt_hdr.it_present =
3063 cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
3064 (1 << IEEE80211_RADIOTAP_FLAGS) |
3065 (1 << IEEE80211_RADIOTAP_RATE) |
3066 (1 << IEEE80211_RADIOTAP_CHANNEL) |
3067 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
3068 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
3069 (1 << IEEE80211_RADIOTAP_ANTENNA));
3071 /* Zero the flags, we'll add to them as we go */
3072 iwl3945_rt->rt_flags = 0;
3074 iwl3945_rt->rt_tsf = cpu_to_le64(tsf);
3076 /* Convert to dBm */
3077 iwl3945_rt->rt_dbmsignal = signal;
3078 iwl3945_rt->rt_dbmnoise = noise;
3080 /* Convert the channel frequency and set the flags */
3081 iwl3945_rt->rt_channelMHz = cpu_to_le16(stats->freq);
3082 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
3083 iwl3945_rt->rt_chbitmask =
3084 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
3085 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
3086 iwl3945_rt->rt_chbitmask =
3087 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
3089 iwl3945_rt->rt_chbitmask =
3090 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ));
3092 rate = iwl3945_rate_index_from_plcp(rate);
3094 iwl3945_rt->rt_rate = 0;
3096 iwl3945_rt->rt_rate = iwl3945_rates[rate].ieee;
3098 /* antenna number */
3099 iwl3945_rt->rt_antenna =
3100 le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
3102 /* set the preamble flag if we have it */
3103 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
3104 iwl3945_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
3106 IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
3108 stats->flag |= RX_FLAG_RADIOTAP;
3109 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
3114 #define IWL_PACKET_RETRY_TIME HZ
3116 int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
3118 u16 sc = le16_to_cpu(header->seq_ctrl);
3119 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
3120 u16 frag = sc & IEEE80211_SCTL_FRAG;
3121 u16 *last_seq, *last_frag;
3122 unsigned long *last_time;
3124 switch (priv->iw_mode) {
3125 case IEEE80211_IF_TYPE_IBSS:{
3126 struct list_head *p;
3127 struct iwl3945_ibss_seq *entry = NULL;
3128 u8 *mac = header->addr2;
3129 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
3131 __list_for_each(p, &priv->ibss_mac_hash[index]) {
3132 entry = list_entry(p, struct iwl3945_ibss_seq, list);
3133 if (!compare_ether_addr(entry->mac, mac))
3136 if (p == &priv->ibss_mac_hash[index]) {
3137 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
3139 IWL_ERROR("Cannot malloc new mac entry\n");
3142 memcpy(entry->mac, mac, ETH_ALEN);
3143 entry->seq_num = seq;
3144 entry->frag_num = frag;
3145 entry->packet_time = jiffies;
3146 list_add(&entry->list, &priv->ibss_mac_hash[index]);
3149 last_seq = &entry->seq_num;
3150 last_frag = &entry->frag_num;
3151 last_time = &entry->packet_time;
3154 case IEEE80211_IF_TYPE_STA:
3155 last_seq = &priv->last_seq_num;
3156 last_frag = &priv->last_frag_num;
3157 last_time = &priv->last_packet_time;
3162 if ((*last_seq == seq) &&
3163 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
3164 if (*last_frag == frag)
3166 if (*last_frag + 1 != frag)
3167 /* out-of-order fragment */
3173 *last_time = jiffies;
3180 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
3182 #include "iwl-spectrum.h"
3184 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
3185 #define BEACON_TIME_MASK_HIGH 0xFF000000
3186 #define TIME_UNIT 1024
3189 * extended beacon time format
3190 * time in usec will be changed into a 32-bit value in 8:24 format
3191 * the high 1 byte is the beacon counts
3192 * the lower 3 bytes is the time in usec within one beacon interval
3195 static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
3199 u32 interval = beacon_interval * 1024;
3201 if (!interval || !usec)
3204 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
3205 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
3207 return (quot << 24) + rem;
3210 /* base is usually what we get from ucode with each received frame,
3211 * the same as HW timer counter counting down
3214 static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
3216 u32 base_low = base & BEACON_TIME_MASK_LOW;
3217 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
3218 u32 interval = beacon_interval * TIME_UNIT;
3219 u32 res = (base & BEACON_TIME_MASK_HIGH) +
3220 (addon & BEACON_TIME_MASK_HIGH);
3222 if (base_low > addon_low)
3223 res += base_low - addon_low;
3224 else if (base_low < addon_low) {
3225 res += interval + base_low - addon_low;
3230 return cpu_to_le32(res);
3233 static int iwl3945_get_measurement(struct iwl3945_priv *priv,
3234 struct ieee80211_measurement_params *params,
3237 struct iwl3945_spectrum_cmd spectrum;
3238 struct iwl3945_rx_packet *res;
3239 struct iwl3945_host_cmd cmd = {
3240 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
3241 .data = (void *)&spectrum,
3242 .meta.flags = CMD_WANT_SKB,
3244 u32 add_time = le64_to_cpu(params->start_time);
3246 int spectrum_resp_status;
3247 int duration = le16_to_cpu(params->duration);
3249 if (iwl3945_is_associated(priv))
3251 iwl3945_usecs_to_beacons(
3252 le64_to_cpu(params->start_time) - priv->last_tsf,
3253 le16_to_cpu(priv->rxon_timing.beacon_interval));
3255 memset(&spectrum, 0, sizeof(spectrum));
3257 spectrum.channel_count = cpu_to_le16(1);
3259 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
3260 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
3261 cmd.len = sizeof(spectrum);
3262 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
3264 if (iwl3945_is_associated(priv))
3265 spectrum.start_time =
3266 iwl3945_add_beacon_time(priv->last_beacon_time,
3268 le16_to_cpu(priv->rxon_timing.beacon_interval));
3270 spectrum.start_time = 0;
3272 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
3273 spectrum.channels[0].channel = params->channel;
3274 spectrum.channels[0].type = type;
3275 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
3276 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
3277 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
3279 rc = iwl3945_send_cmd_sync(priv, &cmd);
3283 res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
3284 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
3285 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
3289 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
3290 switch (spectrum_resp_status) {
3291 case 0: /* Command will be handled */
3292 if (res->u.spectrum.id != 0xff) {
3293 IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
3294 res->u.spectrum.id);
3295 priv->measurement_status &= ~MEASUREMENT_READY;
3297 priv->measurement_status |= MEASUREMENT_ACTIVE;
3301 case 1: /* Command will not be handled */
3306 dev_kfree_skb_any(cmd.meta.u.skb);
3312 static void iwl3945_txstatus_to_ieee(struct iwl3945_priv *priv,
3313 struct iwl3945_tx_info *tx_sta)
3316 tx_sta->status.ack_signal = 0;
3317 tx_sta->status.excessive_retries = 0;
3318 tx_sta->status.queue_length = 0;
3319 tx_sta->status.queue_number = 0;
3322 ieee80211_tx_status_irqsafe(priv->hw,
3323 tx_sta->skb[0], &(tx_sta->status));
3325 ieee80211_tx_status(priv->hw,
3326 tx_sta->skb[0], &(tx_sta->status));
3328 tx_sta->skb[0] = NULL;
3332 * iwl3945_tx_queue_reclaim - Reclaim Tx queue entries no more used by NIC.
3334 * When FW advances 'R' index, all entries between old and
3335 * new 'R' index need to be reclaimed. As result, some free space
3336 * forms. If there is enough free space (> low mark), wake Tx queue.
3338 static int iwl3945_tx_queue_reclaim(struct iwl3945_priv *priv, int txq_id, int index)
3340 struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
3341 struct iwl3945_queue *q = &txq->q;
3344 if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
3345 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3346 "is out of range [0-%d] %d %d.\n", txq_id,
3347 index, q->n_bd, q->write_ptr, q->read_ptr);
3351 for (index = iwl3945_queue_inc_wrap(index, q->n_bd);
3352 q->read_ptr != index;
3353 q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd)) {
3354 if (txq_id != IWL_CMD_QUEUE_NUM) {
3355 iwl3945_txstatus_to_ieee(priv,
3356 &(txq->txb[txq->q.read_ptr]));
3357 iwl3945_hw_txq_free_tfd(priv, txq);
3358 } else if (nfreed > 1) {
3359 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
3360 q->write_ptr, q->read_ptr);
3361 queue_work(priv->workqueue, &priv->restart);
3366 if (iwl3945_queue_space(q) > q->low_mark && (txq_id >= 0) &&
3367 (txq_id != IWL_CMD_QUEUE_NUM) &&
3368 priv->mac80211_registered)
3369 ieee80211_wake_queue(priv->hw, txq_id);
3375 static int iwl3945_is_tx_success(u32 status)
3377 return (status & 0xFF) == 0x1;
3380 /******************************************************************************
3382 * Generic RX handler implementations
3384 ******************************************************************************/
3385 static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
3386 struct iwl3945_rx_mem_buffer *rxb)
3388 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3389 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3390 int txq_id = SEQ_TO_QUEUE(sequence);
3391 int index = SEQ_TO_INDEX(sequence);
3392 struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
3393 struct ieee80211_tx_status *tx_status;
3394 struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3395 u32 status = le32_to_cpu(tx_resp->status);
3397 if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
3398 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3399 "is out of range [0-%d] %d %d\n", txq_id,
3400 index, txq->q.n_bd, txq->q.write_ptr,
3405 tx_status = &(txq->txb[txq->q.read_ptr].status);
3407 tx_status->retry_count = tx_resp->failure_frame;
3408 tx_status->queue_number = status;
3409 tx_status->queue_length = tx_resp->bt_kill_count;
3410 tx_status->queue_length |= tx_resp->failure_rts;
3413 iwl3945_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
3415 tx_status->control.tx_rate = iwl3945_rate_index_from_plcp(tx_resp->rate);
3417 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
3418 txq_id, iwl3945_get_tx_fail_reason(status), status,
3419 tx_resp->rate, tx_resp->failure_frame);
3421 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3423 iwl3945_tx_queue_reclaim(priv, txq_id, index);
3425 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3426 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3430 static void iwl3945_rx_reply_alive(struct iwl3945_priv *priv,
3431 struct iwl3945_rx_mem_buffer *rxb)
3433 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3434 struct iwl3945_alive_resp *palive;
3435 struct delayed_work *pwork;
3437 palive = &pkt->u.alive_frame;
3439 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3441 palive->is_valid, palive->ver_type,
3442 palive->ver_subtype);
3444 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
3445 IWL_DEBUG_INFO("Initialization Alive received.\n");
3446 memcpy(&priv->card_alive_init,
3447 &pkt->u.alive_frame,
3448 sizeof(struct iwl3945_init_alive_resp));
3449 pwork = &priv->init_alive_start;
3451 IWL_DEBUG_INFO("Runtime Alive received.\n");
3452 memcpy(&priv->card_alive, &pkt->u.alive_frame,
3453 sizeof(struct iwl3945_alive_resp));
3454 pwork = &priv->alive_start;
3455 iwl3945_disable_events(priv);
3458 /* We delay the ALIVE response by 5ms to
3459 * give the HW RF Kill time to activate... */
3460 if (palive->is_valid == UCODE_VALID_OK)
3461 queue_delayed_work(priv->workqueue, pwork,
3462 msecs_to_jiffies(5));
3464 IWL_WARNING("uCode did not respond OK.\n");
3467 static void iwl3945_rx_reply_add_sta(struct iwl3945_priv *priv,
3468 struct iwl3945_rx_mem_buffer *rxb)
3470 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3472 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
3476 static void iwl3945_rx_reply_error(struct iwl3945_priv *priv,
3477 struct iwl3945_rx_mem_buffer *rxb)
3479 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3481 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3482 "seq 0x%04X ser 0x%08X\n",
3483 le32_to_cpu(pkt->u.err_resp.error_type),
3484 get_cmd_string(pkt->u.err_resp.cmd_id),
3485 pkt->u.err_resp.cmd_id,
3486 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
3487 le32_to_cpu(pkt->u.err_resp.error_info));
3490 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3492 static void iwl3945_rx_csa(struct iwl3945_priv *priv, struct iwl3945_rx_mem_buffer *rxb)
3494 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3495 struct iwl3945_rxon_cmd *rxon = (void *)&priv->active_rxon;
3496 struct iwl3945_csa_notification *csa = &(pkt->u.csa_notif);
3497 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3498 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
3499 rxon->channel = csa->channel;
3500 priv->staging_rxon.channel = csa->channel;
3503 static void iwl3945_rx_spectrum_measure_notif(struct iwl3945_priv *priv,
3504 struct iwl3945_rx_mem_buffer *rxb)
3506 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
3507 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3508 struct iwl3945_spectrum_notification *report = &(pkt->u.spectrum_notif);
3510 if (!report->state) {
3511 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
3512 "Spectrum Measure Notification: Start\n");
3516 memcpy(&priv->measure_report, report, sizeof(*report));
3517 priv->measurement_status |= MEASUREMENT_READY;
3521 static void iwl3945_rx_pm_sleep_notif(struct iwl3945_priv *priv,
3522 struct iwl3945_rx_mem_buffer *rxb)
3524 #ifdef CONFIG_IWL3945_DEBUG
3525 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3526 struct iwl3945_sleep_notification *sleep = &(pkt->u.sleep_notif);
3527 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3528 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
3532 static void iwl3945_rx_pm_debug_statistics_notif(struct iwl3945_priv *priv,
3533 struct iwl3945_rx_mem_buffer *rxb)
3535 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3536 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3537 "notification for %s:\n",
3538 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
3539 iwl3945_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
3542 static void iwl3945_bg_beacon_update(struct work_struct *work)
3544 struct iwl3945_priv *priv =
3545 container_of(work, struct iwl3945_priv, beacon_update);
3546 struct sk_buff *beacon;
3548 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3549 beacon = ieee80211_beacon_get(priv->hw, priv->interface_id, NULL);
3552 IWL_ERROR("update beacon failed\n");
3556 mutex_lock(&priv->mutex);
3557 /* new beacon skb is allocated every time; dispose previous.*/
3558 if (priv->ibss_beacon)
3559 dev_kfree_skb(priv->ibss_beacon);
3561 priv->ibss_beacon = beacon;
3562 mutex_unlock(&priv->mutex);
3564 iwl3945_send_beacon_cmd(priv);
3567 static void iwl3945_rx_beacon_notif(struct iwl3945_priv *priv,
3568 struct iwl3945_rx_mem_buffer *rxb)
3570 #ifdef CONFIG_IWL3945_DEBUG
3571 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3572 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
3573 u8 rate = beacon->beacon_notify_hdr.rate;
3575 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3576 "tsf %d %d rate %d\n",
3577 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
3578 beacon->beacon_notify_hdr.failure_frame,
3579 le32_to_cpu(beacon->ibss_mgr_status),
3580 le32_to_cpu(beacon->high_tsf),
3581 le32_to_cpu(beacon->low_tsf), rate);
3584 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
3585 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
3586 queue_work(priv->workqueue, &priv->beacon_update);
3589 /* Service response to REPLY_SCAN_CMD (0x80) */
3590 static void iwl3945_rx_reply_scan(struct iwl3945_priv *priv,
3591 struct iwl3945_rx_mem_buffer *rxb)
3593 #ifdef CONFIG_IWL3945_DEBUG
3594 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3595 struct iwl3945_scanreq_notification *notif =
3596 (struct iwl3945_scanreq_notification *)pkt->u.raw;
3598 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
3602 /* Service SCAN_START_NOTIFICATION (0x82) */
3603 static void iwl3945_rx_scan_start_notif(struct iwl3945_priv *priv,
3604 struct iwl3945_rx_mem_buffer *rxb)
3606 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3607 struct iwl3945_scanstart_notification *notif =
3608 (struct iwl3945_scanstart_notification *)pkt->u.raw;
3609 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
3610 IWL_DEBUG_SCAN("Scan start: "
3612 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3614 notif->band ? "bg" : "a",
3616 notif->tsf_low, notif->status, notif->beacon_timer);
3619 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3620 static void iwl3945_rx_scan_results_notif(struct iwl3945_priv *priv,
3621 struct iwl3945_rx_mem_buffer *rxb)
3623 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3624 struct iwl3945_scanresults_notification *notif =
3625 (struct iwl3945_scanresults_notification *)pkt->u.raw;
3627 IWL_DEBUG_SCAN("Scan ch.res: "
3629 "(TSF: 0x%08X:%08X) - %d "
3630 "elapsed=%lu usec (%dms since last)\n",
3632 notif->band ? "bg" : "a",
3633 le32_to_cpu(notif->tsf_high),
3634 le32_to_cpu(notif->tsf_low),
3635 le32_to_cpu(notif->statistics[0]),
3636 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
3637 jiffies_to_msecs(elapsed_jiffies
3638 (priv->last_scan_jiffies, jiffies)));
3640 priv->last_scan_jiffies = jiffies;
3643 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3644 static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv *priv,
3645 struct iwl3945_rx_mem_buffer *rxb)
3647 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3648 struct iwl3945_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
3650 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3651 scan_notif->scanned_channels,
3652 scan_notif->tsf_low,
3653 scan_notif->tsf_high, scan_notif->status);
3655 /* The HW is no longer scanning */
3656 clear_bit(STATUS_SCAN_HW, &priv->status);
3658 /* The scan completion notification came in, so kill that timer... */
3659 cancel_delayed_work(&priv->scan_check);
3661 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3662 (priv->scan_bands == 2) ? "2.4" : "5.2",
3663 jiffies_to_msecs(elapsed_jiffies
3664 (priv->scan_pass_start, jiffies)));
3666 /* Remove this scanned band from the list
3667 * of pending bands to scan */
3670 /* If a request to abort was given, or the scan did not succeed
3671 * then we reset the scan state machine and terminate,
3672 * re-queuing another scan if one has been requested */
3673 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3674 IWL_DEBUG_INFO("Aborted scan completed.\n");
3675 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
3677 /* If there are more bands on this scan pass reschedule */
3678 if (priv->scan_bands > 0)
3682 priv->last_scan_jiffies = jiffies;
3683 IWL_DEBUG_INFO("Setting scan to off\n");
3685 clear_bit(STATUS_SCANNING, &priv->status);
3687 IWL_DEBUG_INFO("Scan took %dms\n",
3688 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
3690 queue_work(priv->workqueue, &priv->scan_completed);
3695 priv->scan_pass_start = jiffies;
3696 queue_work(priv->workqueue, &priv->request_scan);
3699 /* Handle notification from uCode that card's power state is changing
3700 * due to software, hardware, or critical temperature RFKILL */
3701 static void iwl3945_rx_card_state_notif(struct iwl3945_priv *priv,
3702 struct iwl3945_rx_mem_buffer *rxb)
3704 struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3705 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
3706 unsigned long status = priv->status;
3708 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3709 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
3710 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
3712 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
3713 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3715 if (flags & HW_CARD_DISABLED)
3716 set_bit(STATUS_RF_KILL_HW, &priv->status);
3718 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3721 if (flags & SW_CARD_DISABLED)
3722 set_bit(STATUS_RF_KILL_SW, &priv->status);
3724 clear_bit(STATUS_RF_KILL_SW, &priv->status);
3726 iwl3945_scan_cancel(priv);
3728 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
3729 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
3730 (test_bit(STATUS_RF_KILL_SW, &status) !=
3731 test_bit(STATUS_RF_KILL_SW, &priv->status)))
3732 queue_work(priv->workqueue, &priv->rf_kill);
3734 wake_up_interruptible(&priv->wait_command_queue);
3738 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
3740 * Setup the RX handlers for each of the reply types sent from the uCode
3743 * This function chains into the hardware specific files for them to setup
3744 * any hardware specific handlers as well.
3746 static void iwl3945_setup_rx_handlers(struct iwl3945_priv *priv)
3748 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
3749 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
3750 priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
3751 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
3752 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
3753 iwl3945_rx_spectrum_measure_notif;
3754 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
3755 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
3756 iwl3945_rx_pm_debug_statistics_notif;
3757 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
3760 * The same handler is used for both the REPLY to a discrete
3761 * statistics request from the host as well as for the periodic
3762 * statistics notifications (after received beacons) from the uCode.
3764 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
3765 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
3767 priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
3768 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
3769 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
3770 iwl3945_rx_scan_results_notif;
3771 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
3772 iwl3945_rx_scan_complete_notif;
3773 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
3774 priv->rx_handlers[REPLY_TX] = iwl3945_rx_reply_tx;
3776 /* Set up hardware specific Rx handlers */
3777 iwl3945_hw_rx_handler_setup(priv);
3781 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3782 * @rxb: Rx buffer to reclaim
3784 * If an Rx buffer has an async callback associated with it the callback
3785 * will be executed. The attached skb (if present) will only be freed
3786 * if the callback returns 1
3788 static void iwl3945_tx_cmd_complete(struct iwl3945_priv *priv,
3789 struct iwl3945_rx_mem_buffer *rxb)
3791 struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
3792 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3793 int txq_id = SEQ_TO_QUEUE(sequence);
3794 int index = SEQ_TO_INDEX(sequence);
3795 int huge = sequence & SEQ_HUGE_FRAME;
3797 struct iwl3945_cmd *cmd;
3799 /* If a Tx command is being handled and it isn't in the actual
3800 * command queue then there a command routing bug has been introduced
3801 * in the queue management code. */
3802 if (txq_id != IWL_CMD_QUEUE_NUM)
3803 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3804 txq_id, pkt->hdr.cmd);
3805 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
3807 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
3808 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
3810 /* Input error checking is done when commands are added to queue. */
3811 if (cmd->meta.flags & CMD_WANT_SKB) {
3812 cmd->meta.source->u.skb = rxb->skb;
3814 } else if (cmd->meta.u.callback &&
3815 !cmd->meta.u.callback(priv, cmd, rxb->skb))
3818 iwl3945_tx_queue_reclaim(priv, txq_id, index);
3820 if (!(cmd->meta.flags & CMD_ASYNC)) {
3821 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3822 wake_up_interruptible(&priv->wait_command_queue);
3826 /************************** RX-FUNCTIONS ****************************/
3828 * Rx theory of operation
3830 * The host allocates 32 DMA target addresses and passes the host address
3831 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
3835 * The host/firmware share two index registers for managing the Rx buffers.
3837 * The READ index maps to the first position that the firmware may be writing
3838 * to -- the driver can read up to (but not including) this position and get
3840 * The READ index is managed by the firmware once the card is enabled.
3842 * The WRITE index maps to the last position the driver has read from -- the
3843 * position preceding WRITE is the last slot the firmware can place a packet.
3845 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3848 * During initialization, the host sets up the READ queue position to the first
3849 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3851 * When the firmware places a packet in a buffer, it will advance the READ index
3852 * and fire the RX interrupt. The driver can then query the READ index and
3853 * process as many packets as possible, moving the WRITE index forward as it
3854 * resets the Rx queue buffers with new memory.
3856 * The management in the driver is as follows:
3857 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3858 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3859 * to replenish the iwl->rxq->rx_free.
3860 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
3861 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3862 * 'processed' and 'read' driver indexes as well)
3863 * + A received packet is processed and handed to the kernel network stack,
3864 * detached from the iwl->rxq. The driver 'processed' index is updated.
3865 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3866 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3867 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3868 * were enough free buffers and RX_STALLED is set it is cleared.
3873 * iwl3945_rx_queue_alloc() Allocates rx_free
3874 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
3875 * iwl3945_rx_queue_restock
3876 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
3877 * queue, updates firmware pointers, and updates
3878 * the WRITE index. If insufficient rx_free buffers
3879 * are available, schedules iwl3945_rx_replenish
3881 * -- enable interrupts --
3882 * ISR - iwl3945_rx() Detach iwl3945_rx_mem_buffers from pool up to the
3883 * READ INDEX, detaching the SKB from the pool.
3884 * Moves the packet buffer from queue to rx_used.
3885 * Calls iwl3945_rx_queue_restock to refill any empty
3892 * iwl3945_rx_queue_space - Return number of free slots available in queue.
3894 static int iwl3945_rx_queue_space(const struct iwl3945_rx_queue *q)
3896 int s = q->read - q->write;
3899 /* keep some buffer to not confuse full and empty queue */
3907 * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3909 int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv *priv, struct iwl3945_rx_queue *q)
3913 unsigned long flags;
3915 spin_lock_irqsave(&q->lock, flags);
3917 if (q->need_update == 0)
3920 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
3921 reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
3923 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
3924 iwl3945_set_bit(priv, CSR_GP_CNTRL,
3925 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
3929 rc = iwl3945_grab_nic_access(priv);
3933 iwl3945_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
3935 iwl3945_release_nic_access(priv);
3937 iwl3945_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
3943 spin_unlock_irqrestore(&q->lock, flags);
3948 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3950 static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl3945_priv *priv,
3951 dma_addr_t dma_addr)
3953 return cpu_to_le32((u32)dma_addr);
3957 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
3959 * If there are slots in the RX queue that need to be restocked,
3960 * and we have free pre-allocated buffers, fill the ranks as much
3961 * as we can, pulling from rx_free.
3963 * This moves the 'write' index forward to catch up with 'processed', and
3964 * also updates the memory address in the firmware to reference the new
3967 static int iwl3945_rx_queue_restock(struct iwl3945_priv *priv)
3969 struct iwl3945_rx_queue *rxq = &priv->rxq;
3970 struct list_head *element;
3971 struct iwl3945_rx_mem_buffer *rxb;
3972 unsigned long flags;
3975 spin_lock_irqsave(&rxq->lock, flags);
3976 write = rxq->write & ~0x7;
3977 while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
3978 element = rxq->rx_free.next;
3979 rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
3981 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->dma_addr);
3982 rxq->queue[rxq->write] = rxb;
3983 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
3986 spin_unlock_irqrestore(&rxq->lock, flags);
3987 /* If the pre-allocated buffer pool is dropping low, schedule to
3989 if (rxq->free_count <= RX_LOW_WATERMARK)
3990 queue_work(priv->workqueue, &priv->rx_replenish);
3993 /* If we've added more space for the firmware to place data, tell it */
3994 if ((write != (rxq->write & ~0x7))
3995 || (abs(rxq->write - rxq->read) > 7)) {
3996 spin_lock_irqsave(&rxq->lock, flags);
3997 rxq->need_update = 1;
3998 spin_unlock_irqrestore(&rxq->lock, flags);
3999 rc = iwl3945_rx_queue_update_write_ptr(priv, rxq);
4008 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
4010 * When moving to rx_free an SKB is allocated for the slot.
4012 * Also restock the Rx queue via iwl3945_rx_queue_restock.
4013 * This is called as a scheduled work item (except for during initialization)
4015 void iwl3945_rx_replenish(void *data)
4017 struct iwl3945_priv *priv = data;
4018 struct iwl3945_rx_queue *rxq = &priv->rxq;
4019 struct list_head *element;
4020 struct iwl3945_rx_mem_buffer *rxb;
4021 unsigned long flags;
4022 spin_lock_irqsave(&rxq->lock, flags);
4023 while (!list_empty(&rxq->rx_used)) {
4024 element = rxq->rx_used.next;
4025 rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
4027 alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC);
4029 if (net_ratelimit())
4030 printk(KERN_CRIT DRV_NAME
4031 ": Can not allocate SKB buffers\n");
4032 /* We don't reschedule replenish work here -- we will
4033 * call the restock method and if it still needs
4034 * more buffers it will schedule replenish */
4037 priv->alloc_rxb_skb++;
4040 pci_map_single(priv->pci_dev, rxb->skb->data,
4041 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4042 list_add_tail(&rxb->list, &rxq->rx_free);
4045 spin_unlock_irqrestore(&rxq->lock, flags);
4047 spin_lock_irqsave(&priv->lock, flags);
4048 iwl3945_rx_queue_restock(priv);
4049 spin_unlock_irqrestore(&priv->lock, flags);
4052 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4053 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
4054 * This free routine walks the list of POOL entries and if SKB is set to
4055 * non NULL it is unmapped and freed
4057 static void iwl3945_rx_queue_free(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
4060 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4061 if (rxq->pool[i].skb != NULL) {
4062 pci_unmap_single(priv->pci_dev,
4063 rxq->pool[i].dma_addr,
4064 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4065 dev_kfree_skb(rxq->pool[i].skb);
4069 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
4074 int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv)
4076 struct iwl3945_rx_queue *rxq = &priv->rxq;
4077 struct pci_dev *dev = priv->pci_dev;
4080 spin_lock_init(&rxq->lock);
4081 INIT_LIST_HEAD(&rxq->rx_free);
4082 INIT_LIST_HEAD(&rxq->rx_used);
4083 rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
4086 /* Fill the rx_used queue with _all_ of the Rx buffers */
4087 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4088 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4089 /* Set us so that we have processed and used all buffers, but have
4090 * not restocked the Rx queue with fresh buffers */
4091 rxq->read = rxq->write = 0;
4092 rxq->free_count = 0;
4093 rxq->need_update = 0;
4097 void iwl3945_rx_queue_reset(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
4099 unsigned long flags;
4101 spin_lock_irqsave(&rxq->lock, flags);
4102 INIT_LIST_HEAD(&rxq->rx_free);
4103 INIT_LIST_HEAD(&rxq->rx_used);
4104 /* Fill the rx_used queue with _all_ of the Rx buffers */
4105 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
4106 /* In the reset function, these buffers may have been allocated
4107 * to an SKB, so we need to unmap and free potential storage */
4108 if (rxq->pool[i].skb != NULL) {
4109 pci_unmap_single(priv->pci_dev,
4110 rxq->pool[i].dma_addr,
4111 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4112 priv->alloc_rxb_skb--;
4113 dev_kfree_skb(rxq->pool[i].skb);
4114 rxq->pool[i].skb = NULL;
4116 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4119 /* Set us so that we have processed and used all buffers, but have
4120 * not restocked the Rx queue with fresh buffers */
4121 rxq->read = rxq->write = 0;
4122 rxq->free_count = 0;
4123 spin_unlock_irqrestore(&rxq->lock, flags);
4126 /* Convert linear signal-to-noise ratio into dB */
4127 static u8 ratio2dB[100] = {
4128 /* 0 1 2 3 4 5 6 7 8 9 */
4129 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4130 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4131 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4132 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4133 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4134 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4135 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4136 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4137 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4138 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4141 /* Calculates a relative dB value from a ratio of linear
4142 * (i.e. not dB) signal levels.
4143 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4144 int iwl3945_calc_db_from_ratio(int sig_ratio)
4146 /* Anything above 1000:1 just report as 60 dB */
4147 if (sig_ratio > 1000)
4150 /* Above 100:1, divide by 10 and use table,
4151 * add 20 dB to make up for divide by 10 */
4152 if (sig_ratio > 100)
4153 return (20 + (int)ratio2dB[sig_ratio/10]);
4155 /* We shouldn't see this */
4159 /* Use table for ratios 1:1 - 99:1 */
4160 return (int)ratio2dB[sig_ratio];
4163 #define PERFECT_RSSI (-20) /* dBm */
4164 #define WORST_RSSI (-95) /* dBm */
4165 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4167 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
4168 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4169 * about formulas used below. */
4170 int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
4173 int degradation = PERFECT_RSSI - rssi_dbm;
4175 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4176 * as indicator; formula is (signal dbm - noise dbm).
4177 * SNR at or above 40 is a great signal (100%).
4178 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4179 * Weakest usable signal is usually 10 - 15 dB SNR. */
4181 if (rssi_dbm - noise_dbm >= 40)
4183 else if (rssi_dbm < noise_dbm)
4185 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
4187 /* Else use just the signal level.
4188 * This formula is a least squares fit of data points collected and
4189 * compared with a reference system that had a percentage (%) display
4190 * for signal quality. */
4192 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
4193 (15 * RSSI_RANGE + 62 * degradation)) /
4194 (RSSI_RANGE * RSSI_RANGE);
4198 else if (sig_qual < 1)
4205 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
4207 * Uses the priv->rx_handlers callback function array to invoke
4208 * the appropriate handlers, including command responses,
4209 * frame-received notifications, and other notifications.
4211 static void iwl3945_rx_handle(struct iwl3945_priv *priv)
4213 struct iwl3945_rx_mem_buffer *rxb;
4214 struct iwl3945_rx_packet *pkt;
4215 struct iwl3945_rx_queue *rxq = &priv->rxq;
4218 unsigned long flags;
4220 r = iwl3945_hw_get_rx_read(priv);
4223 /* Rx interrupt, but nothing sent from uCode */
4225 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
4228 rxb = rxq->queue[i];
4230 /* If an RXB doesn't have a Rx queue slot associated with it,
4231 * then a bug has been introduced in the queue refilling
4232 * routines -- catch it here */
4233 BUG_ON(rxb == NULL);
4235 rxq->queue[i] = NULL;
4237 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
4239 PCI_DMA_FROMDEVICE);
4240 pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
4242 /* Reclaim a command buffer only if this packet is a response
4243 * to a (driver-originated) command.
4244 * If the packet (e.g. Rx frame) originated from uCode,
4245 * there is no command buffer to reclaim.
4246 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4247 * but apparently a few don't get set; catch them here. */
4248 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
4249 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
4250 (pkt->hdr.cmd != REPLY_TX);
4252 /* Based on type of command response or notification,
4253 * handle those that need handling via function in
4254 * rx_handlers table. See iwl3945_setup_rx_handlers() */
4255 if (priv->rx_handlers[pkt->hdr.cmd]) {
4256 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4257 "r = %d, i = %d, %s, 0x%02x\n", r, i,
4258 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
4259 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
4261 /* No handling needed */
4262 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4263 "r %d i %d No handler needed for %s, 0x%02x\n",
4264 r, i, get_cmd_string(pkt->hdr.cmd),
4269 /* Invoke any callbacks, transfer the skb to caller, and
4270 * fire off the (possibly) blocking iwl3945_send_cmd()
4271 * as we reclaim the driver command queue */
4272 if (rxb && rxb->skb)
4273 iwl3945_tx_cmd_complete(priv, rxb);
4275 IWL_WARNING("Claim null rxb?\n");
4278 /* For now we just don't re-use anything. We can tweak this
4279 * later to try and re-use notification packets and SKBs that
4280 * fail to Rx correctly */
4281 if (rxb->skb != NULL) {
4282 priv->alloc_rxb_skb--;
4283 dev_kfree_skb_any(rxb->skb);
4287 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
4288 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4289 spin_lock_irqsave(&rxq->lock, flags);
4290 list_add_tail(&rxb->list, &priv->rxq.rx_used);
4291 spin_unlock_irqrestore(&rxq->lock, flags);
4292 i = (i + 1) & RX_QUEUE_MASK;
4295 /* Backtrack one entry */
4297 iwl3945_rx_queue_restock(priv);
4300 static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
4301 struct iwl3945_tx_queue *txq)
4305 int txq_id = txq->q.id;
4307 if (txq->need_update == 0)
4310 /* if we're trying to save power */
4311 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4312 /* wake up nic if it's powered down ...
4313 * uCode will wake up, and interrupt us again, so next
4314 * time we'll skip this part. */
4315 reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
4317 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4318 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
4319 iwl3945_set_bit(priv, CSR_GP_CNTRL,
4320 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4324 /* restore this queue's parameters in nic hardware. */
4325 rc = iwl3945_grab_nic_access(priv);
4328 iwl3945_write_direct32(priv, HBUS_TARG_WRPTR,
4329 txq->q.write_ptr | (txq_id << 8));
4330 iwl3945_release_nic_access(priv);
4332 /* else not in power-save mode, uCode will never sleep when we're
4333 * trying to tx (during RFKILL, we're not trying to tx). */
4335 iwl3945_write32(priv, HBUS_TARG_WRPTR,
4336 txq->q.write_ptr | (txq_id << 8));
4338 txq->need_update = 0;
4343 #ifdef CONFIG_IWL3945_DEBUG
4344 static void iwl3945_print_rx_config_cmd(struct iwl3945_rxon_cmd *rxon)
4346 DECLARE_MAC_BUF(mac);
4348 IWL_DEBUG_RADIO("RX CONFIG:\n");
4349 iwl3945_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
4350 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
4351 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
4352 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4353 le32_to_cpu(rxon->filter_flags));
4354 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
4355 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4356 rxon->ofdm_basic_rates);
4357 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
4358 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4359 print_mac(mac, rxon->node_addr));
4360 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4361 print_mac(mac, rxon->bssid_addr));
4362 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
4366 static void iwl3945_enable_interrupts(struct iwl3945_priv *priv)
4368 IWL_DEBUG_ISR("Enabling interrupts\n");
4369 set_bit(STATUS_INT_ENABLED, &priv->status);
4370 iwl3945_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
4373 static inline void iwl3945_disable_interrupts(struct iwl3945_priv *priv)
4375 clear_bit(STATUS_INT_ENABLED, &priv->status);
4377 /* disable interrupts from uCode/NIC to host */
4378 iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
4380 /* acknowledge/clear/reset any interrupts still pending
4381 * from uCode or flow handler (Rx/Tx DMA) */
4382 iwl3945_write32(priv, CSR_INT, 0xffffffff);
4383 iwl3945_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
4384 IWL_DEBUG_ISR("Disabled interrupts\n");
4387 static const char *desc_lookup(int i)
4395 return "BAD_CHECKSUM";
4397 return "NMI_INTERRUPT";
4401 return "FATAL_ERROR";
4407 #define ERROR_START_OFFSET (1 * sizeof(u32))
4408 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4410 static void iwl3945_dump_nic_error_log(struct iwl3945_priv *priv)
4413 u32 desc, time, count, base, data1;
4414 u32 blink1, blink2, ilink1, ilink2;
4417 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
4419 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
4420 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
4424 rc = iwl3945_grab_nic_access(priv);
4426 IWL_WARNING("Can not read from adapter at this time.\n");
4430 count = iwl3945_read_targ_mem(priv, base);
4432 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
4433 IWL_ERROR("Start IWL Error Log Dump:\n");
4434 IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
4435 priv->status, priv->config, count);
4438 IWL_ERROR("Desc Time asrtPC blink2 "
4439 "ilink1 nmiPC Line\n");
4440 for (i = ERROR_START_OFFSET;
4441 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
4442 i += ERROR_ELEM_SIZE) {
4443 desc = iwl3945_read_targ_mem(priv, base + i);
4445 iwl3945_read_targ_mem(priv, base + i + 1 * sizeof(u32));
4447 iwl3945_read_targ_mem(priv, base + i + 2 * sizeof(u32));
4449 iwl3945_read_targ_mem(priv, base + i + 3 * sizeof(u32));
4451 iwl3945_read_targ_mem(priv, base + i + 4 * sizeof(u32));
4453 iwl3945_read_targ_mem(priv, base + i + 5 * sizeof(u32));
4455 iwl3945_read_targ_mem(priv, base + i + 6 * sizeof(u32));
4458 ("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
4459 desc_lookup(desc), desc, time, blink1, blink2,
4460 ilink1, ilink2, data1);
4463 iwl3945_release_nic_access(priv);
4467 #define EVENT_START_OFFSET (6 * sizeof(u32))
4470 * iwl3945_print_event_log - Dump error event log to syslog
4472 * NOTE: Must be called with iwl3945_grab_nic_access() already obtained!
4474 static void iwl3945_print_event_log(struct iwl3945_priv *priv, u32 start_idx,
4475 u32 num_events, u32 mode)
4478 u32 base; /* SRAM byte address of event log header */
4479 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
4480 u32 ptr; /* SRAM byte address of log data */
4481 u32 ev, time, data; /* event log data */
4483 if (num_events == 0)
4486 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4489 event_size = 2 * sizeof(u32);
4491 event_size = 3 * sizeof(u32);
4493 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
4495 /* "time" is actually "data" for mode 0 (no timestamp).
4496 * place event id # at far right for easier visual parsing. */
4497 for (i = 0; i < num_events; i++) {
4498 ev = iwl3945_read_targ_mem(priv, ptr);
4500 time = iwl3945_read_targ_mem(priv, ptr);
4503 IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
4505 data = iwl3945_read_targ_mem(priv, ptr);
4507 IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
4512 static void iwl3945_dump_nic_event_log(struct iwl3945_priv *priv)
4515 u32 base; /* SRAM byte address of event log header */
4516 u32 capacity; /* event log capacity in # entries */
4517 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
4518 u32 num_wraps; /* # times uCode wrapped to top of log */
4519 u32 next_entry; /* index of next entry to be written by uCode */
4520 u32 size; /* # entries that we'll print */
4522 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4523 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
4524 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
4528 rc = iwl3945_grab_nic_access(priv);
4530 IWL_WARNING("Can not read from adapter at this time.\n");
4534 /* event log header */
4535 capacity = iwl3945_read_targ_mem(priv, base);
4536 mode = iwl3945_read_targ_mem(priv, base + (1 * sizeof(u32)));
4537 num_wraps = iwl3945_read_targ_mem(priv, base + (2 * sizeof(u32)));
4538 next_entry = iwl3945_read_targ_mem(priv, base + (3 * sizeof(u32)));
4540 size = num_wraps ? capacity : next_entry;
4542 /* bail out if nothing in log */
4544 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4545 iwl3945_release_nic_access(priv);
4549 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4552 /* if uCode has wrapped back to top of log, start at the oldest entry,
4553 * i.e the next one that uCode would fill. */
4555 iwl3945_print_event_log(priv, next_entry,
4556 capacity - next_entry, mode);
4558 /* (then/else) start at top of log */
4559 iwl3945_print_event_log(priv, 0, next_entry, mode);
4561 iwl3945_release_nic_access(priv);
4565 * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
4567 static void iwl3945_irq_handle_error(struct iwl3945_priv *priv)
4569 /* Set the FW error flag -- cleared on iwl3945_down */
4570 set_bit(STATUS_FW_ERROR, &priv->status);
4572 /* Cancel currently queued command. */
4573 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4575 #ifdef CONFIG_IWL3945_DEBUG
4576 if (iwl3945_debug_level & IWL_DL_FW_ERRORS) {
4577 iwl3945_dump_nic_error_log(priv);
4578 iwl3945_dump_nic_event_log(priv);
4579 iwl3945_print_rx_config_cmd(&priv->staging_rxon);
4583 wake_up_interruptible(&priv->wait_command_queue);
4585 /* Keep the restart process from trying to send host
4586 * commands by clearing the INIT status bit */
4587 clear_bit(STATUS_READY, &priv->status);
4589 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4590 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
4591 "Restarting adapter due to uCode error.\n");
4593 if (iwl3945_is_associated(priv)) {
4594 memcpy(&priv->recovery_rxon, &priv->active_rxon,
4595 sizeof(priv->recovery_rxon));
4596 priv->error_recovering = 1;
4598 queue_work(priv->workqueue, &priv->restart);
4602 static void iwl3945_error_recovery(struct iwl3945_priv *priv)
4604 unsigned long flags;
4606 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
4607 sizeof(priv->staging_rxon));
4608 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4609 iwl3945_commit_rxon(priv);
4611 iwl3945_add_station(priv, priv->bssid, 1, 0);
4613 spin_lock_irqsave(&priv->lock, flags);
4614 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
4615 priv->error_recovering = 0;
4616 spin_unlock_irqrestore(&priv->lock, flags);
4619 static void iwl3945_irq_tasklet(struct iwl3945_priv *priv)
4621 u32 inta, handled = 0;
4623 unsigned long flags;
4624 #ifdef CONFIG_IWL3945_DEBUG
4628 spin_lock_irqsave(&priv->lock, flags);
4630 /* Ack/clear/reset pending uCode interrupts.
4631 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4632 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4633 inta = iwl3945_read32(priv, CSR_INT);
4634 iwl3945_write32(priv, CSR_INT, inta);
4636 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4637 * Any new interrupts that happen after this, either while we're
4638 * in this tasklet, or later, will show up in next ISR/tasklet. */
4639 inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
4640 iwl3945_write32(priv, CSR_FH_INT_STATUS, inta_fh);
4642 #ifdef CONFIG_IWL3945_DEBUG
4643 if (iwl3945_debug_level & IWL_DL_ISR) {
4644 /* just for debug */
4645 inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
4646 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4647 inta, inta_mask, inta_fh);
4651 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4652 * atomic, make sure that inta covers all the interrupts that
4653 * we've discovered, even if FH interrupt came in just after
4654 * reading CSR_INT. */
4655 if (inta_fh & CSR_FH_INT_RX_MASK)
4656 inta |= CSR_INT_BIT_FH_RX;
4657 if (inta_fh & CSR_FH_INT_TX_MASK)
4658 inta |= CSR_INT_BIT_FH_TX;
4660 /* Now service all interrupt bits discovered above. */
4661 if (inta & CSR_INT_BIT_HW_ERR) {
4662 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4664 /* Tell the device to stop sending interrupts */
4665 iwl3945_disable_interrupts(priv);
4667 iwl3945_irq_handle_error(priv);
4669 handled |= CSR_INT_BIT_HW_ERR;
4671 spin_unlock_irqrestore(&priv->lock, flags);
4676 #ifdef CONFIG_IWL3945_DEBUG
4677 if (iwl3945_debug_level & (IWL_DL_ISR)) {
4678 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4679 if (inta & CSR_INT_BIT_MAC_CLK_ACTV)
4680 IWL_DEBUG_ISR("Microcode started or stopped.\n");
4682 /* Alive notification via Rx interrupt will do the real work */
4683 if (inta & CSR_INT_BIT_ALIVE)
4684 IWL_DEBUG_ISR("Alive interrupt\n");
4687 /* Safely ignore these bits for debug checks below */
4688 inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE);
4690 /* HW RF KILL switch toggled (4965 only) */
4691 if (inta & CSR_INT_BIT_RF_KILL) {
4693 if (!(iwl3945_read32(priv, CSR_GP_CNTRL) &
4694 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
4697 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
4698 "RF_KILL bit toggled to %s.\n",
4699 hw_rf_kill ? "disable radio":"enable radio");
4701 /* Queue restart only if RF_KILL switch was set to "kill"
4702 * when we loaded driver, and is now set to "enable".
4703 * After we're Alive, RF_KILL gets handled by
4704 * iwl_rx_card_state_notif() */
4705 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
4706 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4707 queue_work(priv->workqueue, &priv->restart);
4710 handled |= CSR_INT_BIT_RF_KILL;
4713 /* Chip got too hot and stopped itself (4965 only) */
4714 if (inta & CSR_INT_BIT_CT_KILL) {
4715 IWL_ERROR("Microcode CT kill error detected.\n");
4716 handled |= CSR_INT_BIT_CT_KILL;
4719 /* Error detected by uCode */
4720 if (inta & CSR_INT_BIT_SW_ERR) {
4721 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4723 iwl3945_irq_handle_error(priv);
4724 handled |= CSR_INT_BIT_SW_ERR;
4727 /* uCode wakes up after power-down sleep */
4728 if (inta & CSR_INT_BIT_WAKEUP) {
4729 IWL_DEBUG_ISR("Wakeup interrupt\n");
4730 iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq);
4731 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[0]);
4732 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[1]);
4733 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[2]);
4734 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[3]);
4735 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[4]);
4736 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[5]);
4738 handled |= CSR_INT_BIT_WAKEUP;
4741 /* All uCode command responses, including Tx command responses,
4742 * Rx "responses" (frame-received notification), and other
4743 * notifications from uCode come through here*/
4744 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
4745 iwl3945_rx_handle(priv);
4746 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
4749 if (inta & CSR_INT_BIT_FH_TX) {
4750 IWL_DEBUG_ISR("Tx interrupt\n");
4752 iwl3945_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
4753 if (!iwl3945_grab_nic_access(priv)) {
4754 iwl3945_write_direct32(priv,
4756 (ALM_FH_SRVC_CHNL), 0x0);
4757 iwl3945_release_nic_access(priv);
4759 handled |= CSR_INT_BIT_FH_TX;
4762 if (inta & ~handled)
4763 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
4765 if (inta & ~CSR_INI_SET_MASK) {
4766 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4767 inta & ~CSR_INI_SET_MASK);
4768 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
4771 /* Re-enable all interrupts */
4772 iwl3945_enable_interrupts(priv);
4774 #ifdef CONFIG_IWL3945_DEBUG
4775 if (iwl3945_debug_level & (IWL_DL_ISR)) {
4776 inta = iwl3945_read32(priv, CSR_INT);
4777 inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
4778 inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
4779 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4780 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
4783 spin_unlock_irqrestore(&priv->lock, flags);
4786 static irqreturn_t iwl3945_isr(int irq, void *data)
4788 struct iwl3945_priv *priv = data;
4789 u32 inta, inta_mask;
4794 spin_lock(&priv->lock);
4796 /* Disable (but don't clear!) interrupts here to avoid
4797 * back-to-back ISRs and sporadic interrupts from our NIC.
4798 * If we have something to service, the tasklet will re-enable ints.
4799 * If we *don't* have something, we'll re-enable before leaving here. */
4800 inta_mask = iwl3945_read32(priv, CSR_INT_MASK); /* just for debug */
4801 iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
4803 /* Discover which interrupts are active/pending */
4804 inta = iwl3945_read32(priv, CSR_INT);
4805 inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
4807 /* Ignore interrupt if there's nothing in NIC to service.
4808 * This may be due to IRQ shared with another device,
4809 * or due to sporadic interrupts thrown from our NIC. */
4810 if (!inta && !inta_fh) {
4811 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4815 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
4816 /* Hardware disappeared */
4817 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
4821 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4822 inta, inta_mask, inta_fh);
4824 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
4825 tasklet_schedule(&priv->irq_tasklet);
4827 spin_unlock(&priv->lock);
4832 /* re-enable interrupts here since we don't have anything to service. */
4833 iwl3945_enable_interrupts(priv);
4834 spin_unlock(&priv->lock);
4838 /************************** EEPROM BANDS ****************************
4840 * The iwl3945_eeprom_band definitions below provide the mapping from the
4841 * EEPROM contents to the specific channel number supported for each
4844 * For example, iwl3945_priv->eeprom.band_3_channels[4] from the band_3
4845 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
4846 * The specific geography and calibration information for that channel
4847 * is contained in the eeprom map itself.
4849 * During init, we copy the eeprom information and channel map
4850 * information into priv->channel_info_24/52 and priv->channel_map_24/52
4852 * channel_map_24/52 provides the index in the channel_info array for a
4853 * given channel. We have to have two separate maps as there is channel
4854 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
4857 * A value of 0xff stored in the channel_map indicates that the channel
4858 * is not supported by the hardware at all.
4860 * A value of 0xfe in the channel_map indicates that the channel is not
4861 * valid for Tx with the current hardware. This means that
4862 * while the system can tune and receive on a given channel, it may not
4863 * be able to associate or transmit any frames on that
4864 * channel. There is no corresponding channel information for that
4867 *********************************************************************/
4870 static const u8 iwl3945_eeprom_band_1[14] = {
4871 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
4875 static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */
4876 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
4879 static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */
4880 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
4883 static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */
4884 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
4887 static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */
4888 145, 149, 153, 157, 161, 165
4891 static void iwl3945_init_band_reference(const struct iwl3945_priv *priv, int band,
4892 int *eeprom_ch_count,
4893 const struct iwl3945_eeprom_channel
4895 const u8 **eeprom_ch_index)
4898 case 1: /* 2.4GHz band */
4899 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1);
4900 *eeprom_ch_info = priv->eeprom.band_1_channels;
4901 *eeprom_ch_index = iwl3945_eeprom_band_1;
4903 case 2: /* 4.9GHz band */
4904 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2);
4905 *eeprom_ch_info = priv->eeprom.band_2_channels;
4906 *eeprom_ch_index = iwl3945_eeprom_band_2;
4908 case 3: /* 5.2GHz band */
4909 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3);
4910 *eeprom_ch_info = priv->eeprom.band_3_channels;
4911 *eeprom_ch_index = iwl3945_eeprom_band_3;
4913 case 4: /* 5.5GHz band */
4914 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4);
4915 *eeprom_ch_info = priv->eeprom.band_4_channels;
4916 *eeprom_ch_index = iwl3945_eeprom_band_4;
4918 case 5: /* 5.7GHz band */
4919 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5);
4920 *eeprom_ch_info = priv->eeprom.band_5_channels;
4921 *eeprom_ch_index = iwl3945_eeprom_band_5;
4929 const struct iwl3945_channel_info *iwl3945_get_channel_info(const struct iwl3945_priv *priv,
4930 int phymode, u16 channel)
4935 case MODE_IEEE80211A:
4936 for (i = 14; i < priv->channel_count; i++) {
4937 if (priv->channel_info[i].channel == channel)
4938 return &priv->channel_info[i];
4942 case MODE_IEEE80211B:
4943 case MODE_IEEE80211G:
4944 if (channel >= 1 && channel <= 14)
4945 return &priv->channel_info[channel - 1];
4953 #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
4956 static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
4958 int eeprom_ch_count = 0;
4959 const u8 *eeprom_ch_index = NULL;
4960 const struct iwl3945_eeprom_channel *eeprom_ch_info = NULL;
4962 struct iwl3945_channel_info *ch_info;
4964 if (priv->channel_count) {
4965 IWL_DEBUG_INFO("Channel map already initialized.\n");
4969 if (priv->eeprom.version < 0x2f) {
4970 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
4971 priv->eeprom.version);
4975 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
4977 priv->channel_count =
4978 ARRAY_SIZE(iwl3945_eeprom_band_1) +
4979 ARRAY_SIZE(iwl3945_eeprom_band_2) +
4980 ARRAY_SIZE(iwl3945_eeprom_band_3) +
4981 ARRAY_SIZE(iwl3945_eeprom_band_4) +
4982 ARRAY_SIZE(iwl3945_eeprom_band_5);
4984 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
4986 priv->channel_info = kzalloc(sizeof(struct iwl3945_channel_info) *
4987 priv->channel_count, GFP_KERNEL);
4988 if (!priv->channel_info) {
4989 IWL_ERROR("Could not allocate channel_info\n");
4990 priv->channel_count = 0;
4994 ch_info = priv->channel_info;
4996 /* Loop through the 5 EEPROM bands adding them in order to the
4997 * channel map we maintain (that contains additional information than
4998 * what just in the EEPROM) */
4999 for (band = 1; band <= 5; band++) {
5001 iwl3945_init_band_reference(priv, band, &eeprom_ch_count,
5002 &eeprom_ch_info, &eeprom_ch_index);
5004 /* Loop through each band adding each of the channels */
5005 for (ch = 0; ch < eeprom_ch_count; ch++) {
5006 ch_info->channel = eeprom_ch_index[ch];
5007 ch_info->phymode = (band == 1) ? MODE_IEEE80211B :
5010 /* permanently store EEPROM's channel regulatory flags
5011 * and max power in channel info database. */
5012 ch_info->eeprom = eeprom_ch_info[ch];
5014 /* Copy the run-time flags so they are there even on
5015 * invalid channels */
5016 ch_info->flags = eeprom_ch_info[ch].flags;
5018 if (!(is_channel_valid(ch_info))) {
5019 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
5023 is_channel_a_band(ch_info) ?
5029 /* Initialize regulatory-based run-time data */
5030 ch_info->max_power_avg = ch_info->curr_txpow =
5031 eeprom_ch_info[ch].max_power_avg;
5032 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
5033 ch_info->min_power = 0;
5035 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
5036 " %ddBm): Ad-Hoc %ssupported\n",
5038 is_channel_a_band(ch_info) ?
5040 CHECK_AND_PRINT(IBSS),
5041 CHECK_AND_PRINT(ACTIVE),
5042 CHECK_AND_PRINT(RADAR),
5043 CHECK_AND_PRINT(WIDE),
5044 CHECK_AND_PRINT(NARROW),
5045 CHECK_AND_PRINT(DFS),
5046 eeprom_ch_info[ch].flags,
5047 eeprom_ch_info[ch].max_power_avg,
5048 ((eeprom_ch_info[ch].
5049 flags & EEPROM_CHANNEL_IBSS)
5050 && !(eeprom_ch_info[ch].
5051 flags & EEPROM_CHANNEL_RADAR))
5054 /* Set the user_txpower_limit to the highest power
5055 * supported by any channel */
5056 if (eeprom_ch_info[ch].max_power_avg >
5057 priv->user_txpower_limit)
5058 priv->user_txpower_limit =
5059 eeprom_ch_info[ch].max_power_avg;
5065 if (iwl3945_txpower_set_from_eeprom(priv))
5071 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
5072 * sending probe req. This should be set long enough to hear probe responses
5073 * from more than one AP. */
5074 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
5075 #define IWL_ACTIVE_DWELL_TIME_52 (10)
5077 /* For faster active scanning, scan will move to the next channel if fewer than
5078 * PLCP_QUIET_THRESH packets are heard on this channel within
5079 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
5080 * time if it's a quiet channel (nothing responded to our probe, and there's
5081 * no other traffic).
5082 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
5083 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
5084 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
5086 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
5087 * Must be set longer than active dwell time.
5088 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
5089 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
5090 #define IWL_PASSIVE_DWELL_TIME_52 (10)
5091 #define IWL_PASSIVE_DWELL_BASE (100)
5092 #define IWL_CHANNEL_TUNE_TIME 5
5094 static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv, int phymode)
5096 if (phymode == MODE_IEEE80211A)
5097 return IWL_ACTIVE_DWELL_TIME_52;
5099 return IWL_ACTIVE_DWELL_TIME_24;
5102 static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv, int phymode)
5104 u16 active = iwl3945_get_active_dwell_time(priv, phymode);
5105 u16 passive = (phymode != MODE_IEEE80211A) ?
5106 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
5107 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
5109 if (iwl3945_is_associated(priv)) {
5110 /* If we're associated, we clamp the maximum passive
5111 * dwell time to be 98% of the beacon interval (minus
5112 * 2 * channel tune time) */
5113 passive = priv->beacon_int;
5114 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
5115 passive = IWL_PASSIVE_DWELL_BASE;
5116 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
5119 if (passive <= active)
5120 passive = active + 1;
5125 static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, int phymode,
5126 u8 is_active, u8 direct_mask,
5127 struct iwl3945_scan_channel *scan_ch)
5129 const struct ieee80211_channel *channels = NULL;
5130 const struct ieee80211_hw_mode *hw_mode;
5131 const struct iwl3945_channel_info *ch_info;
5132 u16 passive_dwell = 0;
5133 u16 active_dwell = 0;
5136 hw_mode = iwl3945_get_hw_mode(priv, phymode);
5140 channels = hw_mode->channels;
5142 active_dwell = iwl3945_get_active_dwell_time(priv, phymode);
5143 passive_dwell = iwl3945_get_passive_dwell_time(priv, phymode);
5145 for (i = 0, added = 0; i < hw_mode->num_channels; i++) {
5146 if (channels[i].chan ==
5147 le16_to_cpu(priv->active_rxon.channel)) {
5148 if (iwl3945_is_associated(priv)) {
5150 ("Skipping current channel %d\n",
5151 le16_to_cpu(priv->active_rxon.channel));
5154 } else if (priv->only_active_channel)
5157 scan_ch->channel = channels[i].chan;
5159 ch_info = iwl3945_get_channel_info(priv, phymode, scan_ch->channel);
5160 if (!is_channel_valid(ch_info)) {
5161 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5166 if (!is_active || is_channel_passive(ch_info) ||
5167 !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN))
5168 scan_ch->type = 0; /* passive */
5170 scan_ch->type = 1; /* active */
5172 if (scan_ch->type & 1)
5173 scan_ch->type |= (direct_mask << 1);
5175 if (is_channel_narrow(ch_info))
5176 scan_ch->type |= (1 << 7);
5178 scan_ch->active_dwell = cpu_to_le16(active_dwell);
5179 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
5181 /* Set txpower levels to defaults */
5182 scan_ch->tpc.dsp_atten = 110;
5183 /* scan_pwr_info->tpc.dsp_atten; */
5185 /*scan_pwr_info->tpc.tx_gain; */
5186 if (phymode == MODE_IEEE80211A)
5187 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
5189 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
5190 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
5192 * scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3;
5196 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
5198 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
5199 (scan_ch->type & 1) ?
5200 active_dwell : passive_dwell);
5206 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
5210 static void iwl3945_reset_channel_flag(struct iwl3945_priv *priv)
5213 for (i = 0; i < 3; i++) {
5214 struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i];
5215 for (j = 0; j < hw_mode->num_channels; j++)
5216 hw_mode->channels[j].flag = hw_mode->channels[j].val;
5220 static void iwl3945_init_hw_rates(struct iwl3945_priv *priv,
5221 struct ieee80211_rate *rates)
5225 for (i = 0; i < IWL_RATE_COUNT; i++) {
5226 rates[i].rate = iwl3945_rates[i].ieee * 5;
5227 rates[i].val = i; /* Rate scaling will work on indexes */
5229 rates[i].flags = IEEE80211_RATE_SUPPORTED;
5230 /* Only OFDM have the bits-per-symbol set */
5231 if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE))
5232 rates[i].flags |= IEEE80211_RATE_OFDM;
5235 * If CCK 1M then set rate flag to CCK else CCK_2
5236 * which is CCK | PREAMBLE2
5238 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
5239 IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2;
5242 /* Set up which ones are basic rates... */
5243 if (IWL_BASIC_RATES_MASK & (1 << i))
5244 rates[i].flags |= IEEE80211_RATE_BASIC;
5249 * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
5251 static int iwl3945_init_geos(struct iwl3945_priv *priv)
5253 struct iwl3945_channel_info *ch;
5254 struct ieee80211_hw_mode *modes;
5255 struct ieee80211_channel *channels;
5256 struct ieee80211_channel *geo_ch;
5257 struct ieee80211_rate *rates;
5267 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5268 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5272 modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count,
5277 channels = kzalloc(sizeof(struct ieee80211_channel) *
5278 priv->channel_count, GFP_KERNEL);
5284 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
5297 /* 5.2GHz channels start after the 2.4GHz channels */
5298 modes[A].mode = MODE_IEEE80211A;
5299 modes[A].channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)];
5300 modes[A].rates = &rates[4];
5301 modes[A].num_rates = 8; /* just OFDM */
5302 modes[A].num_channels = 0;
5304 modes[B].mode = MODE_IEEE80211B;
5305 modes[B].channels = channels;
5306 modes[B].rates = rates;
5307 modes[B].num_rates = 4; /* just CCK */
5308 modes[B].num_channels = 0;
5310 modes[G].mode = MODE_IEEE80211G;
5311 modes[G].channels = channels;
5312 modes[G].rates = rates;
5313 modes[G].num_rates = 12; /* OFDM & CCK */
5314 modes[G].num_channels = 0;
5316 priv->ieee_channels = channels;
5317 priv->ieee_rates = rates;
5319 iwl3945_init_hw_rates(priv, rates);
5321 for (i = 0, geo_ch = channels; i < priv->channel_count; i++) {
5322 ch = &priv->channel_info[i];
5324 if (!is_channel_valid(ch)) {
5325 IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
5327 ch->channel, is_channel_a_band(ch) ?
5332 if (is_channel_a_band(ch))
5333 geo_ch = &modes[A].channels[modes[A].num_channels++];
5335 geo_ch = &modes[B].channels[modes[B].num_channels++];
5336 modes[G].num_channels++;
5339 geo_ch->freq = ieee80211chan2mhz(ch->channel);
5340 geo_ch->chan = ch->channel;
5341 geo_ch->power_level = ch->max_power_avg;
5342 geo_ch->antenna_max = 0xff;
5344 if (is_channel_valid(ch)) {
5345 geo_ch->flag = IEEE80211_CHAN_W_SCAN;
5346 if (ch->flags & EEPROM_CHANNEL_IBSS)
5347 geo_ch->flag |= IEEE80211_CHAN_W_IBSS;
5349 if (ch->flags & EEPROM_CHANNEL_ACTIVE)
5350 geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN;
5352 if (ch->flags & EEPROM_CHANNEL_RADAR)
5353 geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT;
5355 if (ch->max_power_avg > priv->max_channel_txpower_limit)
5356 priv->max_channel_txpower_limit =
5360 geo_ch->val = geo_ch->flag;
5363 if ((modes[A].num_channels == 0) && priv->is_abg) {
5364 printk(KERN_INFO DRV_NAME
5365 ": Incorrectly detected BG card as ABG. Please send "
5366 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5367 priv->pci_dev->device, priv->pci_dev->subsystem_device);
5371 printk(KERN_INFO DRV_NAME
5372 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5373 modes[G].num_channels, modes[A].num_channels);
5376 * NOTE: We register these in preference of order -- the
5377 * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
5378 * a phymode based on rates or AP capabilities but seems to
5379 * configure it purely on if the channel being configured
5380 * is supported by a mode -- and the first match is taken
5383 if (modes[G].num_channels)
5384 ieee80211_register_hwmode(priv->hw, &modes[G]);
5385 if (modes[B].num_channels)
5386 ieee80211_register_hwmode(priv->hw, &modes[B]);
5387 if (modes[A].num_channels)
5388 ieee80211_register_hwmode(priv->hw, &modes[A]);
5390 priv->modes = modes;
5391 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5396 /******************************************************************************
5398 * uCode download functions
5400 ******************************************************************************/
5402 static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv *priv)
5404 if (priv->ucode_code.v_addr != NULL) {
5405 pci_free_consistent(priv->pci_dev,
5406 priv->ucode_code.len,
5407 priv->ucode_code.v_addr,
5408 priv->ucode_code.p_addr);
5409 priv->ucode_code.v_addr = NULL;
5411 if (priv->ucode_data.v_addr != NULL) {
5412 pci_free_consistent(priv->pci_dev,
5413 priv->ucode_data.len,
5414 priv->ucode_data.v_addr,
5415 priv->ucode_data.p_addr);
5416 priv->ucode_data.v_addr = NULL;
5418 if (priv->ucode_data_backup.v_addr != NULL) {
5419 pci_free_consistent(priv->pci_dev,
5420 priv->ucode_data_backup.len,
5421 priv->ucode_data_backup.v_addr,
5422 priv->ucode_data_backup.p_addr);
5423 priv->ucode_data_backup.v_addr = NULL;
5425 if (priv->ucode_init.v_addr != NULL) {
5426 pci_free_consistent(priv->pci_dev,
5427 priv->ucode_init.len,
5428 priv->ucode_init.v_addr,
5429 priv->ucode_init.p_addr);
5430 priv->ucode_init.v_addr = NULL;
5432 if (priv->ucode_init_data.v_addr != NULL) {
5433 pci_free_consistent(priv->pci_dev,
5434 priv->ucode_init_data.len,
5435 priv->ucode_init_data.v_addr,
5436 priv->ucode_init_data.p_addr);
5437 priv->ucode_init_data.v_addr = NULL;
5439 if (priv->ucode_boot.v_addr != NULL) {
5440 pci_free_consistent(priv->pci_dev,
5441 priv->ucode_boot.len,
5442 priv->ucode_boot.v_addr,
5443 priv->ucode_boot.p_addr);
5444 priv->ucode_boot.v_addr = NULL;
5449 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
5450 * looking at all data.
5452 static int iwl3945_verify_inst_full(struct iwl3945_priv *priv, __le32 * image, u32 len)
5459 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5461 rc = iwl3945_grab_nic_access(priv);
5465 iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
5468 for (; len > 0; len -= sizeof(u32), image++) {
5469 /* read data comes through single port, auto-incr addr */
5470 /* NOTE: Use the debugless read so we don't flood kernel log
5471 * if IWL_DL_IO is set */
5472 val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
5473 if (val != le32_to_cpu(*image)) {
5474 IWL_ERROR("uCode INST section is invalid at "
5475 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5476 save_len - len, val, le32_to_cpu(*image));
5484 iwl3945_release_nic_access(priv);
5487 IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
5494 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
5495 * using sample data 100 bytes apart. If these sample points are good,
5496 * it's a pretty good bet that everything between them is good, too.
5498 static int iwl3945_verify_inst_sparse(struct iwl3945_priv *priv, __le32 *image, u32 len)
5505 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5507 rc = iwl3945_grab_nic_access(priv);
5511 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
5512 /* read data comes through single port, auto-incr addr */
5513 /* NOTE: Use the debugless read so we don't flood kernel log
5514 * if IWL_DL_IO is set */
5515 iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR,
5516 i + RTC_INST_LOWER_BOUND);
5517 val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
5518 if (val != le32_to_cpu(*image)) {
5519 #if 0 /* Enable this if you want to see details */
5520 IWL_ERROR("uCode INST section is invalid at "
5521 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5531 iwl3945_release_nic_access(priv);
5538 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
5539 * and verify its contents
5541 static int iwl3945_verify_ucode(struct iwl3945_priv *priv)
5548 image = (__le32 *)priv->ucode_boot.v_addr;
5549 len = priv->ucode_boot.len;
5550 rc = iwl3945_verify_inst_sparse(priv, image, len);
5552 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5556 /* Try initialize */
5557 image = (__le32 *)priv->ucode_init.v_addr;
5558 len = priv->ucode_init.len;
5559 rc = iwl3945_verify_inst_sparse(priv, image, len);
5561 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5565 /* Try runtime/protocol */
5566 image = (__le32 *)priv->ucode_code.v_addr;
5567 len = priv->ucode_code.len;
5568 rc = iwl3945_verify_inst_sparse(priv, image, len);
5570 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5574 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5576 /* Since nothing seems to match, show first several data entries in
5577 * instruction SRAM, so maybe visual inspection will give a clue.
5578 * Selection of bootstrap image (vs. other images) is arbitrary. */
5579 image = (__le32 *)priv->ucode_boot.v_addr;
5580 len = priv->ucode_boot.len;
5581 rc = iwl3945_verify_inst_full(priv, image, len);
5587 /* check contents of special bootstrap uCode SRAM */
5588 static int iwl3945_verify_bsm(struct iwl3945_priv *priv)
5590 __le32 *image = priv->ucode_boot.v_addr;
5591 u32 len = priv->ucode_boot.len;
5595 IWL_DEBUG_INFO("Begin verify bsm\n");
5597 /* verify BSM SRAM contents */
5598 val = iwl3945_read_prph(priv, BSM_WR_DWCOUNT_REG);
5599 for (reg = BSM_SRAM_LOWER_BOUND;
5600 reg < BSM_SRAM_LOWER_BOUND + len;
5601 reg += sizeof(u32), image ++) {
5602 val = iwl3945_read_prph(priv, reg);
5603 if (val != le32_to_cpu(*image)) {
5604 IWL_ERROR("BSM uCode verification failed at "
5605 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
5606 BSM_SRAM_LOWER_BOUND,
5607 reg - BSM_SRAM_LOWER_BOUND, len,
5608 val, le32_to_cpu(*image));
5613 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
5619 * iwl3945_load_bsm - Load bootstrap instructions
5623 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
5624 * in special SRAM that does not power down during RFKILL. When powering back
5625 * up after power-saving sleeps (or during initial uCode load), the BSM loads
5626 * the bootstrap program into the on-board processor, and starts it.
5628 * The bootstrap program loads (via DMA) instructions and data for a new
5629 * program from host DRAM locations indicated by the host driver in the
5630 * BSM_DRAM_* registers. Once the new program is loaded, it starts
5633 * When initializing the NIC, the host driver points the BSM to the
5634 * "initialize" uCode image. This uCode sets up some internal data, then
5635 * notifies host via "initialize alive" that it is complete.
5637 * The host then replaces the BSM_DRAM_* pointer values to point to the
5638 * normal runtime uCode instructions and a backup uCode data cache buffer
5639 * (filled initially with starting data values for the on-board processor),
5640 * then triggers the "initialize" uCode to load and launch the runtime uCode,
5641 * which begins normal operation.
5643 * When doing a power-save shutdown, runtime uCode saves data SRAM into
5644 * the backup data cache in DRAM before SRAM is powered down.
5646 * When powering back up, the BSM loads the bootstrap program. This reloads
5647 * the runtime uCode instructions and the backup data cache into SRAM,
5648 * and re-launches the runtime uCode from where it left off.
5650 static int iwl3945_load_bsm(struct iwl3945_priv *priv)
5652 __le32 *image = priv->ucode_boot.v_addr;
5653 u32 len = priv->ucode_boot.len;
5663 IWL_DEBUG_INFO("Begin load bsm\n");
5665 /* make sure bootstrap program is no larger than BSM's SRAM size */
5666 if (len > IWL_MAX_BSM_SIZE)
5669 /* Tell bootstrap uCode where to find the "Initialize" uCode
5670 * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
5671 * NOTE: iwl3945_initialize_alive_start() will replace these values,
5672 * after the "initialize" uCode has run, to point to
5673 * runtime/protocol instructions and backup data cache. */
5674 pinst = priv->ucode_init.p_addr;
5675 pdata = priv->ucode_init_data.p_addr;
5676 inst_len = priv->ucode_init.len;
5677 data_len = priv->ucode_init_data.len;
5679 rc = iwl3945_grab_nic_access(priv);
5683 iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
5684 iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
5685 iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
5686 iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
5688 /* Fill BSM memory with bootstrap instructions */
5689 for (reg_offset = BSM_SRAM_LOWER_BOUND;
5690 reg_offset < BSM_SRAM_LOWER_BOUND + len;
5691 reg_offset += sizeof(u32), image++)
5692 _iwl3945_write_prph(priv, reg_offset,
5693 le32_to_cpu(*image));
5695 rc = iwl3945_verify_bsm(priv);
5697 iwl3945_release_nic_access(priv);
5701 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
5702 iwl3945_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
5703 iwl3945_write_prph(priv, BSM_WR_MEM_DST_REG,
5704 RTC_INST_LOWER_BOUND);
5705 iwl3945_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
5707 /* Load bootstrap code into instruction SRAM now,
5708 * to prepare to load "initialize" uCode */
5709 iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
5710 BSM_WR_CTRL_REG_BIT_START);
5712 /* Wait for load of bootstrap uCode to finish */
5713 for (i = 0; i < 100; i++) {
5714 done = iwl3945_read_prph(priv, BSM_WR_CTRL_REG);
5715 if (!(done & BSM_WR_CTRL_REG_BIT_START))
5720 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
5722 IWL_ERROR("BSM write did not complete!\n");
5726 /* Enable future boot loads whenever power management unit triggers it
5727 * (e.g. when powering back up after power-save shutdown) */
5728 iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
5729 BSM_WR_CTRL_REG_BIT_START_EN);
5731 iwl3945_release_nic_access(priv);
5736 static void iwl3945_nic_start(struct iwl3945_priv *priv)
5738 /* Remove all resets to allow NIC to operate */
5739 iwl3945_write32(priv, CSR_RESET, 0);
5742 static int iwl3945_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc)
5744 desc->v_addr = pci_alloc_consistent(pci_dev, desc->len, &desc->p_addr);
5745 return (desc->v_addr != NULL) ? 0 : -ENOMEM;
5749 * iwl3945_read_ucode - Read uCode images from disk file.
5751 * Copy into buffers for card to fetch via bus-mastering
5753 static int iwl3945_read_ucode(struct iwl3945_priv *priv)
5755 struct iwl3945_ucode *ucode;
5757 const struct firmware *ucode_raw;
5758 /* firmware file name contains uCode/driver compatibility version */
5759 const char *name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode";
5762 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
5764 /* Ask kernel firmware_class module to get the boot firmware off disk.
5765 * request_firmware() is synchronous, file is in memory on return. */
5766 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
5768 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5773 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5774 name, ucode_raw->size);
5776 /* Make sure that we got at least our header! */
5777 if (ucode_raw->size < sizeof(*ucode)) {
5778 IWL_ERROR("File size way too small!\n");
5783 /* Data from ucode file: header followed by uCode images */
5784 ucode = (void *)ucode_raw->data;
5786 ver = le32_to_cpu(ucode->ver);
5787 inst_size = le32_to_cpu(ucode->inst_size);
5788 data_size = le32_to_cpu(ucode->data_size);
5789 init_size = le32_to_cpu(ucode->init_size);
5790 init_data_size = le32_to_cpu(ucode->init_data_size);
5791 boot_size = le32_to_cpu(ucode->boot_size);
5793 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
5794 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
5795 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
5796 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
5797 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
5798 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
5800 /* Verify size of file vs. image size info in file's header */
5801 if (ucode_raw->size < sizeof(*ucode) +
5802 inst_size + data_size + init_size +
5803 init_data_size + boot_size) {
5805 IWL_DEBUG_INFO("uCode file size %d too small\n",
5806 (int)ucode_raw->size);
5811 /* Verify that uCode images will fit in card's SRAM */
5812 if (inst_size > IWL_MAX_INST_SIZE) {
5813 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5819 if (data_size > IWL_MAX_DATA_SIZE) {
5820 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5825 if (init_size > IWL_MAX_INST_SIZE) {
5826 IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
5831 if (init_data_size > IWL_MAX_DATA_SIZE) {
5832 IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
5837 if (boot_size > IWL_MAX_BSM_SIZE) {
5838 IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
5844 /* Allocate ucode buffers for card's bus-master loading ... */
5846 /* Runtime instructions and 2 copies of data:
5847 * 1) unmodified from disk
5848 * 2) backup cache for save/restore during power-downs */
5849 priv->ucode_code.len = inst_size;
5850 iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
5852 priv->ucode_data.len = data_size;
5853 iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
5855 priv->ucode_data_backup.len = data_size;
5856 iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
5858 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
5859 !priv->ucode_data_backup.v_addr)
5862 /* Initialization instructions and data */
5863 if (init_size && init_data_size) {
5864 priv->ucode_init.len = init_size;
5865 iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
5867 priv->ucode_init_data.len = init_data_size;
5868 iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
5870 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
5874 /* Bootstrap (instructions only, no data) */
5876 priv->ucode_boot.len = boot_size;
5877 iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
5879 if (!priv->ucode_boot.v_addr)
5883 /* Copy images into buffers for card's bus-master reads ... */
5885 /* Runtime instructions (first block of data in file) */
5886 src = &ucode->data[0];
5887 len = priv->ucode_code.len;
5888 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
5889 memcpy(priv->ucode_code.v_addr, src, len);
5890 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5891 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
5893 /* Runtime data (2nd block)
5894 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
5895 src = &ucode->data[inst_size];
5896 len = priv->ucode_data.len;
5897 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
5898 memcpy(priv->ucode_data.v_addr, src, len);
5899 memcpy(priv->ucode_data_backup.v_addr, src, len);
5901 /* Initialization instructions (3rd block) */
5903 src = &ucode->data[inst_size + data_size];
5904 len = priv->ucode_init.len;
5905 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5907 memcpy(priv->ucode_init.v_addr, src, len);
5910 /* Initialization data (4th block) */
5911 if (init_data_size) {
5912 src = &ucode->data[inst_size + data_size + init_size];
5913 len = priv->ucode_init_data.len;
5914 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
5916 memcpy(priv->ucode_init_data.v_addr, src, len);
5919 /* Bootstrap instructions (5th block) */
5920 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
5921 len = priv->ucode_boot.len;
5922 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
5924 memcpy(priv->ucode_boot.v_addr, src, len);
5926 /* We have our copies now, allow OS release its copies */
5927 release_firmware(ucode_raw);
5931 IWL_ERROR("failed to allocate pci memory\n");
5933 iwl3945_dealloc_ucode_pci(priv);
5936 release_firmware(ucode_raw);
5944 * iwl3945_set_ucode_ptrs - Set uCode address location
5946 * Tell initialization uCode where to find runtime uCode.
5948 * BSM registers initially contain pointers to initialization uCode.
5949 * We need to replace them to load runtime uCode inst and data,
5950 * and to save runtime data when powering down.
5952 static int iwl3945_set_ucode_ptrs(struct iwl3945_priv *priv)
5957 unsigned long flags;
5959 /* bits 31:0 for 3945 */
5960 pinst = priv->ucode_code.p_addr;
5961 pdata = priv->ucode_data_backup.p_addr;
5963 spin_lock_irqsave(&priv->lock, flags);
5964 rc = iwl3945_grab_nic_access(priv);
5966 spin_unlock_irqrestore(&priv->lock, flags);
5970 /* Tell bootstrap uCode where to find image to load */
5971 iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
5972 iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
5973 iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
5974 priv->ucode_data.len);
5976 /* Inst bytecount must be last to set up, bit 31 signals uCode
5977 * that all new ptr/size info is in place */
5978 iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
5979 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
5981 iwl3945_release_nic_access(priv);
5983 spin_unlock_irqrestore(&priv->lock, flags);
5985 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5991 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
5993 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5995 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5997 static void iwl3945_init_alive_start(struct iwl3945_priv *priv)
5999 /* Check alive response for "valid" sign from uCode */
6000 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
6001 /* We had an error bringing up the hardware, so take it
6002 * all the way back down so we can try again */
6003 IWL_DEBUG_INFO("Initialize Alive failed.\n");
6007 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
6008 * This is a paranoid check, because we would not have gotten the
6009 * "initialize" alive if code weren't properly loaded. */
6010 if (iwl3945_verify_ucode(priv)) {
6011 /* Runtime instruction load was bad;
6012 * take it all the way back down so we can try again */
6013 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
6017 /* Send pointers to protocol/runtime uCode image ... init code will
6018 * load and launch runtime uCode, which will send us another "Alive"
6020 IWL_DEBUG_INFO("Initialization Alive received.\n");
6021 if (iwl3945_set_ucode_ptrs(priv)) {
6022 /* Runtime instruction load won't happen;
6023 * take it all the way back down so we can try again */
6024 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
6030 queue_work(priv->workqueue, &priv->restart);
6035 * iwl3945_alive_start - called after REPLY_ALIVE notification received
6036 * from protocol/runtime uCode (initialization uCode's
6037 * Alive gets handled by iwl3945_init_alive_start()).
6039 static void iwl3945_alive_start(struct iwl3945_priv *priv)
6042 int thermal_spin = 0;
6045 IWL_DEBUG_INFO("Runtime Alive received.\n");
6047 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
6048 /* We had an error bringing up the hardware, so take it
6049 * all the way back down so we can try again */
6050 IWL_DEBUG_INFO("Alive failed.\n");
6054 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
6055 * This is a paranoid check, because we would not have gotten the
6056 * "runtime" alive if code weren't properly loaded. */
6057 if (iwl3945_verify_ucode(priv)) {
6058 /* Runtime instruction load was bad;
6059 * take it all the way back down so we can try again */
6060 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
6064 iwl3945_clear_stations_table(priv);
6066 rc = iwl3945_grab_nic_access(priv);
6068 IWL_WARNING("Can not read rfkill status from adapter\n");
6072 rfkill = iwl3945_read_prph(priv, APMG_RFKILL_REG);
6073 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
6074 iwl3945_release_nic_access(priv);
6077 clear_bit(STATUS_RF_KILL_HW, &priv->status);
6078 /* if rfkill is not on, then wait for thermal
6079 * sensor in adapter to kick in */
6080 while (iwl3945_hw_get_temperature(priv) == 0) {
6086 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
6089 set_bit(STATUS_RF_KILL_HW, &priv->status);
6091 /* After the ALIVE response, we can send commands to 3945 uCode */
6092 set_bit(STATUS_ALIVE, &priv->status);
6094 /* Clear out the uCode error bit if it is set */
6095 clear_bit(STATUS_FW_ERROR, &priv->status);
6097 rc = iwl3945_init_channel_map(priv);
6099 IWL_ERROR("initializing regulatory failed: %d\n", rc);
6103 iwl3945_init_geos(priv);
6105 if (iwl3945_is_rfkill(priv))
6108 if (!priv->mac80211_registered) {
6109 /* Unlock so any user space entry points can call back into
6110 * the driver without a deadlock... */
6111 mutex_unlock(&priv->mutex);
6112 iwl3945_rate_control_register(priv->hw);
6113 rc = ieee80211_register_hw(priv->hw);
6114 priv->hw->conf.beacon_int = 100;
6115 mutex_lock(&priv->mutex);
6118 iwl3945_rate_control_unregister(priv->hw);
6119 IWL_ERROR("Failed to register network "
6120 "device (error %d)\n", rc);
6124 priv->mac80211_registered = 1;
6126 iwl3945_reset_channel_flag(priv);
6128 ieee80211_start_queues(priv->hw);
6130 priv->active_rate = priv->rates_mask;
6131 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
6133 iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
6135 if (iwl3945_is_associated(priv)) {
6136 struct iwl3945_rxon_cmd *active_rxon =
6137 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
6139 memcpy(&priv->staging_rxon, &priv->active_rxon,
6140 sizeof(priv->staging_rxon));
6141 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6143 /* Initialize our rx_config data */
6144 iwl3945_connection_init_rx_config(priv);
6145 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
6148 /* Configure Bluetooth device coexistence support */
6149 iwl3945_send_bt_config(priv);
6151 /* Configure the adapter for unassociated operation */
6152 iwl3945_commit_rxon(priv);
6154 /* At this point, the NIC is initialized and operational */
6155 priv->notif_missed_beacons = 0;
6156 set_bit(STATUS_READY, &priv->status);
6158 iwl3945_reg_txpower_periodic(priv);
6160 IWL_DEBUG_INFO("ALIVE processing complete.\n");
6162 if (priv->error_recovering)
6163 iwl3945_error_recovery(priv);
6168 queue_work(priv->workqueue, &priv->restart);
6171 static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv);
6173 static void __iwl3945_down(struct iwl3945_priv *priv)
6175 unsigned long flags;
6176 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
6177 struct ieee80211_conf *conf = NULL;
6179 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
6181 conf = ieee80211_get_hw_conf(priv->hw);
6184 set_bit(STATUS_EXIT_PENDING, &priv->status);
6186 iwl3945_clear_stations_table(priv);
6188 /* Unblock any waiting calls */
6189 wake_up_interruptible_all(&priv->wait_command_queue);
6191 /* Wipe out the EXIT_PENDING status bit if we are not actually
6192 * exiting the module */
6194 clear_bit(STATUS_EXIT_PENDING, &priv->status);
6196 /* stop and reset the on-board processor */
6197 iwl3945_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
6199 /* tell the device to stop sending interrupts */
6200 iwl3945_disable_interrupts(priv);
6202 if (priv->mac80211_registered)
6203 ieee80211_stop_queues(priv->hw);
6205 /* If we have not previously called iwl3945_init() then
6206 * clear all bits but the RF Kill and SUSPEND bits and return */
6207 if (!iwl3945_is_init(priv)) {
6208 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6210 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6212 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6217 /* ...otherwise clear out all the status bits but the RF Kill and
6218 * SUSPEND bits and continue taking the NIC down. */
6219 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6221 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6223 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6225 test_bit(STATUS_FW_ERROR, &priv->status) <<
6228 spin_lock_irqsave(&priv->lock, flags);
6229 iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
6230 spin_unlock_irqrestore(&priv->lock, flags);
6232 iwl3945_hw_txq_ctx_stop(priv);
6233 iwl3945_hw_rxq_stop(priv);
6235 spin_lock_irqsave(&priv->lock, flags);
6236 if (!iwl3945_grab_nic_access(priv)) {
6237 iwl3945_write_prph(priv, APMG_CLK_DIS_REG,
6238 APMG_CLK_VAL_DMA_CLK_RQT);
6239 iwl3945_release_nic_access(priv);
6241 spin_unlock_irqrestore(&priv->lock, flags);
6245 iwl3945_hw_nic_stop_master(priv);
6246 iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
6247 iwl3945_hw_nic_reset(priv);
6250 memset(&priv->card_alive, 0, sizeof(struct iwl3945_alive_resp));
6252 if (priv->ibss_beacon)
6253 dev_kfree_skb(priv->ibss_beacon);
6254 priv->ibss_beacon = NULL;
6256 /* clear out any free frames */
6257 iwl3945_clear_free_frames(priv);
6260 static void iwl3945_down(struct iwl3945_priv *priv)
6262 mutex_lock(&priv->mutex);
6263 __iwl3945_down(priv);
6264 mutex_unlock(&priv->mutex);
6266 iwl3945_cancel_deferred_work(priv);
6269 #define MAX_HW_RESTARTS 5
6271 static int __iwl3945_up(struct iwl3945_priv *priv)
6273 DECLARE_MAC_BUF(mac);
6276 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6277 IWL_WARNING("Exit pending; will not bring the NIC up\n");
6281 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
6282 IWL_WARNING("Radio disabled by SW RF kill (module "
6287 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
6288 IWL_ERROR("ucode not available for device bringup\n");
6292 iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
6294 rc = iwl3945_hw_nic_init(priv);
6296 IWL_ERROR("Unable to int nic\n");
6300 /* make sure rfkill handshake bits are cleared */
6301 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6302 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR,
6303 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
6305 /* clear (again), then enable host interrupts */
6306 iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
6307 iwl3945_enable_interrupts(priv);
6309 /* really make sure rfkill handshake bits are cleared */
6310 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6311 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6313 /* Copy original ucode data image from disk into backup cache.
6314 * This will be used to initialize the on-board processor's
6315 * data SRAM for a clean start when the runtime program first loads. */
6316 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
6317 priv->ucode_data.len);
6319 for (i = 0; i < MAX_HW_RESTARTS; i++) {
6321 iwl3945_clear_stations_table(priv);
6323 /* load bootstrap state machine,
6324 * load bootstrap program into processor's memory,
6325 * prepare to load the "initialize" uCode */
6326 rc = iwl3945_load_bsm(priv);
6329 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
6333 /* start card; "initialize" will load runtime ucode */
6334 iwl3945_nic_start(priv);
6336 /* MAC Address location in EEPROM is same for 3945/4965 */
6337 get_eeprom_mac(priv, priv->mac_addr);
6338 IWL_DEBUG_INFO("MAC address: %s\n",
6339 print_mac(mac, priv->mac_addr));
6341 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
6343 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
6348 set_bit(STATUS_EXIT_PENDING, &priv->status);
6349 __iwl3945_down(priv);
6351 /* tried to restart and config the device for as long as our
6352 * patience could withstand */
6353 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
6358 /*****************************************************************************
6360 * Workqueue callbacks
6362 *****************************************************************************/
6364 static void iwl3945_bg_init_alive_start(struct work_struct *data)
6366 struct iwl3945_priv *priv =
6367 container_of(data, struct iwl3945_priv, init_alive_start.work);
6369 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6372 mutex_lock(&priv->mutex);
6373 iwl3945_init_alive_start(priv);
6374 mutex_unlock(&priv->mutex);
6377 static void iwl3945_bg_alive_start(struct work_struct *data)
6379 struct iwl3945_priv *priv =
6380 container_of(data, struct iwl3945_priv, alive_start.work);
6382 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6385 mutex_lock(&priv->mutex);
6386 iwl3945_alive_start(priv);
6387 mutex_unlock(&priv->mutex);
6390 static void iwl3945_bg_rf_kill(struct work_struct *work)
6392 struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, rf_kill);
6394 wake_up_interruptible(&priv->wait_command_queue);
6396 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6399 mutex_lock(&priv->mutex);
6401 if (!iwl3945_is_rfkill(priv)) {
6402 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
6403 "HW and/or SW RF Kill no longer active, restarting "
6405 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
6406 queue_work(priv->workqueue, &priv->restart);
6409 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
6410 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6411 "disabled by SW switch\n");
6413 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6414 "Kill switch must be turned off for "
6415 "wireless networking to work.\n");
6417 mutex_unlock(&priv->mutex);
6420 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6422 static void iwl3945_bg_scan_check(struct work_struct *data)
6424 struct iwl3945_priv *priv =
6425 container_of(data, struct iwl3945_priv, scan_check.work);
6427 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6430 mutex_lock(&priv->mutex);
6431 if (test_bit(STATUS_SCANNING, &priv->status) ||
6432 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6433 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
6434 "Scan completion watchdog resetting adapter (%dms)\n",
6435 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
6437 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
6438 iwl3945_send_scan_abort(priv);
6440 mutex_unlock(&priv->mutex);
6443 static void iwl3945_bg_request_scan(struct work_struct *data)
6445 struct iwl3945_priv *priv =
6446 container_of(data, struct iwl3945_priv, request_scan);
6447 struct iwl3945_host_cmd cmd = {
6448 .id = REPLY_SCAN_CMD,
6449 .len = sizeof(struct iwl3945_scan_cmd),
6450 .meta.flags = CMD_SIZE_HUGE,
6453 struct iwl3945_scan_cmd *scan;
6454 struct ieee80211_conf *conf = NULL;
6458 conf = ieee80211_get_hw_conf(priv->hw);
6460 mutex_lock(&priv->mutex);
6462 if (!iwl3945_is_ready(priv)) {
6463 IWL_WARNING("request scan called when driver not ready.\n");
6467 /* Make sure the scan wasn't cancelled before this queued work
6468 * was given the chance to run... */
6469 if (!test_bit(STATUS_SCANNING, &priv->status))
6472 /* This should never be called or scheduled if there is currently
6473 * a scan active in the hardware. */
6474 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
6475 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6476 "Ignoring second request.\n");
6481 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6482 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6486 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6487 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6491 if (iwl3945_is_rfkill(priv)) {
6492 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6496 if (!test_bit(STATUS_READY, &priv->status)) {
6497 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6501 if (!priv->scan_bands) {
6502 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6507 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
6508 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
6515 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
6517 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
6518 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
6520 if (iwl3945_is_associated(priv)) {
6523 u32 suspend_time = 100;
6524 u32 scan_suspend_time = 100;
6525 unsigned long flags;
6527 IWL_DEBUG_INFO("Scanning while associated...\n");
6529 spin_lock_irqsave(&priv->lock, flags);
6530 interval = priv->beacon_int;
6531 spin_unlock_irqrestore(&priv->lock, flags);
6533 scan->suspend_time = 0;
6534 scan->max_out_time = cpu_to_le32(200 * 1024);
6536 interval = suspend_time;
6538 * suspend time format:
6539 * 0-19: beacon interval in usec (time before exec.)
6541 * 24-31: number of beacons (suspend between channels)
6544 extra = (suspend_time / interval) << 24;
6545 scan_suspend_time = 0xFF0FFFFF &
6546 (extra | ((suspend_time % interval) * 1024));
6548 scan->suspend_time = cpu_to_le32(scan_suspend_time);
6549 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6550 scan_suspend_time, interval);
6553 /* We should add the ability for user to lock to PASSIVE ONLY */
6554 if (priv->one_direct_scan) {
6556 ("Kicking off one direct scan for '%s'\n",
6557 iwl3945_escape_essid(priv->direct_ssid,
6558 priv->direct_ssid_len));
6559 scan->direct_scan[0].id = WLAN_EID_SSID;
6560 scan->direct_scan[0].len = priv->direct_ssid_len;
6561 memcpy(scan->direct_scan[0].ssid,
6562 priv->direct_ssid, priv->direct_ssid_len);
6564 } else if (!iwl3945_is_associated(priv) && priv->essid_len) {
6565 scan->direct_scan[0].id = WLAN_EID_SSID;
6566 scan->direct_scan[0].len = priv->essid_len;
6567 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
6572 /* We don't build a direct scan probe request; the uCode will do
6573 * that based on the direct_mask added to each channel entry */
6574 scan->tx_cmd.len = cpu_to_le16(
6575 iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
6576 IWL_MAX_SCAN_SIZE - sizeof(scan), 0));
6577 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
6578 scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
6579 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
6581 /* flags + rate selection */
6583 switch (priv->scan_bands) {
6585 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
6586 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
6587 scan->good_CRC_th = 0;
6588 phymode = MODE_IEEE80211G;
6592 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
6593 scan->good_CRC_th = IWL_GOOD_CRC_TH;
6594 phymode = MODE_IEEE80211A;
6598 IWL_WARNING("Invalid scan band count\n");
6602 /* select Rx antennas */
6603 scan->flags |= iwl3945_get_antenna_flags(priv);
6605 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
6606 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
6610 ("Initiating direct scan for %s.\n",
6611 iwl3945_escape_essid(priv->essid, priv->essid_len));
6613 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
6615 scan->channel_count =
6616 iwl3945_get_channels_for_scan(
6617 priv, phymode, 1, /* active */
6619 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6621 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
6622 scan->channel_count * sizeof(struct iwl3945_scan_channel);
6624 scan->len = cpu_to_le16(cmd.len);
6626 set_bit(STATUS_SCAN_HW, &priv->status);
6627 rc = iwl3945_send_cmd_sync(priv, &cmd);
6631 queue_delayed_work(priv->workqueue, &priv->scan_check,
6632 IWL_SCAN_CHECK_WATCHDOG);
6634 mutex_unlock(&priv->mutex);
6638 /* inform mac80211 scan aborted */
6639 queue_work(priv->workqueue, &priv->scan_completed);
6640 mutex_unlock(&priv->mutex);
6643 static void iwl3945_bg_up(struct work_struct *data)
6645 struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, up);
6647 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6650 mutex_lock(&priv->mutex);
6652 mutex_unlock(&priv->mutex);
6655 static void iwl3945_bg_restart(struct work_struct *data)
6657 struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, restart);
6659 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6663 queue_work(priv->workqueue, &priv->up);
6666 static void iwl3945_bg_rx_replenish(struct work_struct *data)
6668 struct iwl3945_priv *priv =
6669 container_of(data, struct iwl3945_priv, rx_replenish);
6671 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6674 mutex_lock(&priv->mutex);
6675 iwl3945_rx_replenish(priv);
6676 mutex_unlock(&priv->mutex);
6679 static void iwl3945_bg_post_associate(struct work_struct *data)
6681 struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv,
6682 post_associate.work);
6685 struct ieee80211_conf *conf = NULL;
6686 DECLARE_MAC_BUF(mac);
6688 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
6689 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
6694 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
6696 print_mac(mac, priv->active_rxon.bssid_addr));
6698 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6701 mutex_lock(&priv->mutex);
6703 if (!priv->interface_id || !priv->is_open) {
6704 mutex_unlock(&priv->mutex);
6707 iwl3945_scan_cancel_timeout(priv, 200);
6709 conf = ieee80211_get_hw_conf(priv->hw);
6711 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6712 iwl3945_commit_rxon(priv);
6714 memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
6715 iwl3945_setup_rxon_timing(priv);
6716 rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
6717 sizeof(priv->rxon_timing), &priv->rxon_timing);
6719 IWL_WARNING("REPLY_RXON_TIMING failed - "
6720 "Attempting to continue.\n");
6722 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
6724 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
6726 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6727 priv->assoc_id, priv->beacon_int);
6729 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6730 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
6732 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
6734 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
6735 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
6736 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
6738 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6740 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6741 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6745 iwl3945_commit_rxon(priv);
6747 switch (priv->iw_mode) {
6748 case IEEE80211_IF_TYPE_STA:
6749 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
6752 case IEEE80211_IF_TYPE_IBSS:
6754 /* clear out the station table */
6755 iwl3945_clear_stations_table(priv);
6757 iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
6758 iwl3945_add_station(priv, priv->bssid, 0, 0);
6759 iwl3945_sync_sta(priv, IWL_STA_ID,
6760 (priv->phymode == MODE_IEEE80211A)?
6761 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
6763 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
6764 iwl3945_send_beacon_cmd(priv);
6769 IWL_ERROR("%s Should not be called in %d mode\n",
6770 __FUNCTION__, priv->iw_mode);
6774 iwl3945_sequence_reset(priv);
6776 #ifdef CONFIG_IWL3945_QOS
6777 iwl3945_activate_qos(priv, 0);
6778 #endif /* CONFIG_IWL3945_QOS */
6779 mutex_unlock(&priv->mutex);
6782 static void iwl3945_bg_abort_scan(struct work_struct *work)
6784 struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, abort_scan);
6786 if (!iwl3945_is_ready(priv))
6789 mutex_lock(&priv->mutex);
6791 set_bit(STATUS_SCAN_ABORTING, &priv->status);
6792 iwl3945_send_scan_abort(priv);
6794 mutex_unlock(&priv->mutex);
6797 static void iwl3945_bg_scan_completed(struct work_struct *work)
6799 struct iwl3945_priv *priv =
6800 container_of(work, struct iwl3945_priv, scan_completed);
6802 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
6804 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6807 ieee80211_scan_completed(priv->hw);
6809 /* Since setting the TXPOWER may have been deferred while
6810 * performing the scan, fire one off */
6811 mutex_lock(&priv->mutex);
6812 iwl3945_hw_reg_send_txpower(priv);
6813 mutex_unlock(&priv->mutex);
6816 /*****************************************************************************
6818 * mac80211 entry point functions
6820 *****************************************************************************/
6822 static int iwl3945_mac_start(struct ieee80211_hw *hw)
6824 struct iwl3945_priv *priv = hw->priv;
6826 IWL_DEBUG_MAC80211("enter\n");
6828 /* we should be verifying the device is ready to be opened */
6829 mutex_lock(&priv->mutex);
6833 if (!iwl3945_is_rfkill(priv))
6834 ieee80211_start_queues(priv->hw);
6836 mutex_unlock(&priv->mutex);
6837 IWL_DEBUG_MAC80211("leave\n");
6841 static void iwl3945_mac_stop(struct ieee80211_hw *hw)
6843 struct iwl3945_priv *priv = hw->priv;
6845 IWL_DEBUG_MAC80211("enter\n");
6848 mutex_lock(&priv->mutex);
6849 /* stop mac, cancel any scan request and clear
6850 * RXON_FILTER_ASSOC_MSK BIT
6853 iwl3945_scan_cancel_timeout(priv, 100);
6854 cancel_delayed_work(&priv->post_associate);
6855 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6856 iwl3945_commit_rxon(priv);
6857 mutex_unlock(&priv->mutex);
6859 IWL_DEBUG_MAC80211("leave\n");
6862 static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
6863 struct ieee80211_tx_control *ctl)
6865 struct iwl3945_priv *priv = hw->priv;
6867 IWL_DEBUG_MAC80211("enter\n");
6869 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
6870 IWL_DEBUG_MAC80211("leave - monitor\n");
6874 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
6877 if (iwl3945_tx_skb(priv, skb, ctl))
6878 dev_kfree_skb_any(skb);
6880 IWL_DEBUG_MAC80211("leave\n");
6884 static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
6885 struct ieee80211_if_init_conf *conf)
6887 struct iwl3945_priv *priv = hw->priv;
6888 unsigned long flags;
6889 DECLARE_MAC_BUF(mac);
6891 IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type);
6893 if (priv->interface_id) {
6894 IWL_DEBUG_MAC80211("leave - interface_id != 0\n");
6898 spin_lock_irqsave(&priv->lock, flags);
6899 priv->interface_id = conf->if_id;
6901 spin_unlock_irqrestore(&priv->lock, flags);
6903 mutex_lock(&priv->mutex);
6905 if (conf->mac_addr) {
6906 IWL_DEBUG_MAC80211("Set: %s\n", print_mac(mac, conf->mac_addr));
6907 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
6910 iwl3945_set_mode(priv, conf->type);
6912 IWL_DEBUG_MAC80211("leave\n");
6913 mutex_unlock(&priv->mutex);
6919 * iwl3945_mac_config - mac80211 config callback
6921 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6922 * be set inappropriately and the driver currently sets the hardware up to
6923 * use it whenever needed.
6925 static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
6927 struct iwl3945_priv *priv = hw->priv;
6928 const struct iwl3945_channel_info *ch_info;
6929 unsigned long flags;
6931 mutex_lock(&priv->mutex);
6932 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel);
6934 if (!iwl3945_is_ready(priv)) {
6935 IWL_DEBUG_MAC80211("leave - not ready\n");
6936 mutex_unlock(&priv->mutex);
6940 /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only
6941 * what is exposed through include/ declarations */
6942 if (unlikely(!iwl3945_param_disable_hw_scan &&
6943 test_bit(STATUS_SCANNING, &priv->status))) {
6944 IWL_DEBUG_MAC80211("leave - scanning\n");
6945 mutex_unlock(&priv->mutex);
6949 spin_lock_irqsave(&priv->lock, flags);
6951 ch_info = iwl3945_get_channel_info(priv, conf->phymode, conf->channel);
6952 if (!is_channel_valid(ch_info)) {
6953 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
6954 conf->channel, conf->phymode);
6955 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6956 spin_unlock_irqrestore(&priv->lock, flags);
6957 mutex_unlock(&priv->mutex);
6961 iwl3945_set_rxon_channel(priv, conf->phymode, conf->channel);
6963 iwl3945_set_flags_for_phymode(priv, conf->phymode);
6965 /* The list of supported rates and rate mask can be different
6966 * for each phymode; since the phymode may have changed, reset
6967 * the rate mask to what mac80211 lists */
6968 iwl3945_set_rate(priv);
6970 spin_unlock_irqrestore(&priv->lock, flags);
6972 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6973 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
6974 iwl3945_hw_channel_switch(priv, conf->channel);
6975 mutex_unlock(&priv->mutex);
6980 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
6982 if (!conf->radio_enabled) {
6983 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6984 mutex_unlock(&priv->mutex);
6988 if (iwl3945_is_rfkill(priv)) {
6989 IWL_DEBUG_MAC80211("leave - RF kill\n");
6990 mutex_unlock(&priv->mutex);
6994 iwl3945_set_rate(priv);
6996 if (memcmp(&priv->active_rxon,
6997 &priv->staging_rxon, sizeof(priv->staging_rxon)))
6998 iwl3945_commit_rxon(priv);
7000 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
7002 IWL_DEBUG_MAC80211("leave\n");
7004 mutex_unlock(&priv->mutex);
7009 static void iwl3945_config_ap(struct iwl3945_priv *priv)
7013 if (priv->status & STATUS_EXIT_PENDING)
7016 /* The following should be done only at AP bring up */
7017 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
7019 /* RXON - unassoc (to set timing command) */
7020 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7021 iwl3945_commit_rxon(priv);
7024 memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
7025 iwl3945_setup_rxon_timing(priv);
7026 rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
7027 sizeof(priv->rxon_timing), &priv->rxon_timing);
7029 IWL_WARNING("REPLY_RXON_TIMING failed - "
7030 "Attempting to continue.\n");
7032 /* FIXME: what should be the assoc_id for AP? */
7033 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7034 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7035 priv->staging_rxon.flags |=
7036 RXON_FLG_SHORT_PREAMBLE_MSK;
7038 priv->staging_rxon.flags &=
7039 ~RXON_FLG_SHORT_PREAMBLE_MSK;
7041 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7042 if (priv->assoc_capability &
7043 WLAN_CAPABILITY_SHORT_SLOT_TIME)
7044 priv->staging_rxon.flags |=
7045 RXON_FLG_SHORT_SLOT_MSK;
7047 priv->staging_rxon.flags &=
7048 ~RXON_FLG_SHORT_SLOT_MSK;
7050 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7051 priv->staging_rxon.flags &=
7052 ~RXON_FLG_SHORT_SLOT_MSK;
7054 /* restore RXON assoc */
7055 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
7056 iwl3945_commit_rxon(priv);
7057 iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
7059 iwl3945_send_beacon_cmd(priv);
7061 /* FIXME - we need to add code here to detect a totally new
7062 * configuration, reset the AP, unassoc, rxon timing, assoc,
7063 * clear sta table, add BCAST sta... */
7066 static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, int if_id,
7067 struct ieee80211_if_conf *conf)
7069 struct iwl3945_priv *priv = hw->priv;
7070 DECLARE_MAC_BUF(mac);
7071 unsigned long flags;
7077 /* XXX: this MUST use conf->mac_addr */
7079 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
7080 (!conf->beacon || !conf->ssid_len)) {
7082 ("Leaving in AP mode because HostAPD is not ready.\n");
7086 mutex_lock(&priv->mutex);
7088 IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id);
7090 IWL_DEBUG_MAC80211("bssid: %s\n",
7091 print_mac(mac, conf->bssid));
7094 * very dubious code was here; the probe filtering flag is never set:
7096 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
7097 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
7099 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
7100 IWL_DEBUG_MAC80211("leave - scanning\n");
7101 mutex_unlock(&priv->mutex);
7105 if (priv->interface_id != if_id) {
7106 IWL_DEBUG_MAC80211("leave - interface_id != if_id\n");
7107 mutex_unlock(&priv->mutex);
7111 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7113 conf->bssid = priv->mac_addr;
7114 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
7115 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
7116 print_mac(mac, conf->bssid));
7118 if (priv->ibss_beacon)
7119 dev_kfree_skb(priv->ibss_beacon);
7121 priv->ibss_beacon = conf->beacon;
7124 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
7125 !is_multicast_ether_addr(conf->bssid)) {
7126 /* If there is currently a HW scan going on in the background
7127 * then we need to cancel it else the RXON below will fail. */
7128 if (iwl3945_scan_cancel_timeout(priv, 100)) {
7129 IWL_WARNING("Aborted scan still in progress "
7131 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
7132 mutex_unlock(&priv->mutex);
7135 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
7137 /* TODO: Audit driver for usage of these members and see
7138 * if mac80211 deprecates them (priv->bssid looks like it
7139 * shouldn't be there, but I haven't scanned the IBSS code
7140 * to verify) - jpk */
7141 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
7143 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
7144 iwl3945_config_ap(priv);
7146 rc = iwl3945_commit_rxon(priv);
7147 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
7148 iwl3945_add_station(priv,
7149 priv->active_rxon.bssid_addr, 1, 0);
7153 iwl3945_scan_cancel_timeout(priv, 100);
7154 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7155 iwl3945_commit_rxon(priv);
7158 spin_lock_irqsave(&priv->lock, flags);
7159 if (!conf->ssid_len)
7160 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7162 memcpy(priv->essid, conf->ssid, conf->ssid_len);
7164 priv->essid_len = conf->ssid_len;
7165 spin_unlock_irqrestore(&priv->lock, flags);
7167 IWL_DEBUG_MAC80211("leave\n");
7168 mutex_unlock(&priv->mutex);
7173 static void iwl3945_configure_filter(struct ieee80211_hw *hw,
7174 unsigned int changed_flags,
7175 unsigned int *total_flags,
7176 int mc_count, struct dev_addr_list *mc_list)
7180 * see also iwl3945_connection_init_rx_config
7185 static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
7186 struct ieee80211_if_init_conf *conf)
7188 struct iwl3945_priv *priv = hw->priv;
7190 IWL_DEBUG_MAC80211("enter\n");
7192 mutex_lock(&priv->mutex);
7194 iwl3945_scan_cancel_timeout(priv, 100);
7195 cancel_delayed_work(&priv->post_associate);
7196 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7197 iwl3945_commit_rxon(priv);
7199 if (priv->interface_id == conf->if_id) {
7200 priv->interface_id = 0;
7201 memset(priv->bssid, 0, ETH_ALEN);
7202 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7203 priv->essid_len = 0;
7205 mutex_unlock(&priv->mutex);
7207 IWL_DEBUG_MAC80211("leave\n");
7211 #define IWL_DELAY_NEXT_SCAN (HZ*2)
7212 static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
7215 unsigned long flags;
7216 struct iwl3945_priv *priv = hw->priv;
7218 IWL_DEBUG_MAC80211("enter\n");
7220 mutex_lock(&priv->mutex);
7221 spin_lock_irqsave(&priv->lock, flags);
7223 if (!iwl3945_is_ready_rf(priv)) {
7225 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7229 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
7231 IWL_ERROR("ERROR: APs don't scan\n");
7235 /* if we just finished scan ask for delay */
7236 if (priv->last_scan_jiffies &&
7237 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
7243 IWL_DEBUG_SCAN("direct scan for "
7245 iwl3945_escape_essid(ssid, len), (int)len);
7247 priv->one_direct_scan = 1;
7248 priv->direct_ssid_len = (u8)
7249 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
7250 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
7252 priv->one_direct_scan = 0;
7254 rc = iwl3945_scan_initiate(priv);
7256 IWL_DEBUG_MAC80211("leave\n");
7259 spin_unlock_irqrestore(&priv->lock, flags);
7260 mutex_unlock(&priv->mutex);
7265 static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
7266 const u8 *local_addr, const u8 *addr,
7267 struct ieee80211_key_conf *key)
7269 struct iwl3945_priv *priv = hw->priv;
7273 IWL_DEBUG_MAC80211("enter\n");
7275 if (!iwl3945_param_hwcrypto) {
7276 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7280 if (is_zero_ether_addr(addr))
7281 /* only support pairwise keys */
7284 sta_id = iwl3945_hw_find_station(priv, addr);
7285 if (sta_id == IWL_INVALID_STATION) {
7286 DECLARE_MAC_BUF(mac);
7288 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7289 print_mac(mac, addr));
7293 mutex_lock(&priv->mutex);
7295 iwl3945_scan_cancel_timeout(priv, 100);
7299 rc = iwl3945_update_sta_key_info(priv, key, sta_id);
7301 iwl3945_set_rxon_hwcrypto(priv, 1);
7302 iwl3945_commit_rxon(priv);
7303 key->hw_key_idx = sta_id;
7304 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7305 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
7309 rc = iwl3945_clear_sta_key_info(priv, sta_id);
7311 iwl3945_set_rxon_hwcrypto(priv, 0);
7312 iwl3945_commit_rxon(priv);
7313 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7320 IWL_DEBUG_MAC80211("leave\n");
7321 mutex_unlock(&priv->mutex);
7326 static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue,
7327 const struct ieee80211_tx_queue_params *params)
7329 struct iwl3945_priv *priv = hw->priv;
7330 #ifdef CONFIG_IWL3945_QOS
7331 unsigned long flags;
7333 #endif /* CONFIG_IWL3945_QOS */
7335 IWL_DEBUG_MAC80211("enter\n");
7337 if (!iwl3945_is_ready_rf(priv)) {
7338 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7342 if (queue >= AC_NUM) {
7343 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
7347 #ifdef CONFIG_IWL3945_QOS
7348 if (!priv->qos_data.qos_enable) {
7349 priv->qos_data.qos_active = 0;
7350 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7353 q = AC_NUM - 1 - queue;
7355 spin_lock_irqsave(&priv->lock, flags);
7357 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
7358 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
7359 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
7360 priv->qos_data.def_qos_parm.ac[q].edca_txop =
7361 cpu_to_le16((params->burst_time * 100));
7363 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
7364 priv->qos_data.qos_active = 1;
7366 spin_unlock_irqrestore(&priv->lock, flags);
7368 mutex_lock(&priv->mutex);
7369 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
7370 iwl3945_activate_qos(priv, 1);
7371 else if (priv->assoc_id && iwl3945_is_associated(priv))
7372 iwl3945_activate_qos(priv, 0);
7374 mutex_unlock(&priv->mutex);
7376 #endif /*CONFIG_IWL3945_QOS */
7378 IWL_DEBUG_MAC80211("leave\n");
7382 static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
7383 struct ieee80211_tx_queue_stats *stats)
7385 struct iwl3945_priv *priv = hw->priv;
7387 struct iwl3945_tx_queue *txq;
7388 struct iwl3945_queue *q;
7389 unsigned long flags;
7391 IWL_DEBUG_MAC80211("enter\n");
7393 if (!iwl3945_is_ready_rf(priv)) {
7394 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7398 spin_lock_irqsave(&priv->lock, flags);
7400 for (i = 0; i < AC_NUM; i++) {
7401 txq = &priv->txq[i];
7403 avail = iwl3945_queue_space(q);
7405 stats->data[i].len = q->n_window - avail;
7406 stats->data[i].limit = q->n_window - q->high_mark;
7407 stats->data[i].count = q->n_window;
7410 spin_unlock_irqrestore(&priv->lock, flags);
7412 IWL_DEBUG_MAC80211("leave\n");
7417 static int iwl3945_mac_get_stats(struct ieee80211_hw *hw,
7418 struct ieee80211_low_level_stats *stats)
7420 IWL_DEBUG_MAC80211("enter\n");
7421 IWL_DEBUG_MAC80211("leave\n");
7426 static u64 iwl3945_mac_get_tsf(struct ieee80211_hw *hw)
7428 IWL_DEBUG_MAC80211("enter\n");
7429 IWL_DEBUG_MAC80211("leave\n");
7434 static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
7436 struct iwl3945_priv *priv = hw->priv;
7437 unsigned long flags;
7439 mutex_lock(&priv->mutex);
7440 IWL_DEBUG_MAC80211("enter\n");
7442 #ifdef CONFIG_IWL3945_QOS
7443 iwl3945_reset_qos(priv);
7445 cancel_delayed_work(&priv->post_associate);
7447 spin_lock_irqsave(&priv->lock, flags);
7449 priv->assoc_capability = 0;
7450 priv->call_post_assoc_from_beacon = 0;
7452 /* new association get rid of ibss beacon skb */
7453 if (priv->ibss_beacon)
7454 dev_kfree_skb(priv->ibss_beacon);
7456 priv->ibss_beacon = NULL;
7458 priv->beacon_int = priv->hw->conf.beacon_int;
7459 priv->timestamp1 = 0;
7460 priv->timestamp0 = 0;
7461 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
7462 priv->beacon_int = 0;
7464 spin_unlock_irqrestore(&priv->lock, flags);
7466 /* we are restarting association process
7467 * clear RXON_FILTER_ASSOC_MSK bit
7469 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
7470 iwl3945_scan_cancel_timeout(priv, 100);
7471 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7472 iwl3945_commit_rxon(priv);
7475 /* Per mac80211.h: This is only used in IBSS mode... */
7476 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7478 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7479 mutex_unlock(&priv->mutex);
7483 if (!iwl3945_is_ready_rf(priv)) {
7484 IWL_DEBUG_MAC80211("leave - not ready\n");
7485 mutex_unlock(&priv->mutex);
7489 priv->only_active_channel = 0;
7491 iwl3945_set_rate(priv);
7493 mutex_unlock(&priv->mutex);
7495 IWL_DEBUG_MAC80211("leave\n");
7499 static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
7500 struct ieee80211_tx_control *control)
7502 struct iwl3945_priv *priv = hw->priv;
7503 unsigned long flags;
7505 mutex_lock(&priv->mutex);
7506 IWL_DEBUG_MAC80211("enter\n");
7508 if (!iwl3945_is_ready_rf(priv)) {
7509 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7510 mutex_unlock(&priv->mutex);
7514 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7515 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7516 mutex_unlock(&priv->mutex);
7520 spin_lock_irqsave(&priv->lock, flags);
7522 if (priv->ibss_beacon)
7523 dev_kfree_skb(priv->ibss_beacon);
7525 priv->ibss_beacon = skb;
7529 IWL_DEBUG_MAC80211("leave\n");
7530 spin_unlock_irqrestore(&priv->lock, flags);
7532 #ifdef CONFIG_IWL3945_QOS
7533 iwl3945_reset_qos(priv);
7536 queue_work(priv->workqueue, &priv->post_associate.work);
7538 mutex_unlock(&priv->mutex);
7543 /*****************************************************************************
7547 *****************************************************************************/
7549 #ifdef CONFIG_IWL3945_DEBUG
7552 * The following adds a new attribute to the sysfs representation
7553 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7554 * used for controlling the debug level.
7556 * See the level definitions in iwl for details.
7559 static ssize_t show_debug_level(struct device_driver *d, char *buf)
7561 return sprintf(buf, "0x%08X\n", iwl3945_debug_level);
7563 static ssize_t store_debug_level(struct device_driver *d,
7564 const char *buf, size_t count)
7566 char *p = (char *)buf;
7569 val = simple_strtoul(p, &p, 0);
7571 printk(KERN_INFO DRV_NAME
7572 ": %s is not in hex or decimal form.\n", buf);
7574 iwl3945_debug_level = val;
7576 return strnlen(buf, count);
7579 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
7580 show_debug_level, store_debug_level);
7582 #endif /* CONFIG_IWL3945_DEBUG */
7584 static ssize_t show_rf_kill(struct device *d,
7585 struct device_attribute *attr, char *buf)
7588 * 0 - RF kill not enabled
7589 * 1 - SW based RF kill active (sysfs)
7590 * 2 - HW based RF kill active
7591 * 3 - Both HW and SW based RF kill active
7593 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7594 int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
7595 (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
7597 return sprintf(buf, "%i\n", val);
7600 static ssize_t store_rf_kill(struct device *d,
7601 struct device_attribute *attr,
7602 const char *buf, size_t count)
7604 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7606 mutex_lock(&priv->mutex);
7607 iwl3945_radio_kill_sw(priv, buf[0] == '1');
7608 mutex_unlock(&priv->mutex);
7613 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
7615 static ssize_t show_temperature(struct device *d,
7616 struct device_attribute *attr, char *buf)
7618 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7620 if (!iwl3945_is_alive(priv))
7623 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
7626 static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
7628 static ssize_t show_rs_window(struct device *d,
7629 struct device_attribute *attr,
7632 struct iwl3945_priv *priv = d->driver_data;
7633 return iwl3945_fill_rs_info(priv->hw, buf, IWL_AP_ID);
7635 static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
7637 static ssize_t show_tx_power(struct device *d,
7638 struct device_attribute *attr, char *buf)
7640 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7641 return sprintf(buf, "%d\n", priv->user_txpower_limit);
7644 static ssize_t store_tx_power(struct device *d,
7645 struct device_attribute *attr,
7646 const char *buf, size_t count)
7648 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7649 char *p = (char *)buf;
7652 val = simple_strtoul(p, &p, 10);
7654 printk(KERN_INFO DRV_NAME
7655 ": %s is not in decimal form.\n", buf);
7657 iwl3945_hw_reg_set_txpower(priv, val);
7662 static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
7664 static ssize_t show_flags(struct device *d,
7665 struct device_attribute *attr, char *buf)
7667 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7669 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
7672 static ssize_t store_flags(struct device *d,
7673 struct device_attribute *attr,
7674 const char *buf, size_t count)
7676 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7677 u32 flags = simple_strtoul(buf, NULL, 0);
7679 mutex_lock(&priv->mutex);
7680 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
7681 /* Cancel any currently running scans... */
7682 if (iwl3945_scan_cancel_timeout(priv, 100))
7683 IWL_WARNING("Could not cancel scan.\n");
7685 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7687 priv->staging_rxon.flags = cpu_to_le32(flags);
7688 iwl3945_commit_rxon(priv);
7691 mutex_unlock(&priv->mutex);
7696 static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
7698 static ssize_t show_filter_flags(struct device *d,
7699 struct device_attribute *attr, char *buf)
7701 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7703 return sprintf(buf, "0x%04X\n",
7704 le32_to_cpu(priv->active_rxon.filter_flags));
7707 static ssize_t store_filter_flags(struct device *d,
7708 struct device_attribute *attr,
7709 const char *buf, size_t count)
7711 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7712 u32 filter_flags = simple_strtoul(buf, NULL, 0);
7714 mutex_lock(&priv->mutex);
7715 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
7716 /* Cancel any currently running scans... */
7717 if (iwl3945_scan_cancel_timeout(priv, 100))
7718 IWL_WARNING("Could not cancel scan.\n");
7720 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7721 "0x%04X\n", filter_flags);
7722 priv->staging_rxon.filter_flags =
7723 cpu_to_le32(filter_flags);
7724 iwl3945_commit_rxon(priv);
7727 mutex_unlock(&priv->mutex);
7732 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
7733 store_filter_flags);
7735 static ssize_t show_tune(struct device *d,
7736 struct device_attribute *attr, char *buf)
7738 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7740 return sprintf(buf, "0x%04X\n",
7741 (priv->phymode << 8) |
7742 le16_to_cpu(priv->active_rxon.channel));
7745 static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode);
7747 static ssize_t store_tune(struct device *d,
7748 struct device_attribute *attr,
7749 const char *buf, size_t count)
7751 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7752 char *p = (char *)buf;
7753 u16 tune = simple_strtoul(p, &p, 0);
7754 u8 phymode = (tune >> 8) & 0xff;
7755 u16 channel = tune & 0xff;
7757 IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel);
7759 mutex_lock(&priv->mutex);
7760 if ((le16_to_cpu(priv->staging_rxon.channel) != channel) ||
7761 (priv->phymode != phymode)) {
7762 const struct iwl3945_channel_info *ch_info;
7764 ch_info = iwl3945_get_channel_info(priv, phymode, channel);
7766 IWL_WARNING("Requested invalid phymode/channel "
7767 "combination: %d %d\n", phymode, channel);
7768 mutex_unlock(&priv->mutex);
7772 /* Cancel any currently running scans... */
7773 if (iwl3945_scan_cancel_timeout(priv, 100))
7774 IWL_WARNING("Could not cancel scan.\n");
7776 IWL_DEBUG_INFO("Committing phymode and "
7777 "rxon.channel = %d %d\n",
7780 iwl3945_set_rxon_channel(priv, phymode, channel);
7781 iwl3945_set_flags_for_phymode(priv, phymode);
7783 iwl3945_set_rate(priv);
7784 iwl3945_commit_rxon(priv);
7787 mutex_unlock(&priv->mutex);
7792 static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune);
7794 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
7796 static ssize_t show_measurement(struct device *d,
7797 struct device_attribute *attr, char *buf)
7799 struct iwl3945_priv *priv = dev_get_drvdata(d);
7800 struct iwl3945_spectrum_notification measure_report;
7801 u32 size = sizeof(measure_report), len = 0, ofs = 0;
7802 u8 *data = (u8 *) & measure_report;
7803 unsigned long flags;
7805 spin_lock_irqsave(&priv->lock, flags);
7806 if (!(priv->measurement_status & MEASUREMENT_READY)) {
7807 spin_unlock_irqrestore(&priv->lock, flags);
7810 memcpy(&measure_report, &priv->measure_report, size);
7811 priv->measurement_status = 0;
7812 spin_unlock_irqrestore(&priv->lock, flags);
7814 while (size && (PAGE_SIZE - len)) {
7815 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
7816 PAGE_SIZE - len, 1);
7818 if (PAGE_SIZE - len)
7822 size -= min(size, 16U);
7828 static ssize_t store_measurement(struct device *d,
7829 struct device_attribute *attr,
7830 const char *buf, size_t count)
7832 struct iwl3945_priv *priv = dev_get_drvdata(d);
7833 struct ieee80211_measurement_params params = {
7834 .channel = le16_to_cpu(priv->active_rxon.channel),
7835 .start_time = cpu_to_le64(priv->last_tsf),
7836 .duration = cpu_to_le16(1),
7838 u8 type = IWL_MEASURE_BASIC;
7844 strncpy(buffer, buf, min(sizeof(buffer), count));
7845 channel = simple_strtoul(p, NULL, 0);
7847 params.channel = channel;
7850 while (*p && *p != ' ')
7853 type = simple_strtoul(p + 1, NULL, 0);
7856 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7857 "channel %d (for '%s')\n", type, params.channel, buf);
7858 iwl3945_get_measurement(priv, ¶ms, type);
7863 static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
7864 show_measurement, store_measurement);
7865 #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
7867 static ssize_t show_rate(struct device *d,
7868 struct device_attribute *attr, char *buf)
7870 struct iwl3945_priv *priv = dev_get_drvdata(d);
7871 unsigned long flags;
7874 spin_lock_irqsave(&priv->sta_lock, flags);
7875 if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
7876 i = priv->stations[IWL_AP_ID].current_rate.s.rate;
7878 i = priv->stations[IWL_STA_ID].current_rate.s.rate;
7879 spin_unlock_irqrestore(&priv->sta_lock, flags);
7881 i = iwl3945_rate_index_from_plcp(i);
7883 return sprintf(buf, "0\n");
7885 return sprintf(buf, "%d%s\n",
7886 (iwl3945_rates[i].ieee >> 1),
7887 (iwl3945_rates[i].ieee & 0x1) ? ".5" : "");
7890 static DEVICE_ATTR(rate, S_IRUSR, show_rate, NULL);
7892 static ssize_t store_retry_rate(struct device *d,
7893 struct device_attribute *attr,
7894 const char *buf, size_t count)
7896 struct iwl3945_priv *priv = dev_get_drvdata(d);
7898 priv->retry_rate = simple_strtoul(buf, NULL, 0);
7899 if (priv->retry_rate <= 0)
7900 priv->retry_rate = 1;
7905 static ssize_t show_retry_rate(struct device *d,
7906 struct device_attribute *attr, char *buf)
7908 struct iwl3945_priv *priv = dev_get_drvdata(d);
7909 return sprintf(buf, "%d", priv->retry_rate);
7912 static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
7915 static ssize_t store_power_level(struct device *d,
7916 struct device_attribute *attr,
7917 const char *buf, size_t count)
7919 struct iwl3945_priv *priv = dev_get_drvdata(d);
7923 mode = simple_strtoul(buf, NULL, 0);
7924 mutex_lock(&priv->mutex);
7926 if (!iwl3945_is_ready(priv)) {
7931 if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
7932 mode = IWL_POWER_AC;
7934 mode |= IWL_POWER_ENABLED;
7936 if (mode != priv->power_mode) {
7937 rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
7939 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7942 priv->power_mode = mode;
7948 mutex_unlock(&priv->mutex);
7952 #define MAX_WX_STRING 80
7954 /* Values are in microsecond */
7955 static const s32 timeout_duration[] = {
7962 static const s32 period_duration[] = {
7970 static ssize_t show_power_level(struct device *d,
7971 struct device_attribute *attr, char *buf)
7973 struct iwl3945_priv *priv = dev_get_drvdata(d);
7974 int level = IWL_POWER_LEVEL(priv->power_mode);
7977 p += sprintf(p, "%d ", level);
7979 case IWL_POWER_MODE_CAM:
7981 p += sprintf(p, "(AC)");
7983 case IWL_POWER_BATTERY:
7984 p += sprintf(p, "(BATTERY)");
7988 "(Timeout %dms, Period %dms)",
7989 timeout_duration[level - 1] / 1000,
7990 period_duration[level - 1] / 1000);
7993 if (!(priv->power_mode & IWL_POWER_ENABLED))
7994 p += sprintf(p, " OFF\n");
7996 p += sprintf(p, " \n");
7998 return (p - buf + 1);
8002 static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
8005 static ssize_t show_channels(struct device *d,
8006 struct device_attribute *attr, char *buf)
8008 struct iwl3945_priv *priv = dev_get_drvdata(d);
8010 struct ieee80211_channel *channels = NULL;
8011 const struct ieee80211_hw_mode *hw_mode = NULL;
8014 if (!iwl3945_is_ready(priv))
8017 hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211G);
8019 hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211B);
8021 channels = hw_mode->channels;
8022 count = hw_mode->num_channels;
8027 "Displaying %d channels in 2.4GHz band "
8028 "(802.11bg):\n", count);
8030 for (i = 0; i < count; i++)
8031 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8033 channels[i].power_level,
8035 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8036 " (IEEE 802.11h required)" : "",
8037 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8040 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8043 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8044 "active/passive" : "passive only");
8046 hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211A);
8048 channels = hw_mode->channels;
8049 count = hw_mode->num_channels;
8055 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
8056 "(802.11a):\n", count);
8058 for (i = 0; i < count; i++)
8059 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8061 channels[i].power_level,
8063 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8064 " (IEEE 802.11h required)" : "",
8065 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8068 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8071 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8072 "active/passive" : "passive only");
8077 static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
8079 static ssize_t show_statistics(struct device *d,
8080 struct device_attribute *attr, char *buf)
8082 struct iwl3945_priv *priv = dev_get_drvdata(d);
8083 u32 size = sizeof(struct iwl3945_notif_statistics);
8084 u32 len = 0, ofs = 0;
8085 u8 *data = (u8 *) & priv->statistics;
8088 if (!iwl3945_is_alive(priv))
8091 mutex_lock(&priv->mutex);
8092 rc = iwl3945_send_statistics_request(priv);
8093 mutex_unlock(&priv->mutex);
8097 "Error sending statistics request: 0x%08X\n", rc);
8101 while (size && (PAGE_SIZE - len)) {
8102 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8103 PAGE_SIZE - len, 1);
8105 if (PAGE_SIZE - len)
8109 size -= min(size, 16U);
8115 static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
8117 static ssize_t show_antenna(struct device *d,
8118 struct device_attribute *attr, char *buf)
8120 struct iwl3945_priv *priv = dev_get_drvdata(d);
8122 if (!iwl3945_is_alive(priv))
8125 return sprintf(buf, "%d\n", priv->antenna);
8128 static ssize_t store_antenna(struct device *d,
8129 struct device_attribute *attr,
8130 const char *buf, size_t count)
8133 struct iwl3945_priv *priv = dev_get_drvdata(d);
8138 if (sscanf(buf, "%1i", &ant) != 1) {
8139 IWL_DEBUG_INFO("not in hex or decimal form.\n");
8143 if ((ant >= 0) && (ant <= 2)) {
8144 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
8145 priv->antenna = (enum iwl3945_antenna)ant;
8147 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
8153 static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
8155 static ssize_t show_status(struct device *d,
8156 struct device_attribute *attr, char *buf)
8158 struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
8159 if (!iwl3945_is_alive(priv))
8161 return sprintf(buf, "0x%08x\n", (int)priv->status);
8164 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
8166 static ssize_t dump_error_log(struct device *d,
8167 struct device_attribute *attr,
8168 const char *buf, size_t count)
8170 char *p = (char *)buf;
8173 iwl3945_dump_nic_error_log((struct iwl3945_priv *)d->driver_data);
8175 return strnlen(buf, count);
8178 static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
8180 static ssize_t dump_event_log(struct device *d,
8181 struct device_attribute *attr,
8182 const char *buf, size_t count)
8184 char *p = (char *)buf;
8187 iwl3945_dump_nic_event_log((struct iwl3945_priv *)d->driver_data);
8189 return strnlen(buf, count);
8192 static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
8194 /*****************************************************************************
8196 * driver setup and teardown
8198 *****************************************************************************/
8200 static void iwl3945_setup_deferred_work(struct iwl3945_priv *priv)
8202 priv->workqueue = create_workqueue(DRV_NAME);
8204 init_waitqueue_head(&priv->wait_command_queue);
8206 INIT_WORK(&priv->up, iwl3945_bg_up);
8207 INIT_WORK(&priv->restart, iwl3945_bg_restart);
8208 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
8209 INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed);
8210 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
8211 INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan);
8212 INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill);
8213 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
8214 INIT_DELAYED_WORK(&priv->post_associate, iwl3945_bg_post_associate);
8215 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
8216 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
8217 INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check);
8219 iwl3945_hw_setup_deferred_work(priv);
8221 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
8222 iwl3945_irq_tasklet, (unsigned long)priv);
8225 static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv)
8227 iwl3945_hw_cancel_deferred_work(priv);
8229 cancel_delayed_work_sync(&priv->init_alive_start);
8230 cancel_delayed_work(&priv->scan_check);
8231 cancel_delayed_work(&priv->alive_start);
8232 cancel_delayed_work(&priv->post_associate);
8233 cancel_work_sync(&priv->beacon_update);
8236 static struct attribute *iwl3945_sysfs_entries[] = {
8237 &dev_attr_antenna.attr,
8238 &dev_attr_channels.attr,
8239 &dev_attr_dump_errors.attr,
8240 &dev_attr_dump_events.attr,
8241 &dev_attr_flags.attr,
8242 &dev_attr_filter_flags.attr,
8243 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
8244 &dev_attr_measurement.attr,
8246 &dev_attr_power_level.attr,
8247 &dev_attr_rate.attr,
8248 &dev_attr_retry_rate.attr,
8249 &dev_attr_rf_kill.attr,
8250 &dev_attr_rs_window.attr,
8251 &dev_attr_statistics.attr,
8252 &dev_attr_status.attr,
8253 &dev_attr_temperature.attr,
8254 &dev_attr_tune.attr,
8255 &dev_attr_tx_power.attr,
8260 static struct attribute_group iwl3945_attribute_group = {
8261 .name = NULL, /* put in device directory */
8262 .attrs = iwl3945_sysfs_entries,
8265 static struct ieee80211_ops iwl3945_hw_ops = {
8266 .tx = iwl3945_mac_tx,
8267 .start = iwl3945_mac_start,
8268 .stop = iwl3945_mac_stop,
8269 .add_interface = iwl3945_mac_add_interface,
8270 .remove_interface = iwl3945_mac_remove_interface,
8271 .config = iwl3945_mac_config,
8272 .config_interface = iwl3945_mac_config_interface,
8273 .configure_filter = iwl3945_configure_filter,
8274 .set_key = iwl3945_mac_set_key,
8275 .get_stats = iwl3945_mac_get_stats,
8276 .get_tx_stats = iwl3945_mac_get_tx_stats,
8277 .conf_tx = iwl3945_mac_conf_tx,
8278 .get_tsf = iwl3945_mac_get_tsf,
8279 .reset_tsf = iwl3945_mac_reset_tsf,
8280 .beacon_update = iwl3945_mac_beacon_update,
8281 .hw_scan = iwl3945_mac_hw_scan
8284 static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
8288 struct iwl3945_priv *priv;
8289 struct ieee80211_hw *hw;
8292 if (iwl3945_param_disable_hw_scan) {
8293 IWL_DEBUG_INFO("Disabling hw_scan\n");
8294 iwl3945_hw_ops.hw_scan = NULL;
8297 if ((iwl3945_param_queues_num > IWL_MAX_NUM_QUEUES) ||
8298 (iwl3945_param_queues_num < IWL_MIN_NUM_QUEUES)) {
8299 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
8300 IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES);
8305 /* mac80211 allocates memory for this device instance, including
8306 * space for this driver's private structure */
8307 hw = ieee80211_alloc_hw(sizeof(struct iwl3945_priv), &iwl3945_hw_ops);
8309 IWL_ERROR("Can not allocate network device\n");
8313 SET_IEEE80211_DEV(hw, &pdev->dev);
8315 hw->rate_control_algorithm = "iwl-3945-rs";
8317 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
8321 priv->pci_dev = pdev;
8322 priv->antenna = (enum iwl3945_antenna)iwl3945_param_antenna;
8323 #ifdef CONFIG_IWL3945_DEBUG
8324 iwl3945_debug_level = iwl3945_param_debug;
8325 atomic_set(&priv->restrict_refcnt, 0);
8327 priv->retry_rate = 1;
8329 priv->ibss_beacon = NULL;
8331 /* Tell mac80211 and its clients (e.g. Wireless Extensions)
8332 * the range of signal quality values that we'll provide.
8333 * Negative values for level/noise indicate that we'll provide dBm.
8334 * For WE, at least, non-0 values here *enable* display of values
8335 * in app (iwconfig). */
8336 hw->max_rssi = -20; /* signal level, negative indicates dBm */
8337 hw->max_noise = -20; /* noise level, negative indicates dBm */
8338 hw->max_signal = 100; /* link quality indication (%) */
8340 /* Tell mac80211 our Tx characteristics */
8341 hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
8345 spin_lock_init(&priv->lock);
8346 spin_lock_init(&priv->power_data.lock);
8347 spin_lock_init(&priv->sta_lock);
8348 spin_lock_init(&priv->hcmd_lock);
8350 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
8351 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
8353 INIT_LIST_HEAD(&priv->free_frames);
8355 mutex_init(&priv->mutex);
8356 if (pci_enable_device(pdev)) {
8358 goto out_ieee80211_free_hw;
8361 pci_set_master(pdev);
8363 iwl3945_clear_stations_table(priv);
8365 priv->data_retry_limit = -1;
8366 priv->ieee_channels = NULL;
8367 priv->ieee_rates = NULL;
8370 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
8372 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
8374 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
8375 goto out_pci_disable_device;
8378 pci_set_drvdata(pdev, priv);
8379 err = pci_request_regions(pdev, DRV_NAME);
8381 goto out_pci_disable_device;
8382 /* We disable the RETRY_TIMEOUT register (0x41) to keep
8383 * PCI Tx retries from interfering with C3 CPU state */
8384 pci_write_config_byte(pdev, 0x41, 0x00);
8385 priv->hw_base = pci_iomap(pdev, 0, 0);
8386 if (!priv->hw_base) {
8388 goto out_pci_release_regions;
8391 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
8392 (unsigned long long) pci_resource_len(pdev, 0));
8393 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
8395 /* Initialize module parameter values here */
8397 if (iwl3945_param_disable) {
8398 set_bit(STATUS_RF_KILL_SW, &priv->status);
8399 IWL_DEBUG_INFO("Radio disabled.\n");
8402 priv->iw_mode = IEEE80211_IF_TYPE_STA;
8405 (priv->pci_dev->device << 16) | priv->pci_dev->subsystem_device;
8408 case 0x42221005: /* 0x4222 0x8086 0x1005 is BG SKU */
8409 case 0x42221034: /* 0x4222 0x8086 0x1034 is BG SKU */
8410 case 0x42271014: /* 0x4227 0x8086 0x1014 is BG SKU */
8411 case 0x42221044: /* 0x4222 0x8086 0x1044 is BG SKU */
8416 * Rest are assumed ABG SKU -- if this is not the
8417 * case then the card will get the wrong 'Detected'
8418 * line in the kernel log however the code that
8419 * initializes the GEO table will detect no A-band
8420 * channels and remove the is_abg mask.
8427 printk(KERN_INFO DRV_NAME
8428 ": Detected Intel PRO/Wireless 3945%sBG Network Connection\n",
8429 priv->is_abg ? "A" : "");
8431 /* Device-specific setup */
8432 if (iwl3945_hw_set_hw_setting(priv)) {
8433 IWL_ERROR("failed to set hw settings\n");
8434 mutex_unlock(&priv->mutex);
8438 #ifdef CONFIG_IWL3945_QOS
8439 if (iwl3945_param_qos_enable)
8440 priv->qos_data.qos_enable = 1;
8442 iwl3945_reset_qos(priv);
8444 priv->qos_data.qos_active = 0;
8445 priv->qos_data.qos_cap.val = 0;
8446 #endif /* CONFIG_IWL3945_QOS */
8448 iwl3945_set_rxon_channel(priv, MODE_IEEE80211G, 6);
8449 iwl3945_setup_deferred_work(priv);
8450 iwl3945_setup_rx_handlers(priv);
8452 priv->rates_mask = IWL_RATES_MASK;
8453 /* If power management is turned on, default to AC mode */
8454 priv->power_mode = IWL_POWER_AC;
8455 priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
8457 iwl3945_disable_interrupts(priv);
8459 pci_enable_msi(pdev);
8461 err = request_irq(pdev->irq, iwl3945_isr, IRQF_SHARED, DRV_NAME, priv);
8463 IWL_ERROR("Error allocating IRQ %d\n", pdev->irq);
8464 goto out_disable_msi;
8467 mutex_lock(&priv->mutex);
8469 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
8471 IWL_ERROR("failed to create sysfs device attributes\n");
8472 mutex_unlock(&priv->mutex);
8473 goto out_release_irq;
8476 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
8477 * ucode filename and max sizes are card-specific. */
8478 err = iwl3945_read_ucode(priv);
8480 IWL_ERROR("Could not read microcode: %d\n", err);
8481 mutex_unlock(&priv->mutex);
8485 mutex_unlock(&priv->mutex);
8487 IWL_DEBUG_INFO("Queueing UP work.\n");
8489 queue_work(priv->workqueue, &priv->up);
8494 iwl3945_dealloc_ucode_pci(priv);
8496 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
8499 free_irq(pdev->irq, priv);
8502 pci_disable_msi(pdev);
8503 destroy_workqueue(priv->workqueue);
8504 priv->workqueue = NULL;
8505 iwl3945_unset_hw_setting(priv);
8508 pci_iounmap(pdev, priv->hw_base);
8509 out_pci_release_regions:
8510 pci_release_regions(pdev);
8511 out_pci_disable_device:
8512 pci_disable_device(pdev);
8513 pci_set_drvdata(pdev, NULL);
8514 out_ieee80211_free_hw:
8515 ieee80211_free_hw(priv->hw);
8520 static void iwl3945_pci_remove(struct pci_dev *pdev)
8522 struct iwl3945_priv *priv = pci_get_drvdata(pdev);
8523 struct list_head *p, *q;
8529 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8531 set_bit(STATUS_EXIT_PENDING, &priv->status);
8535 /* Free MAC hash list for ADHOC */
8536 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
8537 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
8539 kfree(list_entry(p, struct iwl3945_ibss_seq, list));
8543 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
8545 iwl3945_dealloc_ucode_pci(priv);
8548 iwl3945_rx_queue_free(priv, &priv->rxq);
8549 iwl3945_hw_txq_ctx_free(priv);
8551 iwl3945_unset_hw_setting(priv);
8552 iwl3945_clear_stations_table(priv);
8554 if (priv->mac80211_registered) {
8555 ieee80211_unregister_hw(priv->hw);
8556 iwl3945_rate_control_unregister(priv->hw);
8559 /*netif_stop_queue(dev); */
8560 flush_workqueue(priv->workqueue);
8562 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
8563 * priv->workqueue... so we can't take down the workqueue
8565 destroy_workqueue(priv->workqueue);
8566 priv->workqueue = NULL;
8568 free_irq(pdev->irq, priv);
8569 pci_disable_msi(pdev);
8570 pci_iounmap(pdev, priv->hw_base);
8571 pci_release_regions(pdev);
8572 pci_disable_device(pdev);
8573 pci_set_drvdata(pdev, NULL);
8575 kfree(priv->channel_info);
8577 kfree(priv->ieee_channels);
8578 kfree(priv->ieee_rates);
8580 if (priv->ibss_beacon)
8581 dev_kfree_skb(priv->ibss_beacon);
8583 ieee80211_free_hw(priv->hw);
8588 static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
8590 struct iwl3945_priv *priv = pci_get_drvdata(pdev);
8592 set_bit(STATUS_IN_SUSPEND, &priv->status);
8594 /* Take down the device; powers it off, etc. */
8597 if (priv->mac80211_registered)
8598 ieee80211_stop_queues(priv->hw);
8600 pci_save_state(pdev);
8601 pci_disable_device(pdev);
8602 pci_set_power_state(pdev, PCI_D3hot);
8607 static void iwl3945_resume(struct iwl3945_priv *priv)
8609 unsigned long flags;
8611 /* The following it a temporary work around due to the
8612 * suspend / resume not fully initializing the NIC correctly.
8613 * Without all of the following, resume will not attempt to take
8614 * down the NIC (it shouldn't really need to) and will just try
8615 * and bring the NIC back up. However that fails during the
8616 * ucode verification process. This then causes iwl3945_down to be
8617 * called *after* iwl3945_hw_nic_init() has succeeded -- which
8618 * then lets the next init sequence succeed. So, we've
8619 * replicated all of that NIC init code here... */
8621 iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
8623 iwl3945_hw_nic_init(priv);
8625 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
8626 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR,
8627 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
8628 iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
8629 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
8630 iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
8632 /* tell the device to stop sending interrupts */
8633 iwl3945_disable_interrupts(priv);
8635 spin_lock_irqsave(&priv->lock, flags);
8636 iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
8638 if (!iwl3945_grab_nic_access(priv)) {
8639 iwl3945_write_prph(priv, APMG_CLK_DIS_REG,
8640 APMG_CLK_VAL_DMA_CLK_RQT);
8641 iwl3945_release_nic_access(priv);
8643 spin_unlock_irqrestore(&priv->lock, flags);
8647 iwl3945_hw_nic_reset(priv);
8649 /* Bring the device back up */
8650 clear_bit(STATUS_IN_SUSPEND, &priv->status);
8651 queue_work(priv->workqueue, &priv->up);
8654 static int iwl3945_pci_resume(struct pci_dev *pdev)
8656 struct iwl3945_priv *priv = pci_get_drvdata(pdev);
8659 printk(KERN_INFO "Coming out of suspend...\n");
8661 pci_set_power_state(pdev, PCI_D0);
8662 err = pci_enable_device(pdev);
8663 pci_restore_state(pdev);
8666 * Suspend/Resume resets the PCI configuration space, so we have to
8667 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
8668 * from interfering with C3 CPU state. pci_restore_state won't help
8669 * here since it only restores the first 64 bytes pci config header.
8671 pci_write_config_byte(pdev, 0x41, 0x00);
8673 iwl3945_resume(priv);
8678 #endif /* CONFIG_PM */
8680 /*****************************************************************************
8682 * driver and module entry point
8684 *****************************************************************************/
8686 static struct pci_driver iwl3945_driver = {
8688 .id_table = iwl3945_hw_card_ids,
8689 .probe = iwl3945_pci_probe,
8690 .remove = __devexit_p(iwl3945_pci_remove),
8692 .suspend = iwl3945_pci_suspend,
8693 .resume = iwl3945_pci_resume,
8697 static int __init iwl3945_init(void)
8701 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
8702 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
8703 ret = pci_register_driver(&iwl3945_driver);
8705 IWL_ERROR("Unable to initialize PCI module\n");
8708 #ifdef CONFIG_IWL3945_DEBUG
8709 ret = driver_create_file(&iwl3945_driver.driver, &driver_attr_debug_level);
8711 IWL_ERROR("Unable to create driver sysfs file\n");
8712 pci_unregister_driver(&iwl3945_driver);
8720 static void __exit iwl3945_exit(void)
8722 #ifdef CONFIG_IWL3945_DEBUG
8723 driver_remove_file(&iwl3945_driver.driver, &driver_attr_debug_level);
8725 pci_unregister_driver(&iwl3945_driver);
8728 module_param_named(antenna, iwl3945_param_antenna, int, 0444);
8729 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
8730 module_param_named(disable, iwl3945_param_disable, int, 0444);
8731 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
8732 module_param_named(hwcrypto, iwl3945_param_hwcrypto, int, 0444);
8733 MODULE_PARM_DESC(hwcrypto,
8734 "using hardware crypto engine (default 0 [software])\n");
8735 module_param_named(debug, iwl3945_param_debug, int, 0444);
8736 MODULE_PARM_DESC(debug, "debug output mask");
8737 module_param_named(disable_hw_scan, iwl3945_param_disable_hw_scan, int, 0444);
8738 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
8740 module_param_named(queues_num, iwl3945_param_queues_num, int, 0444);
8741 MODULE_PARM_DESC(queues_num, "number of hw queues.");
8744 module_param_named(qos_enable, iwl3945_param_qos_enable, int, 0444);
8745 MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
8747 module_exit(iwl3945_exit);
8748 module_init(iwl3945_init);