Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2008 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 | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 82 | #define DRV_COPYRIGHT "Copyright(c) 2003-2008 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, |
| 95 | /* the rest are 0 by default */ |
| 96 | }; |
| 97 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 98 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 99 | * DMA services |
| 100 | * |
| 101 | * Theory of operation |
| 102 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 103 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 104 | * of buffer descriptors, each of which points to one or more data buffers for |
| 105 | * the device to read from or fill. Driver and device exchange status of each |
| 106 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 107 | * entries in each circular buffer, to protect against confusing empty and full |
| 108 | * queue states. |
| 109 | * |
| 110 | * The device reads or writes the data in the queues via the device's several |
| 111 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 112 | * |
| 113 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 114 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 115 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 116 | * Tx queue resumed. |
| 117 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 118 | * The 3945 operates with six queues: One receive queue, one transmit queue |
| 119 | * (#4) for sending commands to the device firmware, and four transmit queues |
| 120 | * (#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] | 121 | ***************************************************/ |
| 122 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 123 | /** |
| 124 | * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes |
| 125 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 126 | 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] | 127 | int count, int slots_num, u32 id) |
| 128 | { |
| 129 | q->n_bd = count; |
| 130 | q->n_window = slots_num; |
| 131 | q->id = id; |
| 132 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 133 | /* count must be power-of-two size, otherwise iwl_queue_inc_wrap |
| 134 | * and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 135 | BUG_ON(!is_power_of_2(count)); |
| 136 | |
| 137 | /* slots_num must be power-of-two size, otherwise |
| 138 | * get_cmd_index is broken. */ |
| 139 | BUG_ON(!is_power_of_2(slots_num)); |
| 140 | |
| 141 | q->low_mark = q->n_window / 4; |
| 142 | if (q->low_mark < 4) |
| 143 | q->low_mark = 4; |
| 144 | |
| 145 | q->high_mark = q->n_window / 8; |
| 146 | if (q->high_mark < 2) |
| 147 | q->high_mark = 2; |
| 148 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 149 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 154 | /** |
| 155 | * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 156 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 157 | static int iwl3945_tx_queue_alloc(struct iwl_priv *priv, |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 158 | struct iwl_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 159 | { |
| 160 | struct pci_dev *dev = priv->pci_dev; |
| 161 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 162 | /* Driver private data, only for Tx (not command) queues, |
| 163 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 164 | if (id != IWL_CMD_QUEUE_NUM) { |
| 165 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 166 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 167 | if (!txq->txb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 168 | IWL_ERR(priv, "kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 169 | "structures failed\n"); |
| 170 | goto error; |
| 171 | } |
| 172 | } else |
| 173 | txq->txb = NULL; |
| 174 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 175 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 176 | * shared with device */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 177 | txq->tfds39 = pci_alloc_consistent(dev, |
| 178 | sizeof(txq->tfds39[0]) * TFD_QUEUE_SIZE_MAX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 179 | &txq->q.dma_addr); |
| 180 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 181 | if (!txq->tfds39) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 182 | IWL_ERR(priv, "pci_alloc_consistent(%zd) failed\n", |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 183 | sizeof(txq->tfds39[0]) * TFD_QUEUE_SIZE_MAX); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 184 | goto error; |
| 185 | } |
| 186 | txq->q.id = id; |
| 187 | |
| 188 | return 0; |
| 189 | |
| 190 | error: |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 191 | kfree(txq->txb); |
| 192 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 193 | |
| 194 | return -ENOMEM; |
| 195 | } |
| 196 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 197 | /** |
| 198 | * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 199 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 200 | int iwl3945_tx_queue_init(struct iwl_priv *priv, |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 201 | struct iwl_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 202 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 203 | int len, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 204 | int rc = 0; |
| 205 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 206 | /* |
| 207 | * Alloc buffer array for commands (Tx or other types of commands). |
| 208 | * For the command queue (#4), allocate command space + one big |
| 209 | * command for scan, since scan command is very huge; the system will |
| 210 | * not have two scans at the same time, so only one is needed. |
| 211 | * For data Tx queues (all other queues), no super-size command |
| 212 | * space is needed. |
| 213 | */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 214 | len = sizeof(struct iwl_cmd); |
| 215 | for (i = 0; i <= slots_num; i++) { |
| 216 | if (i == slots_num) { |
| 217 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 218 | len += IWL_MAX_SCAN_SIZE; |
| 219 | else |
| 220 | continue; |
| 221 | } |
| 222 | |
| 223 | txq->cmd[i] = kmalloc(len, GFP_KERNEL); |
| 224 | if (!txq->cmd[i]) |
| 225 | goto err; |
| 226 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 227 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 228 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 229 | rc = iwl3945_tx_queue_alloc(priv, txq, txq_id); |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 230 | if (rc) |
| 231 | goto err; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 232 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 233 | txq->need_update = 0; |
| 234 | |
| 235 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 236 | * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 237 | 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] | 238 | |
| 239 | /* Initialize queue high/low-water, head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 240 | 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] | 241 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 242 | /* Tell device where to find queue, enable DMA channel. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 243 | iwl3945_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 244 | |
| 245 | return 0; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 246 | err: |
| 247 | for (i = 0; i < slots_num; i++) { |
| 248 | kfree(txq->cmd[i]); |
| 249 | txq->cmd[i] = NULL; |
| 250 | } |
| 251 | |
| 252 | if (txq_id == IWL_CMD_QUEUE_NUM) { |
| 253 | kfree(txq->cmd[slots_num]); |
| 254 | txq->cmd[slots_num] = NULL; |
| 255 | } |
| 256 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 260 | * iwl3945_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 261 | * @txq: Transmit queue to deallocate. |
| 262 | * |
| 263 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 264 | * Free all buffers. |
| 265 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 266 | */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 267 | 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] | 268 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 269 | struct iwl_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 270 | struct pci_dev *dev = priv->pci_dev; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 271 | int len, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 272 | |
| 273 | if (q->n_bd == 0) |
| 274 | return; |
| 275 | |
| 276 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 277 | for (; q->write_ptr != q->read_ptr; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 278 | 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] | 279 | iwl3945_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 280 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 281 | len = sizeof(struct iwl_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 282 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 283 | len += IWL_MAX_SCAN_SIZE; |
| 284 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 285 | /* De-alloc array of command/tx buffers */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 286 | for (i = 0; i < TFD_TX_CMD_SLOTS; i++) |
| 287 | kfree(txq->cmd[i]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 288 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 289 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 290 | if (txq->q.n_bd) |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 291 | pci_free_consistent(dev, sizeof(struct iwl3945_tfd) * |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 292 | txq->q.n_bd, txq->tfds39, txq->q.dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 293 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 294 | /* De-alloc array of per-TFD driver data */ |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 295 | kfree(txq->txb); |
| 296 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 297 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 298 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 299 | memset(txq, 0, sizeof(*txq)); |
| 300 | } |
| 301 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 302 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 303 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 304 | * the functionality provided here |
| 305 | */ |
| 306 | |
| 307 | /**************************************************************/ |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 308 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 309 | /** |
| 310 | * iwl3945_remove_station - Remove driver's knowledge of station. |
| 311 | * |
| 312 | * NOTE: This does not remove station from device's station table. |
| 313 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 314 | 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] | 315 | { |
| 316 | int index = IWL_INVALID_STATION; |
| 317 | int i; |
| 318 | unsigned long flags; |
| 319 | |
| 320 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 321 | |
| 322 | if (is_ap) |
| 323 | index = IWL_AP_ID; |
| 324 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 325 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 326 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 327 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 328 | if (priv->stations_39[i].used && |
| 329 | !compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 330 | addr)) { |
| 331 | index = i; |
| 332 | break; |
| 333 | } |
| 334 | |
| 335 | if (unlikely(index == IWL_INVALID_STATION)) |
| 336 | goto out; |
| 337 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 338 | if (priv->stations_39[index].used) { |
| 339 | priv->stations_39[index].used = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 340 | priv->num_stations--; |
| 341 | } |
| 342 | |
| 343 | BUG_ON(priv->num_stations < 0); |
| 344 | |
| 345 | out: |
| 346 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 347 | return 0; |
| 348 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 349 | #endif |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 350 | |
| 351 | /** |
| 352 | * iwl3945_clear_stations_table - Clear the driver's station table |
| 353 | * |
| 354 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 355 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 356 | static void iwl3945_clear_stations_table(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 357 | { |
| 358 | unsigned long flags; |
| 359 | |
| 360 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 361 | |
| 362 | priv->num_stations = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 363 | memset(priv->stations_39, 0, sizeof(priv->stations_39)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 364 | |
| 365 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 366 | } |
| 367 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 368 | /** |
| 369 | * iwl3945_add_station - Add station to station tables in driver and device |
| 370 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 371 | 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] | 372 | { |
| 373 | int i; |
| 374 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 375 | struct iwl3945_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 376 | unsigned long flags_spin; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 377 | u8 rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 378 | |
| 379 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 380 | if (is_ap) |
| 381 | index = IWL_AP_ID; |
| 382 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 383 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 384 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 385 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 386 | if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 387 | addr)) { |
| 388 | index = i; |
| 389 | break; |
| 390 | } |
| 391 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 392 | if (!priv->stations_39[i].used && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 393 | index == IWL_INVALID_STATION) |
| 394 | index = i; |
| 395 | } |
| 396 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 397 | /* These two conditions has the same outcome but keep them separate |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 398 | since they have different meaning */ |
| 399 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 400 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 401 | return index; |
| 402 | } |
| 403 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 404 | if (priv->stations_39[index].used && |
| 405 | !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 406 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 407 | return index; |
| 408 | } |
| 409 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 410 | IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 411 | station = &priv->stations_39[index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 412 | station->used = 1; |
| 413 | priv->num_stations++; |
| 414 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 415 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 416 | memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 417 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 418 | station->sta.mode = 0; |
| 419 | station->sta.sta.sta_id = index; |
| 420 | station->sta.station_flags = 0; |
| 421 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 422 | if (priv->band == IEEE80211_BAND_5GHZ) |
Tomas Winkler | 6994633 | 2007-10-25 17:15:27 +0800 | [diff] [blame] | 423 | rate = IWL_RATE_6M_PLCP; |
| 424 | else |
| 425 | rate = IWL_RATE_1M_PLCP; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 426 | |
| 427 | /* Turn on both antennas for the station... */ |
| 428 | station->sta.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 429 | iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 430 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 431 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 432 | |
| 433 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 434 | iwl3945_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 435 | return index; |
| 436 | |
| 437 | } |
| 438 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 439 | |
| 440 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 441 | |
Abhijeet Kolekar | c305606 | 2008-11-12 13:14:08 -0800 | [diff] [blame] | 442 | #define IWL_CMD(x) case x: return #x |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 443 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 444 | |
| 445 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 446 | * iwl3945_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 447 | * @priv: device private data point |
| 448 | * @cmd: a point to the ucode command structure |
| 449 | * |
| 450 | * The function returns < 0 values to indicate the operation is |
| 451 | * failed. On success, it turns the index (> 0) of command in the |
| 452 | * command queue. |
| 453 | */ |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 454 | 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] | 455 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 456 | struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 457 | struct iwl_queue *q = &txq->q; |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 458 | struct iwl3945_tfd *tfd; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 459 | struct iwl_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 460 | u32 idx; |
| 461 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 462 | dma_addr_t phys_addr; |
| 463 | int pad; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 464 | int ret, len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 465 | unsigned long flags; |
| 466 | |
| 467 | /* If any of the command structures end up being larger than |
| 468 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 469 | * we will need to increase the size of the TFD entries */ |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 470 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 471 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 472 | |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 473 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 474 | if (iwl_is_rfkill(priv)) { |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 475 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 476 | return -EIO; |
| 477 | } |
| 478 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 479 | if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 480 | IWL_ERR(priv, "No space for Tx\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 481 | return -ENOSPC; |
| 482 | } |
| 483 | |
| 484 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 485 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 486 | tfd = &txq->tfds39[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 487 | memset(tfd, 0, sizeof(*tfd)); |
| 488 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 489 | 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] | 490 | out_cmd = txq->cmd[idx]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 491 | |
| 492 | out_cmd->hdr.cmd = cmd->id; |
| 493 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 494 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 495 | |
| 496 | /* At this point, the out_cmd now has all of the incoming cmd |
| 497 | * information */ |
| 498 | |
| 499 | out_cmd->hdr.flags = 0; |
| 500 | 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] | 501 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 502 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 503 | out_cmd->hdr.sequence |= SEQ_HUGE_FRAME; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 504 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 505 | len = (idx == TFD_CMD_SLOTS) ? |
| 506 | IWL_MAX_SCAN_SIZE : sizeof(struct iwl_cmd); |
| 507 | |
| 508 | phys_addr = pci_map_single(priv->pci_dev, out_cmd, |
| 509 | len, PCI_DMA_TODEVICE); |
| 510 | pci_unmap_addr_set(&out_cmd->meta, mapping, phys_addr); |
| 511 | pci_unmap_len_set(&out_cmd->meta, len, len); |
| 512 | phys_addr += offsetof(struct iwl_cmd, hdr); |
| 513 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 514 | 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] | 515 | |
| 516 | pad = U32_PAD(cmd->len); |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 517 | tfd->control_flags |= cpu_to_le32(TFD_CTL_PAD_SET(pad)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 518 | |
| 519 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 520 | "%d bytes at %d[%d]:%d\n", |
| 521 | get_cmd_string(out_cmd->hdr.cmd), |
| 522 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 523 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 524 | |
| 525 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 526 | |
| 527 | /* Increment and update queue's write index */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 528 | 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] | 529 | ret = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 530 | |
| 531 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 532 | return ret ? ret : idx; |
| 533 | } |
| 534 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 535 | static int iwl3945_send_cmd_async(struct iwl_priv *priv, |
| 536 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 537 | { |
| 538 | int ret; |
| 539 | |
| 540 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 541 | |
| 542 | /* An asynchronous command can not expect an SKB to be set. */ |
| 543 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 544 | |
| 545 | /* An asynchronous command MUST have a callback. */ |
| 546 | BUG_ON(!cmd->meta.u.callback); |
| 547 | |
| 548 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 549 | return -EBUSY; |
| 550 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 551 | ret = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 552 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 553 | IWL_ERR(priv, |
| 554 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 555 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 556 | return ret; |
| 557 | } |
| 558 | return 0; |
| 559 | } |
| 560 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 561 | static int iwl3945_send_cmd_sync(struct iwl_priv *priv, |
| 562 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 563 | { |
| 564 | int cmd_idx; |
| 565 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 566 | |
| 567 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 568 | |
| 569 | /* A synchronous command can not have a callback set. */ |
| 570 | BUG_ON(cmd->meta.u.callback != NULL); |
| 571 | |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 572 | if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 573 | IWL_ERR(priv, |
| 574 | "Error sending %s: Already sending a host command\n", |
| 575 | get_cmd_string(cmd->id)); |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 576 | ret = -EBUSY; |
| 577 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 581 | |
| 582 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 583 | cmd->meta.source = &cmd->meta; |
| 584 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 585 | cmd_idx = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 586 | if (cmd_idx < 0) { |
| 587 | ret = cmd_idx; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 588 | IWL_ERR(priv, |
| 589 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 590 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 591 | goto out; |
| 592 | } |
| 593 | |
| 594 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 595 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 596 | HOST_COMPLETE_TIMEOUT); |
| 597 | if (!ret) { |
| 598 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 599 | IWL_ERR(priv, "Error sending %s: time out after %dms\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 600 | get_cmd_string(cmd->id), |
| 601 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 602 | |
| 603 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 604 | ret = -ETIMEDOUT; |
| 605 | goto cancel; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 610 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 611 | get_cmd_string(cmd->id)); |
| 612 | ret = -ECANCELED; |
| 613 | goto fail; |
| 614 | } |
| 615 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 616 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 617 | get_cmd_string(cmd->id)); |
| 618 | ret = -EIO; |
| 619 | goto fail; |
| 620 | } |
| 621 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 622 | IWL_ERR(priv, "Error: Response NULL in '%s'\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 623 | get_cmd_string(cmd->id)); |
| 624 | ret = -EIO; |
Zhu Yi | 73e1a65 | 2009-01-08 10:19:58 -0800 | [diff] [blame] | 625 | goto cancel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | ret = 0; |
| 629 | goto out; |
| 630 | |
| 631 | cancel: |
| 632 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 633 | struct iwl_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 634 | |
| 635 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 636 | * TX cmd queue. Otherwise in case the cmd comes |
| 637 | * in later, it will possibly set an invalid |
| 638 | * address (cmd->meta.source). */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 639 | qcmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 640 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 641 | } |
| 642 | fail: |
| 643 | if (cmd->meta.u.skb) { |
| 644 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 645 | cmd->meta.u.skb = NULL; |
| 646 | } |
| 647 | out: |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 648 | clear_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 649 | return ret; |
| 650 | } |
| 651 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 652 | 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] | 653 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 654 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 655 | return iwl3945_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 656 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 657 | return iwl3945_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 660 | 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] | 661 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 662 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 663 | .id = id, |
| 664 | .len = len, |
| 665 | .data = data, |
| 666 | }; |
| 667 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 668 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 671 | 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] | 672 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 673 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 674 | .id = id, |
| 675 | .len = sizeof(val), |
| 676 | .data = &val, |
| 677 | }; |
| 678 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 679 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 682 | int iwl3945_send_statistics_request(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 683 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 684 | return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 688 | * 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] | 689 | * @band: 2.4 or 5 GHz band |
| 690 | * @channel: Any channel valid for the requested band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 691 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 692 | * In addition to setting the staging RXON, priv->band is also set. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 693 | * |
| 694 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 695 | * in the staging RXON flag structure based on the band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 696 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 697 | static int iwl3945_set_rxon_channel(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 698 | enum ieee80211_band band, |
| 699 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 700 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 701 | if (!iwl3945_get_channel_info(priv, band, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 702 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 703 | channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 704 | return -EINVAL; |
| 705 | } |
| 706 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 707 | if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 708 | (priv->band == band)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 709 | return 0; |
| 710 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 711 | priv->staging39_rxon.channel = cpu_to_le16(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 712 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 713 | priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 714 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 715 | priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 716 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 717 | priv->band = band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 718 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 719 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 720 | |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 725 | * iwl3945_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 726 | * |
| 727 | * NOTE: This is really only useful during development and can eventually |
| 728 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 729 | * making changes |
| 730 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 731 | static int iwl3945_check_rxon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 732 | { |
| 733 | int error = 0; |
| 734 | int counter = 1; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 735 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 736 | |
| 737 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 738 | error |= le32_to_cpu(rxon->flags & |
| 739 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 740 | RXON_FLG_RADAR_DETECT_MSK)); |
| 741 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 742 | IWL_WARN(priv, "check 24G fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 743 | counter++, error); |
| 744 | } else { |
| 745 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 746 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 747 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 748 | IWL_WARN(priv, "check 52 fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 749 | counter++, error); |
| 750 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 751 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 752 | IWL_WARN(priv, "check 52 CCK %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 753 | counter++, error); |
| 754 | } |
| 755 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 756 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 757 | IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 758 | |
| 759 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 760 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 761 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 762 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 763 | IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 764 | |
| 765 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 766 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 767 | IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 768 | |
| 769 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 770 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 771 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 772 | IWL_WARN(priv, "check CCK and short slot %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 773 | counter++, error); |
| 774 | |
| 775 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 776 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 777 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 778 | IWL_WARN(priv, "check CCK & auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 779 | counter++, error); |
| 780 | |
| 781 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 782 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 783 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 784 | IWL_WARN(priv, "check TGG and auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 785 | counter++, error); |
| 786 | |
| 787 | if ((rxon->flags & RXON_FLG_DIS_DIV_MSK)) |
| 788 | error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK | |
| 789 | RXON_FLG_ANT_A_MSK)) == 0); |
| 790 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 791 | IWL_WARN(priv, "check antenna %d %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 792 | |
| 793 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 794 | IWL_WARN(priv, "Tuning to channel %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 795 | le16_to_cpu(rxon->channel)); |
| 796 | |
| 797 | if (error) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 798 | IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 799 | return -1; |
| 800 | } |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 805 | * 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] | 806 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 807 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 808 | * If the RXON structure is changing enough to require a new tune, |
| 809 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 810 | * 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] | 811 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 812 | static int iwl3945_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 813 | { |
| 814 | |
| 815 | /* These items are only settable from the full RXON command */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 816 | if (!(iwl3945_is_associated(priv)) || |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 817 | compare_ether_addr(priv->staging39_rxon.bssid_addr, |
| 818 | priv->active39_rxon.bssid_addr) || |
| 819 | compare_ether_addr(priv->staging39_rxon.node_addr, |
| 820 | priv->active39_rxon.node_addr) || |
| 821 | compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr, |
| 822 | priv->active39_rxon.wlap_bssid_addr) || |
| 823 | (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) || |
| 824 | (priv->staging39_rxon.channel != priv->active39_rxon.channel) || |
| 825 | (priv->staging39_rxon.air_propagation != |
| 826 | priv->active39_rxon.air_propagation) || |
| 827 | (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 828 | return 1; |
| 829 | |
| 830 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 831 | * be updated with the RXON_ASSOC command -- however only some |
| 832 | * flag transitions are allowed using RXON_ASSOC */ |
| 833 | |
| 834 | /* Check if we are not switching bands */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 835 | if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 836 | (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 837 | return 1; |
| 838 | |
| 839 | /* Check if we are switching association toggle */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 840 | if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 841 | (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 842 | return 1; |
| 843 | |
| 844 | return 0; |
| 845 | } |
| 846 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 847 | static int iwl3945_send_rxon_assoc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 848 | { |
| 849 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 850 | struct iwl_rx_packet *res = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 851 | struct iwl3945_rxon_assoc_cmd rxon_assoc; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 852 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 853 | .id = REPLY_RXON_ASSOC, |
| 854 | .len = sizeof(rxon_assoc), |
| 855 | .meta.flags = CMD_WANT_SKB, |
| 856 | .data = &rxon_assoc, |
| 857 | }; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 858 | const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon; |
| 859 | const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 860 | |
| 861 | if ((rxon1->flags == rxon2->flags) && |
| 862 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 863 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 864 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 865 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 866 | return 0; |
| 867 | } |
| 868 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 869 | rxon_assoc.flags = priv->staging39_rxon.flags; |
| 870 | rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags; |
| 871 | rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates; |
| 872 | rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 873 | rxon_assoc.reserved = 0; |
| 874 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 875 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 876 | if (rc) |
| 877 | return rc; |
| 878 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 879 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 880 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 881 | IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 882 | rc = -EIO; |
| 883 | } |
| 884 | |
| 885 | priv->alloc_rxb_skb--; |
| 886 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 887 | |
| 888 | return rc; |
| 889 | } |
| 890 | |
| 891 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 892 | * iwl3945_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 893 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 894 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 895 | * the active_rxon structure is updated with the new data. This |
| 896 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 897 | * a HW tune is required based on the RXON structure changes. |
| 898 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 899 | static int iwl3945_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 900 | { |
| 901 | /* cast away the const for active_rxon in this function */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 902 | struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 903 | int rc = 0; |
| 904 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 905 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 906 | return -1; |
| 907 | |
| 908 | /* always get timestamp with Rx frame */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 909 | priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 910 | |
| 911 | /* select antenna */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 912 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 913 | ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 914 | priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 915 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 916 | rc = iwl3945_check_rxon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 917 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 918 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 919 | return -EINVAL; |
| 920 | } |
| 921 | |
| 922 | /* 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] | 923 | * iwl3945_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 924 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 925 | if (!iwl3945_full_rxon_required(priv)) { |
| 926 | rc = iwl3945_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 927 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 928 | IWL_ERR(priv, "Error setting RXON_ASSOC " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 929 | "configuration (%d).\n", rc); |
| 930 | return rc; |
| 931 | } |
| 932 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 933 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 934 | |
| 935 | return 0; |
| 936 | } |
| 937 | |
| 938 | /* If we are currently associated and the new config requires |
| 939 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 940 | * we must clear the associated from the active configuration |
| 941 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 942 | if (iwl3945_is_associated(priv) && |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 943 | (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 944 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 945 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 946 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 947 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
| 948 | sizeof(struct iwl3945_rxon_cmd), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 949 | &priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 950 | |
| 951 | /* If the mask clearing failed then we set |
| 952 | * active_rxon back to what it was previously */ |
| 953 | if (rc) { |
| 954 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 955 | IWL_ERR(priv, "Error clearing ASSOC_MSK on current " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 956 | "configuration (%d).\n", rc); |
| 957 | return rc; |
| 958 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | IWL_DEBUG_INFO("Sending RXON\n" |
| 962 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 963 | "* channel = %d\n" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 964 | "* bssid = %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 965 | ((priv->staging39_rxon.filter_flags & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 966 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 967 | le16_to_cpu(priv->staging39_rxon.channel), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 968 | priv->staging_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 969 | |
| 970 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 971 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 972 | sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 973 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 974 | IWL_ERR(priv, "Error setting new configuration (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 975 | return rc; |
| 976 | } |
| 977 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 978 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 979 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 980 | iwl3945_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 981 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 982 | /* If we issue a new RXON command which required a tune then we must |
| 983 | * 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] | 984 | rc = iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 985 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 986 | IWL_ERR(priv, "Error setting Tx power (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 987 | return rc; |
| 988 | } |
| 989 | |
| 990 | /* Add the broadcast address so we can send broadcast frames */ |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 991 | if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 992 | IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 993 | IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 994 | return -EIO; |
| 995 | } |
| 996 | |
| 997 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 998 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 999 | if (iwl3945_is_associated(priv) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1000 | (priv->iw_mode == NL80211_IFTYPE_STATION)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1001 | if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1002 | == IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1003 | IWL_ERR(priv, "Error adding AP address for transmit\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1004 | return -EIO; |
| 1005 | } |
| 1006 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1007 | /* Init the hardware's rate fallback order based on the band */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1008 | rc = iwl3945_init_hw_rate_table(priv); |
| 1009 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1010 | IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1011 | return -EIO; |
| 1012 | } |
| 1013 | |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1017 | static int iwl3945_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1018 | { |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1019 | struct iwl_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1020 | .flags = 3, |
| 1021 | .lead_time = 0xAA, |
| 1022 | .max_kill = 1, |
| 1023 | .kill_ack_mask = 0, |
| 1024 | .kill_cts_mask = 0, |
| 1025 | }; |
| 1026 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1027 | return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1028 | sizeof(bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1031 | static int iwl3945_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1032 | { |
| 1033 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1034 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1035 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1036 | .id = REPLY_SCAN_ABORT_CMD, |
| 1037 | .meta.flags = CMD_WANT_SKB, |
| 1038 | }; |
| 1039 | |
| 1040 | /* If there isn't a scan actively going on in the hardware |
| 1041 | * then we are in between scan bands and not actually |
| 1042 | * actively scanning, so don't send the abort command */ |
| 1043 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1044 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1048 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1049 | if (rc) { |
| 1050 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1051 | return rc; |
| 1052 | } |
| 1053 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1054 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1055 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1056 | /* The scan abort will return 1 for success or |
| 1057 | * 2 for "failure". A failure condition can be |
| 1058 | * due to simply not being in an active scan which |
| 1059 | * can occur if we send the scan abort before we |
| 1060 | * the microcode has notified us that a scan is |
| 1061 | * completed. */ |
| 1062 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1063 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1064 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1065 | } |
| 1066 | |
| 1067 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1068 | |
| 1069 | return rc; |
| 1070 | } |
| 1071 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1072 | static int iwl3945_add_sta_sync_callback(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1073 | struct iwl_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1074 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1075 | struct iwl_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1076 | |
| 1077 | if (!skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1078 | IWL_ERR(priv, "Error: Response NULL in REPLY_ADD_STA.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1079 | return 1; |
| 1080 | } |
| 1081 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1082 | res = (struct iwl_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1083 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1084 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1085 | res->hdr.flags); |
| 1086 | return 1; |
| 1087 | } |
| 1088 | |
| 1089 | switch (res->u.add_sta.status) { |
| 1090 | case ADD_STA_SUCCESS_MSK: |
| 1091 | break; |
| 1092 | default: |
| 1093 | break; |
| 1094 | } |
| 1095 | |
| 1096 | /* We didn't cache the SKB; let the caller free it */ |
| 1097 | return 1; |
| 1098 | } |
| 1099 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1100 | int iwl3945_send_add_station(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1101 | struct iwl3945_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1102 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1103 | struct iwl_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1104 | int rc = 0; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1105 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1106 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1107 | .len = sizeof(struct iwl3945_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1108 | .meta.flags = flags, |
| 1109 | .data = sta, |
| 1110 | }; |
| 1111 | |
| 1112 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1113 | cmd.meta.u.callback = iwl3945_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1114 | else |
| 1115 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1116 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1117 | rc = iwl3945_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1118 | |
| 1119 | if (rc || (flags & CMD_ASYNC)) |
| 1120 | return rc; |
| 1121 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1122 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1123 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1124 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1125 | res->hdr.flags); |
| 1126 | rc = -EIO; |
| 1127 | } |
| 1128 | |
| 1129 | if (rc == 0) { |
| 1130 | switch (res->u.add_sta.status) { |
| 1131 | case ADD_STA_SUCCESS_MSK: |
| 1132 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1133 | break; |
| 1134 | default: |
| 1135 | rc = -EIO; |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1136 | IWL_WARN(priv, "REPLY_ADD_STA failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1137 | break; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | priv->alloc_rxb_skb--; |
| 1142 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1143 | |
| 1144 | return rc; |
| 1145 | } |
| 1146 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1147 | static int iwl3945_update_sta_key_info(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1148 | struct ieee80211_key_conf *keyconf, |
| 1149 | u8 sta_id) |
| 1150 | { |
| 1151 | unsigned long flags; |
| 1152 | __le16 key_flags = 0; |
| 1153 | |
| 1154 | switch (keyconf->alg) { |
| 1155 | case ALG_CCMP: |
| 1156 | key_flags |= STA_KEY_FLG_CCMP; |
| 1157 | key_flags |= cpu_to_le16( |
| 1158 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1159 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1160 | break; |
| 1161 | case ALG_TKIP: |
| 1162 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1163 | default: |
| 1164 | return -EINVAL; |
| 1165 | } |
| 1166 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1167 | priv->stations_39[sta_id].keyinfo.alg = keyconf->alg; |
| 1168 | priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1169 | memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1170 | keyconf->keylen); |
| 1171 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1172 | memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1173 | keyconf->keylen); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1174 | priv->stations_39[sta_id].sta.key.key_flags = key_flags; |
| 1175 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1176 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1177 | |
| 1178 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1179 | |
| 1180 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1181 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1185 | 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] | 1186 | { |
| 1187 | unsigned long flags; |
| 1188 | |
| 1189 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1190 | memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key)); |
| 1191 | memset(&priv->stations_39[sta_id].sta.key, 0, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1192 | sizeof(struct iwl4965_keyinfo)); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1193 | priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1194 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1195 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1196 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1197 | |
| 1198 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1199 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1203 | static void iwl3945_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1204 | { |
| 1205 | struct list_head *element; |
| 1206 | |
| 1207 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1208 | priv->frames_count); |
| 1209 | |
| 1210 | while (!list_empty(&priv->free_frames)) { |
| 1211 | element = priv->free_frames.next; |
| 1212 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1213 | kfree(list_entry(element, struct iwl3945_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1214 | priv->frames_count--; |
| 1215 | } |
| 1216 | |
| 1217 | if (priv->frames_count) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1218 | 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] | 1219 | priv->frames_count); |
| 1220 | priv->frames_count = 0; |
| 1221 | } |
| 1222 | } |
| 1223 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1224 | static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1225 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1226 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1227 | struct list_head *element; |
| 1228 | if (list_empty(&priv->free_frames)) { |
| 1229 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1230 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1231 | IWL_ERR(priv, "Could not allocate frame!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1232 | return NULL; |
| 1233 | } |
| 1234 | |
| 1235 | priv->frames_count++; |
| 1236 | return frame; |
| 1237 | } |
| 1238 | |
| 1239 | element = priv->free_frames.next; |
| 1240 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1241 | return list_entry(element, struct iwl3945_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1244 | 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] | 1245 | { |
| 1246 | memset(frame, 0, sizeof(*frame)); |
| 1247 | list_add(&frame->list, &priv->free_frames); |
| 1248 | } |
| 1249 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1250 | unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1251 | struct ieee80211_hdr *hdr, |
Rami Rosen | 73ec1cc | 2008-12-16 09:37:07 +0200 | [diff] [blame] | 1252 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1253 | { |
| 1254 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1255 | if (!iwl3945_is_associated(priv) || !priv->ibss_beacon || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1256 | ((priv->iw_mode != NL80211_IFTYPE_ADHOC) && |
| 1257 | (priv->iw_mode != NL80211_IFTYPE_AP))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1258 | return 0; |
| 1259 | |
| 1260 | if (priv->ibss_beacon->len > left) |
| 1261 | return 0; |
| 1262 | |
| 1263 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1264 | |
| 1265 | return priv->ibss_beacon->len; |
| 1266 | } |
| 1267 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1268 | static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1269 | { |
| 1270 | u8 i; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1271 | int rate_mask; |
| 1272 | |
| 1273 | /* Set rate mask*/ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1274 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1275 | rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1276 | else |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1277 | rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1278 | |
| 1279 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1280 | i = iwl3945_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1281 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1282 | return iwl3945_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1285 | /* No valid rate was found. Assign the lowest one */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1286 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1287 | return IWL_RATE_1M_PLCP; |
| 1288 | else |
| 1289 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1292 | static int iwl3945_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1293 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1294 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1295 | unsigned int frame_size; |
| 1296 | int rc; |
| 1297 | u8 rate; |
| 1298 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1299 | frame = iwl3945_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1300 | |
| 1301 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1302 | IWL_ERR(priv, "Could not obtain free frame buffer for beacon " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1303 | "command.\n"); |
| 1304 | return -ENOMEM; |
| 1305 | } |
| 1306 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1307 | rate = iwl3945_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1308 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1309 | frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1310 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1311 | rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1312 | &frame->u.cmd[0]); |
| 1313 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1314 | iwl3945_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1315 | |
| 1316 | return rc; |
| 1317 | } |
| 1318 | |
| 1319 | /****************************************************************************** |
| 1320 | * |
| 1321 | * EEPROM related functions |
| 1322 | * |
| 1323 | ******************************************************************************/ |
| 1324 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1325 | static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1326 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1327 | memcpy(mac, priv->eeprom39.mac_address, 6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1330 | /* |
| 1331 | * Clear the OWNER_MSK, to establish driver (instead of uCode running on |
| 1332 | * embedded controller) as EEPROM reader; each read is a series of pulses |
| 1333 | * to/from the EEPROM chip, not a single event, so even reads could conflict |
| 1334 | * if they weren't arbitrated by some ownership mechanism. Here, the driver |
| 1335 | * simply claims ownership, which should be safe when this function is called |
| 1336 | * (i.e. before loading uCode!). |
| 1337 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1338 | static inline int iwl3945_eeprom_acquire_semaphore(struct iwl_priv *priv) |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1339 | { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1340 | _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] | 1341 | return 0; |
| 1342 | } |
| 1343 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1344 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1345 | * iwl3945_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1346 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1347 | * Load the EEPROM contents from adapter into priv->eeprom39 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1348 | * |
| 1349 | * NOTE: This routine uses the non-debug IO access functions. |
| 1350 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1351 | int iwl3945_eeprom_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1352 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1353 | u16 *e = (u16 *)&priv->eeprom39; |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1354 | u32 gp = iwl_read32(priv, CSR_EEPROM_GP); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1355 | int sz = sizeof(priv->eeprom39); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1356 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1357 | u16 addr; |
| 1358 | |
| 1359 | /* The EEPROM structure has several padding buffers within it |
| 1360 | * and when adding new EEPROM maps is subject to programmer errors |
| 1361 | * which may be very difficult to identify without explicitly |
| 1362 | * checking the resulting size of the eeprom map. */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1363 | BUILD_BUG_ON(sizeof(priv->eeprom39) != IWL_EEPROM_IMAGE_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1364 | |
| 1365 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1366 | IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1367 | return -ENOENT; |
| 1368 | } |
| 1369 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1370 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1371 | ret = iwl3945_eeprom_acquire_semaphore(priv); |
| 1372 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1373 | IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1374 | return -ENOENT; |
| 1375 | } |
| 1376 | |
| 1377 | /* eeprom is an array of 16bit values */ |
| 1378 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1379 | u32 r; |
| 1380 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1381 | _iwl_write32(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1382 | CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1383 | _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
| 1384 | ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1385 | CSR_EEPROM_REG_READ_VALID_MSK, |
| 1386 | IWL_EEPROM_ACCESS_TIMEOUT); |
| 1387 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1388 | IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1389 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1390 | } |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1391 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1392 | r = _iwl_read_direct32(priv, CSR_EEPROM_REG); |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1393 | e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | return 0; |
| 1397 | } |
| 1398 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1399 | static void iwl3945_unset_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1400 | { |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1401 | if (priv->shared_virt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1402 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1403 | sizeof(struct iwl3945_shared), |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1404 | priv->shared_virt, |
| 1405 | priv->shared_phys); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1409 | * 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] | 1410 | * |
| 1411 | * return : set the bit for each supported rate insert in ie |
| 1412 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1413 | static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1414 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1415 | { |
| 1416 | u16 ret_rates = 0, bit; |
| 1417 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1418 | u8 *cnt = ie; |
| 1419 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1420 | |
| 1421 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1422 | if (bit & supported_rate) { |
| 1423 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1424 | rates[*cnt] = iwl3945_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1425 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1426 | (*cnt)++; |
| 1427 | (*left)--; |
| 1428 | if ((*left <= 0) || |
| 1429 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1430 | break; |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | return ret_rates; |
| 1435 | } |
| 1436 | |
| 1437 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1438 | * 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] | 1439 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1440 | static u16 iwl3945_fill_probe_req(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1441 | struct ieee80211_mgmt *frame, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 1442 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1443 | { |
| 1444 | int len = 0; |
| 1445 | u8 *pos = NULL; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1446 | u16 active_rates, ret_rates, cck_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1447 | |
| 1448 | /* Make sure there is enough space for the probe request, |
| 1449 | * two mandatory IEs and the data */ |
| 1450 | left -= 24; |
| 1451 | if (left < 0) |
| 1452 | return 0; |
| 1453 | len += 24; |
| 1454 | |
| 1455 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1456 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1457 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1458 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1459 | frame->seq_ctrl = 0; |
| 1460 | |
| 1461 | /* fill in our indirect SSID IE */ |
| 1462 | /* ...next IE... */ |
| 1463 | |
| 1464 | left -= 2; |
| 1465 | if (left < 0) |
| 1466 | return 0; |
| 1467 | len += 2; |
| 1468 | pos = &(frame->u.probe_req.variable[0]); |
| 1469 | *pos++ = WLAN_EID_SSID; |
| 1470 | *pos++ = 0; |
| 1471 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1472 | /* fill in supported rate */ |
| 1473 | /* ...next IE... */ |
| 1474 | left -= 2; |
| 1475 | if (left < 0) |
| 1476 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1477 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1478 | /* ... fill it in... */ |
| 1479 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1480 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1481 | |
| 1482 | priv->active_rate = priv->rates_mask; |
| 1483 | active_rates = priv->active_rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1484 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 1485 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1486 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1487 | ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1488 | priv->active_rate_basic, &left); |
| 1489 | active_rates &= ~ret_rates; |
| 1490 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1491 | ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1492 | priv->active_rate_basic, &left); |
| 1493 | active_rates &= ~ret_rates; |
| 1494 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1495 | len += 2 + *pos; |
| 1496 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1497 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1498 | goto fill_end; |
| 1499 | |
| 1500 | /* fill in supported extended rate */ |
| 1501 | /* ...next IE... */ |
| 1502 | left -= 2; |
| 1503 | if (left < 0) |
| 1504 | return 0; |
| 1505 | /* ... fill it in... */ |
| 1506 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1507 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1508 | iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1509 | priv->active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1510 | if (*pos > 0) |
| 1511 | len += 2 + *pos; |
| 1512 | |
| 1513 | fill_end: |
| 1514 | return (u16)len; |
| 1515 | } |
| 1516 | |
| 1517 | /* |
| 1518 | * QoS support |
| 1519 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1520 | static int iwl3945_send_qos_params_command(struct iwl_priv *priv, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1521 | struct iwl_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1522 | { |
| 1523 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1524 | return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1525 | sizeof(struct iwl_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1528 | static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1529 | { |
| 1530 | unsigned long flags; |
| 1531 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1532 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1533 | return; |
| 1534 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1535 | spin_lock_irqsave(&priv->lock, flags); |
| 1536 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1537 | |
| 1538 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1539 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1540 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1541 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
| 1542 | |
| 1543 | if (priv->qos_data.qos_active) |
| 1544 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1545 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1546 | |
| 1547 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1548 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1549 | if (force || iwl3945_is_associated(priv)) { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1550 | IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1551 | priv->qos_data.qos_active); |
| 1552 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1553 | iwl3945_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1554 | &(priv->qos_data.def_qos_parm)); |
| 1555 | } |
| 1556 | } |
| 1557 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1558 | /* |
| 1559 | * Power management (not Tx power!) functions |
| 1560 | */ |
| 1561 | #define MSEC_TO_USEC 1024 |
| 1562 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1563 | |
| 1564 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 1565 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1566 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 1567 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 1568 | __constant_cpu_to_le32(X1), \ |
| 1569 | __constant_cpu_to_le32(X2), \ |
| 1570 | __constant_cpu_to_le32(X3), \ |
| 1571 | __constant_cpu_to_le32(X4)} |
| 1572 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1573 | /* default power management (not Tx power) table values */ |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1574 | /* for TIM 0-10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1575 | static struct iwl_power_vec_entry range_0[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1576 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1577 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 1578 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 1579 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 1580 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 1581 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 1582 | }; |
| 1583 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1584 | /* for TIM > 10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1585 | static struct iwl_power_vec_entry range_1[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1586 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1587 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 1588 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 1589 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 1590 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 1591 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 1592 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 1593 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 1594 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 1595 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 1596 | }; |
| 1597 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1598 | int iwl3945_power_init_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1599 | { |
| 1600 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1601 | struct iwl3945_power_mgr *pow_data; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1602 | int size = sizeof(struct iwl_power_vec_entry) * IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1603 | u16 pci_pm; |
| 1604 | |
| 1605 | IWL_DEBUG_POWER("Initialize power \n"); |
| 1606 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1607 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1608 | |
| 1609 | memset(pow_data, 0, sizeof(*pow_data)); |
| 1610 | |
| 1611 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 1612 | pow_data->dtim_val = 0xffff; |
| 1613 | |
| 1614 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 1615 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 1616 | |
| 1617 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 1618 | if (rc != 0) |
| 1619 | return 0; |
| 1620 | else { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1621 | struct iwl_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1622 | |
| 1623 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 1624 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1625 | for (i = 0; i < IWL39_POWER_AC; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1626 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 1627 | |
| 1628 | if (pci_pm & 0x1) |
| 1629 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 1630 | else |
| 1631 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 1632 | } |
| 1633 | } |
| 1634 | return rc; |
| 1635 | } |
| 1636 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1637 | static int iwl3945_update_power_cmd(struct iwl_priv *priv, |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1638 | struct iwl_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1639 | { |
| 1640 | int rc = 0, i; |
| 1641 | u8 skip; |
| 1642 | u32 max_sleep = 0; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1643 | struct iwl_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1644 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1645 | struct iwl3945_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1646 | |
| 1647 | if (mode > IWL_POWER_INDEX_5) { |
| 1648 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 1649 | return -1; |
| 1650 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1651 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1652 | |
| 1653 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 1654 | range = &pow_data->pwr_range_0[0]; |
| 1655 | else |
| 1656 | range = &pow_data->pwr_range_1[1]; |
| 1657 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1658 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1659 | |
| 1660 | #ifdef IWL_MAC80211_DISABLE |
| 1661 | if (priv->assoc_network != NULL) { |
| 1662 | unsigned long flags; |
| 1663 | |
| 1664 | period = priv->assoc_network->tim.tim_period; |
| 1665 | } |
| 1666 | #endif /*IWL_MAC80211_DISABLE */ |
| 1667 | skip = range[mode].no_dtim; |
| 1668 | |
| 1669 | if (period == 0) { |
| 1670 | period = 1; |
| 1671 | skip = 0; |
| 1672 | } |
| 1673 | |
| 1674 | if (skip == 0) { |
| 1675 | max_sleep = period; |
| 1676 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1677 | } else { |
| 1678 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 1679 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 1680 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1681 | } |
| 1682 | |
| 1683 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 1684 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 1685 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 1686 | } |
| 1687 | |
| 1688 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 1689 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 1690 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 1691 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 1692 | le32_to_cpu(cmd->sleep_interval[0]), |
| 1693 | le32_to_cpu(cmd->sleep_interval[1]), |
| 1694 | le32_to_cpu(cmd->sleep_interval[2]), |
| 1695 | le32_to_cpu(cmd->sleep_interval[3]), |
| 1696 | le32_to_cpu(cmd->sleep_interval[4])); |
| 1697 | |
| 1698 | return rc; |
| 1699 | } |
| 1700 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1701 | static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1702 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 1703 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1704 | int rc; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1705 | struct iwl_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1706 | |
| 1707 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1708 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1709 | * else user level */ |
| 1710 | switch (mode) { |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1711 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1712 | final_mode = IWL_POWER_INDEX_3; |
| 1713 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1714 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1715 | final_mode = IWL_POWER_MODE_CAM; |
| 1716 | break; |
| 1717 | default: |
| 1718 | final_mode = mode; |
| 1719 | break; |
| 1720 | } |
| 1721 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1722 | iwl3945_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1723 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1724 | /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */ |
| 1725 | rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, |
| 1726 | sizeof(struct iwl3945_powertable_cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1727 | |
| 1728 | if (final_mode == IWL_POWER_MODE_CAM) |
| 1729 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 1730 | else |
| 1731 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 1732 | |
| 1733 | return rc; |
| 1734 | } |
| 1735 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1736 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1737 | * iwl3945_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1738 | * |
| 1739 | * NOTE: priv->mutex is not required before calling this function |
| 1740 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1741 | static int iwl3945_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1742 | { |
| 1743 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1744 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1745 | return 0; |
| 1746 | } |
| 1747 | |
| 1748 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1749 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1750 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 1751 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1752 | queue_work(priv->workqueue, &priv->abort_scan); |
| 1753 | |
| 1754 | } else |
| 1755 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 1756 | |
| 1757 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1758 | } |
| 1759 | |
| 1760 | return 0; |
| 1761 | } |
| 1762 | |
| 1763 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1764 | * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1765 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 1766 | * |
| 1767 | * NOTE: priv->mutex must be held before calling this function |
| 1768 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1769 | 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] | 1770 | { |
| 1771 | unsigned long now = jiffies; |
| 1772 | int ret; |
| 1773 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1774 | ret = iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1775 | if (ret && ms) { |
| 1776 | mutex_unlock(&priv->mutex); |
| 1777 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 1778 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1779 | msleep(1); |
| 1780 | mutex_lock(&priv->mutex); |
| 1781 | |
| 1782 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1783 | } |
| 1784 | |
| 1785 | return ret; |
| 1786 | } |
| 1787 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1788 | #define MAX_UCODE_BEACON_INTERVAL 1024 |
| 1789 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1790 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1791 | static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1792 | { |
| 1793 | u16 new_val = 0; |
| 1794 | u16 beacon_factor = 0; |
| 1795 | |
| 1796 | beacon_factor = |
| 1797 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1798 | / MAX_UCODE_BEACON_INTERVAL; |
| 1799 | new_val = beacon_val / beacon_factor; |
| 1800 | |
| 1801 | return cpu_to_le16(new_val); |
| 1802 | } |
| 1803 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1804 | static void iwl3945_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1805 | { |
| 1806 | u64 interval_tm_unit; |
| 1807 | u64 tsf, result; |
| 1808 | unsigned long flags; |
| 1809 | struct ieee80211_conf *conf = NULL; |
| 1810 | u16 beacon_int = 0; |
| 1811 | |
| 1812 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1813 | |
| 1814 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1815 | priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1816 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1817 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1818 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1819 | |
| 1820 | beacon_int = priv->beacon_int; |
| 1821 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1822 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1823 | if (priv->iw_mode == NL80211_IFTYPE_STATION) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1824 | if (beacon_int == 0) { |
| 1825 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1826 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1827 | } else { |
| 1828 | priv->rxon_timing.beacon_interval = |
| 1829 | cpu_to_le16(beacon_int); |
| 1830 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1831 | iwl3945_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1832 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1833 | } |
| 1834 | |
| 1835 | priv->rxon_timing.atim_window = 0; |
| 1836 | } else { |
| 1837 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1838 | iwl3945_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1839 | /* TODO: we need to get atim_window from upper stack |
| 1840 | * for now we set to 0 */ |
| 1841 | priv->rxon_timing.atim_window = 0; |
| 1842 | } |
| 1843 | |
| 1844 | interval_tm_unit = |
| 1845 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1846 | result = do_div(tsf, interval_tm_unit); |
| 1847 | priv->rxon_timing.beacon_init_val = |
| 1848 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1849 | |
| 1850 | IWL_DEBUG_ASSOC |
| 1851 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1852 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1853 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1854 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1855 | } |
| 1856 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1857 | static int iwl3945_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1858 | { |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 1859 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1860 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1861 | return -EIO; |
| 1862 | } |
| 1863 | |
| 1864 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1865 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1866 | return -EAGAIN; |
| 1867 | } |
| 1868 | |
| 1869 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1870 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1871 | "Queuing.\n"); |
| 1872 | return -EAGAIN; |
| 1873 | } |
| 1874 | |
| 1875 | IWL_DEBUG_INFO("Starting scan...\n"); |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 1876 | if (priv->cfg->sku & IWL_SKU_G) |
| 1877 | priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ); |
| 1878 | if (priv->cfg->sku & IWL_SKU_A) |
| 1879 | priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1880 | set_bit(STATUS_SCANNING, &priv->status); |
| 1881 | priv->scan_start = jiffies; |
| 1882 | priv->scan_pass_start = priv->scan_start; |
| 1883 | |
| 1884 | queue_work(priv->workqueue, &priv->request_scan); |
| 1885 | |
| 1886 | return 0; |
| 1887 | } |
| 1888 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1889 | 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] | 1890 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1891 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1892 | |
| 1893 | if (hw_decrypt) |
| 1894 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 1895 | else |
| 1896 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 1897 | |
| 1898 | return 0; |
| 1899 | } |
| 1900 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1901 | static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1902 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1903 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1904 | if (band == IEEE80211_BAND_5GHZ) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1905 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1906 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1907 | | RXON_FLG_CCK_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1908 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1909 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1910 | /* Copied from iwl3945_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1911 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1912 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1913 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1914 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1915 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1916 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1917 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1918 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1919 | priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1920 | priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1921 | priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1926 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1927 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1928 | static void iwl3945_connection_init_rx_config(struct iwl_priv *priv, |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1929 | int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1930 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 1931 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1932 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1933 | memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1934 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1935 | switch (mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1936 | case NL80211_IFTYPE_AP: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1937 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1938 | break; |
| 1939 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1940 | case NL80211_IFTYPE_STATION: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1941 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1942 | priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1943 | break; |
| 1944 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1945 | case NL80211_IFTYPE_ADHOC: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1946 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1947 | priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1948 | priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1949 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1950 | break; |
| 1951 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1952 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1953 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1954 | priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1955 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1956 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1957 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1958 | IWL_ERR(priv, "Unsupported interface type %d\n", mode); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1959 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | #if 0 |
| 1963 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1964 | * that */ |
| 1965 | if (!hw_to_local(priv->hw)->short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1966 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1967 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1968 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1969 | #endif |
| 1970 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1971 | ch_info = iwl3945_get_channel_info(priv, priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1972 | le16_to_cpu(priv->active39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1973 | |
| 1974 | if (!ch_info) |
| 1975 | ch_info = &priv->channel_info[0]; |
| 1976 | |
| 1977 | /* |
| 1978 | * in some case A channels are all non IBSS |
| 1979 | * in this case force B/G channel |
| 1980 | */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1981 | if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1982 | ch_info = &priv->channel_info[0]; |
| 1983 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1984 | priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1985 | if (is_channel_a_band(ch_info)) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1986 | priv->band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1987 | else |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1988 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1989 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1990 | iwl3945_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1991 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1992 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1993 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1994 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1995 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1996 | } |
| 1997 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1998 | static int iwl3945_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1999 | { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2000 | if (mode == NL80211_IFTYPE_ADHOC) { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2001 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2002 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2003 | ch_info = iwl3945_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2004 | priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2005 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2006 | |
| 2007 | if (!ch_info || !is_channel_ibss(ch_info)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2008 | IWL_ERR(priv, "channel %d not IBSS channel\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2009 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2010 | return -EINVAL; |
| 2011 | } |
| 2012 | } |
| 2013 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 2014 | iwl3945_connection_init_rx_config(priv, mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2015 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2016 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2017 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2018 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2019 | /* don't commit rxon if rf-kill is on*/ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2020 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2021 | return -EAGAIN; |
| 2022 | |
| 2023 | cancel_delayed_work(&priv->scan_check); |
| 2024 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2025 | IWL_WARN(priv, "Aborted scan still in progress after 100ms\n"); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2026 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2027 | return -EAGAIN; |
| 2028 | } |
| 2029 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2030 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2031 | |
| 2032 | return 0; |
| 2033 | } |
| 2034 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2035 | static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2036 | struct ieee80211_tx_info *info, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2037 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2038 | struct sk_buff *skb_frag, |
| 2039 | int last_frag) |
| 2040 | { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2041 | 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] | 2042 | struct iwl3945_hw_key *keyinfo = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2043 | &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2044 | |
| 2045 | switch (keyinfo->alg) { |
| 2046 | case ALG_CCMP: |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2047 | tx->sec_ctl = TX_CMD_SEC_CCM; |
| 2048 | memcpy(tx->key, keyinfo->key, keyinfo->keylen); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2049 | IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2050 | break; |
| 2051 | |
| 2052 | case ALG_TKIP: |
| 2053 | #if 0 |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2054 | tx->sec_ctl = TX_CMD_SEC_TKIP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2055 | |
| 2056 | if (last_frag) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2057 | memcpy(tx->tkip_mic.byte, skb_frag->tail - 8, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2058 | 8); |
| 2059 | else |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2060 | memset(tx->tkip_mic.byte, 0, 8); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2061 | #endif |
| 2062 | break; |
| 2063 | |
| 2064 | case ALG_WEP: |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2065 | tx->sec_ctl = TX_CMD_SEC_WEP | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2066 | (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] | 2067 | |
| 2068 | if (keyinfo->keylen == 13) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2069 | tx->sec_ctl |= TX_CMD_SEC_KEY128; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2070 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2071 | memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2072 | |
| 2073 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2074 | "with key %d\n", info->control.hw_key->hw_key_idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2075 | break; |
| 2076 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2077 | default: |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2078 | IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2079 | break; |
| 2080 | } |
| 2081 | } |
| 2082 | |
| 2083 | /* |
| 2084 | * handle build REPLY_TX command notification. |
| 2085 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2086 | static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2087 | struct iwl_cmd *cmd, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2088 | struct ieee80211_tx_info *info, |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2089 | struct ieee80211_hdr *hdr, u8 std_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2090 | { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2091 | struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload; |
| 2092 | __le32 tx_flags = tx->tx_flags; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2093 | __le16 fc = hdr->frame_control; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2094 | u8 rc_flags = info->control.rates[0].flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2095 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2096 | tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2097 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2098 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2099 | if (ieee80211_is_mgmt(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2100 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2101 | if (ieee80211_is_probe_resp(fc) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2102 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2103 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2104 | } else { |
| 2105 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2106 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2107 | } |
| 2108 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2109 | tx->sta_id = std_id; |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2110 | if (ieee80211_has_morefrags(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2111 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2112 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2113 | if (ieee80211_is_data_qos(fc)) { |
| 2114 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2115 | tx->tid_tspec = qc[0] & 0xf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2116 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2117 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2118 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2119 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2120 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2121 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2122 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2123 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2124 | } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2125 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2126 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2127 | } |
| 2128 | |
| 2129 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2130 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2131 | |
| 2132 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2133 | if (ieee80211_is_mgmt(fc)) { |
| 2134 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2135 | tx->timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2136 | else |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2137 | tx->timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2138 | } else { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2139 | tx->timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2140 | #ifdef CONFIG_IWL3945_LEDS |
| 2141 | priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len); |
| 2142 | #endif |
| 2143 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2144 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2145 | tx->driver_txop = 0; |
| 2146 | tx->tx_flags = tx_flags; |
| 2147 | tx->next_frame_len = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2150 | /** |
| 2151 | * iwl3945_get_sta_id - Find station's index within station table |
| 2152 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2153 | 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] | 2154 | { |
| 2155 | int sta_id; |
| 2156 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2157 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2158 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2159 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2160 | is_multicast_ether_addr(hdr->addr1)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2161 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2162 | |
| 2163 | switch (priv->iw_mode) { |
| 2164 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2165 | /* If we are a client station in a BSS network, use the special |
| 2166 | * AP station entry (that's the only station we communicate with) */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2167 | case NL80211_IFTYPE_STATION: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2168 | return IWL_AP_ID; |
| 2169 | |
| 2170 | /* If we are an AP, then find the station, or use BCAST */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2171 | case NL80211_IFTYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2172 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2173 | if (sta_id != IWL_INVALID_STATION) |
| 2174 | return sta_id; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2175 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2176 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2177 | /* If this frame is going out to an IBSS network, find the station, |
| 2178 | * or create a new station table entry */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2179 | case NL80211_IFTYPE_ADHOC: { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2180 | /* Create new station table entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2181 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2182 | if (sta_id != IWL_INVALID_STATION) |
| 2183 | return sta_id; |
| 2184 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2185 | sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2186 | |
| 2187 | if (sta_id != IWL_INVALID_STATION) |
| 2188 | return sta_id; |
| 2189 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2190 | IWL_DEBUG_DROP("Station %pM not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2191 | "Defaulting to broadcast...\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2192 | hdr->addr1); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2193 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2194 | return priv->hw_params.bcast_sta_id; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2195 | } |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2196 | /* If we are in monitor mode, use BCAST. This is required for |
| 2197 | * packet injection. */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2198 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2199 | return priv->hw_params.bcast_sta_id; |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2200 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2201 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2202 | IWL_WARN(priv, "Unknown mode of operation: %d\n", |
| 2203 | priv->iw_mode); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2204 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | /* |
| 2209 | * start REPLY_TX command process |
| 2210 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2211 | 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] | 2212 | { |
| 2213 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2214 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2215 | struct iwl3945_tfd *tfd; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2216 | struct iwl3945_tx_cmd *tx; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2217 | struct iwl_tx_queue *txq = NULL; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2218 | struct iwl_queue *q = NULL; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2219 | struct iwl_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2220 | dma_addr_t phys_addr; |
| 2221 | dma_addr_t txcmd_phys; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2222 | int txq_id = skb_get_queue_mapping(skb); |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2223 | u16 len, idx, len_org, hdr_len; |
| 2224 | u8 id; |
| 2225 | u8 unicast; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2226 | u8 sta_id; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2227 | u8 tid = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2228 | u16 seq_number = 0; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2229 | __le16 fc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2230 | u8 wait_write_ptr = 0; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2231 | u8 *qc = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2232 | unsigned long flags; |
| 2233 | int rc; |
| 2234 | |
| 2235 | spin_lock_irqsave(&priv->lock, flags); |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2236 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2237 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2238 | goto drop_unlock; |
| 2239 | } |
| 2240 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2241 | 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] | 2242 | IWL_ERR(priv, "ERROR: No TX rate available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2243 | goto drop_unlock; |
| 2244 | } |
| 2245 | |
| 2246 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2247 | id = 0; |
| 2248 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2249 | fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2250 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2251 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2252 | if (ieee80211_is_auth(fc)) |
| 2253 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2254 | else if (ieee80211_is_assoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2255 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2256 | else if (ieee80211_is_reassoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2257 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2258 | #endif |
| 2259 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2260 | /* drop all data frame if we are not associated */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2261 | if (ieee80211_is_data(fc) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2262 | (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2263 | (!iwl3945_is_associated(priv) || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2264 | ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2265 | IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2266 | goto drop_unlock; |
| 2267 | } |
| 2268 | |
| 2269 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2270 | |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2271 | hdr_len = ieee80211_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2272 | |
| 2273 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2274 | sta_id = iwl3945_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2275 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2276 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n", |
| 2277 | hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2278 | goto drop; |
| 2279 | } |
| 2280 | |
| 2281 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2282 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2283 | if (ieee80211_is_data_qos(fc)) { |
| 2284 | qc = ieee80211_get_qos_ctl(hdr); |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2285 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2286 | seq_number = priv->stations_39[sta_id].tid[tid].seq_number & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2287 | IEEE80211_SCTL_SEQ; |
| 2288 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2289 | (hdr->seq_ctrl & |
| 2290 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2291 | seq_number += 0x10; |
| 2292 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2293 | |
| 2294 | /* Descriptor for chosen Tx queue */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2295 | txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2296 | q = &txq->q; |
| 2297 | |
| 2298 | spin_lock_irqsave(&priv->lock, flags); |
| 2299 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2300 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2301 | tfd = &txq->tfds39[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2302 | memset(tfd, 0, sizeof(*tfd)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2303 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2304 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2305 | /* Set up driver data for this TFD */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2306 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2307 | txq->txb[q->write_ptr].skb[0] = skb; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2308 | |
| 2309 | /* Init first empty entry in queue's array of Tx/cmd buffers */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2310 | out_cmd = txq->cmd[idx]; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2311 | tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2312 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2313 | memset(tx, 0, sizeof(*tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2314 | |
| 2315 | /* |
| 2316 | * Set up the Tx-command (not MAC!) header. |
| 2317 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2318 | * after Tx, uCode's Tx response will return this value so driver can |
| 2319 | * locate the frame within the tx queue and do post-tx processing. |
| 2320 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2321 | out_cmd->hdr.cmd = REPLY_TX; |
| 2322 | 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] | 2323 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2324 | |
| 2325 | /* Copy MAC header from skb into command buffer */ |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2326 | memcpy(tx->hdr, hdr, hdr_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2327 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2328 | /* |
| 2329 | * Use the first empty entry in this queue's command buffer array |
| 2330 | * to contain the Tx command and MAC header concatenated together |
| 2331 | * (payload data will be in another buffer). |
| 2332 | * Size of this varies, due to varying MAC header length. |
| 2333 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2334 | * of the MAC header (device reads on dword boundaries). |
| 2335 | * We'll tell device about this padding later. |
| 2336 | */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2337 | len = sizeof(struct iwl3945_tx_cmd) + |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2338 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2339 | |
| 2340 | len_org = len; |
| 2341 | len = (len + 3) & ~3; |
| 2342 | |
| 2343 | if (len_org != len) |
| 2344 | len_org = 1; |
| 2345 | else |
| 2346 | len_org = 0; |
| 2347 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2348 | /* Physical address of this Tx command's header (not MAC header!), |
| 2349 | * within command buffer array. */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2350 | txcmd_phys = pci_map_single(priv->pci_dev, |
| 2351 | out_cmd, sizeof(struct iwl_cmd), |
| 2352 | PCI_DMA_TODEVICE); |
| 2353 | pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys); |
| 2354 | pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd)); |
| 2355 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2356 | * first entry */ |
| 2357 | txcmd_phys += offsetof(struct iwl_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2358 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2359 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2360 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2361 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2362 | |
Johannes Berg | d0f0980 | 2008-07-29 11:32:07 +0200 | [diff] [blame] | 2363 | if (info->control.hw_key) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2364 | iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2365 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2366 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2367 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2368 | len = skb->len - hdr_len; |
| 2369 | if (len) { |
| 2370 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2371 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2372 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2375 | if (!len) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2376 | /* If there is no payload, then we use only one Tx buffer */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2377 | tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2378 | else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2379 | /* Else use 2 buffers. |
| 2380 | * Tell 3945 about any padding after MAC header */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2381 | tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(2) | |
| 2382 | TFD_CTL_PAD_SET(U32_PAD(len))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2383 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2384 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2385 | len = (u16)skb->len; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2386 | tx->len = cpu_to_le16(len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2387 | |
| 2388 | /* TODO need this for burst mode later on */ |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2389 | iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2390 | |
| 2391 | /* set is_hcca to 0; it probably will never be implemented */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2392 | 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] | 2393 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2394 | tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; |
| 2395 | tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2396 | |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2397 | if (!ieee80211_has_morefrags(hdr->frame_control)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2398 | txq->need_update = 1; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 2399 | if (qc) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2400 | priv->stations_39[sta_id].tid[tid].seq_number = seq_number; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2401 | } else { |
| 2402 | wait_write_ptr = 1; |
| 2403 | txq->need_update = 0; |
| 2404 | } |
| 2405 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2406 | iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2407 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2408 | iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr, |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2409 | ieee80211_hdrlen(fc)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2410 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2411 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2412 | 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] | 2413 | rc = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2414 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2415 | |
| 2416 | if (rc) |
| 2417 | return rc; |
| 2418 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2419 | if ((iwl_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2420 | && priv->mac80211_registered) { |
| 2421 | if (wait_write_ptr) { |
| 2422 | spin_lock_irqsave(&priv->lock, flags); |
| 2423 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2424 | iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2425 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2426 | } |
| 2427 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 2428 | ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | return 0; |
| 2432 | |
| 2433 | drop_unlock: |
| 2434 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2435 | drop: |
| 2436 | return -1; |
| 2437 | } |
| 2438 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2439 | static void iwl3945_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2440 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2441 | const struct ieee80211_supported_band *sband = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2442 | struct ieee80211_rate *rate; |
| 2443 | int i; |
| 2444 | |
Kolekar, Abhijeet | cbba18c | 2008-12-19 10:37:42 +0800 | [diff] [blame] | 2445 | sband = iwl_get_hw_mode(priv, priv->band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2446 | if (!sband) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2447 | 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] | 2448 | return; |
| 2449 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2450 | |
| 2451 | priv->active_rate = 0; |
| 2452 | priv->active_rate_basic = 0; |
| 2453 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2454 | IWL_DEBUG_RATE("Setting rates for %s GHz\n", |
| 2455 | sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2456 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2457 | for (i = 0; i < sband->n_bitrates; i++) { |
| 2458 | rate = &sband->bitrates[i]; |
| 2459 | if ((rate->hw_value < IWL_RATE_COUNT) && |
| 2460 | !(rate->flags & IEEE80211_CHAN_DISABLED)) { |
| 2461 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n", |
| 2462 | rate->hw_value, iwl3945_rates[rate->hw_value].plcp); |
| 2463 | priv->active_rate |= (1 << rate->hw_value); |
| 2464 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2468 | priv->active_rate, priv->active_rate_basic); |
| 2469 | |
| 2470 | /* |
| 2471 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2472 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2473 | * OFDM |
| 2474 | */ |
| 2475 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2476 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2477 | ((priv->active_rate_basic & |
| 2478 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2479 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2480 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2481 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2482 | |
| 2483 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2484 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2485 | ((priv->active_rate_basic & |
| 2486 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2487 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2488 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2489 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2490 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2491 | } |
| 2492 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2493 | 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] | 2494 | { |
| 2495 | unsigned long flags; |
| 2496 | |
| 2497 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2498 | return; |
| 2499 | |
| 2500 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2501 | disable_radio ? "OFF" : "ON"); |
| 2502 | |
| 2503 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2504 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2505 | /* FIXME: This is a workaround for AP */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2506 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2507 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2508 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2509 | CSR_UCODE_SW_BIT_RFKILL); |
| 2510 | spin_unlock_irqrestore(&priv->lock, flags); |
Samuel Ortiz | c496294 | 2008-12-22 11:31:18 +0800 | [diff] [blame] | 2511 | iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2512 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2513 | } |
| 2514 | return; |
| 2515 | } |
| 2516 | |
| 2517 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2518 | 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] | 2519 | |
| 2520 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2521 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2522 | |
| 2523 | /* wake up ucode */ |
| 2524 | msleep(10); |
| 2525 | |
| 2526 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2527 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2528 | if (!iwl_grab_nic_access(priv)) |
| 2529 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2530 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2531 | |
| 2532 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2533 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2534 | "disabled by HW switch\n"); |
| 2535 | return; |
| 2536 | } |
| 2537 | |
Zhu Yi | 808e72a | 2008-06-12 09:47:17 +0800 | [diff] [blame] | 2538 | if (priv->is_open) |
| 2539 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2540 | return; |
| 2541 | } |
| 2542 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2543 | 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] | 2544 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 2545 | { |
| 2546 | u16 fc = |
| 2547 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 2548 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2549 | if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2550 | return; |
| 2551 | |
| 2552 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 2553 | return; |
| 2554 | |
| 2555 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 2556 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2557 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2558 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2559 | RX_RES_STATUS_BAD_ICV_MIC) |
| 2560 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 2561 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 2562 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2563 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2564 | RX_RES_STATUS_DECRYPT_OK) { |
| 2565 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 2566 | stats->flag |= RX_FLAG_DECRYPTED; |
| 2567 | } |
| 2568 | break; |
| 2569 | |
| 2570 | default: |
| 2571 | break; |
| 2572 | } |
| 2573 | } |
| 2574 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2575 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2576 | |
| 2577 | #include "iwl-spectrum.h" |
| 2578 | |
| 2579 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 2580 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 2581 | #define TIME_UNIT 1024 |
| 2582 | |
| 2583 | /* |
| 2584 | * extended beacon time format |
| 2585 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 2586 | * the high 1 byte is the beacon counts |
| 2587 | * the lower 3 bytes is the time in usec within one beacon interval |
| 2588 | */ |
| 2589 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2590 | static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2591 | { |
| 2592 | u32 quot; |
| 2593 | u32 rem; |
| 2594 | u32 interval = beacon_interval * 1024; |
| 2595 | |
| 2596 | if (!interval || !usec) |
| 2597 | return 0; |
| 2598 | |
| 2599 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 2600 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 2601 | |
| 2602 | return (quot << 24) + rem; |
| 2603 | } |
| 2604 | |
| 2605 | /* base is usually what we get from ucode with each received frame, |
| 2606 | * the same as HW timer counter counting down |
| 2607 | */ |
| 2608 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2609 | 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] | 2610 | { |
| 2611 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 2612 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 2613 | u32 interval = beacon_interval * TIME_UNIT; |
| 2614 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 2615 | (addon & BEACON_TIME_MASK_HIGH); |
| 2616 | |
| 2617 | if (base_low > addon_low) |
| 2618 | res += base_low - addon_low; |
| 2619 | else if (base_low < addon_low) { |
| 2620 | res += interval + base_low - addon_low; |
| 2621 | res += (1 << 24); |
| 2622 | } else |
| 2623 | res += (1 << 24); |
| 2624 | |
| 2625 | return cpu_to_le32(res); |
| 2626 | } |
| 2627 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2628 | static int iwl3945_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2629 | struct ieee80211_measurement_params *params, |
| 2630 | u8 type) |
| 2631 | { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2632 | struct iwl_spectrum_cmd spectrum; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2633 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2634 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2635 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 2636 | .data = (void *)&spectrum, |
| 2637 | .meta.flags = CMD_WANT_SKB, |
| 2638 | }; |
| 2639 | u32 add_time = le64_to_cpu(params->start_time); |
| 2640 | int rc; |
| 2641 | int spectrum_resp_status; |
| 2642 | int duration = le16_to_cpu(params->duration); |
| 2643 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2644 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2645 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2646 | iwl3945_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2647 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 2648 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2649 | |
| 2650 | memset(&spectrum, 0, sizeof(spectrum)); |
| 2651 | |
| 2652 | spectrum.channel_count = cpu_to_le16(1); |
| 2653 | spectrum.flags = |
| 2654 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 2655 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 2656 | cmd.len = sizeof(spectrum); |
| 2657 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 2658 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2659 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2660 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2661 | iwl3945_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2662 | add_time, |
| 2663 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2664 | else |
| 2665 | spectrum.start_time = 0; |
| 2666 | |
| 2667 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 2668 | spectrum.channels[0].channel = params->channel; |
| 2669 | spectrum.channels[0].type = type; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2670 | if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2671 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 2672 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 2673 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2674 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2675 | if (rc) |
| 2676 | return rc; |
| 2677 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2678 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2679 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2680 | IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2681 | rc = -EIO; |
| 2682 | } |
| 2683 | |
| 2684 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 2685 | switch (spectrum_resp_status) { |
| 2686 | case 0: /* Command will be handled */ |
| 2687 | if (res->u.spectrum.id != 0xff) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2688 | IWL_DEBUG_INFO("Replaced existing measurement: %d\n", |
| 2689 | res->u.spectrum.id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2690 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 2691 | } |
| 2692 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 2693 | rc = 0; |
| 2694 | break; |
| 2695 | |
| 2696 | case 1: /* Command will not be handled */ |
| 2697 | rc = -EAGAIN; |
| 2698 | break; |
| 2699 | } |
| 2700 | |
| 2701 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 2702 | |
| 2703 | return rc; |
| 2704 | } |
| 2705 | #endif |
| 2706 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2707 | static void iwl3945_rx_reply_alive(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2708 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2709 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2710 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 2711 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2712 | struct delayed_work *pwork; |
| 2713 | |
| 2714 | palive = &pkt->u.alive_frame; |
| 2715 | |
| 2716 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 2717 | "0x%01X 0x%01X\n", |
| 2718 | palive->is_valid, palive->ver_type, |
| 2719 | palive->ver_subtype); |
| 2720 | |
| 2721 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 2722 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2723 | memcpy(&priv->card_alive_init, &pkt->u.alive_frame, |
| 2724 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2725 | pwork = &priv->init_alive_start; |
| 2726 | } else { |
| 2727 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2728 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2729 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2730 | pwork = &priv->alive_start; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2731 | iwl3945_disable_events(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | /* We delay the ALIVE response by 5ms to |
| 2735 | * give the HW RF Kill time to activate... */ |
| 2736 | if (palive->is_valid == UCODE_VALID_OK) |
| 2737 | queue_delayed_work(priv->workqueue, pwork, |
| 2738 | msecs_to_jiffies(5)); |
| 2739 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2740 | IWL_WARN(priv, "uCode did not respond OK.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2743 | static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2744 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2745 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2746 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2747 | |
| 2748 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 2749 | return; |
| 2750 | } |
| 2751 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2752 | static void iwl3945_rx_reply_error(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2753 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2754 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2755 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2756 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2757 | IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2758 | "seq 0x%04X ser 0x%08X\n", |
| 2759 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 2760 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 2761 | pkt->u.err_resp.cmd_id, |
| 2762 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 2763 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 2764 | } |
| 2765 | |
| 2766 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2767 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2768 | 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] | 2769 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2770 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2771 | struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2772 | struct iwl_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2773 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 2774 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 2775 | rxon->channel = csa->channel; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2776 | priv->staging39_rxon.channel = csa->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2779 | static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2780 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2781 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2782 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2783 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2784 | struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2785 | |
| 2786 | if (!report->state) { |
| 2787 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 2788 | "Spectrum Measure Notification: Start\n"); |
| 2789 | return; |
| 2790 | } |
| 2791 | |
| 2792 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2793 | priv->measurement_status |= MEASUREMENT_READY; |
| 2794 | #endif |
| 2795 | } |
| 2796 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2797 | static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2798 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2799 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2800 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2801 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2802 | struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2803 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2804 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2805 | #endif |
| 2806 | } |
| 2807 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2808 | static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2809 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2810 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2811 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2812 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2813 | "notification for %s:\n", |
| 2814 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2815 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, |
| 2816 | le32_to_cpu(pkt->len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2819 | static void iwl3945_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2820 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2821 | struct iwl_priv *priv = |
| 2822 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2823 | struct sk_buff *beacon; |
| 2824 | |
| 2825 | /* 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] | 2826 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2827 | |
| 2828 | if (!beacon) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2829 | IWL_ERR(priv, "update beacon failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2830 | return; |
| 2831 | } |
| 2832 | |
| 2833 | mutex_lock(&priv->mutex); |
| 2834 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2835 | if (priv->ibss_beacon) |
| 2836 | dev_kfree_skb(priv->ibss_beacon); |
| 2837 | |
| 2838 | priv->ibss_beacon = beacon; |
| 2839 | mutex_unlock(&priv->mutex); |
| 2840 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2841 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2842 | } |
| 2843 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2844 | static void iwl3945_rx_beacon_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2845 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2846 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2847 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2848 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2849 | struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2850 | u8 rate = beacon->beacon_notify_hdr.rate; |
| 2851 | |
| 2852 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2853 | "tsf %d %d rate %d\n", |
| 2854 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2855 | beacon->beacon_notify_hdr.failure_frame, |
| 2856 | le32_to_cpu(beacon->ibss_mgr_status), |
| 2857 | le32_to_cpu(beacon->high_tsf), |
| 2858 | le32_to_cpu(beacon->low_tsf), rate); |
| 2859 | #endif |
| 2860 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2861 | if ((priv->iw_mode == NL80211_IFTYPE_AP) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2862 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 2863 | queue_work(priv->workqueue, &priv->beacon_update); |
| 2864 | } |
| 2865 | |
| 2866 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2867 | static void iwl3945_rx_reply_scan(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2868 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2869 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2870 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2871 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2872 | struct iwl_scanreq_notification *notif = |
| 2873 | (struct iwl_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2874 | |
| 2875 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 2876 | #endif |
| 2877 | } |
| 2878 | |
| 2879 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2880 | static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2881 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2882 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2883 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2884 | struct iwl_scanstart_notification *notif = |
| 2885 | (struct iwl_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2886 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 2887 | IWL_DEBUG_SCAN("Scan start: " |
| 2888 | "%d [802.11%s] " |
| 2889 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 2890 | notif->channel, |
| 2891 | notif->band ? "bg" : "a", |
| 2892 | notif->tsf_high, |
| 2893 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 2894 | } |
| 2895 | |
| 2896 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2897 | static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2898 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2899 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2900 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2901 | struct iwl_scanresults_notification *notif = |
| 2902 | (struct iwl_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2903 | |
| 2904 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 2905 | "%d [802.11%s] " |
| 2906 | "(TSF: 0x%08X:%08X) - %d " |
| 2907 | "elapsed=%lu usec (%dms since last)\n", |
| 2908 | notif->channel, |
| 2909 | notif->band ? "bg" : "a", |
| 2910 | le32_to_cpu(notif->tsf_high), |
| 2911 | le32_to_cpu(notif->tsf_low), |
| 2912 | le32_to_cpu(notif->statistics[0]), |
| 2913 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 2914 | jiffies_to_msecs(elapsed_jiffies |
| 2915 | (priv->last_scan_jiffies, jiffies))); |
| 2916 | |
| 2917 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2918 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2922 | static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2923 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2924 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2925 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2926 | struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2927 | |
| 2928 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 2929 | scan_notif->scanned_channels, |
| 2930 | scan_notif->tsf_low, |
| 2931 | scan_notif->tsf_high, scan_notif->status); |
| 2932 | |
| 2933 | /* The HW is no longer scanning */ |
| 2934 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 2935 | |
| 2936 | /* The scan completion notification came in, so kill that timer... */ |
| 2937 | cancel_delayed_work(&priv->scan_check); |
| 2938 | |
| 2939 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 2940 | (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ? |
| 2941 | "2.4" : "5.2", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2942 | jiffies_to_msecs(elapsed_jiffies |
| 2943 | (priv->scan_pass_start, jiffies))); |
| 2944 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 2945 | /* Remove this scanned band from the list of pending |
| 2946 | * bands to scan, band G precedes A in order of scanning |
| 2947 | * as seen in iwl3945_bg_request_scan */ |
| 2948 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) |
| 2949 | priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ); |
| 2950 | else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) |
| 2951 | priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2952 | |
| 2953 | /* If a request to abort was given, or the scan did not succeed |
| 2954 | * then we reset the scan state machine and terminate, |
| 2955 | * re-queuing another scan if one has been requested */ |
| 2956 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2957 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 2958 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2959 | } else { |
| 2960 | /* If there are more bands on this scan pass reschedule */ |
| 2961 | if (priv->scan_bands > 0) |
| 2962 | goto reschedule; |
| 2963 | } |
| 2964 | |
| 2965 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2966 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2967 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 2968 | |
| 2969 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2970 | |
| 2971 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 2972 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 2973 | |
| 2974 | queue_work(priv->workqueue, &priv->scan_completed); |
| 2975 | |
| 2976 | return; |
| 2977 | |
| 2978 | reschedule: |
| 2979 | priv->scan_pass_start = jiffies; |
| 2980 | queue_work(priv->workqueue, &priv->request_scan); |
| 2981 | } |
| 2982 | |
| 2983 | /* Handle notification from uCode that card's power state is changing |
| 2984 | * due to software, hardware, or critical temperature RFKILL */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2985 | static void iwl3945_rx_card_state_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2986 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2987 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2988 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2989 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 2990 | unsigned long status = priv->status; |
| 2991 | |
| 2992 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 2993 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 2994 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 2995 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2996 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2997 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 2998 | |
| 2999 | if (flags & HW_CARD_DISABLED) |
| 3000 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3001 | else |
| 3002 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3003 | |
| 3004 | |
| 3005 | if (flags & SW_CARD_DISABLED) |
| 3006 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3007 | else |
| 3008 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3009 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3010 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3011 | |
| 3012 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 3013 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 3014 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 3015 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 3016 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3017 | else |
| 3018 | wake_up_interruptible(&priv->wait_command_queue); |
| 3019 | } |
| 3020 | |
| 3021 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3022 | * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3023 | * |
| 3024 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3025 | * to the host. |
| 3026 | * |
| 3027 | * This function chains into the hardware specific files for them to setup |
| 3028 | * any hardware specific handlers as well. |
| 3029 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3030 | static void iwl3945_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3031 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3032 | priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive; |
| 3033 | priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta; |
| 3034 | priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error; |
| 3035 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3036 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3037 | iwl3945_rx_spectrum_measure_notif; |
| 3038 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3039 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3040 | iwl3945_rx_pm_debug_statistics_notif; |
| 3041 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3042 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3043 | /* |
| 3044 | * The same handler is used for both the REPLY to a discrete |
| 3045 | * statistics request from the host as well as for the periodic |
| 3046 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3047 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3048 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics; |
| 3049 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3050 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3051 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan; |
| 3052 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3053 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3054 | iwl3945_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3055 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3056 | iwl3945_rx_scan_complete_notif; |
| 3057 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3058 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3059 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3060 | iwl3945_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | /** |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3064 | * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries |
| 3065 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3066 | * need to be reclaimed. |
| 3067 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3068 | static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3069 | int txq_id, int index) |
| 3070 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3071 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 3072 | struct iwl_queue *q = &txq->q; |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3073 | int nfreed = 0; |
| 3074 | |
Winkler, Tomas | 625a381 | 2009-01-08 10:19:55 -0800 | [diff] [blame^] | 3075 | if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3076 | 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] | 3077 | "is out of range [0-%d] %d %d.\n", txq_id, |
| 3078 | index, q->n_bd, q->write_ptr, q->read_ptr); |
| 3079 | return; |
| 3080 | } |
| 3081 | |
| 3082 | for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index; |
| 3083 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
| 3084 | if (nfreed > 1) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3085 | IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3086 | q->write_ptr, q->read_ptr); |
| 3087 | queue_work(priv->workqueue, &priv->restart); |
| 3088 | break; |
| 3089 | } |
| 3090 | nfreed++; |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | |
| 3095 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3096 | * 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] | 3097 | * @rxb: Rx buffer to reclaim |
| 3098 | * |
| 3099 | * If an Rx buffer has an async callback associated with it the callback |
| 3100 | * will be executed. The attached skb (if present) will only be freed |
| 3101 | * if the callback returns 1 |
| 3102 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3103 | static void iwl3945_tx_cmd_complete(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3104 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3105 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3106 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3107 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3108 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3109 | int index = SEQ_TO_INDEX(sequence); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 3110 | int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3111 | int cmd_index; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 3112 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3113 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3114 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3115 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3116 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3117 | cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3118 | |
| 3119 | /* Input error checking is done when commands are added to queue. */ |
| 3120 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3121 | cmd->meta.source->u.skb = rxb->skb; |
| 3122 | rxb->skb = NULL; |
| 3123 | } else if (cmd->meta.u.callback && |
| 3124 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3125 | rxb->skb = NULL; |
| 3126 | |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3127 | iwl3945_cmd_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3128 | |
| 3129 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3130 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3131 | wake_up_interruptible(&priv->wait_command_queue); |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | /************************** RX-FUNCTIONS ****************************/ |
| 3136 | /* |
| 3137 | * Rx theory of operation |
| 3138 | * |
| 3139 | * The host allocates 32 DMA target addresses and passes the host address |
| 3140 | * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
| 3141 | * 0 to 31 |
| 3142 | * |
| 3143 | * Rx Queue Indexes |
| 3144 | * The host/firmware share two index registers for managing the Rx buffers. |
| 3145 | * |
| 3146 | * The READ index maps to the first position that the firmware may be writing |
| 3147 | * to -- the driver can read up to (but not including) this position and get |
| 3148 | * good data. |
| 3149 | * The READ index is managed by the firmware once the card is enabled. |
| 3150 | * |
| 3151 | * The WRITE index maps to the last position the driver has read from -- the |
| 3152 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 3153 | * |
| 3154 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 3155 | * WRITE = READ. |
| 3156 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3157 | * 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] | 3158 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 3159 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3160 | * 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] | 3161 | * and fire the RX interrupt. The driver can then query the READ index and |
| 3162 | * process as many packets as possible, moving the WRITE index forward as it |
| 3163 | * resets the Rx queue buffers with new memory. |
| 3164 | * |
| 3165 | * The management in the driver is as follows: |
| 3166 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 3167 | * 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] | 3168 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3169 | * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3170 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 3171 | * 'processed' and 'read' driver indexes as well) |
| 3172 | * + A received packet is processed and handed to the kernel network stack, |
| 3173 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 3174 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 3175 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 3176 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 3177 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 3178 | * |
| 3179 | * |
| 3180 | * Driver sequence: |
| 3181 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3182 | * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3183 | * iwl3945_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3184 | * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3185 | * queue, updates firmware pointers, and updates |
| 3186 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3187 | * are available, schedules iwl3945_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3188 | * |
| 3189 | * -- enable interrupts -- |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3190 | * 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] | 3191 | * READ INDEX, detaching the SKB from the pool. |
| 3192 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3193 | * Calls iwl3945_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3194 | * slots. |
| 3195 | * ... |
| 3196 | * |
| 3197 | */ |
| 3198 | |
| 3199 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3200 | * 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] | 3201 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3202 | static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3203 | dma_addr_t dma_addr) |
| 3204 | { |
| 3205 | return cpu_to_le32((u32)dma_addr); |
| 3206 | } |
| 3207 | |
| 3208 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3209 | * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3210 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3211 | * 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] | 3212 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3213 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3214 | * |
| 3215 | * This moves the 'write' index forward to catch up with 'processed', and |
| 3216 | * also updates the memory address in the firmware to reference the new |
| 3217 | * target buffer. |
| 3218 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3219 | static int iwl3945_rx_queue_restock(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3220 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3221 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3222 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3223 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3224 | unsigned long flags; |
| 3225 | int write, rc; |
| 3226 | |
| 3227 | spin_lock_irqsave(&rxq->lock, flags); |
| 3228 | write = rxq->write & ~0x7; |
Winkler, Tomas | 37d6831 | 2009-01-08 10:19:54 -0800 | [diff] [blame] | 3229 | while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3230 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3231 | element = rxq->rx_free.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3232 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3233 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3234 | |
| 3235 | /* Point to Rx buffer via next RBD in circular buffer */ |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3236 | 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] | 3237 | rxq->queue[rxq->write] = rxb; |
| 3238 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 3239 | rxq->free_count--; |
| 3240 | } |
| 3241 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3242 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 3243 | * refill it */ |
| 3244 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 3245 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 3246 | |
| 3247 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3248 | /* If we've added more space for the firmware to place data, tell it. |
| 3249 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3250 | if ((write != (rxq->write & ~0x7)) |
| 3251 | || (abs(rxq->write - rxq->read) > 7)) { |
| 3252 | spin_lock_irqsave(&rxq->lock, flags); |
| 3253 | rxq->need_update = 1; |
| 3254 | spin_unlock_irqrestore(&rxq->lock, flags); |
Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 3255 | rc = iwl_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3256 | if (rc) |
| 3257 | return rc; |
| 3258 | } |
| 3259 | |
| 3260 | return 0; |
| 3261 | } |
| 3262 | |
| 3263 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3264 | * 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] | 3265 | * |
| 3266 | * When moving to rx_free an SKB is allocated for the slot. |
| 3267 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3268 | * Also restock the Rx queue via iwl3945_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3269 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3270 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3271 | static void iwl3945_rx_allocate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3272 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3273 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3274 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3275 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3276 | unsigned long flags; |
| 3277 | spin_lock_irqsave(&rxq->lock, flags); |
| 3278 | while (!list_empty(&rxq->rx_used)) { |
| 3279 | element = rxq->rx_used.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3280 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3281 | |
| 3282 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3283 | rxb->skb = |
| 3284 | alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC); |
| 3285 | if (!rxb->skb) { |
| 3286 | if (net_ratelimit()) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 3287 | IWL_CRIT(priv, ": Can not allocate SKB buffers\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3288 | /* We don't reschedule replenish work here -- we will |
| 3289 | * call the restock method and if it still needs |
| 3290 | * more buffers it will schedule replenish */ |
| 3291 | break; |
| 3292 | } |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 3293 | |
| 3294 | /* If radiotap head is required, reserve some headroom here. |
| 3295 | * The physical head count is a variable rx_stats->phy_count. |
| 3296 | * We reserve 4 bytes here. Plus these extra bytes, the |
| 3297 | * headroom of the physical head should be enough for the |
| 3298 | * radiotap head that iwl3945 supported. See iwl3945_rt. |
| 3299 | */ |
| 3300 | skb_reserve(rxb->skb, 4); |
| 3301 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3302 | priv->alloc_rxb_skb++; |
| 3303 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3304 | |
| 3305 | /* Get physical address of RB/SKB */ |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3306 | rxb->real_dma_addr = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3307 | pci_map_single(priv->pci_dev, rxb->skb->data, |
| 3308 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3309 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 3310 | rxq->free_count++; |
| 3311 | } |
| 3312 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | /* |
| 3316 | * this should be called while priv->lock is locked |
| 3317 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 3318 | static void __iwl3945_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3319 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3320 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3321 | |
| 3322 | iwl3945_rx_allocate(priv); |
| 3323 | iwl3945_rx_queue_restock(priv); |
| 3324 | } |
| 3325 | |
| 3326 | |
| 3327 | void iwl3945_rx_replenish(void *data) |
| 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 | unsigned long flags; |
| 3331 | |
| 3332 | iwl3945_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3333 | |
| 3334 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3335 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3336 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3337 | } |
| 3338 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3339 | /* Convert linear signal-to-noise ratio into dB */ |
| 3340 | static u8 ratio2dB[100] = { |
| 3341 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 3342 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 3343 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 3344 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 3345 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 3346 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 3347 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 3348 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 3349 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 3350 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 3351 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 3352 | }; |
| 3353 | |
| 3354 | /* Calculates a relative dB value from a ratio of linear |
| 3355 | * (i.e. not dB) signal levels. |
| 3356 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3357 | int iwl3945_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3358 | { |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3359 | /* 1000:1 or higher just report as 60 dB */ |
| 3360 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3361 | return 60; |
| 3362 | |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3363 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3364 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3365 | if (sig_ratio >= 100) |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 3366 | return 20 + (int)ratio2dB[sig_ratio/10]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3367 | |
| 3368 | /* We shouldn't see this */ |
| 3369 | if (sig_ratio < 1) |
| 3370 | return 0; |
| 3371 | |
| 3372 | /* Use table for ratios 1:1 - 99:1 */ |
| 3373 | return (int)ratio2dB[sig_ratio]; |
| 3374 | } |
| 3375 | |
| 3376 | #define PERFECT_RSSI (-20) /* dBm */ |
| 3377 | #define WORST_RSSI (-95) /* dBm */ |
| 3378 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 3379 | |
| 3380 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 3381 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 3382 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3383 | int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3384 | { |
| 3385 | int sig_qual; |
| 3386 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 3387 | |
| 3388 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 3389 | * as indicator; formula is (signal dbm - noise dbm). |
| 3390 | * SNR at or above 40 is a great signal (100%). |
| 3391 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 3392 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 3393 | if (noise_dbm) { |
| 3394 | if (rssi_dbm - noise_dbm >= 40) |
| 3395 | return 100; |
| 3396 | else if (rssi_dbm < noise_dbm) |
| 3397 | return 0; |
| 3398 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 3399 | |
| 3400 | /* Else use just the signal level. |
| 3401 | * This formula is a least squares fit of data points collected and |
| 3402 | * compared with a reference system that had a percentage (%) display |
| 3403 | * for signal quality. */ |
| 3404 | } else |
| 3405 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 3406 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 3407 | (RSSI_RANGE * RSSI_RANGE); |
| 3408 | |
| 3409 | if (sig_qual > 100) |
| 3410 | sig_qual = 100; |
| 3411 | else if (sig_qual < 1) |
| 3412 | sig_qual = 0; |
| 3413 | |
| 3414 | return sig_qual; |
| 3415 | } |
| 3416 | |
| 3417 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3418 | * iwl3945_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3419 | * |
| 3420 | * Uses the priv->rx_handlers callback function array to invoke |
| 3421 | * the appropriate handlers, including command responses, |
| 3422 | * frame-received notifications, and other notifications. |
| 3423 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3424 | static void iwl3945_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3425 | { |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3426 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3427 | struct iwl_rx_packet *pkt; |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3428 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3429 | u32 r, i; |
| 3430 | int reclaim; |
| 3431 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3432 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 3433 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3434 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3435 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 3436 | * buffer that the driver may process (last buffer filled by ucode). */ |
Winkler, Tomas | 8cd812b | 2008-12-19 10:37:43 +0800 | [diff] [blame] | 3437 | r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3438 | i = rxq->read; |
| 3439 | |
Winkler, Tomas | 37d6831 | 2009-01-08 10:19:54 -0800 | [diff] [blame] | 3440 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3441 | fill_rx = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3442 | /* Rx interrupt, but nothing sent from uCode */ |
| 3443 | if (i == r) |
| 3444 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 3445 | |
| 3446 | while (i != r) { |
| 3447 | rxb = rxq->queue[i]; |
| 3448 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3449 | /* 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] | 3450 | * then a bug has been introduced in the queue refilling |
| 3451 | * routines -- catch it here */ |
| 3452 | BUG_ON(rxb == NULL); |
| 3453 | |
| 3454 | rxq->queue[i] = NULL; |
| 3455 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3456 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3457 | IWL_RX_BUF_SIZE, |
| 3458 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3459 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3460 | |
| 3461 | /* Reclaim a command buffer only if this packet is a response |
| 3462 | * to a (driver-originated) command. |
| 3463 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3464 | * there is no command buffer to reclaim. |
| 3465 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3466 | * but apparently a few don't get set; catch them here. */ |
| 3467 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 3468 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 3469 | (pkt->hdr.cmd != REPLY_TX); |
| 3470 | |
| 3471 | /* Based on type of command response or notification, |
| 3472 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3473 | * rx_handlers table. See iwl3945_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3474 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3475 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3476 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 3477 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 3478 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 3479 | } else { |
| 3480 | /* No handling needed */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3481 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3482 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 3483 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 3484 | pkt->hdr.cmd); |
| 3485 | } |
| 3486 | |
| 3487 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3488 | /* Invoke any callbacks, transfer the skb to caller, and |
| 3489 | * fire off the (possibly) blocking iwl3945_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3490 | * as we reclaim the driver command queue */ |
| 3491 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3492 | iwl3945_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3493 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3494 | IWL_WARN(priv, "Claim null rxb?\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | /* For now we just don't re-use anything. We can tweak this |
| 3498 | * later to try and re-use notification packets and SKBs that |
| 3499 | * fail to Rx correctly */ |
| 3500 | if (rxb->skb != NULL) { |
| 3501 | priv->alloc_rxb_skb--; |
| 3502 | dev_kfree_skb_any(rxb->skb); |
| 3503 | rxb->skb = NULL; |
| 3504 | } |
| 3505 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3506 | pci_unmap_single(priv->pci_dev, rxb->real_dma_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3507 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3508 | spin_lock_irqsave(&rxq->lock, flags); |
| 3509 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 3510 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3511 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3512 | /* If there are a lot of unused frames, |
| 3513 | * restock the Rx queue so ucode won't assert. */ |
| 3514 | if (fill_rx) { |
| 3515 | count++; |
| 3516 | if (count >= 8) { |
| 3517 | priv->rxq.read = i; |
| 3518 | __iwl3945_rx_replenish(priv); |
| 3519 | count = 0; |
| 3520 | } |
| 3521 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | /* Backtrack one entry */ |
| 3525 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3526 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3529 | /** |
| 3530 | * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware |
| 3531 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3532 | static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3533 | struct iwl_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3534 | { |
| 3535 | u32 reg = 0; |
| 3536 | int rc = 0; |
| 3537 | int txq_id = txq->q.id; |
| 3538 | |
| 3539 | if (txq->need_update == 0) |
| 3540 | return rc; |
| 3541 | |
| 3542 | /* if we're trying to save power */ |
| 3543 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 3544 | /* wake up nic if it's powered down ... |
| 3545 | * uCode will wake up, and interrupt us again, so next |
| 3546 | * time we'll skip this part. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3547 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3548 | |
| 3549 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 3550 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3551 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3552 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3553 | return rc; |
| 3554 | } |
| 3555 | |
| 3556 | /* restore this queue's parameters in nic hardware. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3557 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3558 | if (rc) |
| 3559 | return rc; |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3560 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3561 | txq->q.write_ptr | (txq_id << 8)); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3562 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3563 | |
| 3564 | /* else not in power-save mode, uCode will never sleep when we're |
| 3565 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 3566 | } else |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3567 | iwl_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3568 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3569 | |
| 3570 | txq->need_update = 0; |
| 3571 | |
| 3572 | return rc; |
| 3573 | } |
| 3574 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3575 | #ifdef CONFIG_IWL3945_DEBUG |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3576 | static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3577 | struct iwl3945_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3578 | { |
| 3579 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3580 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3581 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 3582 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 3583 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 3584 | le32_to_cpu(rxon->filter_flags)); |
| 3585 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 3586 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 3587 | rxon->ofdm_basic_rates); |
| 3588 | 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] | 3589 | IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr); |
| 3590 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3591 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 3592 | } |
| 3593 | #endif |
| 3594 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3595 | static void iwl3945_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3596 | { |
| 3597 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 3598 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3599 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3602 | |
| 3603 | /* call this function to flush any scheduled tasklet */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3604 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3605 | { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 3606 | /* wait to make sure we flush pending tasklet*/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3607 | synchronize_irq(priv->pci_dev->irq); |
| 3608 | tasklet_kill(&priv->irq_tasklet); |
| 3609 | } |
| 3610 | |
| 3611 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3612 | static inline void iwl3945_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3613 | { |
| 3614 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 3615 | |
| 3616 | /* disable interrupts from uCode/NIC to host */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3617 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3618 | |
| 3619 | /* acknowledge/clear/reset any interrupts still pending |
| 3620 | * from uCode or flow handler (Rx/Tx DMA) */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3621 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 3622 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3623 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 3624 | } |
| 3625 | |
| 3626 | static const char *desc_lookup(int i) |
| 3627 | { |
| 3628 | switch (i) { |
| 3629 | case 1: |
| 3630 | return "FAIL"; |
| 3631 | case 2: |
| 3632 | return "BAD_PARAM"; |
| 3633 | case 3: |
| 3634 | return "BAD_CHECKSUM"; |
| 3635 | case 4: |
| 3636 | return "NMI_INTERRUPT"; |
| 3637 | case 5: |
| 3638 | return "SYSASSERT"; |
| 3639 | case 6: |
| 3640 | return "FATAL_ERROR"; |
| 3641 | } |
| 3642 | |
| 3643 | return "UNKNOWN"; |
| 3644 | } |
| 3645 | |
| 3646 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 3647 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 3648 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3649 | static void iwl3945_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3650 | { |
| 3651 | u32 i; |
| 3652 | u32 desc, time, count, base, data1; |
| 3653 | u32 blink1, blink2, ilink1, ilink2; |
| 3654 | int rc; |
| 3655 | |
| 3656 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 3657 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3658 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3659 | IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3660 | return; |
| 3661 | } |
| 3662 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3663 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3664 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3665 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3666 | return; |
| 3667 | } |
| 3668 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3669 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3670 | |
| 3671 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3672 | IWL_ERR(priv, "Start IWL Error Log Dump:\n"); |
| 3673 | IWL_ERR(priv, "Status: 0x%08lX, count: %d\n", |
| 3674 | priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3675 | } |
| 3676 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3677 | IWL_ERR(priv, "Desc Time asrtPC blink2 " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3678 | "ilink1 nmiPC Line\n"); |
| 3679 | for (i = ERROR_START_OFFSET; |
| 3680 | i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET; |
| 3681 | i += ERROR_ELEM_SIZE) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3682 | desc = iwl_read_targ_mem(priv, base + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3683 | time = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3684 | iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3685 | blink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3686 | iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3687 | blink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3688 | iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3689 | ilink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3690 | iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3691 | ilink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3692 | iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3693 | data1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3694 | iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3695 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3696 | IWL_ERR(priv, |
| 3697 | "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n", |
| 3698 | desc_lookup(desc), desc, time, blink1, blink2, |
| 3699 | ilink1, ilink2, data1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3702 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3703 | |
| 3704 | } |
| 3705 | |
Ben Cahill | f58177b | 2007-11-29 11:09:43 +0800 | [diff] [blame] | 3706 | #define EVENT_START_OFFSET (6 * sizeof(u32)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3707 | |
| 3708 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3709 | * iwl3945_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3710 | * |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3711 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3712 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3713 | 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] | 3714 | u32 num_events, u32 mode) |
| 3715 | { |
| 3716 | u32 i; |
| 3717 | u32 base; /* SRAM byte address of event log header */ |
| 3718 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 3719 | u32 ptr; /* SRAM byte address of log data */ |
| 3720 | u32 ev, time, data; /* event log data */ |
| 3721 | |
| 3722 | if (num_events == 0) |
| 3723 | return; |
| 3724 | |
| 3725 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 3726 | |
| 3727 | if (mode == 0) |
| 3728 | event_size = 2 * sizeof(u32); |
| 3729 | else |
| 3730 | event_size = 3 * sizeof(u32); |
| 3731 | |
| 3732 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 3733 | |
| 3734 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 3735 | * place event id # at far right for easier visual parsing. */ |
| 3736 | for (i = 0; i < num_events; i++) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3737 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3738 | ptr += sizeof(u32); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3739 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3740 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3741 | if (mode == 0) { |
| 3742 | /* data, ev */ |
| 3743 | IWL_ERR(priv, "0x%08x\t%04u\n", time, ev); |
| 3744 | } else { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3745 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3746 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3747 | IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3748 | } |
| 3749 | } |
| 3750 | } |
| 3751 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3752 | static void iwl3945_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3753 | { |
| 3754 | int rc; |
| 3755 | u32 base; /* SRAM byte address of event log header */ |
| 3756 | u32 capacity; /* event log capacity in # entries */ |
| 3757 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 3758 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 3759 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 3760 | u32 size; /* # entries that we'll print */ |
| 3761 | |
| 3762 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3763 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3764 | IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3765 | return; |
| 3766 | } |
| 3767 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3768 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3769 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3770 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3771 | return; |
| 3772 | } |
| 3773 | |
| 3774 | /* event log header */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3775 | capacity = iwl_read_targ_mem(priv, base); |
| 3776 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 3777 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 3778 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3779 | |
| 3780 | size = num_wraps ? capacity : next_entry; |
| 3781 | |
| 3782 | /* bail out if nothing in log */ |
| 3783 | if (size == 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3784 | IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3785 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3786 | return; |
| 3787 | } |
| 3788 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3789 | 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] | 3790 | size, num_wraps); |
| 3791 | |
| 3792 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 3793 | * i.e the next one that uCode would fill. */ |
| 3794 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3795 | iwl3945_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3796 | capacity - next_entry, mode); |
| 3797 | |
| 3798 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3799 | iwl3945_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3800 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3801 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3805 | * 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] | 3806 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3807 | static void iwl3945_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3808 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3809 | /* Set the FW error flag -- cleared on iwl3945_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3810 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 3811 | |
| 3812 | /* Cancel currently queued command. */ |
| 3813 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3814 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3815 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3816 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3817 | iwl3945_dump_nic_error_log(priv); |
| 3818 | iwl3945_dump_nic_event_log(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3819 | iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3820 | } |
| 3821 | #endif |
| 3822 | |
| 3823 | wake_up_interruptible(&priv->wait_command_queue); |
| 3824 | |
| 3825 | /* Keep the restart process from trying to send host |
| 3826 | * commands by clearing the INIT status bit */ |
| 3827 | clear_bit(STATUS_READY, &priv->status); |
| 3828 | |
| 3829 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3830 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 3831 | "Restarting adapter due to uCode error.\n"); |
| 3832 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3833 | if (iwl3945_is_associated(priv)) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3834 | memcpy(&priv->recovery39_rxon, &priv->active39_rxon, |
| 3835 | sizeof(priv->recovery39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3836 | priv->error_recovering = 1; |
| 3837 | } |
| 3838 | queue_work(priv->workqueue, &priv->restart); |
| 3839 | } |
| 3840 | } |
| 3841 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3842 | static void iwl3945_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3843 | { |
| 3844 | unsigned long flags; |
| 3845 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3846 | memcpy(&priv->staging39_rxon, &priv->recovery39_rxon, |
| 3847 | sizeof(priv->staging39_rxon)); |
| 3848 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3849 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3850 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3851 | iwl3945_add_station(priv, priv->bssid, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3852 | |
| 3853 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3854 | priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3855 | priv->error_recovering = 0; |
| 3856 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3857 | } |
| 3858 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3859 | static void iwl3945_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3860 | { |
| 3861 | u32 inta, handled = 0; |
| 3862 | u32 inta_fh; |
| 3863 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3864 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3865 | u32 inta_mask; |
| 3866 | #endif |
| 3867 | |
| 3868 | spin_lock_irqsave(&priv->lock, flags); |
| 3869 | |
| 3870 | /* Ack/clear/reset pending uCode interrupts. |
| 3871 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 3872 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3873 | inta = iwl_read32(priv, CSR_INT); |
| 3874 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3875 | |
| 3876 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 3877 | * Any new interrupts that happen after this, either while we're |
| 3878 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3879 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 3880 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3881 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3882 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3883 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3884 | /* just for debug */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3885 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3886 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 3887 | inta, inta_mask, inta_fh); |
| 3888 | } |
| 3889 | #endif |
| 3890 | |
| 3891 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 3892 | * atomic, make sure that inta covers all the interrupts that |
| 3893 | * we've discovered, even if FH interrupt came in just after |
| 3894 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3895 | if (inta_fh & CSR39_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3896 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3897 | if (inta_fh & CSR39_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3898 | inta |= CSR_INT_BIT_FH_TX; |
| 3899 | |
| 3900 | /* Now service all interrupt bits discovered above. */ |
| 3901 | if (inta & CSR_INT_BIT_HW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3902 | IWL_ERR(priv, "Microcode HW error detected. Restarting.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3903 | |
| 3904 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3905 | iwl3945_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3906 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3907 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3908 | |
| 3909 | handled |= CSR_INT_BIT_HW_ERR; |
| 3910 | |
| 3911 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3912 | |
| 3913 | return; |
| 3914 | } |
| 3915 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3916 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3917 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3918 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3919 | if (inta & CSR_INT_BIT_SCD) |
| 3920 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 3921 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3922 | |
| 3923 | /* Alive notification via Rx interrupt will do the real work */ |
| 3924 | if (inta & CSR_INT_BIT_ALIVE) |
| 3925 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 3926 | } |
| 3927 | #endif |
| 3928 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3929 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3930 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3931 | /* Error detected by uCode */ |
| 3932 | if (inta & CSR_INT_BIT_SW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3933 | IWL_ERR(priv, "Microcode SW error detected. " |
| 3934 | "Restarting 0x%X.\n", inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3935 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3936 | handled |= CSR_INT_BIT_SW_ERR; |
| 3937 | } |
| 3938 | |
| 3939 | /* uCode wakes up after power-down sleep */ |
| 3940 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 3941 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 3942 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3943 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 3944 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 3945 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 3946 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 3947 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 3948 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3949 | |
| 3950 | handled |= CSR_INT_BIT_WAKEUP; |
| 3951 | } |
| 3952 | |
| 3953 | /* All uCode command responses, including Tx command responses, |
| 3954 | * Rx "responses" (frame-received notification), and other |
| 3955 | * notifications from uCode come through here*/ |
| 3956 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3957 | iwl3945_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3958 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 3959 | } |
| 3960 | |
| 3961 | if (inta & CSR_INT_BIT_FH_TX) { |
| 3962 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 3963 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3964 | iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); |
| 3965 | if (!iwl_grab_nic_access(priv)) { |
| 3966 | iwl_write_direct32(priv, FH39_TCSR_CREDIT |
Tomas Winkler | bddadf8 | 2008-12-19 10:37:01 +0800 | [diff] [blame] | 3967 | (FH39_SRVC_CHNL), 0x0); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3968 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3969 | } |
| 3970 | handled |= CSR_INT_BIT_FH_TX; |
| 3971 | } |
| 3972 | |
| 3973 | if (inta & ~handled) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3974 | IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3975 | |
| 3976 | if (inta & ~CSR_INI_SET_MASK) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3977 | IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3978 | inta & ~CSR_INI_SET_MASK); |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3979 | IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3983 | /* only Re-enable if disabled by irq */ |
| 3984 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 3985 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3986 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3987 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3988 | if (priv->debug_level & (IWL_DL_ISR)) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3989 | inta = iwl_read32(priv, CSR_INT); |
| 3990 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 3991 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3992 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 3993 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 3994 | } |
| 3995 | #endif |
| 3996 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3997 | } |
| 3998 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3999 | static irqreturn_t iwl3945_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4000 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4001 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4002 | u32 inta, inta_mask; |
| 4003 | u32 inta_fh; |
| 4004 | if (!priv) |
| 4005 | return IRQ_NONE; |
| 4006 | |
| 4007 | spin_lock(&priv->lock); |
| 4008 | |
| 4009 | /* Disable (but don't clear!) interrupts here to avoid |
| 4010 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 4011 | * If we have something to service, the tasklet will re-enable ints. |
| 4012 | * 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] | 4013 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 4014 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4015 | |
| 4016 | /* Discover which interrupts are active/pending */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4017 | inta = iwl_read32(priv, CSR_INT); |
| 4018 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4019 | |
| 4020 | /* Ignore interrupt if there's nothing in NIC to service. |
| 4021 | * This may be due to IRQ shared with another device, |
| 4022 | * or due to sporadic interrupts thrown from our NIC. */ |
| 4023 | if (!inta && !inta_fh) { |
| 4024 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 4025 | goto none; |
| 4026 | } |
| 4027 | |
| 4028 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
| 4029 | /* Hardware disappeared */ |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4030 | IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4031 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4035 | inta, inta_mask, inta_fh); |
| 4036 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4037 | inta &= ~CSR_INT_BIT_SCD; |
| 4038 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4039 | /* iwl3945_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4040 | if (likely(inta || inta_fh)) |
| 4041 | tasklet_schedule(&priv->irq_tasklet); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4042 | unplugged: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4043 | spin_unlock(&priv->lock); |
| 4044 | |
| 4045 | return IRQ_HANDLED; |
| 4046 | |
| 4047 | none: |
| 4048 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4049 | /* only Re-enable if disabled by irq */ |
| 4050 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 4051 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4052 | spin_unlock(&priv->lock); |
| 4053 | return IRQ_NONE; |
| 4054 | } |
| 4055 | |
| 4056 | /************************** EEPROM BANDS **************************** |
| 4057 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4058 | * The iwl3945_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4059 | * EEPROM contents to the specific channel number supported for each |
| 4060 | * band. |
| 4061 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4062 | * 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] | 4063 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 4064 | * The specific geography and calibration information for that channel |
| 4065 | * is contained in the eeprom map itself. |
| 4066 | * |
| 4067 | * During init, we copy the eeprom information and channel map |
| 4068 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 4069 | * |
| 4070 | * channel_map_24/52 provides the index in the channel_info array for a |
| 4071 | * given channel. We have to have two separate maps as there is channel |
| 4072 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 4073 | * band_2 |
| 4074 | * |
| 4075 | * A value of 0xff stored in the channel_map indicates that the channel |
| 4076 | * is not supported by the hardware at all. |
| 4077 | * |
| 4078 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 4079 | * valid for Tx with the current hardware. This means that |
| 4080 | * while the system can tune and receive on a given channel, it may not |
| 4081 | * be able to associate or transmit any frames on that |
| 4082 | * channel. There is no corresponding channel information for that |
| 4083 | * entry. |
| 4084 | * |
| 4085 | *********************************************************************/ |
| 4086 | |
| 4087 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4088 | static const u8 iwl3945_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4089 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 4090 | }; |
| 4091 | |
| 4092 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4093 | static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4094 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 4095 | }; |
| 4096 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4097 | static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4098 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 4099 | }; |
| 4100 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4101 | static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4102 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 4103 | }; |
| 4104 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4105 | static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4106 | 145, 149, 153, 157, 161, 165 |
| 4107 | }; |
| 4108 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4109 | 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] | 4110 | int *eeprom_ch_count, |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4111 | const struct iwl_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4112 | **eeprom_ch_info, |
| 4113 | const u8 **eeprom_ch_index) |
| 4114 | { |
| 4115 | switch (band) { |
| 4116 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4117 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4118 | *eeprom_ch_info = priv->eeprom39.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4119 | *eeprom_ch_index = iwl3945_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4120 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4121 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4122 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4123 | *eeprom_ch_info = priv->eeprom39.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4124 | *eeprom_ch_index = iwl3945_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4125 | break; |
| 4126 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4127 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4128 | *eeprom_ch_info = priv->eeprom39.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4129 | *eeprom_ch_index = iwl3945_eeprom_band_3; |
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 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4132 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4133 | *eeprom_ch_info = priv->eeprom39.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4134 | *eeprom_ch_index = iwl3945_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4135 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4136 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4137 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4138 | *eeprom_ch_info = priv->eeprom39.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4139 | *eeprom_ch_index = iwl3945_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4140 | break; |
| 4141 | default: |
| 4142 | BUG(); |
| 4143 | return; |
| 4144 | } |
| 4145 | } |
| 4146 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4147 | /** |
| 4148 | * iwl3945_get_channel_info - Find driver's private channel info |
| 4149 | * |
| 4150 | * Based on band and channel number. |
| 4151 | */ |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4152 | const struct iwl_channel_info * |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4153 | iwl3945_get_channel_info(const struct iwl_priv *priv, |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4154 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4155 | { |
| 4156 | int i; |
| 4157 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4158 | switch (band) { |
| 4159 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4160 | for (i = 14; i < priv->channel_count; i++) { |
| 4161 | if (priv->channel_info[i].channel == channel) |
| 4162 | return &priv->channel_info[i]; |
| 4163 | } |
| 4164 | break; |
| 4165 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4166 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4167 | if (channel >= 1 && channel <= 14) |
| 4168 | return &priv->channel_info[channel - 1]; |
| 4169 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4170 | case IEEE80211_NUM_BANDS: |
| 4171 | WARN_ON(1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | return NULL; |
| 4175 | } |
| 4176 | |
| 4177 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 4178 | ? # x " " : "") |
| 4179 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4180 | /** |
| 4181 | * iwl3945_init_channel_map - Set up driver's info for all possible channels |
| 4182 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4183 | static int iwl3945_init_channel_map(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4184 | { |
| 4185 | int eeprom_ch_count = 0; |
| 4186 | const u8 *eeprom_ch_index = NULL; |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4187 | const struct iwl_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4188 | int band, ch; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4189 | struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4190 | |
| 4191 | if (priv->channel_count) { |
| 4192 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 4193 | return 0; |
| 4194 | } |
| 4195 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4196 | if (priv->eeprom39.version < 0x2f) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4197 | IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4198 | priv->eeprom39.version); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4199 | return -EINVAL; |
| 4200 | } |
| 4201 | |
| 4202 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 4203 | |
| 4204 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4205 | ARRAY_SIZE(iwl3945_eeprom_band_1) + |
| 4206 | ARRAY_SIZE(iwl3945_eeprom_band_2) + |
| 4207 | ARRAY_SIZE(iwl3945_eeprom_band_3) + |
| 4208 | ARRAY_SIZE(iwl3945_eeprom_band_4) + |
| 4209 | ARRAY_SIZE(iwl3945_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4210 | |
| 4211 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 4212 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4213 | priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4214 | priv->channel_count, GFP_KERNEL); |
| 4215 | if (!priv->channel_info) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4216 | IWL_ERR(priv, "Could not allocate channel_info\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4217 | priv->channel_count = 0; |
| 4218 | return -ENOMEM; |
| 4219 | } |
| 4220 | |
| 4221 | ch_info = priv->channel_info; |
| 4222 | |
| 4223 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 4224 | * channel map we maintain (that contains additional information than |
| 4225 | * what just in the EEPROM) */ |
| 4226 | for (band = 1; band <= 5; band++) { |
| 4227 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4228 | iwl3945_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4229 | &eeprom_ch_info, &eeprom_ch_index); |
| 4230 | |
| 4231 | /* Loop through each band adding each of the channels */ |
| 4232 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 4233 | ch_info->channel = eeprom_ch_index[ch]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4234 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 4235 | IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4236 | |
| 4237 | /* permanently store EEPROM's channel regulatory flags |
| 4238 | * and max power in channel info database. */ |
| 4239 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 4240 | |
| 4241 | /* Copy the run-time flags so they are there even on |
| 4242 | * invalid channels */ |
| 4243 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 4244 | |
| 4245 | if (!(is_channel_valid(ch_info))) { |
| 4246 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 4247 | "No traffic\n", |
| 4248 | ch_info->channel, |
| 4249 | ch_info->flags, |
| 4250 | is_channel_a_band(ch_info) ? |
| 4251 | "5.2" : "2.4"); |
| 4252 | ch_info++; |
| 4253 | continue; |
| 4254 | } |
| 4255 | |
| 4256 | /* Initialize regulatory-based run-time data */ |
| 4257 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 4258 | eeprom_ch_info[ch].max_power_avg; |
| 4259 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 4260 | ch_info->min_power = 0; |
| 4261 | |
Guy Cohen | fe7c404 | 2008-04-21 15:41:56 -0700 | [diff] [blame] | 4262 | 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] | 4263 | " %ddBm): Ad-Hoc %ssupported\n", |
| 4264 | ch_info->channel, |
| 4265 | is_channel_a_band(ch_info) ? |
| 4266 | "5.2" : "2.4", |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4267 | CHECK_AND_PRINT(VALID), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4268 | CHECK_AND_PRINT(IBSS), |
| 4269 | CHECK_AND_PRINT(ACTIVE), |
| 4270 | CHECK_AND_PRINT(RADAR), |
| 4271 | CHECK_AND_PRINT(WIDE), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4272 | CHECK_AND_PRINT(DFS), |
| 4273 | eeprom_ch_info[ch].flags, |
| 4274 | eeprom_ch_info[ch].max_power_avg, |
| 4275 | ((eeprom_ch_info[ch]. |
| 4276 | flags & EEPROM_CHANNEL_IBSS) |
| 4277 | && !(eeprom_ch_info[ch]. |
| 4278 | flags & EEPROM_CHANNEL_RADAR)) |
| 4279 | ? "" : "not "); |
| 4280 | |
| 4281 | /* Set the user_txpower_limit to the highest power |
| 4282 | * supported by any channel */ |
| 4283 | if (eeprom_ch_info[ch].max_power_avg > |
| 4284 | priv->user_txpower_limit) |
| 4285 | priv->user_txpower_limit = |
| 4286 | eeprom_ch_info[ch].max_power_avg; |
| 4287 | |
| 4288 | ch_info++; |
| 4289 | } |
| 4290 | } |
| 4291 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4292 | /* Set up txpower settings in driver for all channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4293 | if (iwl3945_txpower_set_from_eeprom(priv)) |
| 4294 | return -EIO; |
| 4295 | |
| 4296 | return 0; |
| 4297 | } |
| 4298 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4299 | /* |
| 4300 | * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map |
| 4301 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4302 | static void iwl3945_free_channel_map(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4303 | { |
| 4304 | kfree(priv->channel_info); |
| 4305 | priv->channel_count = 0; |
| 4306 | } |
| 4307 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4308 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 4309 | * sending probe req. This should be set long enough to hear probe responses |
| 4310 | * from more than one AP. */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4311 | #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */ |
| 4312 | #define IWL_ACTIVE_DWELL_TIME_52 (20) |
| 4313 | |
| 4314 | #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3) |
| 4315 | #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4316 | |
| 4317 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 4318 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 4319 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 4320 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 4321 | * no other traffic). |
| 4322 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 4323 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4324 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4325 | |
| 4326 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 4327 | * Must be set longer than active dwell time. |
| 4328 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 4329 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 4330 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 4331 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 4332 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 4333 | |
Kolekar, Abhijeet | e720ce9 | 2008-11-07 09:58:42 -0800 | [diff] [blame] | 4334 | #define IWL_SCAN_PROBE_MASK(n) (BIT(n) | (BIT(n) - BIT(1))) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4335 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4336 | static inline u16 iwl3945_get_active_dwell_time(struct iwl_priv *priv, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4337 | enum ieee80211_band band, |
| 4338 | u8 n_probes) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4339 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4340 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4341 | return IWL_ACTIVE_DWELL_TIME_52 + |
| 4342 | IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4343 | else |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4344 | return IWL_ACTIVE_DWELL_TIME_24 + |
| 4345 | IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4346 | } |
| 4347 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4348 | static u16 iwl3945_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4349 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4350 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4351 | u16 passive = (band == IEEE80211_BAND_2GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4352 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 4353 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 4354 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4355 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4356 | /* If we're associated, we clamp the maximum passive |
| 4357 | * dwell time to be 98% of the beacon interval (minus |
| 4358 | * 2 * channel tune time) */ |
| 4359 | passive = priv->beacon_int; |
| 4360 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 4361 | passive = IWL_PASSIVE_DWELL_BASE; |
| 4362 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 4363 | } |
| 4364 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4365 | return passive; |
| 4366 | } |
| 4367 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4368 | static int iwl3945_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4369 | enum ieee80211_band band, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4370 | u8 is_active, u8 n_probes, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4371 | struct iwl3945_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4372 | { |
| 4373 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4374 | const struct ieee80211_supported_band *sband; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4375 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4376 | u16 passive_dwell = 0; |
| 4377 | u16 active_dwell = 0; |
| 4378 | int added, i; |
| 4379 | |
Kolekar, Abhijeet | cbba18c | 2008-12-19 10:37:42 +0800 | [diff] [blame] | 4380 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4381 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4382 | return 0; |
| 4383 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4384 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4385 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4386 | active_dwell = iwl3945_get_active_dwell_time(priv, band, n_probes); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4387 | passive_dwell = iwl3945_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4388 | |
Abhijeet Kolekar | 8f4807a | 2008-09-03 11:26:31 +0800 | [diff] [blame] | 4389 | if (passive_dwell <= active_dwell) |
| 4390 | passive_dwell = active_dwell + 1; |
| 4391 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4392 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 4393 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 4394 | continue; |
| 4395 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4396 | scan_ch->channel = channels[i].hw_value; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4397 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4398 | ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4399 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 4400 | IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4401 | scan_ch->channel); |
| 4402 | continue; |
| 4403 | } |
| 4404 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4405 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 4406 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 4407 | /* If passive , set up for auto-switch |
| 4408 | * and use long active_dwell time. |
| 4409 | */ |
| 4410 | if (!is_active || is_channel_passive(ch_info) || |
| 4411 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) { |
| 4412 | scan_ch->type = 0; /* passive */ |
| 4413 | if (IWL_UCODE_API(priv->ucode_ver) == 1) |
| 4414 | scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1); |
| 4415 | } else { |
| 4416 | scan_ch->type = 1; /* active */ |
| 4417 | } |
| 4418 | |
| 4419 | /* Set direct probe bits. These may be used both for active |
| 4420 | * scan channels (probes gets sent right away), |
| 4421 | * or for passive channels (probes get se sent only after |
| 4422 | * hearing clear Rx packet).*/ |
| 4423 | if (IWL_UCODE_API(priv->ucode_ver) >= 2) { |
| 4424 | if (n_probes) |
| 4425 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4426 | } else { |
| 4427 | /* uCode v1 does not allow setting direct probe bits on |
| 4428 | * passive channel. */ |
| 4429 | if ((scan_ch->type & 1) && n_probes) |
| 4430 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4431 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4432 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4433 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4434 | scan_ch->tpc.dsp_atten = 110; |
| 4435 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 4436 | |
| 4437 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4438 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4439 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 4440 | else { |
| 4441 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 4442 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4443 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 4444 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4445 | */ |
| 4446 | } |
| 4447 | |
| 4448 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 4449 | scan_ch->channel, |
| 4450 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 4451 | (scan_ch->type & 1) ? |
| 4452 | active_dwell : passive_dwell); |
| 4453 | |
| 4454 | scan_ch++; |
| 4455 | added++; |
| 4456 | } |
| 4457 | |
| 4458 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 4459 | return added; |
| 4460 | } |
| 4461 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4462 | static void iwl3945_init_hw_rates(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4463 | struct ieee80211_rate *rates) |
| 4464 | { |
| 4465 | int i; |
| 4466 | |
| 4467 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4468 | rates[i].bitrate = iwl3945_rates[i].ieee * 5; |
| 4469 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 4470 | rates[i].hw_value_short = i; |
| 4471 | rates[i].flags = 0; |
Samuel Ortiz | d9829a6 | 2008-12-19 10:37:12 +0800 | [diff] [blame] | 4472 | if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4473 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4474 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4475 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4476 | rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4477 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4478 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4479 | } |
| 4480 | } |
| 4481 | |
| 4482 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4483 | * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4484 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4485 | static int iwl3945_init_geos(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4486 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4487 | struct iwl_channel_info *ch; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4488 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4489 | struct ieee80211_channel *channels; |
| 4490 | struct ieee80211_channel *geo_ch; |
| 4491 | struct ieee80211_rate *rates; |
| 4492 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4493 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4494 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 4495 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4496 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 4497 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4498 | return 0; |
| 4499 | } |
| 4500 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4501 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 4502 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4503 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4504 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4505 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4506 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4507 | GFP_KERNEL); |
| 4508 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4509 | kfree(channels); |
| 4510 | return -ENOMEM; |
| 4511 | } |
| 4512 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4513 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4514 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 4515 | sband->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)]; |
| 4516 | /* just OFDM */ |
| 4517 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
| 4518 | sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4519 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4520 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4521 | sband->channels = channels; |
| 4522 | /* OFDM & CCK */ |
| 4523 | sband->bitrates = rates; |
| 4524 | sband->n_bitrates = IWL_RATE_COUNT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4525 | |
| 4526 | priv->ieee_channels = channels; |
| 4527 | priv->ieee_rates = rates; |
| 4528 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4529 | iwl3945_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4530 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4531 | for (i = 0; i < priv->channel_count; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4532 | ch = &priv->channel_info[i]; |
| 4533 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4534 | /* FIXME: might be removed if scan is OK*/ |
| 4535 | if (!is_channel_valid(ch)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4536 | continue; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4537 | |
| 4538 | if (is_channel_a_band(ch)) |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4539 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4540 | else |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4541 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4542 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4543 | geo_ch = &sband->channels[sband->n_channels++]; |
| 4544 | |
| 4545 | geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4546 | geo_ch->max_power = ch->max_power_avg; |
| 4547 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 4548 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4549 | |
| 4550 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4551 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 4552 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4553 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4554 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 4555 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4556 | |
| 4557 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4558 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4559 | |
| 4560 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 4561 | priv->max_channel_txpower_limit = |
| 4562 | ch->max_power_avg; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4563 | } else { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4564 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4565 | } |
| 4566 | |
| 4567 | /* Save flags for reg domain usage */ |
| 4568 | geo_ch->orig_flags = geo_ch->flags; |
| 4569 | |
| 4570 | IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n", |
| 4571 | ch->channel, geo_ch->center_freq, |
| 4572 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 4573 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 4574 | "restricted" : "valid", |
| 4575 | geo_ch->flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4576 | } |
| 4577 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4578 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && |
| 4579 | priv->cfg->sku & IWL_SKU_A) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4580 | IWL_INFO(priv, "Incorrectly detected BG card as ABG. " |
| 4581 | "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 4582 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4583 | priv->cfg->sku &= ~IWL_SKU_A; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4584 | } |
| 4585 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4586 | 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] | 4587 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 4588 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4589 | |
John W. Linville | e0e0a67 | 2008-03-25 15:58:40 -0400 | [diff] [blame] | 4590 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 4591 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 4592 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4593 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 4594 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 4595 | &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4596 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4597 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4598 | |
| 4599 | return 0; |
| 4600 | } |
| 4601 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4602 | /* |
| 4603 | * iwl3945_free_geos - undo allocations in iwl3945_init_geos |
| 4604 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4605 | static void iwl3945_free_geos(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4606 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4607 | kfree(priv->ieee_channels); |
| 4608 | kfree(priv->ieee_rates); |
| 4609 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4610 | } |
| 4611 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4612 | /****************************************************************************** |
| 4613 | * |
| 4614 | * uCode download functions |
| 4615 | * |
| 4616 | ******************************************************************************/ |
| 4617 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4618 | static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4619 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4620 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 4621 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 4622 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 4623 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 4624 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 4625 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4629 | * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4630 | * looking at all data. |
| 4631 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4632 | 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] | 4633 | { |
| 4634 | u32 val; |
| 4635 | u32 save_len = len; |
| 4636 | int rc = 0; |
| 4637 | u32 errcnt; |
| 4638 | |
| 4639 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4640 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4641 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4642 | if (rc) |
| 4643 | return rc; |
| 4644 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4645 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4646 | IWL39_RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4647 | |
| 4648 | errcnt = 0; |
| 4649 | for (; len > 0; len -= sizeof(u32), image++) { |
| 4650 | /* read data comes through single port, auto-incr addr */ |
| 4651 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4652 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4653 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4654 | if (val != le32_to_cpu(*image)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4655 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4656 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4657 | save_len - len, val, le32_to_cpu(*image)); |
| 4658 | rc = -EIO; |
| 4659 | errcnt++; |
| 4660 | if (errcnt >= 20) |
| 4661 | break; |
| 4662 | } |
| 4663 | } |
| 4664 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4665 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4666 | |
| 4667 | if (!errcnt) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 4668 | IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4669 | |
| 4670 | return rc; |
| 4671 | } |
| 4672 | |
| 4673 | |
| 4674 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4675 | * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4676 | * using sample data 100 bytes apart. If these sample points are good, |
| 4677 | * it's a pretty good bet that everything between them is good, too. |
| 4678 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4679 | 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] | 4680 | { |
| 4681 | u32 val; |
| 4682 | int rc = 0; |
| 4683 | u32 errcnt = 0; |
| 4684 | u32 i; |
| 4685 | |
| 4686 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4687 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4688 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4689 | if (rc) |
| 4690 | return rc; |
| 4691 | |
| 4692 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 4693 | /* read data comes through single port, auto-incr addr */ |
| 4694 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4695 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4696 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4697 | i + IWL39_RTC_INST_LOWER_BOUND); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4698 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4699 | if (val != le32_to_cpu(*image)) { |
| 4700 | #if 0 /* Enable this if you want to see details */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4701 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4702 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4703 | i, val, *image); |
| 4704 | #endif |
| 4705 | rc = -EIO; |
| 4706 | errcnt++; |
| 4707 | if (errcnt >= 3) |
| 4708 | break; |
| 4709 | } |
| 4710 | } |
| 4711 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4712 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4713 | |
| 4714 | return rc; |
| 4715 | } |
| 4716 | |
| 4717 | |
| 4718 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4719 | * iwl3945_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4720 | * and verify its contents |
| 4721 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4722 | static int iwl3945_verify_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4723 | { |
| 4724 | __le32 *image; |
| 4725 | u32 len; |
| 4726 | int rc = 0; |
| 4727 | |
| 4728 | /* Try bootstrap */ |
| 4729 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4730 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4731 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4732 | if (rc == 0) { |
| 4733 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 4734 | return 0; |
| 4735 | } |
| 4736 | |
| 4737 | /* Try initialize */ |
| 4738 | image = (__le32 *)priv->ucode_init.v_addr; |
| 4739 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4740 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4741 | if (rc == 0) { |
| 4742 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 4743 | return 0; |
| 4744 | } |
| 4745 | |
| 4746 | /* Try runtime/protocol */ |
| 4747 | image = (__le32 *)priv->ucode_code.v_addr; |
| 4748 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4749 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4750 | if (rc == 0) { |
| 4751 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 4752 | return 0; |
| 4753 | } |
| 4754 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4755 | IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4756 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4757 | /* Since nothing seems to match, show first several data entries in |
| 4758 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 4759 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4760 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4761 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4762 | rc = iwl3945_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4763 | |
| 4764 | return rc; |
| 4765 | } |
| 4766 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4767 | static void iwl3945_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4768 | { |
| 4769 | /* Remove all resets to allow NIC to operate */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4770 | iwl_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4771 | } |
| 4772 | |
| 4773 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4774 | * iwl3945_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4775 | * |
| 4776 | * Copy into buffers for card to fetch via bus-mastering |
| 4777 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4778 | static int iwl3945_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4779 | { |
Kolekar, Abhijeet | a78fe75 | 2008-12-19 10:37:21 +0800 | [diff] [blame] | 4780 | struct iwl_ucode *ucode; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4781 | int ret = -EINVAL, index; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4782 | const struct firmware *ucode_raw; |
| 4783 | /* firmware file name contains uCode/driver compatibility version */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4784 | const char *name_pre = priv->cfg->fw_name_pre; |
| 4785 | const unsigned int api_max = priv->cfg->ucode_api_max; |
| 4786 | const unsigned int api_min = priv->cfg->ucode_api_min; |
| 4787 | char buf[25]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4788 | u8 *src; |
| 4789 | size_t len; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4790 | 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] | 4791 | |
| 4792 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 4793 | * request_firmware() is synchronous, file is in memory on return. */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4794 | for (index = api_max; index >= api_min; index--) { |
| 4795 | sprintf(buf, "%s%u%s", name_pre, index, ".ucode"); |
| 4796 | ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev); |
| 4797 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4798 | IWL_ERR(priv, "%s firmware file req failed: %d\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4799 | buf, ret); |
| 4800 | if (ret == -ENOENT) |
| 4801 | continue; |
| 4802 | else |
| 4803 | goto error; |
| 4804 | } else { |
| 4805 | if (index < api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4806 | IWL_ERR(priv, "Loaded firmware %s, " |
| 4807 | "which is deprecated. " |
| 4808 | " Please use API v%u instead.\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4809 | buf, api_max); |
| 4810 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 4811 | buf, ucode_raw->size); |
| 4812 | break; |
| 4813 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4814 | } |
| 4815 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4816 | if (ret < 0) |
| 4817 | goto error; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4818 | |
| 4819 | /* Make sure that we got at least our header! */ |
| 4820 | if (ucode_raw->size < sizeof(*ucode)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4821 | IWL_ERR(priv, "File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4822 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4823 | goto err_release; |
| 4824 | } |
| 4825 | |
| 4826 | /* Data from ucode file: header followed by uCode images */ |
| 4827 | ucode = (void *)ucode_raw->data; |
| 4828 | |
Chatre, Reinette | c02b3ac | 2008-12-02 12:14:05 -0800 | [diff] [blame] | 4829 | priv->ucode_ver = le32_to_cpu(ucode->ver); |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4830 | api_ver = IWL_UCODE_API(priv->ucode_ver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4831 | inst_size = le32_to_cpu(ucode->inst_size); |
| 4832 | data_size = le32_to_cpu(ucode->data_size); |
| 4833 | init_size = le32_to_cpu(ucode->init_size); |
| 4834 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 4835 | boot_size = le32_to_cpu(ucode->boot_size); |
| 4836 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4837 | /* api_ver should match the api version forming part of the |
| 4838 | * firmware filename ... but we don't check for that and only rely |
| 4839 | * on the API version read from firware header from here on forward */ |
| 4840 | |
| 4841 | if (api_ver < api_min || api_ver > api_max) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4842 | IWL_ERR(priv, "Driver unable to support your firmware API. " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4843 | "Driver supports v%u, firmware is v%u.\n", |
| 4844 | api_max, api_ver); |
| 4845 | priv->ucode_ver = 0; |
| 4846 | ret = -EINVAL; |
| 4847 | goto err_release; |
| 4848 | } |
| 4849 | if (api_ver != api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4850 | IWL_ERR(priv, "Firmware has old API version. Expected %u, " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4851 | "got %u. New firmware can be obtained " |
| 4852 | "from http://www.intellinuxwireless.org.\n", |
| 4853 | api_max, api_ver); |
| 4854 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4855 | IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n", |
| 4856 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 4857 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 4858 | IWL_UCODE_API(priv->ucode_ver), |
| 4859 | IWL_UCODE_SERIAL(priv->ucode_ver)); |
| 4860 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4861 | IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n", |
| 4862 | priv->ucode_ver); |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 4863 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size); |
| 4864 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size); |
| 4865 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size); |
| 4866 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size); |
| 4867 | 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] | 4868 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4869 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4870 | /* Verify size of file vs. image size info in file's header */ |
| 4871 | if (ucode_raw->size < sizeof(*ucode) + |
| 4872 | inst_size + data_size + init_size + |
| 4873 | init_data_size + boot_size) { |
| 4874 | |
| 4875 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 4876 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4877 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4878 | goto err_release; |
| 4879 | } |
| 4880 | |
| 4881 | /* Verify that uCode images will fit in card's SRAM */ |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4882 | if (inst_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4883 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 4884 | inst_size); |
| 4885 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4886 | goto err_release; |
| 4887 | } |
| 4888 | |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4889 | if (data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4890 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 4891 | data_size); |
| 4892 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4893 | goto err_release; |
| 4894 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4895 | if (init_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4896 | IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n", |
| 4897 | init_size); |
| 4898 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4899 | goto err_release; |
| 4900 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4901 | if (init_data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4902 | IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n", |
| 4903 | init_data_size); |
| 4904 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4905 | goto err_release; |
| 4906 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4907 | if (boot_size > IWL39_MAX_BSM_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4908 | IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n", |
| 4909 | boot_size); |
| 4910 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4911 | goto err_release; |
| 4912 | } |
| 4913 | |
| 4914 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 4915 | |
| 4916 | /* Runtime instructions and 2 copies of data: |
| 4917 | * 1) unmodified from disk |
| 4918 | * 2) backup cache for save/restore during power-downs */ |
| 4919 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4920 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4921 | |
| 4922 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4923 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4924 | |
| 4925 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4926 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4927 | |
| 4928 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4929 | !priv->ucode_data_backup.v_addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4930 | goto err_pci_alloc; |
| 4931 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4932 | /* Initialization instructions and data */ |
| 4933 | if (init_size && init_data_size) { |
| 4934 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4935 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4936 | |
| 4937 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4938 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4939 | |
| 4940 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 4941 | goto err_pci_alloc; |
| 4942 | } |
| 4943 | |
| 4944 | /* Bootstrap (instructions only, no data) */ |
| 4945 | if (boot_size) { |
| 4946 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4947 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4948 | |
| 4949 | if (!priv->ucode_boot.v_addr) |
| 4950 | goto err_pci_alloc; |
| 4951 | } |
| 4952 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4953 | /* Copy images into buffers for card's bus-master reads ... */ |
| 4954 | |
| 4955 | /* Runtime instructions (first block of data in file) */ |
| 4956 | src = &ucode->data[0]; |
| 4957 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4958 | 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] | 4959 | memcpy(priv->ucode_code.v_addr, src, len); |
| 4960 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 4961 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 4962 | |
| 4963 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4964 | * NOTE: Copy into backup buffer will be done in iwl3945_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4965 | src = &ucode->data[inst_size]; |
| 4966 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4967 | 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] | 4968 | memcpy(priv->ucode_data.v_addr, src, len); |
| 4969 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 4970 | |
| 4971 | /* Initialization instructions (3rd block) */ |
| 4972 | if (init_size) { |
| 4973 | src = &ucode->data[inst_size + data_size]; |
| 4974 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4975 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 4976 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4977 | memcpy(priv->ucode_init.v_addr, src, len); |
| 4978 | } |
| 4979 | |
| 4980 | /* Initialization data (4th block) */ |
| 4981 | if (init_data_size) { |
| 4982 | src = &ucode->data[inst_size + data_size + init_size]; |
| 4983 | len = priv->ucode_init_data.len; |
| 4984 | IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n", |
| 4985 | (int)len); |
| 4986 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 4987 | } |
| 4988 | |
| 4989 | /* Bootstrap instructions (5th block) */ |
| 4990 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 4991 | len = priv->ucode_boot.len; |
| 4992 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n", |
| 4993 | (int)len); |
| 4994 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 4995 | |
| 4996 | /* We have our copies now, allow OS release its copies */ |
| 4997 | release_firmware(ucode_raw); |
| 4998 | return 0; |
| 4999 | |
| 5000 | err_pci_alloc: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5001 | IWL_ERR(priv, "failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5002 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5003 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5004 | |
| 5005 | err_release: |
| 5006 | release_firmware(ucode_raw); |
| 5007 | |
| 5008 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5009 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | |
| 5013 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5014 | * iwl3945_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5015 | * |
| 5016 | * Tell initialization uCode where to find runtime uCode. |
| 5017 | * |
| 5018 | * BSM registers initially contain pointers to initialization uCode. |
| 5019 | * We need to replace them to load runtime uCode inst and data, |
| 5020 | * and to save runtime data when powering down. |
| 5021 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5022 | static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5023 | { |
| 5024 | dma_addr_t pinst; |
| 5025 | dma_addr_t pdata; |
| 5026 | int rc = 0; |
| 5027 | unsigned long flags; |
| 5028 | |
| 5029 | /* bits 31:0 for 3945 */ |
| 5030 | pinst = priv->ucode_code.p_addr; |
| 5031 | pdata = priv->ucode_data_backup.p_addr; |
| 5032 | |
| 5033 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5034 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5035 | if (rc) { |
| 5036 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5037 | return rc; |
| 5038 | } |
| 5039 | |
| 5040 | /* Tell bootstrap uCode where to find image to load */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5041 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 5042 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 5043 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5044 | priv->ucode_data.len); |
| 5045 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5046 | /* 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] | 5047 | * that all new ptr/size info is in place */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5048 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5049 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 5050 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5051 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5052 | |
| 5053 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5054 | |
| 5055 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 5056 | |
| 5057 | return rc; |
| 5058 | } |
| 5059 | |
| 5060 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5061 | * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5062 | * |
| 5063 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 5064 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5065 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5066 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5067 | static void iwl3945_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5068 | { |
| 5069 | /* Check alive response for "valid" sign from uCode */ |
| 5070 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 5071 | /* We had an error bringing up the hardware, so take it |
| 5072 | * all the way back down so we can try again */ |
| 5073 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 5074 | goto restart; |
| 5075 | } |
| 5076 | |
| 5077 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 5078 | * This is a paranoid check, because we would not have gotten the |
| 5079 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5080 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5081 | /* Runtime instruction load was bad; |
| 5082 | * take it all the way back down so we can try again */ |
| 5083 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 5084 | goto restart; |
| 5085 | } |
| 5086 | |
| 5087 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 5088 | * load and launch runtime uCode, which will send us another "Alive" |
| 5089 | * notification. */ |
| 5090 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5091 | if (iwl3945_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5092 | /* Runtime instruction load won't happen; |
| 5093 | * take it all the way back down so we can try again */ |
| 5094 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 5095 | goto restart; |
| 5096 | } |
| 5097 | return; |
| 5098 | |
| 5099 | restart: |
| 5100 | queue_work(priv->workqueue, &priv->restart); |
| 5101 | } |
| 5102 | |
| 5103 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5104 | /* temporary */ |
| 5105 | static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, |
| 5106 | struct sk_buff *skb); |
| 5107 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5108 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5109 | * iwl3945_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5110 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5111 | * Alive gets handled by iwl3945_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5112 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5113 | static void iwl3945_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5114 | { |
| 5115 | int rc = 0; |
| 5116 | int thermal_spin = 0; |
| 5117 | u32 rfkill; |
| 5118 | |
| 5119 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 5120 | |
| 5121 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 5122 | /* We had an error bringing up the hardware, so take it |
| 5123 | * all the way back down so we can try again */ |
| 5124 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 5125 | goto restart; |
| 5126 | } |
| 5127 | |
| 5128 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 5129 | * This is a paranoid check, because we would not have gotten the |
| 5130 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5131 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5132 | /* Runtime instruction load was bad; |
| 5133 | * take it all the way back down so we can try again */ |
| 5134 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 5135 | goto restart; |
| 5136 | } |
| 5137 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5138 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5139 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5140 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5141 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5142 | IWL_WARN(priv, "Can not read RFKILL status from adapter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5143 | return; |
| 5144 | } |
| 5145 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5146 | rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5147 | IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5148 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5149 | |
| 5150 | if (rfkill & 0x1) { |
| 5151 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5152 | /* if RFKILL is not on, then wait for thermal |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5153 | * sensor in adapter to kick in */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5154 | while (iwl3945_hw_get_temperature(priv) == 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5155 | thermal_spin++; |
| 5156 | udelay(10); |
| 5157 | } |
| 5158 | |
| 5159 | if (thermal_spin) |
| 5160 | IWL_DEBUG_INFO("Thermal calibration took %dus\n", |
| 5161 | thermal_spin * 10); |
| 5162 | } else |
| 5163 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5164 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5165 | /* After the ALIVE response, we can send commands to 3945 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5166 | set_bit(STATUS_ALIVE, &priv->status); |
| 5167 | |
| 5168 | /* Clear out the uCode error bit if it is set */ |
| 5169 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 5170 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5171 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5172 | return; |
| 5173 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 5174 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5175 | |
| 5176 | priv->active_rate = priv->rates_mask; |
| 5177 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 5178 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5179 | iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5180 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5181 | if (iwl3945_is_associated(priv)) { |
| 5182 | struct iwl3945_rxon_cmd *active_rxon = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5183 | (struct iwl3945_rxon_cmd *)(&priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5184 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5185 | memcpy(&priv->staging39_rxon, &priv->active39_rxon, |
| 5186 | sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5187 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5188 | } else { |
| 5189 | /* Initialize our rx_config data */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 5190 | iwl3945_connection_init_rx_config(priv, priv->iw_mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5191 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5192 | } |
| 5193 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5194 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5195 | iwl3945_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5196 | |
| 5197 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5198 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5199 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5200 | iwl3945_reg_txpower_periodic(priv); |
| 5201 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 5202 | iwl3945_led_register(priv); |
| 5203 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5204 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 5205 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5206 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5207 | |
| 5208 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5209 | iwl3945_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5210 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5211 | /* reassociate for ADHOC mode */ |
| 5212 | if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) { |
| 5213 | struct sk_buff *beacon = ieee80211_beacon_get(priv->hw, |
| 5214 | priv->vif); |
| 5215 | if (beacon) |
| 5216 | iwl3945_mac_beacon_update(priv->hw, beacon); |
| 5217 | } |
| 5218 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5219 | return; |
| 5220 | |
| 5221 | restart: |
| 5222 | queue_work(priv->workqueue, &priv->restart); |
| 5223 | } |
| 5224 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5225 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5226 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5227 | static void __iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5228 | { |
| 5229 | unsigned long flags; |
| 5230 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5231 | struct ieee80211_conf *conf = NULL; |
| 5232 | |
| 5233 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 5234 | |
| 5235 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5236 | |
| 5237 | if (!exit_pending) |
| 5238 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5239 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 5240 | iwl3945_led_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5241 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5242 | |
| 5243 | /* Unblock any waiting calls */ |
| 5244 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 5245 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5246 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 5247 | * exiting the module */ |
| 5248 | if (!exit_pending) |
| 5249 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5250 | |
| 5251 | /* stop and reset the on-board processor */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5252 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5253 | |
| 5254 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5255 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5256 | iwl3945_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5257 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5258 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5259 | |
| 5260 | if (priv->mac80211_registered) |
| 5261 | ieee80211_stop_queues(priv->hw); |
| 5262 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5263 | /* If we have not previously called iwl3945_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5264 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5265 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5266 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5267 | STATUS_RF_KILL_HW | |
| 5268 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5269 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5270 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5271 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5272 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5273 | STATUS_IN_SUSPEND | |
| 5274 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5275 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5276 | goto exit; |
| 5277 | } |
| 5278 | |
| 5279 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 5280 | * SUSPEND bits and continue taking the NIC down. */ |
| 5281 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5282 | STATUS_RF_KILL_HW | |
| 5283 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5284 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5285 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5286 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5287 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 5288 | STATUS_IN_SUSPEND | |
| 5289 | test_bit(STATUS_FW_ERROR, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5290 | STATUS_FW_ERROR | |
| 5291 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5292 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5293 | |
| 5294 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5295 | 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] | 5296 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5297 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5298 | iwl3945_hw_txq_ctx_stop(priv); |
| 5299 | iwl3945_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5300 | |
| 5301 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5302 | if (!iwl_grab_nic_access(priv)) { |
| 5303 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5304 | APMG_CLK_VAL_DMA_CLK_RQT); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5305 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5306 | } |
| 5307 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5308 | |
| 5309 | udelay(5); |
| 5310 | |
Kolekar, Abhijeet | 01ec616 | 2008-12-19 10:37:38 +0800 | [diff] [blame] | 5311 | priv->cfg->ops->lib->apm_ops.reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5312 | exit: |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 5313 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5314 | |
| 5315 | if (priv->ibss_beacon) |
| 5316 | dev_kfree_skb(priv->ibss_beacon); |
| 5317 | priv->ibss_beacon = NULL; |
| 5318 | |
| 5319 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5320 | iwl3945_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5321 | } |
| 5322 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5323 | static void iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5324 | { |
| 5325 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5326 | __iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5327 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5328 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5329 | iwl3945_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | #define MAX_HW_RESTARTS 5 |
| 5333 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5334 | static int __iwl3945_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5335 | { |
| 5336 | int rc, i; |
| 5337 | |
| 5338 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5339 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5340 | return -EIO; |
| 5341 | } |
| 5342 | |
| 5343 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5344 | IWL_WARN(priv, "Radio disabled by SW RF kill (module " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5345 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5346 | return -ENODEV; |
| 5347 | } |
| 5348 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5349 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5350 | IWL_ERR(priv, "ucode not available for device bring up\n"); |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5351 | return -EIO; |
| 5352 | } |
| 5353 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5354 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5355 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5356 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 5357 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5358 | else { |
| 5359 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5360 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5361 | IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5362 | return -ENODEV; |
| 5363 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5364 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5365 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5366 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5367 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5368 | rc = iwl3945_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5369 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5370 | IWL_ERR(priv, "Unable to int nic\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5371 | return rc; |
| 5372 | } |
| 5373 | |
| 5374 | /* make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5375 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5376 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5377 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 5378 | |
| 5379 | /* clear (again), then enable host interrupts */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5380 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5381 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5382 | |
| 5383 | /* really make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5384 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5385 | 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] | 5386 | |
| 5387 | /* Copy original ucode data image from disk into backup cache. |
| 5388 | * This will be used to initialize the on-board processor's |
| 5389 | * data SRAM for a clean start when the runtime program first loads. */ |
| 5390 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5391 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5392 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5393 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 5394 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5395 | return 0; |
| 5396 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5397 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 5398 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5399 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5400 | |
| 5401 | /* load bootstrap state machine, |
| 5402 | * load bootstrap program into processor's memory, |
| 5403 | * prepare to load the "initialize" uCode */ |
Kolekar, Abhijeet | 0164b9b | 2008-12-19 10:37:37 +0800 | [diff] [blame] | 5404 | priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5405 | |
| 5406 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5407 | IWL_ERR(priv, |
| 5408 | "Unable to set up bootstrap uCode: %d\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5409 | continue; |
| 5410 | } |
| 5411 | |
| 5412 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5413 | iwl3945_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5414 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5415 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 5416 | |
| 5417 | return 0; |
| 5418 | } |
| 5419 | |
| 5420 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5421 | __iwl3945_down(priv); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5422 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5423 | |
| 5424 | /* tried to restart and config the device for as long as our |
| 5425 | * patience could withstand */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5426 | IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5427 | return -EIO; |
| 5428 | } |
| 5429 | |
| 5430 | |
| 5431 | /***************************************************************************** |
| 5432 | * |
| 5433 | * Workqueue callbacks |
| 5434 | * |
| 5435 | *****************************************************************************/ |
| 5436 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5437 | static void iwl3945_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5438 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5439 | struct iwl_priv *priv = |
| 5440 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5441 | |
| 5442 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5443 | return; |
| 5444 | |
| 5445 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5446 | iwl3945_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5447 | mutex_unlock(&priv->mutex); |
| 5448 | } |
| 5449 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5450 | static void iwl3945_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5451 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5452 | struct iwl_priv *priv = |
| 5453 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5454 | |
| 5455 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5456 | return; |
| 5457 | |
| 5458 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5459 | iwl3945_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5460 | mutex_unlock(&priv->mutex); |
| 5461 | } |
| 5462 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5463 | static void iwl3945_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5464 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5465 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5466 | |
| 5467 | wake_up_interruptible(&priv->wait_command_queue); |
| 5468 | |
| 5469 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5470 | return; |
| 5471 | |
| 5472 | mutex_lock(&priv->mutex); |
| 5473 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5474 | if (!iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5475 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 5476 | "HW and/or SW RF Kill no longer active, restarting " |
| 5477 | "device\n"); |
| 5478 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5479 | queue_work(priv->workqueue, &priv->restart); |
| 5480 | } else { |
| 5481 | |
| 5482 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5483 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 5484 | "disabled by SW switch\n"); |
| 5485 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5486 | IWL_WARN(priv, "Radio Frequency Kill Switch is On:\n" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5487 | "Kill switch must be turned off for " |
| 5488 | "wireless networking to work.\n"); |
| 5489 | } |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5490 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5491 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5492 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 5496 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5497 | static void iwl3945_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5498 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5499 | struct iwl_priv *priv = |
| 5500 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5501 | |
| 5502 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5503 | return; |
| 5504 | |
| 5505 | mutex_lock(&priv->mutex); |
| 5506 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 5507 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5508 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 5509 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 5510 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5511 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5512 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5513 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5514 | } |
| 5515 | mutex_unlock(&priv->mutex); |
| 5516 | } |
| 5517 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5518 | static void iwl3945_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5519 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5520 | struct iwl_priv *priv = |
| 5521 | container_of(data, struct iwl_priv, request_scan); |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 5522 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5523 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5524 | .len = sizeof(struct iwl3945_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5525 | .meta.flags = CMD_SIZE_HUGE, |
| 5526 | }; |
| 5527 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5528 | struct iwl3945_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5529 | struct ieee80211_conf *conf = NULL; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5530 | u8 n_probes = 2; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5531 | enum ieee80211_band band; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5532 | DECLARE_SSID_BUF(ssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5533 | |
| 5534 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5535 | |
| 5536 | mutex_lock(&priv->mutex); |
| 5537 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5538 | if (!iwl_is_ready(priv)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5539 | IWL_WARN(priv, "request scan called when driver not ready.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5540 | goto done; |
| 5541 | } |
| 5542 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5543 | /* Make sure the scan wasn't canceled before this queued work |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5544 | * was given the chance to run... */ |
| 5545 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 5546 | goto done; |
| 5547 | |
| 5548 | /* This should never be called or scheduled if there is currently |
| 5549 | * a scan active in the hardware. */ |
| 5550 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 5551 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 5552 | "Ignoring second request.\n"); |
| 5553 | rc = -EIO; |
| 5554 | goto done; |
| 5555 | } |
| 5556 | |
| 5557 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 5558 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 5559 | goto done; |
| 5560 | } |
| 5561 | |
| 5562 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5563 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 5564 | goto done; |
| 5565 | } |
| 5566 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5567 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5568 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 5569 | goto done; |
| 5570 | } |
| 5571 | |
| 5572 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 5573 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 5574 | goto done; |
| 5575 | } |
| 5576 | |
| 5577 | if (!priv->scan_bands) { |
| 5578 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 5579 | goto done; |
| 5580 | } |
| 5581 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5582 | if (!priv->scan39) { |
| 5583 | priv->scan39 = kmalloc(sizeof(struct iwl3945_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5584 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5585 | if (!priv->scan39) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5586 | rc = -ENOMEM; |
| 5587 | goto done; |
| 5588 | } |
| 5589 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5590 | scan = priv->scan39; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5591 | memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5592 | |
| 5593 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 5594 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 5595 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5596 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5597 | u16 interval = 0; |
| 5598 | u32 extra; |
| 5599 | u32 suspend_time = 100; |
| 5600 | u32 scan_suspend_time = 100; |
| 5601 | unsigned long flags; |
| 5602 | |
| 5603 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 5604 | |
| 5605 | spin_lock_irqsave(&priv->lock, flags); |
| 5606 | interval = priv->beacon_int; |
| 5607 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5608 | |
| 5609 | scan->suspend_time = 0; |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5610 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5611 | if (!interval) |
| 5612 | interval = suspend_time; |
| 5613 | /* |
| 5614 | * suspend time format: |
| 5615 | * 0-19: beacon interval in usec (time before exec.) |
| 5616 | * 20-23: 0 |
| 5617 | * 24-31: number of beacons (suspend between channels) |
| 5618 | */ |
| 5619 | |
| 5620 | extra = (suspend_time / interval) << 24; |
| 5621 | scan_suspend_time = 0xFF0FFFFF & |
| 5622 | (extra | ((suspend_time % interval) * 1024)); |
| 5623 | |
| 5624 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 5625 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 5626 | scan_suspend_time, interval); |
| 5627 | } |
| 5628 | |
| 5629 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 5630 | if (priv->one_direct_scan) { |
| 5631 | IWL_DEBUG_SCAN |
| 5632 | ("Kicking off one direct scan for '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5633 | print_ssid(ssid, priv->direct_ssid, |
| 5634 | priv->direct_ssid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5635 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 5636 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 5637 | memcpy(scan->direct_scan[0].ssid, |
| 5638 | priv->direct_ssid, priv->direct_ssid_len); |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5639 | n_probes++; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5640 | } else |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5641 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5642 | |
| 5643 | /* We don't build a direct scan probe request; the uCode will do |
| 5644 | * that based on the direct_mask added to each channel entry */ |
| 5645 | scan->tx_cmd.len = cpu_to_le16( |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5646 | iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 5647 | IWL_MAX_SCAN_SIZE - sizeof(*scan))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5648 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 5649 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5650 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 5651 | |
| 5652 | /* flags + rate selection */ |
| 5653 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5654 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5655 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 5656 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; |
| 5657 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5658 | band = IEEE80211_BAND_2GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5659 | } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5660 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; |
| 5661 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5662 | band = IEEE80211_BAND_5GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5663 | } else { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5664 | IWL_WARN(priv, "Invalid scan band count\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5665 | goto done; |
| 5666 | } |
| 5667 | |
| 5668 | /* select Rx antennas */ |
| 5669 | scan->flags |= iwl3945_get_antenna_flags(priv); |
| 5670 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5671 | if (priv->iw_mode == NL80211_IFTYPE_MONITOR) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5672 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 5673 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5674 | scan->channel_count = |
| 5675 | iwl3945_get_channels_for_scan(priv, band, 1, /* active */ |
| 5676 | n_probes, |
| 5677 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5678 | |
Reinette Chatre | 14b5433 | 2008-11-04 12:21:35 -0800 | [diff] [blame] | 5679 | if (scan->channel_count == 0) { |
| 5680 | IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count); |
| 5681 | goto done; |
| 5682 | } |
| 5683 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5684 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5685 | scan->channel_count * sizeof(struct iwl3945_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5686 | cmd.data = scan; |
| 5687 | scan->len = cpu_to_le16(cmd.len); |
| 5688 | |
| 5689 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5690 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5691 | if (rc) |
| 5692 | goto done; |
| 5693 | |
| 5694 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 5695 | IWL_SCAN_CHECK_WATCHDOG); |
| 5696 | |
| 5697 | mutex_unlock(&priv->mutex); |
| 5698 | return; |
| 5699 | |
| 5700 | done: |
Mohamed Abbas | 2420ebc | 2008-11-04 12:21:34 -0800 | [diff] [blame] | 5701 | /* can not perform scan make sure we clear scanning |
| 5702 | * bits from status so next scan request can be performed. |
| 5703 | * if we dont clear scanning status bit here all next scan |
| 5704 | * will fail |
| 5705 | */ |
| 5706 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 5707 | clear_bit(STATUS_SCANNING, &priv->status); |
| 5708 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 5709 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5710 | queue_work(priv->workqueue, &priv->scan_completed); |
| 5711 | mutex_unlock(&priv->mutex); |
| 5712 | } |
| 5713 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5714 | static void iwl3945_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5715 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5716 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5717 | |
| 5718 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5719 | return; |
| 5720 | |
| 5721 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5722 | __iwl3945_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5723 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5724 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5725 | } |
| 5726 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5727 | static void iwl3945_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5728 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5729 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5730 | |
| 5731 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5732 | return; |
| 5733 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5734 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5735 | queue_work(priv->workqueue, &priv->up); |
| 5736 | } |
| 5737 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5738 | static void iwl3945_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5739 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5740 | struct iwl_priv *priv = |
| 5741 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5742 | |
| 5743 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5744 | return; |
| 5745 | |
| 5746 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5747 | iwl3945_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5748 | mutex_unlock(&priv->mutex); |
| 5749 | } |
| 5750 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5751 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 5752 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5753 | static void iwl3945_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5754 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5755 | int rc = 0; |
| 5756 | struct ieee80211_conf *conf = NULL; |
| 5757 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5758 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5759 | 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] | 5760 | return; |
| 5761 | } |
| 5762 | |
| 5763 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5764 | IWL_DEBUG_ASSOC("Associated as %d to: %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5765 | priv->assoc_id, priv->active39_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5766 | |
| 5767 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5768 | return; |
| 5769 | |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 5770 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5771 | return; |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 5772 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5773 | iwl3945_scan_cancel_timeout(priv, 200); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5774 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5775 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5776 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5777 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5778 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5779 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 5780 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5781 | iwl3945_setup_rxon_timing(priv); |
| 5782 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5783 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 5784 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5785 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5786 | "Attempting to continue.\n"); |
| 5787 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5788 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5789 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5790 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5791 | |
| 5792 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 5793 | priv->assoc_id, priv->beacon_int); |
| 5794 | |
| 5795 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5796 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5797 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5798 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5799 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5800 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5801 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5802 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5803 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5804 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5805 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5806 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5807 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5808 | |
| 5809 | } |
| 5810 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5811 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5812 | |
| 5813 | switch (priv->iw_mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5814 | case NL80211_IFTYPE_STATION: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5815 | iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5816 | break; |
| 5817 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5818 | case NL80211_IFTYPE_ADHOC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5819 | |
Abhijeet Kolekar | ce546fd | 2008-11-19 15:32:22 -0800 | [diff] [blame] | 5820 | priv->assoc_id = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5821 | iwl3945_add_station(priv, priv->bssid, 0, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5822 | iwl3945_sync_sta(priv, IWL_STA_ID, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5823 | (priv->band == IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5824 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, |
| 5825 | CMD_ASYNC); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5826 | iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); |
| 5827 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5828 | |
| 5829 | break; |
| 5830 | |
| 5831 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5832 | IWL_ERR(priv, "%s Should not be called in %d mode\n", |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 5833 | __func__, priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5834 | break; |
| 5835 | } |
| 5836 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5837 | iwl3945_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 5838 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5839 | /* we have just associated, don't start scan too early */ |
| 5840 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 5841 | } |
| 5842 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5843 | static void iwl3945_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5844 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5845 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5846 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5847 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5848 | return; |
| 5849 | |
| 5850 | mutex_lock(&priv->mutex); |
| 5851 | |
| 5852 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5853 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5854 | |
| 5855 | mutex_unlock(&priv->mutex); |
| 5856 | } |
| 5857 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 5858 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5859 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5860 | static void iwl3945_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5861 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5862 | struct iwl_priv *priv = |
| 5863 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5864 | |
| 5865 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 5866 | |
| 5867 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5868 | return; |
| 5869 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5870 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 5871 | iwl3945_mac_config(priv->hw, 0); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5872 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5873 | ieee80211_scan_completed(priv->hw); |
| 5874 | |
| 5875 | /* Since setting the TXPOWER may have been deferred while |
| 5876 | * performing the scan, fire one off */ |
| 5877 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5878 | iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5879 | mutex_unlock(&priv->mutex); |
| 5880 | } |
| 5881 | |
| 5882 | /***************************************************************************** |
| 5883 | * |
| 5884 | * mac80211 entry point functions |
| 5885 | * |
| 5886 | *****************************************************************************/ |
| 5887 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5888 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 5889 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5890 | static int iwl3945_mac_start(struct ieee80211_hw *hw) |
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 = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5893 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5894 | |
| 5895 | IWL_DEBUG_MAC80211("enter\n"); |
| 5896 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5897 | if (pci_enable_device(priv->pci_dev)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5898 | IWL_ERR(priv, "Fail to pci_enable_device\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5899 | return -ENODEV; |
| 5900 | } |
| 5901 | pci_restore_state(priv->pci_dev); |
| 5902 | pci_enable_msi(priv->pci_dev); |
| 5903 | |
| 5904 | ret = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED, |
| 5905 | DRV_NAME, priv); |
| 5906 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5907 | IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5908 | goto out_disable_msi; |
| 5909 | } |
| 5910 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5911 | /* we should be verifying the device is ready to be opened */ |
| 5912 | mutex_lock(&priv->mutex); |
| 5913 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5914 | memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5915 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 5916 | * ucode filename and max sizes are card-specific. */ |
| 5917 | |
| 5918 | if (!priv->ucode_code.len) { |
| 5919 | ret = iwl3945_read_ucode(priv); |
| 5920 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5921 | IWL_ERR(priv, "Could not read microcode: %d\n", ret); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5922 | mutex_unlock(&priv->mutex); |
| 5923 | goto out_release_irq; |
| 5924 | } |
| 5925 | } |
| 5926 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5927 | ret = __iwl3945_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5928 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5929 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5930 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5931 | iwl3945_rfkill_set_hw_state(priv); |
| 5932 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5933 | if (ret) |
| 5934 | goto out_release_irq; |
| 5935 | |
| 5936 | IWL_DEBUG_INFO("Start UP work.\n"); |
| 5937 | |
| 5938 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 5939 | return 0; |
| 5940 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5941 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 5942 | * mac80211 will not be run successfully. */ |
| 5943 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 5944 | test_bit(STATUS_READY, &priv->status), |
| 5945 | UCODE_READY_TIMEOUT); |
| 5946 | if (!ret) { |
| 5947 | if (!test_bit(STATUS_READY, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5948 | IWL_ERR(priv, |
| 5949 | "Wait for START_ALIVE timeout after %dms.\n", |
| 5950 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5951 | ret = -ETIMEDOUT; |
| 5952 | goto out_release_irq; |
| 5953 | } |
| 5954 | } |
| 5955 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5956 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5957 | IWL_DEBUG_MAC80211("leave\n"); |
| 5958 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5959 | |
| 5960 | out_release_irq: |
| 5961 | free_irq(priv->pci_dev->irq, priv); |
| 5962 | out_disable_msi: |
| 5963 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5964 | pci_disable_device(priv->pci_dev); |
| 5965 | priv->is_open = 0; |
| 5966 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5967 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5968 | } |
| 5969 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5970 | static void iwl3945_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5971 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5972 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5973 | |
| 5974 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5975 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5976 | if (!priv->is_open) { |
| 5977 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 5978 | return; |
| 5979 | } |
| 5980 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5981 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5982 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5983 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5984 | /* stop mac, cancel any scan request and clear |
| 5985 | * RXON_FILTER_ASSOC_MSK BIT |
| 5986 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5987 | mutex_lock(&priv->mutex); |
| 5988 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5989 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5990 | } |
| 5991 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5992 | iwl3945_down(priv); |
| 5993 | |
| 5994 | flush_workqueue(priv->workqueue); |
| 5995 | free_irq(priv->pci_dev->irq, priv); |
| 5996 | pci_disable_msi(priv->pci_dev); |
| 5997 | pci_save_state(priv->pci_dev); |
| 5998 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5999 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6000 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6001 | } |
| 6002 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6003 | 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] | 6004 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6005 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6006 | |
| 6007 | IWL_DEBUG_MAC80211("enter\n"); |
| 6008 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6009 | 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] | 6010 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6011 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6012 | if (iwl3945_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6013 | dev_kfree_skb_any(skb); |
| 6014 | |
| 6015 | IWL_DEBUG_MAC80211("leave\n"); |
Reinette Chatre | 637f883 | 2009-01-19 15:30:32 -0800 | [diff] [blame] | 6016 | return NETDEV_TX_OK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6017 | } |
| 6018 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6019 | static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6020 | struct ieee80211_if_init_conf *conf) |
| 6021 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6022 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6023 | unsigned long flags; |
| 6024 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6025 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6026 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6027 | if (priv->vif) { |
| 6028 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6029 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6030 | } |
| 6031 | |
| 6032 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6033 | priv->vif = conf->vif; |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 6034 | priv->iw_mode = conf->type; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6035 | |
| 6036 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6037 | |
| 6038 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6039 | |
| 6040 | if (conf->mac_addr) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6041 | IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6042 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 6043 | } |
| 6044 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6045 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6046 | iwl3945_set_mode(priv, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6047 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6048 | mutex_unlock(&priv->mutex); |
| 6049 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6050 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6051 | return 0; |
| 6052 | } |
| 6053 | |
| 6054 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6055 | * iwl3945_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6056 | * |
| 6057 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 6058 | * be set inappropriately and the driver currently sets the hardware up to |
| 6059 | * use it whenever needed. |
| 6060 | */ |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6061 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6062 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6063 | struct iwl_priv *priv = hw->priv; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6064 | const struct iwl_channel_info *ch_info; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6065 | struct ieee80211_conf *conf = &hw->conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6066 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6067 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6068 | |
| 6069 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6070 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6071 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6072 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6073 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6074 | ret = -EIO; |
| 6075 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6076 | } |
| 6077 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 6078 | if (unlikely(!iwl3945_mod_params.disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6079 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6080 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 6081 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6082 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6083 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | spin_lock_irqsave(&priv->lock, flags); |
| 6087 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6088 | ch_info = iwl3945_get_channel_info(priv, conf->channel->band, |
| 6089 | conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6090 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 6091 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6092 | conf->channel->hw_value, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6093 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 6094 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6095 | ret = -EINVAL; |
| 6096 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6097 | } |
| 6098 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6099 | iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6100 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6101 | iwl3945_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6102 | |
| 6103 | /* The list of supported rates and rate mask can be different |
| 6104 | * for each phymode; since the phymode may have changed, reset |
| 6105 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6106 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6107 | |
| 6108 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6109 | |
| 6110 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 6111 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6112 | iwl3945_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6113 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6114 | } |
| 6115 | #endif |
| 6116 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6117 | iwl3945_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6118 | |
| 6119 | if (!conf->radio_enabled) { |
| 6120 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6121 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6122 | } |
| 6123 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6124 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6125 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6126 | ret = -EIO; |
| 6127 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6128 | } |
| 6129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6130 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6131 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6132 | if (memcmp(&priv->active39_rxon, |
| 6133 | &priv->staging39_rxon, sizeof(priv->staging39_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6134 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6135 | else |
| 6136 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 6137 | |
| 6138 | IWL_DEBUG_MAC80211("leave\n"); |
| 6139 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6140 | out: |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6141 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6142 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6143 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6144 | } |
| 6145 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6146 | static void iwl3945_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6147 | { |
| 6148 | int rc = 0; |
| 6149 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 6150 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6151 | return; |
| 6152 | |
| 6153 | /* The following should be done only at AP bring up */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 6154 | if (!(iwl3945_is_associated(priv))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6155 | |
| 6156 | /* RXON - unassoc (to set timing command) */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6157 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6158 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6159 | |
| 6160 | /* RXON Timing */ |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6161 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6162 | iwl3945_setup_rxon_timing(priv); |
| 6163 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6164 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 6165 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6166 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6167 | "Attempting to continue.\n"); |
| 6168 | |
| 6169 | /* FIXME: what should be the assoc_id for AP? */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6170 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6171 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6172 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6173 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6174 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6175 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6176 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6177 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6178 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6179 | if (priv->assoc_capability & |
| 6180 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6181 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6182 | RXON_FLG_SHORT_SLOT_MSK; |
| 6183 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6184 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6185 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6186 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6187 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
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_SLOT_MSK; |
| 6190 | } |
| 6191 | /* restore RXON assoc */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6192 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6193 | iwl3945_commit_rxon(priv); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 6194 | iwl3945_add_station(priv, iwl_bcast_addr, 0, 0); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 6195 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6196 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6197 | |
| 6198 | /* FIXME - we need to add code here to detect a totally new |
| 6199 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 6200 | * clear sta table, add BCAST sta... */ |
| 6201 | } |
| 6202 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6203 | static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, |
| 6204 | struct ieee80211_vif *vif, |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6205 | struct ieee80211_if_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6206 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6207 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6208 | int rc; |
| 6209 | |
| 6210 | if (conf == NULL) |
| 6211 | return -EIO; |
| 6212 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6213 | if (priv->vif != vif) { |
| 6214 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6215 | return 0; |
| 6216 | } |
| 6217 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6218 | /* handle this temporarily here */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6219 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6220 | conf->changed & IEEE80211_IFCC_BEACON) { |
| 6221 | struct sk_buff *beacon = ieee80211_beacon_get(hw, vif); |
| 6222 | if (!beacon) |
| 6223 | return -ENOMEM; |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6224 | mutex_lock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6225 | rc = iwl3945_mac_beacon_update(hw, beacon); |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6226 | mutex_unlock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6227 | if (rc) |
| 6228 | return rc; |
| 6229 | } |
| 6230 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6231 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6232 | return -EAGAIN; |
| 6233 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6234 | mutex_lock(&priv->mutex); |
| 6235 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6236 | if (conf->bssid) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6237 | IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6238 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6239 | /* |
| 6240 | * very dubious code was here; the probe filtering flag is never set: |
| 6241 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6242 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 6243 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6244 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6245 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6246 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6247 | if (!conf->bssid) { |
| 6248 | conf->bssid = priv->mac_addr; |
| 6249 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6250 | IWL_DEBUG_MAC80211("bssid was set to: %pM\n", |
| 6251 | conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6252 | } |
| 6253 | if (priv->ibss_beacon) |
| 6254 | dev_kfree_skb(priv->ibss_beacon); |
| 6255 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6256 | priv->ibss_beacon = ieee80211_beacon_get(hw, vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6257 | } |
| 6258 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6259 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6260 | goto done; |
| 6261 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6262 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 6263 | !is_multicast_ether_addr(conf->bssid)) { |
| 6264 | /* If there is currently a HW scan going on in the background |
| 6265 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6266 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6267 | IWL_WARN(priv, "Aborted scan still in progress " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6268 | "after 100ms\n"); |
| 6269 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 6270 | mutex_unlock(&priv->mutex); |
| 6271 | return -EAGAIN; |
| 6272 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6273 | memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6274 | |
| 6275 | /* TODO: Audit driver for usage of these members and see |
| 6276 | * if mac80211 deprecates them (priv->bssid looks like it |
| 6277 | * shouldn't be there, but I haven't scanned the IBSS code |
| 6278 | * to verify) - jpk */ |
| 6279 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 6280 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6281 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6282 | iwl3945_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6283 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6284 | rc = iwl3945_commit_rxon(priv); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6285 | if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6286 | iwl3945_add_station(priv, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6287 | priv->active39_rxon.bssid_addr, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6291 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6292 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6293 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6294 | } |
| 6295 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6296 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6297 | IWL_DEBUG_MAC80211("leave\n"); |
| 6298 | mutex_unlock(&priv->mutex); |
| 6299 | |
| 6300 | return 0; |
| 6301 | } |
| 6302 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6303 | static void iwl3945_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6304 | unsigned int changed_flags, |
| 6305 | unsigned int *total_flags, |
| 6306 | int mc_count, struct dev_addr_list *mc_list) |
| 6307 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6308 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6309 | __le32 *filter_flags = &priv->staging39_rxon.filter_flags; |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6310 | |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6311 | IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n", |
| 6312 | changed_flags, *total_flags); |
| 6313 | |
| 6314 | if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) { |
| 6315 | if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) |
| 6316 | *filter_flags |= RXON_FILTER_PROMISC_MSK; |
| 6317 | else |
| 6318 | *filter_flags &= ~RXON_FILTER_PROMISC_MSK; |
Abhijeet Kolekar | 5ec0397 | 2008-05-05 10:22:48 +0800 | [diff] [blame] | 6319 | } |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6320 | if (changed_flags & FIF_ALLMULTI) { |
| 6321 | if (*total_flags & FIF_ALLMULTI) |
| 6322 | *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK; |
| 6323 | else |
| 6324 | *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK; |
| 6325 | } |
| 6326 | if (changed_flags & FIF_CONTROL) { |
| 6327 | if (*total_flags & FIF_CONTROL) |
| 6328 | *filter_flags |= RXON_FILTER_CTL2HOST_MSK; |
| 6329 | else |
| 6330 | *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK; |
| 6331 | } |
| 6332 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 6333 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
| 6334 | *filter_flags |= RXON_FILTER_BCON_AWARE_MSK; |
| 6335 | else |
| 6336 | *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK; |
| 6337 | } |
| 6338 | |
| 6339 | /* We avoid iwl_commit_rxon here to commit the new filter flags |
| 6340 | * since mac80211 will call ieee80211_hw_config immediately. |
| 6341 | * (mc_list is not supported at this time). Otherwise, we need to |
| 6342 | * queue a background iwl_commit_rxon work. |
| 6343 | */ |
| 6344 | |
| 6345 | *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6346 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6347 | } |
| 6348 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6349 | static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6350 | struct ieee80211_if_init_conf *conf) |
| 6351 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6352 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6353 | |
| 6354 | IWL_DEBUG_MAC80211("enter\n"); |
| 6355 | |
| 6356 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6357 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6358 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6359 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6360 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6361 | iwl3945_commit_rxon(priv); |
| 6362 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6363 | if (priv->vif == conf->vif) { |
| 6364 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6365 | memset(priv->bssid, 0, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6366 | } |
| 6367 | mutex_unlock(&priv->mutex); |
| 6368 | |
| 6369 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6370 | } |
| 6371 | |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6372 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
| 6373 | |
| 6374 | static void iwl3945_bss_info_changed(struct ieee80211_hw *hw, |
| 6375 | struct ieee80211_vif *vif, |
| 6376 | struct ieee80211_bss_conf *bss_conf, |
| 6377 | u32 changes) |
| 6378 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6379 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6380 | |
| 6381 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 6382 | |
| 6383 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 6384 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 6385 | bss_conf->use_short_preamble); |
| 6386 | if (bss_conf->use_short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6387 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6388 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6389 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6390 | } |
| 6391 | |
| 6392 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
| 6393 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
| 6394 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6395 | priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6396 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6397 | priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | if (changes & BSS_CHANGED_ASSOC) { |
| 6401 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
| 6402 | /* This should never happen as this function should |
| 6403 | * never be called from interrupt context. */ |
| 6404 | if (WARN_ON_ONCE(in_interrupt())) |
| 6405 | return; |
| 6406 | if (bss_conf->assoc) { |
| 6407 | priv->assoc_id = bss_conf->aid; |
| 6408 | priv->beacon_int = bss_conf->beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6409 | priv->timestamp = bss_conf->timestamp; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6410 | priv->assoc_capability = bss_conf->assoc_capability; |
| 6411 | priv->next_scan_jiffies = jiffies + |
| 6412 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
| 6413 | mutex_lock(&priv->mutex); |
| 6414 | iwl3945_post_associate(priv); |
| 6415 | mutex_unlock(&priv->mutex); |
| 6416 | } else { |
| 6417 | priv->assoc_id = 0; |
| 6418 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 6419 | } |
| 6420 | } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) { |
| 6421 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
| 6422 | iwl3945_send_rxon_assoc(priv); |
| 6423 | } |
| 6424 | |
| 6425 | } |
| 6426 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6427 | 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] | 6428 | { |
| 6429 | int rc = 0; |
| 6430 | unsigned long flags; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6431 | struct iwl_priv *priv = hw->priv; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6432 | DECLARE_SSID_BUF(ssid_buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6433 | |
| 6434 | IWL_DEBUG_MAC80211("enter\n"); |
| 6435 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6436 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6437 | spin_lock_irqsave(&priv->lock, flags); |
| 6438 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6439 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6440 | rc = -EIO; |
| 6441 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 6442 | goto out_unlock; |
| 6443 | } |
| 6444 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6445 | /* we don't schedule scan within next_scan_jiffies period */ |
| 6446 | if (priv->next_scan_jiffies && |
| 6447 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 6448 | rc = -EAGAIN; |
| 6449 | goto out_unlock; |
| 6450 | } |
Bill Moss | 15dbf1b | 2008-05-06 11:05:15 +0800 | [diff] [blame] | 6451 | /* if we just finished scan ask for delay for a broadcast scan */ |
| 6452 | if ((len == 0) && priv->last_scan_jiffies && |
| 6453 | time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, |
| 6454 | jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6455 | rc = -EAGAIN; |
| 6456 | goto out_unlock; |
| 6457 | } |
| 6458 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6459 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6460 | print_ssid(ssid_buf, ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6461 | |
| 6462 | priv->one_direct_scan = 1; |
| 6463 | priv->direct_ssid_len = (u8) |
| 6464 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 6465 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6466 | } else |
| 6467 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6468 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6469 | rc = iwl3945_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6470 | |
| 6471 | IWL_DEBUG_MAC80211("leave\n"); |
| 6472 | |
| 6473 | out_unlock: |
| 6474 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6475 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6476 | |
| 6477 | return rc; |
| 6478 | } |
| 6479 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6480 | 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] | 6481 | struct ieee80211_vif *vif, |
| 6482 | struct ieee80211_sta *sta, |
| 6483 | struct ieee80211_key_conf *key) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6484 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6485 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 6486 | const u8 *addr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6487 | int rc = 0; |
| 6488 | u8 sta_id; |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 6489 | static const u8 bcast_addr[ETH_ALEN] = |
| 6490 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6491 | |
| 6492 | IWL_DEBUG_MAC80211("enter\n"); |
| 6493 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 6494 | if (iwl3945_mod_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6495 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 6496 | return -EOPNOTSUPP; |
| 6497 | } |
| 6498 | |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 6499 | addr = sta ? sta->addr : bcast_addr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6500 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6501 | sta_id = iwl3945_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6502 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6503 | IWL_DEBUG_MAC80211("leave - %pM not in station map.\n", |
| 6504 | addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6505 | return -EINVAL; |
| 6506 | } |
| 6507 | |
| 6508 | mutex_lock(&priv->mutex); |
| 6509 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6510 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6511 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6512 | switch (cmd) { |
| 6513 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6514 | rc = iwl3945_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6515 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6516 | iwl3945_set_rxon_hwcrypto(priv, 1); |
| 6517 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6518 | key->hw_key_idx = sta_id; |
| 6519 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 6520 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 6521 | } |
| 6522 | break; |
| 6523 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6524 | rc = iwl3945_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6525 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6526 | iwl3945_set_rxon_hwcrypto(priv, 0); |
| 6527 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6528 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 6529 | } |
| 6530 | break; |
| 6531 | default: |
| 6532 | rc = -EINVAL; |
| 6533 | } |
| 6534 | |
| 6535 | IWL_DEBUG_MAC80211("leave\n"); |
| 6536 | mutex_unlock(&priv->mutex); |
| 6537 | |
| 6538 | return rc; |
| 6539 | } |
| 6540 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 6541 | static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6542 | const struct ieee80211_tx_queue_params *params) |
| 6543 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6544 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6545 | unsigned long flags; |
| 6546 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6547 | |
| 6548 | IWL_DEBUG_MAC80211("enter\n"); |
| 6549 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6550 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6551 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6552 | return -EIO; |
| 6553 | } |
| 6554 | |
| 6555 | if (queue >= AC_NUM) { |
| 6556 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 6557 | return 0; |
| 6558 | } |
| 6559 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6560 | q = AC_NUM - 1 - queue; |
| 6561 | |
| 6562 | spin_lock_irqsave(&priv->lock, flags); |
| 6563 | |
| 6564 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 6565 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 6566 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 6567 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 6568 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6569 | |
| 6570 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 6571 | priv->qos_data.qos_active = 1; |
| 6572 | |
| 6573 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6574 | |
| 6575 | mutex_lock(&priv->mutex); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6576 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6577 | iwl3945_activate_qos(priv, 1); |
| 6578 | else if (priv->assoc_id && iwl3945_is_associated(priv)) |
| 6579 | iwl3945_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6580 | |
| 6581 | mutex_unlock(&priv->mutex); |
| 6582 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6583 | IWL_DEBUG_MAC80211("leave\n"); |
| 6584 | return 0; |
| 6585 | } |
| 6586 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6587 | static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6588 | struct ieee80211_tx_queue_stats *stats) |
| 6589 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6590 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6591 | int i, avail; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 6592 | struct iwl_tx_queue *txq; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6593 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6594 | unsigned long flags; |
| 6595 | |
| 6596 | IWL_DEBUG_MAC80211("enter\n"); |
| 6597 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6598 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6599 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6600 | return -EIO; |
| 6601 | } |
| 6602 | |
| 6603 | spin_lock_irqsave(&priv->lock, flags); |
| 6604 | |
| 6605 | for (i = 0; i < AC_NUM; i++) { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 6606 | txq = &priv->txq[i]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6607 | q = &txq->q; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6608 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6609 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 6610 | stats[i].len = q->n_window - avail; |
| 6611 | stats[i].limit = q->n_window - q->high_mark; |
| 6612 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6613 | |
| 6614 | } |
| 6615 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6616 | |
| 6617 | IWL_DEBUG_MAC80211("leave\n"); |
| 6618 | |
| 6619 | return 0; |
| 6620 | } |
| 6621 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6622 | static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6623 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6624 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6625 | unsigned long flags; |
| 6626 | |
| 6627 | mutex_lock(&priv->mutex); |
| 6628 | IWL_DEBUG_MAC80211("enter\n"); |
| 6629 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6630 | iwl_reset_qos(priv); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 6631 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6632 | spin_lock_irqsave(&priv->lock, flags); |
| 6633 | priv->assoc_id = 0; |
| 6634 | priv->assoc_capability = 0; |
| 6635 | priv->call_post_assoc_from_beacon = 0; |
| 6636 | |
| 6637 | /* new association get rid of ibss beacon skb */ |
| 6638 | if (priv->ibss_beacon) |
| 6639 | dev_kfree_skb(priv->ibss_beacon); |
| 6640 | |
| 6641 | priv->ibss_beacon = NULL; |
| 6642 | |
| 6643 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6644 | priv->timestamp = 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6645 | if ((priv->iw_mode == NL80211_IFTYPE_STATION)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6646 | priv->beacon_int = 0; |
| 6647 | |
| 6648 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6649 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6650 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6651 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 6652 | mutex_unlock(&priv->mutex); |
| 6653 | return; |
| 6654 | } |
| 6655 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6656 | /* we are restarting association process |
| 6657 | * clear RXON_FILTER_ASSOC_MSK bit |
| 6658 | */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6659 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6660 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6661 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6662 | iwl3945_commit_rxon(priv); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6663 | } |
| 6664 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6665 | /* Per mac80211.h: This is only used in IBSS mode... */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6666 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6667 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6668 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 6669 | mutex_unlock(&priv->mutex); |
| 6670 | return; |
| 6671 | } |
| 6672 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6673 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6674 | |
| 6675 | mutex_unlock(&priv->mutex); |
| 6676 | |
| 6677 | IWL_DEBUG_MAC80211("leave\n"); |
| 6678 | |
| 6679 | } |
| 6680 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6681 | 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] | 6682 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6683 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6684 | unsigned long flags; |
| 6685 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6686 | IWL_DEBUG_MAC80211("enter\n"); |
| 6687 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6688 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6689 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6690 | return -EIO; |
| 6691 | } |
| 6692 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6693 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6694 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6695 | return -EIO; |
| 6696 | } |
| 6697 | |
| 6698 | spin_lock_irqsave(&priv->lock, flags); |
| 6699 | |
| 6700 | if (priv->ibss_beacon) |
| 6701 | dev_kfree_skb(priv->ibss_beacon); |
| 6702 | |
| 6703 | priv->ibss_beacon = skb; |
| 6704 | |
| 6705 | priv->assoc_id = 0; |
| 6706 | |
| 6707 | IWL_DEBUG_MAC80211("leave\n"); |
| 6708 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6709 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6710 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6711 | |
Abhijeet Kolekar | dc4b1e7 | 2008-09-03 11:26:30 +0800 | [diff] [blame] | 6712 | iwl3945_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6713 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6714 | |
| 6715 | return 0; |
| 6716 | } |
| 6717 | |
| 6718 | /***************************************************************************** |
| 6719 | * |
| 6720 | * sysfs attributes |
| 6721 | * |
| 6722 | *****************************************************************************/ |
| 6723 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6724 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6725 | |
| 6726 | /* |
| 6727 | * The following adds a new attribute to the sysfs representation |
| 6728 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 6729 | * used for controlling the debug level. |
| 6730 | * |
| 6731 | * See the level definitions in iwl for details. |
| 6732 | */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6733 | static ssize_t show_debug_level(struct device *d, |
| 6734 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6735 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6736 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6737 | |
| 6738 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6739 | } |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6740 | static ssize_t store_debug_level(struct device *d, |
| 6741 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6742 | const char *buf, size_t count) |
| 6743 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6744 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6745 | unsigned long val; |
| 6746 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6747 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6748 | ret = strict_strtoul(buf, 0, &val); |
| 6749 | if (ret) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 6750 | 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] | 6751 | else |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6752 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6753 | |
| 6754 | return strnlen(buf, count); |
| 6755 | } |
| 6756 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6757 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 6758 | show_debug_level, store_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6759 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6760 | #endif /* CONFIG_IWL3945_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6761 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6762 | static ssize_t show_temperature(struct device *d, |
| 6763 | struct device_attribute *attr, char *buf) |
| 6764 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6765 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6766 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6767 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6768 | return -EAGAIN; |
| 6769 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6770 | return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6771 | } |
| 6772 | |
| 6773 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 6774 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6775 | static ssize_t show_tx_power(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 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 6780 | } |
| 6781 | |
| 6782 | static ssize_t store_tx_power(struct device *d, |
| 6783 | struct device_attribute *attr, |
| 6784 | const char *buf, size_t count) |
| 6785 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6786 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6787 | char *p = (char *)buf; |
| 6788 | u32 val; |
| 6789 | |
| 6790 | val = simple_strtoul(p, &p, 10); |
| 6791 | if (p == buf) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 6792 | IWL_INFO(priv, ": %s is not in decimal form.\n", buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6793 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6794 | iwl3945_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6795 | |
| 6796 | return count; |
| 6797 | } |
| 6798 | |
| 6799 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 6800 | |
| 6801 | static ssize_t show_flags(struct device *d, |
| 6802 | struct device_attribute *attr, char *buf) |
| 6803 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6804 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6805 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6806 | return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6807 | } |
| 6808 | |
| 6809 | static ssize_t store_flags(struct device *d, |
| 6810 | struct device_attribute *attr, |
| 6811 | const char *buf, size_t count) |
| 6812 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6813 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6814 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 6815 | |
| 6816 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6817 | if (le32_to_cpu(priv->staging39_rxon.flags) != flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6818 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6819 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6820 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6821 | else { |
| 6822 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 6823 | flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6824 | priv->staging39_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6825 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6826 | } |
| 6827 | } |
| 6828 | mutex_unlock(&priv->mutex); |
| 6829 | |
| 6830 | return count; |
| 6831 | } |
| 6832 | |
| 6833 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 6834 | |
| 6835 | static ssize_t show_filter_flags(struct device *d, |
| 6836 | struct device_attribute *attr, char *buf) |
| 6837 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6838 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6839 | |
| 6840 | return sprintf(buf, "0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6841 | le32_to_cpu(priv->active39_rxon.filter_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | static ssize_t store_filter_flags(struct device *d, |
| 6845 | struct device_attribute *attr, |
| 6846 | const char *buf, size_t count) |
| 6847 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6848 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6849 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 6850 | |
| 6851 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6852 | if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6853 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6854 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6855 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6856 | else { |
| 6857 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 6858 | "0x%04X\n", filter_flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6859 | priv->staging39_rxon.filter_flags = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6860 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6861 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6862 | } |
| 6863 | } |
| 6864 | mutex_unlock(&priv->mutex); |
| 6865 | |
| 6866 | return count; |
| 6867 | } |
| 6868 | |
| 6869 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 6870 | store_filter_flags); |
| 6871 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6872 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6873 | |
| 6874 | static ssize_t show_measurement(struct device *d, |
| 6875 | struct device_attribute *attr, char *buf) |
| 6876 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6877 | struct iwl_priv *priv = dev_get_drvdata(d); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 6878 | struct iwl_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6879 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 6880 | u8 *data = (u8 *)&measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6881 | unsigned long flags; |
| 6882 | |
| 6883 | spin_lock_irqsave(&priv->lock, flags); |
| 6884 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 6885 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6886 | return 0; |
| 6887 | } |
| 6888 | memcpy(&measure_report, &priv->measure_report, size); |
| 6889 | priv->measurement_status = 0; |
| 6890 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6891 | |
| 6892 | while (size && (PAGE_SIZE - len)) { |
| 6893 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 6894 | PAGE_SIZE - len, 1); |
| 6895 | len = strlen(buf); |
| 6896 | if (PAGE_SIZE - len) |
| 6897 | buf[len++] = '\n'; |
| 6898 | |
| 6899 | ofs += 16; |
| 6900 | size -= min(size, 16U); |
| 6901 | } |
| 6902 | |
| 6903 | return len; |
| 6904 | } |
| 6905 | |
| 6906 | static ssize_t store_measurement(struct device *d, |
| 6907 | struct device_attribute *attr, |
| 6908 | const char *buf, size_t count) |
| 6909 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6910 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6911 | struct ieee80211_measurement_params params = { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6912 | .channel = le16_to_cpu(priv->active39_rxon.channel), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6913 | .start_time = cpu_to_le64(priv->last_tsf), |
| 6914 | .duration = cpu_to_le16(1), |
| 6915 | }; |
| 6916 | u8 type = IWL_MEASURE_BASIC; |
| 6917 | u8 buffer[32]; |
| 6918 | u8 channel; |
| 6919 | |
| 6920 | if (count) { |
| 6921 | char *p = buffer; |
| 6922 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 6923 | channel = simple_strtoul(p, NULL, 0); |
| 6924 | if (channel) |
| 6925 | params.channel = channel; |
| 6926 | |
| 6927 | p = buffer; |
| 6928 | while (*p && *p != ' ') |
| 6929 | p++; |
| 6930 | if (*p) |
| 6931 | type = simple_strtoul(p + 1, NULL, 0); |
| 6932 | } |
| 6933 | |
| 6934 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 6935 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6936 | iwl3945_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6937 | |
| 6938 | return count; |
| 6939 | } |
| 6940 | |
| 6941 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 6942 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6943 | #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6944 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6945 | static ssize_t store_retry_rate(struct device *d, |
| 6946 | struct device_attribute *attr, |
| 6947 | const char *buf, size_t count) |
| 6948 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6949 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6950 | |
| 6951 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 6952 | if (priv->retry_rate <= 0) |
| 6953 | priv->retry_rate = 1; |
| 6954 | |
| 6955 | return count; |
| 6956 | } |
| 6957 | |
| 6958 | static ssize_t show_retry_rate(struct device *d, |
| 6959 | struct device_attribute *attr, char *buf) |
| 6960 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6961 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6962 | return sprintf(buf, "%d", priv->retry_rate); |
| 6963 | } |
| 6964 | |
| 6965 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 6966 | store_retry_rate); |
| 6967 | |
| 6968 | static ssize_t store_power_level(struct device *d, |
| 6969 | struct device_attribute *attr, |
| 6970 | const char *buf, size_t count) |
| 6971 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6972 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6973 | int rc; |
| 6974 | int mode; |
| 6975 | |
| 6976 | mode = simple_strtoul(buf, NULL, 0); |
| 6977 | mutex_lock(&priv->mutex); |
| 6978 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6979 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6980 | rc = -EAGAIN; |
| 6981 | goto out; |
| 6982 | } |
| 6983 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 6984 | if ((mode < 1) || (mode > IWL39_POWER_LIMIT) || |
| 6985 | (mode == IWL39_POWER_AC)) |
| 6986 | mode = IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6987 | else |
| 6988 | mode |= IWL_POWER_ENABLED; |
| 6989 | |
| 6990 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6991 | rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6992 | if (rc) { |
| 6993 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 6994 | goto out; |
| 6995 | } |
| 6996 | priv->power_mode = mode; |
| 6997 | } |
| 6998 | |
| 6999 | rc = count; |
| 7000 | |
| 7001 | out: |
| 7002 | mutex_unlock(&priv->mutex); |
| 7003 | return rc; |
| 7004 | } |
| 7005 | |
| 7006 | #define MAX_WX_STRING 80 |
| 7007 | |
| 7008 | /* Values are in microsecond */ |
| 7009 | static const s32 timeout_duration[] = { |
| 7010 | 350000, |
| 7011 | 250000, |
| 7012 | 75000, |
| 7013 | 37000, |
| 7014 | 25000, |
| 7015 | }; |
| 7016 | static const s32 period_duration[] = { |
| 7017 | 400000, |
| 7018 | 700000, |
| 7019 | 1000000, |
| 7020 | 1000000, |
| 7021 | 1000000 |
| 7022 | }; |
| 7023 | |
| 7024 | static ssize_t show_power_level(struct device *d, |
| 7025 | struct device_attribute *attr, char *buf) |
| 7026 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7027 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7028 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 7029 | char *p = buf; |
| 7030 | |
| 7031 | p += sprintf(p, "%d ", level); |
| 7032 | switch (level) { |
| 7033 | case IWL_POWER_MODE_CAM: |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7034 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7035 | p += sprintf(p, "(AC)"); |
| 7036 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7037 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7038 | p += sprintf(p, "(BATTERY)"); |
| 7039 | break; |
| 7040 | default: |
| 7041 | p += sprintf(p, |
| 7042 | "(Timeout %dms, Period %dms)", |
| 7043 | timeout_duration[level - 1] / 1000, |
| 7044 | period_duration[level - 1] / 1000); |
| 7045 | } |
| 7046 | |
| 7047 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 7048 | p += sprintf(p, " OFF\n"); |
| 7049 | else |
| 7050 | p += sprintf(p, " \n"); |
| 7051 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7052 | return p - buf + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7053 | |
| 7054 | } |
| 7055 | |
| 7056 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 7057 | store_power_level); |
| 7058 | |
| 7059 | static ssize_t show_channels(struct device *d, |
| 7060 | struct device_attribute *attr, char *buf) |
| 7061 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7062 | /* all this shit doesn't belong into sysfs anyway */ |
| 7063 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7064 | } |
| 7065 | |
| 7066 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 7067 | |
| 7068 | static ssize_t show_statistics(struct device *d, |
| 7069 | struct device_attribute *attr, char *buf) |
| 7070 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7071 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7072 | u32 size = sizeof(struct iwl3945_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7073 | u32 len = 0, ofs = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7074 | u8 *data = (u8 *)&priv->statistics_39; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7075 | int rc = 0; |
| 7076 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7077 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7078 | return -EAGAIN; |
| 7079 | |
| 7080 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7081 | rc = iwl3945_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7082 | mutex_unlock(&priv->mutex); |
| 7083 | |
| 7084 | if (rc) { |
| 7085 | len = sprintf(buf, |
| 7086 | "Error sending statistics request: 0x%08X\n", rc); |
| 7087 | return len; |
| 7088 | } |
| 7089 | |
| 7090 | while (size && (PAGE_SIZE - len)) { |
| 7091 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7092 | PAGE_SIZE - len, 1); |
| 7093 | len = strlen(buf); |
| 7094 | if (PAGE_SIZE - len) |
| 7095 | buf[len++] = '\n'; |
| 7096 | |
| 7097 | ofs += 16; |
| 7098 | size -= min(size, 16U); |
| 7099 | } |
| 7100 | |
| 7101 | return len; |
| 7102 | } |
| 7103 | |
| 7104 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 7105 | |
| 7106 | static ssize_t show_antenna(struct device *d, |
| 7107 | struct device_attribute *attr, char *buf) |
| 7108 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7109 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7110 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7111 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7112 | return -EAGAIN; |
| 7113 | |
| 7114 | return sprintf(buf, "%d\n", priv->antenna); |
| 7115 | } |
| 7116 | |
| 7117 | static ssize_t store_antenna(struct device *d, |
| 7118 | struct device_attribute *attr, |
| 7119 | const char *buf, size_t count) |
| 7120 | { |
| 7121 | int ant; |
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 | |
| 7124 | if (count == 0) |
| 7125 | return 0; |
| 7126 | |
| 7127 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 7128 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 7129 | return count; |
| 7130 | } |
| 7131 | |
| 7132 | if ((ant >= 0) && (ant <= 2)) { |
| 7133 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7134 | priv->antenna = (enum iwl3945_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7135 | } else |
| 7136 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 7137 | |
| 7138 | |
| 7139 | return count; |
| 7140 | } |
| 7141 | |
| 7142 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 7143 | |
| 7144 | static ssize_t show_status(struct device *d, |
| 7145 | struct device_attribute *attr, char *buf) |
| 7146 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7147 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7148 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7149 | return -EAGAIN; |
| 7150 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 7151 | } |
| 7152 | |
| 7153 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 7154 | |
| 7155 | static ssize_t dump_error_log(struct device *d, |
| 7156 | struct device_attribute *attr, |
| 7157 | const char *buf, size_t count) |
| 7158 | { |
| 7159 | char *p = (char *)buf; |
| 7160 | |
| 7161 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7162 | iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7163 | |
| 7164 | return strnlen(buf, count); |
| 7165 | } |
| 7166 | |
| 7167 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 7168 | |
| 7169 | static ssize_t dump_event_log(struct device *d, |
| 7170 | struct device_attribute *attr, |
| 7171 | const char *buf, size_t count) |
| 7172 | { |
| 7173 | char *p = (char *)buf; |
| 7174 | |
| 7175 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7176 | iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7177 | |
| 7178 | return strnlen(buf, count); |
| 7179 | } |
| 7180 | |
| 7181 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 7182 | |
| 7183 | /***************************************************************************** |
| 7184 | * |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 7185 | * driver setup and tear down |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7186 | * |
| 7187 | *****************************************************************************/ |
| 7188 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7189 | static void iwl3945_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7190 | { |
| 7191 | priv->workqueue = create_workqueue(DRV_NAME); |
| 7192 | |
| 7193 | init_waitqueue_head(&priv->wait_command_queue); |
| 7194 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7195 | INIT_WORK(&priv->up, iwl3945_bg_up); |
| 7196 | INIT_WORK(&priv->restart, iwl3945_bg_restart); |
| 7197 | INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); |
| 7198 | INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed); |
| 7199 | INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan); |
| 7200 | INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan); |
| 7201 | INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill); |
| 7202 | INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7203 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); |
| 7204 | INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); |
| 7205 | INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7206 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7207 | iwl3945_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7208 | |
| 7209 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7210 | iwl3945_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7211 | } |
| 7212 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7213 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7214 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7215 | iwl3945_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7216 | |
Joonwoo Park | e47eb6a | 2007-11-29 10:42:49 +0900 | [diff] [blame] | 7217 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7218 | cancel_delayed_work(&priv->scan_check); |
| 7219 | cancel_delayed_work(&priv->alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7220 | cancel_work_sync(&priv->beacon_update); |
| 7221 | } |
| 7222 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7223 | static struct attribute *iwl3945_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7224 | &dev_attr_antenna.attr, |
| 7225 | &dev_attr_channels.attr, |
| 7226 | &dev_attr_dump_errors.attr, |
| 7227 | &dev_attr_dump_events.attr, |
| 7228 | &dev_attr_flags.attr, |
| 7229 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7230 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7231 | &dev_attr_measurement.attr, |
| 7232 | #endif |
| 7233 | &dev_attr_power_level.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7234 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7235 | &dev_attr_statistics.attr, |
| 7236 | &dev_attr_status.attr, |
| 7237 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7238 | &dev_attr_tx_power.attr, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7239 | #ifdef CONFIG_IWL3945_DEBUG |
| 7240 | &dev_attr_debug_level.attr, |
| 7241 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7242 | NULL |
| 7243 | }; |
| 7244 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7245 | static struct attribute_group iwl3945_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7246 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7247 | .attrs = iwl3945_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7248 | }; |
| 7249 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7250 | static struct ieee80211_ops iwl3945_hw_ops = { |
| 7251 | .tx = iwl3945_mac_tx, |
| 7252 | .start = iwl3945_mac_start, |
| 7253 | .stop = iwl3945_mac_stop, |
| 7254 | .add_interface = iwl3945_mac_add_interface, |
| 7255 | .remove_interface = iwl3945_mac_remove_interface, |
| 7256 | .config = iwl3945_mac_config, |
| 7257 | .config_interface = iwl3945_mac_config_interface, |
| 7258 | .configure_filter = iwl3945_configure_filter, |
| 7259 | .set_key = iwl3945_mac_set_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7260 | .get_tx_stats = iwl3945_mac_get_tx_stats, |
| 7261 | .conf_tx = iwl3945_mac_conf_tx, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7262 | .reset_tsf = iwl3945_mac_reset_tsf, |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 7263 | .bss_info_changed = iwl3945_bss_info_changed, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7264 | .hw_scan = iwl3945_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7265 | }; |
| 7266 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 7267 | static int iwl3945_init_drv(struct iwl_priv *priv) |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7268 | { |
| 7269 | int ret; |
| 7270 | |
| 7271 | priv->retry_rate = 1; |
| 7272 | priv->ibss_beacon = NULL; |
| 7273 | |
| 7274 | spin_lock_init(&priv->lock); |
| 7275 | spin_lock_init(&priv->power_data.lock); |
| 7276 | spin_lock_init(&priv->sta_lock); |
| 7277 | spin_lock_init(&priv->hcmd_lock); |
| 7278 | |
| 7279 | INIT_LIST_HEAD(&priv->free_frames); |
| 7280 | |
| 7281 | mutex_init(&priv->mutex); |
| 7282 | |
| 7283 | /* Clear the driver's (not device's) station table */ |
| 7284 | iwl3945_clear_stations_table(priv); |
| 7285 | |
| 7286 | priv->data_retry_limit = -1; |
| 7287 | priv->ieee_channels = NULL; |
| 7288 | priv->ieee_rates = NULL; |
| 7289 | priv->band = IEEE80211_BAND_2GHZ; |
| 7290 | |
| 7291 | priv->iw_mode = NL80211_IFTYPE_STATION; |
| 7292 | |
| 7293 | iwl_reset_qos(priv); |
| 7294 | |
| 7295 | priv->qos_data.qos_active = 0; |
| 7296 | priv->qos_data.qos_cap.val = 0; |
| 7297 | |
| 7298 | priv->rates_mask = IWL_RATES_MASK; |
| 7299 | /* If power management is turned on, default to AC mode */ |
| 7300 | priv->power_mode = IWL_POWER_AC; |
| 7301 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 7302 | |
| 7303 | ret = iwl3945_init_channel_map(priv); |
| 7304 | if (ret) { |
| 7305 | IWL_ERR(priv, "initializing regulatory failed: %d\n", ret); |
| 7306 | goto err; |
| 7307 | } |
| 7308 | |
| 7309 | ret = iwl3945_init_geos(priv); |
| 7310 | if (ret) { |
| 7311 | IWL_ERR(priv, "initializing geos failed: %d\n", ret); |
| 7312 | goto err_free_channel_map; |
| 7313 | } |
| 7314 | |
| 7315 | return 0; |
| 7316 | |
| 7317 | err_free_channel_map: |
| 7318 | iwl3945_free_channel_map(priv); |
| 7319 | err: |
| 7320 | return ret; |
| 7321 | } |
| 7322 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7323 | 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] | 7324 | { |
| 7325 | int err = 0; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7326 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7327 | struct ieee80211_hw *hw; |
Kolekar, Abhijeet | c0f20d9 | 2008-12-19 10:37:19 +0800 | [diff] [blame] | 7328 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7329 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7330 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7331 | /*********************** |
| 7332 | * 1. Allocating HW data |
| 7333 | * ********************/ |
| 7334 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7335 | /* mac80211 allocates memory for this device instance, including |
| 7336 | * space for this driver's private structure */ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7337 | hw = iwl_alloc_all(cfg, &iwl3945_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7338 | if (hw == NULL) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7339 | printk(KERN_ERR DRV_NAME "Can not allocate network device\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7340 | err = -ENOMEM; |
| 7341 | goto out; |
| 7342 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7343 | priv = hw->priv; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7344 | SET_IEEE80211_DEV(hw, &pdev->dev); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7345 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7346 | if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) || |
| 7347 | (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7348 | IWL_ERR(priv, |
| 7349 | "invalid queues_num, should be between %d and %d\n", |
| 7350 | IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES); |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7351 | err = -EINVAL; |
| 7352 | goto out; |
| 7353 | } |
| 7354 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7355 | /* |
| 7356 | * Disabling hardware scan means that mac80211 will perform scans |
| 7357 | * "the hard way", rather than using device's scan. |
| 7358 | */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7359 | if (iwl3945_mod_params.disable_hw_scan) { |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7360 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
| 7361 | iwl3945_hw_ops.hw_scan = NULL; |
| 7362 | } |
| 7363 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7364 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7365 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7366 | priv->cfg = cfg; |
| 7367 | priv->pci_dev = pdev; |
| 7368 | |
| 7369 | #ifdef CONFIG_IWL3945_DEBUG |
| 7370 | priv->debug_level = iwl3945_mod_params.debug; |
| 7371 | atomic_set(&priv->restrict_refcnt, 0); |
| 7372 | #endif |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7373 | hw->rate_control_algorithm = "iwl-3945-rs"; |
| 7374 | hw->sta_data_size = sizeof(struct iwl3945_sta_priv); |
| 7375 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7376 | /* Select antenna (may be helpful if only one antenna is connected) */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7377 | priv->antenna = (enum iwl3945_antenna)iwl3945_mod_params.antenna; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7378 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7379 | /* Tell mac80211 our characteristics */ |
Johannes Berg | 605a0bd | 2008-07-15 10:10:01 +0200 | [diff] [blame] | 7380 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7381 | IEEE80211_HW_NOISE_DBM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7382 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7383 | hw->wiphy->interface_modes = |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7384 | BIT(NL80211_IFTYPE_STATION) | |
| 7385 | BIT(NL80211_IFTYPE_ADHOC); |
| 7386 | |
Luis R. Rodriguez | ea4a82dc | 2008-11-12 14:22:04 -0800 | [diff] [blame] | 7387 | hw->wiphy->fw_handles_regulatory = true; |
| 7388 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7389 | /* 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7390 | hw->queues = 4; |
| 7391 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7392 | /*************************** |
| 7393 | * 2. Initializing PCI bus |
| 7394 | * *************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7395 | if (pci_enable_device(pdev)) { |
| 7396 | err = -ENODEV; |
| 7397 | goto out_ieee80211_free_hw; |
| 7398 | } |
| 7399 | |
| 7400 | pci_set_master(pdev); |
| 7401 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7402 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 7403 | if (!err) |
| 7404 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 7405 | if (err) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7406 | IWL_WARN(priv, "No suitable DMA available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7407 | goto out_pci_disable_device; |
| 7408 | } |
| 7409 | |
| 7410 | pci_set_drvdata(pdev, priv); |
| 7411 | err = pci_request_regions(pdev, DRV_NAME); |
| 7412 | if (err) |
| 7413 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7414 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7415 | /*********************** |
| 7416 | * 3. Read REV Register |
| 7417 | * ********************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7418 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 7419 | if (!priv->hw_base) { |
| 7420 | err = -ENODEV; |
| 7421 | goto out_pci_release_regions; |
| 7422 | } |
| 7423 | |
| 7424 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 7425 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 7426 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 7427 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7428 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 7429 | * PCI Tx retries from interfering with C3 CPU state */ |
| 7430 | pci_write_config_byte(pdev, 0x41, 0x00); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7431 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7432 | /* amp init */ |
| 7433 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7434 | if (err < 0) { |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7435 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 7436 | goto out_iounmap; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7437 | } |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7438 | |
| 7439 | /*********************** |
| 7440 | * 4. Read EEPROM |
| 7441 | * ********************/ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7442 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7443 | /* Read the EEPROM */ |
| 7444 | err = iwl3945_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7445 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7446 | IWL_ERR(priv, "Unable to init EEPROM\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7447 | goto out_remove_sysfs; |
| 7448 | } |
| 7449 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 7450 | get_eeprom_mac(priv, priv->mac_addr); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7451 | IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7452 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 7453 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7454 | /*********************** |
| 7455 | * 5. Setup HW Constants |
| 7456 | * ********************/ |
| 7457 | /* Device-specific setup */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7458 | if (iwl3945_hw_set_hw_params(priv)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7459 | IWL_ERR(priv, "failed to set hw settings\n"); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7460 | goto out_iounmap; |
| 7461 | } |
| 7462 | |
| 7463 | /*********************** |
| 7464 | * 6. Setup priv |
| 7465 | * ********************/ |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7466 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7467 | err = iwl3945_init_drv(priv); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7468 | if (err) { |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7469 | IWL_ERR(priv, "initializing driver failed\n"); |
| 7470 | goto out_free_geos; |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7471 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7472 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7473 | IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n", |
| 7474 | priv->cfg->name); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7475 | |
| 7476 | /*********************************** |
| 7477 | * 7. Initialize Module Parameters |
| 7478 | * **********************************/ |
| 7479 | |
| 7480 | /* Initialize module parameter values here */ |
| 7481 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7482 | if (iwl3945_mod_params.disable) { |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7483 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 7484 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 7485 | } |
| 7486 | |
| 7487 | |
| 7488 | /*********************** |
| 7489 | * 8. Setup Services |
| 7490 | * ********************/ |
| 7491 | |
| 7492 | spin_lock_irqsave(&priv->lock, flags); |
| 7493 | iwl3945_disable_interrupts(priv); |
| 7494 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7495 | |
| 7496 | err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
| 7497 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7498 | IWL_ERR(priv, "failed to create sysfs device attributes\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7499 | goto out_release_irq; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
| 7503 | iwl3945_setup_deferred_work(priv); |
| 7504 | iwl3945_setup_rx_handlers(priv); |
| 7505 | |
| 7506 | /*********************** |
| 7507 | * 9. Conclude |
| 7508 | * ********************/ |
| 7509 | pci_save_state(pdev); |
| 7510 | pci_disable_device(pdev); |
| 7511 | |
| 7512 | /********************************* |
| 7513 | * 10. Setup and Register mac80211 |
| 7514 | * *******************************/ |
| 7515 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7516 | err = ieee80211_register_hw(priv->hw); |
| 7517 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7518 | IWL_ERR(priv, "Failed to register network device: %d\n", err); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7519 | goto out_remove_sysfs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7520 | } |
| 7521 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7522 | priv->hw->conf.beacon_int = 100; |
| 7523 | priv->mac80211_registered = 1; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7524 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7525 | err = iwl3945_rfkill_init(priv); |
| 7526 | if (err) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7527 | IWL_ERR(priv, "Unable to initialize RFKILL system. " |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7528 | "Ignoring error: %d\n", err); |
| 7529 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7530 | return 0; |
| 7531 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7532 | out_remove_sysfs: |
| 7533 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7534 | out_free_geos: |
| 7535 | iwl3945_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7536 | |
| 7537 | out_release_irq: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7538 | destroy_workqueue(priv->workqueue); |
| 7539 | priv->workqueue = NULL; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7540 | iwl3945_unset_hw_params(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7541 | |
| 7542 | out_iounmap: |
| 7543 | pci_iounmap(pdev, priv->hw_base); |
| 7544 | out_pci_release_regions: |
| 7545 | pci_release_regions(pdev); |
| 7546 | out_pci_disable_device: |
| 7547 | pci_disable_device(pdev); |
| 7548 | pci_set_drvdata(pdev, NULL); |
| 7549 | out_ieee80211_free_hw: |
| 7550 | ieee80211_free_hw(priv->hw); |
| 7551 | out: |
| 7552 | return err; |
| 7553 | } |
| 7554 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 7555 | static void __devexit iwl3945_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7556 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7557 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7558 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7559 | |
| 7560 | if (!priv) |
| 7561 | return; |
| 7562 | |
| 7563 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 7564 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7565 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 7566 | |
Kolekar, Abhijeet | d552bfb | 2008-12-19 10:37:41 +0800 | [diff] [blame] | 7567 | if (priv->mac80211_registered) { |
| 7568 | ieee80211_unregister_hw(priv->hw); |
| 7569 | priv->mac80211_registered = 0; |
| 7570 | } else { |
| 7571 | iwl3945_down(priv); |
| 7572 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7573 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7574 | /* make sure we flush any pending irq or |
| 7575 | * tasklet for the driver |
| 7576 | */ |
| 7577 | spin_lock_irqsave(&priv->lock, flags); |
| 7578 | iwl3945_disable_interrupts(priv); |
| 7579 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7580 | |
| 7581 | iwl_synchronize_irq(priv); |
| 7582 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7583 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7584 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7585 | iwl3945_rfkill_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7586 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7587 | |
| 7588 | if (priv->rxq.bd) |
Winkler, Tomas | 51af3d3 | 2008-12-22 11:31:23 +0800 | [diff] [blame] | 7589 | iwl_rx_queue_free(priv, &priv->rxq); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7590 | iwl3945_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7591 | |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7592 | iwl3945_unset_hw_params(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7593 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7594 | |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 7595 | /*netif_stop_queue(dev); */ |
| 7596 | flush_workqueue(priv->workqueue); |
| 7597 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7598 | /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7599 | * priv->workqueue... so we can't take down the workqueue |
| 7600 | * until now... */ |
| 7601 | destroy_workqueue(priv->workqueue); |
| 7602 | priv->workqueue = NULL; |
| 7603 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7604 | pci_iounmap(pdev, priv->hw_base); |
| 7605 | pci_release_regions(pdev); |
| 7606 | pci_disable_device(pdev); |
| 7607 | pci_set_drvdata(pdev, NULL); |
| 7608 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7609 | iwl3945_free_channel_map(priv); |
| 7610 | iwl3945_free_geos(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7611 | kfree(priv->scan39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7612 | if (priv->ibss_beacon) |
| 7613 | dev_kfree_skb(priv->ibss_beacon); |
| 7614 | |
| 7615 | ieee80211_free_hw(priv->hw); |
| 7616 | } |
| 7617 | |
| 7618 | #ifdef CONFIG_PM |
| 7619 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7620 | 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] | 7621 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7622 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7623 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7624 | if (priv->is_open) { |
| 7625 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 7626 | iwl3945_mac_stop(priv->hw); |
| 7627 | priv->is_open = 1; |
| 7628 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7629 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7630 | pci_set_power_state(pdev, PCI_D3hot); |
| 7631 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7632 | return 0; |
| 7633 | } |
| 7634 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7635 | static int iwl3945_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7636 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7637 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7638 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7639 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7640 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7641 | if (priv->is_open) |
| 7642 | iwl3945_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7643 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7644 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7645 | return 0; |
| 7646 | } |
| 7647 | |
| 7648 | #endif /* CONFIG_PM */ |
| 7649 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7650 | /*************** RFKILL FUNCTIONS **********/ |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7651 | #ifdef CONFIG_IWL3945_RFKILL |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7652 | /* software rf-kill from user */ |
| 7653 | static int iwl3945_rfkill_soft_rf_kill(void *data, enum rfkill_state state) |
| 7654 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7655 | struct iwl_priv *priv = data; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7656 | int err = 0; |
| 7657 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7658 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7659 | return 0; |
| 7660 | |
| 7661 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7662 | return 0; |
| 7663 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 7664 | 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] | 7665 | mutex_lock(&priv->mutex); |
| 7666 | |
| 7667 | switch (state) { |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7668 | case RFKILL_STATE_UNBLOCKED: |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7669 | if (iwl_is_rfkill_hw(priv)) { |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7670 | err = -EBUSY; |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7671 | goto out_unlock; |
| 7672 | } |
| 7673 | iwl3945_radio_kill_sw(priv, 0); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7674 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7675 | case RFKILL_STATE_SOFT_BLOCKED: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7676 | iwl3945_radio_kill_sw(priv, 1); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7677 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7678 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 7679 | IWL_WARN(priv, "received unexpected RFKILL state %d\n", state); |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7680 | break; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7681 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7682 | out_unlock: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7683 | mutex_unlock(&priv->mutex); |
| 7684 | |
| 7685 | return err; |
| 7686 | } |
| 7687 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7688 | int iwl3945_rfkill_init(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7689 | { |
| 7690 | struct device *device = wiphy_dev(priv->hw->wiphy); |
| 7691 | int ret = 0; |
| 7692 | |
| 7693 | BUG_ON(device == NULL); |
| 7694 | |
| 7695 | IWL_DEBUG_RF_KILL("Initializing RFKILL.\n"); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7696 | priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN); |
| 7697 | if (!priv->rfkill) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7698 | IWL_ERR(priv, "Unable to allocate rfkill device.\n"); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7699 | ret = -ENOMEM; |
| 7700 | goto error; |
| 7701 | } |
| 7702 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7703 | priv->rfkill->name = priv->cfg->name; |
| 7704 | priv->rfkill->data = priv; |
| 7705 | priv->rfkill->state = RFKILL_STATE_UNBLOCKED; |
| 7706 | priv->rfkill->toggle_radio = iwl3945_rfkill_soft_rf_kill; |
| 7707 | priv->rfkill->user_claim_unsupported = 1; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7708 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7709 | priv->rfkill->dev.class->suspend = NULL; |
| 7710 | priv->rfkill->dev.class->resume = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7711 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7712 | ret = rfkill_register(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7713 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7714 | IWL_ERR(priv, "Unable to register rfkill: %d\n", ret); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7715 | goto freed_rfkill; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7716 | } |
| 7717 | |
| 7718 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 7719 | return ret; |
| 7720 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7721 | freed_rfkill: |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7722 | if (priv->rfkill != NULL) |
| 7723 | rfkill_free(priv->rfkill); |
| 7724 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7725 | |
| 7726 | error: |
| 7727 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 7728 | return ret; |
| 7729 | } |
| 7730 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7731 | void iwl3945_rfkill_unregister(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7732 | { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7733 | if (priv->rfkill) |
| 7734 | rfkill_unregister(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7735 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7736 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7737 | } |
| 7738 | |
| 7739 | /* set rf-kill to the right state. */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7740 | void iwl3945_rfkill_set_hw_state(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7741 | { |
| 7742 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7743 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7744 | return; |
| 7745 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7746 | if (iwl_is_rfkill_hw(priv)) { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7747 | rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED); |
| 7748 | return; |
| 7749 | } |
| 7750 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7751 | if (!iwl_is_rfkill_sw(priv)) |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7752 | rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7753 | else |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7754 | rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7755 | } |
| 7756 | #endif |
| 7757 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7758 | /***************************************************************************** |
| 7759 | * |
| 7760 | * driver and module entry point |
| 7761 | * |
| 7762 | *****************************************************************************/ |
| 7763 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7764 | static struct pci_driver iwl3945_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7765 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7766 | .id_table = iwl3945_hw_card_ids, |
| 7767 | .probe = iwl3945_pci_probe, |
| 7768 | .remove = __devexit_p(iwl3945_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7769 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7770 | .suspend = iwl3945_pci_suspend, |
| 7771 | .resume = iwl3945_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7772 | #endif |
| 7773 | }; |
| 7774 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7775 | static int __init iwl3945_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7776 | { |
| 7777 | |
| 7778 | int ret; |
| 7779 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 7780 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7781 | |
| 7782 | ret = iwl3945_rate_control_register(); |
| 7783 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7784 | printk(KERN_ERR DRV_NAME |
| 7785 | "Unable to register rate control algorithm: %d\n", ret); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7786 | return ret; |
| 7787 | } |
| 7788 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7789 | ret = pci_register_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7790 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7791 | printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7792 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7793 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7794 | |
| 7795 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7796 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7797 | error_register: |
| 7798 | iwl3945_rate_control_unregister(); |
| 7799 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7800 | } |
| 7801 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7802 | static void __exit iwl3945_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7803 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7804 | pci_unregister_driver(&iwl3945_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7805 | iwl3945_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7806 | } |
| 7807 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 7808 | MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX)); |
Zhu Yi | 25cb6ca | 2008-09-11 11:45:22 +0800 | [diff] [blame] | 7809 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7810 | module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7811 | 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] | 7812 | module_param_named(disable, iwl3945_mod_params.disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7813 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7814 | module_param_named(hwcrypto, iwl3945_mod_params.sw_crypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7815 | MODULE_PARM_DESC(hwcrypto, |
| 7816 | "using hardware crypto engine (default 0 [software])\n"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7817 | module_param_named(debug, iwl3945_mod_params.debug, uint, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7818 | MODULE_PARM_DESC(debug, "debug output mask"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7819 | 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] | 7820 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 7821 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7822 | 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] | 7823 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 7824 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7825 | module_exit(iwl3945_exit); |
| 7826 | module_init(iwl3945_init); |