Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 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. |
| 11 | * |
| 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 |
| 15 | * more details. |
| 16 | * |
| 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 |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 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> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 40 | #include <linux/etherdevice.h> |
| 41 | #include <linux/if_arp.h> |
| 42 | |
| 43 | #include <net/ieee80211_radiotap.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 44 | #include <net/lib80211.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 45 | #include <net/mac80211.h> |
| 46 | |
| 47 | #include <asm/div64.h> |
| 48 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 49 | #define DRV_NAME "iwl3945" |
| 50 | |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 51 | #include "iwl-fh.h" |
| 52 | #include "iwl-3945-fh.h" |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 53 | #include "iwl-commands.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 54 | #include "iwl-3945.h" |
| 55 | #include "iwl-helpers.h" |
Kolekar, Abhijeet | 5747d47 | 2008-12-19 10:37:18 +0800 | [diff] [blame] | 56 | #include "iwl-core.h" |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 57 | #include "iwl-dev.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 58 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 59 | static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 60 | struct iwl_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 61 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 62 | /* |
| 63 | * module name, copyright, version, etc. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 64 | */ |
| 65 | |
| 66 | #define DRV_DESCRIPTION \ |
| 67 | "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux" |
| 68 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 69 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 70 | #define VD "d" |
| 71 | #else |
| 72 | #define VD |
| 73 | #endif |
| 74 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 75 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 76 | #define VS "s" |
| 77 | #else |
| 78 | #define VS |
| 79 | #endif |
| 80 | |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 81 | #define IWL39_VERSION "1.2.26k" VD VS |
Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 82 | #define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation" |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 83 | #define DRV_AUTHOR "<ilw@linux.intel.com>" |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 84 | #define DRV_VERSION IWL39_VERSION |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 85 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 86 | |
| 87 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 88 | MODULE_VERSION(DRV_VERSION); |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 89 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 90 | MODULE_LICENSE("GPL"); |
| 91 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 92 | /* module parameters */ |
| 93 | struct iwl_mod_params iwl3945_mod_params = { |
| 94 | .num_of_queues = IWL39_MAX_NUM_QUEUES, |
Samuel Ortiz | 9c74d9f | 2009-01-08 10:19:59 -0800 | [diff] [blame] | 95 | .sw_crypto = 1, |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 96 | /* the rest are 0 by default */ |
| 97 | }; |
| 98 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 99 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 100 | * DMA services |
| 101 | * |
| 102 | * Theory of operation |
| 103 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 104 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 105 | * of buffer descriptors, each of which points to one or more data buffers for |
| 106 | * the device to read from or fill. Driver and device exchange status of each |
| 107 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 108 | * entries in each circular buffer, to protect against confusing empty and full |
| 109 | * queue states. |
| 110 | * |
| 111 | * The device reads or writes the data in the queues via the device's several |
| 112 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 113 | * |
| 114 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 115 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 116 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 117 | * Tx queue resumed. |
| 118 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 119 | * The 3945 operates with six queues: One receive queue, one transmit queue |
| 120 | * (#4) for sending commands to the device firmware, and four transmit queues |
| 121 | * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 122 | ***************************************************/ |
| 123 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 124 | /** |
| 125 | * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes |
| 126 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 127 | static int iwl3945_queue_init(struct iwl_priv *priv, struct iwl_queue *q, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 128 | int count, int slots_num, u32 id) |
| 129 | { |
| 130 | q->n_bd = count; |
| 131 | q->n_window = slots_num; |
| 132 | q->id = id; |
| 133 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 134 | /* count must be power-of-two size, otherwise iwl_queue_inc_wrap |
| 135 | * and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 136 | BUG_ON(!is_power_of_2(count)); |
| 137 | |
| 138 | /* slots_num must be power-of-two size, otherwise |
| 139 | * get_cmd_index is broken. */ |
| 140 | BUG_ON(!is_power_of_2(slots_num)); |
| 141 | |
| 142 | q->low_mark = q->n_window / 4; |
| 143 | if (q->low_mark < 4) |
| 144 | q->low_mark = 4; |
| 145 | |
| 146 | q->high_mark = q->n_window / 8; |
| 147 | if (q->high_mark < 2) |
| 148 | q->high_mark = 2; |
| 149 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 150 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 155 | /** |
| 156 | * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 157 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 158 | static int iwl3945_tx_queue_alloc(struct iwl_priv *priv, |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 159 | struct iwl_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 160 | { |
| 161 | struct pci_dev *dev = priv->pci_dev; |
| 162 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 163 | /* Driver private data, only for Tx (not command) queues, |
| 164 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 165 | if (id != IWL_CMD_QUEUE_NUM) { |
| 166 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 167 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 168 | if (!txq->txb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 169 | IWL_ERR(priv, "kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 170 | "structures failed\n"); |
| 171 | goto error; |
| 172 | } |
| 173 | } else |
| 174 | txq->txb = NULL; |
| 175 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 176 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 177 | * shared with device */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 178 | txq->tfds39 = pci_alloc_consistent(dev, |
| 179 | sizeof(txq->tfds39[0]) * TFD_QUEUE_SIZE_MAX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 180 | &txq->q.dma_addr); |
| 181 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 182 | if (!txq->tfds39) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 183 | IWL_ERR(priv, "pci_alloc_consistent(%zd) failed\n", |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 184 | sizeof(txq->tfds39[0]) * TFD_QUEUE_SIZE_MAX); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 185 | goto error; |
| 186 | } |
| 187 | txq->q.id = id; |
| 188 | |
| 189 | return 0; |
| 190 | |
| 191 | error: |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 192 | kfree(txq->txb); |
| 193 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 194 | |
| 195 | return -ENOMEM; |
| 196 | } |
| 197 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 198 | /** |
| 199 | * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 200 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 201 | int iwl3945_tx_queue_init(struct iwl_priv *priv, |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 202 | struct iwl_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 203 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 204 | int len, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 205 | int rc = 0; |
| 206 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 207 | /* |
| 208 | * Alloc buffer array for commands (Tx or other types of commands). |
| 209 | * For the command queue (#4), allocate command space + one big |
| 210 | * command for scan, since scan command is very huge; the system will |
| 211 | * not have two scans at the same time, so only one is needed. |
| 212 | * For data Tx queues (all other queues), no super-size command |
| 213 | * space is needed. |
| 214 | */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 215 | len = sizeof(struct iwl_cmd); |
| 216 | for (i = 0; i <= slots_num; i++) { |
| 217 | if (i == slots_num) { |
| 218 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 219 | len += IWL_MAX_SCAN_SIZE; |
| 220 | else |
| 221 | continue; |
| 222 | } |
| 223 | |
| 224 | txq->cmd[i] = kmalloc(len, GFP_KERNEL); |
| 225 | if (!txq->cmd[i]) |
| 226 | goto err; |
| 227 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 228 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 229 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 230 | rc = iwl3945_tx_queue_alloc(priv, txq, txq_id); |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 231 | if (rc) |
| 232 | goto err; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 233 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 234 | txq->need_update = 0; |
| 235 | |
| 236 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 237 | * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 238 | BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 239 | |
| 240 | /* Initialize queue high/low-water, head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 241 | iwl3945_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 242 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 243 | /* Tell device where to find queue, enable DMA channel. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 244 | iwl3945_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 245 | |
| 246 | return 0; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 247 | err: |
| 248 | for (i = 0; i < slots_num; i++) { |
| 249 | kfree(txq->cmd[i]); |
| 250 | txq->cmd[i] = NULL; |
| 251 | } |
| 252 | |
| 253 | if (txq_id == IWL_CMD_QUEUE_NUM) { |
| 254 | kfree(txq->cmd[slots_num]); |
| 255 | txq->cmd[slots_num] = NULL; |
| 256 | } |
| 257 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 261 | * iwl3945_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 262 | * @txq: Transmit queue to deallocate. |
| 263 | * |
| 264 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 265 | * Free all buffers. |
| 266 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 267 | */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 268 | void iwl3945_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 269 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 270 | struct iwl_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 271 | struct pci_dev *dev = priv->pci_dev; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 272 | int len, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 273 | |
| 274 | if (q->n_bd == 0) |
| 275 | return; |
| 276 | |
| 277 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 278 | for (; q->write_ptr != q->read_ptr; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 279 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 280 | iwl3945_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 281 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 282 | len = sizeof(struct iwl_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 283 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 284 | len += IWL_MAX_SCAN_SIZE; |
| 285 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 286 | /* De-alloc array of command/tx buffers */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 287 | for (i = 0; i < TFD_TX_CMD_SLOTS; i++) |
| 288 | kfree(txq->cmd[i]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 289 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 290 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 291 | if (txq->q.n_bd) |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 292 | pci_free_consistent(dev, sizeof(struct iwl3945_tfd) * |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 293 | txq->q.n_bd, txq->tfds39, txq->q.dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 294 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 295 | /* De-alloc array of per-TFD driver data */ |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 296 | kfree(txq->txb); |
| 297 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 298 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 299 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 300 | memset(txq, 0, sizeof(*txq)); |
| 301 | } |
| 302 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 303 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 304 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 305 | * the functionality provided here |
| 306 | */ |
| 307 | |
| 308 | /**************************************************************/ |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 309 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 310 | /** |
| 311 | * iwl3945_remove_station - Remove driver's knowledge of station. |
| 312 | * |
| 313 | * NOTE: This does not remove station from device's station table. |
| 314 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 315 | static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 316 | { |
| 317 | int index = IWL_INVALID_STATION; |
| 318 | int i; |
| 319 | unsigned long flags; |
| 320 | |
| 321 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 322 | |
| 323 | if (is_ap) |
| 324 | index = IWL_AP_ID; |
| 325 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 326 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 327 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 328 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 329 | if (priv->stations_39[i].used && |
| 330 | !compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 331 | addr)) { |
| 332 | index = i; |
| 333 | break; |
| 334 | } |
| 335 | |
| 336 | if (unlikely(index == IWL_INVALID_STATION)) |
| 337 | goto out; |
| 338 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 339 | if (priv->stations_39[index].used) { |
| 340 | priv->stations_39[index].used = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 341 | priv->num_stations--; |
| 342 | } |
| 343 | |
| 344 | BUG_ON(priv->num_stations < 0); |
| 345 | |
| 346 | out: |
| 347 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 348 | return 0; |
| 349 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 350 | #endif |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 351 | |
| 352 | /** |
| 353 | * iwl3945_clear_stations_table - Clear the driver's station table |
| 354 | * |
| 355 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 356 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 357 | static void iwl3945_clear_stations_table(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 358 | { |
| 359 | unsigned long flags; |
| 360 | |
| 361 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 362 | |
| 363 | priv->num_stations = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 364 | memset(priv->stations_39, 0, sizeof(priv->stations_39)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 365 | |
| 366 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 367 | } |
| 368 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 369 | /** |
| 370 | * iwl3945_add_station - Add station to station tables in driver and device |
| 371 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 372 | u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 373 | { |
| 374 | int i; |
| 375 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 376 | struct iwl3945_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 377 | unsigned long flags_spin; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 378 | u8 rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 379 | |
| 380 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 381 | if (is_ap) |
| 382 | index = IWL_AP_ID; |
| 383 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 384 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 385 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 386 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 387 | if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 388 | addr)) { |
| 389 | index = i; |
| 390 | break; |
| 391 | } |
| 392 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 393 | if (!priv->stations_39[i].used && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 394 | index == IWL_INVALID_STATION) |
| 395 | index = i; |
| 396 | } |
| 397 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 398 | /* These two conditions has the same outcome but keep them separate |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 399 | since they have different meaning */ |
| 400 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 401 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 402 | return index; |
| 403 | } |
| 404 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 405 | if (priv->stations_39[index].used && |
| 406 | !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 407 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 408 | return index; |
| 409 | } |
| 410 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 411 | IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 412 | station = &priv->stations_39[index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 413 | station->used = 1; |
| 414 | priv->num_stations++; |
| 415 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 416 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 417 | memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 418 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 419 | station->sta.mode = 0; |
| 420 | station->sta.sta.sta_id = index; |
| 421 | station->sta.station_flags = 0; |
| 422 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 423 | if (priv->band == IEEE80211_BAND_5GHZ) |
Tomas Winkler | 6994633 | 2007-10-25 17:15:27 +0800 | [diff] [blame] | 424 | rate = IWL_RATE_6M_PLCP; |
| 425 | else |
| 426 | rate = IWL_RATE_1M_PLCP; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 427 | |
| 428 | /* Turn on both antennas for the station... */ |
| 429 | station->sta.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 430 | iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 431 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 432 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 433 | |
| 434 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 435 | iwl3945_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 436 | return index; |
| 437 | |
| 438 | } |
| 439 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 440 | |
| 441 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 442 | |
Abhijeet Kolekar | c305606 | 2008-11-12 13:14:08 -0800 | [diff] [blame] | 443 | #define IWL_CMD(x) case x: return #x |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 444 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 445 | |
| 446 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 447 | * iwl3945_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 448 | * @priv: device private data point |
| 449 | * @cmd: a point to the ucode command structure |
| 450 | * |
| 451 | * The function returns < 0 values to indicate the operation is |
| 452 | * failed. On success, it turns the index (> 0) of command in the |
| 453 | * command queue. |
| 454 | */ |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 455 | static int iwl3945_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 456 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 457 | struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 458 | struct iwl_queue *q = &txq->q; |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 459 | struct iwl3945_tfd *tfd; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 460 | struct iwl_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 461 | u32 idx; |
| 462 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 463 | dma_addr_t phys_addr; |
| 464 | int pad; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 465 | int ret, len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 466 | unsigned long flags; |
| 467 | |
| 468 | /* If any of the command structures end up being larger than |
| 469 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 470 | * we will need to increase the size of the TFD entries */ |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 471 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 472 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 473 | |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 474 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 475 | if (iwl_is_rfkill(priv)) { |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 476 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 477 | return -EIO; |
| 478 | } |
| 479 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 480 | if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 481 | IWL_ERR(priv, "No space for Tx\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 482 | return -ENOSPC; |
| 483 | } |
| 484 | |
| 485 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 486 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 487 | tfd = &txq->tfds39[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 488 | memset(tfd, 0, sizeof(*tfd)); |
| 489 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 490 | idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE); |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 491 | out_cmd = txq->cmd[idx]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 492 | |
| 493 | out_cmd->hdr.cmd = cmd->id; |
| 494 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 495 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 496 | |
| 497 | /* At this point, the out_cmd now has all of the incoming cmd |
| 498 | * information */ |
| 499 | |
| 500 | out_cmd->hdr.flags = 0; |
| 501 | out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 502 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 503 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 504 | out_cmd->hdr.sequence |= SEQ_HUGE_FRAME; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 505 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 506 | len = (idx == TFD_CMD_SLOTS) ? |
| 507 | IWL_MAX_SCAN_SIZE : sizeof(struct iwl_cmd); |
| 508 | |
| 509 | phys_addr = pci_map_single(priv->pci_dev, out_cmd, |
| 510 | len, PCI_DMA_TODEVICE); |
| 511 | pci_unmap_addr_set(&out_cmd->meta, mapping, phys_addr); |
| 512 | pci_unmap_len_set(&out_cmd->meta, len, len); |
| 513 | phys_addr += offsetof(struct iwl_cmd, hdr); |
| 514 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 515 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 516 | |
| 517 | pad = U32_PAD(cmd->len); |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 518 | tfd->control_flags |= cpu_to_le32(TFD_CTL_PAD_SET(pad)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 519 | |
| 520 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 521 | "%d bytes at %d[%d]:%d\n", |
| 522 | get_cmd_string(out_cmd->hdr.cmd), |
| 523 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 524 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 525 | |
| 526 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 527 | |
| 528 | /* Increment and update queue's write index */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 529 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 530 | ret = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 531 | |
| 532 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 533 | return ret ? ret : idx; |
| 534 | } |
| 535 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 536 | static int iwl3945_send_cmd_async(struct iwl_priv *priv, |
| 537 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 538 | { |
| 539 | int ret; |
| 540 | |
| 541 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 542 | |
| 543 | /* An asynchronous command can not expect an SKB to be set. */ |
| 544 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 545 | |
| 546 | /* An asynchronous command MUST have a callback. */ |
| 547 | BUG_ON(!cmd->meta.u.callback); |
| 548 | |
| 549 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 550 | return -EBUSY; |
| 551 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 552 | ret = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 553 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 554 | IWL_ERR(priv, |
| 555 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 556 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 557 | return ret; |
| 558 | } |
| 559 | return 0; |
| 560 | } |
| 561 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 562 | static int iwl3945_send_cmd_sync(struct iwl_priv *priv, |
| 563 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 564 | { |
| 565 | int cmd_idx; |
| 566 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 567 | |
| 568 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 569 | |
| 570 | /* A synchronous command can not have a callback set. */ |
| 571 | BUG_ON(cmd->meta.u.callback != NULL); |
| 572 | |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 573 | if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 574 | IWL_ERR(priv, |
| 575 | "Error sending %s: Already sending a host command\n", |
| 576 | get_cmd_string(cmd->id)); |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 577 | ret = -EBUSY; |
| 578 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 582 | |
| 583 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 584 | cmd->meta.source = &cmd->meta; |
| 585 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 586 | cmd_idx = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 587 | if (cmd_idx < 0) { |
| 588 | ret = cmd_idx; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 589 | IWL_ERR(priv, |
| 590 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 591 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 592 | goto out; |
| 593 | } |
| 594 | |
| 595 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 596 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 597 | HOST_COMPLETE_TIMEOUT); |
| 598 | if (!ret) { |
| 599 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 600 | IWL_ERR(priv, "Error sending %s: time out after %dms\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 601 | get_cmd_string(cmd->id), |
| 602 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 603 | |
| 604 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 605 | ret = -ETIMEDOUT; |
| 606 | goto cancel; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 611 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 612 | get_cmd_string(cmd->id)); |
| 613 | ret = -ECANCELED; |
| 614 | goto fail; |
| 615 | } |
| 616 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 617 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 618 | get_cmd_string(cmd->id)); |
| 619 | ret = -EIO; |
| 620 | goto fail; |
| 621 | } |
| 622 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 623 | IWL_ERR(priv, "Error: Response NULL in '%s'\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 624 | get_cmd_string(cmd->id)); |
| 625 | ret = -EIO; |
Zhu Yi | 73e1a65 | 2009-01-08 10:19:58 -0800 | [diff] [blame] | 626 | goto cancel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | ret = 0; |
| 630 | goto out; |
| 631 | |
| 632 | cancel: |
| 633 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 634 | struct iwl_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 635 | |
| 636 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 637 | * TX cmd queue. Otherwise in case the cmd comes |
| 638 | * in later, it will possibly set an invalid |
| 639 | * address (cmd->meta.source). */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 640 | qcmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 641 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 642 | } |
| 643 | fail: |
| 644 | if (cmd->meta.u.skb) { |
| 645 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 646 | cmd->meta.u.skb = NULL; |
| 647 | } |
| 648 | out: |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 649 | clear_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 650 | return ret; |
| 651 | } |
| 652 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 653 | int iwl3945_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 654 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 655 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 656 | return iwl3945_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 657 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 658 | return iwl3945_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 661 | int iwl3945_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 662 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 663 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 664 | .id = id, |
| 665 | .len = len, |
| 666 | .data = data, |
| 667 | }; |
| 668 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 669 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 672 | static int __must_check iwl3945_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 673 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 674 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 675 | .id = id, |
| 676 | .len = sizeof(val), |
| 677 | .data = &val, |
| 678 | }; |
| 679 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 680 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 683 | int iwl3945_send_statistics_request(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 684 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 685 | return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 689 | * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 690 | * @band: 2.4 or 5 GHz band |
| 691 | * @channel: Any channel valid for the requested band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 692 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 693 | * In addition to setting the staging RXON, priv->band is also set. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 694 | * |
| 695 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 696 | * in the staging RXON flag structure based on the band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 697 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 698 | static int iwl3945_set_rxon_channel(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 699 | enum ieee80211_band band, |
| 700 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 701 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 702 | if (!iwl3945_get_channel_info(priv, band, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 703 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 704 | channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 705 | return -EINVAL; |
| 706 | } |
| 707 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 708 | if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 709 | (priv->band == band)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 710 | return 0; |
| 711 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 712 | priv->staging39_rxon.channel = cpu_to_le16(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 713 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 714 | priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 715 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 716 | priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 717 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 718 | priv->band = band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 719 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 720 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 721 | |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 726 | * iwl3945_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 727 | * |
| 728 | * NOTE: This is really only useful during development and can eventually |
| 729 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 730 | * making changes |
| 731 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 732 | static int iwl3945_check_rxon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 733 | { |
| 734 | int error = 0; |
| 735 | int counter = 1; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 736 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 737 | |
| 738 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 739 | error |= le32_to_cpu(rxon->flags & |
| 740 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 741 | RXON_FLG_RADAR_DETECT_MSK)); |
| 742 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 743 | IWL_WARN(priv, "check 24G fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 744 | counter++, error); |
| 745 | } else { |
| 746 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 747 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 748 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 749 | IWL_WARN(priv, "check 52 fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 750 | counter++, error); |
| 751 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 752 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 753 | IWL_WARN(priv, "check 52 CCK %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 754 | counter++, error); |
| 755 | } |
| 756 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 757 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 758 | IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 759 | |
| 760 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 761 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 762 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 763 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 764 | IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 765 | |
| 766 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 767 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 768 | IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 769 | |
| 770 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 771 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 772 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 773 | IWL_WARN(priv, "check CCK and short slot %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 774 | counter++, error); |
| 775 | |
| 776 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 777 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 778 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 779 | IWL_WARN(priv, "check CCK & auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 780 | counter++, error); |
| 781 | |
| 782 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 783 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 784 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 785 | IWL_WARN(priv, "check TGG and auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 786 | counter++, error); |
| 787 | |
| 788 | if ((rxon->flags & RXON_FLG_DIS_DIV_MSK)) |
| 789 | error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK | |
| 790 | RXON_FLG_ANT_A_MSK)) == 0); |
| 791 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 792 | IWL_WARN(priv, "check antenna %d %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 793 | |
| 794 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 795 | IWL_WARN(priv, "Tuning to channel %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 796 | le16_to_cpu(rxon->channel)); |
| 797 | |
| 798 | if (error) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 799 | IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 800 | return -1; |
| 801 | } |
| 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 806 | * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 807 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 808 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 809 | * If the RXON structure is changing enough to require a new tune, |
| 810 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 811 | * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 812 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 813 | static int iwl3945_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 814 | { |
| 815 | |
| 816 | /* These items are only settable from the full RXON command */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 817 | if (!(iwl3945_is_associated(priv)) || |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 818 | compare_ether_addr(priv->staging39_rxon.bssid_addr, |
| 819 | priv->active39_rxon.bssid_addr) || |
| 820 | compare_ether_addr(priv->staging39_rxon.node_addr, |
| 821 | priv->active39_rxon.node_addr) || |
| 822 | compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr, |
| 823 | priv->active39_rxon.wlap_bssid_addr) || |
| 824 | (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) || |
| 825 | (priv->staging39_rxon.channel != priv->active39_rxon.channel) || |
| 826 | (priv->staging39_rxon.air_propagation != |
| 827 | priv->active39_rxon.air_propagation) || |
| 828 | (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 829 | return 1; |
| 830 | |
| 831 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 832 | * be updated with the RXON_ASSOC command -- however only some |
| 833 | * flag transitions are allowed using RXON_ASSOC */ |
| 834 | |
| 835 | /* Check if we are not switching bands */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 836 | if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 837 | (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 838 | return 1; |
| 839 | |
| 840 | /* Check if we are switching association toggle */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 841 | if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 842 | (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 843 | return 1; |
| 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 848 | static int iwl3945_send_rxon_assoc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 849 | { |
| 850 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 851 | struct iwl_rx_packet *res = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 852 | struct iwl3945_rxon_assoc_cmd rxon_assoc; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 853 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 854 | .id = REPLY_RXON_ASSOC, |
| 855 | .len = sizeof(rxon_assoc), |
| 856 | .meta.flags = CMD_WANT_SKB, |
| 857 | .data = &rxon_assoc, |
| 858 | }; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 859 | const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon; |
| 860 | const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 861 | |
| 862 | if ((rxon1->flags == rxon2->flags) && |
| 863 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 864 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 865 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 866 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 867 | return 0; |
| 868 | } |
| 869 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 870 | rxon_assoc.flags = priv->staging39_rxon.flags; |
| 871 | rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags; |
| 872 | rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates; |
| 873 | rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 874 | rxon_assoc.reserved = 0; |
| 875 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 876 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 877 | if (rc) |
| 878 | return rc; |
| 879 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 880 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 881 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 882 | IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 883 | rc = -EIO; |
| 884 | } |
| 885 | |
| 886 | priv->alloc_rxb_skb--; |
| 887 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 888 | |
| 889 | return rc; |
| 890 | } |
| 891 | |
| 892 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 893 | * iwl3945_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 894 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 895 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 896 | * the active_rxon structure is updated with the new data. This |
| 897 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 898 | * a HW tune is required based on the RXON structure changes. |
| 899 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 900 | static int iwl3945_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 901 | { |
| 902 | /* cast away the const for active_rxon in this function */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 903 | struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 904 | int rc = 0; |
| 905 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 906 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 907 | return -1; |
| 908 | |
| 909 | /* always get timestamp with Rx frame */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 910 | priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 911 | |
| 912 | /* select antenna */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 913 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 914 | ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 915 | priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 916 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 917 | rc = iwl3945_check_rxon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 918 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 919 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 920 | return -EINVAL; |
| 921 | } |
| 922 | |
| 923 | /* If we don't need to send a full RXON, we can use |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 924 | * iwl3945_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 925 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 926 | if (!iwl3945_full_rxon_required(priv)) { |
| 927 | rc = iwl3945_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 928 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 929 | IWL_ERR(priv, "Error setting RXON_ASSOC " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 930 | "configuration (%d).\n", rc); |
| 931 | return rc; |
| 932 | } |
| 933 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 934 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
| 939 | /* If we are currently associated and the new config requires |
| 940 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 941 | * we must clear the associated from the active configuration |
| 942 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 943 | if (iwl3945_is_associated(priv) && |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 944 | (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 945 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 946 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 947 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 948 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
| 949 | sizeof(struct iwl3945_rxon_cmd), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 950 | &priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 951 | |
| 952 | /* If the mask clearing failed then we set |
| 953 | * active_rxon back to what it was previously */ |
| 954 | if (rc) { |
| 955 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 956 | IWL_ERR(priv, "Error clearing ASSOC_MSK on current " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 957 | "configuration (%d).\n", rc); |
| 958 | return rc; |
| 959 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | IWL_DEBUG_INFO("Sending RXON\n" |
| 963 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 964 | "* channel = %d\n" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 965 | "* bssid = %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 966 | ((priv->staging39_rxon.filter_flags & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 967 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 968 | le16_to_cpu(priv->staging39_rxon.channel), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 969 | priv->staging_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 970 | |
| 971 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 972 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 973 | sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 974 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 975 | IWL_ERR(priv, "Error setting new configuration (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 976 | return rc; |
| 977 | } |
| 978 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 979 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 980 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 981 | iwl3945_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 982 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 983 | /* If we issue a new RXON command which required a tune then we must |
| 984 | * send a new TXPOWER command or we won't be able to Tx any frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 985 | rc = iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 986 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 987 | IWL_ERR(priv, "Error setting Tx power (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 988 | return rc; |
| 989 | } |
| 990 | |
| 991 | /* Add the broadcast address so we can send broadcast frames */ |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 992 | if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 993 | IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 994 | IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 995 | return -EIO; |
| 996 | } |
| 997 | |
| 998 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 999 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1000 | if (iwl3945_is_associated(priv) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1001 | (priv->iw_mode == NL80211_IFTYPE_STATION)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1002 | if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1003 | == IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1004 | IWL_ERR(priv, "Error adding AP address for transmit\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1005 | return -EIO; |
| 1006 | } |
| 1007 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1008 | /* Init the hardware's rate fallback order based on the band */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1009 | rc = iwl3945_init_hw_rate_table(priv); |
| 1010 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1011 | IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1012 | return -EIO; |
| 1013 | } |
| 1014 | |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1018 | static int iwl3945_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1019 | { |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1020 | struct iwl_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1021 | .flags = 3, |
| 1022 | .lead_time = 0xAA, |
| 1023 | .max_kill = 1, |
| 1024 | .kill_ack_mask = 0, |
| 1025 | .kill_cts_mask = 0, |
| 1026 | }; |
| 1027 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1028 | return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1029 | sizeof(bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1032 | static int iwl3945_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1033 | { |
| 1034 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1035 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1036 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1037 | .id = REPLY_SCAN_ABORT_CMD, |
| 1038 | .meta.flags = CMD_WANT_SKB, |
| 1039 | }; |
| 1040 | |
| 1041 | /* If there isn't a scan actively going on in the hardware |
| 1042 | * then we are in between scan bands and not actually |
| 1043 | * actively scanning, so don't send the abort command */ |
| 1044 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1045 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1046 | return 0; |
| 1047 | } |
| 1048 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1049 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1050 | if (rc) { |
| 1051 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1052 | return rc; |
| 1053 | } |
| 1054 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1055 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1056 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1057 | /* The scan abort will return 1 for success or |
| 1058 | * 2 for "failure". A failure condition can be |
| 1059 | * due to simply not being in an active scan which |
| 1060 | * can occur if we send the scan abort before we |
| 1061 | * the microcode has notified us that a scan is |
| 1062 | * completed. */ |
| 1063 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1064 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1065 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1066 | } |
| 1067 | |
| 1068 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1069 | |
| 1070 | return rc; |
| 1071 | } |
| 1072 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1073 | static int iwl3945_add_sta_sync_callback(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1074 | struct iwl_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1075 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1076 | struct iwl_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1077 | |
| 1078 | if (!skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1079 | IWL_ERR(priv, "Error: Response NULL in REPLY_ADD_STA.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1080 | return 1; |
| 1081 | } |
| 1082 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1083 | res = (struct iwl_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1084 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1085 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1086 | res->hdr.flags); |
| 1087 | return 1; |
| 1088 | } |
| 1089 | |
| 1090 | switch (res->u.add_sta.status) { |
| 1091 | case ADD_STA_SUCCESS_MSK: |
| 1092 | break; |
| 1093 | default: |
| 1094 | break; |
| 1095 | } |
| 1096 | |
| 1097 | /* We didn't cache the SKB; let the caller free it */ |
| 1098 | return 1; |
| 1099 | } |
| 1100 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1101 | int iwl3945_send_add_station(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1102 | struct iwl3945_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1103 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1104 | struct iwl_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1105 | int rc = 0; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1106 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1107 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1108 | .len = sizeof(struct iwl3945_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1109 | .meta.flags = flags, |
| 1110 | .data = sta, |
| 1111 | }; |
| 1112 | |
| 1113 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1114 | cmd.meta.u.callback = iwl3945_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1115 | else |
| 1116 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1117 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1118 | rc = iwl3945_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1119 | |
| 1120 | if (rc || (flags & CMD_ASYNC)) |
| 1121 | return rc; |
| 1122 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1123 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1124 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1125 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1126 | res->hdr.flags); |
| 1127 | rc = -EIO; |
| 1128 | } |
| 1129 | |
| 1130 | if (rc == 0) { |
| 1131 | switch (res->u.add_sta.status) { |
| 1132 | case ADD_STA_SUCCESS_MSK: |
| 1133 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1134 | break; |
| 1135 | default: |
| 1136 | rc = -EIO; |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1137 | IWL_WARN(priv, "REPLY_ADD_STA failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1138 | break; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | priv->alloc_rxb_skb--; |
| 1143 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1144 | |
| 1145 | return rc; |
| 1146 | } |
| 1147 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1148 | static int iwl3945_update_sta_key_info(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1149 | struct ieee80211_key_conf *keyconf, |
| 1150 | u8 sta_id) |
| 1151 | { |
| 1152 | unsigned long flags; |
| 1153 | __le16 key_flags = 0; |
| 1154 | |
| 1155 | switch (keyconf->alg) { |
| 1156 | case ALG_CCMP: |
| 1157 | key_flags |= STA_KEY_FLG_CCMP; |
| 1158 | key_flags |= cpu_to_le16( |
| 1159 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1160 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1161 | break; |
| 1162 | case ALG_TKIP: |
| 1163 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1164 | default: |
| 1165 | return -EINVAL; |
| 1166 | } |
| 1167 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1168 | priv->stations_39[sta_id].keyinfo.alg = keyconf->alg; |
| 1169 | priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1170 | memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1171 | keyconf->keylen); |
| 1172 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1173 | memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1174 | keyconf->keylen); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1175 | priv->stations_39[sta_id].sta.key.key_flags = key_flags; |
| 1176 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1177 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1178 | |
| 1179 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1180 | |
| 1181 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1182 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1183 | return 0; |
| 1184 | } |
| 1185 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1186 | static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1187 | { |
| 1188 | unsigned long flags; |
| 1189 | |
| 1190 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1191 | memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key)); |
| 1192 | memset(&priv->stations_39[sta_id].sta.key, 0, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1193 | sizeof(struct iwl4965_keyinfo)); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1194 | priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 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; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1197 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1198 | |
| 1199 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1200 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1201 | return 0; |
| 1202 | } |
| 1203 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1204 | static void iwl3945_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1205 | { |
| 1206 | struct list_head *element; |
| 1207 | |
| 1208 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1209 | priv->frames_count); |
| 1210 | |
| 1211 | while (!list_empty(&priv->free_frames)) { |
| 1212 | element = priv->free_frames.next; |
| 1213 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1214 | kfree(list_entry(element, struct iwl3945_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1215 | priv->frames_count--; |
| 1216 | } |
| 1217 | |
| 1218 | if (priv->frames_count) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1219 | IWL_WARN(priv, "%d frames still in use. Did we lose one?\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1220 | priv->frames_count); |
| 1221 | priv->frames_count = 0; |
| 1222 | } |
| 1223 | } |
| 1224 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1225 | static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1226 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1227 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1228 | struct list_head *element; |
| 1229 | if (list_empty(&priv->free_frames)) { |
| 1230 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1231 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1232 | IWL_ERR(priv, "Could not allocate frame!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1233 | return NULL; |
| 1234 | } |
| 1235 | |
| 1236 | priv->frames_count++; |
| 1237 | return frame; |
| 1238 | } |
| 1239 | |
| 1240 | element = priv->free_frames.next; |
| 1241 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1242 | return list_entry(element, struct iwl3945_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1243 | } |
| 1244 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1245 | static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1246 | { |
| 1247 | memset(frame, 0, sizeof(*frame)); |
| 1248 | list_add(&frame->list, &priv->free_frames); |
| 1249 | } |
| 1250 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1251 | unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1252 | struct ieee80211_hdr *hdr, |
Rami Rosen | 73ec1cc | 2008-12-16 09:37:07 +0200 | [diff] [blame] | 1253 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1254 | { |
| 1255 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1256 | if (!iwl3945_is_associated(priv) || !priv->ibss_beacon || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1257 | ((priv->iw_mode != NL80211_IFTYPE_ADHOC) && |
| 1258 | (priv->iw_mode != NL80211_IFTYPE_AP))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1259 | return 0; |
| 1260 | |
| 1261 | if (priv->ibss_beacon->len > left) |
| 1262 | return 0; |
| 1263 | |
| 1264 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1265 | |
| 1266 | return priv->ibss_beacon->len; |
| 1267 | } |
| 1268 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1269 | static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1270 | { |
| 1271 | u8 i; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1272 | int rate_mask; |
| 1273 | |
| 1274 | /* Set rate mask*/ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1275 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1276 | rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1277 | else |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1278 | rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1279 | |
| 1280 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1281 | i = iwl3945_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1282 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1283 | return iwl3945_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1286 | /* No valid rate was found. Assign the lowest one */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1287 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1288 | return IWL_RATE_1M_PLCP; |
| 1289 | else |
| 1290 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1293 | static int iwl3945_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1294 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1295 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1296 | unsigned int frame_size; |
| 1297 | int rc; |
| 1298 | u8 rate; |
| 1299 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1300 | frame = iwl3945_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1301 | |
| 1302 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1303 | IWL_ERR(priv, "Could not obtain free frame buffer for beacon " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1304 | "command.\n"); |
| 1305 | return -ENOMEM; |
| 1306 | } |
| 1307 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1308 | rate = iwl3945_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1309 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1310 | frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1311 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1312 | rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1313 | &frame->u.cmd[0]); |
| 1314 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1315 | iwl3945_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1316 | |
| 1317 | return rc; |
| 1318 | } |
| 1319 | |
| 1320 | /****************************************************************************** |
| 1321 | * |
| 1322 | * EEPROM related functions |
| 1323 | * |
| 1324 | ******************************************************************************/ |
| 1325 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1326 | static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1327 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1328 | memcpy(mac, priv->eeprom39.mac_address, 6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1331 | /* |
| 1332 | * Clear the OWNER_MSK, to establish driver (instead of uCode running on |
| 1333 | * embedded controller) as EEPROM reader; each read is a series of pulses |
| 1334 | * to/from the EEPROM chip, not a single event, so even reads could conflict |
| 1335 | * if they weren't arbitrated by some ownership mechanism. Here, the driver |
| 1336 | * simply claims ownership, which should be safe when this function is called |
| 1337 | * (i.e. before loading uCode!). |
| 1338 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1339 | static inline int iwl3945_eeprom_acquire_semaphore(struct iwl_priv *priv) |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1340 | { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1341 | _iwl_clear_bit(priv, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK); |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1342 | return 0; |
| 1343 | } |
| 1344 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1345 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1346 | * iwl3945_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1347 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1348 | * Load the EEPROM contents from adapter into priv->eeprom39 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1349 | * |
| 1350 | * NOTE: This routine uses the non-debug IO access functions. |
| 1351 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1352 | int iwl3945_eeprom_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1353 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1354 | u16 *e = (u16 *)&priv->eeprom39; |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1355 | u32 gp = iwl_read32(priv, CSR_EEPROM_GP); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1356 | int sz = sizeof(priv->eeprom39); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1357 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1358 | u16 addr; |
| 1359 | |
| 1360 | /* The EEPROM structure has several padding buffers within it |
| 1361 | * and when adding new EEPROM maps is subject to programmer errors |
| 1362 | * which may be very difficult to identify without explicitly |
| 1363 | * checking the resulting size of the eeprom map. */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1364 | BUILD_BUG_ON(sizeof(priv->eeprom39) != IWL_EEPROM_IMAGE_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1365 | |
| 1366 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1367 | IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1368 | return -ENOENT; |
| 1369 | } |
| 1370 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1371 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1372 | ret = iwl3945_eeprom_acquire_semaphore(priv); |
| 1373 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1374 | IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1375 | return -ENOENT; |
| 1376 | } |
| 1377 | |
| 1378 | /* eeprom is an array of 16bit values */ |
| 1379 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1380 | u32 r; |
| 1381 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1382 | _iwl_write32(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1383 | CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1384 | _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
| 1385 | ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1386 | CSR_EEPROM_REG_READ_VALID_MSK, |
| 1387 | IWL_EEPROM_ACCESS_TIMEOUT); |
| 1388 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1389 | IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1390 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1391 | } |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1392 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1393 | r = _iwl_read_direct32(priv, CSR_EEPROM_REG); |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1394 | e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1400 | static void iwl3945_unset_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1401 | { |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1402 | if (priv->shared_virt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1403 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1404 | sizeof(struct iwl3945_shared), |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1405 | priv->shared_virt, |
| 1406 | priv->shared_phys); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1410 | * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1411 | * |
| 1412 | * return : set the bit for each supported rate insert in ie |
| 1413 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1414 | static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1415 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1416 | { |
| 1417 | u16 ret_rates = 0, bit; |
| 1418 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1419 | u8 *cnt = ie; |
| 1420 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1421 | |
| 1422 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1423 | if (bit & supported_rate) { |
| 1424 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1425 | rates[*cnt] = iwl3945_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1426 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1427 | (*cnt)++; |
| 1428 | (*left)--; |
| 1429 | if ((*left <= 0) || |
| 1430 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1431 | break; |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | return ret_rates; |
| 1436 | } |
| 1437 | |
| 1438 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1439 | * iwl3945_fill_probe_req - fill in all required fields and IE for probe request |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1440 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1441 | static u16 iwl3945_fill_probe_req(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1442 | struct ieee80211_mgmt *frame, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 1443 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1444 | { |
| 1445 | int len = 0; |
| 1446 | u8 *pos = NULL; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1447 | u16 active_rates, ret_rates, cck_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1448 | |
| 1449 | /* Make sure there is enough space for the probe request, |
| 1450 | * two mandatory IEs and the data */ |
| 1451 | left -= 24; |
| 1452 | if (left < 0) |
| 1453 | return 0; |
| 1454 | len += 24; |
| 1455 | |
| 1456 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1457 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1458 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1459 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1460 | frame->seq_ctrl = 0; |
| 1461 | |
| 1462 | /* fill in our indirect SSID IE */ |
| 1463 | /* ...next IE... */ |
| 1464 | |
| 1465 | left -= 2; |
| 1466 | if (left < 0) |
| 1467 | return 0; |
| 1468 | len += 2; |
| 1469 | pos = &(frame->u.probe_req.variable[0]); |
| 1470 | *pos++ = WLAN_EID_SSID; |
| 1471 | *pos++ = 0; |
| 1472 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1473 | /* fill in supported rate */ |
| 1474 | /* ...next IE... */ |
| 1475 | left -= 2; |
| 1476 | if (left < 0) |
| 1477 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1478 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1479 | /* ... fill it in... */ |
| 1480 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1481 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1482 | |
| 1483 | priv->active_rate = priv->rates_mask; |
| 1484 | active_rates = priv->active_rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1485 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 1486 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1487 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1488 | ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1489 | priv->active_rate_basic, &left); |
| 1490 | active_rates &= ~ret_rates; |
| 1491 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1492 | ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1493 | priv->active_rate_basic, &left); |
| 1494 | active_rates &= ~ret_rates; |
| 1495 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1496 | len += 2 + *pos; |
| 1497 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1498 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1499 | goto fill_end; |
| 1500 | |
| 1501 | /* fill in supported extended rate */ |
| 1502 | /* ...next IE... */ |
| 1503 | left -= 2; |
| 1504 | if (left < 0) |
| 1505 | return 0; |
| 1506 | /* ... fill it in... */ |
| 1507 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1508 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1509 | iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1510 | priv->active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1511 | if (*pos > 0) |
| 1512 | len += 2 + *pos; |
| 1513 | |
| 1514 | fill_end: |
| 1515 | return (u16)len; |
| 1516 | } |
| 1517 | |
| 1518 | /* |
| 1519 | * QoS support |
| 1520 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1521 | static int iwl3945_send_qos_params_command(struct iwl_priv *priv, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1522 | struct iwl_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1523 | { |
| 1524 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1525 | return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1526 | sizeof(struct iwl_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1529 | static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1530 | { |
| 1531 | unsigned long flags; |
| 1532 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1533 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1534 | return; |
| 1535 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1536 | spin_lock_irqsave(&priv->lock, flags); |
| 1537 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1538 | |
| 1539 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1540 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1541 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1542 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
| 1543 | |
| 1544 | if (priv->qos_data.qos_active) |
| 1545 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1546 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1547 | |
| 1548 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1549 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1550 | if (force || iwl3945_is_associated(priv)) { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1551 | IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1552 | priv->qos_data.qos_active); |
| 1553 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1554 | iwl3945_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1555 | &(priv->qos_data.def_qos_parm)); |
| 1556 | } |
| 1557 | } |
| 1558 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1559 | /* |
| 1560 | * Power management (not Tx power!) functions |
| 1561 | */ |
| 1562 | #define MSEC_TO_USEC 1024 |
| 1563 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1564 | |
| 1565 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 1566 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1567 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 1568 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 1569 | __constant_cpu_to_le32(X1), \ |
| 1570 | __constant_cpu_to_le32(X2), \ |
| 1571 | __constant_cpu_to_le32(X3), \ |
| 1572 | __constant_cpu_to_le32(X4)} |
| 1573 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1574 | /* default power management (not Tx power) table values */ |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1575 | /* for TIM 0-10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1576 | static struct iwl_power_vec_entry range_0[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1578 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 1579 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 1580 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 1581 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 1582 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 1583 | }; |
| 1584 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1585 | /* for TIM > 10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1586 | static struct iwl_power_vec_entry range_1[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1587 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1588 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 1589 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 1590 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 1591 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 1592 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 1593 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 1594 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 1595 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 1596 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 1597 | }; |
| 1598 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1599 | int iwl3945_power_init_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1600 | { |
| 1601 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1602 | struct iwl3945_power_mgr *pow_data; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1603 | int size = sizeof(struct iwl_power_vec_entry) * IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1604 | u16 pci_pm; |
| 1605 | |
| 1606 | IWL_DEBUG_POWER("Initialize power \n"); |
| 1607 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1608 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1609 | |
| 1610 | memset(pow_data, 0, sizeof(*pow_data)); |
| 1611 | |
| 1612 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 1613 | pow_data->dtim_val = 0xffff; |
| 1614 | |
| 1615 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 1616 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 1617 | |
| 1618 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 1619 | if (rc != 0) |
| 1620 | return 0; |
| 1621 | else { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1622 | struct iwl_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1623 | |
| 1624 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 1625 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1626 | for (i = 0; i < IWL39_POWER_AC; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1627 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 1628 | |
| 1629 | if (pci_pm & 0x1) |
| 1630 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 1631 | else |
| 1632 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 1633 | } |
| 1634 | } |
| 1635 | return rc; |
| 1636 | } |
| 1637 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1638 | static int iwl3945_update_power_cmd(struct iwl_priv *priv, |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1639 | struct iwl_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1640 | { |
| 1641 | int rc = 0, i; |
| 1642 | u8 skip; |
| 1643 | u32 max_sleep = 0; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1644 | struct iwl_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1645 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1646 | struct iwl3945_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1647 | |
| 1648 | if (mode > IWL_POWER_INDEX_5) { |
| 1649 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 1650 | return -1; |
| 1651 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1652 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1653 | |
| 1654 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 1655 | range = &pow_data->pwr_range_0[0]; |
| 1656 | else |
| 1657 | range = &pow_data->pwr_range_1[1]; |
| 1658 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1659 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1660 | |
| 1661 | #ifdef IWL_MAC80211_DISABLE |
| 1662 | if (priv->assoc_network != NULL) { |
| 1663 | unsigned long flags; |
| 1664 | |
| 1665 | period = priv->assoc_network->tim.tim_period; |
| 1666 | } |
| 1667 | #endif /*IWL_MAC80211_DISABLE */ |
| 1668 | skip = range[mode].no_dtim; |
| 1669 | |
| 1670 | if (period == 0) { |
| 1671 | period = 1; |
| 1672 | skip = 0; |
| 1673 | } |
| 1674 | |
| 1675 | if (skip == 0) { |
| 1676 | max_sleep = period; |
| 1677 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1678 | } else { |
| 1679 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 1680 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 1681 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1682 | } |
| 1683 | |
| 1684 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 1685 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 1686 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 1687 | } |
| 1688 | |
| 1689 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 1690 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 1691 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 1692 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 1693 | le32_to_cpu(cmd->sleep_interval[0]), |
| 1694 | le32_to_cpu(cmd->sleep_interval[1]), |
| 1695 | le32_to_cpu(cmd->sleep_interval[2]), |
| 1696 | le32_to_cpu(cmd->sleep_interval[3]), |
| 1697 | le32_to_cpu(cmd->sleep_interval[4])); |
| 1698 | |
| 1699 | return rc; |
| 1700 | } |
| 1701 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1702 | static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1703 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 1704 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1705 | int rc; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1706 | struct iwl_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1707 | |
| 1708 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1709 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1710 | * else user level */ |
| 1711 | switch (mode) { |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1712 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1713 | final_mode = IWL_POWER_INDEX_3; |
| 1714 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1715 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1716 | final_mode = IWL_POWER_MODE_CAM; |
| 1717 | break; |
| 1718 | default: |
| 1719 | final_mode = mode; |
| 1720 | break; |
| 1721 | } |
| 1722 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1723 | iwl3945_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1724 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1725 | /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */ |
| 1726 | rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, |
| 1727 | sizeof(struct iwl3945_powertable_cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1728 | |
| 1729 | if (final_mode == IWL_POWER_MODE_CAM) |
| 1730 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 1731 | else |
| 1732 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 1733 | |
| 1734 | return rc; |
| 1735 | } |
| 1736 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1737 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1738 | * iwl3945_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1739 | * |
| 1740 | * NOTE: priv->mutex is not required before calling this function |
| 1741 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1742 | static int iwl3945_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1743 | { |
| 1744 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1745 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1746 | return 0; |
| 1747 | } |
| 1748 | |
| 1749 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1750 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1751 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 1752 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1753 | queue_work(priv->workqueue, &priv->abort_scan); |
| 1754 | |
| 1755 | } else |
| 1756 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 1757 | |
| 1758 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1759 | } |
| 1760 | |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
| 1764 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1765 | * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1766 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 1767 | * |
| 1768 | * NOTE: priv->mutex must be held before calling this function |
| 1769 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1770 | static int iwl3945_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1771 | { |
| 1772 | unsigned long now = jiffies; |
| 1773 | int ret; |
| 1774 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1775 | ret = iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1776 | if (ret && ms) { |
| 1777 | mutex_unlock(&priv->mutex); |
| 1778 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 1779 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1780 | msleep(1); |
| 1781 | mutex_lock(&priv->mutex); |
| 1782 | |
| 1783 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1784 | } |
| 1785 | |
| 1786 | return ret; |
| 1787 | } |
| 1788 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1789 | #define MAX_UCODE_BEACON_INTERVAL 1024 |
| 1790 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1791 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1792 | static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1793 | { |
| 1794 | u16 new_val = 0; |
| 1795 | u16 beacon_factor = 0; |
| 1796 | |
| 1797 | beacon_factor = |
| 1798 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1799 | / MAX_UCODE_BEACON_INTERVAL; |
| 1800 | new_val = beacon_val / beacon_factor; |
| 1801 | |
| 1802 | return cpu_to_le16(new_val); |
| 1803 | } |
| 1804 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1805 | static void iwl3945_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1806 | { |
| 1807 | u64 interval_tm_unit; |
| 1808 | u64 tsf, result; |
| 1809 | unsigned long flags; |
| 1810 | struct ieee80211_conf *conf = NULL; |
| 1811 | u16 beacon_int = 0; |
| 1812 | |
| 1813 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1814 | |
| 1815 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1816 | priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1817 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1818 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1819 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1820 | |
| 1821 | beacon_int = priv->beacon_int; |
| 1822 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1823 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1824 | if (priv->iw_mode == NL80211_IFTYPE_STATION) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1825 | if (beacon_int == 0) { |
| 1826 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1827 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1828 | } else { |
| 1829 | priv->rxon_timing.beacon_interval = |
| 1830 | cpu_to_le16(beacon_int); |
| 1831 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1832 | iwl3945_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1833 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1834 | } |
| 1835 | |
| 1836 | priv->rxon_timing.atim_window = 0; |
| 1837 | } else { |
| 1838 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1839 | iwl3945_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1840 | /* TODO: we need to get atim_window from upper stack |
| 1841 | * for now we set to 0 */ |
| 1842 | priv->rxon_timing.atim_window = 0; |
| 1843 | } |
| 1844 | |
| 1845 | interval_tm_unit = |
| 1846 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1847 | result = do_div(tsf, interval_tm_unit); |
| 1848 | priv->rxon_timing.beacon_init_val = |
| 1849 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1850 | |
| 1851 | IWL_DEBUG_ASSOC |
| 1852 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1853 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1854 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1855 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1856 | } |
| 1857 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1858 | static int iwl3945_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1859 | { |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 1860 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1861 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1862 | return -EIO; |
| 1863 | } |
| 1864 | |
| 1865 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1866 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1867 | return -EAGAIN; |
| 1868 | } |
| 1869 | |
| 1870 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1871 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1872 | "Queuing.\n"); |
| 1873 | return -EAGAIN; |
| 1874 | } |
| 1875 | |
| 1876 | IWL_DEBUG_INFO("Starting scan...\n"); |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 1877 | if (priv->cfg->sku & IWL_SKU_G) |
| 1878 | priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ); |
| 1879 | if (priv->cfg->sku & IWL_SKU_A) |
| 1880 | priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1881 | set_bit(STATUS_SCANNING, &priv->status); |
| 1882 | priv->scan_start = jiffies; |
| 1883 | priv->scan_pass_start = priv->scan_start; |
| 1884 | |
| 1885 | queue_work(priv->workqueue, &priv->request_scan); |
| 1886 | |
| 1887 | return 0; |
| 1888 | } |
| 1889 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1890 | static int iwl3945_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1891 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1892 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1893 | |
| 1894 | if (hw_decrypt) |
| 1895 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 1896 | else |
| 1897 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 1898 | |
| 1899 | return 0; |
| 1900 | } |
| 1901 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1902 | static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1903 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1904 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1905 | if (band == IEEE80211_BAND_5GHZ) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1906 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1907 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1908 | | RXON_FLG_CCK_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1909 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1910 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1911 | /* Copied from iwl3945_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1912 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1913 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1914 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1915 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1916 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1917 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1918 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1919 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1920 | priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1921 | priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1922 | priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1927 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1928 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1929 | static void iwl3945_connection_init_rx_config(struct iwl_priv *priv, |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1930 | int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1931 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 1932 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1933 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1934 | memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1935 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1936 | switch (mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1937 | case NL80211_IFTYPE_AP: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1938 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1939 | break; |
| 1940 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1941 | case NL80211_IFTYPE_STATION: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1942 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1943 | priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1944 | break; |
| 1945 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1946 | case NL80211_IFTYPE_ADHOC: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1947 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1948 | priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1949 | priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1950 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1951 | break; |
| 1952 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1953 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1954 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1955 | priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1956 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1957 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1958 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1959 | IWL_ERR(priv, "Unsupported interface type %d\n", mode); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1960 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | #if 0 |
| 1964 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1965 | * that */ |
| 1966 | if (!hw_to_local(priv->hw)->short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1967 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1968 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1969 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1970 | #endif |
| 1971 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1972 | ch_info = iwl3945_get_channel_info(priv, priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1973 | le16_to_cpu(priv->active39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1974 | |
| 1975 | if (!ch_info) |
| 1976 | ch_info = &priv->channel_info[0]; |
| 1977 | |
| 1978 | /* |
| 1979 | * in some case A channels are all non IBSS |
| 1980 | * in this case force B/G channel |
| 1981 | */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1982 | if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1983 | ch_info = &priv->channel_info[0]; |
| 1984 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1985 | priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1986 | if (is_channel_a_band(ch_info)) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1987 | priv->band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1988 | else |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1989 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1990 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1991 | iwl3945_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1992 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1993 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1994 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1995 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1996 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1997 | } |
| 1998 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1999 | static int iwl3945_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2000 | { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2001 | if (mode == NL80211_IFTYPE_ADHOC) { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2002 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2003 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2004 | ch_info = iwl3945_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2005 | priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2006 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2007 | |
| 2008 | if (!ch_info || !is_channel_ibss(ch_info)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2009 | IWL_ERR(priv, "channel %d not IBSS channel\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2010 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2011 | return -EINVAL; |
| 2012 | } |
| 2013 | } |
| 2014 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 2015 | iwl3945_connection_init_rx_config(priv, mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2016 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2017 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2018 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2019 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2020 | /* don't commit rxon if rf-kill is on*/ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2021 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2022 | return -EAGAIN; |
| 2023 | |
| 2024 | cancel_delayed_work(&priv->scan_check); |
| 2025 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2026 | IWL_WARN(priv, "Aborted scan still in progress after 100ms\n"); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2027 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2028 | return -EAGAIN; |
| 2029 | } |
| 2030 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2031 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2032 | |
| 2033 | return 0; |
| 2034 | } |
| 2035 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2036 | static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2037 | struct ieee80211_tx_info *info, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2038 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2039 | struct sk_buff *skb_frag, |
| 2040 | int last_frag) |
| 2041 | { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2042 | struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload; |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 2043 | struct iwl3945_hw_key *keyinfo = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2044 | &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2045 | |
| 2046 | switch (keyinfo->alg) { |
| 2047 | case ALG_CCMP: |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2048 | tx->sec_ctl = TX_CMD_SEC_CCM; |
| 2049 | memcpy(tx->key, keyinfo->key, keyinfo->keylen); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2050 | IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2051 | break; |
| 2052 | |
| 2053 | case ALG_TKIP: |
| 2054 | #if 0 |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2055 | tx->sec_ctl = TX_CMD_SEC_TKIP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2056 | |
| 2057 | if (last_frag) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2058 | memcpy(tx->tkip_mic.byte, skb_frag->tail - 8, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2059 | 8); |
| 2060 | else |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2061 | memset(tx->tkip_mic.byte, 0, 8); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2062 | #endif |
| 2063 | break; |
| 2064 | |
| 2065 | case ALG_WEP: |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2066 | tx->sec_ctl = TX_CMD_SEC_WEP | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2067 | (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2068 | |
| 2069 | if (keyinfo->keylen == 13) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2070 | tx->sec_ctl |= TX_CMD_SEC_KEY128; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2071 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2072 | memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2073 | |
| 2074 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2075 | "with key %d\n", info->control.hw_key->hw_key_idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2076 | break; |
| 2077 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2078 | default: |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2079 | IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2080 | break; |
| 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | /* |
| 2085 | * handle build REPLY_TX command notification. |
| 2086 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2087 | static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2088 | struct iwl_cmd *cmd, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2089 | struct ieee80211_tx_info *info, |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2090 | struct ieee80211_hdr *hdr, u8 std_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2091 | { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2092 | struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload; |
| 2093 | __le32 tx_flags = tx->tx_flags; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2094 | __le16 fc = hdr->frame_control; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2095 | u8 rc_flags = info->control.rates[0].flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2096 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2097 | tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2098 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2099 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2100 | if (ieee80211_is_mgmt(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2101 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2102 | if (ieee80211_is_probe_resp(fc) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2103 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2104 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2105 | } else { |
| 2106 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2107 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2108 | } |
| 2109 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2110 | tx->sta_id = std_id; |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2111 | if (ieee80211_has_morefrags(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2112 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2113 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2114 | if (ieee80211_is_data_qos(fc)) { |
| 2115 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2116 | tx->tid_tspec = qc[0] & 0xf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2117 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2118 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2119 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2120 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2121 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2122 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2123 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2124 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2125 | } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2126 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2127 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2128 | } |
| 2129 | |
| 2130 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2131 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2132 | |
| 2133 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2134 | if (ieee80211_is_mgmt(fc)) { |
| 2135 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2136 | tx->timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2137 | else |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2138 | tx->timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2139 | } else { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2140 | tx->timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2141 | #ifdef CONFIG_IWL3945_LEDS |
| 2142 | priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len); |
| 2143 | #endif |
| 2144 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2145 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2146 | tx->driver_txop = 0; |
| 2147 | tx->tx_flags = tx_flags; |
| 2148 | tx->next_frame_len = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2151 | /** |
| 2152 | * iwl3945_get_sta_id - Find station's index within station table |
| 2153 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2154 | static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2155 | { |
| 2156 | int sta_id; |
| 2157 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2158 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2159 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2160 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2161 | is_multicast_ether_addr(hdr->addr1)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2162 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2163 | |
| 2164 | switch (priv->iw_mode) { |
| 2165 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2166 | /* If we are a client station in a BSS network, use the special |
| 2167 | * AP station entry (that's the only station we communicate with) */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2168 | case NL80211_IFTYPE_STATION: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2169 | return IWL_AP_ID; |
| 2170 | |
| 2171 | /* If we are an AP, then find the station, or use BCAST */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2172 | case NL80211_IFTYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2173 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2174 | if (sta_id != IWL_INVALID_STATION) |
| 2175 | return sta_id; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2176 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2177 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2178 | /* If this frame is going out to an IBSS network, find the station, |
| 2179 | * or create a new station table entry */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2180 | case NL80211_IFTYPE_ADHOC: { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2181 | /* Create new station table entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2182 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2183 | if (sta_id != IWL_INVALID_STATION) |
| 2184 | return sta_id; |
| 2185 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2186 | sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2187 | |
| 2188 | if (sta_id != IWL_INVALID_STATION) |
| 2189 | return sta_id; |
| 2190 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2191 | IWL_DEBUG_DROP("Station %pM not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2192 | "Defaulting to broadcast...\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2193 | hdr->addr1); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2194 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2195 | return priv->hw_params.bcast_sta_id; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2196 | } |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2197 | /* If we are in monitor mode, use BCAST. This is required for |
| 2198 | * packet injection. */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2199 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2200 | return priv->hw_params.bcast_sta_id; |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2201 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2202 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2203 | IWL_WARN(priv, "Unknown mode of operation: %d\n", |
| 2204 | priv->iw_mode); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2205 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2206 | } |
| 2207 | } |
| 2208 | |
| 2209 | /* |
| 2210 | * start REPLY_TX command process |
| 2211 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2212 | static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2213 | { |
| 2214 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2215 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2216 | struct iwl3945_tfd *tfd; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2217 | struct iwl3945_tx_cmd *tx; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2218 | struct iwl_tx_queue *txq = NULL; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2219 | struct iwl_queue *q = NULL; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2220 | struct iwl_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2221 | dma_addr_t phys_addr; |
| 2222 | dma_addr_t txcmd_phys; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2223 | int txq_id = skb_get_queue_mapping(skb); |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2224 | u16 len, idx, len_org, hdr_len; |
| 2225 | u8 id; |
| 2226 | u8 unicast; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2227 | u8 sta_id; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2228 | u8 tid = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2229 | u16 seq_number = 0; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2230 | __le16 fc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2231 | u8 wait_write_ptr = 0; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2232 | u8 *qc = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2233 | unsigned long flags; |
| 2234 | int rc; |
| 2235 | |
| 2236 | spin_lock_irqsave(&priv->lock, flags); |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2237 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2238 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2239 | goto drop_unlock; |
| 2240 | } |
| 2241 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2242 | if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2243 | IWL_ERR(priv, "ERROR: No TX rate available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2244 | goto drop_unlock; |
| 2245 | } |
| 2246 | |
| 2247 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2248 | id = 0; |
| 2249 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2250 | fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2251 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2252 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2253 | if (ieee80211_is_auth(fc)) |
| 2254 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2255 | else if (ieee80211_is_assoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2256 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2257 | else if (ieee80211_is_reassoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2258 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2259 | #endif |
| 2260 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2261 | /* drop all data frame if we are not associated */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2262 | if (ieee80211_is_data(fc) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2263 | (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2264 | (!iwl3945_is_associated(priv) || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2265 | ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2266 | IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2267 | goto drop_unlock; |
| 2268 | } |
| 2269 | |
| 2270 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2271 | |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2272 | hdr_len = ieee80211_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2273 | |
| 2274 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2275 | sta_id = iwl3945_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2276 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2277 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n", |
| 2278 | hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2279 | goto drop; |
| 2280 | } |
| 2281 | |
| 2282 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2283 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2284 | if (ieee80211_is_data_qos(fc)) { |
| 2285 | qc = ieee80211_get_qos_ctl(hdr); |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2286 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2287 | seq_number = priv->stations_39[sta_id].tid[tid].seq_number & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2288 | IEEE80211_SCTL_SEQ; |
| 2289 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2290 | (hdr->seq_ctrl & |
| 2291 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2292 | seq_number += 0x10; |
| 2293 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2294 | |
| 2295 | /* Descriptor for chosen Tx queue */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2296 | txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2297 | q = &txq->q; |
| 2298 | |
| 2299 | spin_lock_irqsave(&priv->lock, flags); |
| 2300 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2301 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2302 | tfd = &txq->tfds39[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2303 | memset(tfd, 0, sizeof(*tfd)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2304 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2305 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2306 | /* Set up driver data for this TFD */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2307 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2308 | txq->txb[q->write_ptr].skb[0] = skb; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2309 | |
| 2310 | /* Init first empty entry in queue's array of Tx/cmd buffers */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2311 | out_cmd = txq->cmd[idx]; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2312 | tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2313 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2314 | memset(tx, 0, sizeof(*tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2315 | |
| 2316 | /* |
| 2317 | * Set up the Tx-command (not MAC!) header. |
| 2318 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2319 | * after Tx, uCode's Tx response will return this value so driver can |
| 2320 | * locate the frame within the tx queue and do post-tx processing. |
| 2321 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2322 | out_cmd->hdr.cmd = REPLY_TX; |
| 2323 | out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2324 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2325 | |
| 2326 | /* Copy MAC header from skb into command buffer */ |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2327 | memcpy(tx->hdr, hdr, hdr_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2328 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2329 | /* |
| 2330 | * Use the first empty entry in this queue's command buffer array |
| 2331 | * to contain the Tx command and MAC header concatenated together |
| 2332 | * (payload data will be in another buffer). |
| 2333 | * Size of this varies, due to varying MAC header length. |
| 2334 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2335 | * of the MAC header (device reads on dword boundaries). |
| 2336 | * We'll tell device about this padding later. |
| 2337 | */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2338 | len = sizeof(struct iwl3945_tx_cmd) + |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2339 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2340 | |
| 2341 | len_org = len; |
| 2342 | len = (len + 3) & ~3; |
| 2343 | |
| 2344 | if (len_org != len) |
| 2345 | len_org = 1; |
| 2346 | else |
| 2347 | len_org = 0; |
| 2348 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2349 | /* Physical address of this Tx command's header (not MAC header!), |
| 2350 | * within command buffer array. */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2351 | txcmd_phys = pci_map_single(priv->pci_dev, |
| 2352 | out_cmd, sizeof(struct iwl_cmd), |
| 2353 | PCI_DMA_TODEVICE); |
| 2354 | pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys); |
| 2355 | pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd)); |
| 2356 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2357 | * first entry */ |
| 2358 | txcmd_phys += offsetof(struct iwl_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2359 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2360 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2361 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2362 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2363 | |
Johannes Berg | d0f0980 | 2008-07-29 11:32:07 +0200 | [diff] [blame] | 2364 | if (info->control.hw_key) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2365 | iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2366 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2367 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2368 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2369 | len = skb->len - hdr_len; |
| 2370 | if (len) { |
| 2371 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2372 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2373 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2376 | if (!len) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2377 | /* If there is no payload, then we use only one Tx buffer */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2378 | tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2379 | else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2380 | /* Else use 2 buffers. |
| 2381 | * Tell 3945 about any padding after MAC header */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2382 | tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(2) | |
| 2383 | TFD_CTL_PAD_SET(U32_PAD(len))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2384 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2385 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2386 | len = (u16)skb->len; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2387 | tx->len = cpu_to_le16(len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2388 | |
| 2389 | /* TODO need this for burst mode later on */ |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2390 | iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2391 | |
| 2392 | /* set is_hcca to 0; it probably will never be implemented */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2393 | iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2394 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2395 | tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; |
| 2396 | tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2397 | |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2398 | if (!ieee80211_has_morefrags(hdr->frame_control)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2399 | txq->need_update = 1; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 2400 | if (qc) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2401 | priv->stations_39[sta_id].tid[tid].seq_number = seq_number; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2402 | } else { |
| 2403 | wait_write_ptr = 1; |
| 2404 | txq->need_update = 0; |
| 2405 | } |
| 2406 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2407 | iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2408 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2409 | iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr, |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2410 | ieee80211_hdrlen(fc)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2411 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2412 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2413 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2414 | rc = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2415 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2416 | |
| 2417 | if (rc) |
| 2418 | return rc; |
| 2419 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2420 | if ((iwl_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2421 | && priv->mac80211_registered) { |
| 2422 | if (wait_write_ptr) { |
| 2423 | spin_lock_irqsave(&priv->lock, flags); |
| 2424 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2425 | iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2426 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2427 | } |
| 2428 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 2429 | ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | return 0; |
| 2433 | |
| 2434 | drop_unlock: |
| 2435 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2436 | drop: |
| 2437 | return -1; |
| 2438 | } |
| 2439 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2440 | static void iwl3945_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2441 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2442 | const struct ieee80211_supported_band *sband = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2443 | struct ieee80211_rate *rate; |
| 2444 | int i; |
| 2445 | |
Kolekar, Abhijeet | cbba18c | 2008-12-19 10:37:42 +0800 | [diff] [blame] | 2446 | sband = iwl_get_hw_mode(priv, priv->band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2447 | if (!sband) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2448 | IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n"); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 2449 | return; |
| 2450 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2451 | |
| 2452 | priv->active_rate = 0; |
| 2453 | priv->active_rate_basic = 0; |
| 2454 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2455 | IWL_DEBUG_RATE("Setting rates for %s GHz\n", |
| 2456 | sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2457 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2458 | for (i = 0; i < sband->n_bitrates; i++) { |
| 2459 | rate = &sband->bitrates[i]; |
| 2460 | if ((rate->hw_value < IWL_RATE_COUNT) && |
| 2461 | !(rate->flags & IEEE80211_CHAN_DISABLED)) { |
| 2462 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n", |
| 2463 | rate->hw_value, iwl3945_rates[rate->hw_value].plcp); |
| 2464 | priv->active_rate |= (1 << rate->hw_value); |
| 2465 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2469 | priv->active_rate, priv->active_rate_basic); |
| 2470 | |
| 2471 | /* |
| 2472 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2473 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2474 | * OFDM |
| 2475 | */ |
| 2476 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2477 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2478 | ((priv->active_rate_basic & |
| 2479 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2480 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2481 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2482 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2483 | |
| 2484 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2485 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2486 | ((priv->active_rate_basic & |
| 2487 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2488 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2489 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2490 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2491 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2492 | } |
| 2493 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2494 | static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2495 | { |
| 2496 | unsigned long flags; |
| 2497 | |
| 2498 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2499 | return; |
| 2500 | |
| 2501 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2502 | disable_radio ? "OFF" : "ON"); |
| 2503 | |
| 2504 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2505 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2506 | /* FIXME: This is a workaround for AP */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2507 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2508 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2509 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2510 | CSR_UCODE_SW_BIT_RFKILL); |
| 2511 | spin_unlock_irqrestore(&priv->lock, flags); |
Samuel Ortiz | c496294 | 2008-12-22 11:31:18 +0800 | [diff] [blame] | 2512 | iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2513 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2514 | } |
| 2515 | return; |
| 2516 | } |
| 2517 | |
| 2518 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2519 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2520 | |
| 2521 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2522 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2523 | |
| 2524 | /* wake up ucode */ |
| 2525 | msleep(10); |
| 2526 | |
| 2527 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2528 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2529 | if (!iwl_grab_nic_access(priv)) |
| 2530 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2531 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2532 | |
| 2533 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2534 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2535 | "disabled by HW switch\n"); |
| 2536 | return; |
| 2537 | } |
| 2538 | |
Zhu Yi | 808e72a | 2008-06-12 09:47:17 +0800 | [diff] [blame] | 2539 | if (priv->is_open) |
| 2540 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2541 | return; |
| 2542 | } |
| 2543 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2544 | void iwl3945_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2545 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 2546 | { |
| 2547 | u16 fc = |
| 2548 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 2549 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2550 | if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2551 | return; |
| 2552 | |
| 2553 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 2554 | return; |
| 2555 | |
| 2556 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 2557 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2558 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2559 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2560 | RX_RES_STATUS_BAD_ICV_MIC) |
| 2561 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 2562 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 2563 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2564 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2565 | RX_RES_STATUS_DECRYPT_OK) { |
| 2566 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 2567 | stats->flag |= RX_FLAG_DECRYPTED; |
| 2568 | } |
| 2569 | break; |
| 2570 | |
| 2571 | default: |
| 2572 | break; |
| 2573 | } |
| 2574 | } |
| 2575 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2576 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2577 | |
| 2578 | #include "iwl-spectrum.h" |
| 2579 | |
| 2580 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 2581 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 2582 | #define TIME_UNIT 1024 |
| 2583 | |
| 2584 | /* |
| 2585 | * extended beacon time format |
| 2586 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 2587 | * the high 1 byte is the beacon counts |
| 2588 | * the lower 3 bytes is the time in usec within one beacon interval |
| 2589 | */ |
| 2590 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2591 | static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2592 | { |
| 2593 | u32 quot; |
| 2594 | u32 rem; |
| 2595 | u32 interval = beacon_interval * 1024; |
| 2596 | |
| 2597 | if (!interval || !usec) |
| 2598 | return 0; |
| 2599 | |
| 2600 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 2601 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 2602 | |
| 2603 | return (quot << 24) + rem; |
| 2604 | } |
| 2605 | |
| 2606 | /* base is usually what we get from ucode with each received frame, |
| 2607 | * the same as HW timer counter counting down |
| 2608 | */ |
| 2609 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2610 | static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2611 | { |
| 2612 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 2613 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 2614 | u32 interval = beacon_interval * TIME_UNIT; |
| 2615 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 2616 | (addon & BEACON_TIME_MASK_HIGH); |
| 2617 | |
| 2618 | if (base_low > addon_low) |
| 2619 | res += base_low - addon_low; |
| 2620 | else if (base_low < addon_low) { |
| 2621 | res += interval + base_low - addon_low; |
| 2622 | res += (1 << 24); |
| 2623 | } else |
| 2624 | res += (1 << 24); |
| 2625 | |
| 2626 | return cpu_to_le32(res); |
| 2627 | } |
| 2628 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2629 | static int iwl3945_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2630 | struct ieee80211_measurement_params *params, |
| 2631 | u8 type) |
| 2632 | { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2633 | struct iwl_spectrum_cmd spectrum; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2634 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2635 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2636 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 2637 | .data = (void *)&spectrum, |
| 2638 | .meta.flags = CMD_WANT_SKB, |
| 2639 | }; |
| 2640 | u32 add_time = le64_to_cpu(params->start_time); |
| 2641 | int rc; |
| 2642 | int spectrum_resp_status; |
| 2643 | int duration = le16_to_cpu(params->duration); |
| 2644 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2645 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2646 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2647 | iwl3945_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2648 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 2649 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2650 | |
| 2651 | memset(&spectrum, 0, sizeof(spectrum)); |
| 2652 | |
| 2653 | spectrum.channel_count = cpu_to_le16(1); |
| 2654 | spectrum.flags = |
| 2655 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 2656 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 2657 | cmd.len = sizeof(spectrum); |
| 2658 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 2659 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2660 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2661 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2662 | iwl3945_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2663 | add_time, |
| 2664 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2665 | else |
| 2666 | spectrum.start_time = 0; |
| 2667 | |
| 2668 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 2669 | spectrum.channels[0].channel = params->channel; |
| 2670 | spectrum.channels[0].type = type; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2671 | if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2672 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 2673 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 2674 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2675 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2676 | if (rc) |
| 2677 | return rc; |
| 2678 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2679 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2680 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2681 | IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2682 | rc = -EIO; |
| 2683 | } |
| 2684 | |
| 2685 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 2686 | switch (spectrum_resp_status) { |
| 2687 | case 0: /* Command will be handled */ |
| 2688 | if (res->u.spectrum.id != 0xff) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2689 | IWL_DEBUG_INFO("Replaced existing measurement: %d\n", |
| 2690 | res->u.spectrum.id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2691 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 2692 | } |
| 2693 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 2694 | rc = 0; |
| 2695 | break; |
| 2696 | |
| 2697 | case 1: /* Command will not be handled */ |
| 2698 | rc = -EAGAIN; |
| 2699 | break; |
| 2700 | } |
| 2701 | |
| 2702 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 2703 | |
| 2704 | return rc; |
| 2705 | } |
| 2706 | #endif |
| 2707 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2708 | static void iwl3945_rx_reply_alive(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2709 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2710 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2711 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 2712 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2713 | struct delayed_work *pwork; |
| 2714 | |
| 2715 | palive = &pkt->u.alive_frame; |
| 2716 | |
| 2717 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 2718 | "0x%01X 0x%01X\n", |
| 2719 | palive->is_valid, palive->ver_type, |
| 2720 | palive->ver_subtype); |
| 2721 | |
| 2722 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 2723 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2724 | memcpy(&priv->card_alive_init, &pkt->u.alive_frame, |
| 2725 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2726 | pwork = &priv->init_alive_start; |
| 2727 | } else { |
| 2728 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2729 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2730 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2731 | pwork = &priv->alive_start; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2732 | iwl3945_disable_events(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | /* We delay the ALIVE response by 5ms to |
| 2736 | * give the HW RF Kill time to activate... */ |
| 2737 | if (palive->is_valid == UCODE_VALID_OK) |
| 2738 | queue_delayed_work(priv->workqueue, pwork, |
| 2739 | msecs_to_jiffies(5)); |
| 2740 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2741 | IWL_WARN(priv, "uCode did not respond OK.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2744 | static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2745 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2746 | { |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2747 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2748 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2749 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2750 | |
| 2751 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 2752 | return; |
| 2753 | } |
| 2754 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2755 | static void iwl3945_rx_reply_error(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2756 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2757 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2758 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2759 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2760 | IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2761 | "seq 0x%04X ser 0x%08X\n", |
| 2762 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 2763 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 2764 | pkt->u.err_resp.cmd_id, |
| 2765 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 2766 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 2767 | } |
| 2768 | |
| 2769 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2770 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2771 | static void iwl3945_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2772 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2773 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2774 | struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2775 | struct iwl_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2776 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 2777 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 2778 | rxon->channel = csa->channel; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2779 | priv->staging39_rxon.channel = csa->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2782 | static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2783 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2784 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2785 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2786 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2787 | struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2788 | |
| 2789 | if (!report->state) { |
| 2790 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 2791 | "Spectrum Measure Notification: Start\n"); |
| 2792 | return; |
| 2793 | } |
| 2794 | |
| 2795 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2796 | priv->measurement_status |= MEASUREMENT_READY; |
| 2797 | #endif |
| 2798 | } |
| 2799 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2800 | static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2801 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2802 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2803 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2804 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2805 | struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2806 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2807 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2808 | #endif |
| 2809 | } |
| 2810 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2811 | static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2812 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2813 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2814 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2815 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2816 | "notification for %s:\n", |
| 2817 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2818 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, |
| 2819 | le32_to_cpu(pkt->len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2822 | static void iwl3945_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2823 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2824 | struct iwl_priv *priv = |
| 2825 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2826 | struct sk_buff *beacon; |
| 2827 | |
| 2828 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2829 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2830 | |
| 2831 | if (!beacon) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2832 | IWL_ERR(priv, "update beacon failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2833 | return; |
| 2834 | } |
| 2835 | |
| 2836 | mutex_lock(&priv->mutex); |
| 2837 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2838 | if (priv->ibss_beacon) |
| 2839 | dev_kfree_skb(priv->ibss_beacon); |
| 2840 | |
| 2841 | priv->ibss_beacon = beacon; |
| 2842 | mutex_unlock(&priv->mutex); |
| 2843 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2844 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2847 | static void iwl3945_rx_beacon_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2848 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2849 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2850 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2851 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2852 | struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2853 | u8 rate = beacon->beacon_notify_hdr.rate; |
| 2854 | |
| 2855 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2856 | "tsf %d %d rate %d\n", |
| 2857 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2858 | beacon->beacon_notify_hdr.failure_frame, |
| 2859 | le32_to_cpu(beacon->ibss_mgr_status), |
| 2860 | le32_to_cpu(beacon->high_tsf), |
| 2861 | le32_to_cpu(beacon->low_tsf), rate); |
| 2862 | #endif |
| 2863 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2864 | if ((priv->iw_mode == NL80211_IFTYPE_AP) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2865 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 2866 | queue_work(priv->workqueue, &priv->beacon_update); |
| 2867 | } |
| 2868 | |
| 2869 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2870 | static void iwl3945_rx_reply_scan(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2871 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2872 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2873 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2874 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2875 | struct iwl_scanreq_notification *notif = |
| 2876 | (struct iwl_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2877 | |
| 2878 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 2879 | #endif |
| 2880 | } |
| 2881 | |
| 2882 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2883 | static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2884 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2885 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2886 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2887 | struct iwl_scanstart_notification *notif = |
| 2888 | (struct iwl_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2889 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 2890 | IWL_DEBUG_SCAN("Scan start: " |
| 2891 | "%d [802.11%s] " |
| 2892 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 2893 | notif->channel, |
| 2894 | notif->band ? "bg" : "a", |
| 2895 | notif->tsf_high, |
| 2896 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 2897 | } |
| 2898 | |
| 2899 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2900 | static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2901 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2902 | { |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2903 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2904 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2905 | struct iwl_scanresults_notification *notif = |
| 2906 | (struct iwl_scanresults_notification *)pkt->u.raw; |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2907 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2908 | |
| 2909 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 2910 | "%d [802.11%s] " |
| 2911 | "(TSF: 0x%08X:%08X) - %d " |
| 2912 | "elapsed=%lu usec (%dms since last)\n", |
| 2913 | notif->channel, |
| 2914 | notif->band ? "bg" : "a", |
| 2915 | le32_to_cpu(notif->tsf_high), |
| 2916 | le32_to_cpu(notif->tsf_low), |
| 2917 | le32_to_cpu(notif->statistics[0]), |
| 2918 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 2919 | jiffies_to_msecs(elapsed_jiffies |
| 2920 | (priv->last_scan_jiffies, jiffies))); |
| 2921 | |
| 2922 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2923 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2927 | static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2928 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2929 | { |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2930 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2931 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2932 | struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2933 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2934 | |
| 2935 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 2936 | scan_notif->scanned_channels, |
| 2937 | scan_notif->tsf_low, |
| 2938 | scan_notif->tsf_high, scan_notif->status); |
| 2939 | |
| 2940 | /* The HW is no longer scanning */ |
| 2941 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 2942 | |
| 2943 | /* The scan completion notification came in, so kill that timer... */ |
| 2944 | cancel_delayed_work(&priv->scan_check); |
| 2945 | |
| 2946 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 2947 | (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ? |
| 2948 | "2.4" : "5.2", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2949 | jiffies_to_msecs(elapsed_jiffies |
| 2950 | (priv->scan_pass_start, jiffies))); |
| 2951 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 2952 | /* Remove this scanned band from the list of pending |
| 2953 | * bands to scan, band G precedes A in order of scanning |
| 2954 | * as seen in iwl3945_bg_request_scan */ |
| 2955 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) |
| 2956 | priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ); |
| 2957 | else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) |
| 2958 | priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2959 | |
| 2960 | /* If a request to abort was given, or the scan did not succeed |
| 2961 | * then we reset the scan state machine and terminate, |
| 2962 | * re-queuing another scan if one has been requested */ |
| 2963 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2964 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 2965 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2966 | } else { |
| 2967 | /* If there are more bands on this scan pass reschedule */ |
| 2968 | if (priv->scan_bands > 0) |
| 2969 | goto reschedule; |
| 2970 | } |
| 2971 | |
| 2972 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2973 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2974 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 2975 | |
| 2976 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2977 | |
| 2978 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 2979 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 2980 | |
| 2981 | queue_work(priv->workqueue, &priv->scan_completed); |
| 2982 | |
| 2983 | return; |
| 2984 | |
| 2985 | reschedule: |
| 2986 | priv->scan_pass_start = jiffies; |
| 2987 | queue_work(priv->workqueue, &priv->request_scan); |
| 2988 | } |
| 2989 | |
| 2990 | /* Handle notification from uCode that card's power state is changing |
| 2991 | * due to software, hardware, or critical temperature RFKILL */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2992 | static void iwl3945_rx_card_state_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2993 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2994 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2995 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2996 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 2997 | unsigned long status = priv->status; |
| 2998 | |
| 2999 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 3000 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3001 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 3002 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3003 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3004 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3005 | |
| 3006 | if (flags & HW_CARD_DISABLED) |
| 3007 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3008 | else |
| 3009 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3010 | |
| 3011 | |
| 3012 | if (flags & SW_CARD_DISABLED) |
| 3013 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3014 | else |
| 3015 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3016 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3017 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3018 | |
| 3019 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 3020 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 3021 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 3022 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 3023 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3024 | else |
| 3025 | wake_up_interruptible(&priv->wait_command_queue); |
| 3026 | } |
| 3027 | |
| 3028 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3029 | * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3030 | * |
| 3031 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3032 | * to the host. |
| 3033 | * |
| 3034 | * This function chains into the hardware specific files for them to setup |
| 3035 | * any hardware specific handlers as well. |
| 3036 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3037 | static void iwl3945_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3038 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3039 | priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive; |
| 3040 | priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta; |
| 3041 | priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error; |
| 3042 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3043 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3044 | iwl3945_rx_spectrum_measure_notif; |
| 3045 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3046 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3047 | iwl3945_rx_pm_debug_statistics_notif; |
| 3048 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3049 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3050 | /* |
| 3051 | * The same handler is used for both the REPLY to a discrete |
| 3052 | * statistics request from the host as well as for the periodic |
| 3053 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3054 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3055 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics; |
| 3056 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3057 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3058 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan; |
| 3059 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3060 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3061 | iwl3945_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3062 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3063 | iwl3945_rx_scan_complete_notif; |
| 3064 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3065 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3066 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3067 | iwl3945_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | /** |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3071 | * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries |
| 3072 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3073 | * need to be reclaimed. |
| 3074 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3075 | static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3076 | int txq_id, int index) |
| 3077 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3078 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 3079 | struct iwl_queue *q = &txq->q; |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3080 | int nfreed = 0; |
| 3081 | |
Winkler, Tomas | 625a381 | 2009-01-08 10:19:55 -0800 | [diff] [blame] | 3082 | if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3083 | IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, " |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3084 | "is out of range [0-%d] %d %d.\n", txq_id, |
| 3085 | index, q->n_bd, q->write_ptr, q->read_ptr); |
| 3086 | return; |
| 3087 | } |
| 3088 | |
| 3089 | for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index; |
| 3090 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
| 3091 | if (nfreed > 1) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3092 | IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3093 | q->write_ptr, q->read_ptr); |
| 3094 | queue_work(priv->workqueue, &priv->restart); |
| 3095 | break; |
| 3096 | } |
| 3097 | nfreed++; |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | |
| 3102 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3103 | * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3104 | * @rxb: Rx buffer to reclaim |
| 3105 | * |
| 3106 | * If an Rx buffer has an async callback associated with it the callback |
| 3107 | * will be executed. The attached skb (if present) will only be freed |
| 3108 | * if the callback returns 1 |
| 3109 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3110 | static void iwl3945_tx_cmd_complete(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3111 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3112 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3113 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3114 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3115 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3116 | int index = SEQ_TO_INDEX(sequence); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 3117 | int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3118 | int cmd_index; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 3119 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3120 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3121 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3122 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3123 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3124 | cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3125 | |
| 3126 | /* Input error checking is done when commands are added to queue. */ |
| 3127 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3128 | cmd->meta.source->u.skb = rxb->skb; |
| 3129 | rxb->skb = NULL; |
| 3130 | } else if (cmd->meta.u.callback && |
| 3131 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3132 | rxb->skb = NULL; |
| 3133 | |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3134 | iwl3945_cmd_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3135 | |
| 3136 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3137 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3138 | wake_up_interruptible(&priv->wait_command_queue); |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | /************************** RX-FUNCTIONS ****************************/ |
| 3143 | /* |
| 3144 | * Rx theory of operation |
| 3145 | * |
| 3146 | * The host allocates 32 DMA target addresses and passes the host address |
| 3147 | * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
| 3148 | * 0 to 31 |
| 3149 | * |
| 3150 | * Rx Queue Indexes |
| 3151 | * The host/firmware share two index registers for managing the Rx buffers. |
| 3152 | * |
| 3153 | * The READ index maps to the first position that the firmware may be writing |
| 3154 | * to -- the driver can read up to (but not including) this position and get |
| 3155 | * good data. |
| 3156 | * The READ index is managed by the firmware once the card is enabled. |
| 3157 | * |
| 3158 | * The WRITE index maps to the last position the driver has read from -- the |
| 3159 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 3160 | * |
| 3161 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 3162 | * WRITE = READ. |
| 3163 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3164 | * During initialization, the host sets up the READ queue position to the first |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3165 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 3166 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3167 | * When the firmware places a packet in a buffer, it will advance the READ index |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3168 | * and fire the RX interrupt. The driver can then query the READ index and |
| 3169 | * process as many packets as possible, moving the WRITE index forward as it |
| 3170 | * resets the Rx queue buffers with new memory. |
| 3171 | * |
| 3172 | * The management in the driver is as follows: |
| 3173 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 3174 | * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3175 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3176 | * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3177 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 3178 | * 'processed' and 'read' driver indexes as well) |
| 3179 | * + A received packet is processed and handed to the kernel network stack, |
| 3180 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 3181 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 3182 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 3183 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 3184 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 3185 | * |
| 3186 | * |
| 3187 | * Driver sequence: |
| 3188 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3189 | * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3190 | * iwl3945_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3191 | * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3192 | * queue, updates firmware pointers, and updates |
| 3193 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3194 | * are available, schedules iwl3945_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3195 | * |
| 3196 | * -- enable interrupts -- |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3197 | * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3198 | * READ INDEX, detaching the SKB from the pool. |
| 3199 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3200 | * Calls iwl3945_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3201 | * slots. |
| 3202 | * ... |
| 3203 | * |
| 3204 | */ |
| 3205 | |
| 3206 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3207 | * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3208 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3209 | static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3210 | dma_addr_t dma_addr) |
| 3211 | { |
| 3212 | return cpu_to_le32((u32)dma_addr); |
| 3213 | } |
| 3214 | |
| 3215 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3216 | * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3217 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3218 | * If there are slots in the RX queue that need to be restocked, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3219 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3220 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3221 | * |
| 3222 | * This moves the 'write' index forward to catch up with 'processed', and |
| 3223 | * also updates the memory address in the firmware to reference the new |
| 3224 | * target buffer. |
| 3225 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3226 | static int iwl3945_rx_queue_restock(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3227 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3228 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3229 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3230 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3231 | unsigned long flags; |
| 3232 | int write, rc; |
| 3233 | |
| 3234 | spin_lock_irqsave(&rxq->lock, flags); |
| 3235 | write = rxq->write & ~0x7; |
Winkler, Tomas | 37d6831 | 2009-01-08 10:19:54 -0800 | [diff] [blame] | 3236 | while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3237 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3238 | element = rxq->rx_free.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3239 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3240 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3241 | |
| 3242 | /* Point to Rx buffer via next RBD in circular buffer */ |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3243 | rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3244 | rxq->queue[rxq->write] = rxb; |
| 3245 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 3246 | rxq->free_count--; |
| 3247 | } |
| 3248 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3249 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 3250 | * refill it */ |
| 3251 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 3252 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 3253 | |
| 3254 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3255 | /* If we've added more space for the firmware to place data, tell it. |
| 3256 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3257 | if ((write != (rxq->write & ~0x7)) |
| 3258 | || (abs(rxq->write - rxq->read) > 7)) { |
| 3259 | spin_lock_irqsave(&rxq->lock, flags); |
| 3260 | rxq->need_update = 1; |
| 3261 | spin_unlock_irqrestore(&rxq->lock, flags); |
Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 3262 | rc = iwl_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3263 | if (rc) |
| 3264 | return rc; |
| 3265 | } |
| 3266 | |
| 3267 | return 0; |
| 3268 | } |
| 3269 | |
| 3270 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3271 | * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3272 | * |
| 3273 | * When moving to rx_free an SKB is allocated for the slot. |
| 3274 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3275 | * Also restock the Rx queue via iwl3945_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3276 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3277 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3278 | static void iwl3945_rx_allocate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3279 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3280 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3281 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3282 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3283 | unsigned long flags; |
| 3284 | spin_lock_irqsave(&rxq->lock, flags); |
| 3285 | while (!list_empty(&rxq->rx_used)) { |
| 3286 | element = rxq->rx_used.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3287 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3288 | |
| 3289 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3290 | rxb->skb = |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 3291 | alloc_skb(priv->hw_params.rx_buf_size, |
| 3292 | __GFP_NOWARN | GFP_ATOMIC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3293 | if (!rxb->skb) { |
| 3294 | if (net_ratelimit()) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 3295 | IWL_CRIT(priv, ": Can not allocate SKB buffers\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3296 | /* We don't reschedule replenish work here -- we will |
| 3297 | * call the restock method and if it still needs |
| 3298 | * more buffers it will schedule replenish */ |
| 3299 | break; |
| 3300 | } |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 3301 | |
| 3302 | /* If radiotap head is required, reserve some headroom here. |
| 3303 | * The physical head count is a variable rx_stats->phy_count. |
| 3304 | * We reserve 4 bytes here. Plus these extra bytes, the |
| 3305 | * headroom of the physical head should be enough for the |
| 3306 | * radiotap head that iwl3945 supported. See iwl3945_rt. |
| 3307 | */ |
| 3308 | skb_reserve(rxb->skb, 4); |
| 3309 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3310 | priv->alloc_rxb_skb++; |
| 3311 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3312 | |
| 3313 | /* Get physical address of RB/SKB */ |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 3314 | rxb->real_dma_addr = pci_map_single(priv->pci_dev, |
| 3315 | rxb->skb->data, |
| 3316 | priv->hw_params.rx_buf_size, |
| 3317 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3318 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 3319 | rxq->free_count++; |
| 3320 | } |
| 3321 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | /* |
| 3325 | * this should be called while priv->lock is locked |
| 3326 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 3327 | static void __iwl3945_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3328 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3329 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3330 | |
| 3331 | iwl3945_rx_allocate(priv); |
| 3332 | iwl3945_rx_queue_restock(priv); |
| 3333 | } |
| 3334 | |
| 3335 | |
| 3336 | void iwl3945_rx_replenish(void *data) |
| 3337 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3338 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3339 | unsigned long flags; |
| 3340 | |
| 3341 | iwl3945_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3342 | |
| 3343 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3344 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3345 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3346 | } |
| 3347 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3348 | /* Convert linear signal-to-noise ratio into dB */ |
| 3349 | static u8 ratio2dB[100] = { |
| 3350 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 3351 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 3352 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 3353 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 3354 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 3355 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 3356 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 3357 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 3358 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 3359 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 3360 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 3361 | }; |
| 3362 | |
| 3363 | /* Calculates a relative dB value from a ratio of linear |
| 3364 | * (i.e. not dB) signal levels. |
| 3365 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3366 | int iwl3945_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3367 | { |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3368 | /* 1000:1 or higher just report as 60 dB */ |
| 3369 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3370 | return 60; |
| 3371 | |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3372 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3373 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3374 | if (sig_ratio >= 100) |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 3375 | return 20 + (int)ratio2dB[sig_ratio/10]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3376 | |
| 3377 | /* We shouldn't see this */ |
| 3378 | if (sig_ratio < 1) |
| 3379 | return 0; |
| 3380 | |
| 3381 | /* Use table for ratios 1:1 - 99:1 */ |
| 3382 | return (int)ratio2dB[sig_ratio]; |
| 3383 | } |
| 3384 | |
| 3385 | #define PERFECT_RSSI (-20) /* dBm */ |
| 3386 | #define WORST_RSSI (-95) /* dBm */ |
| 3387 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 3388 | |
| 3389 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 3390 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 3391 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3392 | int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3393 | { |
| 3394 | int sig_qual; |
| 3395 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 3396 | |
| 3397 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 3398 | * as indicator; formula is (signal dbm - noise dbm). |
| 3399 | * SNR at or above 40 is a great signal (100%). |
| 3400 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 3401 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 3402 | if (noise_dbm) { |
| 3403 | if (rssi_dbm - noise_dbm >= 40) |
| 3404 | return 100; |
| 3405 | else if (rssi_dbm < noise_dbm) |
| 3406 | return 0; |
| 3407 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 3408 | |
| 3409 | /* Else use just the signal level. |
| 3410 | * This formula is a least squares fit of data points collected and |
| 3411 | * compared with a reference system that had a percentage (%) display |
| 3412 | * for signal quality. */ |
| 3413 | } else |
| 3414 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 3415 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 3416 | (RSSI_RANGE * RSSI_RANGE); |
| 3417 | |
| 3418 | if (sig_qual > 100) |
| 3419 | sig_qual = 100; |
| 3420 | else if (sig_qual < 1) |
| 3421 | sig_qual = 0; |
| 3422 | |
| 3423 | return sig_qual; |
| 3424 | } |
| 3425 | |
| 3426 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3427 | * iwl3945_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3428 | * |
| 3429 | * Uses the priv->rx_handlers callback function array to invoke |
| 3430 | * the appropriate handlers, including command responses, |
| 3431 | * frame-received notifications, and other notifications. |
| 3432 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3433 | static void iwl3945_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3434 | { |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3435 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3436 | struct iwl_rx_packet *pkt; |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3437 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3438 | u32 r, i; |
| 3439 | int reclaim; |
| 3440 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3441 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 3442 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3443 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3444 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 3445 | * buffer that the driver may process (last buffer filled by ucode). */ |
Winkler, Tomas | 8cd812b | 2008-12-19 10:37:43 +0800 | [diff] [blame] | 3446 | r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3447 | i = rxq->read; |
| 3448 | |
Winkler, Tomas | 37d6831 | 2009-01-08 10:19:54 -0800 | [diff] [blame] | 3449 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3450 | fill_rx = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3451 | /* Rx interrupt, but nothing sent from uCode */ |
| 3452 | if (i == r) |
| 3453 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 3454 | |
| 3455 | while (i != r) { |
| 3456 | rxb = rxq->queue[i]; |
| 3457 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3458 | /* If an RXB doesn't have a Rx queue slot associated with it, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3459 | * then a bug has been introduced in the queue refilling |
| 3460 | * routines -- catch it here */ |
| 3461 | BUG_ON(rxb == NULL); |
| 3462 | |
| 3463 | rxq->queue[i] = NULL; |
| 3464 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3465 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr, |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 3466 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3467 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3468 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3469 | |
| 3470 | /* Reclaim a command buffer only if this packet is a response |
| 3471 | * to a (driver-originated) command. |
| 3472 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3473 | * there is no command buffer to reclaim. |
| 3474 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3475 | * but apparently a few don't get set; catch them here. */ |
| 3476 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 3477 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 3478 | (pkt->hdr.cmd != REPLY_TX); |
| 3479 | |
| 3480 | /* Based on type of command response or notification, |
| 3481 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3482 | * rx_handlers table. See iwl3945_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3483 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3484 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3485 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 3486 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 3487 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 3488 | } else { |
| 3489 | /* No handling needed */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3490 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3491 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 3492 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 3493 | pkt->hdr.cmd); |
| 3494 | } |
| 3495 | |
| 3496 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3497 | /* Invoke any callbacks, transfer the skb to caller, and |
| 3498 | * fire off the (possibly) blocking iwl3945_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3499 | * as we reclaim the driver command queue */ |
| 3500 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3501 | iwl3945_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3502 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3503 | IWL_WARN(priv, "Claim null rxb?\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | /* For now we just don't re-use anything. We can tweak this |
| 3507 | * later to try and re-use notification packets and SKBs that |
| 3508 | * fail to Rx correctly */ |
| 3509 | if (rxb->skb != NULL) { |
| 3510 | priv->alloc_rxb_skb--; |
| 3511 | dev_kfree_skb_any(rxb->skb); |
| 3512 | rxb->skb = NULL; |
| 3513 | } |
| 3514 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3515 | pci_unmap_single(priv->pci_dev, rxb->real_dma_addr, |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 3516 | priv->hw_params.rx_buf_size, |
| 3517 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3518 | spin_lock_irqsave(&rxq->lock, flags); |
| 3519 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 3520 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3521 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3522 | /* If there are a lot of unused frames, |
| 3523 | * restock the Rx queue so ucode won't assert. */ |
| 3524 | if (fill_rx) { |
| 3525 | count++; |
| 3526 | if (count >= 8) { |
| 3527 | priv->rxq.read = i; |
| 3528 | __iwl3945_rx_replenish(priv); |
| 3529 | count = 0; |
| 3530 | } |
| 3531 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | /* Backtrack one entry */ |
| 3535 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3536 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3539 | /** |
| 3540 | * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware |
| 3541 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3542 | static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3543 | struct iwl_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3544 | { |
| 3545 | u32 reg = 0; |
| 3546 | int rc = 0; |
| 3547 | int txq_id = txq->q.id; |
| 3548 | |
| 3549 | if (txq->need_update == 0) |
| 3550 | return rc; |
| 3551 | |
| 3552 | /* if we're trying to save power */ |
| 3553 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 3554 | /* wake up nic if it's powered down ... |
| 3555 | * uCode will wake up, and interrupt us again, so next |
| 3556 | * time we'll skip this part. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3557 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3558 | |
| 3559 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 3560 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3561 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3562 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3563 | return rc; |
| 3564 | } |
| 3565 | |
| 3566 | /* restore this queue's parameters in nic hardware. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3567 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3568 | if (rc) |
| 3569 | return rc; |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3570 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3571 | txq->q.write_ptr | (txq_id << 8)); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3572 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3573 | |
| 3574 | /* else not in power-save mode, uCode will never sleep when we're |
| 3575 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 3576 | } else |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3577 | iwl_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3578 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3579 | |
| 3580 | txq->need_update = 0; |
| 3581 | |
| 3582 | return rc; |
| 3583 | } |
| 3584 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3585 | #ifdef CONFIG_IWL3945_DEBUG |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3586 | static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3587 | struct iwl3945_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3588 | { |
| 3589 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3590 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3591 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 3592 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 3593 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 3594 | le32_to_cpu(rxon->filter_flags)); |
| 3595 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 3596 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 3597 | rxon->ofdm_basic_rates); |
| 3598 | IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3599 | IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr); |
| 3600 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3601 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 3602 | } |
| 3603 | #endif |
| 3604 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3605 | static void iwl3945_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3606 | { |
| 3607 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 3608 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3609 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3610 | } |
| 3611 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3612 | |
| 3613 | /* call this function to flush any scheduled tasklet */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3614 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3615 | { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 3616 | /* wait to make sure we flush pending tasklet*/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3617 | synchronize_irq(priv->pci_dev->irq); |
| 3618 | tasklet_kill(&priv->irq_tasklet); |
| 3619 | } |
| 3620 | |
| 3621 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3622 | static inline void iwl3945_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3623 | { |
| 3624 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 3625 | |
| 3626 | /* disable interrupts from uCode/NIC to host */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3627 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3628 | |
| 3629 | /* acknowledge/clear/reset any interrupts still pending |
| 3630 | * from uCode or flow handler (Rx/Tx DMA) */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3631 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 3632 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3633 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 3634 | } |
| 3635 | |
| 3636 | static const char *desc_lookup(int i) |
| 3637 | { |
| 3638 | switch (i) { |
| 3639 | case 1: |
| 3640 | return "FAIL"; |
| 3641 | case 2: |
| 3642 | return "BAD_PARAM"; |
| 3643 | case 3: |
| 3644 | return "BAD_CHECKSUM"; |
| 3645 | case 4: |
| 3646 | return "NMI_INTERRUPT"; |
| 3647 | case 5: |
| 3648 | return "SYSASSERT"; |
| 3649 | case 6: |
| 3650 | return "FATAL_ERROR"; |
| 3651 | } |
| 3652 | |
| 3653 | return "UNKNOWN"; |
| 3654 | } |
| 3655 | |
| 3656 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 3657 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 3658 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3659 | static void iwl3945_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3660 | { |
| 3661 | u32 i; |
| 3662 | u32 desc, time, count, base, data1; |
| 3663 | u32 blink1, blink2, ilink1, ilink2; |
| 3664 | int rc; |
| 3665 | |
| 3666 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 3667 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3668 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3669 | IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3670 | return; |
| 3671 | } |
| 3672 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3673 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3674 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3675 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3676 | return; |
| 3677 | } |
| 3678 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3679 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3680 | |
| 3681 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3682 | IWL_ERR(priv, "Start IWL Error Log Dump:\n"); |
| 3683 | IWL_ERR(priv, "Status: 0x%08lX, count: %d\n", |
| 3684 | priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3685 | } |
| 3686 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3687 | IWL_ERR(priv, "Desc Time asrtPC blink2 " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3688 | "ilink1 nmiPC Line\n"); |
| 3689 | for (i = ERROR_START_OFFSET; |
| 3690 | i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET; |
| 3691 | i += ERROR_ELEM_SIZE) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3692 | desc = iwl_read_targ_mem(priv, base + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3693 | time = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3694 | iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3695 | blink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3696 | iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3697 | blink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3698 | iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3699 | ilink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3700 | iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3701 | ilink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3702 | iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3703 | data1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3704 | iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3705 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3706 | IWL_ERR(priv, |
| 3707 | "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n", |
| 3708 | desc_lookup(desc), desc, time, blink1, blink2, |
| 3709 | ilink1, ilink2, data1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3712 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3713 | |
| 3714 | } |
| 3715 | |
Ben Cahill | f58177b | 2007-11-29 11:09:43 +0800 | [diff] [blame] | 3716 | #define EVENT_START_OFFSET (6 * sizeof(u32)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3717 | |
| 3718 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3719 | * iwl3945_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3720 | * |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3721 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3722 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3723 | static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3724 | u32 num_events, u32 mode) |
| 3725 | { |
| 3726 | u32 i; |
| 3727 | u32 base; /* SRAM byte address of event log header */ |
| 3728 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 3729 | u32 ptr; /* SRAM byte address of log data */ |
| 3730 | u32 ev, time, data; /* event log data */ |
| 3731 | |
| 3732 | if (num_events == 0) |
| 3733 | return; |
| 3734 | |
| 3735 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 3736 | |
| 3737 | if (mode == 0) |
| 3738 | event_size = 2 * sizeof(u32); |
| 3739 | else |
| 3740 | event_size = 3 * sizeof(u32); |
| 3741 | |
| 3742 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 3743 | |
| 3744 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 3745 | * place event id # at far right for easier visual parsing. */ |
| 3746 | for (i = 0; i < num_events; i++) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3747 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3748 | ptr += sizeof(u32); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3749 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3750 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3751 | if (mode == 0) { |
| 3752 | /* data, ev */ |
| 3753 | IWL_ERR(priv, "0x%08x\t%04u\n", time, ev); |
| 3754 | } else { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3755 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3756 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3757 | IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3758 | } |
| 3759 | } |
| 3760 | } |
| 3761 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3762 | static void iwl3945_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3763 | { |
| 3764 | int rc; |
| 3765 | u32 base; /* SRAM byte address of event log header */ |
| 3766 | u32 capacity; /* event log capacity in # entries */ |
| 3767 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 3768 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 3769 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 3770 | u32 size; /* # entries that we'll print */ |
| 3771 | |
| 3772 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3773 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3774 | IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3775 | return; |
| 3776 | } |
| 3777 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3778 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3779 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3780 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3781 | return; |
| 3782 | } |
| 3783 | |
| 3784 | /* event log header */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3785 | capacity = iwl_read_targ_mem(priv, base); |
| 3786 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 3787 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 3788 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3789 | |
| 3790 | size = num_wraps ? capacity : next_entry; |
| 3791 | |
| 3792 | /* bail out if nothing in log */ |
| 3793 | if (size == 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3794 | IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3795 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3796 | return; |
| 3797 | } |
| 3798 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3799 | IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3800 | size, num_wraps); |
| 3801 | |
| 3802 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 3803 | * i.e the next one that uCode would fill. */ |
| 3804 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3805 | iwl3945_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3806 | capacity - next_entry, mode); |
| 3807 | |
| 3808 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3809 | iwl3945_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3810 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3811 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3815 | * iwl3945_irq_handle_error - called for HW or SW error interrupt from card |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3816 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3817 | static void iwl3945_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3818 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3819 | /* Set the FW error flag -- cleared on iwl3945_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3820 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 3821 | |
| 3822 | /* Cancel currently queued command. */ |
| 3823 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3824 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3825 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3826 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3827 | iwl3945_dump_nic_error_log(priv); |
| 3828 | iwl3945_dump_nic_event_log(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3829 | iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3830 | } |
| 3831 | #endif |
| 3832 | |
| 3833 | wake_up_interruptible(&priv->wait_command_queue); |
| 3834 | |
| 3835 | /* Keep the restart process from trying to send host |
| 3836 | * commands by clearing the INIT status bit */ |
| 3837 | clear_bit(STATUS_READY, &priv->status); |
| 3838 | |
| 3839 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3840 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 3841 | "Restarting adapter due to uCode error.\n"); |
| 3842 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3843 | if (iwl3945_is_associated(priv)) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3844 | memcpy(&priv->recovery39_rxon, &priv->active39_rxon, |
| 3845 | sizeof(priv->recovery39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3846 | priv->error_recovering = 1; |
| 3847 | } |
| 3848 | queue_work(priv->workqueue, &priv->restart); |
| 3849 | } |
| 3850 | } |
| 3851 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3852 | static void iwl3945_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3853 | { |
| 3854 | unsigned long flags; |
| 3855 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3856 | memcpy(&priv->staging39_rxon, &priv->recovery39_rxon, |
| 3857 | sizeof(priv->staging39_rxon)); |
| 3858 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3859 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3860 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3861 | iwl3945_add_station(priv, priv->bssid, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3862 | |
| 3863 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3864 | priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3865 | priv->error_recovering = 0; |
| 3866 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3867 | } |
| 3868 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3869 | static void iwl3945_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3870 | { |
| 3871 | u32 inta, handled = 0; |
| 3872 | u32 inta_fh; |
| 3873 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3874 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3875 | u32 inta_mask; |
| 3876 | #endif |
| 3877 | |
| 3878 | spin_lock_irqsave(&priv->lock, flags); |
| 3879 | |
| 3880 | /* Ack/clear/reset pending uCode interrupts. |
| 3881 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 3882 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3883 | inta = iwl_read32(priv, CSR_INT); |
| 3884 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3885 | |
| 3886 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 3887 | * Any new interrupts that happen after this, either while we're |
| 3888 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3889 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 3890 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3891 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3892 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3893 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3894 | /* just for debug */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3895 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3896 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 3897 | inta, inta_mask, inta_fh); |
| 3898 | } |
| 3899 | #endif |
| 3900 | |
| 3901 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 3902 | * atomic, make sure that inta covers all the interrupts that |
| 3903 | * we've discovered, even if FH interrupt came in just after |
| 3904 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3905 | if (inta_fh & CSR39_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3906 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3907 | if (inta_fh & CSR39_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3908 | inta |= CSR_INT_BIT_FH_TX; |
| 3909 | |
| 3910 | /* Now service all interrupt bits discovered above. */ |
| 3911 | if (inta & CSR_INT_BIT_HW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3912 | IWL_ERR(priv, "Microcode HW error detected. Restarting.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3913 | |
| 3914 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3915 | iwl3945_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3916 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3917 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3918 | |
| 3919 | handled |= CSR_INT_BIT_HW_ERR; |
| 3920 | |
| 3921 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3922 | |
| 3923 | return; |
| 3924 | } |
| 3925 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3926 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3927 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3928 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3929 | if (inta & CSR_INT_BIT_SCD) |
| 3930 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 3931 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3932 | |
| 3933 | /* Alive notification via Rx interrupt will do the real work */ |
| 3934 | if (inta & CSR_INT_BIT_ALIVE) |
| 3935 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 3936 | } |
| 3937 | #endif |
| 3938 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3939 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3940 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3941 | /* Error detected by uCode */ |
| 3942 | if (inta & CSR_INT_BIT_SW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3943 | IWL_ERR(priv, "Microcode SW error detected. " |
| 3944 | "Restarting 0x%X.\n", inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3945 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3946 | handled |= CSR_INT_BIT_SW_ERR; |
| 3947 | } |
| 3948 | |
| 3949 | /* uCode wakes up after power-down sleep */ |
| 3950 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 3951 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 3952 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3953 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 3954 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 3955 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 3956 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 3957 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 3958 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3959 | |
| 3960 | handled |= CSR_INT_BIT_WAKEUP; |
| 3961 | } |
| 3962 | |
| 3963 | /* All uCode command responses, including Tx command responses, |
| 3964 | * Rx "responses" (frame-received notification), and other |
| 3965 | * notifications from uCode come through here*/ |
| 3966 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3967 | iwl3945_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3968 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 3969 | } |
| 3970 | |
| 3971 | if (inta & CSR_INT_BIT_FH_TX) { |
| 3972 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 3973 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3974 | iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); |
| 3975 | if (!iwl_grab_nic_access(priv)) { |
| 3976 | iwl_write_direct32(priv, FH39_TCSR_CREDIT |
Tomas Winkler | bddadf8 | 2008-12-19 10:37:01 +0800 | [diff] [blame] | 3977 | (FH39_SRVC_CHNL), 0x0); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3978 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3979 | } |
| 3980 | handled |= CSR_INT_BIT_FH_TX; |
| 3981 | } |
| 3982 | |
| 3983 | if (inta & ~handled) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3984 | IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3985 | |
| 3986 | if (inta & ~CSR_INI_SET_MASK) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3987 | IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3988 | inta & ~CSR_INI_SET_MASK); |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3989 | IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3993 | /* only Re-enable if disabled by irq */ |
| 3994 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 3995 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3996 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3997 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3998 | if (priv->debug_level & (IWL_DL_ISR)) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3999 | inta = iwl_read32(priv, CSR_INT); |
| 4000 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 4001 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4002 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 4003 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 4004 | } |
| 4005 | #endif |
| 4006 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4007 | } |
| 4008 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4009 | static irqreturn_t iwl3945_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4010 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4011 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4012 | u32 inta, inta_mask; |
| 4013 | u32 inta_fh; |
| 4014 | if (!priv) |
| 4015 | return IRQ_NONE; |
| 4016 | |
| 4017 | spin_lock(&priv->lock); |
| 4018 | |
| 4019 | /* Disable (but don't clear!) interrupts here to avoid |
| 4020 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 4021 | * If we have something to service, the tasklet will re-enable ints. |
| 4022 | * If we *don't* have something, we'll re-enable before leaving here. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4023 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 4024 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4025 | |
| 4026 | /* Discover which interrupts are active/pending */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4027 | inta = iwl_read32(priv, CSR_INT); |
| 4028 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4029 | |
| 4030 | /* Ignore interrupt if there's nothing in NIC to service. |
| 4031 | * This may be due to IRQ shared with another device, |
| 4032 | * or due to sporadic interrupts thrown from our NIC. */ |
| 4033 | if (!inta && !inta_fh) { |
| 4034 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 4035 | goto none; |
| 4036 | } |
| 4037 | |
| 4038 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
| 4039 | /* Hardware disappeared */ |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4040 | IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4041 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4045 | inta, inta_mask, inta_fh); |
| 4046 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4047 | inta &= ~CSR_INT_BIT_SCD; |
| 4048 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4049 | /* iwl3945_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4050 | if (likely(inta || inta_fh)) |
| 4051 | tasklet_schedule(&priv->irq_tasklet); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4052 | unplugged: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4053 | spin_unlock(&priv->lock); |
| 4054 | |
| 4055 | return IRQ_HANDLED; |
| 4056 | |
| 4057 | none: |
| 4058 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4059 | /* only Re-enable if disabled by irq */ |
| 4060 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 4061 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4062 | spin_unlock(&priv->lock); |
| 4063 | return IRQ_NONE; |
| 4064 | } |
| 4065 | |
| 4066 | /************************** EEPROM BANDS **************************** |
| 4067 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4068 | * The iwl3945_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4069 | * EEPROM contents to the specific channel number supported for each |
| 4070 | * band. |
| 4071 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4072 | * For example, iwl3945_priv->eeprom39.band_3_channels[4] from the band_3 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4073 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 4074 | * The specific geography and calibration information for that channel |
| 4075 | * is contained in the eeprom map itself. |
| 4076 | * |
| 4077 | * During init, we copy the eeprom information and channel map |
| 4078 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 4079 | * |
| 4080 | * channel_map_24/52 provides the index in the channel_info array for a |
| 4081 | * given channel. We have to have two separate maps as there is channel |
| 4082 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 4083 | * band_2 |
| 4084 | * |
| 4085 | * A value of 0xff stored in the channel_map indicates that the channel |
| 4086 | * is not supported by the hardware at all. |
| 4087 | * |
| 4088 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 4089 | * valid for Tx with the current hardware. This means that |
| 4090 | * while the system can tune and receive on a given channel, it may not |
| 4091 | * be able to associate or transmit any frames on that |
| 4092 | * channel. There is no corresponding channel information for that |
| 4093 | * entry. |
| 4094 | * |
| 4095 | *********************************************************************/ |
| 4096 | |
| 4097 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4098 | static const u8 iwl3945_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4099 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 4100 | }; |
| 4101 | |
| 4102 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4103 | static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4104 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 4105 | }; |
| 4106 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4107 | static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4108 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 4109 | }; |
| 4110 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4111 | static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4112 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 4113 | }; |
| 4114 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4115 | static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4116 | 145, 149, 153, 157, 161, 165 |
| 4117 | }; |
| 4118 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4119 | static void iwl3945_init_band_reference(const struct iwl_priv *priv, int band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4120 | int *eeprom_ch_count, |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4121 | const struct iwl_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4122 | **eeprom_ch_info, |
| 4123 | const u8 **eeprom_ch_index) |
| 4124 | { |
| 4125 | switch (band) { |
| 4126 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4127 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4128 | *eeprom_ch_info = priv->eeprom39.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4129 | *eeprom_ch_index = iwl3945_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4130 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4131 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4132 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4133 | *eeprom_ch_info = priv->eeprom39.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4134 | *eeprom_ch_index = iwl3945_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4135 | break; |
| 4136 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4137 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4138 | *eeprom_ch_info = priv->eeprom39.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4139 | *eeprom_ch_index = iwl3945_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4140 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4141 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4142 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4143 | *eeprom_ch_info = priv->eeprom39.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4144 | *eeprom_ch_index = iwl3945_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4145 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4146 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4147 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4148 | *eeprom_ch_info = priv->eeprom39.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4149 | *eeprom_ch_index = iwl3945_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4150 | break; |
| 4151 | default: |
| 4152 | BUG(); |
| 4153 | return; |
| 4154 | } |
| 4155 | } |
| 4156 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4157 | /** |
| 4158 | * iwl3945_get_channel_info - Find driver's private channel info |
| 4159 | * |
| 4160 | * Based on band and channel number. |
| 4161 | */ |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4162 | const struct iwl_channel_info * |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4163 | iwl3945_get_channel_info(const struct iwl_priv *priv, |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4164 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4165 | { |
| 4166 | int i; |
| 4167 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4168 | switch (band) { |
| 4169 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4170 | for (i = 14; i < priv->channel_count; i++) { |
| 4171 | if (priv->channel_info[i].channel == channel) |
| 4172 | return &priv->channel_info[i]; |
| 4173 | } |
| 4174 | break; |
| 4175 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4176 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4177 | if (channel >= 1 && channel <= 14) |
| 4178 | return &priv->channel_info[channel - 1]; |
| 4179 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4180 | case IEEE80211_NUM_BANDS: |
| 4181 | WARN_ON(1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | return NULL; |
| 4185 | } |
| 4186 | |
| 4187 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 4188 | ? # x " " : "") |
| 4189 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4190 | /** |
| 4191 | * iwl3945_init_channel_map - Set up driver's info for all possible channels |
| 4192 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4193 | static int iwl3945_init_channel_map(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4194 | { |
| 4195 | int eeprom_ch_count = 0; |
| 4196 | const u8 *eeprom_ch_index = NULL; |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4197 | const struct iwl_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4198 | int band, ch; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4199 | struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4200 | |
| 4201 | if (priv->channel_count) { |
| 4202 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 4203 | return 0; |
| 4204 | } |
| 4205 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4206 | if (priv->eeprom39.version < 0x2f) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4207 | IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4208 | priv->eeprom39.version); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4209 | return -EINVAL; |
| 4210 | } |
| 4211 | |
| 4212 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 4213 | |
| 4214 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4215 | ARRAY_SIZE(iwl3945_eeprom_band_1) + |
| 4216 | ARRAY_SIZE(iwl3945_eeprom_band_2) + |
| 4217 | ARRAY_SIZE(iwl3945_eeprom_band_3) + |
| 4218 | ARRAY_SIZE(iwl3945_eeprom_band_4) + |
| 4219 | ARRAY_SIZE(iwl3945_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4220 | |
| 4221 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 4222 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4223 | priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4224 | priv->channel_count, GFP_KERNEL); |
| 4225 | if (!priv->channel_info) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4226 | IWL_ERR(priv, "Could not allocate channel_info\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4227 | priv->channel_count = 0; |
| 4228 | return -ENOMEM; |
| 4229 | } |
| 4230 | |
| 4231 | ch_info = priv->channel_info; |
| 4232 | |
| 4233 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 4234 | * channel map we maintain (that contains additional information than |
| 4235 | * what just in the EEPROM) */ |
| 4236 | for (band = 1; band <= 5; band++) { |
| 4237 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4238 | iwl3945_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4239 | &eeprom_ch_info, &eeprom_ch_index); |
| 4240 | |
| 4241 | /* Loop through each band adding each of the channels */ |
| 4242 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 4243 | ch_info->channel = eeprom_ch_index[ch]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4244 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 4245 | IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4246 | |
| 4247 | /* permanently store EEPROM's channel regulatory flags |
| 4248 | * and max power in channel info database. */ |
| 4249 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 4250 | |
| 4251 | /* Copy the run-time flags so they are there even on |
| 4252 | * invalid channels */ |
| 4253 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 4254 | |
| 4255 | if (!(is_channel_valid(ch_info))) { |
| 4256 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 4257 | "No traffic\n", |
| 4258 | ch_info->channel, |
| 4259 | ch_info->flags, |
| 4260 | is_channel_a_band(ch_info) ? |
| 4261 | "5.2" : "2.4"); |
| 4262 | ch_info++; |
| 4263 | continue; |
| 4264 | } |
| 4265 | |
| 4266 | /* Initialize regulatory-based run-time data */ |
| 4267 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 4268 | eeprom_ch_info[ch].max_power_avg; |
| 4269 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 4270 | ch_info->min_power = 0; |
| 4271 | |
Guy Cohen | fe7c404 | 2008-04-21 15:41:56 -0700 | [diff] [blame] | 4272 | IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4273 | " %ddBm): Ad-Hoc %ssupported\n", |
| 4274 | ch_info->channel, |
| 4275 | is_channel_a_band(ch_info) ? |
| 4276 | "5.2" : "2.4", |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4277 | CHECK_AND_PRINT(VALID), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4278 | CHECK_AND_PRINT(IBSS), |
| 4279 | CHECK_AND_PRINT(ACTIVE), |
| 4280 | CHECK_AND_PRINT(RADAR), |
| 4281 | CHECK_AND_PRINT(WIDE), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4282 | CHECK_AND_PRINT(DFS), |
| 4283 | eeprom_ch_info[ch].flags, |
| 4284 | eeprom_ch_info[ch].max_power_avg, |
| 4285 | ((eeprom_ch_info[ch]. |
| 4286 | flags & EEPROM_CHANNEL_IBSS) |
| 4287 | && !(eeprom_ch_info[ch]. |
| 4288 | flags & EEPROM_CHANNEL_RADAR)) |
| 4289 | ? "" : "not "); |
| 4290 | |
| 4291 | /* Set the user_txpower_limit to the highest power |
| 4292 | * supported by any channel */ |
| 4293 | if (eeprom_ch_info[ch].max_power_avg > |
| 4294 | priv->user_txpower_limit) |
| 4295 | priv->user_txpower_limit = |
| 4296 | eeprom_ch_info[ch].max_power_avg; |
| 4297 | |
| 4298 | ch_info++; |
| 4299 | } |
| 4300 | } |
| 4301 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4302 | /* Set up txpower settings in driver for all channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4303 | if (iwl3945_txpower_set_from_eeprom(priv)) |
| 4304 | return -EIO; |
| 4305 | |
| 4306 | return 0; |
| 4307 | } |
| 4308 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4309 | /* |
| 4310 | * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map |
| 4311 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4312 | static void iwl3945_free_channel_map(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4313 | { |
| 4314 | kfree(priv->channel_info); |
| 4315 | priv->channel_count = 0; |
| 4316 | } |
| 4317 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4318 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 4319 | * sending probe req. This should be set long enough to hear probe responses |
| 4320 | * from more than one AP. */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4321 | #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */ |
| 4322 | #define IWL_ACTIVE_DWELL_TIME_52 (20) |
| 4323 | |
| 4324 | #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3) |
| 4325 | #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4326 | |
| 4327 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 4328 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 4329 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 4330 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 4331 | * no other traffic). |
| 4332 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 4333 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4334 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4335 | |
| 4336 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 4337 | * Must be set longer than active dwell time. |
| 4338 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 4339 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 4340 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 4341 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 4342 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 4343 | |
Kolekar, Abhijeet | e720ce9 | 2008-11-07 09:58:42 -0800 | [diff] [blame] | 4344 | #define IWL_SCAN_PROBE_MASK(n) (BIT(n) | (BIT(n) - BIT(1))) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4345 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4346 | static inline u16 iwl3945_get_active_dwell_time(struct iwl_priv *priv, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4347 | enum ieee80211_band band, |
| 4348 | u8 n_probes) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4349 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4350 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4351 | return IWL_ACTIVE_DWELL_TIME_52 + |
| 4352 | IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4353 | else |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4354 | return IWL_ACTIVE_DWELL_TIME_24 + |
| 4355 | IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4356 | } |
| 4357 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4358 | static u16 iwl3945_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4359 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4360 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4361 | u16 passive = (band == IEEE80211_BAND_2GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4362 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 4363 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 4364 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4365 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4366 | /* If we're associated, we clamp the maximum passive |
| 4367 | * dwell time to be 98% of the beacon interval (minus |
| 4368 | * 2 * channel tune time) */ |
| 4369 | passive = priv->beacon_int; |
| 4370 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 4371 | passive = IWL_PASSIVE_DWELL_BASE; |
| 4372 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 4373 | } |
| 4374 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4375 | return passive; |
| 4376 | } |
| 4377 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4378 | static int iwl3945_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4379 | enum ieee80211_band band, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4380 | u8 is_active, u8 n_probes, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4381 | struct iwl3945_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4382 | { |
| 4383 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4384 | const struct ieee80211_supported_band *sband; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4385 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4386 | u16 passive_dwell = 0; |
| 4387 | u16 active_dwell = 0; |
| 4388 | int added, i; |
| 4389 | |
Kolekar, Abhijeet | cbba18c | 2008-12-19 10:37:42 +0800 | [diff] [blame] | 4390 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4391 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4392 | return 0; |
| 4393 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4394 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4395 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4396 | active_dwell = iwl3945_get_active_dwell_time(priv, band, n_probes); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4397 | passive_dwell = iwl3945_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4398 | |
Abhijeet Kolekar | 8f4807a | 2008-09-03 11:26:31 +0800 | [diff] [blame] | 4399 | if (passive_dwell <= active_dwell) |
| 4400 | passive_dwell = active_dwell + 1; |
| 4401 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4402 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 4403 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 4404 | continue; |
| 4405 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4406 | scan_ch->channel = channels[i].hw_value; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4407 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4408 | ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4409 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 4410 | IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4411 | scan_ch->channel); |
| 4412 | continue; |
| 4413 | } |
| 4414 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4415 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 4416 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 4417 | /* If passive , set up for auto-switch |
| 4418 | * and use long active_dwell time. |
| 4419 | */ |
| 4420 | if (!is_active || is_channel_passive(ch_info) || |
| 4421 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) { |
| 4422 | scan_ch->type = 0; /* passive */ |
| 4423 | if (IWL_UCODE_API(priv->ucode_ver) == 1) |
| 4424 | scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1); |
| 4425 | } else { |
| 4426 | scan_ch->type = 1; /* active */ |
| 4427 | } |
| 4428 | |
| 4429 | /* Set direct probe bits. These may be used both for active |
| 4430 | * scan channels (probes gets sent right away), |
| 4431 | * or for passive channels (probes get se sent only after |
| 4432 | * hearing clear Rx packet).*/ |
| 4433 | if (IWL_UCODE_API(priv->ucode_ver) >= 2) { |
| 4434 | if (n_probes) |
| 4435 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4436 | } else { |
| 4437 | /* uCode v1 does not allow setting direct probe bits on |
| 4438 | * passive channel. */ |
| 4439 | if ((scan_ch->type & 1) && n_probes) |
| 4440 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4441 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4442 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4443 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4444 | scan_ch->tpc.dsp_atten = 110; |
| 4445 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 4446 | |
| 4447 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4448 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4449 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 4450 | else { |
| 4451 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 4452 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4453 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 4454 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4455 | */ |
| 4456 | } |
| 4457 | |
| 4458 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 4459 | scan_ch->channel, |
| 4460 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 4461 | (scan_ch->type & 1) ? |
| 4462 | active_dwell : passive_dwell); |
| 4463 | |
| 4464 | scan_ch++; |
| 4465 | added++; |
| 4466 | } |
| 4467 | |
| 4468 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 4469 | return added; |
| 4470 | } |
| 4471 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4472 | static void iwl3945_init_hw_rates(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4473 | struct ieee80211_rate *rates) |
| 4474 | { |
| 4475 | int i; |
| 4476 | |
| 4477 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4478 | rates[i].bitrate = iwl3945_rates[i].ieee * 5; |
| 4479 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 4480 | rates[i].hw_value_short = i; |
| 4481 | rates[i].flags = 0; |
Samuel Ortiz | d9829a6 | 2008-12-19 10:37:12 +0800 | [diff] [blame] | 4482 | if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4483 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4484 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4485 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4486 | rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4487 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4488 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4493 | * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4494 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4495 | static int iwl3945_init_geos(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4496 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4497 | struct iwl_channel_info *ch; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4498 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4499 | struct ieee80211_channel *channels; |
| 4500 | struct ieee80211_channel *geo_ch; |
| 4501 | struct ieee80211_rate *rates; |
| 4502 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4503 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4504 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 4505 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4506 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 4507 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4508 | return 0; |
| 4509 | } |
| 4510 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4511 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 4512 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4513 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4514 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4515 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4516 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4517 | GFP_KERNEL); |
| 4518 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4519 | kfree(channels); |
| 4520 | return -ENOMEM; |
| 4521 | } |
| 4522 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4523 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4524 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 4525 | sband->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)]; |
| 4526 | /* just OFDM */ |
| 4527 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
| 4528 | sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4529 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4530 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4531 | sband->channels = channels; |
| 4532 | /* OFDM & CCK */ |
| 4533 | sband->bitrates = rates; |
| 4534 | sband->n_bitrates = IWL_RATE_COUNT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4535 | |
| 4536 | priv->ieee_channels = channels; |
| 4537 | priv->ieee_rates = rates; |
| 4538 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4539 | iwl3945_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4540 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4541 | for (i = 0; i < priv->channel_count; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4542 | ch = &priv->channel_info[i]; |
| 4543 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4544 | /* FIXME: might be removed if scan is OK*/ |
| 4545 | if (!is_channel_valid(ch)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4546 | continue; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4547 | |
| 4548 | if (is_channel_a_band(ch)) |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4549 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4550 | else |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4551 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4552 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4553 | geo_ch = &sband->channels[sband->n_channels++]; |
| 4554 | |
| 4555 | geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4556 | geo_ch->max_power = ch->max_power_avg; |
| 4557 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 4558 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4559 | |
| 4560 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4561 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 4562 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4563 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4564 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 4565 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4566 | |
| 4567 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4568 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4569 | |
| 4570 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 4571 | priv->max_channel_txpower_limit = |
| 4572 | ch->max_power_avg; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4573 | } else { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4574 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4575 | } |
| 4576 | |
| 4577 | /* Save flags for reg domain usage */ |
| 4578 | geo_ch->orig_flags = geo_ch->flags; |
| 4579 | |
| 4580 | IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n", |
| 4581 | ch->channel, geo_ch->center_freq, |
| 4582 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 4583 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 4584 | "restricted" : "valid", |
| 4585 | geo_ch->flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4586 | } |
| 4587 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4588 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && |
| 4589 | priv->cfg->sku & IWL_SKU_A) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4590 | IWL_INFO(priv, "Incorrectly detected BG card as ABG. " |
| 4591 | "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 4592 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4593 | priv->cfg->sku &= ~IWL_SKU_A; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4594 | } |
| 4595 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4596 | IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4597 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 4598 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4599 | |
John W. Linville | e0e0a67 | 2008-03-25 15:58:40 -0400 | [diff] [blame] | 4600 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 4601 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 4602 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4603 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 4604 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 4605 | &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4606 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4607 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4608 | |
| 4609 | return 0; |
| 4610 | } |
| 4611 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4612 | /* |
| 4613 | * iwl3945_free_geos - undo allocations in iwl3945_init_geos |
| 4614 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4615 | static void iwl3945_free_geos(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4616 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4617 | kfree(priv->ieee_channels); |
| 4618 | kfree(priv->ieee_rates); |
| 4619 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4620 | } |
| 4621 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4622 | /****************************************************************************** |
| 4623 | * |
| 4624 | * uCode download functions |
| 4625 | * |
| 4626 | ******************************************************************************/ |
| 4627 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4628 | static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4629 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4630 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 4631 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 4632 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 4633 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 4634 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 4635 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4639 | * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4640 | * looking at all data. |
| 4641 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4642 | static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4643 | { |
| 4644 | u32 val; |
| 4645 | u32 save_len = len; |
| 4646 | int rc = 0; |
| 4647 | u32 errcnt; |
| 4648 | |
| 4649 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4650 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4651 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4652 | if (rc) |
| 4653 | return rc; |
| 4654 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4655 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4656 | IWL39_RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4657 | |
| 4658 | errcnt = 0; |
| 4659 | for (; len > 0; len -= sizeof(u32), image++) { |
| 4660 | /* read data comes through single port, auto-incr addr */ |
| 4661 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4662 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4663 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4664 | if (val != le32_to_cpu(*image)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4665 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4666 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4667 | save_len - len, val, le32_to_cpu(*image)); |
| 4668 | rc = -EIO; |
| 4669 | errcnt++; |
| 4670 | if (errcnt >= 20) |
| 4671 | break; |
| 4672 | } |
| 4673 | } |
| 4674 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4675 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4676 | |
| 4677 | if (!errcnt) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 4678 | IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4679 | |
| 4680 | return rc; |
| 4681 | } |
| 4682 | |
| 4683 | |
| 4684 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4685 | * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4686 | * using sample data 100 bytes apart. If these sample points are good, |
| 4687 | * it's a pretty good bet that everything between them is good, too. |
| 4688 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4689 | static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4690 | { |
| 4691 | u32 val; |
| 4692 | int rc = 0; |
| 4693 | u32 errcnt = 0; |
| 4694 | u32 i; |
| 4695 | |
| 4696 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4697 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4698 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4699 | if (rc) |
| 4700 | return rc; |
| 4701 | |
| 4702 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 4703 | /* read data comes through single port, auto-incr addr */ |
| 4704 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4705 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4706 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4707 | i + IWL39_RTC_INST_LOWER_BOUND); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4708 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4709 | if (val != le32_to_cpu(*image)) { |
| 4710 | #if 0 /* Enable this if you want to see details */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4711 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4712 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4713 | i, val, *image); |
| 4714 | #endif |
| 4715 | rc = -EIO; |
| 4716 | errcnt++; |
| 4717 | if (errcnt >= 3) |
| 4718 | break; |
| 4719 | } |
| 4720 | } |
| 4721 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4722 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4723 | |
| 4724 | return rc; |
| 4725 | } |
| 4726 | |
| 4727 | |
| 4728 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4729 | * iwl3945_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4730 | * and verify its contents |
| 4731 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4732 | static int iwl3945_verify_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4733 | { |
| 4734 | __le32 *image; |
| 4735 | u32 len; |
| 4736 | int rc = 0; |
| 4737 | |
| 4738 | /* Try bootstrap */ |
| 4739 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4740 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4741 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4742 | if (rc == 0) { |
| 4743 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 4744 | return 0; |
| 4745 | } |
| 4746 | |
| 4747 | /* Try initialize */ |
| 4748 | image = (__le32 *)priv->ucode_init.v_addr; |
| 4749 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4750 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4751 | if (rc == 0) { |
| 4752 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 4753 | return 0; |
| 4754 | } |
| 4755 | |
| 4756 | /* Try runtime/protocol */ |
| 4757 | image = (__le32 *)priv->ucode_code.v_addr; |
| 4758 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4759 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4760 | if (rc == 0) { |
| 4761 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 4762 | return 0; |
| 4763 | } |
| 4764 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4765 | IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4766 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4767 | /* Since nothing seems to match, show first several data entries in |
| 4768 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 4769 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4770 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4771 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4772 | rc = iwl3945_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4773 | |
| 4774 | return rc; |
| 4775 | } |
| 4776 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4777 | static void iwl3945_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4778 | { |
| 4779 | /* Remove all resets to allow NIC to operate */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4780 | iwl_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4784 | * iwl3945_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4785 | * |
| 4786 | * Copy into buffers for card to fetch via bus-mastering |
| 4787 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4788 | static int iwl3945_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4789 | { |
Kolekar, Abhijeet | a78fe75 | 2008-12-19 10:37:21 +0800 | [diff] [blame] | 4790 | struct iwl_ucode *ucode; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4791 | int ret = -EINVAL, index; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4792 | const struct firmware *ucode_raw; |
| 4793 | /* firmware file name contains uCode/driver compatibility version */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4794 | const char *name_pre = priv->cfg->fw_name_pre; |
| 4795 | const unsigned int api_max = priv->cfg->ucode_api_max; |
| 4796 | const unsigned int api_min = priv->cfg->ucode_api_min; |
| 4797 | char buf[25]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4798 | u8 *src; |
| 4799 | size_t len; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4800 | u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4801 | |
| 4802 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 4803 | * request_firmware() is synchronous, file is in memory on return. */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4804 | for (index = api_max; index >= api_min; index--) { |
| 4805 | sprintf(buf, "%s%u%s", name_pre, index, ".ucode"); |
| 4806 | ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev); |
| 4807 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4808 | IWL_ERR(priv, "%s firmware file req failed: %d\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4809 | buf, ret); |
| 4810 | if (ret == -ENOENT) |
| 4811 | continue; |
| 4812 | else |
| 4813 | goto error; |
| 4814 | } else { |
| 4815 | if (index < api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4816 | IWL_ERR(priv, "Loaded firmware %s, " |
| 4817 | "which is deprecated. " |
| 4818 | " Please use API v%u instead.\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4819 | buf, api_max); |
| 4820 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 4821 | buf, ucode_raw->size); |
| 4822 | break; |
| 4823 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4824 | } |
| 4825 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4826 | if (ret < 0) |
| 4827 | goto error; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4828 | |
| 4829 | /* Make sure that we got at least our header! */ |
| 4830 | if (ucode_raw->size < sizeof(*ucode)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4831 | IWL_ERR(priv, "File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4832 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4833 | goto err_release; |
| 4834 | } |
| 4835 | |
| 4836 | /* Data from ucode file: header followed by uCode images */ |
| 4837 | ucode = (void *)ucode_raw->data; |
| 4838 | |
Chatre, Reinette | c02b3ac | 2008-12-02 12:14:05 -0800 | [diff] [blame] | 4839 | priv->ucode_ver = le32_to_cpu(ucode->ver); |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4840 | api_ver = IWL_UCODE_API(priv->ucode_ver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4841 | inst_size = le32_to_cpu(ucode->inst_size); |
| 4842 | data_size = le32_to_cpu(ucode->data_size); |
| 4843 | init_size = le32_to_cpu(ucode->init_size); |
| 4844 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 4845 | boot_size = le32_to_cpu(ucode->boot_size); |
| 4846 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4847 | /* api_ver should match the api version forming part of the |
| 4848 | * firmware filename ... but we don't check for that and only rely |
| 4849 | * on the API version read from firware header from here on forward */ |
| 4850 | |
| 4851 | if (api_ver < api_min || api_ver > api_max) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4852 | IWL_ERR(priv, "Driver unable to support your firmware API. " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4853 | "Driver supports v%u, firmware is v%u.\n", |
| 4854 | api_max, api_ver); |
| 4855 | priv->ucode_ver = 0; |
| 4856 | ret = -EINVAL; |
| 4857 | goto err_release; |
| 4858 | } |
| 4859 | if (api_ver != api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4860 | IWL_ERR(priv, "Firmware has old API version. Expected %u, " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4861 | "got %u. New firmware can be obtained " |
| 4862 | "from http://www.intellinuxwireless.org.\n", |
| 4863 | api_max, api_ver); |
| 4864 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4865 | IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n", |
| 4866 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 4867 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 4868 | IWL_UCODE_API(priv->ucode_ver), |
| 4869 | IWL_UCODE_SERIAL(priv->ucode_ver)); |
| 4870 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4871 | IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n", |
| 4872 | priv->ucode_ver); |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 4873 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size); |
| 4874 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size); |
| 4875 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size); |
| 4876 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size); |
| 4877 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4878 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4879 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4880 | /* Verify size of file vs. image size info in file's header */ |
| 4881 | if (ucode_raw->size < sizeof(*ucode) + |
| 4882 | inst_size + data_size + init_size + |
| 4883 | init_data_size + boot_size) { |
| 4884 | |
| 4885 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 4886 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4887 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4888 | goto err_release; |
| 4889 | } |
| 4890 | |
| 4891 | /* Verify that uCode images will fit in card's SRAM */ |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4892 | if (inst_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4893 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 4894 | inst_size); |
| 4895 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4896 | goto err_release; |
| 4897 | } |
| 4898 | |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4899 | if (data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4900 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 4901 | data_size); |
| 4902 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4903 | goto err_release; |
| 4904 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4905 | if (init_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4906 | IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n", |
| 4907 | init_size); |
| 4908 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4909 | goto err_release; |
| 4910 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4911 | if (init_data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4912 | IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n", |
| 4913 | init_data_size); |
| 4914 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4915 | goto err_release; |
| 4916 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4917 | if (boot_size > IWL39_MAX_BSM_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4918 | IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n", |
| 4919 | boot_size); |
| 4920 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4921 | goto err_release; |
| 4922 | } |
| 4923 | |
| 4924 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 4925 | |
| 4926 | /* Runtime instructions and 2 copies of data: |
| 4927 | * 1) unmodified from disk |
| 4928 | * 2) backup cache for save/restore during power-downs */ |
| 4929 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4930 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4931 | |
| 4932 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4933 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4934 | |
| 4935 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4936 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4937 | |
| 4938 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4939 | !priv->ucode_data_backup.v_addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4940 | goto err_pci_alloc; |
| 4941 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4942 | /* Initialization instructions and data */ |
| 4943 | if (init_size && init_data_size) { |
| 4944 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4945 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4946 | |
| 4947 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4948 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4949 | |
| 4950 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 4951 | goto err_pci_alloc; |
| 4952 | } |
| 4953 | |
| 4954 | /* Bootstrap (instructions only, no data) */ |
| 4955 | if (boot_size) { |
| 4956 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4957 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4958 | |
| 4959 | if (!priv->ucode_boot.v_addr) |
| 4960 | goto err_pci_alloc; |
| 4961 | } |
| 4962 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4963 | /* Copy images into buffers for card's bus-master reads ... */ |
| 4964 | |
| 4965 | /* Runtime instructions (first block of data in file) */ |
| 4966 | src = &ucode->data[0]; |
| 4967 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4968 | IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4969 | memcpy(priv->ucode_code.v_addr, src, len); |
| 4970 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 4971 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 4972 | |
| 4973 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4974 | * NOTE: Copy into backup buffer will be done in iwl3945_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4975 | src = &ucode->data[inst_size]; |
| 4976 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4977 | IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4978 | memcpy(priv->ucode_data.v_addr, src, len); |
| 4979 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 4980 | |
| 4981 | /* Initialization instructions (3rd block) */ |
| 4982 | if (init_size) { |
| 4983 | src = &ucode->data[inst_size + data_size]; |
| 4984 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4985 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 4986 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4987 | memcpy(priv->ucode_init.v_addr, src, len); |
| 4988 | } |
| 4989 | |
| 4990 | /* Initialization data (4th block) */ |
| 4991 | if (init_data_size) { |
| 4992 | src = &ucode->data[inst_size + data_size + init_size]; |
| 4993 | len = priv->ucode_init_data.len; |
| 4994 | IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n", |
| 4995 | (int)len); |
| 4996 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 4997 | } |
| 4998 | |
| 4999 | /* Bootstrap instructions (5th block) */ |
| 5000 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 5001 | len = priv->ucode_boot.len; |
| 5002 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n", |
| 5003 | (int)len); |
| 5004 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 5005 | |
| 5006 | /* We have our copies now, allow OS release its copies */ |
| 5007 | release_firmware(ucode_raw); |
| 5008 | return 0; |
| 5009 | |
| 5010 | err_pci_alloc: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5011 | IWL_ERR(priv, "failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5012 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5013 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5014 | |
| 5015 | err_release: |
| 5016 | release_firmware(ucode_raw); |
| 5017 | |
| 5018 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5019 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | |
| 5023 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5024 | * iwl3945_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5025 | * |
| 5026 | * Tell initialization uCode where to find runtime uCode. |
| 5027 | * |
| 5028 | * BSM registers initially contain pointers to initialization uCode. |
| 5029 | * We need to replace them to load runtime uCode inst and data, |
| 5030 | * and to save runtime data when powering down. |
| 5031 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5032 | static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5033 | { |
| 5034 | dma_addr_t pinst; |
| 5035 | dma_addr_t pdata; |
| 5036 | int rc = 0; |
| 5037 | unsigned long flags; |
| 5038 | |
| 5039 | /* bits 31:0 for 3945 */ |
| 5040 | pinst = priv->ucode_code.p_addr; |
| 5041 | pdata = priv->ucode_data_backup.p_addr; |
| 5042 | |
| 5043 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5044 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5045 | if (rc) { |
| 5046 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5047 | return rc; |
| 5048 | } |
| 5049 | |
| 5050 | /* Tell bootstrap uCode where to find image to load */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5051 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 5052 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 5053 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5054 | priv->ucode_data.len); |
| 5055 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5056 | /* Inst byte count must be last to set up, bit 31 signals uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5057 | * that all new ptr/size info is in place */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5058 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5059 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 5060 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5061 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5062 | |
| 5063 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5064 | |
| 5065 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 5066 | |
| 5067 | return rc; |
| 5068 | } |
| 5069 | |
| 5070 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5071 | * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5072 | * |
| 5073 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 5074 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5075 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5076 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5077 | static void iwl3945_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5078 | { |
| 5079 | /* Check alive response for "valid" sign from uCode */ |
| 5080 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 5081 | /* We had an error bringing up the hardware, so take it |
| 5082 | * all the way back down so we can try again */ |
| 5083 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 5084 | goto restart; |
| 5085 | } |
| 5086 | |
| 5087 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 5088 | * This is a paranoid check, because we would not have gotten the |
| 5089 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5090 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5091 | /* Runtime instruction load was bad; |
| 5092 | * take it all the way back down so we can try again */ |
| 5093 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 5094 | goto restart; |
| 5095 | } |
| 5096 | |
| 5097 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 5098 | * load and launch runtime uCode, which will send us another "Alive" |
| 5099 | * notification. */ |
| 5100 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5101 | if (iwl3945_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5102 | /* Runtime instruction load won't happen; |
| 5103 | * take it all the way back down so we can try again */ |
| 5104 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 5105 | goto restart; |
| 5106 | } |
| 5107 | return; |
| 5108 | |
| 5109 | restart: |
| 5110 | queue_work(priv->workqueue, &priv->restart); |
| 5111 | } |
| 5112 | |
| 5113 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5114 | /* temporary */ |
| 5115 | static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, |
| 5116 | struct sk_buff *skb); |
| 5117 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5118 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5119 | * iwl3945_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5120 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5121 | * Alive gets handled by iwl3945_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5122 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5123 | static void iwl3945_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5124 | { |
| 5125 | int rc = 0; |
| 5126 | int thermal_spin = 0; |
| 5127 | u32 rfkill; |
| 5128 | |
| 5129 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 5130 | |
| 5131 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 5132 | /* We had an error bringing up the hardware, so take it |
| 5133 | * all the way back down so we can try again */ |
| 5134 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 5135 | goto restart; |
| 5136 | } |
| 5137 | |
| 5138 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 5139 | * This is a paranoid check, because we would not have gotten the |
| 5140 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5141 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5142 | /* Runtime instruction load was bad; |
| 5143 | * take it all the way back down so we can try again */ |
| 5144 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 5145 | goto restart; |
| 5146 | } |
| 5147 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5148 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5149 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5150 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5151 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5152 | IWL_WARN(priv, "Can not read RFKILL status from adapter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5153 | return; |
| 5154 | } |
| 5155 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5156 | rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5157 | IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5158 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5159 | |
| 5160 | if (rfkill & 0x1) { |
| 5161 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5162 | /* if RFKILL is not on, then wait for thermal |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5163 | * sensor in adapter to kick in */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5164 | while (iwl3945_hw_get_temperature(priv) == 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5165 | thermal_spin++; |
| 5166 | udelay(10); |
| 5167 | } |
| 5168 | |
| 5169 | if (thermal_spin) |
| 5170 | IWL_DEBUG_INFO("Thermal calibration took %dus\n", |
| 5171 | thermal_spin * 10); |
| 5172 | } else |
| 5173 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5174 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5175 | /* After the ALIVE response, we can send commands to 3945 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5176 | set_bit(STATUS_ALIVE, &priv->status); |
| 5177 | |
| 5178 | /* Clear out the uCode error bit if it is set */ |
| 5179 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 5180 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5181 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5182 | return; |
| 5183 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 5184 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5185 | |
| 5186 | priv->active_rate = priv->rates_mask; |
| 5187 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 5188 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5189 | iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5190 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5191 | if (iwl3945_is_associated(priv)) { |
| 5192 | struct iwl3945_rxon_cmd *active_rxon = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5193 | (struct iwl3945_rxon_cmd *)(&priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5194 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5195 | memcpy(&priv->staging39_rxon, &priv->active39_rxon, |
| 5196 | sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5197 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5198 | } else { |
| 5199 | /* Initialize our rx_config data */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 5200 | iwl3945_connection_init_rx_config(priv, priv->iw_mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5201 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5202 | } |
| 5203 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5204 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5205 | iwl3945_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5206 | |
| 5207 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5208 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5209 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5210 | iwl3945_reg_txpower_periodic(priv); |
| 5211 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 5212 | iwl3945_led_register(priv); |
| 5213 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5214 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 5215 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5216 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5217 | |
| 5218 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5219 | iwl3945_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5220 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5221 | /* reassociate for ADHOC mode */ |
| 5222 | if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) { |
| 5223 | struct sk_buff *beacon = ieee80211_beacon_get(priv->hw, |
| 5224 | priv->vif); |
| 5225 | if (beacon) |
| 5226 | iwl3945_mac_beacon_update(priv->hw, beacon); |
| 5227 | } |
| 5228 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5229 | return; |
| 5230 | |
| 5231 | restart: |
| 5232 | queue_work(priv->workqueue, &priv->restart); |
| 5233 | } |
| 5234 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5235 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5236 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5237 | static void __iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5238 | { |
| 5239 | unsigned long flags; |
| 5240 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5241 | struct ieee80211_conf *conf = NULL; |
| 5242 | |
| 5243 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 5244 | |
| 5245 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5246 | |
| 5247 | if (!exit_pending) |
| 5248 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5249 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 5250 | iwl3945_led_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5251 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5252 | |
| 5253 | /* Unblock any waiting calls */ |
| 5254 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 5255 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5256 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 5257 | * exiting the module */ |
| 5258 | if (!exit_pending) |
| 5259 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5260 | |
| 5261 | /* stop and reset the on-board processor */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5262 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5263 | |
| 5264 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5265 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5266 | iwl3945_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5267 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5268 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5269 | |
| 5270 | if (priv->mac80211_registered) |
| 5271 | ieee80211_stop_queues(priv->hw); |
| 5272 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5273 | /* If we have not previously called iwl3945_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5274 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5275 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5276 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5277 | STATUS_RF_KILL_HW | |
| 5278 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5279 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5280 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5281 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5282 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5283 | STATUS_IN_SUSPEND | |
| 5284 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5285 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5286 | goto exit; |
| 5287 | } |
| 5288 | |
| 5289 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 5290 | * SUSPEND bits and continue taking the NIC down. */ |
| 5291 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5292 | STATUS_RF_KILL_HW | |
| 5293 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5294 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5295 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5296 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5297 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 5298 | STATUS_IN_SUSPEND | |
| 5299 | test_bit(STATUS_FW_ERROR, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5300 | STATUS_FW_ERROR | |
| 5301 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5302 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5303 | |
| 5304 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5305 | iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5306 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5307 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5308 | iwl3945_hw_txq_ctx_stop(priv); |
| 5309 | iwl3945_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5310 | |
| 5311 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5312 | if (!iwl_grab_nic_access(priv)) { |
| 5313 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5314 | APMG_CLK_VAL_DMA_CLK_RQT); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5315 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5316 | } |
| 5317 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5318 | |
| 5319 | udelay(5); |
| 5320 | |
Kolekar, Abhijeet | 01ec616 | 2008-12-19 10:37:38 +0800 | [diff] [blame] | 5321 | priv->cfg->ops->lib->apm_ops.reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5322 | exit: |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 5323 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5324 | |
| 5325 | if (priv->ibss_beacon) |
| 5326 | dev_kfree_skb(priv->ibss_beacon); |
| 5327 | priv->ibss_beacon = NULL; |
| 5328 | |
| 5329 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5330 | iwl3945_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5331 | } |
| 5332 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5333 | static void iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5334 | { |
| 5335 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5336 | __iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5337 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5338 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5339 | iwl3945_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | #define MAX_HW_RESTARTS 5 |
| 5343 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5344 | static int __iwl3945_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5345 | { |
| 5346 | int rc, i; |
| 5347 | |
| 5348 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5349 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5350 | return -EIO; |
| 5351 | } |
| 5352 | |
| 5353 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5354 | IWL_WARN(priv, "Radio disabled by SW RF kill (module " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5355 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5356 | return -ENODEV; |
| 5357 | } |
| 5358 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5359 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5360 | IWL_ERR(priv, "ucode not available for device bring up\n"); |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5361 | return -EIO; |
| 5362 | } |
| 5363 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5364 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5365 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5366 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 5367 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5368 | else { |
| 5369 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5370 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5371 | IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5372 | return -ENODEV; |
| 5373 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5374 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5375 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5376 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5377 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5378 | rc = iwl3945_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5379 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5380 | IWL_ERR(priv, "Unable to int nic\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5381 | return rc; |
| 5382 | } |
| 5383 | |
| 5384 | /* make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5385 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5386 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5387 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 5388 | |
| 5389 | /* clear (again), then enable host interrupts */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5390 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5391 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5392 | |
| 5393 | /* really make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5394 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5395 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5396 | |
| 5397 | /* Copy original ucode data image from disk into backup cache. |
| 5398 | * This will be used to initialize the on-board processor's |
| 5399 | * data SRAM for a clean start when the runtime program first loads. */ |
| 5400 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5401 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5402 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5403 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 5404 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5405 | return 0; |
| 5406 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5407 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 5408 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5409 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5410 | |
| 5411 | /* load bootstrap state machine, |
| 5412 | * load bootstrap program into processor's memory, |
| 5413 | * prepare to load the "initialize" uCode */ |
Kolekar, Abhijeet | 0164b9b | 2008-12-19 10:37:37 +0800 | [diff] [blame] | 5414 | priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5415 | |
| 5416 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5417 | IWL_ERR(priv, |
| 5418 | "Unable to set up bootstrap uCode: %d\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5419 | continue; |
| 5420 | } |
| 5421 | |
| 5422 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5423 | iwl3945_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5424 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5425 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 5426 | |
| 5427 | return 0; |
| 5428 | } |
| 5429 | |
| 5430 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5431 | __iwl3945_down(priv); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5432 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5433 | |
| 5434 | /* tried to restart and config the device for as long as our |
| 5435 | * patience could withstand */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5436 | IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5437 | return -EIO; |
| 5438 | } |
| 5439 | |
| 5440 | |
| 5441 | /***************************************************************************** |
| 5442 | * |
| 5443 | * Workqueue callbacks |
| 5444 | * |
| 5445 | *****************************************************************************/ |
| 5446 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5447 | static void iwl3945_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5448 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5449 | struct iwl_priv *priv = |
| 5450 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5451 | |
| 5452 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5453 | return; |
| 5454 | |
| 5455 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5456 | iwl3945_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5457 | mutex_unlock(&priv->mutex); |
| 5458 | } |
| 5459 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5460 | static void iwl3945_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5461 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5462 | struct iwl_priv *priv = |
| 5463 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5464 | |
| 5465 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5466 | return; |
| 5467 | |
| 5468 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5469 | iwl3945_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5470 | mutex_unlock(&priv->mutex); |
| 5471 | } |
| 5472 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5473 | static void iwl3945_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5474 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5475 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5476 | |
| 5477 | wake_up_interruptible(&priv->wait_command_queue); |
| 5478 | |
| 5479 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5480 | return; |
| 5481 | |
| 5482 | mutex_lock(&priv->mutex); |
| 5483 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5484 | if (!iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5485 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 5486 | "HW and/or SW RF Kill no longer active, restarting " |
| 5487 | "device\n"); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5488 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status) && |
| 5489 | test_bit(STATUS_ALIVE, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5490 | queue_work(priv->workqueue, &priv->restart); |
| 5491 | } else { |
| 5492 | |
| 5493 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5494 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 5495 | "disabled by SW switch\n"); |
| 5496 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5497 | IWL_WARN(priv, "Radio Frequency Kill Switch is On:\n" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5498 | "Kill switch must be turned off for " |
| 5499 | "wireless networking to work.\n"); |
| 5500 | } |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5501 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5502 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5503 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5504 | } |
| 5505 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5506 | static void iwl3945_rfkill_poll(struct work_struct *data) |
| 5507 | { |
| 5508 | struct iwl_priv *priv = |
| 5509 | container_of(data, struct iwl_priv, rfkill_poll.work); |
| 5510 | unsigned long status = priv->status; |
| 5511 | |
| 5512 | if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 5513 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5514 | else |
| 5515 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5516 | |
| 5517 | if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5518 | queue_work(priv->workqueue, &priv->rf_kill); |
| 5519 | |
| 5520 | queue_delayed_work(priv->workqueue, &priv->rfkill_poll, |
| 5521 | round_jiffies_relative(2 * HZ)); |
| 5522 | |
| 5523 | } |
| 5524 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5525 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 5526 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5527 | static void iwl3945_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5528 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5529 | struct iwl_priv *priv = |
| 5530 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5531 | |
| 5532 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5533 | return; |
| 5534 | |
| 5535 | mutex_lock(&priv->mutex); |
| 5536 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 5537 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5538 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 5539 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 5540 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5541 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5542 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5543 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5544 | } |
| 5545 | mutex_unlock(&priv->mutex); |
| 5546 | } |
| 5547 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5548 | static void iwl3945_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5549 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5550 | struct iwl_priv *priv = |
| 5551 | container_of(data, struct iwl_priv, request_scan); |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 5552 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5553 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5554 | .len = sizeof(struct iwl3945_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5555 | .meta.flags = CMD_SIZE_HUGE, |
| 5556 | }; |
| 5557 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5558 | struct iwl3945_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5559 | struct ieee80211_conf *conf = NULL; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5560 | u8 n_probes = 2; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5561 | enum ieee80211_band band; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5562 | DECLARE_SSID_BUF(ssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5563 | |
| 5564 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5565 | |
| 5566 | mutex_lock(&priv->mutex); |
| 5567 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5568 | if (!iwl_is_ready(priv)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5569 | IWL_WARN(priv, "request scan called when driver not ready.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5570 | goto done; |
| 5571 | } |
| 5572 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5573 | /* Make sure the scan wasn't canceled before this queued work |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5574 | * was given the chance to run... */ |
| 5575 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 5576 | goto done; |
| 5577 | |
| 5578 | /* This should never be called or scheduled if there is currently |
| 5579 | * a scan active in the hardware. */ |
| 5580 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 5581 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 5582 | "Ignoring second request.\n"); |
| 5583 | rc = -EIO; |
| 5584 | goto done; |
| 5585 | } |
| 5586 | |
| 5587 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 5588 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 5589 | goto done; |
| 5590 | } |
| 5591 | |
| 5592 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5593 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 5594 | goto done; |
| 5595 | } |
| 5596 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5597 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5598 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 5599 | goto done; |
| 5600 | } |
| 5601 | |
| 5602 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 5603 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 5604 | goto done; |
| 5605 | } |
| 5606 | |
| 5607 | if (!priv->scan_bands) { |
| 5608 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 5609 | goto done; |
| 5610 | } |
| 5611 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5612 | if (!priv->scan39) { |
| 5613 | priv->scan39 = kmalloc(sizeof(struct iwl3945_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5614 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5615 | if (!priv->scan39) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5616 | rc = -ENOMEM; |
| 5617 | goto done; |
| 5618 | } |
| 5619 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5620 | scan = priv->scan39; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5621 | memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5622 | |
| 5623 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 5624 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 5625 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5626 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5627 | u16 interval = 0; |
| 5628 | u32 extra; |
| 5629 | u32 suspend_time = 100; |
| 5630 | u32 scan_suspend_time = 100; |
| 5631 | unsigned long flags; |
| 5632 | |
| 5633 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 5634 | |
| 5635 | spin_lock_irqsave(&priv->lock, flags); |
| 5636 | interval = priv->beacon_int; |
| 5637 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5638 | |
| 5639 | scan->suspend_time = 0; |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5640 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5641 | if (!interval) |
| 5642 | interval = suspend_time; |
| 5643 | /* |
| 5644 | * suspend time format: |
| 5645 | * 0-19: beacon interval in usec (time before exec.) |
| 5646 | * 20-23: 0 |
| 5647 | * 24-31: number of beacons (suspend between channels) |
| 5648 | */ |
| 5649 | |
| 5650 | extra = (suspend_time / interval) << 24; |
| 5651 | scan_suspend_time = 0xFF0FFFFF & |
| 5652 | (extra | ((suspend_time % interval) * 1024)); |
| 5653 | |
| 5654 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 5655 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 5656 | scan_suspend_time, interval); |
| 5657 | } |
| 5658 | |
| 5659 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 5660 | if (priv->one_direct_scan) { |
| 5661 | IWL_DEBUG_SCAN |
| 5662 | ("Kicking off one direct scan for '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5663 | print_ssid(ssid, priv->direct_ssid, |
| 5664 | priv->direct_ssid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5665 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 5666 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 5667 | memcpy(scan->direct_scan[0].ssid, |
| 5668 | priv->direct_ssid, priv->direct_ssid_len); |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5669 | n_probes++; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5670 | } else |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5671 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5672 | |
| 5673 | /* We don't build a direct scan probe request; the uCode will do |
| 5674 | * that based on the direct_mask added to each channel entry */ |
| 5675 | scan->tx_cmd.len = cpu_to_le16( |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5676 | iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 5677 | IWL_MAX_SCAN_SIZE - sizeof(*scan))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5678 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 5679 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5680 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 5681 | |
| 5682 | /* flags + rate selection */ |
| 5683 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5684 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5685 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 5686 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; |
| 5687 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5688 | band = IEEE80211_BAND_2GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5689 | } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5690 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; |
| 5691 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5692 | band = IEEE80211_BAND_5GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5693 | } else { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5694 | IWL_WARN(priv, "Invalid scan band count\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5695 | goto done; |
| 5696 | } |
| 5697 | |
| 5698 | /* select Rx antennas */ |
| 5699 | scan->flags |= iwl3945_get_antenna_flags(priv); |
| 5700 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5701 | if (priv->iw_mode == NL80211_IFTYPE_MONITOR) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5702 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 5703 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5704 | scan->channel_count = |
| 5705 | iwl3945_get_channels_for_scan(priv, band, 1, /* active */ |
| 5706 | n_probes, |
| 5707 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5708 | |
Reinette Chatre | 14b5433 | 2008-11-04 12:21:35 -0800 | [diff] [blame] | 5709 | if (scan->channel_count == 0) { |
| 5710 | IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count); |
| 5711 | goto done; |
| 5712 | } |
| 5713 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5714 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5715 | scan->channel_count * sizeof(struct iwl3945_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5716 | cmd.data = scan; |
| 5717 | scan->len = cpu_to_le16(cmd.len); |
| 5718 | |
| 5719 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5720 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5721 | if (rc) |
| 5722 | goto done; |
| 5723 | |
| 5724 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 5725 | IWL_SCAN_CHECK_WATCHDOG); |
| 5726 | |
| 5727 | mutex_unlock(&priv->mutex); |
| 5728 | return; |
| 5729 | |
| 5730 | done: |
Mohamed Abbas | 2420ebc | 2008-11-04 12:21:34 -0800 | [diff] [blame] | 5731 | /* can not perform scan make sure we clear scanning |
| 5732 | * bits from status so next scan request can be performed. |
| 5733 | * if we dont clear scanning status bit here all next scan |
| 5734 | * will fail |
| 5735 | */ |
| 5736 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 5737 | clear_bit(STATUS_SCANNING, &priv->status); |
| 5738 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 5739 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5740 | queue_work(priv->workqueue, &priv->scan_completed); |
| 5741 | mutex_unlock(&priv->mutex); |
| 5742 | } |
| 5743 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5744 | static void iwl3945_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5745 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5746 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5747 | |
| 5748 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5749 | return; |
| 5750 | |
| 5751 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5752 | __iwl3945_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5753 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5754 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5755 | } |
| 5756 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5757 | static void iwl3945_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5758 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5759 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5760 | |
| 5761 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5762 | return; |
| 5763 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5764 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5765 | queue_work(priv->workqueue, &priv->up); |
| 5766 | } |
| 5767 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5768 | static void iwl3945_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5769 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5770 | struct iwl_priv *priv = |
| 5771 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5772 | |
| 5773 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5774 | return; |
| 5775 | |
| 5776 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5777 | iwl3945_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5778 | mutex_unlock(&priv->mutex); |
| 5779 | } |
| 5780 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5781 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 5782 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5783 | static void iwl3945_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5784 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5785 | int rc = 0; |
| 5786 | struct ieee80211_conf *conf = NULL; |
| 5787 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5788 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5789 | IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5790 | return; |
| 5791 | } |
| 5792 | |
| 5793 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5794 | IWL_DEBUG_ASSOC("Associated as %d to: %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5795 | priv->assoc_id, priv->active39_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5796 | |
| 5797 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5798 | return; |
| 5799 | |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 5800 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5801 | return; |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 5802 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5803 | iwl3945_scan_cancel_timeout(priv, 200); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5804 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5805 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5806 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5807 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5808 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5809 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 5810 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5811 | iwl3945_setup_rxon_timing(priv); |
| 5812 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5813 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 5814 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5815 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5816 | "Attempting to continue.\n"); |
| 5817 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5818 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5819 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5820 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5821 | |
| 5822 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 5823 | priv->assoc_id, priv->beacon_int); |
| 5824 | |
| 5825 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5826 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5827 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5828 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5829 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5830 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5831 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5832 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5833 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5834 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5835 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5836 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5837 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5838 | |
| 5839 | } |
| 5840 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5841 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5842 | |
| 5843 | switch (priv->iw_mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5844 | case NL80211_IFTYPE_STATION: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5845 | iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5846 | break; |
| 5847 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5848 | case NL80211_IFTYPE_ADHOC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5849 | |
Abhijeet Kolekar | ce546fd | 2008-11-19 15:32:22 -0800 | [diff] [blame] | 5850 | priv->assoc_id = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5851 | iwl3945_add_station(priv, priv->bssid, 0, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5852 | iwl3945_sync_sta(priv, IWL_STA_ID, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5853 | (priv->band == IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5854 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, |
| 5855 | CMD_ASYNC); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5856 | iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); |
| 5857 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5858 | |
| 5859 | break; |
| 5860 | |
| 5861 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5862 | IWL_ERR(priv, "%s Should not be called in %d mode\n", |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 5863 | __func__, priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5864 | break; |
| 5865 | } |
| 5866 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5867 | iwl3945_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 5868 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5869 | /* we have just associated, don't start scan too early */ |
| 5870 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 5871 | } |
| 5872 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5873 | static void iwl3945_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5874 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5875 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5876 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5877 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5878 | return; |
| 5879 | |
| 5880 | mutex_lock(&priv->mutex); |
| 5881 | |
| 5882 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5883 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5884 | |
| 5885 | mutex_unlock(&priv->mutex); |
| 5886 | } |
| 5887 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 5888 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5889 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5890 | static void iwl3945_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5891 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5892 | struct iwl_priv *priv = |
| 5893 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5894 | |
| 5895 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 5896 | |
| 5897 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5898 | return; |
| 5899 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5900 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 5901 | iwl3945_mac_config(priv->hw, 0); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5902 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5903 | ieee80211_scan_completed(priv->hw); |
| 5904 | |
| 5905 | /* Since setting the TXPOWER may have been deferred while |
| 5906 | * performing the scan, fire one off */ |
| 5907 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5908 | iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5909 | mutex_unlock(&priv->mutex); |
| 5910 | } |
| 5911 | |
| 5912 | /***************************************************************************** |
| 5913 | * |
| 5914 | * mac80211 entry point functions |
| 5915 | * |
| 5916 | *****************************************************************************/ |
| 5917 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5918 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 5919 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5920 | static int iwl3945_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5921 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5922 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5923 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5924 | |
| 5925 | IWL_DEBUG_MAC80211("enter\n"); |
| 5926 | |
| 5927 | /* we should be verifying the device is ready to be opened */ |
| 5928 | mutex_lock(&priv->mutex); |
| 5929 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5930 | memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5931 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 5932 | * ucode filename and max sizes are card-specific. */ |
| 5933 | |
| 5934 | if (!priv->ucode_code.len) { |
| 5935 | ret = iwl3945_read_ucode(priv); |
| 5936 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5937 | IWL_ERR(priv, "Could not read microcode: %d\n", ret); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5938 | mutex_unlock(&priv->mutex); |
| 5939 | goto out_release_irq; |
| 5940 | } |
| 5941 | } |
| 5942 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5943 | ret = __iwl3945_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5944 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5945 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5946 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5947 | iwl3945_rfkill_set_hw_state(priv); |
| 5948 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5949 | if (ret) |
| 5950 | goto out_release_irq; |
| 5951 | |
| 5952 | IWL_DEBUG_INFO("Start UP work.\n"); |
| 5953 | |
| 5954 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 5955 | return 0; |
| 5956 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5957 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 5958 | * mac80211 will not be run successfully. */ |
| 5959 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 5960 | test_bit(STATUS_READY, &priv->status), |
| 5961 | UCODE_READY_TIMEOUT); |
| 5962 | if (!ret) { |
| 5963 | if (!test_bit(STATUS_READY, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5964 | IWL_ERR(priv, |
| 5965 | "Wait for START_ALIVE timeout after %dms.\n", |
| 5966 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5967 | ret = -ETIMEDOUT; |
| 5968 | goto out_release_irq; |
| 5969 | } |
| 5970 | } |
| 5971 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5972 | /* ucode is running and will send rfkill notifications, |
| 5973 | * no need to poll the killswitch state anymore */ |
| 5974 | cancel_delayed_work(&priv->rfkill_poll); |
| 5975 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5976 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5977 | IWL_DEBUG_MAC80211("leave\n"); |
| 5978 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5979 | |
| 5980 | out_release_irq: |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5981 | priv->is_open = 0; |
| 5982 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5983 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5984 | } |
| 5985 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5986 | static void iwl3945_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5987 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5988 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5989 | |
| 5990 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5991 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5992 | if (!priv->is_open) { |
| 5993 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 5994 | return; |
| 5995 | } |
| 5996 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5997 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5998 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5999 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6000 | /* stop mac, cancel any scan request and clear |
| 6001 | * RXON_FILTER_ASSOC_MSK BIT |
| 6002 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6003 | mutex_lock(&priv->mutex); |
| 6004 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6005 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6006 | } |
| 6007 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6008 | iwl3945_down(priv); |
| 6009 | |
| 6010 | flush_workqueue(priv->workqueue); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 6011 | |
| 6012 | /* start polling the killswitch state again */ |
| 6013 | queue_delayed_work(priv->workqueue, &priv->rfkill_poll, |
| 6014 | round_jiffies_relative(2 * HZ)); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6015 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6016 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6017 | } |
| 6018 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6019 | static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6020 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6021 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6022 | |
| 6023 | IWL_DEBUG_MAC80211("enter\n"); |
| 6024 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6025 | IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6026 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6027 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6028 | if (iwl3945_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6029 | dev_kfree_skb_any(skb); |
| 6030 | |
| 6031 | IWL_DEBUG_MAC80211("leave\n"); |
Reinette Chatre | 637f883 | 2009-01-19 15:30:32 -0800 | [diff] [blame] | 6032 | return NETDEV_TX_OK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6035 | static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6036 | struct ieee80211_if_init_conf *conf) |
| 6037 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6038 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6039 | unsigned long flags; |
| 6040 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6041 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6042 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6043 | if (priv->vif) { |
| 6044 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6045 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6049 | priv->vif = conf->vif; |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 6050 | priv->iw_mode = conf->type; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6051 | |
| 6052 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6053 | |
| 6054 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6055 | |
| 6056 | if (conf->mac_addr) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6057 | IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6058 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 6059 | } |
| 6060 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6061 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6062 | iwl3945_set_mode(priv, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6063 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6064 | mutex_unlock(&priv->mutex); |
| 6065 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6066 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6067 | return 0; |
| 6068 | } |
| 6069 | |
| 6070 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6071 | * iwl3945_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6072 | * |
| 6073 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 6074 | * be set inappropriately and the driver currently sets the hardware up to |
| 6075 | * use it whenever needed. |
| 6076 | */ |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6077 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6078 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6079 | struct iwl_priv *priv = hw->priv; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6080 | const struct iwl_channel_info *ch_info; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6081 | struct ieee80211_conf *conf = &hw->conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6082 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6083 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6084 | |
| 6085 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6086 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6087 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6088 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6089 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6090 | ret = -EIO; |
| 6091 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6092 | } |
| 6093 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 6094 | if (unlikely(!iwl3945_mod_params.disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6095 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6096 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 6097 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6098 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6099 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6100 | } |
| 6101 | |
| 6102 | spin_lock_irqsave(&priv->lock, flags); |
| 6103 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6104 | ch_info = iwl3945_get_channel_info(priv, conf->channel->band, |
| 6105 | conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6106 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 6107 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6108 | conf->channel->hw_value, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6109 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 6110 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6111 | ret = -EINVAL; |
| 6112 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6113 | } |
| 6114 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6115 | iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6116 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6117 | iwl3945_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6118 | |
| 6119 | /* The list of supported rates and rate mask can be different |
| 6120 | * for each phymode; since the phymode may have changed, reset |
| 6121 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6122 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6123 | |
| 6124 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6125 | |
| 6126 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 6127 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6128 | iwl3945_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6129 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6130 | } |
| 6131 | #endif |
| 6132 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6133 | iwl3945_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6134 | |
| 6135 | if (!conf->radio_enabled) { |
| 6136 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6137 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6138 | } |
| 6139 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6140 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6141 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6142 | ret = -EIO; |
| 6143 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6144 | } |
| 6145 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6146 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6147 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6148 | if (memcmp(&priv->active39_rxon, |
| 6149 | &priv->staging39_rxon, sizeof(priv->staging39_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6150 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6151 | else |
| 6152 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 6153 | |
| 6154 | IWL_DEBUG_MAC80211("leave\n"); |
| 6155 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6156 | out: |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6157 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6158 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6159 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6160 | } |
| 6161 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6162 | static void iwl3945_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6163 | { |
| 6164 | int rc = 0; |
| 6165 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 6166 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6167 | return; |
| 6168 | |
| 6169 | /* The following should be done only at AP bring up */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 6170 | if (!(iwl3945_is_associated(priv))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6171 | |
| 6172 | /* RXON - unassoc (to set timing command) */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6173 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6174 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6175 | |
| 6176 | /* RXON Timing */ |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6177 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6178 | iwl3945_setup_rxon_timing(priv); |
| 6179 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6180 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 6181 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6182 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6183 | "Attempting to continue.\n"); |
| 6184 | |
| 6185 | /* FIXME: what should be the assoc_id for AP? */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6186 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6187 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6188 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6189 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6190 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6191 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6192 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6193 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6194 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6195 | if (priv->assoc_capability & |
| 6196 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6197 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6198 | RXON_FLG_SHORT_SLOT_MSK; |
| 6199 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6200 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6201 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6202 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6203 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6204 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6205 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6206 | } |
| 6207 | /* restore RXON assoc */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6208 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6209 | iwl3945_commit_rxon(priv); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 6210 | iwl3945_add_station(priv, iwl_bcast_addr, 0, 0); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 6211 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6212 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6213 | |
| 6214 | /* FIXME - we need to add code here to detect a totally new |
| 6215 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 6216 | * clear sta table, add BCAST sta... */ |
| 6217 | } |
| 6218 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6219 | static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, |
| 6220 | struct ieee80211_vif *vif, |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6221 | struct ieee80211_if_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6222 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6223 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6224 | int rc; |
| 6225 | |
| 6226 | if (conf == NULL) |
| 6227 | return -EIO; |
| 6228 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6229 | if (priv->vif != vif) { |
| 6230 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6231 | return 0; |
| 6232 | } |
| 6233 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6234 | /* handle this temporarily here */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6235 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6236 | conf->changed & IEEE80211_IFCC_BEACON) { |
| 6237 | struct sk_buff *beacon = ieee80211_beacon_get(hw, vif); |
| 6238 | if (!beacon) |
| 6239 | return -ENOMEM; |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6240 | mutex_lock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6241 | rc = iwl3945_mac_beacon_update(hw, beacon); |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6242 | mutex_unlock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6243 | if (rc) |
| 6244 | return rc; |
| 6245 | } |
| 6246 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6247 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6248 | return -EAGAIN; |
| 6249 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6250 | mutex_lock(&priv->mutex); |
| 6251 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6252 | if (conf->bssid) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6253 | IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6254 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6255 | /* |
| 6256 | * very dubious code was here; the probe filtering flag is never set: |
| 6257 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6258 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 6259 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6260 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6261 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6262 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6263 | if (!conf->bssid) { |
| 6264 | conf->bssid = priv->mac_addr; |
| 6265 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6266 | IWL_DEBUG_MAC80211("bssid was set to: %pM\n", |
| 6267 | conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6268 | } |
| 6269 | if (priv->ibss_beacon) |
| 6270 | dev_kfree_skb(priv->ibss_beacon); |
| 6271 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6272 | priv->ibss_beacon = ieee80211_beacon_get(hw, vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6275 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6276 | goto done; |
| 6277 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6278 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 6279 | !is_multicast_ether_addr(conf->bssid)) { |
| 6280 | /* If there is currently a HW scan going on in the background |
| 6281 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6282 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6283 | IWL_WARN(priv, "Aborted scan still in progress " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6284 | "after 100ms\n"); |
| 6285 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 6286 | mutex_unlock(&priv->mutex); |
| 6287 | return -EAGAIN; |
| 6288 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6289 | memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6290 | |
| 6291 | /* TODO: Audit driver for usage of these members and see |
| 6292 | * if mac80211 deprecates them (priv->bssid looks like it |
| 6293 | * shouldn't be there, but I haven't scanned the IBSS code |
| 6294 | * to verify) - jpk */ |
| 6295 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 6296 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6297 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6298 | iwl3945_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6299 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6300 | rc = iwl3945_commit_rxon(priv); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6301 | if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6302 | iwl3945_add_station(priv, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6303 | priv->active39_rxon.bssid_addr, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6304 | } |
| 6305 | |
| 6306 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6307 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6308 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6309 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6310 | } |
| 6311 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6312 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6313 | IWL_DEBUG_MAC80211("leave\n"); |
| 6314 | mutex_unlock(&priv->mutex); |
| 6315 | |
| 6316 | return 0; |
| 6317 | } |
| 6318 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6319 | static void iwl3945_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6320 | unsigned int changed_flags, |
| 6321 | unsigned int *total_flags, |
| 6322 | int mc_count, struct dev_addr_list *mc_list) |
| 6323 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6324 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6325 | __le32 *filter_flags = &priv->staging39_rxon.filter_flags; |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6326 | |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6327 | IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n", |
| 6328 | changed_flags, *total_flags); |
| 6329 | |
| 6330 | if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) { |
| 6331 | if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) |
| 6332 | *filter_flags |= RXON_FILTER_PROMISC_MSK; |
| 6333 | else |
| 6334 | *filter_flags &= ~RXON_FILTER_PROMISC_MSK; |
Abhijeet Kolekar | 5ec0397 | 2008-05-05 10:22:48 +0800 | [diff] [blame] | 6335 | } |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6336 | if (changed_flags & FIF_ALLMULTI) { |
| 6337 | if (*total_flags & FIF_ALLMULTI) |
| 6338 | *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK; |
| 6339 | else |
| 6340 | *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK; |
| 6341 | } |
| 6342 | if (changed_flags & FIF_CONTROL) { |
| 6343 | if (*total_flags & FIF_CONTROL) |
| 6344 | *filter_flags |= RXON_FILTER_CTL2HOST_MSK; |
| 6345 | else |
| 6346 | *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK; |
| 6347 | } |
| 6348 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 6349 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
| 6350 | *filter_flags |= RXON_FILTER_BCON_AWARE_MSK; |
| 6351 | else |
| 6352 | *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK; |
| 6353 | } |
| 6354 | |
| 6355 | /* We avoid iwl_commit_rxon here to commit the new filter flags |
| 6356 | * since mac80211 will call ieee80211_hw_config immediately. |
| 6357 | * (mc_list is not supported at this time). Otherwise, we need to |
| 6358 | * queue a background iwl_commit_rxon work. |
| 6359 | */ |
| 6360 | |
| 6361 | *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6362 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6363 | } |
| 6364 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6365 | static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6366 | struct ieee80211_if_init_conf *conf) |
| 6367 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6368 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6369 | |
| 6370 | IWL_DEBUG_MAC80211("enter\n"); |
| 6371 | |
| 6372 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6373 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6374 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6375 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6376 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6377 | iwl3945_commit_rxon(priv); |
| 6378 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6379 | if (priv->vif == conf->vif) { |
| 6380 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6381 | memset(priv->bssid, 0, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6382 | } |
| 6383 | mutex_unlock(&priv->mutex); |
| 6384 | |
| 6385 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6386 | } |
| 6387 | |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6388 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
| 6389 | |
| 6390 | static void iwl3945_bss_info_changed(struct ieee80211_hw *hw, |
| 6391 | struct ieee80211_vif *vif, |
| 6392 | struct ieee80211_bss_conf *bss_conf, |
| 6393 | u32 changes) |
| 6394 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6395 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6396 | |
| 6397 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 6398 | |
| 6399 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 6400 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 6401 | bss_conf->use_short_preamble); |
| 6402 | if (bss_conf->use_short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6403 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6404 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6405 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6406 | } |
| 6407 | |
| 6408 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
| 6409 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
| 6410 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6411 | priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6412 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6413 | priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6414 | } |
| 6415 | |
| 6416 | if (changes & BSS_CHANGED_ASSOC) { |
| 6417 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
| 6418 | /* This should never happen as this function should |
| 6419 | * never be called from interrupt context. */ |
| 6420 | if (WARN_ON_ONCE(in_interrupt())) |
| 6421 | return; |
| 6422 | if (bss_conf->assoc) { |
| 6423 | priv->assoc_id = bss_conf->aid; |
| 6424 | priv->beacon_int = bss_conf->beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6425 | priv->timestamp = bss_conf->timestamp; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6426 | priv->assoc_capability = bss_conf->assoc_capability; |
| 6427 | priv->next_scan_jiffies = jiffies + |
| 6428 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
| 6429 | mutex_lock(&priv->mutex); |
| 6430 | iwl3945_post_associate(priv); |
| 6431 | mutex_unlock(&priv->mutex); |
| 6432 | } else { |
| 6433 | priv->assoc_id = 0; |
| 6434 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 6435 | } |
| 6436 | } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) { |
| 6437 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
| 6438 | iwl3945_send_rxon_assoc(priv); |
| 6439 | } |
| 6440 | |
| 6441 | } |
| 6442 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6443 | static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6444 | { |
| 6445 | int rc = 0; |
| 6446 | unsigned long flags; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6447 | struct iwl_priv *priv = hw->priv; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6448 | DECLARE_SSID_BUF(ssid_buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6449 | |
| 6450 | IWL_DEBUG_MAC80211("enter\n"); |
| 6451 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6452 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6453 | spin_lock_irqsave(&priv->lock, flags); |
| 6454 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6455 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6456 | rc = -EIO; |
| 6457 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 6458 | goto out_unlock; |
| 6459 | } |
| 6460 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6461 | /* we don't schedule scan within next_scan_jiffies period */ |
| 6462 | if (priv->next_scan_jiffies && |
| 6463 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 6464 | rc = -EAGAIN; |
| 6465 | goto out_unlock; |
| 6466 | } |
Bill Moss | 15dbf1b | 2008-05-06 11:05:15 +0800 | [diff] [blame] | 6467 | /* if we just finished scan ask for delay for a broadcast scan */ |
| 6468 | if ((len == 0) && priv->last_scan_jiffies && |
| 6469 | time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, |
| 6470 | jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6471 | rc = -EAGAIN; |
| 6472 | goto out_unlock; |
| 6473 | } |
| 6474 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6475 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6476 | print_ssid(ssid_buf, ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6477 | |
| 6478 | priv->one_direct_scan = 1; |
| 6479 | priv->direct_ssid_len = (u8) |
| 6480 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 6481 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6482 | } else |
| 6483 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6484 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6485 | rc = iwl3945_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6486 | |
| 6487 | IWL_DEBUG_MAC80211("leave\n"); |
| 6488 | |
| 6489 | out_unlock: |
| 6490 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6491 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6492 | |
| 6493 | return rc; |
| 6494 | } |
| 6495 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6496 | static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 6497 | struct ieee80211_vif *vif, |
| 6498 | struct ieee80211_sta *sta, |
| 6499 | struct ieee80211_key_conf *key) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6500 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6501 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 6502 | const u8 *addr; |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame^] | 6503 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6504 | u8 sta_id; |
| 6505 | |
| 6506 | IWL_DEBUG_MAC80211("enter\n"); |
| 6507 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 6508 | if (iwl3945_mod_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6509 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 6510 | return -EOPNOTSUPP; |
| 6511 | } |
| 6512 | |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame^] | 6513 | addr = sta ? sta->addr : iwl_bcast_addr; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6514 | sta_id = iwl3945_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6515 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6516 | IWL_DEBUG_MAC80211("leave - %pM not in station map.\n", |
| 6517 | addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6518 | return -EINVAL; |
| 6519 | } |
| 6520 | |
| 6521 | mutex_lock(&priv->mutex); |
| 6522 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6523 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6524 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6525 | switch (cmd) { |
| 6526 | case SET_KEY: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame^] | 6527 | ret = iwl3945_update_sta_key_info(priv, key, sta_id); |
| 6528 | if (!ret) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6529 | iwl3945_set_rxon_hwcrypto(priv, 1); |
| 6530 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6531 | key->hw_key_idx = sta_id; |
| 6532 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 6533 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 6534 | } |
| 6535 | break; |
| 6536 | case DISABLE_KEY: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame^] | 6537 | ret = iwl3945_clear_sta_key_info(priv, sta_id); |
| 6538 | if (!ret) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6539 | iwl3945_set_rxon_hwcrypto(priv, 0); |
| 6540 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6541 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 6542 | } |
| 6543 | break; |
| 6544 | default: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame^] | 6545 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | IWL_DEBUG_MAC80211("leave\n"); |
| 6549 | mutex_unlock(&priv->mutex); |
| 6550 | |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame^] | 6551 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6552 | } |
| 6553 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 6554 | static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6555 | const struct ieee80211_tx_queue_params *params) |
| 6556 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6557 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6558 | unsigned long flags; |
| 6559 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6560 | |
| 6561 | IWL_DEBUG_MAC80211("enter\n"); |
| 6562 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6563 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6564 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6565 | return -EIO; |
| 6566 | } |
| 6567 | |
| 6568 | if (queue >= AC_NUM) { |
| 6569 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 6570 | return 0; |
| 6571 | } |
| 6572 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6573 | q = AC_NUM - 1 - queue; |
| 6574 | |
| 6575 | spin_lock_irqsave(&priv->lock, flags); |
| 6576 | |
| 6577 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 6578 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 6579 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 6580 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 6581 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6582 | |
| 6583 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 6584 | priv->qos_data.qos_active = 1; |
| 6585 | |
| 6586 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6587 | |
| 6588 | mutex_lock(&priv->mutex); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6589 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6590 | iwl3945_activate_qos(priv, 1); |
| 6591 | else if (priv->assoc_id && iwl3945_is_associated(priv)) |
| 6592 | iwl3945_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6593 | |
| 6594 | mutex_unlock(&priv->mutex); |
| 6595 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6596 | IWL_DEBUG_MAC80211("leave\n"); |
| 6597 | return 0; |
| 6598 | } |
| 6599 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6600 | static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6601 | struct ieee80211_tx_queue_stats *stats) |
| 6602 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6603 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6604 | int i, avail; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 6605 | struct iwl_tx_queue *txq; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6606 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6607 | unsigned long flags; |
| 6608 | |
| 6609 | IWL_DEBUG_MAC80211("enter\n"); |
| 6610 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6611 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6612 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6613 | return -EIO; |
| 6614 | } |
| 6615 | |
| 6616 | spin_lock_irqsave(&priv->lock, flags); |
| 6617 | |
| 6618 | for (i = 0; i < AC_NUM; i++) { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 6619 | txq = &priv->txq[i]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6620 | q = &txq->q; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6621 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6622 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 6623 | stats[i].len = q->n_window - avail; |
| 6624 | stats[i].limit = q->n_window - q->high_mark; |
| 6625 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6626 | |
| 6627 | } |
| 6628 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6629 | |
| 6630 | IWL_DEBUG_MAC80211("leave\n"); |
| 6631 | |
| 6632 | return 0; |
| 6633 | } |
| 6634 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6635 | static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6636 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6637 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6638 | unsigned long flags; |
| 6639 | |
| 6640 | mutex_lock(&priv->mutex); |
| 6641 | IWL_DEBUG_MAC80211("enter\n"); |
| 6642 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6643 | iwl_reset_qos(priv); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 6644 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6645 | spin_lock_irqsave(&priv->lock, flags); |
| 6646 | priv->assoc_id = 0; |
| 6647 | priv->assoc_capability = 0; |
| 6648 | priv->call_post_assoc_from_beacon = 0; |
| 6649 | |
| 6650 | /* new association get rid of ibss beacon skb */ |
| 6651 | if (priv->ibss_beacon) |
| 6652 | dev_kfree_skb(priv->ibss_beacon); |
| 6653 | |
| 6654 | priv->ibss_beacon = NULL; |
| 6655 | |
| 6656 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6657 | priv->timestamp = 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6658 | if ((priv->iw_mode == NL80211_IFTYPE_STATION)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6659 | priv->beacon_int = 0; |
| 6660 | |
| 6661 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6662 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6663 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6664 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 6665 | mutex_unlock(&priv->mutex); |
| 6666 | return; |
| 6667 | } |
| 6668 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6669 | /* we are restarting association process |
| 6670 | * clear RXON_FILTER_ASSOC_MSK bit |
| 6671 | */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6672 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6673 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6674 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6675 | iwl3945_commit_rxon(priv); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6676 | } |
| 6677 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6678 | /* Per mac80211.h: This is only used in IBSS mode... */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6679 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6680 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6681 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 6682 | mutex_unlock(&priv->mutex); |
| 6683 | return; |
| 6684 | } |
| 6685 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6686 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6687 | |
| 6688 | mutex_unlock(&priv->mutex); |
| 6689 | |
| 6690 | IWL_DEBUG_MAC80211("leave\n"); |
| 6691 | |
| 6692 | } |
| 6693 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6694 | static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6695 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6696 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6697 | unsigned long flags; |
| 6698 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6699 | IWL_DEBUG_MAC80211("enter\n"); |
| 6700 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6701 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6702 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6703 | return -EIO; |
| 6704 | } |
| 6705 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6706 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6707 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6708 | return -EIO; |
| 6709 | } |
| 6710 | |
| 6711 | spin_lock_irqsave(&priv->lock, flags); |
| 6712 | |
| 6713 | if (priv->ibss_beacon) |
| 6714 | dev_kfree_skb(priv->ibss_beacon); |
| 6715 | |
| 6716 | priv->ibss_beacon = skb; |
| 6717 | |
| 6718 | priv->assoc_id = 0; |
| 6719 | |
| 6720 | IWL_DEBUG_MAC80211("leave\n"); |
| 6721 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6722 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6723 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6724 | |
Abhijeet Kolekar | dc4b1e7 | 2008-09-03 11:26:30 +0800 | [diff] [blame] | 6725 | iwl3945_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6726 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6727 | |
| 6728 | return 0; |
| 6729 | } |
| 6730 | |
| 6731 | /***************************************************************************** |
| 6732 | * |
| 6733 | * sysfs attributes |
| 6734 | * |
| 6735 | *****************************************************************************/ |
| 6736 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6737 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6738 | |
| 6739 | /* |
| 6740 | * The following adds a new attribute to the sysfs representation |
| 6741 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 6742 | * used for controlling the debug level. |
| 6743 | * |
| 6744 | * See the level definitions in iwl for details. |
| 6745 | */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6746 | static ssize_t show_debug_level(struct device *d, |
| 6747 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6748 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6749 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6750 | |
| 6751 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6752 | } |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6753 | static ssize_t store_debug_level(struct device *d, |
| 6754 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6755 | const char *buf, size_t count) |
| 6756 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6757 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6758 | unsigned long val; |
| 6759 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6760 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6761 | ret = strict_strtoul(buf, 0, &val); |
| 6762 | if (ret) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 6763 | IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6764 | else |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6765 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6766 | |
| 6767 | return strnlen(buf, count); |
| 6768 | } |
| 6769 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6770 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 6771 | show_debug_level, store_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6772 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6773 | #endif /* CONFIG_IWL3945_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6774 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6775 | static ssize_t show_temperature(struct device *d, |
| 6776 | struct device_attribute *attr, char *buf) |
| 6777 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6778 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6779 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6780 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6781 | return -EAGAIN; |
| 6782 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6783 | return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 6787 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6788 | static ssize_t show_tx_power(struct device *d, |
| 6789 | struct device_attribute *attr, char *buf) |
| 6790 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6791 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6792 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 6793 | } |
| 6794 | |
| 6795 | static ssize_t store_tx_power(struct device *d, |
| 6796 | struct device_attribute *attr, |
| 6797 | const char *buf, size_t count) |
| 6798 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6799 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6800 | char *p = (char *)buf; |
| 6801 | u32 val; |
| 6802 | |
| 6803 | val = simple_strtoul(p, &p, 10); |
| 6804 | if (p == buf) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 6805 | IWL_INFO(priv, ": %s is not in decimal form.\n", buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6806 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6807 | iwl3945_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6808 | |
| 6809 | return count; |
| 6810 | } |
| 6811 | |
| 6812 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 6813 | |
| 6814 | static ssize_t show_flags(struct device *d, |
| 6815 | struct device_attribute *attr, char *buf) |
| 6816 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6817 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6818 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6819 | return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6820 | } |
| 6821 | |
| 6822 | static ssize_t store_flags(struct device *d, |
| 6823 | struct device_attribute *attr, |
| 6824 | const char *buf, size_t count) |
| 6825 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6826 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6827 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 6828 | |
| 6829 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6830 | if (le32_to_cpu(priv->staging39_rxon.flags) != flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6831 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6832 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6833 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6834 | else { |
| 6835 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 6836 | flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6837 | priv->staging39_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6838 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6839 | } |
| 6840 | } |
| 6841 | mutex_unlock(&priv->mutex); |
| 6842 | |
| 6843 | return count; |
| 6844 | } |
| 6845 | |
| 6846 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 6847 | |
| 6848 | static ssize_t show_filter_flags(struct device *d, |
| 6849 | struct device_attribute *attr, char *buf) |
| 6850 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6851 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6852 | |
| 6853 | return sprintf(buf, "0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6854 | le32_to_cpu(priv->active39_rxon.filter_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6855 | } |
| 6856 | |
| 6857 | static ssize_t store_filter_flags(struct device *d, |
| 6858 | struct device_attribute *attr, |
| 6859 | const char *buf, size_t count) |
| 6860 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6861 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6862 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 6863 | |
| 6864 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6865 | if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6866 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6867 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6868 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6869 | else { |
| 6870 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 6871 | "0x%04X\n", filter_flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6872 | priv->staging39_rxon.filter_flags = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6873 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6874 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6875 | } |
| 6876 | } |
| 6877 | mutex_unlock(&priv->mutex); |
| 6878 | |
| 6879 | return count; |
| 6880 | } |
| 6881 | |
| 6882 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 6883 | store_filter_flags); |
| 6884 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6885 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6886 | |
| 6887 | static ssize_t show_measurement(struct device *d, |
| 6888 | struct device_attribute *attr, char *buf) |
| 6889 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6890 | struct iwl_priv *priv = dev_get_drvdata(d); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 6891 | struct iwl_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6892 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 6893 | u8 *data = (u8 *)&measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6894 | unsigned long flags; |
| 6895 | |
| 6896 | spin_lock_irqsave(&priv->lock, flags); |
| 6897 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 6898 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6899 | return 0; |
| 6900 | } |
| 6901 | memcpy(&measure_report, &priv->measure_report, size); |
| 6902 | priv->measurement_status = 0; |
| 6903 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6904 | |
| 6905 | while (size && (PAGE_SIZE - len)) { |
| 6906 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 6907 | PAGE_SIZE - len, 1); |
| 6908 | len = strlen(buf); |
| 6909 | if (PAGE_SIZE - len) |
| 6910 | buf[len++] = '\n'; |
| 6911 | |
| 6912 | ofs += 16; |
| 6913 | size -= min(size, 16U); |
| 6914 | } |
| 6915 | |
| 6916 | return len; |
| 6917 | } |
| 6918 | |
| 6919 | static ssize_t store_measurement(struct device *d, |
| 6920 | struct device_attribute *attr, |
| 6921 | const char *buf, size_t count) |
| 6922 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6923 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6924 | struct ieee80211_measurement_params params = { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6925 | .channel = le16_to_cpu(priv->active39_rxon.channel), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6926 | .start_time = cpu_to_le64(priv->last_tsf), |
| 6927 | .duration = cpu_to_le16(1), |
| 6928 | }; |
| 6929 | u8 type = IWL_MEASURE_BASIC; |
| 6930 | u8 buffer[32]; |
| 6931 | u8 channel; |
| 6932 | |
| 6933 | if (count) { |
| 6934 | char *p = buffer; |
| 6935 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 6936 | channel = simple_strtoul(p, NULL, 0); |
| 6937 | if (channel) |
| 6938 | params.channel = channel; |
| 6939 | |
| 6940 | p = buffer; |
| 6941 | while (*p && *p != ' ') |
| 6942 | p++; |
| 6943 | if (*p) |
| 6944 | type = simple_strtoul(p + 1, NULL, 0); |
| 6945 | } |
| 6946 | |
| 6947 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 6948 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6949 | iwl3945_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6950 | |
| 6951 | return count; |
| 6952 | } |
| 6953 | |
| 6954 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 6955 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6956 | #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6957 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6958 | static ssize_t store_retry_rate(struct device *d, |
| 6959 | struct device_attribute *attr, |
| 6960 | const char *buf, size_t count) |
| 6961 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6962 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6963 | |
| 6964 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 6965 | if (priv->retry_rate <= 0) |
| 6966 | priv->retry_rate = 1; |
| 6967 | |
| 6968 | return count; |
| 6969 | } |
| 6970 | |
| 6971 | static ssize_t show_retry_rate(struct device *d, |
| 6972 | struct device_attribute *attr, char *buf) |
| 6973 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6974 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6975 | return sprintf(buf, "%d", priv->retry_rate); |
| 6976 | } |
| 6977 | |
| 6978 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 6979 | store_retry_rate); |
| 6980 | |
| 6981 | static ssize_t store_power_level(struct device *d, |
| 6982 | struct device_attribute *attr, |
| 6983 | const char *buf, size_t count) |
| 6984 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6985 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6986 | int rc; |
| 6987 | int mode; |
| 6988 | |
| 6989 | mode = simple_strtoul(buf, NULL, 0); |
| 6990 | mutex_lock(&priv->mutex); |
| 6991 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6992 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6993 | rc = -EAGAIN; |
| 6994 | goto out; |
| 6995 | } |
| 6996 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 6997 | if ((mode < 1) || (mode > IWL39_POWER_LIMIT) || |
| 6998 | (mode == IWL39_POWER_AC)) |
| 6999 | mode = IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7000 | else |
| 7001 | mode |= IWL_POWER_ENABLED; |
| 7002 | |
| 7003 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7004 | rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7005 | if (rc) { |
| 7006 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 7007 | goto out; |
| 7008 | } |
| 7009 | priv->power_mode = mode; |
| 7010 | } |
| 7011 | |
| 7012 | rc = count; |
| 7013 | |
| 7014 | out: |
| 7015 | mutex_unlock(&priv->mutex); |
| 7016 | return rc; |
| 7017 | } |
| 7018 | |
| 7019 | #define MAX_WX_STRING 80 |
| 7020 | |
| 7021 | /* Values are in microsecond */ |
| 7022 | static const s32 timeout_duration[] = { |
| 7023 | 350000, |
| 7024 | 250000, |
| 7025 | 75000, |
| 7026 | 37000, |
| 7027 | 25000, |
| 7028 | }; |
| 7029 | static const s32 period_duration[] = { |
| 7030 | 400000, |
| 7031 | 700000, |
| 7032 | 1000000, |
| 7033 | 1000000, |
| 7034 | 1000000 |
| 7035 | }; |
| 7036 | |
| 7037 | static ssize_t show_power_level(struct device *d, |
| 7038 | struct device_attribute *attr, char *buf) |
| 7039 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7040 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7041 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 7042 | char *p = buf; |
| 7043 | |
| 7044 | p += sprintf(p, "%d ", level); |
| 7045 | switch (level) { |
| 7046 | case IWL_POWER_MODE_CAM: |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7047 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7048 | p += sprintf(p, "(AC)"); |
| 7049 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7050 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7051 | p += sprintf(p, "(BATTERY)"); |
| 7052 | break; |
| 7053 | default: |
| 7054 | p += sprintf(p, |
| 7055 | "(Timeout %dms, Period %dms)", |
| 7056 | timeout_duration[level - 1] / 1000, |
| 7057 | period_duration[level - 1] / 1000); |
| 7058 | } |
| 7059 | |
| 7060 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 7061 | p += sprintf(p, " OFF\n"); |
| 7062 | else |
| 7063 | p += sprintf(p, " \n"); |
| 7064 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7065 | return p - buf + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7066 | |
| 7067 | } |
| 7068 | |
| 7069 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 7070 | store_power_level); |
| 7071 | |
| 7072 | static ssize_t show_channels(struct device *d, |
| 7073 | struct device_attribute *attr, char *buf) |
| 7074 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7075 | /* all this shit doesn't belong into sysfs anyway */ |
| 7076 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7077 | } |
| 7078 | |
| 7079 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 7080 | |
| 7081 | static ssize_t show_statistics(struct device *d, |
| 7082 | struct device_attribute *attr, char *buf) |
| 7083 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7084 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7085 | u32 size = sizeof(struct iwl3945_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7086 | u32 len = 0, ofs = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7087 | u8 *data = (u8 *)&priv->statistics_39; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7088 | int rc = 0; |
| 7089 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7090 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7091 | return -EAGAIN; |
| 7092 | |
| 7093 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7094 | rc = iwl3945_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7095 | mutex_unlock(&priv->mutex); |
| 7096 | |
| 7097 | if (rc) { |
| 7098 | len = sprintf(buf, |
| 7099 | "Error sending statistics request: 0x%08X\n", rc); |
| 7100 | return len; |
| 7101 | } |
| 7102 | |
| 7103 | while (size && (PAGE_SIZE - len)) { |
| 7104 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7105 | PAGE_SIZE - len, 1); |
| 7106 | len = strlen(buf); |
| 7107 | if (PAGE_SIZE - len) |
| 7108 | buf[len++] = '\n'; |
| 7109 | |
| 7110 | ofs += 16; |
| 7111 | size -= min(size, 16U); |
| 7112 | } |
| 7113 | |
| 7114 | return len; |
| 7115 | } |
| 7116 | |
| 7117 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 7118 | |
| 7119 | static ssize_t show_antenna(struct device *d, |
| 7120 | struct device_attribute *attr, char *buf) |
| 7121 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7122 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7123 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7124 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7125 | return -EAGAIN; |
| 7126 | |
| 7127 | return sprintf(buf, "%d\n", priv->antenna); |
| 7128 | } |
| 7129 | |
| 7130 | static ssize_t store_antenna(struct device *d, |
| 7131 | struct device_attribute *attr, |
| 7132 | const char *buf, size_t count) |
| 7133 | { |
| 7134 | int ant; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7135 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7136 | |
| 7137 | if (count == 0) |
| 7138 | return 0; |
| 7139 | |
| 7140 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 7141 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 7142 | return count; |
| 7143 | } |
| 7144 | |
| 7145 | if ((ant >= 0) && (ant <= 2)) { |
| 7146 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7147 | priv->antenna = (enum iwl3945_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7148 | } else |
| 7149 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 7150 | |
| 7151 | |
| 7152 | return count; |
| 7153 | } |
| 7154 | |
| 7155 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 7156 | |
| 7157 | static ssize_t show_status(struct device *d, |
| 7158 | struct device_attribute *attr, char *buf) |
| 7159 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7160 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7161 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7162 | return -EAGAIN; |
| 7163 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 7164 | } |
| 7165 | |
| 7166 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 7167 | |
| 7168 | static ssize_t dump_error_log(struct device *d, |
| 7169 | struct device_attribute *attr, |
| 7170 | const char *buf, size_t count) |
| 7171 | { |
| 7172 | char *p = (char *)buf; |
| 7173 | |
| 7174 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7175 | iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7176 | |
| 7177 | return strnlen(buf, count); |
| 7178 | } |
| 7179 | |
| 7180 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 7181 | |
| 7182 | static ssize_t dump_event_log(struct device *d, |
| 7183 | struct device_attribute *attr, |
| 7184 | const char *buf, size_t count) |
| 7185 | { |
| 7186 | char *p = (char *)buf; |
| 7187 | |
| 7188 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7189 | iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7190 | |
| 7191 | return strnlen(buf, count); |
| 7192 | } |
| 7193 | |
| 7194 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 7195 | |
| 7196 | /***************************************************************************** |
| 7197 | * |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 7198 | * driver setup and tear down |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7199 | * |
| 7200 | *****************************************************************************/ |
| 7201 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7202 | static void iwl3945_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7203 | { |
| 7204 | priv->workqueue = create_workqueue(DRV_NAME); |
| 7205 | |
| 7206 | init_waitqueue_head(&priv->wait_command_queue); |
| 7207 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7208 | INIT_WORK(&priv->up, iwl3945_bg_up); |
| 7209 | INIT_WORK(&priv->restart, iwl3945_bg_restart); |
| 7210 | INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); |
| 7211 | INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed); |
| 7212 | INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan); |
| 7213 | INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan); |
| 7214 | INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill); |
| 7215 | INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7216 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); |
| 7217 | INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); |
| 7218 | INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7219 | INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7220 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7221 | iwl3945_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7222 | |
| 7223 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7224 | iwl3945_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7225 | } |
| 7226 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7227 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7228 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7229 | iwl3945_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7230 | |
Joonwoo Park | e47eb6a | 2007-11-29 10:42:49 +0900 | [diff] [blame] | 7231 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7232 | cancel_delayed_work(&priv->scan_check); |
| 7233 | cancel_delayed_work(&priv->alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7234 | cancel_work_sync(&priv->beacon_update); |
| 7235 | } |
| 7236 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7237 | static struct attribute *iwl3945_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7238 | &dev_attr_antenna.attr, |
| 7239 | &dev_attr_channels.attr, |
| 7240 | &dev_attr_dump_errors.attr, |
| 7241 | &dev_attr_dump_events.attr, |
| 7242 | &dev_attr_flags.attr, |
| 7243 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7244 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7245 | &dev_attr_measurement.attr, |
| 7246 | #endif |
| 7247 | &dev_attr_power_level.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7248 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7249 | &dev_attr_statistics.attr, |
| 7250 | &dev_attr_status.attr, |
| 7251 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7252 | &dev_attr_tx_power.attr, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7253 | #ifdef CONFIG_IWL3945_DEBUG |
| 7254 | &dev_attr_debug_level.attr, |
| 7255 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7256 | NULL |
| 7257 | }; |
| 7258 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7259 | static struct attribute_group iwl3945_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7260 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7261 | .attrs = iwl3945_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7262 | }; |
| 7263 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7264 | static struct ieee80211_ops iwl3945_hw_ops = { |
| 7265 | .tx = iwl3945_mac_tx, |
| 7266 | .start = iwl3945_mac_start, |
| 7267 | .stop = iwl3945_mac_stop, |
| 7268 | .add_interface = iwl3945_mac_add_interface, |
| 7269 | .remove_interface = iwl3945_mac_remove_interface, |
| 7270 | .config = iwl3945_mac_config, |
| 7271 | .config_interface = iwl3945_mac_config_interface, |
| 7272 | .configure_filter = iwl3945_configure_filter, |
| 7273 | .set_key = iwl3945_mac_set_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7274 | .get_tx_stats = iwl3945_mac_get_tx_stats, |
| 7275 | .conf_tx = iwl3945_mac_conf_tx, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7276 | .reset_tsf = iwl3945_mac_reset_tsf, |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 7277 | .bss_info_changed = iwl3945_bss_info_changed, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7278 | .hw_scan = iwl3945_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7279 | }; |
| 7280 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 7281 | static int iwl3945_init_drv(struct iwl_priv *priv) |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7282 | { |
| 7283 | int ret; |
| 7284 | |
| 7285 | priv->retry_rate = 1; |
| 7286 | priv->ibss_beacon = NULL; |
| 7287 | |
| 7288 | spin_lock_init(&priv->lock); |
Samuel Ortiz | c7a7c8e | 2009-01-08 10:20:01 -0800 | [diff] [blame] | 7289 | spin_lock_init(&priv->power_data_39.lock); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7290 | spin_lock_init(&priv->sta_lock); |
| 7291 | spin_lock_init(&priv->hcmd_lock); |
| 7292 | |
| 7293 | INIT_LIST_HEAD(&priv->free_frames); |
| 7294 | |
| 7295 | mutex_init(&priv->mutex); |
| 7296 | |
| 7297 | /* Clear the driver's (not device's) station table */ |
| 7298 | iwl3945_clear_stations_table(priv); |
| 7299 | |
| 7300 | priv->data_retry_limit = -1; |
| 7301 | priv->ieee_channels = NULL; |
| 7302 | priv->ieee_rates = NULL; |
| 7303 | priv->band = IEEE80211_BAND_2GHZ; |
| 7304 | |
| 7305 | priv->iw_mode = NL80211_IFTYPE_STATION; |
| 7306 | |
| 7307 | iwl_reset_qos(priv); |
| 7308 | |
| 7309 | priv->qos_data.qos_active = 0; |
| 7310 | priv->qos_data.qos_cap.val = 0; |
| 7311 | |
| 7312 | priv->rates_mask = IWL_RATES_MASK; |
| 7313 | /* If power management is turned on, default to AC mode */ |
Samuel Ortiz | c7a7c8e | 2009-01-08 10:20:01 -0800 | [diff] [blame] | 7314 | priv->power_mode = IWL39_POWER_AC; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7315 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 7316 | |
| 7317 | ret = iwl3945_init_channel_map(priv); |
| 7318 | if (ret) { |
| 7319 | IWL_ERR(priv, "initializing regulatory failed: %d\n", ret); |
| 7320 | goto err; |
| 7321 | } |
| 7322 | |
| 7323 | ret = iwl3945_init_geos(priv); |
| 7324 | if (ret) { |
| 7325 | IWL_ERR(priv, "initializing geos failed: %d\n", ret); |
| 7326 | goto err_free_channel_map; |
| 7327 | } |
| 7328 | |
| 7329 | return 0; |
| 7330 | |
| 7331 | err_free_channel_map: |
| 7332 | iwl3945_free_channel_map(priv); |
| 7333 | err: |
| 7334 | return ret; |
| 7335 | } |
| 7336 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7337 | static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7338 | { |
| 7339 | int err = 0; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7340 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7341 | struct ieee80211_hw *hw; |
Kolekar, Abhijeet | c0f20d9 | 2008-12-19 10:37:19 +0800 | [diff] [blame] | 7342 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7343 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7344 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7345 | /*********************** |
| 7346 | * 1. Allocating HW data |
| 7347 | * ********************/ |
| 7348 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7349 | /* mac80211 allocates memory for this device instance, including |
| 7350 | * space for this driver's private structure */ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7351 | hw = iwl_alloc_all(cfg, &iwl3945_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7352 | if (hw == NULL) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7353 | printk(KERN_ERR DRV_NAME "Can not allocate network device\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7354 | err = -ENOMEM; |
| 7355 | goto out; |
| 7356 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7357 | priv = hw->priv; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7358 | SET_IEEE80211_DEV(hw, &pdev->dev); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7359 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7360 | if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) || |
| 7361 | (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7362 | IWL_ERR(priv, |
| 7363 | "invalid queues_num, should be between %d and %d\n", |
| 7364 | IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES); |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7365 | err = -EINVAL; |
| 7366 | goto out; |
| 7367 | } |
| 7368 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7369 | /* |
| 7370 | * Disabling hardware scan means that mac80211 will perform scans |
| 7371 | * "the hard way", rather than using device's scan. |
| 7372 | */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7373 | if (iwl3945_mod_params.disable_hw_scan) { |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7374 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
| 7375 | iwl3945_hw_ops.hw_scan = NULL; |
| 7376 | } |
| 7377 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7378 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7379 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7380 | priv->cfg = cfg; |
| 7381 | priv->pci_dev = pdev; |
| 7382 | |
| 7383 | #ifdef CONFIG_IWL3945_DEBUG |
| 7384 | priv->debug_level = iwl3945_mod_params.debug; |
| 7385 | atomic_set(&priv->restrict_refcnt, 0); |
| 7386 | #endif |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7387 | hw->rate_control_algorithm = "iwl-3945-rs"; |
| 7388 | hw->sta_data_size = sizeof(struct iwl3945_sta_priv); |
| 7389 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7390 | /* Select antenna (may be helpful if only one antenna is connected) */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7391 | priv->antenna = (enum iwl3945_antenna)iwl3945_mod_params.antenna; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7392 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7393 | /* Tell mac80211 our characteristics */ |
Johannes Berg | 605a0bd | 2008-07-15 10:10:01 +0200 | [diff] [blame] | 7394 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7395 | IEEE80211_HW_NOISE_DBM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7396 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7397 | hw->wiphy->interface_modes = |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7398 | BIT(NL80211_IFTYPE_STATION) | |
| 7399 | BIT(NL80211_IFTYPE_ADHOC); |
| 7400 | |
Luis R. Rodriguez | ea4a82dc | 2008-11-12 14:22:04 -0800 | [diff] [blame] | 7401 | hw->wiphy->fw_handles_regulatory = true; |
| 7402 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7403 | /* 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7404 | hw->queues = 4; |
| 7405 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7406 | /*************************** |
| 7407 | * 2. Initializing PCI bus |
| 7408 | * *************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7409 | if (pci_enable_device(pdev)) { |
| 7410 | err = -ENODEV; |
| 7411 | goto out_ieee80211_free_hw; |
| 7412 | } |
| 7413 | |
| 7414 | pci_set_master(pdev); |
| 7415 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7416 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 7417 | if (!err) |
| 7418 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 7419 | if (err) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7420 | IWL_WARN(priv, "No suitable DMA available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7421 | goto out_pci_disable_device; |
| 7422 | } |
| 7423 | |
| 7424 | pci_set_drvdata(pdev, priv); |
| 7425 | err = pci_request_regions(pdev, DRV_NAME); |
| 7426 | if (err) |
| 7427 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7428 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7429 | /*********************** |
| 7430 | * 3. Read REV Register |
| 7431 | * ********************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7432 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 7433 | if (!priv->hw_base) { |
| 7434 | err = -ENODEV; |
| 7435 | goto out_pci_release_regions; |
| 7436 | } |
| 7437 | |
| 7438 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 7439 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 7440 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 7441 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7442 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 7443 | * PCI Tx retries from interfering with C3 CPU state */ |
| 7444 | pci_write_config_byte(pdev, 0x41, 0x00); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7445 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7446 | /* amp init */ |
| 7447 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7448 | if (err < 0) { |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7449 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 7450 | goto out_iounmap; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7451 | } |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7452 | |
| 7453 | /*********************** |
| 7454 | * 4. Read EEPROM |
| 7455 | * ********************/ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7456 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7457 | /* Read the EEPROM */ |
| 7458 | err = iwl3945_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7459 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7460 | IWL_ERR(priv, "Unable to init EEPROM\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7461 | goto out_remove_sysfs; |
| 7462 | } |
| 7463 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 7464 | get_eeprom_mac(priv, priv->mac_addr); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7465 | IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7466 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 7467 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7468 | /*********************** |
| 7469 | * 5. Setup HW Constants |
| 7470 | * ********************/ |
| 7471 | /* Device-specific setup */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7472 | if (iwl3945_hw_set_hw_params(priv)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7473 | IWL_ERR(priv, "failed to set hw settings\n"); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7474 | goto out_iounmap; |
| 7475 | } |
| 7476 | |
| 7477 | /*********************** |
| 7478 | * 6. Setup priv |
| 7479 | * ********************/ |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7480 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7481 | err = iwl3945_init_drv(priv); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7482 | if (err) { |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7483 | IWL_ERR(priv, "initializing driver failed\n"); |
| 7484 | goto out_free_geos; |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7485 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7486 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7487 | IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n", |
| 7488 | priv->cfg->name); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7489 | |
| 7490 | /*********************************** |
| 7491 | * 7. Initialize Module Parameters |
| 7492 | * **********************************/ |
| 7493 | |
| 7494 | /* Initialize module parameter values here */ |
| 7495 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7496 | if (iwl3945_mod_params.disable) { |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7497 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 7498 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 7499 | } |
| 7500 | |
| 7501 | |
| 7502 | /*********************** |
| 7503 | * 8. Setup Services |
| 7504 | * ********************/ |
| 7505 | |
| 7506 | spin_lock_irqsave(&priv->lock, flags); |
| 7507 | iwl3945_disable_interrupts(priv); |
| 7508 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7509 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7510 | pci_enable_msi(priv->pci_dev); |
| 7511 | |
| 7512 | err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED, |
| 7513 | DRV_NAME, priv); |
| 7514 | if (err) { |
| 7515 | IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 7516 | goto out_disable_msi; |
| 7517 | } |
| 7518 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7519 | err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
| 7520 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7521 | IWL_ERR(priv, "failed to create sysfs device attributes\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7522 | goto out_release_irq; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7523 | } |
| 7524 | |
| 7525 | iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
| 7526 | iwl3945_setup_deferred_work(priv); |
| 7527 | iwl3945_setup_rx_handlers(priv); |
| 7528 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7529 | /********************************* |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7530 | * 9. Setup and Register mac80211 |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7531 | * *******************************/ |
| 7532 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7533 | err = ieee80211_register_hw(priv->hw); |
| 7534 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7535 | IWL_ERR(priv, "Failed to register network device: %d\n", err); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7536 | goto out_remove_sysfs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7537 | } |
| 7538 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7539 | priv->hw->conf.beacon_int = 100; |
| 7540 | priv->mac80211_registered = 1; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7541 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7542 | err = iwl3945_rfkill_init(priv); |
| 7543 | if (err) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7544 | IWL_ERR(priv, "Unable to initialize RFKILL system. " |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7545 | "Ignoring error: %d\n", err); |
| 7546 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7547 | /* Start monitoring the killswitch */ |
| 7548 | queue_delayed_work(priv->workqueue, &priv->rfkill_poll, |
| 7549 | 2 * HZ); |
| 7550 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7551 | return 0; |
| 7552 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7553 | out_remove_sysfs: |
| 7554 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7555 | out_free_geos: |
| 7556 | iwl3945_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7557 | |
| 7558 | out_release_irq: |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7559 | free_irq(priv->pci_dev->irq, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7560 | destroy_workqueue(priv->workqueue); |
| 7561 | priv->workqueue = NULL; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7562 | iwl3945_unset_hw_params(priv); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7563 | out_disable_msi: |
| 7564 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7565 | out_iounmap: |
| 7566 | pci_iounmap(pdev, priv->hw_base); |
| 7567 | out_pci_release_regions: |
| 7568 | pci_release_regions(pdev); |
| 7569 | out_pci_disable_device: |
| 7570 | pci_disable_device(pdev); |
| 7571 | pci_set_drvdata(pdev, NULL); |
| 7572 | out_ieee80211_free_hw: |
| 7573 | ieee80211_free_hw(priv->hw); |
| 7574 | out: |
| 7575 | return err; |
| 7576 | } |
| 7577 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 7578 | static void __devexit iwl3945_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7579 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7580 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7581 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7582 | |
| 7583 | if (!priv) |
| 7584 | return; |
| 7585 | |
| 7586 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 7587 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7588 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 7589 | |
Kolekar, Abhijeet | d552bfb | 2008-12-19 10:37:41 +0800 | [diff] [blame] | 7590 | if (priv->mac80211_registered) { |
| 7591 | ieee80211_unregister_hw(priv->hw); |
| 7592 | priv->mac80211_registered = 0; |
| 7593 | } else { |
| 7594 | iwl3945_down(priv); |
| 7595 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7596 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7597 | /* make sure we flush any pending irq or |
| 7598 | * tasklet for the driver |
| 7599 | */ |
| 7600 | spin_lock_irqsave(&priv->lock, flags); |
| 7601 | iwl3945_disable_interrupts(priv); |
| 7602 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7603 | |
| 7604 | iwl_synchronize_irq(priv); |
| 7605 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7606 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7607 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7608 | iwl3945_rfkill_unregister(priv); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7609 | cancel_delayed_work(&priv->rfkill_poll); |
| 7610 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7611 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7612 | |
| 7613 | if (priv->rxq.bd) |
Winkler, Tomas | 51af3d3 | 2008-12-22 11:31:23 +0800 | [diff] [blame] | 7614 | iwl_rx_queue_free(priv, &priv->rxq); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7615 | iwl3945_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7616 | |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7617 | iwl3945_unset_hw_params(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7618 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7619 | |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 7620 | /*netif_stop_queue(dev); */ |
| 7621 | flush_workqueue(priv->workqueue); |
| 7622 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7623 | /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7624 | * priv->workqueue... so we can't take down the workqueue |
| 7625 | * until now... */ |
| 7626 | destroy_workqueue(priv->workqueue); |
| 7627 | priv->workqueue = NULL; |
| 7628 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7629 | free_irq(pdev->irq, priv); |
| 7630 | pci_disable_msi(pdev); |
| 7631 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7632 | pci_iounmap(pdev, priv->hw_base); |
| 7633 | pci_release_regions(pdev); |
| 7634 | pci_disable_device(pdev); |
| 7635 | pci_set_drvdata(pdev, NULL); |
| 7636 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7637 | iwl3945_free_channel_map(priv); |
| 7638 | iwl3945_free_geos(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7639 | kfree(priv->scan39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7640 | if (priv->ibss_beacon) |
| 7641 | dev_kfree_skb(priv->ibss_beacon); |
| 7642 | |
| 7643 | ieee80211_free_hw(priv->hw); |
| 7644 | } |
| 7645 | |
| 7646 | #ifdef CONFIG_PM |
| 7647 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7648 | static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7649 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7650 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7651 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7652 | if (priv->is_open) { |
| 7653 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 7654 | iwl3945_mac_stop(priv->hw); |
| 7655 | priv->is_open = 1; |
| 7656 | } |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7657 | pci_save_state(pdev); |
| 7658 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7659 | pci_set_power_state(pdev, PCI_D3hot); |
| 7660 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7661 | return 0; |
| 7662 | } |
| 7663 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7664 | static int iwl3945_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7665 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7666 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7667 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7668 | pci_set_power_state(pdev, PCI_D0); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7669 | pci_enable_device(pdev); |
| 7670 | pci_restore_state(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7671 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7672 | if (priv->is_open) |
| 7673 | iwl3945_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7674 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7675 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7676 | return 0; |
| 7677 | } |
| 7678 | |
| 7679 | #endif /* CONFIG_PM */ |
| 7680 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7681 | /*************** RFKILL FUNCTIONS **********/ |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7682 | #ifdef CONFIG_IWL3945_RFKILL |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7683 | /* software rf-kill from user */ |
| 7684 | static int iwl3945_rfkill_soft_rf_kill(void *data, enum rfkill_state state) |
| 7685 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7686 | struct iwl_priv *priv = data; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7687 | int err = 0; |
| 7688 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7689 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7690 | return 0; |
| 7691 | |
| 7692 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7693 | return 0; |
| 7694 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 7695 | IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7696 | mutex_lock(&priv->mutex); |
| 7697 | |
| 7698 | switch (state) { |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7699 | case RFKILL_STATE_UNBLOCKED: |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7700 | if (iwl_is_rfkill_hw(priv)) { |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7701 | err = -EBUSY; |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7702 | goto out_unlock; |
| 7703 | } |
| 7704 | iwl3945_radio_kill_sw(priv, 0); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7705 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7706 | case RFKILL_STATE_SOFT_BLOCKED: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7707 | iwl3945_radio_kill_sw(priv, 1); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7708 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7709 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 7710 | IWL_WARN(priv, "received unexpected RFKILL state %d\n", state); |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7711 | break; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7712 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7713 | out_unlock: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7714 | mutex_unlock(&priv->mutex); |
| 7715 | |
| 7716 | return err; |
| 7717 | } |
| 7718 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7719 | int iwl3945_rfkill_init(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7720 | { |
| 7721 | struct device *device = wiphy_dev(priv->hw->wiphy); |
| 7722 | int ret = 0; |
| 7723 | |
| 7724 | BUG_ON(device == NULL); |
| 7725 | |
| 7726 | IWL_DEBUG_RF_KILL("Initializing RFKILL.\n"); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7727 | priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN); |
| 7728 | if (!priv->rfkill) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7729 | IWL_ERR(priv, "Unable to allocate rfkill device.\n"); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7730 | ret = -ENOMEM; |
| 7731 | goto error; |
| 7732 | } |
| 7733 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7734 | priv->rfkill->name = priv->cfg->name; |
| 7735 | priv->rfkill->data = priv; |
| 7736 | priv->rfkill->state = RFKILL_STATE_UNBLOCKED; |
| 7737 | priv->rfkill->toggle_radio = iwl3945_rfkill_soft_rf_kill; |
| 7738 | priv->rfkill->user_claim_unsupported = 1; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7739 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7740 | priv->rfkill->dev.class->suspend = NULL; |
| 7741 | priv->rfkill->dev.class->resume = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7742 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7743 | ret = rfkill_register(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7744 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7745 | IWL_ERR(priv, "Unable to register rfkill: %d\n", ret); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7746 | goto freed_rfkill; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7747 | } |
| 7748 | |
| 7749 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 7750 | return ret; |
| 7751 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7752 | freed_rfkill: |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7753 | if (priv->rfkill != NULL) |
| 7754 | rfkill_free(priv->rfkill); |
| 7755 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7756 | |
| 7757 | error: |
| 7758 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 7759 | return ret; |
| 7760 | } |
| 7761 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7762 | void iwl3945_rfkill_unregister(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7763 | { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7764 | if (priv->rfkill) |
| 7765 | rfkill_unregister(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7766 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7767 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7768 | } |
| 7769 | |
| 7770 | /* set rf-kill to the right state. */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7771 | void iwl3945_rfkill_set_hw_state(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7772 | { |
| 7773 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7774 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7775 | return; |
| 7776 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7777 | if (iwl_is_rfkill_hw(priv)) { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7778 | rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED); |
| 7779 | return; |
| 7780 | } |
| 7781 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7782 | if (!iwl_is_rfkill_sw(priv)) |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7783 | rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7784 | else |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7785 | rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7786 | } |
| 7787 | #endif |
| 7788 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7789 | /***************************************************************************** |
| 7790 | * |
| 7791 | * driver and module entry point |
| 7792 | * |
| 7793 | *****************************************************************************/ |
| 7794 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7795 | static struct pci_driver iwl3945_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7796 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7797 | .id_table = iwl3945_hw_card_ids, |
| 7798 | .probe = iwl3945_pci_probe, |
| 7799 | .remove = __devexit_p(iwl3945_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7800 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7801 | .suspend = iwl3945_pci_suspend, |
| 7802 | .resume = iwl3945_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7803 | #endif |
| 7804 | }; |
| 7805 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7806 | static int __init iwl3945_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7807 | { |
| 7808 | |
| 7809 | int ret; |
| 7810 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 7811 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7812 | |
| 7813 | ret = iwl3945_rate_control_register(); |
| 7814 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7815 | printk(KERN_ERR DRV_NAME |
| 7816 | "Unable to register rate control algorithm: %d\n", ret); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7817 | return ret; |
| 7818 | } |
| 7819 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7820 | ret = pci_register_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7821 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7822 | printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7823 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7824 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7825 | |
| 7826 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7827 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7828 | error_register: |
| 7829 | iwl3945_rate_control_unregister(); |
| 7830 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7831 | } |
| 7832 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7833 | static void __exit iwl3945_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7834 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7835 | pci_unregister_driver(&iwl3945_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7836 | iwl3945_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7837 | } |
| 7838 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 7839 | MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX)); |
Zhu Yi | 25cb6ca | 2008-09-11 11:45:22 +0800 | [diff] [blame] | 7840 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7841 | module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7842 | MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7843 | module_param_named(disable, iwl3945_mod_params.disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7844 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Samuel Ortiz | 9c74d9f | 2009-01-08 10:19:59 -0800 | [diff] [blame] | 7845 | module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444); |
| 7846 | MODULE_PARM_DESC(swcrypto, |
| 7847 | "using software crypto (default 1 [software])\n"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7848 | module_param_named(debug, iwl3945_mod_params.debug, uint, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7849 | MODULE_PARM_DESC(debug, "debug output mask"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7850 | module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7851 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 7852 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7853 | module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7854 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 7855 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7856 | module_exit(iwl3945_exit); |
| 7857 | module_init(iwl3945_init); |