1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/pci.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/delay.h>
36 #include <linux/skbuff.h>
37 #include <linux/netdevice.h>
38 #include <linux/wireless.h>
39 #include <linux/firmware.h>
40 #include <linux/etherdevice.h>
41 #include <linux/if_arp.h>
43 #include <net/ieee80211_radiotap.h>
44 #include <net/lib80211.h>
45 #include <net/mac80211.h>
47 #include <asm/div64.h>
49 #define DRV_NAME "iwl3945"
51 #include "iwl-commands.h"
53 #include "iwl-3945-fh.h"
54 #include "iwl-helpers.h"
58 static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv *priv,
59 struct iwl3945_tx_queue *txq);
62 * module name, copyright, version, etc.
65 #define DRV_DESCRIPTION \
66 "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
68 #ifdef CONFIG_IWL3945_DEBUG
74 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
80 #define IWL39_VERSION "1.2.26k" VD VS
81 #define DRV_COPYRIGHT "Copyright(c) 2003-2008 Intel Corporation"
82 #define DRV_AUTHOR "<ilw@linux.intel.com>"
83 #define DRV_VERSION IWL39_VERSION
86 MODULE_DESCRIPTION(DRV_DESCRIPTION);
87 MODULE_VERSION(DRV_VERSION);
88 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
89 MODULE_LICENSE("GPL");
91 /* module parameters */
92 struct iwl_mod_params iwl3945_mod_params = {
93 .num_of_queues = IWL39_MAX_NUM_QUEUES,
94 /* the rest are 0 by default */
97 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
100 * Theory of operation
102 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
103 * of buffer descriptors, each of which points to one or more data buffers for
104 * the device to read from or fill. Driver and device exchange status of each
105 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
106 * entries in each circular buffer, to protect against confusing empty and full
109 * The device reads or writes the data in the queues via the device's several
110 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
112 * For Tx queue, there are low mark and high mark limits. If, after queuing
113 * the packet for Tx, free space become < low mark, Tx queue stopped. When
114 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
117 * The 3945 operates with six queues: One receive queue, one transmit queue
118 * (#4) for sending commands to the device firmware, and four transmit queues
119 * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
120 ***************************************************/
122 int iwl3945_x2_queue_used(const struct iwl_queue *q, int i)
124 return q->write_ptr > q->read_ptr ?
125 (i >= q->read_ptr && i < q->write_ptr) :
126 !(i < q->read_ptr && i >= q->write_ptr);
130 * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
132 static int iwl3945_queue_init(struct iwl_priv *priv, struct iwl_queue *q,
133 int count, int slots_num, u32 id)
136 q->n_window = slots_num;
139 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
140 * and iwl_queue_dec_wrap are broken. */
141 BUG_ON(!is_power_of_2(count));
143 /* slots_num must be power-of-two size, otherwise
144 * get_cmd_index is broken. */
145 BUG_ON(!is_power_of_2(slots_num));
147 q->low_mark = q->n_window / 4;
151 q->high_mark = q->n_window / 8;
152 if (q->high_mark < 2)
155 q->write_ptr = q->read_ptr = 0;
161 * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
163 static int iwl3945_tx_queue_alloc(struct iwl_priv *priv,
164 struct iwl3945_tx_queue *txq, u32 id)
166 struct pci_dev *dev = priv->pci_dev;
168 /* Driver private data, only for Tx (not command) queues,
169 * not shared with device. */
170 if (id != IWL_CMD_QUEUE_NUM) {
171 txq->txb = kmalloc(sizeof(txq->txb[0]) *
172 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
174 IWL_ERR(priv, "kmalloc for auxiliary BD "
175 "structures failed\n");
181 /* Circular buffer of transmit frame descriptors (TFDs),
182 * shared with device */
183 txq->bd = pci_alloc_consistent(dev,
184 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
188 IWL_ERR(priv, "pci_alloc_consistent(%zd) failed\n",
189 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
204 * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
206 int iwl3945_tx_queue_init(struct iwl_priv *priv,
207 struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id)
209 struct pci_dev *dev = priv->pci_dev;
214 * Alloc buffer array for commands (Tx or other types of commands).
215 * For the command queue (#4), allocate command space + one big
216 * command for scan, since scan command is very huge; the system will
217 * not have two scans at the same time, so only one is needed.
218 * For data Tx queues (all other queues), no super-size command
221 len = sizeof(struct iwl_cmd) * slots_num;
222 if (txq_id == IWL_CMD_QUEUE_NUM)
223 len += IWL_MAX_SCAN_SIZE;
224 txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
228 /* Alloc driver data array and TFD circular buffer */
229 rc = iwl3945_tx_queue_alloc(priv, txq, txq_id);
231 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
235 txq->need_update = 0;
237 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
238 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
239 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
241 /* Initialize queue high/low-water, head/tail indexes */
242 iwl3945_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
244 /* Tell device where to find queue, enable DMA channel. */
245 iwl3945_hw_tx_queue_init(priv, txq);
251 * iwl3945_tx_queue_free - Deallocate DMA queue.
252 * @txq: Transmit queue to deallocate.
254 * Empty queue by removing and destroying all BD's.
256 * 0-fill, but do not free "txq" descriptor structure.
258 void iwl3945_tx_queue_free(struct iwl_priv *priv, struct iwl3945_tx_queue *txq)
260 struct iwl_queue *q = &txq->q;
261 struct pci_dev *dev = priv->pci_dev;
267 /* first, empty all BD's */
268 for (; q->write_ptr != q->read_ptr;
269 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
270 iwl3945_hw_txq_free_tfd(priv, txq);
272 len = sizeof(struct iwl_cmd) * q->n_window;
273 if (q->id == IWL_CMD_QUEUE_NUM)
274 len += IWL_MAX_SCAN_SIZE;
276 /* De-alloc array of command/tx buffers */
277 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
279 /* De-alloc circular buffer of TFDs */
281 pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) *
282 txq->q.n_bd, txq->bd, txq->q.dma_addr);
284 /* De-alloc array of per-TFD driver data */
288 /* 0-fill queue descriptor structure */
289 memset(txq, 0, sizeof(*txq));
292 /*************** STATION TABLE MANAGEMENT ****
293 * mac80211 should be examined to determine if sta_info is duplicating
294 * the functionality provided here
297 /**************************************************************/
298 #if 0 /* temporary disable till we add real remove station */
300 * iwl3945_remove_station - Remove driver's knowledge of station.
302 * NOTE: This does not remove station from device's station table.
304 static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
306 int index = IWL_INVALID_STATION;
310 spin_lock_irqsave(&priv->sta_lock, flags);
314 else if (is_broadcast_ether_addr(addr))
315 index = priv->hw_params.bcast_sta_id;
317 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
318 if (priv->stations_39[i].used &&
319 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
325 if (unlikely(index == IWL_INVALID_STATION))
328 if (priv->stations_39[index].used) {
329 priv->stations_39[index].used = 0;
330 priv->num_stations--;
333 BUG_ON(priv->num_stations < 0);
336 spin_unlock_irqrestore(&priv->sta_lock, flags);
342 * iwl3945_clear_stations_table - Clear the driver's station table
344 * NOTE: This does not clear or otherwise alter the device's station table.
346 static void iwl3945_clear_stations_table(struct iwl_priv *priv)
350 spin_lock_irqsave(&priv->sta_lock, flags);
352 priv->num_stations = 0;
353 memset(priv->stations_39, 0, sizeof(priv->stations_39));
355 spin_unlock_irqrestore(&priv->sta_lock, flags);
359 * iwl3945_add_station - Add station to station tables in driver and device
361 u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
364 int index = IWL_INVALID_STATION;
365 struct iwl3945_station_entry *station;
366 unsigned long flags_spin;
369 spin_lock_irqsave(&priv->sta_lock, flags_spin);
372 else if (is_broadcast_ether_addr(addr))
373 index = priv->hw_params.bcast_sta_id;
375 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
376 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
382 if (!priv->stations_39[i].used &&
383 index == IWL_INVALID_STATION)
387 /* These two conditions has the same outcome but keep them separate
388 since they have different meaning */
389 if (unlikely(index == IWL_INVALID_STATION)) {
390 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
394 if (priv->stations_39[index].used &&
395 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
396 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
400 IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr);
401 station = &priv->stations_39[index];
403 priv->num_stations++;
405 /* Set up the REPLY_ADD_STA command to send to device */
406 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
407 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
408 station->sta.mode = 0;
409 station->sta.sta.sta_id = index;
410 station->sta.station_flags = 0;
412 if (priv->band == IEEE80211_BAND_5GHZ)
413 rate = IWL_RATE_6M_PLCP;
415 rate = IWL_RATE_1M_PLCP;
417 /* Turn on both antennas for the station... */
418 station->sta.rate_n_flags =
419 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
421 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
423 /* Add station to device's station table */
424 iwl3945_send_add_station(priv, &station->sta, flags);
430 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
432 #define IWL_CMD(x) case x: return #x
433 #define HOST_COMPLETE_TIMEOUT (HZ / 2)
436 * iwl3945_enqueue_hcmd - enqueue a uCode command
437 * @priv: device private data point
438 * @cmd: a point to the ucode command structure
440 * The function returns < 0 values to indicate the operation is
441 * failed. On success, it turns the index (> 0) of command in the
444 static int iwl3945_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
446 struct iwl3945_tx_queue *txq = &priv->txq39[IWL_CMD_QUEUE_NUM];
447 struct iwl_queue *q = &txq->q;
448 struct iwl3945_tfd_frame *tfd;
450 struct iwl_cmd *out_cmd;
452 u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
453 dma_addr_t phys_addr;
459 /* If any of the command structures end up being larger than
460 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
461 * we will need to increase the size of the TFD entries */
462 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
463 !(cmd->meta.flags & CMD_SIZE_HUGE));
466 if (iwl_is_rfkill(priv)) {
467 IWL_DEBUG_INFO("Not sending command - RF KILL");
471 if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
472 IWL_ERR(priv, "No space for Tx\n");
476 spin_lock_irqsave(&priv->hcmd_lock, flags);
478 tfd = &txq->bd[q->write_ptr];
479 memset(tfd, 0, sizeof(*tfd));
481 control_flags = (u32 *) tfd;
483 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
484 out_cmd = &txq->cmd[idx];
486 out_cmd->hdr.cmd = cmd->id;
487 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
488 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
490 /* At this point, the out_cmd now has all of the incoming cmd
493 out_cmd->hdr.flags = 0;
494 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
495 INDEX_TO_SEQ(q->write_ptr));
496 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
497 out_cmd->hdr.sequence |= SEQ_HUGE_FRAME;
499 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
500 offsetof(struct iwl_cmd, hdr);
501 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
503 pad = U32_PAD(cmd->len);
504 count = TFD_CTL_COUNT_GET(*control_flags);
505 *control_flags = TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad);
507 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
508 "%d bytes at %d[%d]:%d\n",
509 get_cmd_string(out_cmd->hdr.cmd),
510 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
511 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
513 txq->need_update = 1;
515 /* Increment and update queue's write index */
516 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
517 ret = iwl3945_tx_queue_update_write_ptr(priv, txq);
519 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
520 return ret ? ret : idx;
523 static int iwl3945_send_cmd_async(struct iwl_priv *priv,
524 struct iwl_host_cmd *cmd)
528 BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
530 /* An asynchronous command can not expect an SKB to be set. */
531 BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
533 /* An asynchronous command MUST have a callback. */
534 BUG_ON(!cmd->meta.u.callback);
536 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
539 ret = iwl3945_enqueue_hcmd(priv, cmd);
542 "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
543 get_cmd_string(cmd->id), ret);
549 static int iwl3945_send_cmd_sync(struct iwl_priv *priv,
550 struct iwl_host_cmd *cmd)
555 BUG_ON(cmd->meta.flags & CMD_ASYNC);
557 /* A synchronous command can not have a callback set. */
558 BUG_ON(cmd->meta.u.callback != NULL);
560 if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status)) {
562 "Error sending %s: Already sending a host command\n",
563 get_cmd_string(cmd->id));
568 set_bit(STATUS_HCMD_ACTIVE, &priv->status);
570 if (cmd->meta.flags & CMD_WANT_SKB)
571 cmd->meta.source = &cmd->meta;
573 cmd_idx = iwl3945_enqueue_hcmd(priv, cmd);
577 "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
578 get_cmd_string(cmd->id), ret);
582 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
583 !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
584 HOST_COMPLETE_TIMEOUT);
586 if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
587 IWL_ERR(priv, "Error sending %s: time out after %dms\n",
588 get_cmd_string(cmd->id),
589 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
591 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
597 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
598 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
599 get_cmd_string(cmd->id));
603 if (test_bit(STATUS_FW_ERROR, &priv->status)) {
604 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
605 get_cmd_string(cmd->id));
609 if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
610 IWL_ERR(priv, "Error: Response NULL in '%s'\n",
611 get_cmd_string(cmd->id));
620 if (cmd->meta.flags & CMD_WANT_SKB) {
621 struct iwl_cmd *qcmd;
623 /* Cancel the CMD_WANT_SKB flag for the cmd in the
624 * TX cmd queue. Otherwise in case the cmd comes
625 * in later, it will possibly set an invalid
626 * address (cmd->meta.source). */
627 qcmd = &priv->txq39[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
628 qcmd->meta.flags &= ~CMD_WANT_SKB;
631 if (cmd->meta.u.skb) {
632 dev_kfree_skb_any(cmd->meta.u.skb);
633 cmd->meta.u.skb = NULL;
636 clear_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status);
640 int iwl3945_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
642 if (cmd->meta.flags & CMD_ASYNC)
643 return iwl3945_send_cmd_async(priv, cmd);
645 return iwl3945_send_cmd_sync(priv, cmd);
648 int iwl3945_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data)
650 struct iwl_host_cmd cmd = {
656 return iwl3945_send_cmd_sync(priv, &cmd);
659 static int __must_check iwl3945_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val)
661 struct iwl_host_cmd cmd = {
667 return iwl3945_send_cmd_sync(priv, &cmd);
670 int iwl3945_send_statistics_request(struct iwl_priv *priv)
672 return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
676 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
677 * @band: 2.4 or 5 GHz band
678 * @channel: Any channel valid for the requested band
680 * In addition to setting the staging RXON, priv->band is also set.
682 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
683 * in the staging RXON flag structure based on the band
685 static int iwl3945_set_rxon_channel(struct iwl_priv *priv,
686 enum ieee80211_band band,
689 if (!iwl3945_get_channel_info(priv, band, channel)) {
690 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
695 if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) &&
696 (priv->band == band))
699 priv->staging39_rxon.channel = cpu_to_le16(channel);
700 if (band == IEEE80211_BAND_5GHZ)
701 priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
703 priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
707 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
713 * iwl3945_check_rxon_cmd - validate RXON structure is valid
715 * NOTE: This is really only useful during development and can eventually
716 * be #ifdef'd out once the driver is stable and folks aren't actively
719 static int iwl3945_check_rxon_cmd(struct iwl_priv *priv)
723 struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
725 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
726 error |= le32_to_cpu(rxon->flags &
727 (RXON_FLG_TGJ_NARROW_BAND_MSK |
728 RXON_FLG_RADAR_DETECT_MSK));
730 IWL_WARN(priv, "check 24G fields %d | %d\n",
733 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
734 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
736 IWL_WARN(priv, "check 52 fields %d | %d\n",
738 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
740 IWL_WARN(priv, "check 52 CCK %d | %d\n",
743 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
745 IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
747 /* make sure basic rates 6Mbps and 1Mbps are supported */
748 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
749 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
751 IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
753 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
755 IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
757 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
758 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
760 IWL_WARN(priv, "check CCK and short slot %d | %d\n",
763 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
764 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
766 IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
769 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
770 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
772 IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
775 if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
776 error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
777 RXON_FLG_ANT_A_MSK)) == 0);
779 IWL_WARN(priv, "check antenna %d %d\n", counter++, error);
782 IWL_WARN(priv, "Tuning to channel %d\n",
783 le16_to_cpu(rxon->channel));
786 IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n");
793 * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
794 * @priv: staging_rxon is compared to active_rxon
796 * If the RXON structure is changing enough to require a new tune,
797 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
798 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
800 static int iwl3945_full_rxon_required(struct iwl_priv *priv)
803 /* These items are only settable from the full RXON command */
804 if (!(iwl3945_is_associated(priv)) ||
805 compare_ether_addr(priv->staging39_rxon.bssid_addr,
806 priv->active39_rxon.bssid_addr) ||
807 compare_ether_addr(priv->staging39_rxon.node_addr,
808 priv->active39_rxon.node_addr) ||
809 compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr,
810 priv->active39_rxon.wlap_bssid_addr) ||
811 (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) ||
812 (priv->staging39_rxon.channel != priv->active39_rxon.channel) ||
813 (priv->staging39_rxon.air_propagation !=
814 priv->active39_rxon.air_propagation) ||
815 (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id))
818 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
819 * be updated with the RXON_ASSOC command -- however only some
820 * flag transitions are allowed using RXON_ASSOC */
822 /* Check if we are not switching bands */
823 if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
824 (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK))
827 /* Check if we are switching association toggle */
828 if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
829 (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
835 static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
838 struct iwl_rx_packet *res = NULL;
839 struct iwl3945_rxon_assoc_cmd rxon_assoc;
840 struct iwl_host_cmd cmd = {
841 .id = REPLY_RXON_ASSOC,
842 .len = sizeof(rxon_assoc),
843 .meta.flags = CMD_WANT_SKB,
846 const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon;
847 const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon;
849 if ((rxon1->flags == rxon2->flags) &&
850 (rxon1->filter_flags == rxon2->filter_flags) &&
851 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
852 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
853 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
857 rxon_assoc.flags = priv->staging39_rxon.flags;
858 rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags;
859 rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates;
860 rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates;
861 rxon_assoc.reserved = 0;
863 rc = iwl3945_send_cmd_sync(priv, &cmd);
867 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
868 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
869 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
873 priv->alloc_rxb_skb--;
874 dev_kfree_skb_any(cmd.meta.u.skb);
880 * iwl3945_commit_rxon - commit staging_rxon to hardware
882 * The RXON command in staging_rxon is committed to the hardware and
883 * the active_rxon structure is updated with the new data. This
884 * function correctly transitions out of the RXON_ASSOC_MSK state if
885 * a HW tune is required based on the RXON structure changes.
887 static int iwl3945_commit_rxon(struct iwl_priv *priv)
889 /* cast away the const for active_rxon in this function */
890 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon;
893 if (!iwl_is_alive(priv))
896 /* always get timestamp with Rx frame */
897 priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
900 priv->staging39_rxon.flags &=
901 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
902 priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv);
904 rc = iwl3945_check_rxon_cmd(priv);
906 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
910 /* If we don't need to send a full RXON, we can use
911 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
912 * and other flags for the current radio configuration. */
913 if (!iwl3945_full_rxon_required(priv)) {
914 rc = iwl3945_send_rxon_assoc(priv);
916 IWL_ERR(priv, "Error setting RXON_ASSOC "
917 "configuration (%d).\n", rc);
921 memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
926 /* If we are currently associated and the new config requires
927 * an RXON_ASSOC and the new config wants the associated mask enabled,
928 * we must clear the associated from the active configuration
929 * before we apply the new config */
930 if (iwl3945_is_associated(priv) &&
931 (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
932 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
933 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
935 rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
936 sizeof(struct iwl3945_rxon_cmd),
937 &priv->active39_rxon);
939 /* If the mask clearing failed then we set
940 * active_rxon back to what it was previously */
942 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
943 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
944 "configuration (%d).\n", rc);
949 IWL_DEBUG_INFO("Sending RXON\n"
950 "* with%s RXON_FILTER_ASSOC_MSK\n"
953 ((priv->staging39_rxon.filter_flags &
954 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
955 le16_to_cpu(priv->staging39_rxon.channel),
956 priv->staging_rxon.bssid_addr);
958 /* Apply the new configuration */
959 rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
960 sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon);
962 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
966 memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
968 iwl3945_clear_stations_table(priv);
970 /* If we issue a new RXON command which required a tune then we must
971 * send a new TXPOWER command or we won't be able to Tx any frames */
972 rc = iwl3945_hw_reg_send_txpower(priv);
974 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
978 /* Add the broadcast address so we can send broadcast frames */
979 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
980 IWL_INVALID_STATION) {
981 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
985 /* If we have set the ASSOC_MSK and we are in BSS mode then
986 * add the IWL_AP_ID to the station rate table */
987 if (iwl3945_is_associated(priv) &&
988 (priv->iw_mode == NL80211_IFTYPE_STATION))
989 if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0)
990 == IWL_INVALID_STATION) {
991 IWL_ERR(priv, "Error adding AP address for transmit\n");
995 /* Init the hardware's rate fallback order based on the band */
996 rc = iwl3945_init_hw_rate_table(priv);
998 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
1005 static int iwl3945_send_bt_config(struct iwl_priv *priv)
1007 struct iwl_bt_cmd bt_cmd = {
1015 return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1016 sizeof(bt_cmd), &bt_cmd);
1019 static int iwl3945_send_scan_abort(struct iwl_priv *priv)
1022 struct iwl_rx_packet *res;
1023 struct iwl_host_cmd cmd = {
1024 .id = REPLY_SCAN_ABORT_CMD,
1025 .meta.flags = CMD_WANT_SKB,
1028 /* If there isn't a scan actively going on in the hardware
1029 * then we are in between scan bands and not actually
1030 * actively scanning, so don't send the abort command */
1031 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1032 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1036 rc = iwl3945_send_cmd_sync(priv, &cmd);
1038 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1042 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
1043 if (res->u.status != CAN_ABORT_STATUS) {
1044 /* The scan abort will return 1 for success or
1045 * 2 for "failure". A failure condition can be
1046 * due to simply not being in an active scan which
1047 * can occur if we send the scan abort before we
1048 * the microcode has notified us that a scan is
1050 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
1051 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1052 clear_bit(STATUS_SCAN_HW, &priv->status);
1055 dev_kfree_skb_any(cmd.meta.u.skb);
1060 static int iwl3945_card_state_sync_callback(struct iwl_priv *priv,
1061 struct iwl_cmd *cmd,
1062 struct sk_buff *skb)
1070 * Use: Sets the device's internal card state to enable, disable, or halt
1072 * When in the 'enable' state the card operates as normal.
1073 * When in the 'disable' state, the card enters into a low power mode.
1074 * When in the 'halt' state, the card is shut down and must be fully
1075 * restarted to come back on.
1077 static int iwl3945_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
1079 struct iwl_host_cmd cmd = {
1080 .id = REPLY_CARD_STATE_CMD,
1083 .meta.flags = meta_flag,
1086 if (meta_flag & CMD_ASYNC)
1087 cmd.meta.u.callback = iwl3945_card_state_sync_callback;
1089 return iwl3945_send_cmd(priv, &cmd);
1092 static int iwl3945_add_sta_sync_callback(struct iwl_priv *priv,
1093 struct iwl_cmd *cmd, struct sk_buff *skb)
1095 struct iwl_rx_packet *res = NULL;
1098 IWL_ERR(priv, "Error: Response NULL in REPLY_ADD_STA.\n");
1102 res = (struct iwl_rx_packet *)skb->data;
1103 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1104 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
1109 switch (res->u.add_sta.status) {
1110 case ADD_STA_SUCCESS_MSK:
1116 /* We didn't cache the SKB; let the caller free it */
1120 int iwl3945_send_add_station(struct iwl_priv *priv,
1121 struct iwl3945_addsta_cmd *sta, u8 flags)
1123 struct iwl_rx_packet *res = NULL;
1125 struct iwl_host_cmd cmd = {
1126 .id = REPLY_ADD_STA,
1127 .len = sizeof(struct iwl3945_addsta_cmd),
1128 .meta.flags = flags,
1132 if (flags & CMD_ASYNC)
1133 cmd.meta.u.callback = iwl3945_add_sta_sync_callback;
1135 cmd.meta.flags |= CMD_WANT_SKB;
1137 rc = iwl3945_send_cmd(priv, &cmd);
1139 if (rc || (flags & CMD_ASYNC))
1142 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
1143 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1144 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
1150 switch (res->u.add_sta.status) {
1151 case ADD_STA_SUCCESS_MSK:
1152 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1156 IWL_WARN(priv, "REPLY_ADD_STA failed\n");
1161 priv->alloc_rxb_skb--;
1162 dev_kfree_skb_any(cmd.meta.u.skb);
1167 static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
1168 struct ieee80211_key_conf *keyconf,
1171 unsigned long flags;
1172 __le16 key_flags = 0;
1174 switch (keyconf->alg) {
1176 key_flags |= STA_KEY_FLG_CCMP;
1177 key_flags |= cpu_to_le16(
1178 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1179 key_flags &= ~STA_KEY_FLG_INVALID;
1186 spin_lock_irqsave(&priv->sta_lock, flags);
1187 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
1188 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
1189 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
1192 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
1194 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
1195 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1196 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1198 spin_unlock_irqrestore(&priv->sta_lock, flags);
1200 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1201 iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0);
1205 static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
1207 unsigned long flags;
1209 spin_lock_irqsave(&priv->sta_lock, flags);
1210 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
1211 memset(&priv->stations_39[sta_id].sta.key, 0,
1212 sizeof(struct iwl4965_keyinfo));
1213 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
1214 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1215 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1216 spin_unlock_irqrestore(&priv->sta_lock, flags);
1218 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1219 iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0);
1223 static void iwl3945_clear_free_frames(struct iwl_priv *priv)
1225 struct list_head *element;
1227 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1228 priv->frames_count);
1230 while (!list_empty(&priv->free_frames)) {
1231 element = priv->free_frames.next;
1233 kfree(list_entry(element, struct iwl3945_frame, list));
1234 priv->frames_count--;
1237 if (priv->frames_count) {
1238 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
1239 priv->frames_count);
1240 priv->frames_count = 0;
1244 static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
1246 struct iwl3945_frame *frame;
1247 struct list_head *element;
1248 if (list_empty(&priv->free_frames)) {
1249 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1251 IWL_ERR(priv, "Could not allocate frame!\n");
1255 priv->frames_count++;
1259 element = priv->free_frames.next;
1261 return list_entry(element, struct iwl3945_frame, list);
1264 static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
1266 memset(frame, 0, sizeof(*frame));
1267 list_add(&frame->list, &priv->free_frames);
1270 unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
1271 struct ieee80211_hdr *hdr,
1275 if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
1276 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
1277 (priv->iw_mode != NL80211_IFTYPE_AP)))
1280 if (priv->ibss_beacon->len > left)
1283 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1285 return priv->ibss_beacon->len;
1288 static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv)
1294 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
1295 rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
1297 rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
1299 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
1300 i = iwl3945_rates[i].next_ieee) {
1301 if (rate_mask & (1 << i))
1302 return iwl3945_rates[i].plcp;
1305 /* No valid rate was found. Assign the lowest one */
1306 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
1307 return IWL_RATE_1M_PLCP;
1309 return IWL_RATE_6M_PLCP;
1312 static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
1314 struct iwl3945_frame *frame;
1315 unsigned int frame_size;
1319 frame = iwl3945_get_free_frame(priv);
1322 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
1327 rate = iwl3945_rate_get_lowest_plcp(priv);
1329 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
1331 rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
1334 iwl3945_free_frame(priv, frame);
1339 /******************************************************************************
1341 * EEPROM related functions
1343 ******************************************************************************/
1345 static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac)
1347 memcpy(mac, priv->eeprom39.mac_address, 6);
1351 * Clear the OWNER_MSK, to establish driver (instead of uCode running on
1352 * embedded controller) as EEPROM reader; each read is a series of pulses
1353 * to/from the EEPROM chip, not a single event, so even reads could conflict
1354 * if they weren't arbitrated by some ownership mechanism. Here, the driver
1355 * simply claims ownership, which should be safe when this function is called
1356 * (i.e. before loading uCode!).
1358 static inline int iwl3945_eeprom_acquire_semaphore(struct iwl_priv *priv)
1360 _iwl_clear_bit(priv, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK);
1365 * iwl3945_eeprom_init - read EEPROM contents
1367 * Load the EEPROM contents from adapter into priv->eeprom39
1369 * NOTE: This routine uses the non-debug IO access functions.
1371 int iwl3945_eeprom_init(struct iwl_priv *priv)
1373 u16 *e = (u16 *)&priv->eeprom39;
1374 u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
1375 int sz = sizeof(priv->eeprom39);
1379 /* The EEPROM structure has several padding buffers within it
1380 * and when adding new EEPROM maps is subject to programmer errors
1381 * which may be very difficult to identify without explicitly
1382 * checking the resulting size of the eeprom map. */
1383 BUILD_BUG_ON(sizeof(priv->eeprom39) != IWL_EEPROM_IMAGE_SIZE);
1385 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
1386 IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
1390 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
1391 ret = iwl3945_eeprom_acquire_semaphore(priv);
1393 IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
1397 /* eeprom is an array of 16bit values */
1398 for (addr = 0; addr < sz; addr += sizeof(u16)) {
1401 _iwl_write32(priv, CSR_EEPROM_REG,
1402 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
1403 _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
1404 ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
1405 CSR_EEPROM_REG_READ_VALID_MSK,
1406 IWL_EEPROM_ACCESS_TIMEOUT);
1408 IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr);
1412 r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
1413 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
1419 static void iwl3945_unset_hw_params(struct iwl_priv *priv)
1421 if (priv->shared_virt)
1422 pci_free_consistent(priv->pci_dev,
1423 sizeof(struct iwl3945_shared),
1429 * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field
1431 * return : set the bit for each supported rate insert in ie
1433 static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate,
1434 u16 basic_rate, int *left)
1436 u16 ret_rates = 0, bit;
1441 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1442 if (bit & supported_rate) {
1444 rates[*cnt] = iwl3945_rates[i].ieee |
1445 ((bit & basic_rate) ? 0x80 : 0x00);
1449 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
1458 * iwl3945_fill_probe_req - fill in all required fields and IE for probe request
1460 static u16 iwl3945_fill_probe_req(struct iwl_priv *priv,
1461 struct ieee80211_mgmt *frame,
1466 u16 active_rates, ret_rates, cck_rates;
1468 /* Make sure there is enough space for the probe request,
1469 * two mandatory IEs and the data */
1475 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1476 memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
1477 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
1478 memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
1479 frame->seq_ctrl = 0;
1481 /* fill in our indirect SSID IE */
1488 pos = &(frame->u.probe_req.variable[0]);
1489 *pos++ = WLAN_EID_SSID;
1492 /* fill in supported rate */
1498 /* ... fill it in... */
1499 *pos++ = WLAN_EID_SUPP_RATES;
1502 priv->active_rate = priv->rates_mask;
1503 active_rates = priv->active_rate;
1504 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1506 cck_rates = IWL_CCK_RATES_MASK & active_rates;
1507 ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates,
1508 priv->active_rate_basic, &left);
1509 active_rates &= ~ret_rates;
1511 ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates,
1512 priv->active_rate_basic, &left);
1513 active_rates &= ~ret_rates;
1517 if (active_rates == 0)
1520 /* fill in supported extended rate */
1525 /* ... fill it in... */
1526 *pos++ = WLAN_EID_EXT_SUPP_RATES;
1528 iwl3945_supported_rate_to_ie(pos, active_rates,
1529 priv->active_rate_basic, &left);
1540 static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
1541 struct iwl_qosparam_cmd *qos)
1544 return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM,
1545 sizeof(struct iwl_qosparam_cmd), qos);
1548 static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
1550 unsigned long flags;
1552 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1555 spin_lock_irqsave(&priv->lock, flags);
1556 priv->qos_data.def_qos_parm.qos_flags = 0;
1558 if (priv->qos_data.qos_cap.q_AP.queue_request &&
1559 !priv->qos_data.qos_cap.q_AP.txop_request)
1560 priv->qos_data.def_qos_parm.qos_flags |=
1561 QOS_PARAM_FLG_TXOP_TYPE_MSK;
1563 if (priv->qos_data.qos_active)
1564 priv->qos_data.def_qos_parm.qos_flags |=
1565 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
1567 spin_unlock_irqrestore(&priv->lock, flags);
1569 if (force || iwl3945_is_associated(priv)) {
1570 IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n",
1571 priv->qos_data.qos_active);
1573 iwl3945_send_qos_params_command(priv,
1574 &(priv->qos_data.def_qos_parm));
1579 * Power management (not Tx power!) functions
1581 #define MSEC_TO_USEC 1024
1584 #define NOSLP __constant_cpu_to_le16(0), 0, 0
1585 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1586 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1587 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1588 __constant_cpu_to_le32(X1), \
1589 __constant_cpu_to_le32(X2), \
1590 __constant_cpu_to_le32(X3), \
1591 __constant_cpu_to_le32(X4)}
1593 /* default power management (not Tx power) table values */
1595 static struct iwl_power_vec_entry range_0[IWL39_POWER_AC] = {
1596 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1597 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1598 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1599 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1600 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1601 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1605 static struct iwl_power_vec_entry range_1[IWL39_POWER_AC] = {
1606 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1607 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1608 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1609 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1610 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1611 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1612 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1613 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1614 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1615 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1618 int iwl3945_power_init_handle(struct iwl_priv *priv)
1621 struct iwl3945_power_mgr *pow_data;
1622 int size = sizeof(struct iwl_power_vec_entry) * IWL39_POWER_AC;
1625 IWL_DEBUG_POWER("Initialize power \n");
1627 pow_data = &(priv->power_data_39);
1629 memset(pow_data, 0, sizeof(*pow_data));
1631 pow_data->active_index = IWL_POWER_RANGE_0;
1632 pow_data->dtim_val = 0xffff;
1634 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
1635 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
1637 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
1641 struct iwl_powertable_cmd *cmd;
1643 IWL_DEBUG_POWER("adjust power command flags\n");
1645 for (i = 0; i < IWL39_POWER_AC; i++) {
1646 cmd = &pow_data->pwr_range_0[i].cmd;
1649 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
1651 cmd->flags |= IWL_POWER_PCI_PM_MSK;
1657 static int iwl3945_update_power_cmd(struct iwl_priv *priv,
1658 struct iwl_powertable_cmd *cmd, u32 mode)
1663 struct iwl_power_vec_entry *range;
1665 struct iwl3945_power_mgr *pow_data;
1667 if (mode > IWL_POWER_INDEX_5) {
1668 IWL_DEBUG_POWER("Error invalid power mode \n");
1671 pow_data = &(priv->power_data_39);
1673 if (pow_data->active_index == IWL_POWER_RANGE_0)
1674 range = &pow_data->pwr_range_0[0];
1676 range = &pow_data->pwr_range_1[1];
1678 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
1680 #ifdef IWL_MAC80211_DISABLE
1681 if (priv->assoc_network != NULL) {
1682 unsigned long flags;
1684 period = priv->assoc_network->tim.tim_period;
1686 #endif /*IWL_MAC80211_DISABLE */
1687 skip = range[mode].no_dtim;
1696 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
1698 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
1699 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
1700 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
1703 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
1704 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
1705 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
1708 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
1709 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
1710 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
1711 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1712 le32_to_cpu(cmd->sleep_interval[0]),
1713 le32_to_cpu(cmd->sleep_interval[1]),
1714 le32_to_cpu(cmd->sleep_interval[2]),
1715 le32_to_cpu(cmd->sleep_interval[3]),
1716 le32_to_cpu(cmd->sleep_interval[4]));
1721 static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode)
1723 u32 uninitialized_var(final_mode);
1725 struct iwl_powertable_cmd cmd;
1727 /* If on battery, set to 3,
1728 * if plugged into AC power, set to CAM ("continuously aware mode"),
1729 * else user level */
1731 case IWL39_POWER_BATTERY:
1732 final_mode = IWL_POWER_INDEX_3;
1734 case IWL39_POWER_AC:
1735 final_mode = IWL_POWER_MODE_CAM;
1742 iwl3945_update_power_cmd(priv, &cmd, final_mode);
1744 /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */
1745 rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD,
1746 sizeof(struct iwl3945_powertable_cmd), &cmd);
1748 if (final_mode == IWL_POWER_MODE_CAM)
1749 clear_bit(STATUS_POWER_PMI, &priv->status);
1751 set_bit(STATUS_POWER_PMI, &priv->status);
1757 * iwl3945_scan_cancel - Cancel any currently executing HW scan
1759 * NOTE: priv->mutex is not required before calling this function
1761 static int iwl3945_scan_cancel(struct iwl_priv *priv)
1763 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1764 clear_bit(STATUS_SCANNING, &priv->status);
1768 if (test_bit(STATUS_SCANNING, &priv->status)) {
1769 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1770 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1771 set_bit(STATUS_SCAN_ABORTING, &priv->status);
1772 queue_work(priv->workqueue, &priv->abort_scan);
1775 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1777 return test_bit(STATUS_SCANNING, &priv->status);
1784 * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan
1785 * @ms: amount of time to wait (in milliseconds) for scan to abort
1787 * NOTE: priv->mutex must be held before calling this function
1789 static int iwl3945_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
1791 unsigned long now = jiffies;
1794 ret = iwl3945_scan_cancel(priv);
1796 mutex_unlock(&priv->mutex);
1797 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
1798 test_bit(STATUS_SCANNING, &priv->status))
1800 mutex_lock(&priv->mutex);
1802 return test_bit(STATUS_SCANNING, &priv->status);
1808 #define MAX_UCODE_BEACON_INTERVAL 1024
1809 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1811 static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
1814 u16 beacon_factor = 0;
1817 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
1818 / MAX_UCODE_BEACON_INTERVAL;
1819 new_val = beacon_val / beacon_factor;
1821 return cpu_to_le16(new_val);
1824 static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
1826 u64 interval_tm_unit;
1828 unsigned long flags;
1829 struct ieee80211_conf *conf = NULL;
1832 conf = ieee80211_get_hw_conf(priv->hw);
1834 spin_lock_irqsave(&priv->lock, flags);
1835 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
1836 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
1838 tsf = priv->timestamp;
1840 beacon_int = priv->beacon_int;
1841 spin_unlock_irqrestore(&priv->lock, flags);
1843 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
1844 if (beacon_int == 0) {
1845 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
1846 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
1848 priv->rxon_timing.beacon_interval =
1849 cpu_to_le16(beacon_int);
1850 priv->rxon_timing.beacon_interval =
1851 iwl3945_adjust_beacon_interval(
1852 le16_to_cpu(priv->rxon_timing.beacon_interval));
1855 priv->rxon_timing.atim_window = 0;
1857 priv->rxon_timing.beacon_interval =
1858 iwl3945_adjust_beacon_interval(conf->beacon_int);
1859 /* TODO: we need to get atim_window from upper stack
1860 * for now we set to 0 */
1861 priv->rxon_timing.atim_window = 0;
1865 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
1866 result = do_div(tsf, interval_tm_unit);
1867 priv->rxon_timing.beacon_init_val =
1868 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
1871 ("beacon interval %d beacon timer %d beacon tim %d\n",
1872 le16_to_cpu(priv->rxon_timing.beacon_interval),
1873 le32_to_cpu(priv->rxon_timing.beacon_init_val),
1874 le16_to_cpu(priv->rxon_timing.atim_window));
1877 static int iwl3945_scan_initiate(struct iwl_priv *priv)
1879 if (!iwl_is_ready_rf(priv)) {
1880 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1884 if (test_bit(STATUS_SCANNING, &priv->status)) {
1885 IWL_DEBUG_SCAN("Scan already in progress.\n");
1889 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1890 IWL_DEBUG_SCAN("Scan request while abort pending. "
1895 IWL_DEBUG_INFO("Starting scan...\n");
1896 if (priv->cfg->sku & IWL_SKU_G)
1897 priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
1898 if (priv->cfg->sku & IWL_SKU_A)
1899 priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
1900 set_bit(STATUS_SCANNING, &priv->status);
1901 priv->scan_start = jiffies;
1902 priv->scan_pass_start = priv->scan_start;
1904 queue_work(priv->workqueue, &priv->request_scan);
1909 static int iwl3945_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
1911 struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
1914 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
1916 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
1921 static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv,
1922 enum ieee80211_band band)
1924 if (band == IEEE80211_BAND_5GHZ) {
1925 priv->staging39_rxon.flags &=
1926 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
1927 | RXON_FLG_CCK_MSK);
1928 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1930 /* Copied from iwl3945_bg_post_associate() */
1931 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
1932 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1934 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1936 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
1937 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1939 priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1940 priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
1941 priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK;
1946 * initialize rxon structure with default values from eeprom
1948 static void iwl3945_connection_init_rx_config(struct iwl_priv *priv,
1951 const struct iwl_channel_info *ch_info;
1953 memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon));
1956 case NL80211_IFTYPE_AP:
1957 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP;
1960 case NL80211_IFTYPE_STATION:
1961 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS;
1962 priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
1965 case NL80211_IFTYPE_ADHOC:
1966 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS;
1967 priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
1968 priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
1969 RXON_FILTER_ACCEPT_GRP_MSK;
1972 case NL80211_IFTYPE_MONITOR:
1973 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
1974 priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
1975 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
1978 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
1983 /* TODO: Figure out when short_preamble would be set and cache from
1985 if (!hw_to_local(priv->hw)->short_preamble)
1986 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1988 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1991 ch_info = iwl3945_get_channel_info(priv, priv->band,
1992 le16_to_cpu(priv->active39_rxon.channel));
1995 ch_info = &priv->channel_info[0];
1998 * in some case A channels are all non IBSS
1999 * in this case force B/G channel
2001 if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info)))
2002 ch_info = &priv->channel_info[0];
2004 priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel);
2005 if (is_channel_a_band(ch_info))
2006 priv->band = IEEE80211_BAND_5GHZ;
2008 priv->band = IEEE80211_BAND_2GHZ;
2010 iwl3945_set_flags_for_phymode(priv, priv->band);
2012 priv->staging39_rxon.ofdm_basic_rates =
2013 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2014 priv->staging39_rxon.cck_basic_rates =
2015 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2018 static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
2020 if (mode == NL80211_IFTYPE_ADHOC) {
2021 const struct iwl_channel_info *ch_info;
2023 ch_info = iwl3945_get_channel_info(priv,
2025 le16_to_cpu(priv->staging39_rxon.channel));
2027 if (!ch_info || !is_channel_ibss(ch_info)) {
2028 IWL_ERR(priv, "channel %d not IBSS channel\n",
2029 le16_to_cpu(priv->staging39_rxon.channel));
2034 iwl3945_connection_init_rx_config(priv, mode);
2035 memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2037 iwl3945_clear_stations_table(priv);
2039 /* don't commit rxon if rf-kill is on*/
2040 if (!iwl_is_ready_rf(priv))
2043 cancel_delayed_work(&priv->scan_check);
2044 if (iwl3945_scan_cancel_timeout(priv, 100)) {
2045 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
2046 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2050 iwl3945_commit_rxon(priv);
2055 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
2056 struct ieee80211_tx_info *info,
2057 struct iwl_cmd *cmd,
2058 struct sk_buff *skb_frag,
2061 struct iwl3945_hw_key *keyinfo =
2062 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
2064 switch (keyinfo->alg) {
2066 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
2067 memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
2068 IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n");
2073 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
2076 memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
2079 memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
2084 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2085 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2087 if (keyinfo->keylen == 13)
2088 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
2090 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2092 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2093 "with key %d\n", info->control.hw_key->hw_key_idx);
2097 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
2103 * handle build REPLY_TX command notification.
2105 static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
2106 struct iwl_cmd *cmd,
2107 struct ieee80211_tx_info *info,
2108 struct ieee80211_hdr *hdr,
2109 int is_unicast, u8 std_id)
2111 __le16 fc = hdr->frame_control;
2112 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2113 u8 rc_flags = info->control.rates[0].flags;
2115 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2116 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
2117 tx_flags |= TX_CMD_FLG_ACK_MSK;
2118 if (ieee80211_is_mgmt(fc))
2119 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2120 if (ieee80211_is_probe_resp(fc) &&
2121 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2122 tx_flags |= TX_CMD_FLG_TSF_MSK;
2124 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2125 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2128 cmd->cmd.tx.sta_id = std_id;
2129 if (ieee80211_has_morefrags(fc))
2130 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2132 if (ieee80211_is_data_qos(fc)) {
2133 u8 *qc = ieee80211_get_qos_ctl(hdr);
2134 cmd->cmd.tx.tid_tspec = qc[0] & 0xf;
2135 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2137 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2140 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
2141 tx_flags |= TX_CMD_FLG_RTS_MSK;
2142 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2143 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
2144 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2145 tx_flags |= TX_CMD_FLG_CTS_MSK;
2148 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2149 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2151 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2152 if (ieee80211_is_mgmt(fc)) {
2153 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
2154 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
2156 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
2158 cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2159 #ifdef CONFIG_IWL3945_LEDS
2160 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
2164 cmd->cmd.tx.driver_txop = 0;
2165 cmd->cmd.tx.tx_flags = tx_flags;
2166 cmd->cmd.tx.next_frame_len = 0;
2170 * iwl3945_get_sta_id - Find station's index within station table
2172 static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
2175 u16 fc = le16_to_cpu(hdr->frame_control);
2177 /* If this frame is broadcast or management, use broadcast station id */
2178 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2179 is_multicast_ether_addr(hdr->addr1))
2180 return priv->hw_params.bcast_sta_id;
2182 switch (priv->iw_mode) {
2184 /* If we are a client station in a BSS network, use the special
2185 * AP station entry (that's the only station we communicate with) */
2186 case NL80211_IFTYPE_STATION:
2189 /* If we are an AP, then find the station, or use BCAST */
2190 case NL80211_IFTYPE_AP:
2191 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
2192 if (sta_id != IWL_INVALID_STATION)
2194 return priv->hw_params.bcast_sta_id;
2196 /* If this frame is going out to an IBSS network, find the station,
2197 * or create a new station table entry */
2198 case NL80211_IFTYPE_ADHOC: {
2199 /* Create new station table entry */
2200 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
2201 if (sta_id != IWL_INVALID_STATION)
2204 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
2206 if (sta_id != IWL_INVALID_STATION)
2209 IWL_DEBUG_DROP("Station %pM not in station map. "
2210 "Defaulting to broadcast...\n",
2212 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
2213 return priv->hw_params.bcast_sta_id;
2215 /* If we are in monitor mode, use BCAST. This is required for
2216 * packet injection. */
2217 case NL80211_IFTYPE_MONITOR:
2218 return priv->hw_params.bcast_sta_id;
2221 IWL_WARN(priv, "Unknown mode of operation: %d\n",
2223 return priv->hw_params.bcast_sta_id;
2228 * start REPLY_TX command process
2230 static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
2232 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2233 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2234 struct iwl3945_tfd_frame *tfd;
2236 int txq_id = skb_get_queue_mapping(skb);
2237 struct iwl3945_tx_queue *txq = NULL;
2238 struct iwl_queue *q = NULL;
2239 dma_addr_t phys_addr;
2240 dma_addr_t txcmd_phys;
2241 struct iwl_cmd *out_cmd = NULL;
2242 u16 len, idx, len_org, hdr_len;
2249 u8 wait_write_ptr = 0;
2251 unsigned long flags;
2254 spin_lock_irqsave(&priv->lock, flags);
2255 if (iwl_is_rfkill(priv)) {
2256 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2260 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
2261 IWL_ERR(priv, "ERROR: No TX rate available.\n");
2265 unicast = !is_multicast_ether_addr(hdr->addr1);
2268 fc = hdr->frame_control;
2270 #ifdef CONFIG_IWL3945_DEBUG
2271 if (ieee80211_is_auth(fc))
2272 IWL_DEBUG_TX("Sending AUTH frame\n");
2273 else if (ieee80211_is_assoc_req(fc))
2274 IWL_DEBUG_TX("Sending ASSOC frame\n");
2275 else if (ieee80211_is_reassoc_req(fc))
2276 IWL_DEBUG_TX("Sending REASSOC frame\n");
2279 /* drop all data frame if we are not associated */
2280 if (ieee80211_is_data(fc) &&
2281 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
2282 (!iwl3945_is_associated(priv) ||
2283 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
2284 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
2288 spin_unlock_irqrestore(&priv->lock, flags);
2290 hdr_len = ieee80211_hdrlen(fc);
2292 /* Find (or create) index into station table for destination station */
2293 sta_id = iwl3945_get_sta_id(priv, hdr);
2294 if (sta_id == IWL_INVALID_STATION) {
2295 IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n",
2300 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2302 if (ieee80211_is_data_qos(fc)) {
2303 qc = ieee80211_get_qos_ctl(hdr);
2304 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
2305 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
2307 hdr->seq_ctrl = cpu_to_le16(seq_number) |
2309 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
2313 /* Descriptor for chosen Tx queue */
2314 txq = &priv->txq39[txq_id];
2317 spin_lock_irqsave(&priv->lock, flags);
2319 /* Set up first empty TFD within this queue's circular TFD buffer */
2320 tfd = &txq->bd[q->write_ptr];
2321 memset(tfd, 0, sizeof(*tfd));
2322 control_flags = (u32 *) tfd;
2323 idx = get_cmd_index(q, q->write_ptr, 0);
2325 /* Set up driver data for this TFD */
2326 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info));
2327 txq->txb[q->write_ptr].skb[0] = skb;
2329 /* Init first empty entry in queue's array of Tx/cmd buffers */
2330 out_cmd = &txq->cmd[idx];
2331 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
2332 memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
2335 * Set up the Tx-command (not MAC!) header.
2336 * Store the chosen Tx queue and TFD index within the sequence field;
2337 * after Tx, uCode's Tx response will return this value so driver can
2338 * locate the frame within the tx queue and do post-tx processing.
2340 out_cmd->hdr.cmd = REPLY_TX;
2341 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
2342 INDEX_TO_SEQ(q->write_ptr)));
2344 /* Copy MAC header from skb into command buffer */
2345 memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
2348 * Use the first empty entry in this queue's command buffer array
2349 * to contain the Tx command and MAC header concatenated together
2350 * (payload data will be in another buffer).
2351 * Size of this varies, due to varying MAC header length.
2352 * If end is not dword aligned, we'll have 2 extra bytes at the end
2353 * of the MAC header (device reads on dword boundaries).
2354 * We'll tell device about this padding later.
2356 len = sizeof(struct iwl3945_tx_cmd) +
2357 sizeof(struct iwl_cmd_header) + hdr_len;
2360 len = (len + 3) & ~3;
2367 /* Physical address of this Tx command's header (not MAC header!),
2368 * within command buffer array. */
2369 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx +
2370 offsetof(struct iwl_cmd, hdr);
2372 /* Add buffer containing Tx command and MAC(!) header to TFD's
2374 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
2376 if (info->control.hw_key)
2377 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
2379 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2380 * if any (802.11 null frames have no payload). */
2381 len = skb->len - hdr_len;
2383 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
2384 len, PCI_DMA_TODEVICE);
2385 iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
2389 /* If there is no payload, then we use only one Tx buffer */
2390 *control_flags = TFD_CTL_COUNT_SET(1);
2392 /* Else use 2 buffers.
2393 * Tell 3945 about any padding after MAC header */
2394 *control_flags = TFD_CTL_COUNT_SET(2) |
2395 TFD_CTL_PAD_SET(U32_PAD(len));
2397 /* Total # bytes to be transmitted */
2398 len = (u16)skb->len;
2399 out_cmd->cmd.tx.len = cpu_to_le16(len);
2401 /* TODO need this for burst mode later on */
2402 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, unicast, sta_id);
2404 /* set is_hcca to 0; it probably will never be implemented */
2405 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
2407 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
2408 out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
2410 if (!ieee80211_has_morefrags(hdr->frame_control)) {
2411 txq->need_update = 1;
2413 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
2416 txq->need_update = 0;
2419 iwl_print_hex_dump(priv, IWL_DL_TX, out_cmd->cmd.payload,
2420 sizeof(out_cmd->cmd.tx));
2422 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
2423 ieee80211_hdrlen(fc));
2425 /* Tell device the write index *just past* this latest filled TFD */
2426 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
2427 rc = iwl3945_tx_queue_update_write_ptr(priv, txq);
2428 spin_unlock_irqrestore(&priv->lock, flags);
2433 if ((iwl_queue_space(q) < q->high_mark)
2434 && priv->mac80211_registered) {
2435 if (wait_write_ptr) {
2436 spin_lock_irqsave(&priv->lock, flags);
2437 txq->need_update = 1;
2438 iwl3945_tx_queue_update_write_ptr(priv, txq);
2439 spin_unlock_irqrestore(&priv->lock, flags);
2442 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
2448 spin_unlock_irqrestore(&priv->lock, flags);
2453 static void iwl3945_set_rate(struct iwl_priv *priv)
2455 const struct ieee80211_supported_band *sband = NULL;
2456 struct ieee80211_rate *rate;
2459 sband = iwl_get_hw_mode(priv, priv->band);
2461 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
2465 priv->active_rate = 0;
2466 priv->active_rate_basic = 0;
2468 IWL_DEBUG_RATE("Setting rates for %s GHz\n",
2469 sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5");
2471 for (i = 0; i < sband->n_bitrates; i++) {
2472 rate = &sband->bitrates[i];
2473 if ((rate->hw_value < IWL_RATE_COUNT) &&
2474 !(rate->flags & IEEE80211_CHAN_DISABLED)) {
2475 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
2476 rate->hw_value, iwl3945_rates[rate->hw_value].plcp);
2477 priv->active_rate |= (1 << rate->hw_value);
2481 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2482 priv->active_rate, priv->active_rate_basic);
2485 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2486 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2489 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
2490 priv->staging39_rxon.cck_basic_rates =
2491 ((priv->active_rate_basic &
2492 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
2494 priv->staging39_rxon.cck_basic_rates =
2495 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2497 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
2498 priv->staging39_rxon.ofdm_basic_rates =
2499 ((priv->active_rate_basic &
2500 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
2501 IWL_FIRST_OFDM_RATE) & 0xFF;
2503 priv->staging39_rxon.ofdm_basic_rates =
2504 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2507 static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
2509 unsigned long flags;
2511 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
2514 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2515 disable_radio ? "OFF" : "ON");
2517 if (disable_radio) {
2518 iwl3945_scan_cancel(priv);
2519 /* FIXME: This is a workaround for AP */
2520 if (priv->iw_mode != NL80211_IFTYPE_AP) {
2521 spin_lock_irqsave(&priv->lock, flags);
2522 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
2523 CSR_UCODE_SW_BIT_RFKILL);
2524 spin_unlock_irqrestore(&priv->lock, flags);
2525 iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
2526 set_bit(STATUS_RF_KILL_SW, &priv->status);
2531 spin_lock_irqsave(&priv->lock, flags);
2532 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2534 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2535 spin_unlock_irqrestore(&priv->lock, flags);
2540 spin_lock_irqsave(&priv->lock, flags);
2541 iwl_read32(priv, CSR_UCODE_DRV_GP1);
2542 if (!iwl_grab_nic_access(priv))
2543 iwl_release_nic_access(priv);
2544 spin_unlock_irqrestore(&priv->lock, flags);
2546 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
2547 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2548 "disabled by HW switch\n");
2553 queue_work(priv->workqueue, &priv->restart);
2557 void iwl3945_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
2558 u32 decrypt_res, struct ieee80211_rx_status *stats)
2561 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
2563 if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2566 if (!(fc & IEEE80211_FCTL_PROTECTED))
2569 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2570 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2571 case RX_RES_STATUS_SEC_TYPE_TKIP:
2572 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2573 RX_RES_STATUS_BAD_ICV_MIC)
2574 stats->flag |= RX_FLAG_MMIC_ERROR;
2575 case RX_RES_STATUS_SEC_TYPE_WEP:
2576 case RX_RES_STATUS_SEC_TYPE_CCMP:
2577 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2578 RX_RES_STATUS_DECRYPT_OK) {
2579 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2580 stats->flag |= RX_FLAG_DECRYPTED;
2589 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
2591 #include "iwl-spectrum.h"
2593 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2594 #define BEACON_TIME_MASK_HIGH 0xFF000000
2595 #define TIME_UNIT 1024
2598 * extended beacon time format
2599 * time in usec will be changed into a 32-bit value in 8:24 format
2600 * the high 1 byte is the beacon counts
2601 * the lower 3 bytes is the time in usec within one beacon interval
2604 static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
2608 u32 interval = beacon_interval * 1024;
2610 if (!interval || !usec)
2613 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
2614 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
2616 return (quot << 24) + rem;
2619 /* base is usually what we get from ucode with each received frame,
2620 * the same as HW timer counter counting down
2623 static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
2625 u32 base_low = base & BEACON_TIME_MASK_LOW;
2626 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
2627 u32 interval = beacon_interval * TIME_UNIT;
2628 u32 res = (base & BEACON_TIME_MASK_HIGH) +
2629 (addon & BEACON_TIME_MASK_HIGH);
2631 if (base_low > addon_low)
2632 res += base_low - addon_low;
2633 else if (base_low < addon_low) {
2634 res += interval + base_low - addon_low;
2639 return cpu_to_le32(res);
2642 static int iwl3945_get_measurement(struct iwl_priv *priv,
2643 struct ieee80211_measurement_params *params,
2646 struct iwl_spectrum_cmd spectrum;
2647 struct iwl_rx_packet *res;
2648 struct iwl_host_cmd cmd = {
2649 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
2650 .data = (void *)&spectrum,
2651 .meta.flags = CMD_WANT_SKB,
2653 u32 add_time = le64_to_cpu(params->start_time);
2655 int spectrum_resp_status;
2656 int duration = le16_to_cpu(params->duration);
2658 if (iwl3945_is_associated(priv))
2660 iwl3945_usecs_to_beacons(
2661 le64_to_cpu(params->start_time) - priv->last_tsf,
2662 le16_to_cpu(priv->rxon_timing.beacon_interval));
2664 memset(&spectrum, 0, sizeof(spectrum));
2666 spectrum.channel_count = cpu_to_le16(1);
2668 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
2669 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
2670 cmd.len = sizeof(spectrum);
2671 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
2673 if (iwl3945_is_associated(priv))
2674 spectrum.start_time =
2675 iwl3945_add_beacon_time(priv->last_beacon_time,
2677 le16_to_cpu(priv->rxon_timing.beacon_interval));
2679 spectrum.start_time = 0;
2681 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
2682 spectrum.channels[0].channel = params->channel;
2683 spectrum.channels[0].type = type;
2684 if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)
2685 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
2686 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
2688 rc = iwl3945_send_cmd_sync(priv, &cmd);
2692 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
2693 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
2694 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
2698 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
2699 switch (spectrum_resp_status) {
2700 case 0: /* Command will be handled */
2701 if (res->u.spectrum.id != 0xff) {
2702 IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
2703 res->u.spectrum.id);
2704 priv->measurement_status &= ~MEASUREMENT_READY;
2706 priv->measurement_status |= MEASUREMENT_ACTIVE;
2710 case 1: /* Command will not be handled */
2715 dev_kfree_skb_any(cmd.meta.u.skb);
2721 static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
2722 struct iwl_rx_mem_buffer *rxb)
2724 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2725 struct iwl_alive_resp *palive;
2726 struct delayed_work *pwork;
2728 palive = &pkt->u.alive_frame;
2730 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
2732 palive->is_valid, palive->ver_type,
2733 palive->ver_subtype);
2735 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
2736 IWL_DEBUG_INFO("Initialization Alive received.\n");
2737 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
2738 sizeof(struct iwl_alive_resp));
2739 pwork = &priv->init_alive_start;
2741 IWL_DEBUG_INFO("Runtime Alive received.\n");
2742 memcpy(&priv->card_alive, &pkt->u.alive_frame,
2743 sizeof(struct iwl_alive_resp));
2744 pwork = &priv->alive_start;
2745 iwl3945_disable_events(priv);
2748 /* We delay the ALIVE response by 5ms to
2749 * give the HW RF Kill time to activate... */
2750 if (palive->is_valid == UCODE_VALID_OK)
2751 queue_delayed_work(priv->workqueue, pwork,
2752 msecs_to_jiffies(5));
2754 IWL_WARN(priv, "uCode did not respond OK.\n");
2757 static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
2758 struct iwl_rx_mem_buffer *rxb)
2760 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2762 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
2766 static void iwl3945_rx_reply_error(struct iwl_priv *priv,
2767 struct iwl_rx_mem_buffer *rxb)
2769 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2771 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
2772 "seq 0x%04X ser 0x%08X\n",
2773 le32_to_cpu(pkt->u.err_resp.error_type),
2774 get_cmd_string(pkt->u.err_resp.cmd_id),
2775 pkt->u.err_resp.cmd_id,
2776 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
2777 le32_to_cpu(pkt->u.err_resp.error_info));
2780 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2782 static void iwl3945_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
2784 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2785 struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon;
2786 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
2787 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
2788 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
2789 rxon->channel = csa->channel;
2790 priv->staging39_rxon.channel = csa->channel;
2793 static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
2794 struct iwl_rx_mem_buffer *rxb)
2796 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
2797 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2798 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
2800 if (!report->state) {
2801 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
2802 "Spectrum Measure Notification: Start\n");
2806 memcpy(&priv->measure_report, report, sizeof(*report));
2807 priv->measurement_status |= MEASUREMENT_READY;
2811 static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv,
2812 struct iwl_rx_mem_buffer *rxb)
2814 #ifdef CONFIG_IWL3945_DEBUG
2815 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2816 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
2817 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
2818 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
2822 static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
2823 struct iwl_rx_mem_buffer *rxb)
2825 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2826 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
2827 "notification for %s:\n",
2828 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
2829 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw,
2830 le32_to_cpu(pkt->len));
2833 static void iwl3945_bg_beacon_update(struct work_struct *work)
2835 struct iwl_priv *priv =
2836 container_of(work, struct iwl_priv, beacon_update);
2837 struct sk_buff *beacon;
2839 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
2840 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
2843 IWL_ERR(priv, "update beacon failed\n");
2847 mutex_lock(&priv->mutex);
2848 /* new beacon skb is allocated every time; dispose previous.*/
2849 if (priv->ibss_beacon)
2850 dev_kfree_skb(priv->ibss_beacon);
2852 priv->ibss_beacon = beacon;
2853 mutex_unlock(&priv->mutex);
2855 iwl3945_send_beacon_cmd(priv);
2858 static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
2859 struct iwl_rx_mem_buffer *rxb)
2861 #ifdef CONFIG_IWL3945_DEBUG
2862 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2863 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
2864 u8 rate = beacon->beacon_notify_hdr.rate;
2866 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
2867 "tsf %d %d rate %d\n",
2868 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
2869 beacon->beacon_notify_hdr.failure_frame,
2870 le32_to_cpu(beacon->ibss_mgr_status),
2871 le32_to_cpu(beacon->high_tsf),
2872 le32_to_cpu(beacon->low_tsf), rate);
2875 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
2876 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
2877 queue_work(priv->workqueue, &priv->beacon_update);
2880 /* Service response to REPLY_SCAN_CMD (0x80) */
2881 static void iwl3945_rx_reply_scan(struct iwl_priv *priv,
2882 struct iwl_rx_mem_buffer *rxb)
2884 #ifdef CONFIG_IWL3945_DEBUG
2885 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2886 struct iwl_scanreq_notification *notif =
2887 (struct iwl_scanreq_notification *)pkt->u.raw;
2889 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
2893 /* Service SCAN_START_NOTIFICATION (0x82) */
2894 static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv,
2895 struct iwl_rx_mem_buffer *rxb)
2897 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2898 struct iwl_scanstart_notification *notif =
2899 (struct iwl_scanstart_notification *)pkt->u.raw;
2900 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
2901 IWL_DEBUG_SCAN("Scan start: "
2903 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
2905 notif->band ? "bg" : "a",
2907 notif->tsf_low, notif->status, notif->beacon_timer);
2910 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
2911 static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv,
2912 struct iwl_rx_mem_buffer *rxb)
2914 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2915 struct iwl_scanresults_notification *notif =
2916 (struct iwl_scanresults_notification *)pkt->u.raw;
2918 IWL_DEBUG_SCAN("Scan ch.res: "
2920 "(TSF: 0x%08X:%08X) - %d "
2921 "elapsed=%lu usec (%dms since last)\n",
2923 notif->band ? "bg" : "a",
2924 le32_to_cpu(notif->tsf_high),
2925 le32_to_cpu(notif->tsf_low),
2926 le32_to_cpu(notif->statistics[0]),
2927 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
2928 jiffies_to_msecs(elapsed_jiffies
2929 (priv->last_scan_jiffies, jiffies)));
2931 priv->last_scan_jiffies = jiffies;
2932 priv->next_scan_jiffies = 0;
2935 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
2936 static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv,
2937 struct iwl_rx_mem_buffer *rxb)
2939 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2940 struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
2942 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
2943 scan_notif->scanned_channels,
2944 scan_notif->tsf_low,
2945 scan_notif->tsf_high, scan_notif->status);
2947 /* The HW is no longer scanning */
2948 clear_bit(STATUS_SCAN_HW, &priv->status);
2950 /* The scan completion notification came in, so kill that timer... */
2951 cancel_delayed_work(&priv->scan_check);
2953 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
2954 (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
2956 jiffies_to_msecs(elapsed_jiffies
2957 (priv->scan_pass_start, jiffies)));
2959 /* Remove this scanned band from the list of pending
2960 * bands to scan, band G precedes A in order of scanning
2961 * as seen in iwl3945_bg_request_scan */
2962 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
2963 priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
2964 else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ))
2965 priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
2967 /* If a request to abort was given, or the scan did not succeed
2968 * then we reset the scan state machine and terminate,
2969 * re-queuing another scan if one has been requested */
2970 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2971 IWL_DEBUG_INFO("Aborted scan completed.\n");
2972 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
2974 /* If there are more bands on this scan pass reschedule */
2975 if (priv->scan_bands > 0)
2979 priv->last_scan_jiffies = jiffies;
2980 priv->next_scan_jiffies = 0;
2981 IWL_DEBUG_INFO("Setting scan to off\n");
2983 clear_bit(STATUS_SCANNING, &priv->status);
2985 IWL_DEBUG_INFO("Scan took %dms\n",
2986 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
2988 queue_work(priv->workqueue, &priv->scan_completed);
2993 priv->scan_pass_start = jiffies;
2994 queue_work(priv->workqueue, &priv->request_scan);
2997 /* Handle notification from uCode that card's power state is changing
2998 * due to software, hardware, or critical temperature RFKILL */
2999 static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
3000 struct iwl_rx_mem_buffer *rxb)
3002 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
3003 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
3004 unsigned long status = priv->status;
3006 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3007 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
3008 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
3010 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
3011 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3013 if (flags & HW_CARD_DISABLED)
3014 set_bit(STATUS_RF_KILL_HW, &priv->status);
3016 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3019 if (flags & SW_CARD_DISABLED)
3020 set_bit(STATUS_RF_KILL_SW, &priv->status);
3022 clear_bit(STATUS_RF_KILL_SW, &priv->status);
3024 iwl3945_scan_cancel(priv);
3026 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
3027 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
3028 (test_bit(STATUS_RF_KILL_SW, &status) !=
3029 test_bit(STATUS_RF_KILL_SW, &priv->status)))
3030 queue_work(priv->workqueue, &priv->rf_kill);
3032 wake_up_interruptible(&priv->wait_command_queue);
3036 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
3038 * Setup the RX handlers for each of the reply types sent from the uCode
3041 * This function chains into the hardware specific files for them to setup
3042 * any hardware specific handlers as well.
3044 static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
3046 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
3047 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
3048 priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
3049 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
3050 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
3051 iwl3945_rx_spectrum_measure_notif;
3052 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
3053 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
3054 iwl3945_rx_pm_debug_statistics_notif;
3055 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
3058 * The same handler is used for both the REPLY to a discrete
3059 * statistics request from the host as well as for the periodic
3060 * statistics notifications (after received beacons) from the uCode.
3062 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
3063 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
3065 priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
3066 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
3067 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
3068 iwl3945_rx_scan_results_notif;
3069 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
3070 iwl3945_rx_scan_complete_notif;
3071 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
3073 /* Set up hardware specific Rx handlers */
3074 iwl3945_hw_rx_handler_setup(priv);
3078 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
3079 * When FW advances 'R' index, all entries between old and new 'R' index
3080 * need to be reclaimed.
3082 static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
3083 int txq_id, int index)
3085 struct iwl3945_tx_queue *txq = &priv->txq39[txq_id];
3086 struct iwl_queue *q = &txq->q;
3089 if ((index >= q->n_bd) || (iwl3945_x2_queue_used(q, index) == 0)) {
3090 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
3091 "is out of range [0-%d] %d %d.\n", txq_id,
3092 index, q->n_bd, q->write_ptr, q->read_ptr);
3096 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
3097 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
3099 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
3100 q->write_ptr, q->read_ptr);
3101 queue_work(priv->workqueue, &priv->restart);
3110 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3111 * @rxb: Rx buffer to reclaim
3113 * If an Rx buffer has an async callback associated with it the callback
3114 * will be executed. The attached skb (if present) will only be freed
3115 * if the callback returns 1
3117 static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
3118 struct iwl_rx_mem_buffer *rxb)
3120 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
3121 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3122 int txq_id = SEQ_TO_QUEUE(sequence);
3123 int index = SEQ_TO_INDEX(sequence);
3124 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
3126 struct iwl_cmd *cmd;
3128 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
3130 cmd_index = get_cmd_index(&priv->txq39[IWL_CMD_QUEUE_NUM].q, index, huge);
3131 cmd = &priv->txq39[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
3133 /* Input error checking is done when commands are added to queue. */
3134 if (cmd->meta.flags & CMD_WANT_SKB) {
3135 cmd->meta.source->u.skb = rxb->skb;
3137 } else if (cmd->meta.u.callback &&
3138 !cmd->meta.u.callback(priv, cmd, rxb->skb))
3141 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
3143 if (!(cmd->meta.flags & CMD_ASYNC)) {
3144 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3145 wake_up_interruptible(&priv->wait_command_queue);
3149 /************************** RX-FUNCTIONS ****************************/
3151 * Rx theory of operation
3153 * The host allocates 32 DMA target addresses and passes the host address
3154 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
3158 * The host/firmware share two index registers for managing the Rx buffers.
3160 * The READ index maps to the first position that the firmware may be writing
3161 * to -- the driver can read up to (but not including) this position and get
3163 * The READ index is managed by the firmware once the card is enabled.
3165 * The WRITE index maps to the last position the driver has read from -- the
3166 * position preceding WRITE is the last slot the firmware can place a packet.
3168 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3171 * During initialization, the host sets up the READ queue position to the first
3172 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3174 * When the firmware places a packet in a buffer, it will advance the READ index
3175 * and fire the RX interrupt. The driver can then query the READ index and
3176 * process as many packets as possible, moving the WRITE index forward as it
3177 * resets the Rx queue buffers with new memory.
3179 * The management in the driver is as follows:
3180 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3181 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3182 * to replenish the iwl->rxq->rx_free.
3183 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
3184 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3185 * 'processed' and 'read' driver indexes as well)
3186 * + A received packet is processed and handed to the kernel network stack,
3187 * detached from the iwl->rxq. The driver 'processed' index is updated.
3188 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3189 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3190 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3191 * were enough free buffers and RX_STALLED is set it is cleared.
3196 * iwl3945_rx_queue_alloc() Allocates rx_free
3197 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
3198 * iwl3945_rx_queue_restock
3199 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
3200 * queue, updates firmware pointers, and updates
3201 * the WRITE index. If insufficient rx_free buffers
3202 * are available, schedules iwl3945_rx_replenish
3204 * -- enable interrupts --
3205 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
3206 * READ INDEX, detaching the SKB from the pool.
3207 * Moves the packet buffer from queue to rx_used.
3208 * Calls iwl3945_rx_queue_restock to refill any empty
3215 * iwl3945_rx_queue_space - Return number of free slots available in queue.
3217 static int iwl3945_rx_queue_space(const struct iwl_rx_queue *q)
3219 int s = q->read - q->write;
3222 /* keep some buffer to not confuse full and empty queue */
3230 * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3232 int iwl3945_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q)
3236 unsigned long flags;
3238 spin_lock_irqsave(&q->lock, flags);
3240 if (q->need_update == 0)
3243 /* If power-saving is in use, make sure device is awake */
3244 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
3245 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
3247 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
3248 iwl_set_bit(priv, CSR_GP_CNTRL,
3249 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
3253 rc = iwl_grab_nic_access(priv);
3257 /* Device expects a multiple of 8 */
3258 iwl_write_direct32(priv, FH39_RSCSR_CHNL0_WPTR,
3260 iwl_release_nic_access(priv);
3262 /* Else device is assumed to be awake */
3264 /* Device expects a multiple of 8 */
3265 iwl_write32(priv, FH39_RSCSR_CHNL0_WPTR, q->write & ~0x7);
3271 spin_unlock_irqrestore(&q->lock, flags);
3276 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3278 static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
3279 dma_addr_t dma_addr)
3281 return cpu_to_le32((u32)dma_addr);
3285 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
3287 * If there are slots in the RX queue that need to be restocked,
3288 * and we have free pre-allocated buffers, fill the ranks as much
3289 * as we can, pulling from rx_free.
3291 * This moves the 'write' index forward to catch up with 'processed', and
3292 * also updates the memory address in the firmware to reference the new
3295 static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
3297 struct iwl_rx_queue *rxq = &priv->rxq;
3298 struct list_head *element;
3299 struct iwl_rx_mem_buffer *rxb;
3300 unsigned long flags;
3303 spin_lock_irqsave(&rxq->lock, flags);
3304 write = rxq->write & ~0x7;
3305 while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
3306 /* Get next free Rx buffer, remove from free list */
3307 element = rxq->rx_free.next;
3308 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
3311 /* Point to Rx buffer via next RBD in circular buffer */
3312 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
3313 rxq->queue[rxq->write] = rxb;
3314 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
3317 spin_unlock_irqrestore(&rxq->lock, flags);
3318 /* If the pre-allocated buffer pool is dropping low, schedule to
3320 if (rxq->free_count <= RX_LOW_WATERMARK)
3321 queue_work(priv->workqueue, &priv->rx_replenish);
3324 /* If we've added more space for the firmware to place data, tell it.
3325 * Increment device's write pointer in multiples of 8. */
3326 if ((write != (rxq->write & ~0x7))
3327 || (abs(rxq->write - rxq->read) > 7)) {
3328 spin_lock_irqsave(&rxq->lock, flags);
3329 rxq->need_update = 1;
3330 spin_unlock_irqrestore(&rxq->lock, flags);
3331 rc = iwl3945_rx_queue_update_write_ptr(priv, rxq);
3340 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
3342 * When moving to rx_free an SKB is allocated for the slot.
3344 * Also restock the Rx queue via iwl3945_rx_queue_restock.
3345 * This is called as a scheduled work item (except for during initialization)
3347 static void iwl3945_rx_allocate(struct iwl_priv *priv)
3349 struct iwl_rx_queue *rxq = &priv->rxq;
3350 struct list_head *element;
3351 struct iwl_rx_mem_buffer *rxb;
3352 unsigned long flags;
3353 spin_lock_irqsave(&rxq->lock, flags);
3354 while (!list_empty(&rxq->rx_used)) {
3355 element = rxq->rx_used.next;
3356 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
3358 /* Alloc a new receive buffer */
3360 alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC);
3362 if (net_ratelimit())
3363 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
3364 /* We don't reschedule replenish work here -- we will
3365 * call the restock method and if it still needs
3366 * more buffers it will schedule replenish */
3370 /* If radiotap head is required, reserve some headroom here.
3371 * The physical head count is a variable rx_stats->phy_count.
3372 * We reserve 4 bytes here. Plus these extra bytes, the
3373 * headroom of the physical head should be enough for the
3374 * radiotap head that iwl3945 supported. See iwl3945_rt.
3376 skb_reserve(rxb->skb, 4);
3378 priv->alloc_rxb_skb++;
3381 /* Get physical address of RB/SKB */
3382 rxb->real_dma_addr =
3383 pci_map_single(priv->pci_dev, rxb->skb->data,
3384 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3385 list_add_tail(&rxb->list, &rxq->rx_free);
3388 spin_unlock_irqrestore(&rxq->lock, flags);
3392 * this should be called while priv->lock is locked
3394 static void __iwl3945_rx_replenish(void *data)
3396 struct iwl_priv *priv = data;
3398 iwl3945_rx_allocate(priv);
3399 iwl3945_rx_queue_restock(priv);
3403 void iwl3945_rx_replenish(void *data)
3405 struct iwl_priv *priv = data;
3406 unsigned long flags;
3408 iwl3945_rx_allocate(priv);
3410 spin_lock_irqsave(&priv->lock, flags);
3411 iwl3945_rx_queue_restock(priv);
3412 spin_unlock_irqrestore(&priv->lock, flags);
3415 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3416 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3417 * This free routine walks the list of POOL entries and if SKB is set to
3418 * non NULL it is unmapped and freed
3420 static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
3423 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
3424 if (rxq->pool[i].skb != NULL) {
3425 pci_unmap_single(priv->pci_dev,
3426 rxq->pool[i].real_dma_addr,
3427 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3428 dev_kfree_skb(rxq->pool[i].skb);
3432 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
3437 int iwl3945_rx_queue_alloc(struct iwl_priv *priv)
3439 struct iwl_rx_queue *rxq = &priv->rxq;
3440 struct pci_dev *dev = priv->pci_dev;
3443 spin_lock_init(&rxq->lock);
3444 INIT_LIST_HEAD(&rxq->rx_free);
3445 INIT_LIST_HEAD(&rxq->rx_used);
3447 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3448 rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
3452 /* Fill the rx_used queue with _all_ of the Rx buffers */
3453 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
3454 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3456 /* Set us so that we have processed and used all buffers, but have
3457 * not restocked the Rx queue with fresh buffers */
3458 rxq->read = rxq->write = 0;
3459 rxq->free_count = 0;
3460 rxq->need_update = 0;
3464 void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
3466 unsigned long flags;
3468 spin_lock_irqsave(&rxq->lock, flags);
3469 INIT_LIST_HEAD(&rxq->rx_free);
3470 INIT_LIST_HEAD(&rxq->rx_used);
3471 /* Fill the rx_used queue with _all_ of the Rx buffers */
3472 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3473 /* In the reset function, these buffers may have been allocated
3474 * to an SKB, so we need to unmap and free potential storage */
3475 if (rxq->pool[i].skb != NULL) {
3476 pci_unmap_single(priv->pci_dev,
3477 rxq->pool[i].real_dma_addr,
3478 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3479 priv->alloc_rxb_skb--;
3480 dev_kfree_skb(rxq->pool[i].skb);
3481 rxq->pool[i].skb = NULL;
3483 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3486 /* Set us so that we have processed and used all buffers, but have
3487 * not restocked the Rx queue with fresh buffers */
3488 rxq->read = rxq->write = 0;
3489 rxq->free_count = 0;
3490 spin_unlock_irqrestore(&rxq->lock, flags);
3493 /* Convert linear signal-to-noise ratio into dB */
3494 static u8 ratio2dB[100] = {
3495 /* 0 1 2 3 4 5 6 7 8 9 */
3496 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3497 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3498 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3499 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3500 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3501 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
3502 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
3503 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
3504 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
3505 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
3508 /* Calculates a relative dB value from a ratio of linear
3509 * (i.e. not dB) signal levels.
3510 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
3511 int iwl3945_calc_db_from_ratio(int sig_ratio)
3513 /* 1000:1 or higher just report as 60 dB */
3514 if (sig_ratio >= 1000)
3517 /* 100:1 or higher, divide by 10 and use table,
3518 * add 20 dB to make up for divide by 10 */
3519 if (sig_ratio >= 100)
3520 return 20 + (int)ratio2dB[sig_ratio/10];
3522 /* We shouldn't see this */
3526 /* Use table for ratios 1:1 - 99:1 */
3527 return (int)ratio2dB[sig_ratio];
3530 #define PERFECT_RSSI (-20) /* dBm */
3531 #define WORST_RSSI (-95) /* dBm */
3532 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
3534 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
3535 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
3536 * about formulas used below. */
3537 int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
3540 int degradation = PERFECT_RSSI - rssi_dbm;
3542 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
3543 * as indicator; formula is (signal dbm - noise dbm).
3544 * SNR at or above 40 is a great signal (100%).
3545 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
3546 * Weakest usable signal is usually 10 - 15 dB SNR. */
3548 if (rssi_dbm - noise_dbm >= 40)
3550 else if (rssi_dbm < noise_dbm)
3552 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
3554 /* Else use just the signal level.
3555 * This formula is a least squares fit of data points collected and
3556 * compared with a reference system that had a percentage (%) display
3557 * for signal quality. */
3559 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
3560 (15 * RSSI_RANGE + 62 * degradation)) /
3561 (RSSI_RANGE * RSSI_RANGE);
3565 else if (sig_qual < 1)
3572 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
3574 * Uses the priv->rx_handlers callback function array to invoke
3575 * the appropriate handlers, including command responses,
3576 * frame-received notifications, and other notifications.
3578 static void iwl3945_rx_handle(struct iwl_priv *priv)
3580 struct iwl_rx_mem_buffer *rxb;
3581 struct iwl_rx_packet *pkt;
3582 struct iwl_rx_queue *rxq = &priv->rxq;
3585 unsigned long flags;
3589 /* uCode's read index (stored in shared DRAM) indicates the last Rx
3590 * buffer that the driver may process (last buffer filled by ucode). */
3591 r = iwl3945_hw_get_rx_read(priv);
3594 if (iwl3945_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
3596 /* Rx interrupt, but nothing sent from uCode */
3598 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
3601 rxb = rxq->queue[i];
3603 /* If an RXB doesn't have a Rx queue slot associated with it,
3604 * then a bug has been introduced in the queue refilling
3605 * routines -- catch it here */
3606 BUG_ON(rxb == NULL);
3608 rxq->queue[i] = NULL;
3610 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
3612 PCI_DMA_FROMDEVICE);
3613 pkt = (struct iwl_rx_packet *)rxb->skb->data;
3615 /* Reclaim a command buffer only if this packet is a response
3616 * to a (driver-originated) command.
3617 * If the packet (e.g. Rx frame) originated from uCode,
3618 * there is no command buffer to reclaim.
3619 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
3620 * but apparently a few don't get set; catch them here. */
3621 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
3622 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
3623 (pkt->hdr.cmd != REPLY_TX);
3625 /* Based on type of command response or notification,
3626 * handle those that need handling via function in
3627 * rx_handlers table. See iwl3945_setup_rx_handlers() */
3628 if (priv->rx_handlers[pkt->hdr.cmd]) {
3629 IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
3630 "r = %d, i = %d, %s, 0x%02x\n", r, i,
3631 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
3632 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
3634 /* No handling needed */
3635 IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
3636 "r %d i %d No handler needed for %s, 0x%02x\n",
3637 r, i, get_cmd_string(pkt->hdr.cmd),
3642 /* Invoke any callbacks, transfer the skb to caller, and
3643 * fire off the (possibly) blocking iwl3945_send_cmd()
3644 * as we reclaim the driver command queue */
3645 if (rxb && rxb->skb)
3646 iwl3945_tx_cmd_complete(priv, rxb);
3648 IWL_WARN(priv, "Claim null rxb?\n");
3651 /* For now we just don't re-use anything. We can tweak this
3652 * later to try and re-use notification packets and SKBs that
3653 * fail to Rx correctly */
3654 if (rxb->skb != NULL) {
3655 priv->alloc_rxb_skb--;
3656 dev_kfree_skb_any(rxb->skb);
3660 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
3661 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3662 spin_lock_irqsave(&rxq->lock, flags);
3663 list_add_tail(&rxb->list, &priv->rxq.rx_used);
3664 spin_unlock_irqrestore(&rxq->lock, flags);
3665 i = (i + 1) & RX_QUEUE_MASK;
3666 /* If there are a lot of unused frames,
3667 * restock the Rx queue so ucode won't assert. */
3672 __iwl3945_rx_replenish(priv);
3678 /* Backtrack one entry */
3680 iwl3945_rx_queue_restock(priv);
3684 * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware
3686 static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv *priv,
3687 struct iwl3945_tx_queue *txq)
3691 int txq_id = txq->q.id;
3693 if (txq->need_update == 0)
3696 /* if we're trying to save power */
3697 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
3698 /* wake up nic if it's powered down ...
3699 * uCode will wake up, and interrupt us again, so next
3700 * time we'll skip this part. */
3701 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
3703 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
3704 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
3705 iwl_set_bit(priv, CSR_GP_CNTRL,
3706 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
3710 /* restore this queue's parameters in nic hardware. */
3711 rc = iwl_grab_nic_access(priv);
3714 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
3715 txq->q.write_ptr | (txq_id << 8));
3716 iwl_release_nic_access(priv);
3718 /* else not in power-save mode, uCode will never sleep when we're
3719 * trying to tx (during RFKILL, we're not trying to tx). */
3721 iwl_write32(priv, HBUS_TARG_WRPTR,
3722 txq->q.write_ptr | (txq_id << 8));
3724 txq->need_update = 0;
3729 #ifdef CONFIG_IWL3945_DEBUG
3730 static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv,
3731 struct iwl3945_rxon_cmd *rxon)
3733 IWL_DEBUG_RADIO("RX CONFIG:\n");
3734 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
3735 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
3736 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
3737 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
3738 le32_to_cpu(rxon->filter_flags));
3739 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
3740 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
3741 rxon->ofdm_basic_rates);
3742 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
3743 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
3744 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
3745 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
3749 static void iwl3945_enable_interrupts(struct iwl_priv *priv)
3751 IWL_DEBUG_ISR("Enabling interrupts\n");
3752 set_bit(STATUS_INT_ENABLED, &priv->status);
3753 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
3757 /* call this function to flush any scheduled tasklet */
3758 static inline void iwl_synchronize_irq(struct iwl_priv *priv)
3760 /* wait to make sure we flush pending tasklet*/
3761 synchronize_irq(priv->pci_dev->irq);
3762 tasklet_kill(&priv->irq_tasklet);
3766 static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
3768 clear_bit(STATUS_INT_ENABLED, &priv->status);
3770 /* disable interrupts from uCode/NIC to host */
3771 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
3773 /* acknowledge/clear/reset any interrupts still pending
3774 * from uCode or flow handler (Rx/Tx DMA) */
3775 iwl_write32(priv, CSR_INT, 0xffffffff);
3776 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
3777 IWL_DEBUG_ISR("Disabled interrupts\n");
3780 static const char *desc_lookup(int i)
3788 return "BAD_CHECKSUM";
3790 return "NMI_INTERRUPT";
3794 return "FATAL_ERROR";
3800 #define ERROR_START_OFFSET (1 * sizeof(u32))
3801 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
3803 static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
3806 u32 desc, time, count, base, data1;
3807 u32 blink1, blink2, ilink1, ilink2;
3810 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
3812 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
3813 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
3817 rc = iwl_grab_nic_access(priv);
3819 IWL_WARN(priv, "Can not read from adapter at this time.\n");
3823 count = iwl_read_targ_mem(priv, base);
3825 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
3826 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
3827 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
3828 priv->status, count);
3831 IWL_ERR(priv, "Desc Time asrtPC blink2 "
3832 "ilink1 nmiPC Line\n");
3833 for (i = ERROR_START_OFFSET;
3834 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
3835 i += ERROR_ELEM_SIZE) {
3836 desc = iwl_read_targ_mem(priv, base + i);
3838 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
3840 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
3842 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
3844 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
3846 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
3848 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
3851 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
3852 desc_lookup(desc), desc, time, blink1, blink2,
3853 ilink1, ilink2, data1);
3856 iwl_release_nic_access(priv);
3860 #define EVENT_START_OFFSET (6 * sizeof(u32))
3863 * iwl3945_print_event_log - Dump error event log to syslog
3865 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
3867 static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
3868 u32 num_events, u32 mode)
3871 u32 base; /* SRAM byte address of event log header */
3872 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
3873 u32 ptr; /* SRAM byte address of log data */
3874 u32 ev, time, data; /* event log data */
3876 if (num_events == 0)
3879 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
3882 event_size = 2 * sizeof(u32);
3884 event_size = 3 * sizeof(u32);
3886 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
3888 /* "time" is actually "data" for mode 0 (no timestamp).
3889 * place event id # at far right for easier visual parsing. */
3890 for (i = 0; i < num_events; i++) {
3891 ev = iwl_read_targ_mem(priv, ptr);
3893 time = iwl_read_targ_mem(priv, ptr);
3897 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
3899 data = iwl_read_targ_mem(priv, ptr);
3901 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
3906 static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
3909 u32 base; /* SRAM byte address of event log header */
3910 u32 capacity; /* event log capacity in # entries */
3911 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
3912 u32 num_wraps; /* # times uCode wrapped to top of log */
3913 u32 next_entry; /* index of next entry to be written by uCode */
3914 u32 size; /* # entries that we'll print */
3916 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
3917 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
3918 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
3922 rc = iwl_grab_nic_access(priv);
3924 IWL_WARN(priv, "Can not read from adapter at this time.\n");
3928 /* event log header */
3929 capacity = iwl_read_targ_mem(priv, base);
3930 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
3931 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
3932 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
3934 size = num_wraps ? capacity : next_entry;
3936 /* bail out if nothing in log */
3938 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
3939 iwl_release_nic_access(priv);
3943 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
3946 /* if uCode has wrapped back to top of log, start at the oldest entry,
3947 * i.e the next one that uCode would fill. */
3949 iwl3945_print_event_log(priv, next_entry,
3950 capacity - next_entry, mode);
3952 /* (then/else) start at top of log */
3953 iwl3945_print_event_log(priv, 0, next_entry, mode);
3955 iwl_release_nic_access(priv);
3959 * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
3961 static void iwl3945_irq_handle_error(struct iwl_priv *priv)
3963 /* Set the FW error flag -- cleared on iwl3945_down */
3964 set_bit(STATUS_FW_ERROR, &priv->status);
3966 /* Cancel currently queued command. */
3967 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3969 #ifdef CONFIG_IWL3945_DEBUG
3970 if (priv->debug_level & IWL_DL_FW_ERRORS) {
3971 iwl3945_dump_nic_error_log(priv);
3972 iwl3945_dump_nic_event_log(priv);
3973 iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon);
3977 wake_up_interruptible(&priv->wait_command_queue);
3979 /* Keep the restart process from trying to send host
3980 * commands by clearing the INIT status bit */
3981 clear_bit(STATUS_READY, &priv->status);
3983 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3984 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
3985 "Restarting adapter due to uCode error.\n");
3987 if (iwl3945_is_associated(priv)) {
3988 memcpy(&priv->recovery39_rxon, &priv->active39_rxon,
3989 sizeof(priv->recovery39_rxon));
3990 priv->error_recovering = 1;
3992 queue_work(priv->workqueue, &priv->restart);
3996 static void iwl3945_error_recovery(struct iwl_priv *priv)
3998 unsigned long flags;
4000 memcpy(&priv->staging39_rxon, &priv->recovery39_rxon,
4001 sizeof(priv->staging39_rxon));
4002 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4003 iwl3945_commit_rxon(priv);
4005 iwl3945_add_station(priv, priv->bssid, 1, 0);
4007 spin_lock_irqsave(&priv->lock, flags);
4008 priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id);
4009 priv->error_recovering = 0;
4010 spin_unlock_irqrestore(&priv->lock, flags);
4013 static void iwl3945_irq_tasklet(struct iwl_priv *priv)
4015 u32 inta, handled = 0;
4017 unsigned long flags;
4018 #ifdef CONFIG_IWL3945_DEBUG
4022 spin_lock_irqsave(&priv->lock, flags);
4024 /* Ack/clear/reset pending uCode interrupts.
4025 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4026 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4027 inta = iwl_read32(priv, CSR_INT);
4028 iwl_write32(priv, CSR_INT, inta);
4030 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4031 * Any new interrupts that happen after this, either while we're
4032 * in this tasklet, or later, will show up in next ISR/tasklet. */
4033 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
4034 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
4036 #ifdef CONFIG_IWL3945_DEBUG
4037 if (priv->debug_level & IWL_DL_ISR) {
4038 /* just for debug */
4039 inta_mask = iwl_read32(priv, CSR_INT_MASK);
4040 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4041 inta, inta_mask, inta_fh);
4045 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4046 * atomic, make sure that inta covers all the interrupts that
4047 * we've discovered, even if FH interrupt came in just after
4048 * reading CSR_INT. */
4049 if (inta_fh & CSR39_FH_INT_RX_MASK)
4050 inta |= CSR_INT_BIT_FH_RX;
4051 if (inta_fh & CSR39_FH_INT_TX_MASK)
4052 inta |= CSR_INT_BIT_FH_TX;
4054 /* Now service all interrupt bits discovered above. */
4055 if (inta & CSR_INT_BIT_HW_ERR) {
4056 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
4058 /* Tell the device to stop sending interrupts */
4059 iwl3945_disable_interrupts(priv);
4061 iwl3945_irq_handle_error(priv);
4063 handled |= CSR_INT_BIT_HW_ERR;
4065 spin_unlock_irqrestore(&priv->lock, flags);
4070 #ifdef CONFIG_IWL3945_DEBUG
4071 if (priv->debug_level & (IWL_DL_ISR)) {
4072 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4073 if (inta & CSR_INT_BIT_SCD)
4074 IWL_DEBUG_ISR("Scheduler finished to transmit "
4075 "the frame/frames.\n");
4077 /* Alive notification via Rx interrupt will do the real work */
4078 if (inta & CSR_INT_BIT_ALIVE)
4079 IWL_DEBUG_ISR("Alive interrupt\n");
4082 /* Safely ignore these bits for debug checks below */
4083 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
4085 /* Error detected by uCode */
4086 if (inta & CSR_INT_BIT_SW_ERR) {
4087 IWL_ERR(priv, "Microcode SW error detected. "
4088 "Restarting 0x%X.\n", inta);
4089 iwl3945_irq_handle_error(priv);
4090 handled |= CSR_INT_BIT_SW_ERR;
4093 /* uCode wakes up after power-down sleep */
4094 if (inta & CSR_INT_BIT_WAKEUP) {
4095 IWL_DEBUG_ISR("Wakeup interrupt\n");
4096 iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq);
4097 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[0]);
4098 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[1]);
4099 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[2]);
4100 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[3]);
4101 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[4]);
4102 iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[5]);
4104 handled |= CSR_INT_BIT_WAKEUP;
4107 /* All uCode command responses, including Tx command responses,
4108 * Rx "responses" (frame-received notification), and other
4109 * notifications from uCode come through here*/
4110 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
4111 iwl3945_rx_handle(priv);
4112 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
4115 if (inta & CSR_INT_BIT_FH_TX) {
4116 IWL_DEBUG_ISR("Tx interrupt\n");
4118 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
4119 if (!iwl_grab_nic_access(priv)) {
4120 iwl_write_direct32(priv, FH39_TCSR_CREDIT
4121 (FH39_SRVC_CHNL), 0x0);
4122 iwl_release_nic_access(priv);
4124 handled |= CSR_INT_BIT_FH_TX;
4127 if (inta & ~handled)
4128 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
4130 if (inta & ~CSR_INI_SET_MASK) {
4131 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
4132 inta & ~CSR_INI_SET_MASK);
4133 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
4136 /* Re-enable all interrupts */
4137 /* only Re-enable if disabled by irq */
4138 if (test_bit(STATUS_INT_ENABLED, &priv->status))
4139 iwl3945_enable_interrupts(priv);
4141 #ifdef CONFIG_IWL3945_DEBUG
4142 if (priv->debug_level & (IWL_DL_ISR)) {
4143 inta = iwl_read32(priv, CSR_INT);
4144 inta_mask = iwl_read32(priv, CSR_INT_MASK);
4145 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
4146 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4147 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
4150 spin_unlock_irqrestore(&priv->lock, flags);
4153 static irqreturn_t iwl3945_isr(int irq, void *data)
4155 struct iwl_priv *priv = data;
4156 u32 inta, inta_mask;
4161 spin_lock(&priv->lock);
4163 /* Disable (but don't clear!) interrupts here to avoid
4164 * back-to-back ISRs and sporadic interrupts from our NIC.
4165 * If we have something to service, the tasklet will re-enable ints.
4166 * If we *don't* have something, we'll re-enable before leaving here. */
4167 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
4168 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
4170 /* Discover which interrupts are active/pending */
4171 inta = iwl_read32(priv, CSR_INT);
4172 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
4174 /* Ignore interrupt if there's nothing in NIC to service.
4175 * This may be due to IRQ shared with another device,
4176 * or due to sporadic interrupts thrown from our NIC. */
4177 if (!inta && !inta_fh) {
4178 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4182 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
4183 /* Hardware disappeared */
4184 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
4188 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4189 inta, inta_mask, inta_fh);
4191 inta &= ~CSR_INT_BIT_SCD;
4193 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
4194 if (likely(inta || inta_fh))
4195 tasklet_schedule(&priv->irq_tasklet);
4197 spin_unlock(&priv->lock);
4202 /* re-enable interrupts here since we don't have anything to service. */
4203 /* only Re-enable if disabled by irq */
4204 if (test_bit(STATUS_INT_ENABLED, &priv->status))
4205 iwl3945_enable_interrupts(priv);
4206 spin_unlock(&priv->lock);
4210 /************************** EEPROM BANDS ****************************
4212 * The iwl3945_eeprom_band definitions below provide the mapping from the
4213 * EEPROM contents to the specific channel number supported for each
4216 * For example, iwl3945_priv->eeprom39.band_3_channels[4] from the band_3
4217 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
4218 * The specific geography and calibration information for that channel
4219 * is contained in the eeprom map itself.
4221 * During init, we copy the eeprom information and channel map
4222 * information into priv->channel_info_24/52 and priv->channel_map_24/52
4224 * channel_map_24/52 provides the index in the channel_info array for a
4225 * given channel. We have to have two separate maps as there is channel
4226 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
4229 * A value of 0xff stored in the channel_map indicates that the channel
4230 * is not supported by the hardware at all.
4232 * A value of 0xfe in the channel_map indicates that the channel is not
4233 * valid for Tx with the current hardware. This means that
4234 * while the system can tune and receive on a given channel, it may not
4235 * be able to associate or transmit any frames on that
4236 * channel. There is no corresponding channel information for that
4239 *********************************************************************/
4242 static const u8 iwl3945_eeprom_band_1[14] = {
4243 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
4247 static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */
4248 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
4251 static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */
4252 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
4255 static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */
4256 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
4259 static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */
4260 145, 149, 153, 157, 161, 165
4263 static void iwl3945_init_band_reference(const struct iwl_priv *priv, int band,
4264 int *eeprom_ch_count,
4265 const struct iwl_eeprom_channel
4267 const u8 **eeprom_ch_index)
4270 case 1: /* 2.4GHz band */
4271 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1);
4272 *eeprom_ch_info = priv->eeprom39.band_1_channels;
4273 *eeprom_ch_index = iwl3945_eeprom_band_1;
4275 case 2: /* 4.9GHz band */
4276 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2);
4277 *eeprom_ch_info = priv->eeprom39.band_2_channels;
4278 *eeprom_ch_index = iwl3945_eeprom_band_2;
4280 case 3: /* 5.2GHz band */
4281 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3);
4282 *eeprom_ch_info = priv->eeprom39.band_3_channels;
4283 *eeprom_ch_index = iwl3945_eeprom_band_3;
4285 case 4: /* 5.5GHz band */
4286 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4);
4287 *eeprom_ch_info = priv->eeprom39.band_4_channels;
4288 *eeprom_ch_index = iwl3945_eeprom_band_4;
4290 case 5: /* 5.7GHz band */
4291 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5);
4292 *eeprom_ch_info = priv->eeprom39.band_5_channels;
4293 *eeprom_ch_index = iwl3945_eeprom_band_5;
4302 * iwl3945_get_channel_info - Find driver's private channel info
4304 * Based on band and channel number.
4306 const struct iwl_channel_info *
4307 iwl3945_get_channel_info(const struct iwl_priv *priv,
4308 enum ieee80211_band band, u16 channel)
4313 case IEEE80211_BAND_5GHZ:
4314 for (i = 14; i < priv->channel_count; i++) {
4315 if (priv->channel_info[i].channel == channel)
4316 return &priv->channel_info[i];
4320 case IEEE80211_BAND_2GHZ:
4321 if (channel >= 1 && channel <= 14)
4322 return &priv->channel_info[channel - 1];
4324 case IEEE80211_NUM_BANDS:
4331 #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
4335 * iwl3945_init_channel_map - Set up driver's info for all possible channels
4337 static int iwl3945_init_channel_map(struct iwl_priv *priv)
4339 int eeprom_ch_count = 0;
4340 const u8 *eeprom_ch_index = NULL;
4341 const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
4343 struct iwl_channel_info *ch_info;
4345 if (priv->channel_count) {
4346 IWL_DEBUG_INFO("Channel map already initialized.\n");
4350 if (priv->eeprom39.version < 0x2f) {
4351 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
4352 priv->eeprom39.version);
4356 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
4358 priv->channel_count =
4359 ARRAY_SIZE(iwl3945_eeprom_band_1) +
4360 ARRAY_SIZE(iwl3945_eeprom_band_2) +
4361 ARRAY_SIZE(iwl3945_eeprom_band_3) +
4362 ARRAY_SIZE(iwl3945_eeprom_band_4) +
4363 ARRAY_SIZE(iwl3945_eeprom_band_5);
4365 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
4367 priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) *
4368 priv->channel_count, GFP_KERNEL);
4369 if (!priv->channel_info) {
4370 IWL_ERR(priv, "Could not allocate channel_info\n");
4371 priv->channel_count = 0;
4375 ch_info = priv->channel_info;
4377 /* Loop through the 5 EEPROM bands adding them in order to the
4378 * channel map we maintain (that contains additional information than
4379 * what just in the EEPROM) */
4380 for (band = 1; band <= 5; band++) {
4382 iwl3945_init_band_reference(priv, band, &eeprom_ch_count,
4383 &eeprom_ch_info, &eeprom_ch_index);
4385 /* Loop through each band adding each of the channels */
4386 for (ch = 0; ch < eeprom_ch_count; ch++) {
4387 ch_info->channel = eeprom_ch_index[ch];
4388 ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
4389 IEEE80211_BAND_5GHZ;
4391 /* permanently store EEPROM's channel regulatory flags
4392 * and max power in channel info database. */
4393 ch_info->eeprom = eeprom_ch_info[ch];
4395 /* Copy the run-time flags so they are there even on
4396 * invalid channels */
4397 ch_info->flags = eeprom_ch_info[ch].flags;
4399 if (!(is_channel_valid(ch_info))) {
4400 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
4404 is_channel_a_band(ch_info) ?
4410 /* Initialize regulatory-based run-time data */
4411 ch_info->max_power_avg = ch_info->curr_txpow =
4412 eeprom_ch_info[ch].max_power_avg;
4413 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
4414 ch_info->min_power = 0;
4416 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
4417 " %ddBm): Ad-Hoc %ssupported\n",
4419 is_channel_a_band(ch_info) ?
4421 CHECK_AND_PRINT(VALID),
4422 CHECK_AND_PRINT(IBSS),
4423 CHECK_AND_PRINT(ACTIVE),
4424 CHECK_AND_PRINT(RADAR),
4425 CHECK_AND_PRINT(WIDE),
4426 CHECK_AND_PRINT(DFS),
4427 eeprom_ch_info[ch].flags,
4428 eeprom_ch_info[ch].max_power_avg,
4429 ((eeprom_ch_info[ch].
4430 flags & EEPROM_CHANNEL_IBSS)
4431 && !(eeprom_ch_info[ch].
4432 flags & EEPROM_CHANNEL_RADAR))
4435 /* Set the user_txpower_limit to the highest power
4436 * supported by any channel */
4437 if (eeprom_ch_info[ch].max_power_avg >
4438 priv->user_txpower_limit)
4439 priv->user_txpower_limit =
4440 eeprom_ch_info[ch].max_power_avg;
4446 /* Set up txpower settings in driver for all channels */
4447 if (iwl3945_txpower_set_from_eeprom(priv))
4454 * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map
4456 static void iwl3945_free_channel_map(struct iwl_priv *priv)
4458 kfree(priv->channel_info);
4459 priv->channel_count = 0;
4462 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4463 * sending probe req. This should be set long enough to hear probe responses
4464 * from more than one AP. */
4465 #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */
4466 #define IWL_ACTIVE_DWELL_TIME_52 (20)
4468 #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
4469 #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
4471 /* For faster active scanning, scan will move to the next channel if fewer than
4472 * PLCP_QUIET_THRESH packets are heard on this channel within
4473 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4474 * time if it's a quiet channel (nothing responded to our probe, and there's
4475 * no other traffic).
4476 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4477 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4478 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */
4480 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4481 * Must be set longer than active dwell time.
4482 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4483 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4484 #define IWL_PASSIVE_DWELL_TIME_52 (10)
4485 #define IWL_PASSIVE_DWELL_BASE (100)
4486 #define IWL_CHANNEL_TUNE_TIME 5
4488 #define IWL_SCAN_PROBE_MASK(n) (BIT(n) | (BIT(n) - BIT(1)))
4490 static inline u16 iwl3945_get_active_dwell_time(struct iwl_priv *priv,
4491 enum ieee80211_band band,
4494 if (band == IEEE80211_BAND_5GHZ)
4495 return IWL_ACTIVE_DWELL_TIME_52 +
4496 IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1);
4498 return IWL_ACTIVE_DWELL_TIME_24 +
4499 IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1);
4502 static u16 iwl3945_get_passive_dwell_time(struct iwl_priv *priv,
4503 enum ieee80211_band band)
4505 u16 passive = (band == IEEE80211_BAND_2GHZ) ?
4506 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
4507 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
4509 if (iwl3945_is_associated(priv)) {
4510 /* If we're associated, we clamp the maximum passive
4511 * dwell time to be 98% of the beacon interval (minus
4512 * 2 * channel tune time) */
4513 passive = priv->beacon_int;
4514 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
4515 passive = IWL_PASSIVE_DWELL_BASE;
4516 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
4522 static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
4523 enum ieee80211_band band,
4524 u8 is_active, u8 n_probes,
4525 struct iwl3945_scan_channel *scan_ch)
4527 const struct ieee80211_channel *channels = NULL;
4528 const struct ieee80211_supported_band *sband;
4529 const struct iwl_channel_info *ch_info;
4530 u16 passive_dwell = 0;
4531 u16 active_dwell = 0;
4534 sband = iwl_get_hw_mode(priv, band);
4538 channels = sband->channels;
4540 active_dwell = iwl3945_get_active_dwell_time(priv, band, n_probes);
4541 passive_dwell = iwl3945_get_passive_dwell_time(priv, band);
4543 if (passive_dwell <= active_dwell)
4544 passive_dwell = active_dwell + 1;
4546 for (i = 0, added = 0; i < sband->n_channels; i++) {
4547 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
4550 scan_ch->channel = channels[i].hw_value;
4552 ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel);
4553 if (!is_channel_valid(ch_info)) {
4554 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
4559 scan_ch->active_dwell = cpu_to_le16(active_dwell);
4560 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
4561 /* If passive , set up for auto-switch
4562 * and use long active_dwell time.
4564 if (!is_active || is_channel_passive(ch_info) ||
4565 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
4566 scan_ch->type = 0; /* passive */
4567 if (IWL_UCODE_API(priv->ucode_ver) == 1)
4568 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
4570 scan_ch->type = 1; /* active */
4573 /* Set direct probe bits. These may be used both for active
4574 * scan channels (probes gets sent right away),
4575 * or for passive channels (probes get se sent only after
4576 * hearing clear Rx packet).*/
4577 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
4579 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
4581 /* uCode v1 does not allow setting direct probe bits on
4582 * passive channel. */
4583 if ((scan_ch->type & 1) && n_probes)
4584 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
4587 /* Set txpower levels to defaults */
4588 scan_ch->tpc.dsp_atten = 110;
4589 /* scan_pwr_info->tpc.dsp_atten; */
4591 /*scan_pwr_info->tpc.tx_gain; */
4592 if (band == IEEE80211_BAND_5GHZ)
4593 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
4595 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
4596 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4598 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4602 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4604 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
4605 (scan_ch->type & 1) ?
4606 active_dwell : passive_dwell);
4612 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
4616 static void iwl3945_init_hw_rates(struct iwl_priv *priv,
4617 struct ieee80211_rate *rates)
4621 for (i = 0; i < IWL_RATE_COUNT; i++) {
4622 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
4623 rates[i].hw_value = i; /* Rate scaling will work on indexes */
4624 rates[i].hw_value_short = i;
4626 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
4628 * If CCK != 1M then set short preamble rate flag.
4630 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
4631 0 : IEEE80211_RATE_SHORT_PREAMBLE;
4637 * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
4639 static int iwl3945_init_geos(struct iwl_priv *priv)
4641 struct iwl_channel_info *ch;
4642 struct ieee80211_supported_band *sband;
4643 struct ieee80211_channel *channels;
4644 struct ieee80211_channel *geo_ch;
4645 struct ieee80211_rate *rates;
4648 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
4649 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
4650 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4651 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
4655 channels = kzalloc(sizeof(struct ieee80211_channel) *
4656 priv->channel_count, GFP_KERNEL);
4660 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
4667 /* 5.2GHz channels start after the 2.4GHz channels */
4668 sband = &priv->bands[IEEE80211_BAND_5GHZ];
4669 sband->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)];
4671 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
4672 sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
4674 sband = &priv->bands[IEEE80211_BAND_2GHZ];
4675 sband->channels = channels;
4677 sband->bitrates = rates;
4678 sband->n_bitrates = IWL_RATE_COUNT;
4680 priv->ieee_channels = channels;
4681 priv->ieee_rates = rates;
4683 iwl3945_init_hw_rates(priv, rates);
4685 for (i = 0; i < priv->channel_count; i++) {
4686 ch = &priv->channel_info[i];
4688 /* FIXME: might be removed if scan is OK*/
4689 if (!is_channel_valid(ch))
4692 if (is_channel_a_band(ch))
4693 sband = &priv->bands[IEEE80211_BAND_5GHZ];
4695 sband = &priv->bands[IEEE80211_BAND_2GHZ];
4697 geo_ch = &sband->channels[sband->n_channels++];
4699 geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
4700 geo_ch->max_power = ch->max_power_avg;
4701 geo_ch->max_antenna_gain = 0xff;
4702 geo_ch->hw_value = ch->channel;
4704 if (is_channel_valid(ch)) {
4705 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
4706 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
4708 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
4709 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
4711 if (ch->flags & EEPROM_CHANNEL_RADAR)
4712 geo_ch->flags |= IEEE80211_CHAN_RADAR;
4714 if (ch->max_power_avg > priv->max_channel_txpower_limit)
4715 priv->max_channel_txpower_limit =
4718 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
4721 /* Save flags for reg domain usage */
4722 geo_ch->orig_flags = geo_ch->flags;
4724 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4725 ch->channel, geo_ch->center_freq,
4726 is_channel_a_band(ch) ? "5.2" : "2.4",
4727 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
4728 "restricted" : "valid",
4732 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
4733 priv->cfg->sku & IWL_SKU_A) {
4734 IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
4735 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
4736 priv->pci_dev->device, priv->pci_dev->subsystem_device);
4737 priv->cfg->sku &= ~IWL_SKU_A;
4740 IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
4741 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
4742 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
4744 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4745 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4746 &priv->bands[IEEE80211_BAND_2GHZ];
4747 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
4748 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4749 &priv->bands[IEEE80211_BAND_5GHZ];
4751 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
4757 * iwl3945_free_geos - undo allocations in iwl3945_init_geos
4759 static void iwl3945_free_geos(struct iwl_priv *priv)
4761 kfree(priv->ieee_channels);
4762 kfree(priv->ieee_rates);
4763 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
4766 /******************************************************************************
4768 * uCode download functions
4770 ******************************************************************************/
4772 static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
4774 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
4775 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
4776 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
4777 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
4778 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
4779 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
4783 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
4784 * looking at all data.
4786 static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
4793 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
4795 rc = iwl_grab_nic_access(priv);
4799 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
4800 IWL39_RTC_INST_LOWER_BOUND);
4803 for (; len > 0; len -= sizeof(u32), image++) {
4804 /* read data comes through single port, auto-incr addr */
4805 /* NOTE: Use the debugless read so we don't flood kernel log
4806 * if IWL_DL_IO is set */
4807 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
4808 if (val != le32_to_cpu(*image)) {
4809 IWL_ERR(priv, "uCode INST section is invalid at "
4810 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4811 save_len - len, val, le32_to_cpu(*image));
4819 iwl_release_nic_access(priv);
4822 IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
4829 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
4830 * using sample data 100 bytes apart. If these sample points are good,
4831 * it's a pretty good bet that everything between them is good, too.
4833 static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
4840 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
4842 rc = iwl_grab_nic_access(priv);
4846 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
4847 /* read data comes through single port, auto-incr addr */
4848 /* NOTE: Use the debugless read so we don't flood kernel log
4849 * if IWL_DL_IO is set */
4850 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
4851 i + IWL39_RTC_INST_LOWER_BOUND);
4852 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
4853 if (val != le32_to_cpu(*image)) {
4854 #if 0 /* Enable this if you want to see details */
4855 IWL_ERR(priv, "uCode INST section is invalid at "
4856 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4866 iwl_release_nic_access(priv);
4873 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
4874 * and verify its contents
4876 static int iwl3945_verify_ucode(struct iwl_priv *priv)
4883 image = (__le32 *)priv->ucode_boot.v_addr;
4884 len = priv->ucode_boot.len;
4885 rc = iwl3945_verify_inst_sparse(priv, image, len);
4887 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
4891 /* Try initialize */
4892 image = (__le32 *)priv->ucode_init.v_addr;
4893 len = priv->ucode_init.len;
4894 rc = iwl3945_verify_inst_sparse(priv, image, len);
4896 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
4900 /* Try runtime/protocol */
4901 image = (__le32 *)priv->ucode_code.v_addr;
4902 len = priv->ucode_code.len;
4903 rc = iwl3945_verify_inst_sparse(priv, image, len);
4905 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
4909 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
4911 /* Since nothing seems to match, show first several data entries in
4912 * instruction SRAM, so maybe visual inspection will give a clue.
4913 * Selection of bootstrap image (vs. other images) is arbitrary. */
4914 image = (__le32 *)priv->ucode_boot.v_addr;
4915 len = priv->ucode_boot.len;
4916 rc = iwl3945_verify_inst_full(priv, image, len);
4921 static void iwl3945_nic_start(struct iwl_priv *priv)
4923 /* Remove all resets to allow NIC to operate */
4924 iwl_write32(priv, CSR_RESET, 0);
4928 * iwl3945_read_ucode - Read uCode images from disk file.
4930 * Copy into buffers for card to fetch via bus-mastering
4932 static int iwl3945_read_ucode(struct iwl_priv *priv)
4934 struct iwl_ucode *ucode;
4935 int ret = -EINVAL, index;
4936 const struct firmware *ucode_raw;
4937 /* firmware file name contains uCode/driver compatibility version */
4938 const char *name_pre = priv->cfg->fw_name_pre;
4939 const unsigned int api_max = priv->cfg->ucode_api_max;
4940 const unsigned int api_min = priv->cfg->ucode_api_min;
4944 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
4946 /* Ask kernel firmware_class module to get the boot firmware off disk.
4947 * request_firmware() is synchronous, file is in memory on return. */
4948 for (index = api_max; index >= api_min; index--) {
4949 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
4950 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
4952 IWL_ERR(priv, "%s firmware file req failed: %d\n",
4959 if (index < api_max)
4960 IWL_ERR(priv, "Loaded firmware %s, "
4961 "which is deprecated. "
4962 " Please use API v%u instead.\n",
4964 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
4965 buf, ucode_raw->size);
4973 /* Make sure that we got at least our header! */
4974 if (ucode_raw->size < sizeof(*ucode)) {
4975 IWL_ERR(priv, "File size way too small!\n");
4980 /* Data from ucode file: header followed by uCode images */
4981 ucode = (void *)ucode_raw->data;
4983 priv->ucode_ver = le32_to_cpu(ucode->ver);
4984 api_ver = IWL_UCODE_API(priv->ucode_ver);
4985 inst_size = le32_to_cpu(ucode->inst_size);
4986 data_size = le32_to_cpu(ucode->data_size);
4987 init_size = le32_to_cpu(ucode->init_size);
4988 init_data_size = le32_to_cpu(ucode->init_data_size);
4989 boot_size = le32_to_cpu(ucode->boot_size);
4991 /* api_ver should match the api version forming part of the
4992 * firmware filename ... but we don't check for that and only rely
4993 * on the API version read from firware header from here on forward */
4995 if (api_ver < api_min || api_ver > api_max) {
4996 IWL_ERR(priv, "Driver unable to support your firmware API. "
4997 "Driver supports v%u, firmware is v%u.\n",
4999 priv->ucode_ver = 0;
5003 if (api_ver != api_max)
5004 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
5005 "got %u. New firmware can be obtained "
5006 "from http://www.intellinuxwireless.org.\n",
5009 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
5010 IWL_UCODE_MAJOR(priv->ucode_ver),
5011 IWL_UCODE_MINOR(priv->ucode_ver),
5012 IWL_UCODE_API(priv->ucode_ver),
5013 IWL_UCODE_SERIAL(priv->ucode_ver));
5015 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
5017 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
5018 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
5019 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
5020 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
5021 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
5024 /* Verify size of file vs. image size info in file's header */
5025 if (ucode_raw->size < sizeof(*ucode) +
5026 inst_size + data_size + init_size +
5027 init_data_size + boot_size) {
5029 IWL_DEBUG_INFO("uCode file size %d too small\n",
5030 (int)ucode_raw->size);
5035 /* Verify that uCode images will fit in card's SRAM */
5036 if (inst_size > IWL39_MAX_INST_SIZE) {
5037 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5043 if (data_size > IWL39_MAX_DATA_SIZE) {
5044 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5049 if (init_size > IWL39_MAX_INST_SIZE) {
5050 IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
5055 if (init_data_size > IWL39_MAX_DATA_SIZE) {
5056 IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
5061 if (boot_size > IWL39_MAX_BSM_SIZE) {
5062 IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
5068 /* Allocate ucode buffers for card's bus-master loading ... */
5070 /* Runtime instructions and 2 copies of data:
5071 * 1) unmodified from disk
5072 * 2) backup cache for save/restore during power-downs */
5073 priv->ucode_code.len = inst_size;
5074 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
5076 priv->ucode_data.len = data_size;
5077 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
5079 priv->ucode_data_backup.len = data_size;
5080 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
5082 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
5083 !priv->ucode_data_backup.v_addr)
5086 /* Initialization instructions and data */
5087 if (init_size && init_data_size) {
5088 priv->ucode_init.len = init_size;
5089 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
5091 priv->ucode_init_data.len = init_data_size;
5092 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
5094 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
5098 /* Bootstrap (instructions only, no data) */
5100 priv->ucode_boot.len = boot_size;
5101 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
5103 if (!priv->ucode_boot.v_addr)
5107 /* Copy images into buffers for card's bus-master reads ... */
5109 /* Runtime instructions (first block of data in file) */
5110 src = &ucode->data[0];
5111 len = priv->ucode_code.len;
5112 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
5113 memcpy(priv->ucode_code.v_addr, src, len);
5114 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5115 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
5117 /* Runtime data (2nd block)
5118 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
5119 src = &ucode->data[inst_size];
5120 len = priv->ucode_data.len;
5121 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
5122 memcpy(priv->ucode_data.v_addr, src, len);
5123 memcpy(priv->ucode_data_backup.v_addr, src, len);
5125 /* Initialization instructions (3rd block) */
5127 src = &ucode->data[inst_size + data_size];
5128 len = priv->ucode_init.len;
5129 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5131 memcpy(priv->ucode_init.v_addr, src, len);
5134 /* Initialization data (4th block) */
5135 if (init_data_size) {
5136 src = &ucode->data[inst_size + data_size + init_size];
5137 len = priv->ucode_init_data.len;
5138 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
5140 memcpy(priv->ucode_init_data.v_addr, src, len);
5143 /* Bootstrap instructions (5th block) */
5144 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
5145 len = priv->ucode_boot.len;
5146 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
5148 memcpy(priv->ucode_boot.v_addr, src, len);
5150 /* We have our copies now, allow OS release its copies */
5151 release_firmware(ucode_raw);
5155 IWL_ERR(priv, "failed to allocate pci memory\n");
5157 iwl3945_dealloc_ucode_pci(priv);
5160 release_firmware(ucode_raw);
5168 * iwl3945_set_ucode_ptrs - Set uCode address location
5170 * Tell initialization uCode where to find runtime uCode.
5172 * BSM registers initially contain pointers to initialization uCode.
5173 * We need to replace them to load runtime uCode inst and data,
5174 * and to save runtime data when powering down.
5176 static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
5181 unsigned long flags;
5183 /* bits 31:0 for 3945 */
5184 pinst = priv->ucode_code.p_addr;
5185 pdata = priv->ucode_data_backup.p_addr;
5187 spin_lock_irqsave(&priv->lock, flags);
5188 rc = iwl_grab_nic_access(priv);
5190 spin_unlock_irqrestore(&priv->lock, flags);
5194 /* Tell bootstrap uCode where to find image to load */
5195 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
5196 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
5197 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
5198 priv->ucode_data.len);
5200 /* Inst byte count must be last to set up, bit 31 signals uCode
5201 * that all new ptr/size info is in place */
5202 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
5203 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
5205 iwl_release_nic_access(priv);
5207 spin_unlock_irqrestore(&priv->lock, flags);
5209 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5215 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
5217 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5219 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5221 static void iwl3945_init_alive_start(struct iwl_priv *priv)
5223 /* Check alive response for "valid" sign from uCode */
5224 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
5225 /* We had an error bringing up the hardware, so take it
5226 * all the way back down so we can try again */
5227 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5231 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5232 * This is a paranoid check, because we would not have gotten the
5233 * "initialize" alive if code weren't properly loaded. */
5234 if (iwl3945_verify_ucode(priv)) {
5235 /* Runtime instruction load was bad;
5236 * take it all the way back down so we can try again */
5237 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5241 /* Send pointers to protocol/runtime uCode image ... init code will
5242 * load and launch runtime uCode, which will send us another "Alive"
5244 IWL_DEBUG_INFO("Initialization Alive received.\n");
5245 if (iwl3945_set_ucode_ptrs(priv)) {
5246 /* Runtime instruction load won't happen;
5247 * take it all the way back down so we can try again */
5248 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5254 queue_work(priv->workqueue, &priv->restart);
5259 static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
5260 struct sk_buff *skb);
5263 * iwl3945_alive_start - called after REPLY_ALIVE notification received
5264 * from protocol/runtime uCode (initialization uCode's
5265 * Alive gets handled by iwl3945_init_alive_start()).
5267 static void iwl3945_alive_start(struct iwl_priv *priv)
5270 int thermal_spin = 0;
5273 IWL_DEBUG_INFO("Runtime Alive received.\n");
5275 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
5276 /* We had an error bringing up the hardware, so take it
5277 * all the way back down so we can try again */
5278 IWL_DEBUG_INFO("Alive failed.\n");
5282 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5283 * This is a paranoid check, because we would not have gotten the
5284 * "runtime" alive if code weren't properly loaded. */
5285 if (iwl3945_verify_ucode(priv)) {
5286 /* Runtime instruction load was bad;
5287 * take it all the way back down so we can try again */
5288 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5292 iwl3945_clear_stations_table(priv);
5294 rc = iwl_grab_nic_access(priv);
5296 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
5300 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
5301 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
5302 iwl_release_nic_access(priv);
5305 clear_bit(STATUS_RF_KILL_HW, &priv->status);
5306 /* if RFKILL is not on, then wait for thermal
5307 * sensor in adapter to kick in */
5308 while (iwl3945_hw_get_temperature(priv) == 0) {
5314 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
5317 set_bit(STATUS_RF_KILL_HW, &priv->status);
5319 /* After the ALIVE response, we can send commands to 3945 uCode */
5320 set_bit(STATUS_ALIVE, &priv->status);
5322 /* Clear out the uCode error bit if it is set */
5323 clear_bit(STATUS_FW_ERROR, &priv->status);
5325 if (iwl_is_rfkill(priv))
5328 ieee80211_wake_queues(priv->hw);
5330 priv->active_rate = priv->rates_mask;
5331 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
5333 iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
5335 if (iwl3945_is_associated(priv)) {
5336 struct iwl3945_rxon_cmd *active_rxon =
5337 (struct iwl3945_rxon_cmd *)(&priv->active39_rxon);
5339 memcpy(&priv->staging39_rxon, &priv->active39_rxon,
5340 sizeof(priv->staging39_rxon));
5341 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
5343 /* Initialize our rx_config data */
5344 iwl3945_connection_init_rx_config(priv, priv->iw_mode);
5345 memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
5348 /* Configure Bluetooth device coexistence support */
5349 iwl3945_send_bt_config(priv);
5351 /* Configure the adapter for unassociated operation */
5352 iwl3945_commit_rxon(priv);
5354 iwl3945_reg_txpower_periodic(priv);
5356 iwl3945_led_register(priv);
5358 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5359 set_bit(STATUS_READY, &priv->status);
5360 wake_up_interruptible(&priv->wait_command_queue);
5362 if (priv->error_recovering)
5363 iwl3945_error_recovery(priv);
5365 /* reassociate for ADHOC mode */
5366 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
5367 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
5370 iwl3945_mac_beacon_update(priv->hw, beacon);
5376 queue_work(priv->workqueue, &priv->restart);
5379 static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
5381 static void __iwl3945_down(struct iwl_priv *priv)
5383 unsigned long flags;
5384 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
5385 struct ieee80211_conf *conf = NULL;
5387 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
5389 conf = ieee80211_get_hw_conf(priv->hw);
5392 set_bit(STATUS_EXIT_PENDING, &priv->status);
5394 iwl3945_led_unregister(priv);
5395 iwl3945_clear_stations_table(priv);
5397 /* Unblock any waiting calls */
5398 wake_up_interruptible_all(&priv->wait_command_queue);
5400 /* Wipe out the EXIT_PENDING status bit if we are not actually
5401 * exiting the module */
5403 clear_bit(STATUS_EXIT_PENDING, &priv->status);
5405 /* stop and reset the on-board processor */
5406 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
5408 /* tell the device to stop sending interrupts */
5409 spin_lock_irqsave(&priv->lock, flags);
5410 iwl3945_disable_interrupts(priv);
5411 spin_unlock_irqrestore(&priv->lock, flags);
5412 iwl_synchronize_irq(priv);
5414 if (priv->mac80211_registered)
5415 ieee80211_stop_queues(priv->hw);
5417 /* If we have not previously called iwl3945_init() then
5418 * clear all bits but the RF Kill and SUSPEND bits and return */
5419 if (!iwl_is_init(priv)) {
5420 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
5422 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
5424 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
5425 STATUS_GEO_CONFIGURED |
5426 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5428 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
5429 STATUS_EXIT_PENDING;
5433 /* ...otherwise clear out all the status bits but the RF Kill and
5434 * SUSPEND bits and continue taking the NIC down. */
5435 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
5437 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
5439 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
5440 STATUS_GEO_CONFIGURED |
5441 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5443 test_bit(STATUS_FW_ERROR, &priv->status) <<
5445 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
5446 STATUS_EXIT_PENDING;
5448 spin_lock_irqsave(&priv->lock, flags);
5449 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
5450 spin_unlock_irqrestore(&priv->lock, flags);
5452 iwl3945_hw_txq_ctx_stop(priv);
5453 iwl3945_hw_rxq_stop(priv);
5455 spin_lock_irqsave(&priv->lock, flags);
5456 if (!iwl_grab_nic_access(priv)) {
5457 iwl_write_prph(priv, APMG_CLK_DIS_REG,
5458 APMG_CLK_VAL_DMA_CLK_RQT);
5459 iwl_release_nic_access(priv);
5461 spin_unlock_irqrestore(&priv->lock, flags);
5465 priv->cfg->ops->lib->apm_ops.reset(priv);
5467 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
5469 if (priv->ibss_beacon)
5470 dev_kfree_skb(priv->ibss_beacon);
5471 priv->ibss_beacon = NULL;
5473 /* clear out any free frames */
5474 iwl3945_clear_free_frames(priv);
5477 static void iwl3945_down(struct iwl_priv *priv)
5479 mutex_lock(&priv->mutex);
5480 __iwl3945_down(priv);
5481 mutex_unlock(&priv->mutex);
5483 iwl3945_cancel_deferred_work(priv);
5486 #define MAX_HW_RESTARTS 5
5488 static int __iwl3945_up(struct iwl_priv *priv)
5492 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
5493 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
5497 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
5498 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
5503 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
5504 IWL_ERR(priv, "ucode not available for device bring up\n");
5508 /* If platform's RF_KILL switch is NOT set to KILL */
5509 if (iwl_read32(priv, CSR_GP_CNTRL) &
5510 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
5511 clear_bit(STATUS_RF_KILL_HW, &priv->status);
5513 set_bit(STATUS_RF_KILL_HW, &priv->status);
5514 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
5515 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
5520 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
5522 rc = iwl3945_hw_nic_init(priv);
5524 IWL_ERR(priv, "Unable to int nic\n");
5528 /* make sure rfkill handshake bits are cleared */
5529 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
5530 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
5531 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
5533 /* clear (again), then enable host interrupts */
5534 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
5535 iwl3945_enable_interrupts(priv);
5537 /* really make sure rfkill handshake bits are cleared */
5538 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
5539 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
5541 /* Copy original ucode data image from disk into backup cache.
5542 * This will be used to initialize the on-board processor's
5543 * data SRAM for a clean start when the runtime program first loads. */
5544 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
5545 priv->ucode_data.len);
5547 /* We return success when we resume from suspend and rf_kill is on. */
5548 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
5551 for (i = 0; i < MAX_HW_RESTARTS; i++) {
5553 iwl3945_clear_stations_table(priv);
5555 /* load bootstrap state machine,
5556 * load bootstrap program into processor's memory,
5557 * prepare to load the "initialize" uCode */
5558 priv->cfg->ops->lib->load_ucode(priv);
5562 "Unable to set up bootstrap uCode: %d\n", rc);
5566 /* start card; "initialize" will load runtime ucode */
5567 iwl3945_nic_start(priv);
5569 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
5574 set_bit(STATUS_EXIT_PENDING, &priv->status);
5575 __iwl3945_down(priv);
5576 clear_bit(STATUS_EXIT_PENDING, &priv->status);
5578 /* tried to restart and config the device for as long as our
5579 * patience could withstand */
5580 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
5585 /*****************************************************************************
5587 * Workqueue callbacks
5589 *****************************************************************************/
5591 static void iwl3945_bg_init_alive_start(struct work_struct *data)
5593 struct iwl_priv *priv =
5594 container_of(data, struct iwl_priv, init_alive_start.work);
5596 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5599 mutex_lock(&priv->mutex);
5600 iwl3945_init_alive_start(priv);
5601 mutex_unlock(&priv->mutex);
5604 static void iwl3945_bg_alive_start(struct work_struct *data)
5606 struct iwl_priv *priv =
5607 container_of(data, struct iwl_priv, alive_start.work);
5609 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5612 mutex_lock(&priv->mutex);
5613 iwl3945_alive_start(priv);
5614 mutex_unlock(&priv->mutex);
5617 static void iwl3945_bg_rf_kill(struct work_struct *work)
5619 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
5621 wake_up_interruptible(&priv->wait_command_queue);
5623 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5626 mutex_lock(&priv->mutex);
5628 if (!iwl_is_rfkill(priv)) {
5629 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
5630 "HW and/or SW RF Kill no longer active, restarting "
5632 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
5633 queue_work(priv->workqueue, &priv->restart);
5636 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
5637 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
5638 "disabled by SW switch\n");
5640 IWL_WARN(priv, "Radio Frequency Kill Switch is On:\n"
5641 "Kill switch must be turned off for "
5642 "wireless networking to work.\n");
5645 mutex_unlock(&priv->mutex);
5646 iwl3945_rfkill_set_hw_state(priv);
5649 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
5651 static void iwl3945_bg_scan_check(struct work_struct *data)
5653 struct iwl_priv *priv =
5654 container_of(data, struct iwl_priv, scan_check.work);
5656 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5659 mutex_lock(&priv->mutex);
5660 if (test_bit(STATUS_SCANNING, &priv->status) ||
5661 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
5662 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
5663 "Scan completion watchdog resetting adapter (%dms)\n",
5664 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
5666 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
5667 iwl3945_send_scan_abort(priv);
5669 mutex_unlock(&priv->mutex);
5672 static void iwl3945_bg_request_scan(struct work_struct *data)
5674 struct iwl_priv *priv =
5675 container_of(data, struct iwl_priv, request_scan);
5676 struct iwl_host_cmd cmd = {
5677 .id = REPLY_SCAN_CMD,
5678 .len = sizeof(struct iwl3945_scan_cmd),
5679 .meta.flags = CMD_SIZE_HUGE,
5682 struct iwl3945_scan_cmd *scan;
5683 struct ieee80211_conf *conf = NULL;
5685 enum ieee80211_band band;
5686 DECLARE_SSID_BUF(ssid);
5688 conf = ieee80211_get_hw_conf(priv->hw);
5690 mutex_lock(&priv->mutex);
5692 if (!iwl_is_ready(priv)) {
5693 IWL_WARN(priv, "request scan called when driver not ready.\n");
5697 /* Make sure the scan wasn't canceled before this queued work
5698 * was given the chance to run... */
5699 if (!test_bit(STATUS_SCANNING, &priv->status))
5702 /* This should never be called or scheduled if there is currently
5703 * a scan active in the hardware. */
5704 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
5705 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
5706 "Ignoring second request.\n");
5711 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
5712 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5716 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
5717 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5721 if (iwl_is_rfkill(priv)) {
5722 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5726 if (!test_bit(STATUS_READY, &priv->status)) {
5727 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
5731 if (!priv->scan_bands) {
5732 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
5736 if (!priv->scan39) {
5737 priv->scan39 = kmalloc(sizeof(struct iwl3945_scan_cmd) +
5738 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
5739 if (!priv->scan39) {
5744 scan = priv->scan39;
5745 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
5747 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
5748 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
5750 if (iwl3945_is_associated(priv)) {
5753 u32 suspend_time = 100;
5754 u32 scan_suspend_time = 100;
5755 unsigned long flags;
5757 IWL_DEBUG_INFO("Scanning while associated...\n");
5759 spin_lock_irqsave(&priv->lock, flags);
5760 interval = priv->beacon_int;
5761 spin_unlock_irqrestore(&priv->lock, flags);
5763 scan->suspend_time = 0;
5764 scan->max_out_time = cpu_to_le32(200 * 1024);
5766 interval = suspend_time;
5768 * suspend time format:
5769 * 0-19: beacon interval in usec (time before exec.)
5771 * 24-31: number of beacons (suspend between channels)
5774 extra = (suspend_time / interval) << 24;
5775 scan_suspend_time = 0xFF0FFFFF &
5776 (extra | ((suspend_time % interval) * 1024));
5778 scan->suspend_time = cpu_to_le32(scan_suspend_time);
5779 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
5780 scan_suspend_time, interval);
5783 /* We should add the ability for user to lock to PASSIVE ONLY */
5784 if (priv->one_direct_scan) {
5786 ("Kicking off one direct scan for '%s'\n",
5787 print_ssid(ssid, priv->direct_ssid,
5788 priv->direct_ssid_len));
5789 scan->direct_scan[0].id = WLAN_EID_SSID;
5790 scan->direct_scan[0].len = priv->direct_ssid_len;
5791 memcpy(scan->direct_scan[0].ssid,
5792 priv->direct_ssid, priv->direct_ssid_len);
5795 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
5797 /* We don't build a direct scan probe request; the uCode will do
5798 * that based on the direct_mask added to each channel entry */
5799 scan->tx_cmd.len = cpu_to_le16(
5800 iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
5801 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
5802 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
5803 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
5804 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
5806 /* flags + rate selection */
5808 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
5809 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
5810 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
5811 scan->good_CRC_th = 0;
5812 band = IEEE80211_BAND_2GHZ;
5813 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
5814 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
5815 scan->good_CRC_th = IWL_GOOD_CRC_TH;
5816 band = IEEE80211_BAND_5GHZ;
5818 IWL_WARN(priv, "Invalid scan band count\n");
5822 /* select Rx antennas */
5823 scan->flags |= iwl3945_get_antenna_flags(priv);
5825 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
5826 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
5828 scan->channel_count =
5829 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
5831 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
5833 if (scan->channel_count == 0) {
5834 IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count);
5838 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
5839 scan->channel_count * sizeof(struct iwl3945_scan_channel);
5841 scan->len = cpu_to_le16(cmd.len);
5843 set_bit(STATUS_SCAN_HW, &priv->status);
5844 rc = iwl3945_send_cmd_sync(priv, &cmd);
5848 queue_delayed_work(priv->workqueue, &priv->scan_check,
5849 IWL_SCAN_CHECK_WATCHDOG);
5851 mutex_unlock(&priv->mutex);
5855 /* can not perform scan make sure we clear scanning
5856 * bits from status so next scan request can be performed.
5857 * if we dont clear scanning status bit here all next scan
5860 clear_bit(STATUS_SCAN_HW, &priv->status);
5861 clear_bit(STATUS_SCANNING, &priv->status);
5863 /* inform mac80211 scan aborted */
5864 queue_work(priv->workqueue, &priv->scan_completed);
5865 mutex_unlock(&priv->mutex);
5868 static void iwl3945_bg_up(struct work_struct *data)
5870 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
5872 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5875 mutex_lock(&priv->mutex);
5877 mutex_unlock(&priv->mutex);
5878 iwl3945_rfkill_set_hw_state(priv);
5881 static void iwl3945_bg_restart(struct work_struct *data)
5883 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
5885 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5889 queue_work(priv->workqueue, &priv->up);
5892 static void iwl3945_bg_rx_replenish(struct work_struct *data)
5894 struct iwl_priv *priv =
5895 container_of(data, struct iwl_priv, rx_replenish);
5897 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5900 mutex_lock(&priv->mutex);
5901 iwl3945_rx_replenish(priv);
5902 mutex_unlock(&priv->mutex);
5905 #define IWL_DELAY_NEXT_SCAN (HZ*2)
5907 static void iwl3945_post_associate(struct iwl_priv *priv)
5910 struct ieee80211_conf *conf = NULL;
5912 if (priv->iw_mode == NL80211_IFTYPE_AP) {
5913 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
5918 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
5919 priv->assoc_id, priv->active39_rxon.bssid_addr);
5921 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5924 if (!priv->vif || !priv->is_open)
5927 iwl3945_scan_cancel_timeout(priv, 200);
5929 conf = ieee80211_get_hw_conf(priv->hw);
5931 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
5932 iwl3945_commit_rxon(priv);
5934 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
5935 iwl3945_setup_rxon_timing(priv);
5936 rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
5937 sizeof(priv->rxon_timing), &priv->rxon_timing);
5939 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
5940 "Attempting to continue.\n");
5942 priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
5944 priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
5946 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
5947 priv->assoc_id, priv->beacon_int);
5949 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
5950 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
5952 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
5954 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
5955 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
5956 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
5958 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
5960 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
5961 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
5965 iwl3945_commit_rxon(priv);
5967 switch (priv->iw_mode) {
5968 case NL80211_IFTYPE_STATION:
5969 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
5972 case NL80211_IFTYPE_ADHOC:
5975 iwl3945_add_station(priv, priv->bssid, 0, 0);
5976 iwl3945_sync_sta(priv, IWL_STA_ID,
5977 (priv->band == IEEE80211_BAND_5GHZ) ?
5978 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
5980 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
5981 iwl3945_send_beacon_cmd(priv);
5986 IWL_ERR(priv, "%s Should not be called in %d mode\n",
5987 __func__, priv->iw_mode);
5991 iwl3945_activate_qos(priv, 0);
5993 /* we have just associated, don't start scan too early */
5994 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
5997 static void iwl3945_bg_abort_scan(struct work_struct *work)
5999 struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
6001 if (!iwl_is_ready(priv))
6004 mutex_lock(&priv->mutex);
6006 set_bit(STATUS_SCAN_ABORTING, &priv->status);
6007 iwl3945_send_scan_abort(priv);
6009 mutex_unlock(&priv->mutex);
6012 static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
6014 static void iwl3945_bg_scan_completed(struct work_struct *work)
6016 struct iwl_priv *priv =
6017 container_of(work, struct iwl_priv, scan_completed);
6019 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
6021 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6024 if (test_bit(STATUS_CONF_PENDING, &priv->status))
6025 iwl3945_mac_config(priv->hw, 0);
6027 ieee80211_scan_completed(priv->hw);
6029 /* Since setting the TXPOWER may have been deferred while
6030 * performing the scan, fire one off */
6031 mutex_lock(&priv->mutex);
6032 iwl3945_hw_reg_send_txpower(priv);
6033 mutex_unlock(&priv->mutex);
6036 /*****************************************************************************
6038 * mac80211 entry point functions
6040 *****************************************************************************/
6042 #define UCODE_READY_TIMEOUT (2 * HZ)
6044 static int iwl3945_mac_start(struct ieee80211_hw *hw)
6046 struct iwl_priv *priv = hw->priv;
6049 IWL_DEBUG_MAC80211("enter\n");
6051 if (pci_enable_device(priv->pci_dev)) {
6052 IWL_ERR(priv, "Fail to pci_enable_device\n");
6055 pci_restore_state(priv->pci_dev);
6056 pci_enable_msi(priv->pci_dev);
6058 ret = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
6061 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
6062 goto out_disable_msi;
6065 /* we should be verifying the device is ready to be opened */
6066 mutex_lock(&priv->mutex);
6068 memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd));
6069 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6070 * ucode filename and max sizes are card-specific. */
6072 if (!priv->ucode_code.len) {
6073 ret = iwl3945_read_ucode(priv);
6075 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
6076 mutex_unlock(&priv->mutex);
6077 goto out_release_irq;
6081 ret = __iwl3945_up(priv);
6083 mutex_unlock(&priv->mutex);
6085 iwl3945_rfkill_set_hw_state(priv);
6088 goto out_release_irq;
6090 IWL_DEBUG_INFO("Start UP work.\n");
6092 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
6095 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6096 * mac80211 will not be run successfully. */
6097 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
6098 test_bit(STATUS_READY, &priv->status),
6099 UCODE_READY_TIMEOUT);
6101 if (!test_bit(STATUS_READY, &priv->status)) {
6103 "Wait for START_ALIVE timeout after %dms.\n",
6104 jiffies_to_msecs(UCODE_READY_TIMEOUT));
6106 goto out_release_irq;
6111 IWL_DEBUG_MAC80211("leave\n");
6115 free_irq(priv->pci_dev->irq, priv);
6117 pci_disable_msi(priv->pci_dev);
6118 pci_disable_device(priv->pci_dev);
6120 IWL_DEBUG_MAC80211("leave - failed\n");
6124 static void iwl3945_mac_stop(struct ieee80211_hw *hw)
6126 struct iwl_priv *priv = hw->priv;
6128 IWL_DEBUG_MAC80211("enter\n");
6130 if (!priv->is_open) {
6131 IWL_DEBUG_MAC80211("leave - skip\n");
6137 if (iwl_is_ready_rf(priv)) {
6138 /* stop mac, cancel any scan request and clear
6139 * RXON_FILTER_ASSOC_MSK BIT
6141 mutex_lock(&priv->mutex);
6142 iwl3945_scan_cancel_timeout(priv, 100);
6143 mutex_unlock(&priv->mutex);
6148 flush_workqueue(priv->workqueue);
6149 free_irq(priv->pci_dev->irq, priv);
6150 pci_disable_msi(priv->pci_dev);
6151 pci_save_state(priv->pci_dev);
6152 pci_disable_device(priv->pci_dev);
6154 IWL_DEBUG_MAC80211("leave\n");
6157 static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
6159 struct iwl_priv *priv = hw->priv;
6161 IWL_DEBUG_MAC80211("enter\n");
6163 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
6164 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
6166 if (iwl3945_tx_skb(priv, skb))
6167 dev_kfree_skb_any(skb);
6169 IWL_DEBUG_MAC80211("leave\n");
6170 return NETDEV_TX_OK;
6173 static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
6174 struct ieee80211_if_init_conf *conf)
6176 struct iwl_priv *priv = hw->priv;
6177 unsigned long flags;
6179 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
6182 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6186 spin_lock_irqsave(&priv->lock, flags);
6187 priv->vif = conf->vif;
6188 priv->iw_mode = conf->type;
6190 spin_unlock_irqrestore(&priv->lock, flags);
6192 mutex_lock(&priv->mutex);
6194 if (conf->mac_addr) {
6195 IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr);
6196 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
6199 if (iwl_is_ready(priv))
6200 iwl3945_set_mode(priv, conf->type);
6202 mutex_unlock(&priv->mutex);
6204 IWL_DEBUG_MAC80211("leave\n");
6209 * iwl3945_mac_config - mac80211 config callback
6211 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6212 * be set inappropriately and the driver currently sets the hardware up to
6213 * use it whenever needed.
6215 static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
6217 struct iwl_priv *priv = hw->priv;
6218 const struct iwl_channel_info *ch_info;
6219 struct ieee80211_conf *conf = &hw->conf;
6220 unsigned long flags;
6223 mutex_lock(&priv->mutex);
6224 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
6226 if (!iwl_is_ready(priv)) {
6227 IWL_DEBUG_MAC80211("leave - not ready\n");
6232 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
6233 test_bit(STATUS_SCANNING, &priv->status))) {
6234 IWL_DEBUG_MAC80211("leave - scanning\n");
6235 set_bit(STATUS_CONF_PENDING, &priv->status);
6236 mutex_unlock(&priv->mutex);
6240 spin_lock_irqsave(&priv->lock, flags);
6242 ch_info = iwl3945_get_channel_info(priv, conf->channel->band,
6243 conf->channel->hw_value);
6244 if (!is_channel_valid(ch_info)) {
6245 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
6246 conf->channel->hw_value, conf->channel->band);
6247 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6248 spin_unlock_irqrestore(&priv->lock, flags);
6253 iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value);
6255 iwl3945_set_flags_for_phymode(priv, conf->channel->band);
6257 /* The list of supported rates and rate mask can be different
6258 * for each phymode; since the phymode may have changed, reset
6259 * the rate mask to what mac80211 lists */
6260 iwl3945_set_rate(priv);
6262 spin_unlock_irqrestore(&priv->lock, flags);
6264 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6265 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
6266 iwl3945_hw_channel_switch(priv, conf->channel);
6271 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
6273 if (!conf->radio_enabled) {
6274 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6278 if (iwl_is_rfkill(priv)) {
6279 IWL_DEBUG_MAC80211("leave - RF kill\n");
6284 iwl3945_set_rate(priv);
6286 if (memcmp(&priv->active39_rxon,
6287 &priv->staging39_rxon, sizeof(priv->staging39_rxon)))
6288 iwl3945_commit_rxon(priv);
6290 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6292 IWL_DEBUG_MAC80211("leave\n");
6295 clear_bit(STATUS_CONF_PENDING, &priv->status);
6296 mutex_unlock(&priv->mutex);
6300 static void iwl3945_config_ap(struct iwl_priv *priv)
6304 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6307 /* The following should be done only at AP bring up */
6308 if (!(iwl3945_is_associated(priv))) {
6310 /* RXON - unassoc (to set timing command) */
6311 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6312 iwl3945_commit_rxon(priv);
6315 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
6316 iwl3945_setup_rxon_timing(priv);
6317 rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
6318 sizeof(priv->rxon_timing), &priv->rxon_timing);
6320 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
6321 "Attempting to continue.\n");
6323 /* FIXME: what should be the assoc_id for AP? */
6324 priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
6325 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6326 priv->staging39_rxon.flags |=
6327 RXON_FLG_SHORT_PREAMBLE_MSK;
6329 priv->staging39_rxon.flags &=
6330 ~RXON_FLG_SHORT_PREAMBLE_MSK;
6332 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
6333 if (priv->assoc_capability &
6334 WLAN_CAPABILITY_SHORT_SLOT_TIME)
6335 priv->staging39_rxon.flags |=
6336 RXON_FLG_SHORT_SLOT_MSK;
6338 priv->staging39_rxon.flags &=
6339 ~RXON_FLG_SHORT_SLOT_MSK;
6341 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
6342 priv->staging39_rxon.flags &=
6343 ~RXON_FLG_SHORT_SLOT_MSK;
6345 /* restore RXON assoc */
6346 priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
6347 iwl3945_commit_rxon(priv);
6348 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
6350 iwl3945_send_beacon_cmd(priv);
6352 /* FIXME - we need to add code here to detect a totally new
6353 * configuration, reset the AP, unassoc, rxon timing, assoc,
6354 * clear sta table, add BCAST sta... */
6357 static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6358 struct ieee80211_vif *vif,
6359 struct ieee80211_if_conf *conf)
6361 struct iwl_priv *priv = hw->priv;
6367 if (priv->vif != vif) {
6368 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6372 /* handle this temporarily here */
6373 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
6374 conf->changed & IEEE80211_IFCC_BEACON) {
6375 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
6378 mutex_lock(&priv->mutex);
6379 rc = iwl3945_mac_beacon_update(hw, beacon);
6380 mutex_unlock(&priv->mutex);
6385 if (!iwl_is_alive(priv))
6388 mutex_lock(&priv->mutex);
6391 IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
6394 * very dubious code was here; the probe filtering flag is never set:
6396 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6397 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6400 if (priv->iw_mode == NL80211_IFTYPE_AP) {
6402 conf->bssid = priv->mac_addr;
6403 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
6404 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
6407 if (priv->ibss_beacon)
6408 dev_kfree_skb(priv->ibss_beacon);
6410 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
6413 if (iwl_is_rfkill(priv))
6416 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
6417 !is_multicast_ether_addr(conf->bssid)) {
6418 /* If there is currently a HW scan going on in the background
6419 * then we need to cancel it else the RXON below will fail. */
6420 if (iwl3945_scan_cancel_timeout(priv, 100)) {
6421 IWL_WARN(priv, "Aborted scan still in progress "
6423 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6424 mutex_unlock(&priv->mutex);
6427 memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN);
6429 /* TODO: Audit driver for usage of these members and see
6430 * if mac80211 deprecates them (priv->bssid looks like it
6431 * shouldn't be there, but I haven't scanned the IBSS code
6432 * to verify) - jpk */
6433 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
6435 if (priv->iw_mode == NL80211_IFTYPE_AP)
6436 iwl3945_config_ap(priv);
6438 rc = iwl3945_commit_rxon(priv);
6439 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
6440 iwl3945_add_station(priv,
6441 priv->active39_rxon.bssid_addr, 1, 0);
6445 iwl3945_scan_cancel_timeout(priv, 100);
6446 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6447 iwl3945_commit_rxon(priv);
6451 IWL_DEBUG_MAC80211("leave\n");
6452 mutex_unlock(&priv->mutex);
6457 static void iwl3945_configure_filter(struct ieee80211_hw *hw,
6458 unsigned int changed_flags,
6459 unsigned int *total_flags,
6460 int mc_count, struct dev_addr_list *mc_list)
6462 struct iwl_priv *priv = hw->priv;
6463 __le32 *filter_flags = &priv->staging39_rxon.filter_flags;
6465 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
6466 changed_flags, *total_flags);
6468 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
6469 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
6470 *filter_flags |= RXON_FILTER_PROMISC_MSK;
6472 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
6474 if (changed_flags & FIF_ALLMULTI) {
6475 if (*total_flags & FIF_ALLMULTI)
6476 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
6478 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
6480 if (changed_flags & FIF_CONTROL) {
6481 if (*total_flags & FIF_CONTROL)
6482 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
6484 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
6486 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
6487 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
6488 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
6490 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
6493 /* We avoid iwl_commit_rxon here to commit the new filter flags
6494 * since mac80211 will call ieee80211_hw_config immediately.
6495 * (mc_list is not supported at this time). Otherwise, we need to
6496 * queue a background iwl_commit_rxon work.
6499 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
6500 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
6503 static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
6504 struct ieee80211_if_init_conf *conf)
6506 struct iwl_priv *priv = hw->priv;
6508 IWL_DEBUG_MAC80211("enter\n");
6510 mutex_lock(&priv->mutex);
6512 if (iwl_is_ready_rf(priv)) {
6513 iwl3945_scan_cancel_timeout(priv, 100);
6514 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6515 iwl3945_commit_rxon(priv);
6517 if (priv->vif == conf->vif) {
6519 memset(priv->bssid, 0, ETH_ALEN);
6521 mutex_unlock(&priv->mutex);
6523 IWL_DEBUG_MAC80211("leave\n");
6526 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6528 static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
6529 struct ieee80211_vif *vif,
6530 struct ieee80211_bss_conf *bss_conf,
6533 struct iwl_priv *priv = hw->priv;
6535 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
6537 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
6538 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
6539 bss_conf->use_short_preamble);
6540 if (bss_conf->use_short_preamble)
6541 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
6543 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
6546 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
6547 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
6548 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
6549 priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
6551 priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
6554 if (changes & BSS_CHANGED_ASSOC) {
6555 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
6556 /* This should never happen as this function should
6557 * never be called from interrupt context. */
6558 if (WARN_ON_ONCE(in_interrupt()))
6560 if (bss_conf->assoc) {
6561 priv->assoc_id = bss_conf->aid;
6562 priv->beacon_int = bss_conf->beacon_int;
6563 priv->timestamp = bss_conf->timestamp;
6564 priv->assoc_capability = bss_conf->assoc_capability;
6565 priv->next_scan_jiffies = jiffies +
6566 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
6567 mutex_lock(&priv->mutex);
6568 iwl3945_post_associate(priv);
6569 mutex_unlock(&priv->mutex);
6572 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
6574 } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) {
6575 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
6576 iwl3945_send_rxon_assoc(priv);
6581 static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
6584 unsigned long flags;
6585 struct iwl_priv *priv = hw->priv;
6586 DECLARE_SSID_BUF(ssid_buf);
6588 IWL_DEBUG_MAC80211("enter\n");
6590 mutex_lock(&priv->mutex);
6591 spin_lock_irqsave(&priv->lock, flags);
6593 if (!iwl_is_ready_rf(priv)) {
6595 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6599 /* we don't schedule scan within next_scan_jiffies period */
6600 if (priv->next_scan_jiffies &&
6601 time_after(priv->next_scan_jiffies, jiffies)) {
6605 /* if we just finished scan ask for delay for a broadcast scan */
6606 if ((len == 0) && priv->last_scan_jiffies &&
6607 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
6613 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6614 print_ssid(ssid_buf, ssid, len), (int)len);
6616 priv->one_direct_scan = 1;
6617 priv->direct_ssid_len = (u8)
6618 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
6619 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
6621 priv->one_direct_scan = 0;
6623 rc = iwl3945_scan_initiate(priv);
6625 IWL_DEBUG_MAC80211("leave\n");
6628 spin_unlock_irqrestore(&priv->lock, flags);
6629 mutex_unlock(&priv->mutex);
6634 static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6635 const u8 *local_addr, const u8 *addr,
6636 struct ieee80211_key_conf *key)
6638 struct iwl_priv *priv = hw->priv;
6642 IWL_DEBUG_MAC80211("enter\n");
6644 if (iwl3945_mod_params.sw_crypto) {
6645 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
6649 if (is_zero_ether_addr(addr))
6650 /* only support pairwise keys */
6653 sta_id = iwl3945_hw_find_station(priv, addr);
6654 if (sta_id == IWL_INVALID_STATION) {
6655 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
6660 mutex_lock(&priv->mutex);
6662 iwl3945_scan_cancel_timeout(priv, 100);
6666 rc = iwl3945_update_sta_key_info(priv, key, sta_id);
6668 iwl3945_set_rxon_hwcrypto(priv, 1);
6669 iwl3945_commit_rxon(priv);
6670 key->hw_key_idx = sta_id;
6671 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
6672 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
6676 rc = iwl3945_clear_sta_key_info(priv, sta_id);
6678 iwl3945_set_rxon_hwcrypto(priv, 0);
6679 iwl3945_commit_rxon(priv);
6680 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
6687 IWL_DEBUG_MAC80211("leave\n");
6688 mutex_unlock(&priv->mutex);
6693 static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
6694 const struct ieee80211_tx_queue_params *params)
6696 struct iwl_priv *priv = hw->priv;
6697 unsigned long flags;
6700 IWL_DEBUG_MAC80211("enter\n");
6702 if (!iwl_is_ready_rf(priv)) {
6703 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6707 if (queue >= AC_NUM) {
6708 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
6712 q = AC_NUM - 1 - queue;
6714 spin_lock_irqsave(&priv->lock, flags);
6716 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
6717 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
6718 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
6719 priv->qos_data.def_qos_parm.ac[q].edca_txop =
6720 cpu_to_le16((params->txop * 32));
6722 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
6723 priv->qos_data.qos_active = 1;
6725 spin_unlock_irqrestore(&priv->lock, flags);
6727 mutex_lock(&priv->mutex);
6728 if (priv->iw_mode == NL80211_IFTYPE_AP)
6729 iwl3945_activate_qos(priv, 1);
6730 else if (priv->assoc_id && iwl3945_is_associated(priv))
6731 iwl3945_activate_qos(priv, 0);
6733 mutex_unlock(&priv->mutex);
6735 IWL_DEBUG_MAC80211("leave\n");
6739 static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
6740 struct ieee80211_tx_queue_stats *stats)
6742 struct iwl_priv *priv = hw->priv;
6744 struct iwl3945_tx_queue *txq;
6745 struct iwl_queue *q;
6746 unsigned long flags;
6748 IWL_DEBUG_MAC80211("enter\n");
6750 if (!iwl_is_ready_rf(priv)) {
6751 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6755 spin_lock_irqsave(&priv->lock, flags);
6757 for (i = 0; i < AC_NUM; i++) {
6758 txq = &priv->txq39[i];
6760 avail = iwl_queue_space(q);
6762 stats[i].len = q->n_window - avail;
6763 stats[i].limit = q->n_window - q->high_mark;
6764 stats[i].count = q->n_window;
6767 spin_unlock_irqrestore(&priv->lock, flags);
6769 IWL_DEBUG_MAC80211("leave\n");
6774 static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
6776 struct iwl_priv *priv = hw->priv;
6777 unsigned long flags;
6779 mutex_lock(&priv->mutex);
6780 IWL_DEBUG_MAC80211("enter\n");
6782 iwl_reset_qos(priv);
6784 spin_lock_irqsave(&priv->lock, flags);
6786 priv->assoc_capability = 0;
6787 priv->call_post_assoc_from_beacon = 0;
6789 /* new association get rid of ibss beacon skb */
6790 if (priv->ibss_beacon)
6791 dev_kfree_skb(priv->ibss_beacon);
6793 priv->ibss_beacon = NULL;
6795 priv->beacon_int = priv->hw->conf.beacon_int;
6796 priv->timestamp = 0;
6797 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
6798 priv->beacon_int = 0;
6800 spin_unlock_irqrestore(&priv->lock, flags);
6802 if (!iwl_is_ready_rf(priv)) {
6803 IWL_DEBUG_MAC80211("leave - not ready\n");
6804 mutex_unlock(&priv->mutex);
6808 /* we are restarting association process
6809 * clear RXON_FILTER_ASSOC_MSK bit
6811 if (priv->iw_mode != NL80211_IFTYPE_AP) {
6812 iwl3945_scan_cancel_timeout(priv, 100);
6813 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6814 iwl3945_commit_rxon(priv);
6817 /* Per mac80211.h: This is only used in IBSS mode... */
6818 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
6820 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
6821 mutex_unlock(&priv->mutex);
6825 iwl3945_set_rate(priv);
6827 mutex_unlock(&priv->mutex);
6829 IWL_DEBUG_MAC80211("leave\n");
6833 static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
6835 struct iwl_priv *priv = hw->priv;
6836 unsigned long flags;
6838 IWL_DEBUG_MAC80211("enter\n");
6840 if (!iwl_is_ready_rf(priv)) {
6841 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6845 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
6846 IWL_DEBUG_MAC80211("leave - not IBSS\n");
6850 spin_lock_irqsave(&priv->lock, flags);
6852 if (priv->ibss_beacon)
6853 dev_kfree_skb(priv->ibss_beacon);
6855 priv->ibss_beacon = skb;
6859 IWL_DEBUG_MAC80211("leave\n");
6860 spin_unlock_irqrestore(&priv->lock, flags);
6862 iwl_reset_qos(priv);
6864 iwl3945_post_associate(priv);
6870 /*****************************************************************************
6874 *****************************************************************************/
6876 #ifdef CONFIG_IWL3945_DEBUG
6879 * The following adds a new attribute to the sysfs representation
6880 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
6881 * used for controlling the debug level.
6883 * See the level definitions in iwl for details.
6885 static ssize_t show_debug_level(struct device *d,
6886 struct device_attribute *attr, char *buf)
6888 struct iwl_priv *priv = d->driver_data;
6890 return sprintf(buf, "0x%08X\n", priv->debug_level);
6892 static ssize_t store_debug_level(struct device *d,
6893 struct device_attribute *attr,
6894 const char *buf, size_t count)
6896 struct iwl_priv *priv = d->driver_data;
6900 ret = strict_strtoul(buf, 0, &val);
6902 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
6904 priv->debug_level = val;
6906 return strnlen(buf, count);
6909 static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
6910 show_debug_level, store_debug_level);
6912 #endif /* CONFIG_IWL3945_DEBUG */
6914 static ssize_t show_temperature(struct device *d,
6915 struct device_attribute *attr, char *buf)
6917 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
6919 if (!iwl_is_alive(priv))
6922 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
6925 static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
6927 static ssize_t show_tx_power(struct device *d,
6928 struct device_attribute *attr, char *buf)
6930 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
6931 return sprintf(buf, "%d\n", priv->user_txpower_limit);
6934 static ssize_t store_tx_power(struct device *d,
6935 struct device_attribute *attr,
6936 const char *buf, size_t count)
6938 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
6939 char *p = (char *)buf;
6942 val = simple_strtoul(p, &p, 10);
6944 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
6946 iwl3945_hw_reg_set_txpower(priv, val);
6951 static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
6953 static ssize_t show_flags(struct device *d,
6954 struct device_attribute *attr, char *buf)
6956 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
6958 return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags);
6961 static ssize_t store_flags(struct device *d,
6962 struct device_attribute *attr,
6963 const char *buf, size_t count)
6965 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
6966 u32 flags = simple_strtoul(buf, NULL, 0);
6968 mutex_lock(&priv->mutex);
6969 if (le32_to_cpu(priv->staging39_rxon.flags) != flags) {
6970 /* Cancel any currently running scans... */
6971 if (iwl3945_scan_cancel_timeout(priv, 100))
6972 IWL_WARN(priv, "Could not cancel scan.\n");
6974 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
6976 priv->staging39_rxon.flags = cpu_to_le32(flags);
6977 iwl3945_commit_rxon(priv);
6980 mutex_unlock(&priv->mutex);
6985 static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
6987 static ssize_t show_filter_flags(struct device *d,
6988 struct device_attribute *attr, char *buf)
6990 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
6992 return sprintf(buf, "0x%04X\n",
6993 le32_to_cpu(priv->active39_rxon.filter_flags));
6996 static ssize_t store_filter_flags(struct device *d,
6997 struct device_attribute *attr,
6998 const char *buf, size_t count)
7000 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7001 u32 filter_flags = simple_strtoul(buf, NULL, 0);
7003 mutex_lock(&priv->mutex);
7004 if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) {
7005 /* Cancel any currently running scans... */
7006 if (iwl3945_scan_cancel_timeout(priv, 100))
7007 IWL_WARN(priv, "Could not cancel scan.\n");
7009 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7010 "0x%04X\n", filter_flags);
7011 priv->staging39_rxon.filter_flags =
7012 cpu_to_le32(filter_flags);
7013 iwl3945_commit_rxon(priv);
7016 mutex_unlock(&priv->mutex);
7021 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
7022 store_filter_flags);
7024 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
7026 static ssize_t show_measurement(struct device *d,
7027 struct device_attribute *attr, char *buf)
7029 struct iwl_priv *priv = dev_get_drvdata(d);
7030 struct iwl_spectrum_notification measure_report;
7031 u32 size = sizeof(measure_report), len = 0, ofs = 0;
7032 u8 *data = (u8 *)&measure_report;
7033 unsigned long flags;
7035 spin_lock_irqsave(&priv->lock, flags);
7036 if (!(priv->measurement_status & MEASUREMENT_READY)) {
7037 spin_unlock_irqrestore(&priv->lock, flags);
7040 memcpy(&measure_report, &priv->measure_report, size);
7041 priv->measurement_status = 0;
7042 spin_unlock_irqrestore(&priv->lock, flags);
7044 while (size && (PAGE_SIZE - len)) {
7045 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
7046 PAGE_SIZE - len, 1);
7048 if (PAGE_SIZE - len)
7052 size -= min(size, 16U);
7058 static ssize_t store_measurement(struct device *d,
7059 struct device_attribute *attr,
7060 const char *buf, size_t count)
7062 struct iwl_priv *priv = dev_get_drvdata(d);
7063 struct ieee80211_measurement_params params = {
7064 .channel = le16_to_cpu(priv->active39_rxon.channel),
7065 .start_time = cpu_to_le64(priv->last_tsf),
7066 .duration = cpu_to_le16(1),
7068 u8 type = IWL_MEASURE_BASIC;
7074 strncpy(buffer, buf, min(sizeof(buffer), count));
7075 channel = simple_strtoul(p, NULL, 0);
7077 params.channel = channel;
7080 while (*p && *p != ' ')
7083 type = simple_strtoul(p + 1, NULL, 0);
7086 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7087 "channel %d (for '%s')\n", type, params.channel, buf);
7088 iwl3945_get_measurement(priv, ¶ms, type);
7093 static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
7094 show_measurement, store_measurement);
7095 #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
7097 static ssize_t store_retry_rate(struct device *d,
7098 struct device_attribute *attr,
7099 const char *buf, size_t count)
7101 struct iwl_priv *priv = dev_get_drvdata(d);
7103 priv->retry_rate = simple_strtoul(buf, NULL, 0);
7104 if (priv->retry_rate <= 0)
7105 priv->retry_rate = 1;
7110 static ssize_t show_retry_rate(struct device *d,
7111 struct device_attribute *attr, char *buf)
7113 struct iwl_priv *priv = dev_get_drvdata(d);
7114 return sprintf(buf, "%d", priv->retry_rate);
7117 static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
7120 static ssize_t store_power_level(struct device *d,
7121 struct device_attribute *attr,
7122 const char *buf, size_t count)
7124 struct iwl_priv *priv = dev_get_drvdata(d);
7128 mode = simple_strtoul(buf, NULL, 0);
7129 mutex_lock(&priv->mutex);
7131 if (!iwl_is_ready(priv)) {
7136 if ((mode < 1) || (mode > IWL39_POWER_LIMIT) ||
7137 (mode == IWL39_POWER_AC))
7138 mode = IWL39_POWER_AC;
7140 mode |= IWL_POWER_ENABLED;
7142 if (mode != priv->power_mode) {
7143 rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
7145 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7148 priv->power_mode = mode;
7154 mutex_unlock(&priv->mutex);
7158 #define MAX_WX_STRING 80
7160 /* Values are in microsecond */
7161 static const s32 timeout_duration[] = {
7168 static const s32 period_duration[] = {
7176 static ssize_t show_power_level(struct device *d,
7177 struct device_attribute *attr, char *buf)
7179 struct iwl_priv *priv = dev_get_drvdata(d);
7180 int level = IWL_POWER_LEVEL(priv->power_mode);
7183 p += sprintf(p, "%d ", level);
7185 case IWL_POWER_MODE_CAM:
7186 case IWL39_POWER_AC:
7187 p += sprintf(p, "(AC)");
7189 case IWL39_POWER_BATTERY:
7190 p += sprintf(p, "(BATTERY)");
7194 "(Timeout %dms, Period %dms)",
7195 timeout_duration[level - 1] / 1000,
7196 period_duration[level - 1] / 1000);
7199 if (!(priv->power_mode & IWL_POWER_ENABLED))
7200 p += sprintf(p, " OFF\n");
7202 p += sprintf(p, " \n");
7208 static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
7211 static ssize_t show_channels(struct device *d,
7212 struct device_attribute *attr, char *buf)
7214 /* all this shit doesn't belong into sysfs anyway */
7218 static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
7220 static ssize_t show_statistics(struct device *d,
7221 struct device_attribute *attr, char *buf)
7223 struct iwl_priv *priv = dev_get_drvdata(d);
7224 u32 size = sizeof(struct iwl3945_notif_statistics);
7225 u32 len = 0, ofs = 0;
7226 u8 *data = (u8 *)&priv->statistics_39;
7229 if (!iwl_is_alive(priv))
7232 mutex_lock(&priv->mutex);
7233 rc = iwl3945_send_statistics_request(priv);
7234 mutex_unlock(&priv->mutex);
7238 "Error sending statistics request: 0x%08X\n", rc);
7242 while (size && (PAGE_SIZE - len)) {
7243 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
7244 PAGE_SIZE - len, 1);
7246 if (PAGE_SIZE - len)
7250 size -= min(size, 16U);
7256 static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
7258 static ssize_t show_antenna(struct device *d,
7259 struct device_attribute *attr, char *buf)
7261 struct iwl_priv *priv = dev_get_drvdata(d);
7263 if (!iwl_is_alive(priv))
7266 return sprintf(buf, "%d\n", priv->antenna);
7269 static ssize_t store_antenna(struct device *d,
7270 struct device_attribute *attr,
7271 const char *buf, size_t count)
7274 struct iwl_priv *priv = dev_get_drvdata(d);
7279 if (sscanf(buf, "%1i", &ant) != 1) {
7280 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7284 if ((ant >= 0) && (ant <= 2)) {
7285 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
7286 priv->antenna = (enum iwl3945_antenna)ant;
7288 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
7294 static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
7296 static ssize_t show_status(struct device *d,
7297 struct device_attribute *attr, char *buf)
7299 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
7300 if (!iwl_is_alive(priv))
7302 return sprintf(buf, "0x%08x\n", (int)priv->status);
7305 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
7307 static ssize_t dump_error_log(struct device *d,
7308 struct device_attribute *attr,
7309 const char *buf, size_t count)
7311 char *p = (char *)buf;
7314 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
7316 return strnlen(buf, count);
7319 static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
7321 static ssize_t dump_event_log(struct device *d,
7322 struct device_attribute *attr,
7323 const char *buf, size_t count)
7325 char *p = (char *)buf;
7328 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
7330 return strnlen(buf, count);
7333 static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
7335 /*****************************************************************************
7337 * driver setup and tear down
7339 *****************************************************************************/
7341 static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
7343 priv->workqueue = create_workqueue(DRV_NAME);
7345 init_waitqueue_head(&priv->wait_command_queue);
7347 INIT_WORK(&priv->up, iwl3945_bg_up);
7348 INIT_WORK(&priv->restart, iwl3945_bg_restart);
7349 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
7350 INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed);
7351 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
7352 INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan);
7353 INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill);
7354 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
7355 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
7356 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
7357 INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check);
7359 iwl3945_hw_setup_deferred_work(priv);
7361 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
7362 iwl3945_irq_tasklet, (unsigned long)priv);
7365 static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
7367 iwl3945_hw_cancel_deferred_work(priv);
7369 cancel_delayed_work_sync(&priv->init_alive_start);
7370 cancel_delayed_work(&priv->scan_check);
7371 cancel_delayed_work(&priv->alive_start);
7372 cancel_work_sync(&priv->beacon_update);
7375 static struct attribute *iwl3945_sysfs_entries[] = {
7376 &dev_attr_antenna.attr,
7377 &dev_attr_channels.attr,
7378 &dev_attr_dump_errors.attr,
7379 &dev_attr_dump_events.attr,
7380 &dev_attr_flags.attr,
7381 &dev_attr_filter_flags.attr,
7382 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
7383 &dev_attr_measurement.attr,
7385 &dev_attr_power_level.attr,
7386 &dev_attr_retry_rate.attr,
7387 &dev_attr_statistics.attr,
7388 &dev_attr_status.attr,
7389 &dev_attr_temperature.attr,
7390 &dev_attr_tx_power.attr,
7391 #ifdef CONFIG_IWL3945_DEBUG
7392 &dev_attr_debug_level.attr,
7397 static struct attribute_group iwl3945_attribute_group = {
7398 .name = NULL, /* put in device directory */
7399 .attrs = iwl3945_sysfs_entries,
7402 static struct ieee80211_ops iwl3945_hw_ops = {
7403 .tx = iwl3945_mac_tx,
7404 .start = iwl3945_mac_start,
7405 .stop = iwl3945_mac_stop,
7406 .add_interface = iwl3945_mac_add_interface,
7407 .remove_interface = iwl3945_mac_remove_interface,
7408 .config = iwl3945_mac_config,
7409 .config_interface = iwl3945_mac_config_interface,
7410 .configure_filter = iwl3945_configure_filter,
7411 .set_key = iwl3945_mac_set_key,
7412 .get_tx_stats = iwl3945_mac_get_tx_stats,
7413 .conf_tx = iwl3945_mac_conf_tx,
7414 .reset_tsf = iwl3945_mac_reset_tsf,
7415 .bss_info_changed = iwl3945_bss_info_changed,
7416 .hw_scan = iwl3945_mac_hw_scan
7419 int iwl3945_init_drv(struct iwl_priv *priv)
7423 priv->retry_rate = 1;
7424 priv->ibss_beacon = NULL;
7426 spin_lock_init(&priv->lock);
7427 spin_lock_init(&priv->power_data.lock);
7428 spin_lock_init(&priv->sta_lock);
7429 spin_lock_init(&priv->hcmd_lock);
7431 INIT_LIST_HEAD(&priv->free_frames);
7433 mutex_init(&priv->mutex);
7435 /* Clear the driver's (not device's) station table */
7436 iwl3945_clear_stations_table(priv);
7438 priv->data_retry_limit = -1;
7439 priv->ieee_channels = NULL;
7440 priv->ieee_rates = NULL;
7441 priv->band = IEEE80211_BAND_2GHZ;
7443 priv->iw_mode = NL80211_IFTYPE_STATION;
7445 iwl_reset_qos(priv);
7447 priv->qos_data.qos_active = 0;
7448 priv->qos_data.qos_cap.val = 0;
7450 priv->rates_mask = IWL_RATES_MASK;
7451 /* If power management is turned on, default to AC mode */
7452 priv->power_mode = IWL_POWER_AC;
7453 priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
7455 ret = iwl3945_init_channel_map(priv);
7457 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
7461 ret = iwl3945_init_geos(priv);
7463 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
7464 goto err_free_channel_map;
7469 err_free_channel_map:
7470 iwl3945_free_channel_map(priv);
7475 static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7478 struct iwl_priv *priv;
7479 struct ieee80211_hw *hw;
7480 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
7481 unsigned long flags;
7483 /***********************
7484 * 1. Allocating HW data
7485 * ********************/
7487 /* mac80211 allocates memory for this device instance, including
7488 * space for this driver's private structure */
7489 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
7491 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
7496 SET_IEEE80211_DEV(hw, &pdev->dev);
7498 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
7499 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
7501 "invalid queues_num, should be between %d and %d\n",
7502 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
7508 * Disabling hardware scan means that mac80211 will perform scans
7509 * "the hard way", rather than using device's scan.
7511 if (iwl3945_mod_params.disable_hw_scan) {
7512 IWL_DEBUG_INFO("Disabling hw_scan\n");
7513 iwl3945_hw_ops.hw_scan = NULL;
7517 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7519 priv->pci_dev = pdev;
7521 #ifdef CONFIG_IWL3945_DEBUG
7522 priv->debug_level = iwl3945_mod_params.debug;
7523 atomic_set(&priv->restrict_refcnt, 0);
7525 hw->rate_control_algorithm = "iwl-3945-rs";
7526 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
7528 /* Select antenna (may be helpful if only one antenna is connected) */
7529 priv->antenna = (enum iwl3945_antenna)iwl3945_mod_params.antenna;
7531 /* Tell mac80211 our characteristics */
7532 hw->flags = IEEE80211_HW_SIGNAL_DBM |
7533 IEEE80211_HW_NOISE_DBM;
7535 hw->wiphy->interface_modes =
7536 BIT(NL80211_IFTYPE_STATION) |
7537 BIT(NL80211_IFTYPE_ADHOC);
7539 hw->wiphy->fw_handles_regulatory = true;
7541 /* 4 EDCA QOS priorities */
7544 /***************************
7545 * 2. Initializing PCI bus
7546 * *************************/
7547 if (pci_enable_device(pdev)) {
7549 goto out_ieee80211_free_hw;
7552 pci_set_master(pdev);
7554 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
7556 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
7558 IWL_WARN(priv, "No suitable DMA available.\n");
7559 goto out_pci_disable_device;
7562 pci_set_drvdata(pdev, priv);
7563 err = pci_request_regions(pdev, DRV_NAME);
7565 goto out_pci_disable_device;
7567 /***********************
7568 * 3. Read REV Register
7569 * ********************/
7570 priv->hw_base = pci_iomap(pdev, 0, 0);
7571 if (!priv->hw_base) {
7573 goto out_pci_release_regions;
7576 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
7577 (unsigned long long) pci_resource_len(pdev, 0));
7578 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
7580 /* We disable the RETRY_TIMEOUT register (0x41) to keep
7581 * PCI Tx retries from interfering with C3 CPU state */
7582 pci_write_config_byte(pdev, 0x41, 0x00);
7585 err = priv->cfg->ops->lib->apm_ops.init(priv);
7587 IWL_DEBUG_INFO("Failed to init APMG\n");
7591 /***********************
7593 * ********************/
7595 /* Read the EEPROM */
7596 err = iwl3945_eeprom_init(priv);
7598 IWL_ERR(priv, "Unable to init EEPROM\n");
7599 goto out_remove_sysfs;
7601 /* MAC Address location in EEPROM same for 3945/4965 */
7602 get_eeprom_mac(priv, priv->mac_addr);
7603 IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
7604 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
7606 /***********************
7607 * 5. Setup HW Constants
7608 * ********************/
7609 /* Device-specific setup */
7610 if (iwl3945_hw_set_hw_params(priv)) {
7611 IWL_ERR(priv, "failed to set hw settings\n");
7615 /***********************
7617 * ********************/
7619 err = iwl3945_init_drv(priv);
7621 IWL_ERR(priv, "initializing driver failed\n");
7625 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
7628 /***********************************
7629 * 7. Initialize Module Parameters
7630 * **********************************/
7632 /* Initialize module parameter values here */
7633 /* Disable radio (SW RF KILL) via parameter when loading driver */
7634 if (iwl3945_mod_params.disable) {
7635 set_bit(STATUS_RF_KILL_SW, &priv->status);
7636 IWL_DEBUG_INFO("Radio disabled.\n");
7640 /***********************
7642 * ********************/
7644 spin_lock_irqsave(&priv->lock, flags);
7645 iwl3945_disable_interrupts(priv);
7646 spin_unlock_irqrestore(&priv->lock, flags);
7648 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
7650 IWL_ERR(priv, "failed to create sysfs device attributes\n");
7651 goto out_release_irq;
7654 iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
7655 iwl3945_setup_deferred_work(priv);
7656 iwl3945_setup_rx_handlers(priv);
7658 /***********************
7660 * ********************/
7661 pci_save_state(pdev);
7662 pci_disable_device(pdev);
7664 /*********************************
7665 * 10. Setup and Register mac80211
7666 * *******************************/
7668 err = ieee80211_register_hw(priv->hw);
7670 IWL_ERR(priv, "Failed to register network device: %d\n", err);
7671 goto out_remove_sysfs;
7674 priv->hw->conf.beacon_int = 100;
7675 priv->mac80211_registered = 1;
7677 err = iwl3945_rfkill_init(priv);
7679 IWL_ERR(priv, "Unable to initialize RFKILL system. "
7680 "Ignoring error: %d\n", err);
7685 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
7687 iwl3945_free_geos(priv);
7690 destroy_workqueue(priv->workqueue);
7691 priv->workqueue = NULL;
7692 iwl3945_unset_hw_params(priv);
7695 pci_iounmap(pdev, priv->hw_base);
7696 out_pci_release_regions:
7697 pci_release_regions(pdev);
7698 out_pci_disable_device:
7699 pci_disable_device(pdev);
7700 pci_set_drvdata(pdev, NULL);
7701 out_ieee80211_free_hw:
7702 ieee80211_free_hw(priv->hw);
7707 static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
7709 struct iwl_priv *priv = pci_get_drvdata(pdev);
7710 unsigned long flags;
7715 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
7717 set_bit(STATUS_EXIT_PENDING, &priv->status);
7719 if (priv->mac80211_registered) {
7720 ieee80211_unregister_hw(priv->hw);
7721 priv->mac80211_registered = 0;
7726 /* make sure we flush any pending irq or
7727 * tasklet for the driver
7729 spin_lock_irqsave(&priv->lock, flags);
7730 iwl3945_disable_interrupts(priv);
7731 spin_unlock_irqrestore(&priv->lock, flags);
7733 iwl_synchronize_irq(priv);
7735 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
7737 iwl3945_rfkill_unregister(priv);
7738 iwl3945_dealloc_ucode_pci(priv);
7741 iwl3945_rx_queue_free(priv, &priv->rxq);
7742 iwl3945_hw_txq_ctx_free(priv);
7744 iwl3945_unset_hw_params(priv);
7745 iwl3945_clear_stations_table(priv);
7747 /*netif_stop_queue(dev); */
7748 flush_workqueue(priv->workqueue);
7750 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
7751 * priv->workqueue... so we can't take down the workqueue
7753 destroy_workqueue(priv->workqueue);
7754 priv->workqueue = NULL;
7756 pci_iounmap(pdev, priv->hw_base);
7757 pci_release_regions(pdev);
7758 pci_disable_device(pdev);
7759 pci_set_drvdata(pdev, NULL);
7761 iwl3945_free_channel_map(priv);
7762 iwl3945_free_geos(priv);
7763 kfree(priv->scan39);
7764 if (priv->ibss_beacon)
7765 dev_kfree_skb(priv->ibss_beacon);
7767 ieee80211_free_hw(priv->hw);
7772 static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
7774 struct iwl_priv *priv = pci_get_drvdata(pdev);
7776 if (priv->is_open) {
7777 set_bit(STATUS_IN_SUSPEND, &priv->status);
7778 iwl3945_mac_stop(priv->hw);
7782 pci_set_power_state(pdev, PCI_D3hot);
7787 static int iwl3945_pci_resume(struct pci_dev *pdev)
7789 struct iwl_priv *priv = pci_get_drvdata(pdev);
7791 pci_set_power_state(pdev, PCI_D0);
7794 iwl3945_mac_start(priv->hw);
7796 clear_bit(STATUS_IN_SUSPEND, &priv->status);
7800 #endif /* CONFIG_PM */
7802 /*************** RFKILL FUNCTIONS **********/
7803 #ifdef CONFIG_IWL3945_RFKILL
7804 /* software rf-kill from user */
7805 static int iwl3945_rfkill_soft_rf_kill(void *data, enum rfkill_state state)
7807 struct iwl_priv *priv = data;
7813 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7816 IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state);
7817 mutex_lock(&priv->mutex);
7820 case RFKILL_STATE_UNBLOCKED:
7821 if (iwl_is_rfkill_hw(priv)) {
7825 iwl3945_radio_kill_sw(priv, 0);
7827 case RFKILL_STATE_SOFT_BLOCKED:
7828 iwl3945_radio_kill_sw(priv, 1);
7831 IWL_WARN(priv, "received unexpected RFKILL state %d\n", state);
7835 mutex_unlock(&priv->mutex);
7840 int iwl3945_rfkill_init(struct iwl_priv *priv)
7842 struct device *device = wiphy_dev(priv->hw->wiphy);
7845 BUG_ON(device == NULL);
7847 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
7848 priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN);
7849 if (!priv->rfkill) {
7850 IWL_ERR(priv, "Unable to allocate rfkill device.\n");
7855 priv->rfkill->name = priv->cfg->name;
7856 priv->rfkill->data = priv;
7857 priv->rfkill->state = RFKILL_STATE_UNBLOCKED;
7858 priv->rfkill->toggle_radio = iwl3945_rfkill_soft_rf_kill;
7859 priv->rfkill->user_claim_unsupported = 1;
7861 priv->rfkill->dev.class->suspend = NULL;
7862 priv->rfkill->dev.class->resume = NULL;
7864 ret = rfkill_register(priv->rfkill);
7866 IWL_ERR(priv, "Unable to register rfkill: %d\n", ret);
7870 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
7874 if (priv->rfkill != NULL)
7875 rfkill_free(priv->rfkill);
7876 priv->rfkill = NULL;
7879 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
7883 void iwl3945_rfkill_unregister(struct iwl_priv *priv)
7886 rfkill_unregister(priv->rfkill);
7888 priv->rfkill = NULL;
7891 /* set rf-kill to the right state. */
7892 void iwl3945_rfkill_set_hw_state(struct iwl_priv *priv)
7898 if (iwl_is_rfkill_hw(priv)) {
7899 rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED);
7903 if (!iwl_is_rfkill_sw(priv))
7904 rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED);
7906 rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED);
7910 /*****************************************************************************
7912 * driver and module entry point
7914 *****************************************************************************/
7916 static struct pci_driver iwl3945_driver = {
7918 .id_table = iwl3945_hw_card_ids,
7919 .probe = iwl3945_pci_probe,
7920 .remove = __devexit_p(iwl3945_pci_remove),
7922 .suspend = iwl3945_pci_suspend,
7923 .resume = iwl3945_pci_resume,
7927 static int __init iwl3945_init(void)
7931 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
7932 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
7934 ret = iwl3945_rate_control_register();
7936 printk(KERN_ERR DRV_NAME
7937 "Unable to register rate control algorithm: %d\n", ret);
7941 ret = pci_register_driver(&iwl3945_driver);
7943 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
7944 goto error_register;
7950 iwl3945_rate_control_unregister();
7954 static void __exit iwl3945_exit(void)
7956 pci_unregister_driver(&iwl3945_driver);
7957 iwl3945_rate_control_unregister();
7960 MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
7962 module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
7963 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
7964 module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
7965 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
7966 module_param_named(hwcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
7967 MODULE_PARM_DESC(hwcrypto,
7968 "using hardware crypto engine (default 0 [software])\n");
7969 module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
7970 MODULE_PARM_DESC(debug, "debug output mask");
7971 module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
7972 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
7974 module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
7975 MODULE_PARM_DESC(queues_num, "number of hw queues.");
7977 module_exit(iwl3945_exit);
7978 module_init(iwl3945_init);