Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/dma-mapping.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/skbuff.h> |
| 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/wireless.h> |
| 39 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 40 | #include <linux/etherdevice.h> |
| 41 | #include <linux/if_arp.h> |
| 42 | |
| 43 | #include <net/ieee80211_radiotap.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 44 | #include <net/lib80211.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 45 | #include <net/mac80211.h> |
| 46 | |
| 47 | #include <asm/div64.h> |
| 48 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 49 | #define DRV_NAME "iwl3945" |
| 50 | |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 51 | #include "iwl-fh.h" |
| 52 | #include "iwl-3945-fh.h" |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 53 | #include "iwl-commands.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 54 | #include "iwl-3945.h" |
| 55 | #include "iwl-helpers.h" |
Kolekar, Abhijeet | 5747d47 | 2008-12-19 10:37:18 +0800 | [diff] [blame] | 56 | #include "iwl-core.h" |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 57 | #include "iwl-dev.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 58 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 59 | /* |
| 60 | * module name, copyright, version, etc. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 61 | */ |
| 62 | |
| 63 | #define DRV_DESCRIPTION \ |
| 64 | "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux" |
| 65 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 66 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 67 | #define VD "d" |
| 68 | #else |
| 69 | #define VD |
| 70 | #endif |
| 71 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 72 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 73 | #define VS "s" |
| 74 | #else |
| 75 | #define VS |
| 76 | #endif |
| 77 | |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 78 | #define IWL39_VERSION "1.2.26k" VD VS |
Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 79 | #define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation" |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 80 | #define DRV_AUTHOR "<ilw@linux.intel.com>" |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 81 | #define DRV_VERSION IWL39_VERSION |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 82 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 83 | |
| 84 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 85 | MODULE_VERSION(DRV_VERSION); |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 86 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 87 | MODULE_LICENSE("GPL"); |
| 88 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 89 | /* module parameters */ |
| 90 | struct iwl_mod_params iwl3945_mod_params = { |
| 91 | .num_of_queues = IWL39_MAX_NUM_QUEUES, |
Samuel Ortiz | 9c74d9f | 2009-01-08 10:19:59 -0800 | [diff] [blame] | 92 | .sw_crypto = 1, |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 93 | /* the rest are 0 by default */ |
| 94 | }; |
| 95 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 96 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 97 | * DMA services |
| 98 | * |
| 99 | * Theory of operation |
| 100 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 101 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 102 | * of buffer descriptors, each of which points to one or more data buffers for |
| 103 | * the device to read from or fill. Driver and device exchange status of each |
| 104 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 105 | * entries in each circular buffer, to protect against confusing empty and full |
| 106 | * queue states. |
| 107 | * |
| 108 | * The device reads or writes the data in the queues via the device's several |
| 109 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 110 | * |
| 111 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 112 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 113 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 114 | * Tx queue resumed. |
| 115 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 116 | * The 3945 operates with six queues: One receive queue, one transmit queue |
| 117 | * (#4) for sending commands to the device firmware, and four transmit queues |
| 118 | * (#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] | 119 | ***************************************************/ |
| 120 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 121 | /** |
| 122 | * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes |
| 123 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 124 | 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] | 125 | int count, int slots_num, u32 id) |
| 126 | { |
| 127 | q->n_bd = count; |
| 128 | q->n_window = slots_num; |
| 129 | q->id = id; |
| 130 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 131 | /* count must be power-of-two size, otherwise iwl_queue_inc_wrap |
| 132 | * and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 133 | BUG_ON(!is_power_of_2(count)); |
| 134 | |
| 135 | /* slots_num must be power-of-two size, otherwise |
| 136 | * get_cmd_index is broken. */ |
| 137 | BUG_ON(!is_power_of_2(slots_num)); |
| 138 | |
| 139 | q->low_mark = q->n_window / 4; |
| 140 | if (q->low_mark < 4) |
| 141 | q->low_mark = 4; |
| 142 | |
| 143 | q->high_mark = q->n_window / 8; |
| 144 | if (q->high_mark < 2) |
| 145 | q->high_mark = 2; |
| 146 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 147 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 152 | /** |
| 153 | * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 154 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 155 | static int iwl3945_tx_queue_alloc(struct iwl_priv *priv, |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 156 | struct iwl_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 157 | { |
| 158 | struct pci_dev *dev = priv->pci_dev; |
| 159 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 160 | /* Driver private data, only for Tx (not command) queues, |
| 161 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 162 | if (id != IWL_CMD_QUEUE_NUM) { |
| 163 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 164 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 165 | if (!txq->txb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 166 | IWL_ERR(priv, "kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 167 | "structures failed\n"); |
| 168 | goto error; |
| 169 | } |
| 170 | } else |
| 171 | txq->txb = NULL; |
| 172 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 173 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 174 | * shared with device */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 175 | txq->tfds39 = pci_alloc_consistent(dev, |
| 176 | sizeof(txq->tfds39[0]) * TFD_QUEUE_SIZE_MAX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 177 | &txq->q.dma_addr); |
| 178 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 179 | if (!txq->tfds39) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 180 | IWL_ERR(priv, "pci_alloc_consistent(%zd) failed\n", |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 181 | sizeof(txq->tfds39[0]) * TFD_QUEUE_SIZE_MAX); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 182 | goto error; |
| 183 | } |
| 184 | txq->q.id = id; |
| 185 | |
| 186 | return 0; |
| 187 | |
| 188 | error: |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 189 | kfree(txq->txb); |
| 190 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 191 | |
| 192 | return -ENOMEM; |
| 193 | } |
| 194 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 195 | /** |
| 196 | * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 197 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 198 | int iwl3945_tx_queue_init(struct iwl_priv *priv, |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 199 | struct iwl_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 200 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 201 | int len, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 202 | int rc = 0; |
| 203 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 204 | /* |
| 205 | * Alloc buffer array for commands (Tx or other types of commands). |
| 206 | * For the command queue (#4), allocate command space + one big |
| 207 | * command for scan, since scan command is very huge; the system will |
| 208 | * not have two scans at the same time, so only one is needed. |
| 209 | * For data Tx queues (all other queues), no super-size command |
| 210 | * space is needed. |
| 211 | */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 212 | len = sizeof(struct iwl_cmd); |
| 213 | for (i = 0; i <= slots_num; i++) { |
| 214 | if (i == slots_num) { |
| 215 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 216 | len += IWL_MAX_SCAN_SIZE; |
| 217 | else |
| 218 | continue; |
| 219 | } |
| 220 | |
| 221 | txq->cmd[i] = kmalloc(len, GFP_KERNEL); |
| 222 | if (!txq->cmd[i]) |
| 223 | goto err; |
| 224 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 225 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 226 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 227 | rc = iwl3945_tx_queue_alloc(priv, txq, txq_id); |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 228 | if (rc) |
| 229 | goto err; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 230 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 231 | txq->need_update = 0; |
| 232 | |
| 233 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 234 | * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 235 | 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] | 236 | |
| 237 | /* Initialize queue high/low-water, head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 238 | 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] | 239 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 240 | /* Tell device where to find queue, enable DMA channel. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 241 | iwl3945_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 242 | |
| 243 | return 0; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 244 | err: |
| 245 | for (i = 0; i < slots_num; i++) { |
| 246 | kfree(txq->cmd[i]); |
| 247 | txq->cmd[i] = NULL; |
| 248 | } |
| 249 | |
| 250 | if (txq_id == IWL_CMD_QUEUE_NUM) { |
| 251 | kfree(txq->cmd[slots_num]); |
| 252 | txq->cmd[slots_num] = NULL; |
| 253 | } |
| 254 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 258 | * iwl3945_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 259 | * @txq: Transmit queue to deallocate. |
| 260 | * |
| 261 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 262 | * Free all buffers. |
| 263 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 264 | */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 265 | 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] | 266 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 267 | struct iwl_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 268 | struct pci_dev *dev = priv->pci_dev; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 269 | int len, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 270 | |
| 271 | if (q->n_bd == 0) |
| 272 | return; |
| 273 | |
| 274 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 275 | for (; q->write_ptr != q->read_ptr; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 276 | 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] | 277 | iwl3945_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 278 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 279 | len = sizeof(struct iwl_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 280 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 281 | len += IWL_MAX_SCAN_SIZE; |
| 282 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 283 | /* De-alloc array of command/tx buffers */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 284 | for (i = 0; i < TFD_TX_CMD_SLOTS; i++) |
| 285 | kfree(txq->cmd[i]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 286 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 287 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 288 | if (txq->q.n_bd) |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 289 | pci_free_consistent(dev, sizeof(struct iwl3945_tfd) * |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 290 | txq->q.n_bd, txq->tfds39, txq->q.dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 291 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 292 | /* De-alloc array of per-TFD driver data */ |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 293 | kfree(txq->txb); |
| 294 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 295 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 296 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 297 | memset(txq, 0, sizeof(*txq)); |
| 298 | } |
| 299 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 300 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 301 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 302 | * the functionality provided here |
| 303 | */ |
| 304 | |
| 305 | /**************************************************************/ |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 306 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 307 | /** |
| 308 | * iwl3945_remove_station - Remove driver's knowledge of station. |
| 309 | * |
| 310 | * NOTE: This does not remove station from device's station table. |
| 311 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 312 | 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] | 313 | { |
| 314 | int index = IWL_INVALID_STATION; |
| 315 | int i; |
| 316 | unsigned long flags; |
| 317 | |
| 318 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 319 | |
| 320 | if (is_ap) |
| 321 | index = IWL_AP_ID; |
| 322 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 323 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 324 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 325 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 326 | if (priv->stations_39[i].used && |
| 327 | !compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 328 | addr)) { |
| 329 | index = i; |
| 330 | break; |
| 331 | } |
| 332 | |
| 333 | if (unlikely(index == IWL_INVALID_STATION)) |
| 334 | goto out; |
| 335 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 336 | if (priv->stations_39[index].used) { |
| 337 | priv->stations_39[index].used = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 338 | priv->num_stations--; |
| 339 | } |
| 340 | |
| 341 | BUG_ON(priv->num_stations < 0); |
| 342 | |
| 343 | out: |
| 344 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 345 | return 0; |
| 346 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 347 | #endif |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 348 | |
| 349 | /** |
| 350 | * iwl3945_clear_stations_table - Clear the driver's station table |
| 351 | * |
| 352 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 353 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 354 | static void iwl3945_clear_stations_table(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 355 | { |
| 356 | unsigned long flags; |
| 357 | |
| 358 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 359 | |
| 360 | priv->num_stations = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 361 | memset(priv->stations_39, 0, sizeof(priv->stations_39)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 362 | |
| 363 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 364 | } |
| 365 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 366 | /** |
| 367 | * iwl3945_add_station - Add station to station tables in driver and device |
| 368 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 369 | 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] | 370 | { |
| 371 | int i; |
| 372 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 373 | struct iwl3945_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 374 | unsigned long flags_spin; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 375 | u8 rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 376 | |
| 377 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 378 | if (is_ap) |
| 379 | index = IWL_AP_ID; |
| 380 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 381 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 382 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 383 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 384 | if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 385 | addr)) { |
| 386 | index = i; |
| 387 | break; |
| 388 | } |
| 389 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 390 | if (!priv->stations_39[i].used && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 391 | index == IWL_INVALID_STATION) |
| 392 | index = i; |
| 393 | } |
| 394 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 395 | /* These two conditions has the same outcome but keep them separate |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 396 | since they have different meaning */ |
| 397 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 398 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 399 | return index; |
| 400 | } |
| 401 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 402 | if (priv->stations_39[index].used && |
| 403 | !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 404 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 405 | return index; |
| 406 | } |
| 407 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 408 | IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 409 | station = &priv->stations_39[index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 410 | station->used = 1; |
| 411 | priv->num_stations++; |
| 412 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 413 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 414 | memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 415 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 416 | station->sta.mode = 0; |
| 417 | station->sta.sta.sta_id = index; |
| 418 | station->sta.station_flags = 0; |
| 419 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 420 | if (priv->band == IEEE80211_BAND_5GHZ) |
Tomas Winkler | 6994633 | 2007-10-25 17:15:27 +0800 | [diff] [blame] | 421 | rate = IWL_RATE_6M_PLCP; |
| 422 | else |
| 423 | rate = IWL_RATE_1M_PLCP; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 424 | |
| 425 | /* Turn on both antennas for the station... */ |
| 426 | station->sta.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 427 | iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 428 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 429 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 430 | |
| 431 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 432 | iwl3945_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 433 | return index; |
| 434 | |
| 435 | } |
| 436 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 437 | |
| 438 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 439 | |
Abhijeet Kolekar | c305606 | 2008-11-12 13:14:08 -0800 | [diff] [blame] | 440 | #define IWL_CMD(x) case x: return #x |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 441 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 442 | |
| 443 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 444 | * iwl3945_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 445 | * @priv: device private data point |
| 446 | * @cmd: a point to the ucode command structure |
| 447 | * |
| 448 | * The function returns < 0 values to indicate the operation is |
| 449 | * failed. On success, it turns the index (> 0) of command in the |
| 450 | * command queue. |
| 451 | */ |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 452 | 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] | 453 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 454 | struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 455 | struct iwl_queue *q = &txq->q; |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 456 | struct iwl3945_tfd *tfd; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 457 | struct iwl_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 458 | u32 idx; |
| 459 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 460 | dma_addr_t phys_addr; |
| 461 | int pad; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 462 | int ret, len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 463 | unsigned long flags; |
| 464 | |
| 465 | /* If any of the command structures end up being larger than |
| 466 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 467 | * we will need to increase the size of the TFD entries */ |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 468 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 469 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 470 | |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 471 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 472 | if (iwl_is_rfkill(priv)) { |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 473 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 474 | return -EIO; |
| 475 | } |
| 476 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 477 | if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 478 | IWL_ERR(priv, "No space for Tx\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 479 | return -ENOSPC; |
| 480 | } |
| 481 | |
| 482 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 483 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 484 | tfd = &txq->tfds39[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 485 | memset(tfd, 0, sizeof(*tfd)); |
| 486 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 487 | 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] | 488 | out_cmd = txq->cmd[idx]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 489 | |
| 490 | out_cmd->hdr.cmd = cmd->id; |
| 491 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 492 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 493 | |
| 494 | /* At this point, the out_cmd now has all of the incoming cmd |
| 495 | * information */ |
| 496 | |
| 497 | out_cmd->hdr.flags = 0; |
| 498 | 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] | 499 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 500 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 501 | out_cmd->hdr.sequence |= SEQ_HUGE_FRAME; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 502 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 503 | len = (idx == TFD_CMD_SLOTS) ? |
| 504 | IWL_MAX_SCAN_SIZE : sizeof(struct iwl_cmd); |
| 505 | |
| 506 | phys_addr = pci_map_single(priv->pci_dev, out_cmd, |
| 507 | len, PCI_DMA_TODEVICE); |
| 508 | pci_unmap_addr_set(&out_cmd->meta, mapping, phys_addr); |
| 509 | pci_unmap_len_set(&out_cmd->meta, len, len); |
| 510 | phys_addr += offsetof(struct iwl_cmd, hdr); |
| 511 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 512 | 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] | 513 | |
| 514 | pad = U32_PAD(cmd->len); |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 515 | tfd->control_flags |= cpu_to_le32(TFD_CTL_PAD_SET(pad)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 516 | |
| 517 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 518 | "%d bytes at %d[%d]:%d\n", |
| 519 | get_cmd_string(out_cmd->hdr.cmd), |
| 520 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 521 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 522 | |
| 523 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 524 | |
| 525 | /* Increment and update queue's write index */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 526 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Samuel Ortiz | 4f3602c | 2009-01-19 15:30:25 -0800 | [diff] [blame^] | 527 | ret = iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 528 | |
| 529 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 530 | return ret ? ret : idx; |
| 531 | } |
| 532 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 533 | static int iwl3945_send_cmd_async(struct iwl_priv *priv, |
| 534 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 535 | { |
| 536 | int ret; |
| 537 | |
| 538 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 539 | |
| 540 | /* An asynchronous command can not expect an SKB to be set. */ |
| 541 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 542 | |
| 543 | /* An asynchronous command MUST have a callback. */ |
| 544 | BUG_ON(!cmd->meta.u.callback); |
| 545 | |
| 546 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 547 | return -EBUSY; |
| 548 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 549 | ret = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 550 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 551 | IWL_ERR(priv, |
| 552 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 553 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 554 | return ret; |
| 555 | } |
| 556 | return 0; |
| 557 | } |
| 558 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 559 | static int iwl3945_send_cmd_sync(struct iwl_priv *priv, |
| 560 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 561 | { |
| 562 | int cmd_idx; |
| 563 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 564 | |
| 565 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 566 | |
| 567 | /* A synchronous command can not have a callback set. */ |
| 568 | BUG_ON(cmd->meta.u.callback != NULL); |
| 569 | |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 570 | if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 571 | IWL_ERR(priv, |
| 572 | "Error sending %s: Already sending a host command\n", |
| 573 | get_cmd_string(cmd->id)); |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 574 | ret = -EBUSY; |
| 575 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 579 | |
| 580 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 581 | cmd->meta.source = &cmd->meta; |
| 582 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 583 | cmd_idx = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 584 | if (cmd_idx < 0) { |
| 585 | ret = cmd_idx; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 586 | IWL_ERR(priv, |
| 587 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 588 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 589 | goto out; |
| 590 | } |
| 591 | |
| 592 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 593 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 594 | HOST_COMPLETE_TIMEOUT); |
| 595 | if (!ret) { |
| 596 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 597 | IWL_ERR(priv, "Error sending %s: time out after %dms\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 598 | get_cmd_string(cmd->id), |
| 599 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 600 | |
| 601 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 602 | ret = -ETIMEDOUT; |
| 603 | goto cancel; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 608 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 609 | get_cmd_string(cmd->id)); |
| 610 | ret = -ECANCELED; |
| 611 | goto fail; |
| 612 | } |
| 613 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 614 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 615 | get_cmd_string(cmd->id)); |
| 616 | ret = -EIO; |
| 617 | goto fail; |
| 618 | } |
| 619 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 620 | IWL_ERR(priv, "Error: Response NULL in '%s'\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 621 | get_cmd_string(cmd->id)); |
| 622 | ret = -EIO; |
Zhu Yi | 73e1a65 | 2009-01-08 10:19:58 -0800 | [diff] [blame] | 623 | goto cancel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | ret = 0; |
| 627 | goto out; |
| 628 | |
| 629 | cancel: |
| 630 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 631 | struct iwl_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 632 | |
| 633 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 634 | * TX cmd queue. Otherwise in case the cmd comes |
| 635 | * in later, it will possibly set an invalid |
| 636 | * address (cmd->meta.source). */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 637 | qcmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 638 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 639 | } |
| 640 | fail: |
| 641 | if (cmd->meta.u.skb) { |
| 642 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 643 | cmd->meta.u.skb = NULL; |
| 644 | } |
| 645 | out: |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 646 | clear_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 647 | return ret; |
| 648 | } |
| 649 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 650 | 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] | 651 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 652 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 653 | return iwl3945_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 654 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 655 | return iwl3945_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 658 | 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] | 659 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 660 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 661 | .id = id, |
| 662 | .len = len, |
| 663 | .data = data, |
| 664 | }; |
| 665 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 666 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 669 | 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] | 670 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 671 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 672 | .id = id, |
| 673 | .len = sizeof(val), |
| 674 | .data = &val, |
| 675 | }; |
| 676 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 677 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 680 | int iwl3945_send_statistics_request(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 681 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 682 | return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 686 | * 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] | 687 | * @band: 2.4 or 5 GHz band |
| 688 | * @channel: Any channel valid for the requested band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 689 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 690 | * In addition to setting the staging RXON, priv->band is also set. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 691 | * |
| 692 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 693 | * in the staging RXON flag structure based on the band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 694 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 695 | static int iwl3945_set_rxon_channel(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 696 | enum ieee80211_band band, |
| 697 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 698 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 699 | if (!iwl3945_get_channel_info(priv, band, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 700 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 701 | channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 702 | return -EINVAL; |
| 703 | } |
| 704 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 705 | if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 706 | (priv->band == band)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 707 | return 0; |
| 708 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 709 | priv->staging39_rxon.channel = cpu_to_le16(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 710 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 711 | priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 712 | else |
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 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 715 | priv->band = band; |
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 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 718 | |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 723 | * iwl3945_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 724 | * |
| 725 | * NOTE: This is really only useful during development and can eventually |
| 726 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 727 | * making changes |
| 728 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 729 | static int iwl3945_check_rxon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 730 | { |
| 731 | int error = 0; |
| 732 | int counter = 1; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 733 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 734 | |
| 735 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 736 | error |= le32_to_cpu(rxon->flags & |
| 737 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 738 | RXON_FLG_RADAR_DETECT_MSK)); |
| 739 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 740 | IWL_WARN(priv, "check 24G fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 741 | counter++, error); |
| 742 | } else { |
| 743 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 744 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 745 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 746 | IWL_WARN(priv, "check 52 fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 747 | counter++, error); |
| 748 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 749 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 750 | IWL_WARN(priv, "check 52 CCK %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 751 | counter++, error); |
| 752 | } |
| 753 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 754 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 755 | IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 756 | |
| 757 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 758 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 759 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 760 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 761 | IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 762 | |
| 763 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 764 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 765 | IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 766 | |
| 767 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 768 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 769 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 770 | IWL_WARN(priv, "check CCK and short slot %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 771 | counter++, error); |
| 772 | |
| 773 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 774 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 775 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 776 | IWL_WARN(priv, "check CCK & auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 777 | counter++, error); |
| 778 | |
| 779 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 780 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 781 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 782 | IWL_WARN(priv, "check TGG and auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 783 | counter++, error); |
| 784 | |
| 785 | if ((rxon->flags & RXON_FLG_DIS_DIV_MSK)) |
| 786 | error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK | |
| 787 | RXON_FLG_ANT_A_MSK)) == 0); |
| 788 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 789 | IWL_WARN(priv, "check antenna %d %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 790 | |
| 791 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 792 | IWL_WARN(priv, "Tuning to channel %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 793 | le16_to_cpu(rxon->channel)); |
| 794 | |
| 795 | if (error) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 796 | IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 797 | return -1; |
| 798 | } |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 803 | * 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] | 804 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 805 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 806 | * If the RXON structure is changing enough to require a new tune, |
| 807 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 808 | * 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] | 809 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 810 | static int iwl3945_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 811 | { |
| 812 | |
| 813 | /* These items are only settable from the full RXON command */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 814 | if (!(iwl3945_is_associated(priv)) || |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 815 | compare_ether_addr(priv->staging39_rxon.bssid_addr, |
| 816 | priv->active39_rxon.bssid_addr) || |
| 817 | compare_ether_addr(priv->staging39_rxon.node_addr, |
| 818 | priv->active39_rxon.node_addr) || |
| 819 | compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr, |
| 820 | priv->active39_rxon.wlap_bssid_addr) || |
| 821 | (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) || |
| 822 | (priv->staging39_rxon.channel != priv->active39_rxon.channel) || |
| 823 | (priv->staging39_rxon.air_propagation != |
| 824 | priv->active39_rxon.air_propagation) || |
| 825 | (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 826 | return 1; |
| 827 | |
| 828 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 829 | * be updated with the RXON_ASSOC command -- however only some |
| 830 | * flag transitions are allowed using RXON_ASSOC */ |
| 831 | |
| 832 | /* Check if we are not switching bands */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 833 | if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 834 | (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 835 | return 1; |
| 836 | |
| 837 | /* Check if we are switching association toggle */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 838 | if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 839 | (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 840 | return 1; |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 845 | static int iwl3945_send_rxon_assoc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 846 | { |
| 847 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 848 | struct iwl_rx_packet *res = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 849 | struct iwl3945_rxon_assoc_cmd rxon_assoc; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 850 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 851 | .id = REPLY_RXON_ASSOC, |
| 852 | .len = sizeof(rxon_assoc), |
| 853 | .meta.flags = CMD_WANT_SKB, |
| 854 | .data = &rxon_assoc, |
| 855 | }; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 856 | const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon; |
| 857 | const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 858 | |
| 859 | if ((rxon1->flags == rxon2->flags) && |
| 860 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 861 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 862 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 863 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 864 | return 0; |
| 865 | } |
| 866 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 867 | rxon_assoc.flags = priv->staging39_rxon.flags; |
| 868 | rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags; |
| 869 | rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates; |
| 870 | rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 871 | rxon_assoc.reserved = 0; |
| 872 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 873 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 874 | if (rc) |
| 875 | return rc; |
| 876 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 877 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 878 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 879 | IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 880 | rc = -EIO; |
| 881 | } |
| 882 | |
| 883 | priv->alloc_rxb_skb--; |
| 884 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 885 | |
| 886 | return rc; |
| 887 | } |
| 888 | |
| 889 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 890 | * iwl3945_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 891 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 892 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 893 | * the active_rxon structure is updated with the new data. This |
| 894 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 895 | * a HW tune is required based on the RXON structure changes. |
| 896 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 897 | static int iwl3945_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 898 | { |
| 899 | /* cast away the const for active_rxon in this function */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 900 | struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 901 | int rc = 0; |
| 902 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 903 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 904 | return -1; |
| 905 | |
| 906 | /* always get timestamp with Rx frame */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 907 | priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 908 | |
| 909 | /* select antenna */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 910 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 911 | ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 912 | priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 913 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 914 | rc = iwl3945_check_rxon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 915 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 916 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 917 | return -EINVAL; |
| 918 | } |
| 919 | |
| 920 | /* 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] | 921 | * iwl3945_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 922 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 923 | if (!iwl3945_full_rxon_required(priv)) { |
| 924 | rc = iwl3945_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 925 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 926 | IWL_ERR(priv, "Error setting RXON_ASSOC " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 927 | "configuration (%d).\n", rc); |
| 928 | return rc; |
| 929 | } |
| 930 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 931 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 932 | |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | /* If we are currently associated and the new config requires |
| 937 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 938 | * we must clear the associated from the active configuration |
| 939 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 940 | if (iwl3945_is_associated(priv) && |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 941 | (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 942 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 943 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 944 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 945 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
| 946 | sizeof(struct iwl3945_rxon_cmd), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 947 | &priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 948 | |
| 949 | /* If the mask clearing failed then we set |
| 950 | * active_rxon back to what it was previously */ |
| 951 | if (rc) { |
| 952 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 953 | IWL_ERR(priv, "Error clearing ASSOC_MSK on current " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 954 | "configuration (%d).\n", rc); |
| 955 | return rc; |
| 956 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | IWL_DEBUG_INFO("Sending RXON\n" |
| 960 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 961 | "* channel = %d\n" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 962 | "* bssid = %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 963 | ((priv->staging39_rxon.filter_flags & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 964 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 965 | le16_to_cpu(priv->staging39_rxon.channel), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 966 | priv->staging_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 967 | |
| 968 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 969 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 970 | sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 971 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 972 | IWL_ERR(priv, "Error setting new configuration (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 973 | return rc; |
| 974 | } |
| 975 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 976 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 977 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 978 | iwl3945_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 979 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 980 | /* If we issue a new RXON command which required a tune then we must |
| 981 | * 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] | 982 | rc = iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 983 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 984 | IWL_ERR(priv, "Error setting Tx power (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 985 | return rc; |
| 986 | } |
| 987 | |
| 988 | /* Add the broadcast address so we can send broadcast frames */ |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 989 | if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 990 | IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 991 | IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 992 | return -EIO; |
| 993 | } |
| 994 | |
| 995 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 996 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 997 | if (iwl3945_is_associated(priv) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 998 | (priv->iw_mode == NL80211_IFTYPE_STATION)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 999 | if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1000 | == IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1001 | IWL_ERR(priv, "Error adding AP address for transmit\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1002 | return -EIO; |
| 1003 | } |
| 1004 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1005 | /* Init the hardware's rate fallback order based on the band */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1006 | rc = iwl3945_init_hw_rate_table(priv); |
| 1007 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1008 | IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1009 | return -EIO; |
| 1010 | } |
| 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1015 | static int iwl3945_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1016 | { |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1017 | struct iwl_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1018 | .flags = 3, |
| 1019 | .lead_time = 0xAA, |
| 1020 | .max_kill = 1, |
| 1021 | .kill_ack_mask = 0, |
| 1022 | .kill_cts_mask = 0, |
| 1023 | }; |
| 1024 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1025 | return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1026 | sizeof(bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1029 | static int iwl3945_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1030 | { |
| 1031 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1032 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1033 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1034 | .id = REPLY_SCAN_ABORT_CMD, |
| 1035 | .meta.flags = CMD_WANT_SKB, |
| 1036 | }; |
| 1037 | |
| 1038 | /* If there isn't a scan actively going on in the hardware |
| 1039 | * then we are in between scan bands and not actually |
| 1040 | * actively scanning, so don't send the abort command */ |
| 1041 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1042 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1046 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1047 | if (rc) { |
| 1048 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1049 | return rc; |
| 1050 | } |
| 1051 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1052 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1053 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1054 | /* The scan abort will return 1 for success or |
| 1055 | * 2 for "failure". A failure condition can be |
| 1056 | * due to simply not being in an active scan which |
| 1057 | * can occur if we send the scan abort before we |
| 1058 | * the microcode has notified us that a scan is |
| 1059 | * completed. */ |
| 1060 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1061 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1062 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1063 | } |
| 1064 | |
| 1065 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1066 | |
| 1067 | return rc; |
| 1068 | } |
| 1069 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1070 | static int iwl3945_add_sta_sync_callback(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1071 | struct iwl_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1072 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1073 | struct iwl_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1074 | |
| 1075 | if (!skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1076 | IWL_ERR(priv, "Error: Response NULL in REPLY_ADD_STA.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1077 | return 1; |
| 1078 | } |
| 1079 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1080 | res = (struct iwl_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1081 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1082 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1083 | res->hdr.flags); |
| 1084 | return 1; |
| 1085 | } |
| 1086 | |
| 1087 | switch (res->u.add_sta.status) { |
| 1088 | case ADD_STA_SUCCESS_MSK: |
| 1089 | break; |
| 1090 | default: |
| 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | /* We didn't cache the SKB; let the caller free it */ |
| 1095 | return 1; |
| 1096 | } |
| 1097 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1098 | int iwl3945_send_add_station(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1099 | struct iwl3945_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1100 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1101 | struct iwl_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1102 | int rc = 0; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1103 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1104 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1105 | .len = sizeof(struct iwl3945_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1106 | .meta.flags = flags, |
| 1107 | .data = sta, |
| 1108 | }; |
| 1109 | |
| 1110 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1111 | cmd.meta.u.callback = iwl3945_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1112 | else |
| 1113 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1114 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1115 | rc = iwl3945_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1116 | |
| 1117 | if (rc || (flags & CMD_ASYNC)) |
| 1118 | return rc; |
| 1119 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1120 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1122 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1123 | res->hdr.flags); |
| 1124 | rc = -EIO; |
| 1125 | } |
| 1126 | |
| 1127 | if (rc == 0) { |
| 1128 | switch (res->u.add_sta.status) { |
| 1129 | case ADD_STA_SUCCESS_MSK: |
| 1130 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1131 | break; |
| 1132 | default: |
| 1133 | rc = -EIO; |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1134 | IWL_WARN(priv, "REPLY_ADD_STA failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1135 | break; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | priv->alloc_rxb_skb--; |
| 1140 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1141 | |
| 1142 | return rc; |
| 1143 | } |
| 1144 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1145 | static int iwl3945_update_sta_key_info(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1146 | struct ieee80211_key_conf *keyconf, |
| 1147 | u8 sta_id) |
| 1148 | { |
| 1149 | unsigned long flags; |
| 1150 | __le16 key_flags = 0; |
| 1151 | |
| 1152 | switch (keyconf->alg) { |
| 1153 | case ALG_CCMP: |
| 1154 | key_flags |= STA_KEY_FLG_CCMP; |
| 1155 | key_flags |= cpu_to_le16( |
| 1156 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1157 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1158 | break; |
| 1159 | case ALG_TKIP: |
| 1160 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1161 | default: |
| 1162 | return -EINVAL; |
| 1163 | } |
| 1164 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1165 | priv->stations_39[sta_id].keyinfo.alg = keyconf->alg; |
| 1166 | priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1167 | memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1168 | keyconf->keylen); |
| 1169 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1170 | memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1171 | keyconf->keylen); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1172 | priv->stations_39[sta_id].sta.key.key_flags = key_flags; |
| 1173 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1174 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1175 | |
| 1176 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1177 | |
| 1178 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1179 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1180 | return 0; |
| 1181 | } |
| 1182 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1183 | 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] | 1184 | { |
| 1185 | unsigned long flags; |
| 1186 | |
| 1187 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1188 | memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key)); |
| 1189 | memset(&priv->stations_39[sta_id].sta.key, 0, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1190 | sizeof(struct iwl4965_keyinfo)); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1191 | priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1192 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1193 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1194 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1195 | |
| 1196 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1197 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1198 | return 0; |
| 1199 | } |
| 1200 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1201 | static void iwl3945_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1202 | { |
| 1203 | struct list_head *element; |
| 1204 | |
| 1205 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1206 | priv->frames_count); |
| 1207 | |
| 1208 | while (!list_empty(&priv->free_frames)) { |
| 1209 | element = priv->free_frames.next; |
| 1210 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1211 | kfree(list_entry(element, struct iwl3945_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1212 | priv->frames_count--; |
| 1213 | } |
| 1214 | |
| 1215 | if (priv->frames_count) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1216 | 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] | 1217 | priv->frames_count); |
| 1218 | priv->frames_count = 0; |
| 1219 | } |
| 1220 | } |
| 1221 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1222 | static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1223 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1224 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1225 | struct list_head *element; |
| 1226 | if (list_empty(&priv->free_frames)) { |
| 1227 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1228 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1229 | IWL_ERR(priv, "Could not allocate frame!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1230 | return NULL; |
| 1231 | } |
| 1232 | |
| 1233 | priv->frames_count++; |
| 1234 | return frame; |
| 1235 | } |
| 1236 | |
| 1237 | element = priv->free_frames.next; |
| 1238 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1239 | return list_entry(element, struct iwl3945_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1242 | 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] | 1243 | { |
| 1244 | memset(frame, 0, sizeof(*frame)); |
| 1245 | list_add(&frame->list, &priv->free_frames); |
| 1246 | } |
| 1247 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1248 | unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1249 | struct ieee80211_hdr *hdr, |
Rami Rosen | 73ec1cc | 2008-12-16 09:37:07 +0200 | [diff] [blame] | 1250 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1251 | { |
| 1252 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1253 | if (!iwl3945_is_associated(priv) || !priv->ibss_beacon || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1254 | ((priv->iw_mode != NL80211_IFTYPE_ADHOC) && |
| 1255 | (priv->iw_mode != NL80211_IFTYPE_AP))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1256 | return 0; |
| 1257 | |
| 1258 | if (priv->ibss_beacon->len > left) |
| 1259 | return 0; |
| 1260 | |
| 1261 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1262 | |
| 1263 | return priv->ibss_beacon->len; |
| 1264 | } |
| 1265 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1266 | static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1267 | { |
| 1268 | u8 i; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1269 | int rate_mask; |
| 1270 | |
| 1271 | /* Set rate mask*/ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1272 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1273 | rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1274 | else |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1275 | rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1276 | |
| 1277 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1278 | i = iwl3945_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1279 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1280 | return iwl3945_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1283 | /* No valid rate was found. Assign the lowest one */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1284 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1285 | return IWL_RATE_1M_PLCP; |
| 1286 | else |
| 1287 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1290 | static int iwl3945_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1291 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1292 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1293 | unsigned int frame_size; |
| 1294 | int rc; |
| 1295 | u8 rate; |
| 1296 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1297 | frame = iwl3945_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1298 | |
| 1299 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1300 | IWL_ERR(priv, "Could not obtain free frame buffer for beacon " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1301 | "command.\n"); |
| 1302 | return -ENOMEM; |
| 1303 | } |
| 1304 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1305 | rate = iwl3945_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1306 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1307 | frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); |
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 | rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1310 | &frame->u.cmd[0]); |
| 1311 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1312 | iwl3945_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1313 | |
| 1314 | return rc; |
| 1315 | } |
| 1316 | |
| 1317 | /****************************************************************************** |
| 1318 | * |
| 1319 | * EEPROM related functions |
| 1320 | * |
| 1321 | ******************************************************************************/ |
| 1322 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1323 | static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1324 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1325 | memcpy(mac, priv->eeprom39.mac_address, 6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1328 | /* |
| 1329 | * Clear the OWNER_MSK, to establish driver (instead of uCode running on |
| 1330 | * embedded controller) as EEPROM reader; each read is a series of pulses |
| 1331 | * to/from the EEPROM chip, not a single event, so even reads could conflict |
| 1332 | * if they weren't arbitrated by some ownership mechanism. Here, the driver |
| 1333 | * simply claims ownership, which should be safe when this function is called |
| 1334 | * (i.e. before loading uCode!). |
| 1335 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1336 | static inline int iwl3945_eeprom_acquire_semaphore(struct iwl_priv *priv) |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1337 | { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1338 | _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] | 1339 | return 0; |
| 1340 | } |
| 1341 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1342 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1343 | * iwl3945_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1344 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1345 | * Load the EEPROM contents from adapter into priv->eeprom39 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1346 | * |
| 1347 | * NOTE: This routine uses the non-debug IO access functions. |
| 1348 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1349 | int iwl3945_eeprom_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1350 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1351 | u16 *e = (u16 *)&priv->eeprom39; |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1352 | u32 gp = iwl_read32(priv, CSR_EEPROM_GP); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1353 | int sz = sizeof(priv->eeprom39); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1354 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1355 | u16 addr; |
| 1356 | |
| 1357 | /* The EEPROM structure has several padding buffers within it |
| 1358 | * and when adding new EEPROM maps is subject to programmer errors |
| 1359 | * which may be very difficult to identify without explicitly |
| 1360 | * checking the resulting size of the eeprom map. */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1361 | BUILD_BUG_ON(sizeof(priv->eeprom39) != IWL_EEPROM_IMAGE_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1362 | |
| 1363 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1364 | IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1365 | return -ENOENT; |
| 1366 | } |
| 1367 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1368 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1369 | ret = iwl3945_eeprom_acquire_semaphore(priv); |
| 1370 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1371 | IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1372 | return -ENOENT; |
| 1373 | } |
| 1374 | |
| 1375 | /* eeprom is an array of 16bit values */ |
| 1376 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1377 | u32 r; |
| 1378 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1379 | _iwl_write32(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1380 | CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1381 | _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
| 1382 | ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1383 | CSR_EEPROM_REG_READ_VALID_MSK, |
| 1384 | IWL_EEPROM_ACCESS_TIMEOUT); |
| 1385 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1386 | IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1387 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1388 | } |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1389 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1390 | r = _iwl_read_direct32(priv, CSR_EEPROM_REG); |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1391 | e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | return 0; |
| 1395 | } |
| 1396 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1397 | static void iwl3945_unset_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1398 | { |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1399 | if (priv->shared_virt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1400 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1401 | sizeof(struct iwl3945_shared), |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1402 | priv->shared_virt, |
| 1403 | priv->shared_phys); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1407 | * 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] | 1408 | * |
| 1409 | * return : set the bit for each supported rate insert in ie |
| 1410 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1411 | static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1412 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1413 | { |
| 1414 | u16 ret_rates = 0, bit; |
| 1415 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1416 | u8 *cnt = ie; |
| 1417 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1418 | |
| 1419 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1420 | if (bit & supported_rate) { |
| 1421 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1422 | rates[*cnt] = iwl3945_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1423 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1424 | (*cnt)++; |
| 1425 | (*left)--; |
| 1426 | if ((*left <= 0) || |
| 1427 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1428 | break; |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | return ret_rates; |
| 1433 | } |
| 1434 | |
| 1435 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1436 | * 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] | 1437 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1438 | static u16 iwl3945_fill_probe_req(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1439 | struct ieee80211_mgmt *frame, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 1440 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1441 | { |
| 1442 | int len = 0; |
| 1443 | u8 *pos = NULL; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1444 | u16 active_rates, ret_rates, cck_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1445 | |
| 1446 | /* Make sure there is enough space for the probe request, |
| 1447 | * two mandatory IEs and the data */ |
| 1448 | left -= 24; |
| 1449 | if (left < 0) |
| 1450 | return 0; |
| 1451 | len += 24; |
| 1452 | |
| 1453 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1454 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1455 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1456 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1457 | frame->seq_ctrl = 0; |
| 1458 | |
| 1459 | /* fill in our indirect SSID IE */ |
| 1460 | /* ...next IE... */ |
| 1461 | |
| 1462 | left -= 2; |
| 1463 | if (left < 0) |
| 1464 | return 0; |
| 1465 | len += 2; |
| 1466 | pos = &(frame->u.probe_req.variable[0]); |
| 1467 | *pos++ = WLAN_EID_SSID; |
| 1468 | *pos++ = 0; |
| 1469 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1470 | /* fill in supported rate */ |
| 1471 | /* ...next IE... */ |
| 1472 | left -= 2; |
| 1473 | if (left < 0) |
| 1474 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1475 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1476 | /* ... fill it in... */ |
| 1477 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1478 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1479 | |
| 1480 | priv->active_rate = priv->rates_mask; |
| 1481 | active_rates = priv->active_rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1482 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 1483 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1484 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1485 | ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1486 | priv->active_rate_basic, &left); |
| 1487 | active_rates &= ~ret_rates; |
| 1488 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1489 | ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1490 | priv->active_rate_basic, &left); |
| 1491 | active_rates &= ~ret_rates; |
| 1492 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1493 | len += 2 + *pos; |
| 1494 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1495 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1496 | goto fill_end; |
| 1497 | |
| 1498 | /* fill in supported extended rate */ |
| 1499 | /* ...next IE... */ |
| 1500 | left -= 2; |
| 1501 | if (left < 0) |
| 1502 | return 0; |
| 1503 | /* ... fill it in... */ |
| 1504 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1505 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1506 | iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1507 | priv->active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1508 | if (*pos > 0) |
| 1509 | len += 2 + *pos; |
| 1510 | |
| 1511 | fill_end: |
| 1512 | return (u16)len; |
| 1513 | } |
| 1514 | |
| 1515 | /* |
| 1516 | * QoS support |
| 1517 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1518 | static int iwl3945_send_qos_params_command(struct iwl_priv *priv, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1519 | struct iwl_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1520 | { |
| 1521 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1522 | return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1523 | sizeof(struct iwl_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1526 | static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1527 | { |
| 1528 | unsigned long flags; |
| 1529 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1530 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1531 | return; |
| 1532 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1533 | spin_lock_irqsave(&priv->lock, flags); |
| 1534 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1535 | |
| 1536 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1537 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1538 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1539 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
| 1540 | |
| 1541 | if (priv->qos_data.qos_active) |
| 1542 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1543 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1544 | |
| 1545 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1546 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1547 | if (force || iwl3945_is_associated(priv)) { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1548 | IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1549 | priv->qos_data.qos_active); |
| 1550 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1551 | iwl3945_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1552 | &(priv->qos_data.def_qos_parm)); |
| 1553 | } |
| 1554 | } |
| 1555 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1556 | /* |
| 1557 | * Power management (not Tx power!) functions |
| 1558 | */ |
| 1559 | #define MSEC_TO_USEC 1024 |
| 1560 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1561 | |
| 1562 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 1563 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1564 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 1565 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 1566 | __constant_cpu_to_le32(X1), \ |
| 1567 | __constant_cpu_to_le32(X2), \ |
| 1568 | __constant_cpu_to_le32(X3), \ |
| 1569 | __constant_cpu_to_le32(X4)} |
| 1570 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1571 | /* default power management (not Tx power) table values */ |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1572 | /* for TIM 0-10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1573 | static struct iwl_power_vec_entry range_0[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1574 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1575 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 1576 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 1577 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 1578 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 1579 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 1580 | }; |
| 1581 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1582 | /* for TIM > 10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1583 | static struct iwl_power_vec_entry range_1[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1584 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1585 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 1586 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 1587 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 1588 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 1589 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 1590 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 1591 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 1592 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 1593 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 1594 | }; |
| 1595 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1596 | int iwl3945_power_init_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1597 | { |
| 1598 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1599 | struct iwl3945_power_mgr *pow_data; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1600 | int size = sizeof(struct iwl_power_vec_entry) * IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1601 | u16 pci_pm; |
| 1602 | |
| 1603 | IWL_DEBUG_POWER("Initialize power \n"); |
| 1604 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1605 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1606 | |
| 1607 | memset(pow_data, 0, sizeof(*pow_data)); |
| 1608 | |
| 1609 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 1610 | pow_data->dtim_val = 0xffff; |
| 1611 | |
| 1612 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 1613 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 1614 | |
| 1615 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 1616 | if (rc != 0) |
| 1617 | return 0; |
| 1618 | else { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1619 | struct iwl_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1620 | |
| 1621 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 1622 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1623 | for (i = 0; i < IWL39_POWER_AC; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1624 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 1625 | |
| 1626 | if (pci_pm & 0x1) |
| 1627 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 1628 | else |
| 1629 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 1630 | } |
| 1631 | } |
| 1632 | return rc; |
| 1633 | } |
| 1634 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1635 | static int iwl3945_update_power_cmd(struct iwl_priv *priv, |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1636 | struct iwl_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1637 | { |
| 1638 | int rc = 0, i; |
| 1639 | u8 skip; |
| 1640 | u32 max_sleep = 0; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1641 | struct iwl_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1642 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1643 | struct iwl3945_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1644 | |
| 1645 | if (mode > IWL_POWER_INDEX_5) { |
| 1646 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 1647 | return -1; |
| 1648 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1649 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1650 | |
| 1651 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 1652 | range = &pow_data->pwr_range_0[0]; |
| 1653 | else |
| 1654 | range = &pow_data->pwr_range_1[1]; |
| 1655 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1656 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1657 | |
| 1658 | #ifdef IWL_MAC80211_DISABLE |
| 1659 | if (priv->assoc_network != NULL) { |
| 1660 | unsigned long flags; |
| 1661 | |
| 1662 | period = priv->assoc_network->tim.tim_period; |
| 1663 | } |
| 1664 | #endif /*IWL_MAC80211_DISABLE */ |
| 1665 | skip = range[mode].no_dtim; |
| 1666 | |
| 1667 | if (period == 0) { |
| 1668 | period = 1; |
| 1669 | skip = 0; |
| 1670 | } |
| 1671 | |
| 1672 | if (skip == 0) { |
| 1673 | max_sleep = period; |
| 1674 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1675 | } else { |
| 1676 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 1677 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 1678 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1679 | } |
| 1680 | |
| 1681 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 1682 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 1683 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 1684 | } |
| 1685 | |
| 1686 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 1687 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 1688 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 1689 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 1690 | le32_to_cpu(cmd->sleep_interval[0]), |
| 1691 | le32_to_cpu(cmd->sleep_interval[1]), |
| 1692 | le32_to_cpu(cmd->sleep_interval[2]), |
| 1693 | le32_to_cpu(cmd->sleep_interval[3]), |
| 1694 | le32_to_cpu(cmd->sleep_interval[4])); |
| 1695 | |
| 1696 | return rc; |
| 1697 | } |
| 1698 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1699 | static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1700 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 1701 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1702 | int rc; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1703 | struct iwl_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1704 | |
| 1705 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1706 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1707 | * else user level */ |
| 1708 | switch (mode) { |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1709 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1710 | final_mode = IWL_POWER_INDEX_3; |
| 1711 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1712 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1713 | final_mode = IWL_POWER_MODE_CAM; |
| 1714 | break; |
| 1715 | default: |
| 1716 | final_mode = mode; |
| 1717 | break; |
| 1718 | } |
| 1719 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1720 | iwl3945_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1721 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1722 | /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */ |
| 1723 | rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, |
| 1724 | sizeof(struct iwl3945_powertable_cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1725 | |
| 1726 | if (final_mode == IWL_POWER_MODE_CAM) |
| 1727 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 1728 | else |
| 1729 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 1730 | |
| 1731 | return rc; |
| 1732 | } |
| 1733 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1734 | #define MAX_UCODE_BEACON_INTERVAL 1024 |
| 1735 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1736 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1737 | static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1738 | { |
| 1739 | u16 new_val = 0; |
| 1740 | u16 beacon_factor = 0; |
| 1741 | |
| 1742 | beacon_factor = |
| 1743 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1744 | / MAX_UCODE_BEACON_INTERVAL; |
| 1745 | new_val = beacon_val / beacon_factor; |
| 1746 | |
| 1747 | return cpu_to_le16(new_val); |
| 1748 | } |
| 1749 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1750 | static void iwl3945_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1751 | { |
| 1752 | u64 interval_tm_unit; |
| 1753 | u64 tsf, result; |
| 1754 | unsigned long flags; |
| 1755 | struct ieee80211_conf *conf = NULL; |
| 1756 | u16 beacon_int = 0; |
| 1757 | |
| 1758 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1759 | |
| 1760 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1761 | priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1762 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1763 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1764 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1765 | |
| 1766 | beacon_int = priv->beacon_int; |
| 1767 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1768 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1769 | if (priv->iw_mode == NL80211_IFTYPE_STATION) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1770 | if (beacon_int == 0) { |
| 1771 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1772 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1773 | } else { |
| 1774 | priv->rxon_timing.beacon_interval = |
| 1775 | cpu_to_le16(beacon_int); |
| 1776 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1777 | iwl3945_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1778 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1779 | } |
| 1780 | |
| 1781 | priv->rxon_timing.atim_window = 0; |
| 1782 | } else { |
| 1783 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1784 | iwl3945_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1785 | /* TODO: we need to get atim_window from upper stack |
| 1786 | * for now we set to 0 */ |
| 1787 | priv->rxon_timing.atim_window = 0; |
| 1788 | } |
| 1789 | |
| 1790 | interval_tm_unit = |
| 1791 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1792 | result = do_div(tsf, interval_tm_unit); |
| 1793 | priv->rxon_timing.beacon_init_val = |
| 1794 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1795 | |
| 1796 | IWL_DEBUG_ASSOC |
| 1797 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1798 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1799 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1800 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1801 | } |
| 1802 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1803 | static int iwl3945_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1804 | { |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 1805 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1806 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1807 | return -EIO; |
| 1808 | } |
| 1809 | |
| 1810 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1811 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1812 | return -EAGAIN; |
| 1813 | } |
| 1814 | |
| 1815 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1816 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1817 | "Queuing.\n"); |
| 1818 | return -EAGAIN; |
| 1819 | } |
| 1820 | |
| 1821 | IWL_DEBUG_INFO("Starting scan...\n"); |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 1822 | if (priv->cfg->sku & IWL_SKU_G) |
| 1823 | priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ); |
| 1824 | if (priv->cfg->sku & IWL_SKU_A) |
| 1825 | priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1826 | set_bit(STATUS_SCANNING, &priv->status); |
| 1827 | priv->scan_start = jiffies; |
| 1828 | priv->scan_pass_start = priv->scan_start; |
| 1829 | |
| 1830 | queue_work(priv->workqueue, &priv->request_scan); |
| 1831 | |
| 1832 | return 0; |
| 1833 | } |
| 1834 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1835 | 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] | 1836 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1837 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1838 | |
| 1839 | if (hw_decrypt) |
| 1840 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 1841 | else |
| 1842 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 1843 | |
| 1844 | return 0; |
| 1845 | } |
| 1846 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1847 | static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1848 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1849 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1850 | if (band == IEEE80211_BAND_5GHZ) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1851 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1852 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1853 | | RXON_FLG_CCK_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1854 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1855 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1856 | /* Copied from iwl3945_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1857 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1858 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1859 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1860 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1861 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1862 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1863 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1864 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1865 | priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1866 | priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1867 | priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1872 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1873 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1874 | static void iwl3945_connection_init_rx_config(struct iwl_priv *priv, |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1875 | int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1876 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 1877 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1878 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1879 | memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1880 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1881 | switch (mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1882 | case NL80211_IFTYPE_AP: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1883 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1884 | break; |
| 1885 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1886 | case NL80211_IFTYPE_STATION: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1887 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1888 | priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1889 | break; |
| 1890 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1891 | case NL80211_IFTYPE_ADHOC: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1892 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1893 | priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1894 | priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1895 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1896 | break; |
| 1897 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1898 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1899 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1900 | priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1901 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1902 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1903 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1904 | IWL_ERR(priv, "Unsupported interface type %d\n", mode); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1905 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | #if 0 |
| 1909 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1910 | * that */ |
| 1911 | if (!hw_to_local(priv->hw)->short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1912 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_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_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1915 | #endif |
| 1916 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1917 | ch_info = iwl3945_get_channel_info(priv, priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1918 | le16_to_cpu(priv->active39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1919 | |
| 1920 | if (!ch_info) |
| 1921 | ch_info = &priv->channel_info[0]; |
| 1922 | |
| 1923 | /* |
| 1924 | * in some case A channels are all non IBSS |
| 1925 | * in this case force B/G channel |
| 1926 | */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1927 | if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1928 | ch_info = &priv->channel_info[0]; |
| 1929 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1930 | priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1931 | if (is_channel_a_band(ch_info)) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1932 | priv->band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1933 | else |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1934 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1935 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1936 | iwl3945_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1937 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1938 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1939 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1940 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1941 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1942 | } |
| 1943 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1944 | static int iwl3945_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1945 | { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1946 | if (mode == NL80211_IFTYPE_ADHOC) { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 1947 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1948 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1949 | ch_info = iwl3945_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1950 | priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1951 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1952 | |
| 1953 | if (!ch_info || !is_channel_ibss(ch_info)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1954 | IWL_ERR(priv, "channel %d not IBSS channel\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1955 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1956 | return -EINVAL; |
| 1957 | } |
| 1958 | } |
| 1959 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1960 | iwl3945_connection_init_rx_config(priv, mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1961 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1962 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1963 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1964 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1965 | /* don't commit rxon if rf-kill is on*/ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 1966 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1967 | return -EAGAIN; |
| 1968 | |
| 1969 | cancel_delayed_work(&priv->scan_check); |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 1970 | if (iwl_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1971 | IWL_WARN(priv, "Aborted scan still in progress after 100ms\n"); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1972 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 1973 | return -EAGAIN; |
| 1974 | } |
| 1975 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1976 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1977 | |
| 1978 | return 0; |
| 1979 | } |
| 1980 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1981 | static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1982 | struct ieee80211_tx_info *info, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1983 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1984 | struct sk_buff *skb_frag, |
| 1985 | int last_frag) |
| 1986 | { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1987 | 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] | 1988 | struct iwl3945_hw_key *keyinfo = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1989 | &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1990 | |
| 1991 | switch (keyinfo->alg) { |
| 1992 | case ALG_CCMP: |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1993 | tx->sec_ctl = TX_CMD_SEC_CCM; |
| 1994 | memcpy(tx->key, keyinfo->key, keyinfo->keylen); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1995 | IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1996 | break; |
| 1997 | |
| 1998 | case ALG_TKIP: |
| 1999 | #if 0 |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2000 | tx->sec_ctl = TX_CMD_SEC_TKIP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2001 | |
| 2002 | if (last_frag) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2003 | memcpy(tx->tkip_mic.byte, skb_frag->tail - 8, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2004 | 8); |
| 2005 | else |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2006 | memset(tx->tkip_mic.byte, 0, 8); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2007 | #endif |
| 2008 | break; |
| 2009 | |
| 2010 | case ALG_WEP: |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2011 | tx->sec_ctl = TX_CMD_SEC_WEP | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2012 | (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] | 2013 | |
| 2014 | if (keyinfo->keylen == 13) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2015 | tx->sec_ctl |= TX_CMD_SEC_KEY128; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2016 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2017 | memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2018 | |
| 2019 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2020 | "with key %d\n", info->control.hw_key->hw_key_idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2021 | break; |
| 2022 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2023 | default: |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2024 | IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2025 | break; |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | /* |
| 2030 | * handle build REPLY_TX command notification. |
| 2031 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2032 | static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2033 | struct iwl_cmd *cmd, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2034 | struct ieee80211_tx_info *info, |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2035 | struct ieee80211_hdr *hdr, u8 std_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2036 | { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2037 | struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload; |
| 2038 | __le32 tx_flags = tx->tx_flags; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2039 | __le16 fc = hdr->frame_control; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2040 | u8 rc_flags = info->control.rates[0].flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2041 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2042 | tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2043 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2044 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2045 | if (ieee80211_is_mgmt(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2046 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2047 | if (ieee80211_is_probe_resp(fc) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2048 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2049 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2050 | } else { |
| 2051 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2052 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2053 | } |
| 2054 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2055 | tx->sta_id = std_id; |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2056 | if (ieee80211_has_morefrags(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2057 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2058 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2059 | if (ieee80211_is_data_qos(fc)) { |
| 2060 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2061 | tx->tid_tspec = qc[0] & 0xf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2062 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2063 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2064 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2065 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2066 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2067 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2068 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2069 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2070 | } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2071 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2072 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2073 | } |
| 2074 | |
| 2075 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2076 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2077 | |
| 2078 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2079 | if (ieee80211_is_mgmt(fc)) { |
| 2080 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2081 | tx->timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2082 | else |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2083 | tx->timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2084 | } else { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2085 | tx->timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2086 | #ifdef CONFIG_IWL3945_LEDS |
| 2087 | priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len); |
| 2088 | #endif |
| 2089 | } |
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 | tx->driver_txop = 0; |
| 2092 | tx->tx_flags = tx_flags; |
| 2093 | tx->next_frame_len = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2096 | /** |
| 2097 | * iwl3945_get_sta_id - Find station's index within station table |
| 2098 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2099 | 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] | 2100 | { |
| 2101 | int sta_id; |
| 2102 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2103 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2104 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2105 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2106 | is_multicast_ether_addr(hdr->addr1)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2107 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2108 | |
| 2109 | switch (priv->iw_mode) { |
| 2110 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2111 | /* If we are a client station in a BSS network, use the special |
| 2112 | * AP station entry (that's the only station we communicate with) */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2113 | case NL80211_IFTYPE_STATION: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2114 | return IWL_AP_ID; |
| 2115 | |
| 2116 | /* If we are an AP, then find the station, or use BCAST */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2117 | case NL80211_IFTYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2118 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2119 | if (sta_id != IWL_INVALID_STATION) |
| 2120 | return sta_id; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2121 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2122 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2123 | /* If this frame is going out to an IBSS network, find the station, |
| 2124 | * or create a new station table entry */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2125 | case NL80211_IFTYPE_ADHOC: { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2126 | /* Create new station table entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2127 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2128 | if (sta_id != IWL_INVALID_STATION) |
| 2129 | return sta_id; |
| 2130 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2131 | sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2132 | |
| 2133 | if (sta_id != IWL_INVALID_STATION) |
| 2134 | return sta_id; |
| 2135 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2136 | IWL_DEBUG_DROP("Station %pM not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2137 | "Defaulting to broadcast...\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2138 | hdr->addr1); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2139 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2140 | return priv->hw_params.bcast_sta_id; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2141 | } |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2142 | /* If we are in monitor mode, use BCAST. This is required for |
| 2143 | * packet injection. */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2144 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2145 | return priv->hw_params.bcast_sta_id; |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2146 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2147 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2148 | IWL_WARN(priv, "Unknown mode of operation: %d\n", |
| 2149 | priv->iw_mode); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2150 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | /* |
| 2155 | * start REPLY_TX command process |
| 2156 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2157 | 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] | 2158 | { |
| 2159 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2160 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2161 | struct iwl3945_tfd *tfd; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2162 | struct iwl3945_tx_cmd *tx; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2163 | struct iwl_tx_queue *txq = NULL; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2164 | struct iwl_queue *q = NULL; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2165 | struct iwl_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2166 | dma_addr_t phys_addr; |
| 2167 | dma_addr_t txcmd_phys; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2168 | int txq_id = skb_get_queue_mapping(skb); |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2169 | u16 len, idx, len_org, hdr_len; |
| 2170 | u8 id; |
| 2171 | u8 unicast; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2172 | u8 sta_id; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2173 | u8 tid = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2174 | u16 seq_number = 0; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2175 | __le16 fc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2176 | u8 wait_write_ptr = 0; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2177 | u8 *qc = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2178 | unsigned long flags; |
| 2179 | int rc; |
| 2180 | |
| 2181 | spin_lock_irqsave(&priv->lock, flags); |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2182 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2183 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2184 | goto drop_unlock; |
| 2185 | } |
| 2186 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2187 | 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] | 2188 | IWL_ERR(priv, "ERROR: No TX rate available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2189 | goto drop_unlock; |
| 2190 | } |
| 2191 | |
| 2192 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2193 | id = 0; |
| 2194 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2195 | fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2196 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2197 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2198 | if (ieee80211_is_auth(fc)) |
| 2199 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2200 | else if (ieee80211_is_assoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2201 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2202 | else if (ieee80211_is_reassoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2203 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2204 | #endif |
| 2205 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2206 | /* drop all data frame if we are not associated */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2207 | if (ieee80211_is_data(fc) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2208 | (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2209 | (!iwl3945_is_associated(priv) || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2210 | ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2211 | IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2212 | goto drop_unlock; |
| 2213 | } |
| 2214 | |
| 2215 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2216 | |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2217 | hdr_len = ieee80211_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2218 | |
| 2219 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2220 | sta_id = iwl3945_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2221 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2222 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n", |
| 2223 | hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2224 | goto drop; |
| 2225 | } |
| 2226 | |
| 2227 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2228 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2229 | if (ieee80211_is_data_qos(fc)) { |
| 2230 | qc = ieee80211_get_qos_ctl(hdr); |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2231 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2232 | seq_number = priv->stations_39[sta_id].tid[tid].seq_number & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2233 | IEEE80211_SCTL_SEQ; |
| 2234 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2235 | (hdr->seq_ctrl & |
| 2236 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2237 | seq_number += 0x10; |
| 2238 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2239 | |
| 2240 | /* Descriptor for chosen Tx queue */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2241 | txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2242 | q = &txq->q; |
| 2243 | |
| 2244 | spin_lock_irqsave(&priv->lock, flags); |
| 2245 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2246 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2247 | tfd = &txq->tfds39[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2248 | memset(tfd, 0, sizeof(*tfd)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2249 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2250 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2251 | /* Set up driver data for this TFD */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2252 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2253 | txq->txb[q->write_ptr].skb[0] = skb; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2254 | |
| 2255 | /* Init first empty entry in queue's array of Tx/cmd buffers */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2256 | out_cmd = txq->cmd[idx]; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2257 | tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2258 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2259 | memset(tx, 0, sizeof(*tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2260 | |
| 2261 | /* |
| 2262 | * Set up the Tx-command (not MAC!) header. |
| 2263 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2264 | * after Tx, uCode's Tx response will return this value so driver can |
| 2265 | * locate the frame within the tx queue and do post-tx processing. |
| 2266 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2267 | out_cmd->hdr.cmd = REPLY_TX; |
| 2268 | 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] | 2269 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2270 | |
| 2271 | /* Copy MAC header from skb into command buffer */ |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2272 | memcpy(tx->hdr, hdr, hdr_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2273 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2274 | /* |
| 2275 | * Use the first empty entry in this queue's command buffer array |
| 2276 | * to contain the Tx command and MAC header concatenated together |
| 2277 | * (payload data will be in another buffer). |
| 2278 | * Size of this varies, due to varying MAC header length. |
| 2279 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2280 | * of the MAC header (device reads on dword boundaries). |
| 2281 | * We'll tell device about this padding later. |
| 2282 | */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2283 | len = sizeof(struct iwl3945_tx_cmd) + |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2284 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2285 | |
| 2286 | len_org = len; |
| 2287 | len = (len + 3) & ~3; |
| 2288 | |
| 2289 | if (len_org != len) |
| 2290 | len_org = 1; |
| 2291 | else |
| 2292 | len_org = 0; |
| 2293 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2294 | /* Physical address of this Tx command's header (not MAC header!), |
| 2295 | * within command buffer array. */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 2296 | txcmd_phys = pci_map_single(priv->pci_dev, |
| 2297 | out_cmd, sizeof(struct iwl_cmd), |
| 2298 | PCI_DMA_TODEVICE); |
| 2299 | pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys); |
| 2300 | pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd)); |
| 2301 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2302 | * first entry */ |
| 2303 | txcmd_phys += offsetof(struct iwl_cmd, hdr); |
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 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2306 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2307 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2308 | |
Johannes Berg | d0f0980 | 2008-07-29 11:32:07 +0200 | [diff] [blame] | 2309 | if (info->control.hw_key) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2310 | iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2311 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2312 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2313 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2314 | len = skb->len - hdr_len; |
| 2315 | if (len) { |
| 2316 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2317 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2318 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2321 | if (!len) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2322 | /* If there is no payload, then we use only one Tx buffer */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2323 | tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2324 | else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2325 | /* Else use 2 buffers. |
| 2326 | * Tell 3945 about any padding after MAC header */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 2327 | tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(2) | |
| 2328 | TFD_CTL_PAD_SET(U32_PAD(len))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2329 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2330 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2331 | len = (u16)skb->len; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2332 | tx->len = cpu_to_le16(len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2333 | |
| 2334 | /* TODO need this for burst mode later on */ |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2335 | iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2336 | |
| 2337 | /* set is_hcca to 0; it probably will never be implemented */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2338 | 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] | 2339 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2340 | tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; |
| 2341 | tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2342 | |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2343 | if (!ieee80211_has_morefrags(hdr->frame_control)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2344 | txq->need_update = 1; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 2345 | if (qc) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2346 | priv->stations_39[sta_id].tid[tid].seq_number = seq_number; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2347 | } else { |
| 2348 | wait_write_ptr = 1; |
| 2349 | txq->need_update = 0; |
| 2350 | } |
| 2351 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2352 | iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2353 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 2354 | iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr, |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2355 | ieee80211_hdrlen(fc)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2356 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2357 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2358 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Samuel Ortiz | 4f3602c | 2009-01-19 15:30:25 -0800 | [diff] [blame^] | 2359 | rc = iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2360 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2361 | |
| 2362 | if (rc) |
| 2363 | return rc; |
| 2364 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2365 | if ((iwl_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2366 | && priv->mac80211_registered) { |
| 2367 | if (wait_write_ptr) { |
| 2368 | spin_lock_irqsave(&priv->lock, flags); |
| 2369 | txq->need_update = 1; |
Samuel Ortiz | 4f3602c | 2009-01-19 15:30:25 -0800 | [diff] [blame^] | 2370 | iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2371 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2372 | } |
| 2373 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 2374 | ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | return 0; |
| 2378 | |
| 2379 | drop_unlock: |
| 2380 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2381 | drop: |
| 2382 | return -1; |
| 2383 | } |
| 2384 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2385 | static void iwl3945_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2386 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2387 | const struct ieee80211_supported_band *sband = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2388 | struct ieee80211_rate *rate; |
| 2389 | int i; |
| 2390 | |
Kolekar, Abhijeet | cbba18c | 2008-12-19 10:37:42 +0800 | [diff] [blame] | 2391 | sband = iwl_get_hw_mode(priv, priv->band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2392 | if (!sband) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2393 | 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] | 2394 | return; |
| 2395 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2396 | |
| 2397 | priv->active_rate = 0; |
| 2398 | priv->active_rate_basic = 0; |
| 2399 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2400 | IWL_DEBUG_RATE("Setting rates for %s GHz\n", |
| 2401 | sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2402 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2403 | for (i = 0; i < sband->n_bitrates; i++) { |
| 2404 | rate = &sband->bitrates[i]; |
| 2405 | if ((rate->hw_value < IWL_RATE_COUNT) && |
| 2406 | !(rate->flags & IEEE80211_CHAN_DISABLED)) { |
| 2407 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n", |
| 2408 | rate->hw_value, iwl3945_rates[rate->hw_value].plcp); |
| 2409 | priv->active_rate |= (1 << rate->hw_value); |
| 2410 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2414 | priv->active_rate, priv->active_rate_basic); |
| 2415 | |
| 2416 | /* |
| 2417 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2418 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2419 | * OFDM |
| 2420 | */ |
| 2421 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2422 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2423 | ((priv->active_rate_basic & |
| 2424 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2425 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2426 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2427 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2428 | |
| 2429 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2430 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2431 | ((priv->active_rate_basic & |
| 2432 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2433 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2434 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2435 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2436 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2437 | } |
| 2438 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2439 | 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] | 2440 | { |
| 2441 | unsigned long flags; |
| 2442 | |
| 2443 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2444 | return; |
| 2445 | |
| 2446 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2447 | disable_radio ? "OFF" : "ON"); |
| 2448 | |
| 2449 | if (disable_radio) { |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 2450 | iwl_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2451 | /* FIXME: This is a workaround for AP */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2452 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2453 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2454 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2455 | CSR_UCODE_SW_BIT_RFKILL); |
| 2456 | spin_unlock_irqrestore(&priv->lock, flags); |
Samuel Ortiz | c496294 | 2008-12-22 11:31:18 +0800 | [diff] [blame] | 2457 | iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2458 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2459 | } |
| 2460 | return; |
| 2461 | } |
| 2462 | |
| 2463 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2464 | 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] | 2465 | |
| 2466 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2467 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2468 | |
| 2469 | /* wake up ucode */ |
| 2470 | msleep(10); |
| 2471 | |
| 2472 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2473 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2474 | if (!iwl_grab_nic_access(priv)) |
| 2475 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2476 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2477 | |
| 2478 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2479 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2480 | "disabled by HW switch\n"); |
| 2481 | return; |
| 2482 | } |
| 2483 | |
Zhu Yi | 808e72a | 2008-06-12 09:47:17 +0800 | [diff] [blame] | 2484 | if (priv->is_open) |
| 2485 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2486 | return; |
| 2487 | } |
| 2488 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2489 | 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] | 2490 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 2491 | { |
| 2492 | u16 fc = |
| 2493 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 2494 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2495 | if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2496 | return; |
| 2497 | |
| 2498 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 2499 | return; |
| 2500 | |
| 2501 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 2502 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2503 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2504 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2505 | RX_RES_STATUS_BAD_ICV_MIC) |
| 2506 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 2507 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 2508 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2509 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2510 | RX_RES_STATUS_DECRYPT_OK) { |
| 2511 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 2512 | stats->flag |= RX_FLAG_DECRYPTED; |
| 2513 | } |
| 2514 | break; |
| 2515 | |
| 2516 | default: |
| 2517 | break; |
| 2518 | } |
| 2519 | } |
| 2520 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2521 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2522 | |
| 2523 | #include "iwl-spectrum.h" |
| 2524 | |
| 2525 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 2526 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 2527 | #define TIME_UNIT 1024 |
| 2528 | |
| 2529 | /* |
| 2530 | * extended beacon time format |
| 2531 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 2532 | * the high 1 byte is the beacon counts |
| 2533 | * the lower 3 bytes is the time in usec within one beacon interval |
| 2534 | */ |
| 2535 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2536 | static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2537 | { |
| 2538 | u32 quot; |
| 2539 | u32 rem; |
| 2540 | u32 interval = beacon_interval * 1024; |
| 2541 | |
| 2542 | if (!interval || !usec) |
| 2543 | return 0; |
| 2544 | |
| 2545 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 2546 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 2547 | |
| 2548 | return (quot << 24) + rem; |
| 2549 | } |
| 2550 | |
| 2551 | /* base is usually what we get from ucode with each received frame, |
| 2552 | * the same as HW timer counter counting down |
| 2553 | */ |
| 2554 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2555 | 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] | 2556 | { |
| 2557 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 2558 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 2559 | u32 interval = beacon_interval * TIME_UNIT; |
| 2560 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 2561 | (addon & BEACON_TIME_MASK_HIGH); |
| 2562 | |
| 2563 | if (base_low > addon_low) |
| 2564 | res += base_low - addon_low; |
| 2565 | else if (base_low < addon_low) { |
| 2566 | res += interval + base_low - addon_low; |
| 2567 | res += (1 << 24); |
| 2568 | } else |
| 2569 | res += (1 << 24); |
| 2570 | |
| 2571 | return cpu_to_le32(res); |
| 2572 | } |
| 2573 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2574 | static int iwl3945_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2575 | struct ieee80211_measurement_params *params, |
| 2576 | u8 type) |
| 2577 | { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2578 | struct iwl_spectrum_cmd spectrum; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2579 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2580 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2581 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 2582 | .data = (void *)&spectrum, |
| 2583 | .meta.flags = CMD_WANT_SKB, |
| 2584 | }; |
| 2585 | u32 add_time = le64_to_cpu(params->start_time); |
| 2586 | int rc; |
| 2587 | int spectrum_resp_status; |
| 2588 | int duration = le16_to_cpu(params->duration); |
| 2589 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2590 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2591 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2592 | iwl3945_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2593 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 2594 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2595 | |
| 2596 | memset(&spectrum, 0, sizeof(spectrum)); |
| 2597 | |
| 2598 | spectrum.channel_count = cpu_to_le16(1); |
| 2599 | spectrum.flags = |
| 2600 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 2601 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 2602 | cmd.len = sizeof(spectrum); |
| 2603 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 2604 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2605 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2606 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2607 | iwl3945_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2608 | add_time, |
| 2609 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2610 | else |
| 2611 | spectrum.start_time = 0; |
| 2612 | |
| 2613 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 2614 | spectrum.channels[0].channel = params->channel; |
| 2615 | spectrum.channels[0].type = type; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2616 | if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2617 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 2618 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 2619 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2620 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2621 | if (rc) |
| 2622 | return rc; |
| 2623 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2624 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2625 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2626 | IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2627 | rc = -EIO; |
| 2628 | } |
| 2629 | |
| 2630 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 2631 | switch (spectrum_resp_status) { |
| 2632 | case 0: /* Command will be handled */ |
| 2633 | if (res->u.spectrum.id != 0xff) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2634 | IWL_DEBUG_INFO("Replaced existing measurement: %d\n", |
| 2635 | res->u.spectrum.id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2636 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 2637 | } |
| 2638 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 2639 | rc = 0; |
| 2640 | break; |
| 2641 | |
| 2642 | case 1: /* Command will not be handled */ |
| 2643 | rc = -EAGAIN; |
| 2644 | break; |
| 2645 | } |
| 2646 | |
| 2647 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 2648 | |
| 2649 | return rc; |
| 2650 | } |
| 2651 | #endif |
| 2652 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2653 | static void iwl3945_rx_reply_alive(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2654 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2655 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2656 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 2657 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2658 | struct delayed_work *pwork; |
| 2659 | |
| 2660 | palive = &pkt->u.alive_frame; |
| 2661 | |
| 2662 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 2663 | "0x%01X 0x%01X\n", |
| 2664 | palive->is_valid, palive->ver_type, |
| 2665 | palive->ver_subtype); |
| 2666 | |
| 2667 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 2668 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2669 | memcpy(&priv->card_alive_init, &pkt->u.alive_frame, |
| 2670 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2671 | pwork = &priv->init_alive_start; |
| 2672 | } else { |
| 2673 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2674 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2675 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2676 | pwork = &priv->alive_start; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2677 | iwl3945_disable_events(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | /* We delay the ALIVE response by 5ms to |
| 2681 | * give the HW RF Kill time to activate... */ |
| 2682 | if (palive->is_valid == UCODE_VALID_OK) |
| 2683 | queue_delayed_work(priv->workqueue, pwork, |
| 2684 | msecs_to_jiffies(5)); |
| 2685 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2686 | IWL_WARN(priv, "uCode did not respond OK.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2689 | static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2690 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2691 | { |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2692 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2693 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2694 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2695 | |
| 2696 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 2697 | return; |
| 2698 | } |
| 2699 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2700 | static void iwl3945_rx_reply_error(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2701 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2702 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2703 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2704 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2705 | IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2706 | "seq 0x%04X ser 0x%08X\n", |
| 2707 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 2708 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 2709 | pkt->u.err_resp.cmd_id, |
| 2710 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 2711 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 2712 | } |
| 2713 | |
| 2714 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2715 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2716 | 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] | 2717 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2718 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2719 | struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2720 | struct iwl_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2721 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 2722 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 2723 | rxon->channel = csa->channel; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2724 | priv->staging39_rxon.channel = csa->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2727 | static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2728 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2729 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2730 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2731 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2732 | struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2733 | |
| 2734 | if (!report->state) { |
| 2735 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 2736 | "Spectrum Measure Notification: Start\n"); |
| 2737 | return; |
| 2738 | } |
| 2739 | |
| 2740 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2741 | priv->measurement_status |= MEASUREMENT_READY; |
| 2742 | #endif |
| 2743 | } |
| 2744 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2745 | static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2746 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2747 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2748 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2749 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2750 | struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2751 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2752 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2753 | #endif |
| 2754 | } |
| 2755 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2756 | static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2757 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2758 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2759 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2760 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2761 | "notification for %s:\n", |
| 2762 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2763 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, |
| 2764 | le32_to_cpu(pkt->len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2767 | static void iwl3945_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2768 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2769 | struct iwl_priv *priv = |
| 2770 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2771 | struct sk_buff *beacon; |
| 2772 | |
| 2773 | /* 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] | 2774 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2775 | |
| 2776 | if (!beacon) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2777 | IWL_ERR(priv, "update beacon failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2778 | return; |
| 2779 | } |
| 2780 | |
| 2781 | mutex_lock(&priv->mutex); |
| 2782 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2783 | if (priv->ibss_beacon) |
| 2784 | dev_kfree_skb(priv->ibss_beacon); |
| 2785 | |
| 2786 | priv->ibss_beacon = beacon; |
| 2787 | mutex_unlock(&priv->mutex); |
| 2788 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2789 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2792 | static void iwl3945_rx_beacon_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2793 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2794 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2795 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2796 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2797 | struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2798 | u8 rate = beacon->beacon_notify_hdr.rate; |
| 2799 | |
| 2800 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2801 | "tsf %d %d rate %d\n", |
| 2802 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2803 | beacon->beacon_notify_hdr.failure_frame, |
| 2804 | le32_to_cpu(beacon->ibss_mgr_status), |
| 2805 | le32_to_cpu(beacon->high_tsf), |
| 2806 | le32_to_cpu(beacon->low_tsf), rate); |
| 2807 | #endif |
| 2808 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2809 | if ((priv->iw_mode == NL80211_IFTYPE_AP) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2810 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 2811 | queue_work(priv->workqueue, &priv->beacon_update); |
| 2812 | } |
| 2813 | |
| 2814 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2815 | static void iwl3945_rx_reply_scan(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2816 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2817 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2818 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2819 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2820 | struct iwl_scanreq_notification *notif = |
| 2821 | (struct iwl_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2822 | |
| 2823 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 2824 | #endif |
| 2825 | } |
| 2826 | |
| 2827 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2828 | static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2829 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2830 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2831 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2832 | struct iwl_scanstart_notification *notif = |
| 2833 | (struct iwl_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2834 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 2835 | IWL_DEBUG_SCAN("Scan start: " |
| 2836 | "%d [802.11%s] " |
| 2837 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 2838 | notif->channel, |
| 2839 | notif->band ? "bg" : "a", |
| 2840 | notif->tsf_high, |
| 2841 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 2842 | } |
| 2843 | |
| 2844 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2845 | static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2846 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2847 | { |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2848 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2849 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2850 | struct iwl_scanresults_notification *notif = |
| 2851 | (struct iwl_scanresults_notification *)pkt->u.raw; |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2852 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2853 | |
| 2854 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 2855 | "%d [802.11%s] " |
| 2856 | "(TSF: 0x%08X:%08X) - %d " |
| 2857 | "elapsed=%lu usec (%dms since last)\n", |
| 2858 | notif->channel, |
| 2859 | notif->band ? "bg" : "a", |
| 2860 | le32_to_cpu(notif->tsf_high), |
| 2861 | le32_to_cpu(notif->tsf_low), |
| 2862 | le32_to_cpu(notif->statistics[0]), |
| 2863 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 2864 | jiffies_to_msecs(elapsed_jiffies |
| 2865 | (priv->last_scan_jiffies, jiffies))); |
| 2866 | |
| 2867 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2868 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2872 | static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2873 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2874 | { |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2875 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2876 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2877 | struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 2878 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2879 | |
| 2880 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 2881 | scan_notif->scanned_channels, |
| 2882 | scan_notif->tsf_low, |
| 2883 | scan_notif->tsf_high, scan_notif->status); |
| 2884 | |
| 2885 | /* The HW is no longer scanning */ |
| 2886 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 2887 | |
| 2888 | /* The scan completion notification came in, so kill that timer... */ |
| 2889 | cancel_delayed_work(&priv->scan_check); |
| 2890 | |
| 2891 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 2892 | (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ? |
| 2893 | "2.4" : "5.2", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2894 | jiffies_to_msecs(elapsed_jiffies |
| 2895 | (priv->scan_pass_start, jiffies))); |
| 2896 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 2897 | /* Remove this scanned band from the list of pending |
| 2898 | * bands to scan, band G precedes A in order of scanning |
| 2899 | * as seen in iwl3945_bg_request_scan */ |
| 2900 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) |
| 2901 | priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ); |
| 2902 | else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) |
| 2903 | priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2904 | |
| 2905 | /* If a request to abort was given, or the scan did not succeed |
| 2906 | * then we reset the scan state machine and terminate, |
| 2907 | * re-queuing another scan if one has been requested */ |
| 2908 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2909 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 2910 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2911 | } else { |
| 2912 | /* If there are more bands on this scan pass reschedule */ |
| 2913 | if (priv->scan_bands > 0) |
| 2914 | goto reschedule; |
| 2915 | } |
| 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 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 2920 | |
| 2921 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2922 | |
| 2923 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 2924 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 2925 | |
| 2926 | queue_work(priv->workqueue, &priv->scan_completed); |
| 2927 | |
| 2928 | return; |
| 2929 | |
| 2930 | reschedule: |
| 2931 | priv->scan_pass_start = jiffies; |
| 2932 | queue_work(priv->workqueue, &priv->request_scan); |
| 2933 | } |
| 2934 | |
| 2935 | /* Handle notification from uCode that card's power state is changing |
| 2936 | * due to software, hardware, or critical temperature RFKILL */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2937 | static void iwl3945_rx_card_state_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2938 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2939 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2940 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2941 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 2942 | unsigned long status = priv->status; |
| 2943 | |
| 2944 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 2945 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 2946 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 2947 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2948 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2949 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 2950 | |
| 2951 | if (flags & HW_CARD_DISABLED) |
| 2952 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2953 | else |
| 2954 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2955 | |
| 2956 | |
| 2957 | if (flags & SW_CARD_DISABLED) |
| 2958 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2959 | else |
| 2960 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2961 | |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 2962 | iwl_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2963 | |
| 2964 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 2965 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 2966 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 2967 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 2968 | queue_work(priv->workqueue, &priv->rf_kill); |
| 2969 | else |
| 2970 | wake_up_interruptible(&priv->wait_command_queue); |
| 2971 | } |
| 2972 | |
| 2973 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2974 | * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2975 | * |
| 2976 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 2977 | * to the host. |
| 2978 | * |
| 2979 | * This function chains into the hardware specific files for them to setup |
| 2980 | * any hardware specific handlers as well. |
| 2981 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2982 | static void iwl3945_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2983 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2984 | priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive; |
| 2985 | priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta; |
| 2986 | priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error; |
| 2987 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2988 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2989 | iwl3945_rx_spectrum_measure_notif; |
| 2990 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2991 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2992 | iwl3945_rx_pm_debug_statistics_notif; |
| 2993 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2994 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2995 | /* |
| 2996 | * The same handler is used for both the REPLY to a discrete |
| 2997 | * statistics request from the host as well as for the periodic |
| 2998 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2999 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3000 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics; |
| 3001 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3002 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3003 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan; |
| 3004 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3005 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3006 | iwl3945_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3007 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3008 | iwl3945_rx_scan_complete_notif; |
| 3009 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3011 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3012 | iwl3945_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | /** |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3016 | * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries |
| 3017 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3018 | * need to be reclaimed. |
| 3019 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3020 | static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3021 | int txq_id, int index) |
| 3022 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3023 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 3024 | struct iwl_queue *q = &txq->q; |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3025 | int nfreed = 0; |
| 3026 | |
Winkler, Tomas | 625a381 | 2009-01-08 10:19:55 -0800 | [diff] [blame] | 3027 | if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3028 | 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] | 3029 | "is out of range [0-%d] %d %d.\n", txq_id, |
| 3030 | index, q->n_bd, q->write_ptr, q->read_ptr); |
| 3031 | return; |
| 3032 | } |
| 3033 | |
| 3034 | for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index; |
| 3035 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
| 3036 | if (nfreed > 1) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3037 | IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3038 | q->write_ptr, q->read_ptr); |
| 3039 | queue_work(priv->workqueue, &priv->restart); |
| 3040 | break; |
| 3041 | } |
| 3042 | nfreed++; |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | |
| 3047 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3048 | * 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] | 3049 | * @rxb: Rx buffer to reclaim |
| 3050 | * |
| 3051 | * If an Rx buffer has an async callback associated with it the callback |
| 3052 | * will be executed. The attached skb (if present) will only be freed |
| 3053 | * if the callback returns 1 |
| 3054 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3055 | static void iwl3945_tx_cmd_complete(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3056 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3057 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3058 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3059 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3060 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3061 | int index = SEQ_TO_INDEX(sequence); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 3062 | int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3063 | int cmd_index; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 3064 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3065 | |
Chatre, Reinette | 638d0eb | 2009-01-19 15:30:24 -0800 | [diff] [blame] | 3066 | if (WARN(txq_id != IWL_CMD_QUEUE_NUM, |
| 3067 | "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n", |
| 3068 | txq_id, sequence, |
| 3069 | priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr, |
| 3070 | priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) { |
| 3071 | iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32); |
| 3072 | return; |
| 3073 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3074 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 3075 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3076 | cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3077 | |
| 3078 | /* Input error checking is done when commands are added to queue. */ |
| 3079 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3080 | cmd->meta.source->u.skb = rxb->skb; |
| 3081 | rxb->skb = NULL; |
| 3082 | } else if (cmd->meta.u.callback && |
| 3083 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3084 | rxb->skb = NULL; |
| 3085 | |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3086 | iwl3945_cmd_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3087 | |
| 3088 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3089 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3090 | wake_up_interruptible(&priv->wait_command_queue); |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | /************************** RX-FUNCTIONS ****************************/ |
| 3095 | /* |
| 3096 | * Rx theory of operation |
| 3097 | * |
| 3098 | * The host allocates 32 DMA target addresses and passes the host address |
| 3099 | * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
| 3100 | * 0 to 31 |
| 3101 | * |
| 3102 | * Rx Queue Indexes |
| 3103 | * The host/firmware share two index registers for managing the Rx buffers. |
| 3104 | * |
| 3105 | * The READ index maps to the first position that the firmware may be writing |
| 3106 | * to -- the driver can read up to (but not including) this position and get |
| 3107 | * good data. |
| 3108 | * The READ index is managed by the firmware once the card is enabled. |
| 3109 | * |
| 3110 | * The WRITE index maps to the last position the driver has read from -- the |
| 3111 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 3112 | * |
| 3113 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 3114 | * WRITE = READ. |
| 3115 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3116 | * 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] | 3117 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 3118 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3119 | * 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] | 3120 | * and fire the RX interrupt. The driver can then query the READ index and |
| 3121 | * process as many packets as possible, moving the WRITE index forward as it |
| 3122 | * resets the Rx queue buffers with new memory. |
| 3123 | * |
| 3124 | * The management in the driver is as follows: |
| 3125 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 3126 | * 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] | 3127 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3128 | * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3129 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 3130 | * 'processed' and 'read' driver indexes as well) |
| 3131 | * + A received packet is processed and handed to the kernel network stack, |
| 3132 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 3133 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 3134 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 3135 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 3136 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 3137 | * |
| 3138 | * |
| 3139 | * Driver sequence: |
| 3140 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3141 | * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3142 | * iwl3945_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3143 | * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3144 | * queue, updates firmware pointers, and updates |
| 3145 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3146 | * are available, schedules iwl3945_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3147 | * |
| 3148 | * -- enable interrupts -- |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3149 | * 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] | 3150 | * READ INDEX, detaching the SKB from the pool. |
| 3151 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3152 | * Calls iwl3945_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3153 | * slots. |
| 3154 | * ... |
| 3155 | * |
| 3156 | */ |
| 3157 | |
| 3158 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3159 | * 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] | 3160 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3161 | static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3162 | dma_addr_t dma_addr) |
| 3163 | { |
| 3164 | return cpu_to_le32((u32)dma_addr); |
| 3165 | } |
| 3166 | |
| 3167 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3168 | * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3169 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3170 | * 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] | 3171 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3172 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3173 | * |
| 3174 | * This moves the 'write' index forward to catch up with 'processed', and |
| 3175 | * also updates the memory address in the firmware to reference the new |
| 3176 | * target buffer. |
| 3177 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3178 | static int iwl3945_rx_queue_restock(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3179 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3180 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3181 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3182 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3183 | unsigned long flags; |
| 3184 | int write, rc; |
| 3185 | |
| 3186 | spin_lock_irqsave(&rxq->lock, flags); |
| 3187 | write = rxq->write & ~0x7; |
Winkler, Tomas | 37d6831 | 2009-01-08 10:19:54 -0800 | [diff] [blame] | 3188 | while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3189 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3190 | element = rxq->rx_free.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3191 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3192 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3193 | |
| 3194 | /* Point to Rx buffer via next RBD in circular buffer */ |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3195 | 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] | 3196 | rxq->queue[rxq->write] = rxb; |
| 3197 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 3198 | rxq->free_count--; |
| 3199 | } |
| 3200 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3201 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 3202 | * refill it */ |
| 3203 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 3204 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 3205 | |
| 3206 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3207 | /* If we've added more space for the firmware to place data, tell it. |
| 3208 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3209 | if ((write != (rxq->write & ~0x7)) |
| 3210 | || (abs(rxq->write - rxq->read) > 7)) { |
| 3211 | spin_lock_irqsave(&rxq->lock, flags); |
| 3212 | rxq->need_update = 1; |
| 3213 | spin_unlock_irqrestore(&rxq->lock, flags); |
Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 3214 | rc = iwl_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3215 | if (rc) |
| 3216 | return rc; |
| 3217 | } |
| 3218 | |
| 3219 | return 0; |
| 3220 | } |
| 3221 | |
| 3222 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3223 | * 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] | 3224 | * |
| 3225 | * When moving to rx_free an SKB is allocated for the slot. |
| 3226 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3227 | * Also restock the Rx queue via iwl3945_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3228 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3229 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3230 | static void iwl3945_rx_allocate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3231 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3232 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3233 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3234 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3235 | unsigned long flags; |
| 3236 | spin_lock_irqsave(&rxq->lock, flags); |
| 3237 | while (!list_empty(&rxq->rx_used)) { |
| 3238 | element = rxq->rx_used.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3239 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3240 | |
| 3241 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3242 | rxb->skb = |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 3243 | alloc_skb(priv->hw_params.rx_buf_size, |
| 3244 | __GFP_NOWARN | GFP_ATOMIC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3245 | if (!rxb->skb) { |
| 3246 | if (net_ratelimit()) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 3247 | IWL_CRIT(priv, ": Can not allocate SKB buffers\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3248 | /* We don't reschedule replenish work here -- we will |
| 3249 | * call the restock method and if it still needs |
| 3250 | * more buffers it will schedule replenish */ |
| 3251 | break; |
| 3252 | } |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 3253 | |
| 3254 | /* If radiotap head is required, reserve some headroom here. |
| 3255 | * The physical head count is a variable rx_stats->phy_count. |
| 3256 | * We reserve 4 bytes here. Plus these extra bytes, the |
| 3257 | * headroom of the physical head should be enough for the |
| 3258 | * radiotap head that iwl3945 supported. See iwl3945_rt. |
| 3259 | */ |
| 3260 | skb_reserve(rxb->skb, 4); |
| 3261 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3262 | priv->alloc_rxb_skb++; |
| 3263 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3264 | |
| 3265 | /* Get physical address of RB/SKB */ |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 3266 | rxb->real_dma_addr = pci_map_single(priv->pci_dev, |
| 3267 | rxb->skb->data, |
| 3268 | priv->hw_params.rx_buf_size, |
| 3269 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3270 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 3271 | rxq->free_count++; |
| 3272 | } |
| 3273 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | /* |
| 3277 | * this should be called while priv->lock is locked |
| 3278 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 3279 | static void __iwl3945_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3280 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3281 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3282 | |
| 3283 | iwl3945_rx_allocate(priv); |
| 3284 | iwl3945_rx_queue_restock(priv); |
| 3285 | } |
| 3286 | |
| 3287 | |
| 3288 | void iwl3945_rx_replenish(void *data) |
| 3289 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3290 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3291 | unsigned long flags; |
| 3292 | |
| 3293 | iwl3945_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3294 | |
| 3295 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3296 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3298 | } |
| 3299 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3300 | /* Convert linear signal-to-noise ratio into dB */ |
| 3301 | static u8 ratio2dB[100] = { |
| 3302 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 3303 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 3304 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 3305 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 3306 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 3307 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 3308 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 3309 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 3310 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 3311 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 3312 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 3313 | }; |
| 3314 | |
| 3315 | /* Calculates a relative dB value from a ratio of linear |
| 3316 | * (i.e. not dB) signal levels. |
| 3317 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3318 | int iwl3945_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3319 | { |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3320 | /* 1000:1 or higher just report as 60 dB */ |
| 3321 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3322 | return 60; |
| 3323 | |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3324 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3325 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3326 | if (sig_ratio >= 100) |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 3327 | return 20 + (int)ratio2dB[sig_ratio/10]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3328 | |
| 3329 | /* We shouldn't see this */ |
| 3330 | if (sig_ratio < 1) |
| 3331 | return 0; |
| 3332 | |
| 3333 | /* Use table for ratios 1:1 - 99:1 */ |
| 3334 | return (int)ratio2dB[sig_ratio]; |
| 3335 | } |
| 3336 | |
| 3337 | #define PERFECT_RSSI (-20) /* dBm */ |
| 3338 | #define WORST_RSSI (-95) /* dBm */ |
| 3339 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 3340 | |
| 3341 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 3342 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 3343 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3344 | int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3345 | { |
| 3346 | int sig_qual; |
| 3347 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 3348 | |
| 3349 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 3350 | * as indicator; formula is (signal dbm - noise dbm). |
| 3351 | * SNR at or above 40 is a great signal (100%). |
| 3352 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 3353 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 3354 | if (noise_dbm) { |
| 3355 | if (rssi_dbm - noise_dbm >= 40) |
| 3356 | return 100; |
| 3357 | else if (rssi_dbm < noise_dbm) |
| 3358 | return 0; |
| 3359 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 3360 | |
| 3361 | /* Else use just the signal level. |
| 3362 | * This formula is a least squares fit of data points collected and |
| 3363 | * compared with a reference system that had a percentage (%) display |
| 3364 | * for signal quality. */ |
| 3365 | } else |
| 3366 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 3367 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 3368 | (RSSI_RANGE * RSSI_RANGE); |
| 3369 | |
| 3370 | if (sig_qual > 100) |
| 3371 | sig_qual = 100; |
| 3372 | else if (sig_qual < 1) |
| 3373 | sig_qual = 0; |
| 3374 | |
| 3375 | return sig_qual; |
| 3376 | } |
| 3377 | |
| 3378 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3379 | * iwl3945_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3380 | * |
| 3381 | * Uses the priv->rx_handlers callback function array to invoke |
| 3382 | * the appropriate handlers, including command responses, |
| 3383 | * frame-received notifications, and other notifications. |
| 3384 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3385 | static void iwl3945_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3386 | { |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3387 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3388 | struct iwl_rx_packet *pkt; |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3389 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3390 | u32 r, i; |
| 3391 | int reclaim; |
| 3392 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3393 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 3394 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3395 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3396 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 3397 | * buffer that the driver may process (last buffer filled by ucode). */ |
Winkler, Tomas | 8cd812b | 2008-12-19 10:37:43 +0800 | [diff] [blame] | 3398 | r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3399 | i = rxq->read; |
| 3400 | |
Winkler, Tomas | 37d6831 | 2009-01-08 10:19:54 -0800 | [diff] [blame] | 3401 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3402 | fill_rx = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3403 | /* Rx interrupt, but nothing sent from uCode */ |
| 3404 | if (i == r) |
| 3405 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 3406 | |
| 3407 | while (i != r) { |
| 3408 | rxb = rxq->queue[i]; |
| 3409 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3410 | /* 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] | 3411 | * then a bug has been introduced in the queue refilling |
| 3412 | * routines -- catch it here */ |
| 3413 | BUG_ON(rxb == NULL); |
| 3414 | |
| 3415 | rxq->queue[i] = NULL; |
| 3416 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3417 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr, |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 3418 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3419 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3420 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3421 | |
| 3422 | /* Reclaim a command buffer only if this packet is a response |
| 3423 | * to a (driver-originated) command. |
| 3424 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3425 | * there is no command buffer to reclaim. |
| 3426 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3427 | * but apparently a few don't get set; catch them here. */ |
| 3428 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 3429 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 3430 | (pkt->hdr.cmd != REPLY_TX); |
| 3431 | |
| 3432 | /* Based on type of command response or notification, |
| 3433 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3434 | * rx_handlers table. See iwl3945_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3435 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3436 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3437 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 3438 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 3439 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 3440 | } else { |
| 3441 | /* No handling needed */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3442 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3443 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 3444 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 3445 | pkt->hdr.cmd); |
| 3446 | } |
| 3447 | |
| 3448 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3449 | /* Invoke any callbacks, transfer the skb to caller, and |
| 3450 | * fire off the (possibly) blocking iwl3945_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3451 | * as we reclaim the driver command queue */ |
| 3452 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3453 | iwl3945_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3454 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3455 | IWL_WARN(priv, "Claim null rxb?\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | /* For now we just don't re-use anything. We can tweak this |
| 3459 | * later to try and re-use notification packets and SKBs that |
| 3460 | * fail to Rx correctly */ |
| 3461 | if (rxb->skb != NULL) { |
| 3462 | priv->alloc_rxb_skb--; |
| 3463 | dev_kfree_skb_any(rxb->skb); |
| 3464 | rxb->skb = NULL; |
| 3465 | } |
| 3466 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3467 | pci_unmap_single(priv->pci_dev, rxb->real_dma_addr, |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 3468 | priv->hw_params.rx_buf_size, |
| 3469 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3470 | spin_lock_irqsave(&rxq->lock, flags); |
| 3471 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 3472 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3473 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3474 | /* If there are a lot of unused frames, |
| 3475 | * restock the Rx queue so ucode won't assert. */ |
| 3476 | if (fill_rx) { |
| 3477 | count++; |
| 3478 | if (count >= 8) { |
| 3479 | priv->rxq.read = i; |
| 3480 | __iwl3945_rx_replenish(priv); |
| 3481 | count = 0; |
| 3482 | } |
| 3483 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | /* Backtrack one entry */ |
| 3487 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3488 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3489 | } |
| 3490 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3491 | #ifdef CONFIG_IWL3945_DEBUG |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3492 | static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3493 | struct iwl3945_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3494 | { |
| 3495 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3496 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3497 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 3498 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 3499 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 3500 | le32_to_cpu(rxon->filter_flags)); |
| 3501 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 3502 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 3503 | rxon->ofdm_basic_rates); |
| 3504 | 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] | 3505 | IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr); |
| 3506 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3507 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 3508 | } |
| 3509 | #endif |
| 3510 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3511 | static void iwl3945_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3512 | { |
| 3513 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 3514 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3515 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3518 | |
| 3519 | /* call this function to flush any scheduled tasklet */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3520 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3521 | { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 3522 | /* wait to make sure we flush pending tasklet*/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3523 | synchronize_irq(priv->pci_dev->irq); |
| 3524 | tasklet_kill(&priv->irq_tasklet); |
| 3525 | } |
| 3526 | |
| 3527 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3528 | static inline void iwl3945_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3529 | { |
| 3530 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 3531 | |
| 3532 | /* disable interrupts from uCode/NIC to host */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3533 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3534 | |
| 3535 | /* acknowledge/clear/reset any interrupts still pending |
| 3536 | * from uCode or flow handler (Rx/Tx DMA) */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3537 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 3538 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3539 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 3540 | } |
| 3541 | |
| 3542 | static const char *desc_lookup(int i) |
| 3543 | { |
| 3544 | switch (i) { |
| 3545 | case 1: |
| 3546 | return "FAIL"; |
| 3547 | case 2: |
| 3548 | return "BAD_PARAM"; |
| 3549 | case 3: |
| 3550 | return "BAD_CHECKSUM"; |
| 3551 | case 4: |
| 3552 | return "NMI_INTERRUPT"; |
| 3553 | case 5: |
| 3554 | return "SYSASSERT"; |
| 3555 | case 6: |
| 3556 | return "FATAL_ERROR"; |
| 3557 | } |
| 3558 | |
| 3559 | return "UNKNOWN"; |
| 3560 | } |
| 3561 | |
| 3562 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 3563 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 3564 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3565 | static void iwl3945_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3566 | { |
| 3567 | u32 i; |
| 3568 | u32 desc, time, count, base, data1; |
| 3569 | u32 blink1, blink2, ilink1, ilink2; |
| 3570 | int rc; |
| 3571 | |
| 3572 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 3573 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3574 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3575 | IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3576 | return; |
| 3577 | } |
| 3578 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3579 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3580 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3581 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3582 | return; |
| 3583 | } |
| 3584 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3585 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3586 | |
| 3587 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3588 | IWL_ERR(priv, "Start IWL Error Log Dump:\n"); |
| 3589 | IWL_ERR(priv, "Status: 0x%08lX, count: %d\n", |
| 3590 | priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3591 | } |
| 3592 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3593 | IWL_ERR(priv, "Desc Time asrtPC blink2 " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3594 | "ilink1 nmiPC Line\n"); |
| 3595 | for (i = ERROR_START_OFFSET; |
| 3596 | i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET; |
| 3597 | i += ERROR_ELEM_SIZE) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3598 | desc = iwl_read_targ_mem(priv, base + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3599 | time = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3600 | iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3601 | blink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3602 | iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3603 | blink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3604 | iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3605 | ilink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3606 | iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3607 | ilink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3608 | iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3609 | data1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3610 | iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3611 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3612 | IWL_ERR(priv, |
| 3613 | "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n", |
| 3614 | desc_lookup(desc), desc, time, blink1, blink2, |
| 3615 | ilink1, ilink2, data1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3618 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3619 | |
| 3620 | } |
| 3621 | |
Ben Cahill | f58177b | 2007-11-29 11:09:43 +0800 | [diff] [blame] | 3622 | #define EVENT_START_OFFSET (6 * sizeof(u32)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3623 | |
| 3624 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3625 | * iwl3945_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3626 | * |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3627 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3628 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3629 | 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] | 3630 | u32 num_events, u32 mode) |
| 3631 | { |
| 3632 | u32 i; |
| 3633 | u32 base; /* SRAM byte address of event log header */ |
| 3634 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 3635 | u32 ptr; /* SRAM byte address of log data */ |
| 3636 | u32 ev, time, data; /* event log data */ |
| 3637 | |
| 3638 | if (num_events == 0) |
| 3639 | return; |
| 3640 | |
| 3641 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 3642 | |
| 3643 | if (mode == 0) |
| 3644 | event_size = 2 * sizeof(u32); |
| 3645 | else |
| 3646 | event_size = 3 * sizeof(u32); |
| 3647 | |
| 3648 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 3649 | |
| 3650 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 3651 | * place event id # at far right for easier visual parsing. */ |
| 3652 | for (i = 0; i < num_events; i++) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3653 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3654 | ptr += sizeof(u32); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3655 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3656 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3657 | if (mode == 0) { |
| 3658 | /* data, ev */ |
| 3659 | IWL_ERR(priv, "0x%08x\t%04u\n", time, ev); |
| 3660 | } else { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3661 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3662 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3663 | IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3664 | } |
| 3665 | } |
| 3666 | } |
| 3667 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3668 | static void iwl3945_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3669 | { |
| 3670 | int rc; |
| 3671 | u32 base; /* SRAM byte address of event log header */ |
| 3672 | u32 capacity; /* event log capacity in # entries */ |
| 3673 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 3674 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 3675 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 3676 | u32 size; /* # entries that we'll print */ |
| 3677 | |
| 3678 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3679 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3680 | IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3681 | return; |
| 3682 | } |
| 3683 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3684 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3685 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3686 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3687 | return; |
| 3688 | } |
| 3689 | |
| 3690 | /* event log header */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3691 | capacity = iwl_read_targ_mem(priv, base); |
| 3692 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 3693 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 3694 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3695 | |
| 3696 | size = num_wraps ? capacity : next_entry; |
| 3697 | |
| 3698 | /* bail out if nothing in log */ |
| 3699 | if (size == 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3700 | IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3701 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3702 | return; |
| 3703 | } |
| 3704 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3705 | 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] | 3706 | size, num_wraps); |
| 3707 | |
| 3708 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 3709 | * i.e the next one that uCode would fill. */ |
| 3710 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3711 | iwl3945_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3712 | capacity - next_entry, mode); |
| 3713 | |
| 3714 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3715 | iwl3945_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3716 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3717 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3721 | * 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] | 3722 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3723 | static void iwl3945_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3724 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3725 | /* Set the FW error flag -- cleared on iwl3945_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3726 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 3727 | |
| 3728 | /* Cancel currently queued command. */ |
| 3729 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3730 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3731 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3732 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3733 | iwl3945_dump_nic_error_log(priv); |
| 3734 | iwl3945_dump_nic_event_log(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3735 | iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3736 | } |
| 3737 | #endif |
| 3738 | |
| 3739 | wake_up_interruptible(&priv->wait_command_queue); |
| 3740 | |
| 3741 | /* Keep the restart process from trying to send host |
| 3742 | * commands by clearing the INIT status bit */ |
| 3743 | clear_bit(STATUS_READY, &priv->status); |
| 3744 | |
| 3745 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3746 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 3747 | "Restarting adapter due to uCode error.\n"); |
| 3748 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3749 | if (iwl3945_is_associated(priv)) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3750 | memcpy(&priv->recovery39_rxon, &priv->active39_rxon, |
| 3751 | sizeof(priv->recovery39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3752 | priv->error_recovering = 1; |
| 3753 | } |
| 3754 | queue_work(priv->workqueue, &priv->restart); |
| 3755 | } |
| 3756 | } |
| 3757 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3758 | static void iwl3945_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3759 | { |
| 3760 | unsigned long flags; |
| 3761 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3762 | memcpy(&priv->staging39_rxon, &priv->recovery39_rxon, |
| 3763 | sizeof(priv->staging39_rxon)); |
| 3764 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3765 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3766 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3767 | iwl3945_add_station(priv, priv->bssid, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3768 | |
| 3769 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3770 | priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3771 | priv->error_recovering = 0; |
| 3772 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3773 | } |
| 3774 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3775 | static void iwl3945_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3776 | { |
| 3777 | u32 inta, handled = 0; |
| 3778 | u32 inta_fh; |
| 3779 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3780 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3781 | u32 inta_mask; |
| 3782 | #endif |
| 3783 | |
| 3784 | spin_lock_irqsave(&priv->lock, flags); |
| 3785 | |
| 3786 | /* Ack/clear/reset pending uCode interrupts. |
| 3787 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 3788 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3789 | inta = iwl_read32(priv, CSR_INT); |
| 3790 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3791 | |
| 3792 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 3793 | * Any new interrupts that happen after this, either while we're |
| 3794 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3795 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 3796 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3797 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3798 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3799 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3800 | /* just for debug */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3801 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3802 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 3803 | inta, inta_mask, inta_fh); |
| 3804 | } |
| 3805 | #endif |
| 3806 | |
| 3807 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 3808 | * atomic, make sure that inta covers all the interrupts that |
| 3809 | * we've discovered, even if FH interrupt came in just after |
| 3810 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3811 | if (inta_fh & CSR39_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3812 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3813 | if (inta_fh & CSR39_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3814 | inta |= CSR_INT_BIT_FH_TX; |
| 3815 | |
| 3816 | /* Now service all interrupt bits discovered above. */ |
| 3817 | if (inta & CSR_INT_BIT_HW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3818 | IWL_ERR(priv, "Microcode HW error detected. Restarting.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3819 | |
| 3820 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3821 | iwl3945_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3822 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3823 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3824 | |
| 3825 | handled |= CSR_INT_BIT_HW_ERR; |
| 3826 | |
| 3827 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3828 | |
| 3829 | return; |
| 3830 | } |
| 3831 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3832 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3833 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3834 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3835 | if (inta & CSR_INT_BIT_SCD) |
| 3836 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 3837 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3838 | |
| 3839 | /* Alive notification via Rx interrupt will do the real work */ |
| 3840 | if (inta & CSR_INT_BIT_ALIVE) |
| 3841 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 3842 | } |
| 3843 | #endif |
| 3844 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3845 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3846 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3847 | /* Error detected by uCode */ |
| 3848 | if (inta & CSR_INT_BIT_SW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3849 | IWL_ERR(priv, "Microcode SW error detected. " |
| 3850 | "Restarting 0x%X.\n", inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3851 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3852 | handled |= CSR_INT_BIT_SW_ERR; |
| 3853 | } |
| 3854 | |
| 3855 | /* uCode wakes up after power-down sleep */ |
| 3856 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 3857 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 3858 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Samuel Ortiz | 4f3602c | 2009-01-19 15:30:25 -0800 | [diff] [blame^] | 3859 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 3860 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 3861 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 3862 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 3863 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 3864 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3865 | |
| 3866 | handled |= CSR_INT_BIT_WAKEUP; |
| 3867 | } |
| 3868 | |
| 3869 | /* All uCode command responses, including Tx command responses, |
| 3870 | * Rx "responses" (frame-received notification), and other |
| 3871 | * notifications from uCode come through here*/ |
| 3872 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3873 | iwl3945_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3874 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 3875 | } |
| 3876 | |
| 3877 | if (inta & CSR_INT_BIT_FH_TX) { |
| 3878 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 3879 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3880 | iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); |
| 3881 | if (!iwl_grab_nic_access(priv)) { |
| 3882 | iwl_write_direct32(priv, FH39_TCSR_CREDIT |
Tomas Winkler | bddadf8 | 2008-12-19 10:37:01 +0800 | [diff] [blame] | 3883 | (FH39_SRVC_CHNL), 0x0); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3884 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3885 | } |
| 3886 | handled |= CSR_INT_BIT_FH_TX; |
| 3887 | } |
| 3888 | |
| 3889 | if (inta & ~handled) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3890 | IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3891 | |
| 3892 | if (inta & ~CSR_INI_SET_MASK) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3893 | IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3894 | inta & ~CSR_INI_SET_MASK); |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3895 | IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3899 | /* only Re-enable if disabled by irq */ |
| 3900 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 3901 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3902 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3903 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3904 | if (priv->debug_level & (IWL_DL_ISR)) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3905 | inta = iwl_read32(priv, CSR_INT); |
| 3906 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 3907 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3908 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 3909 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 3910 | } |
| 3911 | #endif |
| 3912 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3913 | } |
| 3914 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3915 | static irqreturn_t iwl3945_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3916 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3917 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3918 | u32 inta, inta_mask; |
| 3919 | u32 inta_fh; |
| 3920 | if (!priv) |
| 3921 | return IRQ_NONE; |
| 3922 | |
| 3923 | spin_lock(&priv->lock); |
| 3924 | |
| 3925 | /* Disable (but don't clear!) interrupts here to avoid |
| 3926 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 3927 | * If we have something to service, the tasklet will re-enable ints. |
| 3928 | * 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] | 3929 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 3930 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3931 | |
| 3932 | /* Discover which interrupts are active/pending */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3933 | inta = iwl_read32(priv, CSR_INT); |
| 3934 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3935 | |
| 3936 | /* Ignore interrupt if there's nothing in NIC to service. |
| 3937 | * This may be due to IRQ shared with another device, |
| 3938 | * or due to sporadic interrupts thrown from our NIC. */ |
| 3939 | if (!inta && !inta_fh) { |
| 3940 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 3941 | goto none; |
| 3942 | } |
| 3943 | |
| 3944 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
| 3945 | /* Hardware disappeared */ |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3946 | IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 3947 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 3951 | inta, inta_mask, inta_fh); |
| 3952 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3953 | inta &= ~CSR_INT_BIT_SCD; |
| 3954 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3955 | /* iwl3945_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3956 | if (likely(inta || inta_fh)) |
| 3957 | tasklet_schedule(&priv->irq_tasklet); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 3958 | unplugged: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3959 | spin_unlock(&priv->lock); |
| 3960 | |
| 3961 | return IRQ_HANDLED; |
| 3962 | |
| 3963 | none: |
| 3964 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3965 | /* only Re-enable if disabled by irq */ |
| 3966 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 3967 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3968 | spin_unlock(&priv->lock); |
| 3969 | return IRQ_NONE; |
| 3970 | } |
| 3971 | |
| 3972 | /************************** EEPROM BANDS **************************** |
| 3973 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3974 | * The iwl3945_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3975 | * EEPROM contents to the specific channel number supported for each |
| 3976 | * band. |
| 3977 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3978 | * 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] | 3979 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 3980 | * The specific geography and calibration information for that channel |
| 3981 | * is contained in the eeprom map itself. |
| 3982 | * |
| 3983 | * During init, we copy the eeprom information and channel map |
| 3984 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 3985 | * |
| 3986 | * channel_map_24/52 provides the index in the channel_info array for a |
| 3987 | * given channel. We have to have two separate maps as there is channel |
| 3988 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 3989 | * band_2 |
| 3990 | * |
| 3991 | * A value of 0xff stored in the channel_map indicates that the channel |
| 3992 | * is not supported by the hardware at all. |
| 3993 | * |
| 3994 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 3995 | * valid for Tx with the current hardware. This means that |
| 3996 | * while the system can tune and receive on a given channel, it may not |
| 3997 | * be able to associate or transmit any frames on that |
| 3998 | * channel. There is no corresponding channel information for that |
| 3999 | * entry. |
| 4000 | * |
| 4001 | *********************************************************************/ |
| 4002 | |
| 4003 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4004 | static const u8 iwl3945_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4005 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 4006 | }; |
| 4007 | |
| 4008 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4009 | static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4010 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 4011 | }; |
| 4012 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4013 | static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4014 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 4015 | }; |
| 4016 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4017 | static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4018 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 4019 | }; |
| 4020 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4021 | static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4022 | 145, 149, 153, 157, 161, 165 |
| 4023 | }; |
| 4024 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4025 | 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] | 4026 | int *eeprom_ch_count, |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4027 | const struct iwl_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4028 | **eeprom_ch_info, |
| 4029 | const u8 **eeprom_ch_index) |
| 4030 | { |
| 4031 | switch (band) { |
| 4032 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4033 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4034 | *eeprom_ch_info = priv->eeprom39.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4035 | *eeprom_ch_index = iwl3945_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4036 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4037 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4038 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4039 | *eeprom_ch_info = priv->eeprom39.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4040 | *eeprom_ch_index = iwl3945_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4041 | break; |
| 4042 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4043 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4044 | *eeprom_ch_info = priv->eeprom39.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4045 | *eeprom_ch_index = iwl3945_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4046 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4047 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4048 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4049 | *eeprom_ch_info = priv->eeprom39.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4050 | *eeprom_ch_index = iwl3945_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4051 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4052 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4053 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4054 | *eeprom_ch_info = priv->eeprom39.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4055 | *eeprom_ch_index = iwl3945_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4056 | break; |
| 4057 | default: |
| 4058 | BUG(); |
| 4059 | return; |
| 4060 | } |
| 4061 | } |
| 4062 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4063 | /** |
| 4064 | * iwl3945_get_channel_info - Find driver's private channel info |
| 4065 | * |
| 4066 | * Based on band and channel number. |
| 4067 | */ |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4068 | const struct iwl_channel_info * |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4069 | iwl3945_get_channel_info(const struct iwl_priv *priv, |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4070 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4071 | { |
| 4072 | int i; |
| 4073 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4074 | switch (band) { |
| 4075 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4076 | for (i = 14; i < priv->channel_count; i++) { |
| 4077 | if (priv->channel_info[i].channel == channel) |
| 4078 | return &priv->channel_info[i]; |
| 4079 | } |
| 4080 | break; |
| 4081 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4082 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4083 | if (channel >= 1 && channel <= 14) |
| 4084 | return &priv->channel_info[channel - 1]; |
| 4085 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4086 | case IEEE80211_NUM_BANDS: |
| 4087 | WARN_ON(1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | return NULL; |
| 4091 | } |
| 4092 | |
| 4093 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 4094 | ? # x " " : "") |
| 4095 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4096 | /** |
| 4097 | * iwl3945_init_channel_map - Set up driver's info for all possible channels |
| 4098 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4099 | static int iwl3945_init_channel_map(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4100 | { |
| 4101 | int eeprom_ch_count = 0; |
| 4102 | const u8 *eeprom_ch_index = NULL; |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4103 | const struct iwl_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4104 | int band, ch; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4105 | struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4106 | |
| 4107 | if (priv->channel_count) { |
| 4108 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 4109 | return 0; |
| 4110 | } |
| 4111 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4112 | if (priv->eeprom39.version < 0x2f) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4113 | IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4114 | priv->eeprom39.version); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4115 | return -EINVAL; |
| 4116 | } |
| 4117 | |
| 4118 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 4119 | |
| 4120 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4121 | ARRAY_SIZE(iwl3945_eeprom_band_1) + |
| 4122 | ARRAY_SIZE(iwl3945_eeprom_band_2) + |
| 4123 | ARRAY_SIZE(iwl3945_eeprom_band_3) + |
| 4124 | ARRAY_SIZE(iwl3945_eeprom_band_4) + |
| 4125 | ARRAY_SIZE(iwl3945_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4126 | |
| 4127 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 4128 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4129 | priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4130 | priv->channel_count, GFP_KERNEL); |
| 4131 | if (!priv->channel_info) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4132 | IWL_ERR(priv, "Could not allocate channel_info\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4133 | priv->channel_count = 0; |
| 4134 | return -ENOMEM; |
| 4135 | } |
| 4136 | |
| 4137 | ch_info = priv->channel_info; |
| 4138 | |
| 4139 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 4140 | * channel map we maintain (that contains additional information than |
| 4141 | * what just in the EEPROM) */ |
| 4142 | for (band = 1; band <= 5; band++) { |
| 4143 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4144 | iwl3945_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4145 | &eeprom_ch_info, &eeprom_ch_index); |
| 4146 | |
| 4147 | /* Loop through each band adding each of the channels */ |
| 4148 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 4149 | ch_info->channel = eeprom_ch_index[ch]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4150 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 4151 | IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4152 | |
| 4153 | /* permanently store EEPROM's channel regulatory flags |
| 4154 | * and max power in channel info database. */ |
| 4155 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 4156 | |
| 4157 | /* Copy the run-time flags so they are there even on |
| 4158 | * invalid channels */ |
| 4159 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 4160 | |
| 4161 | if (!(is_channel_valid(ch_info))) { |
| 4162 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 4163 | "No traffic\n", |
| 4164 | ch_info->channel, |
| 4165 | ch_info->flags, |
| 4166 | is_channel_a_band(ch_info) ? |
| 4167 | "5.2" : "2.4"); |
| 4168 | ch_info++; |
| 4169 | continue; |
| 4170 | } |
| 4171 | |
| 4172 | /* Initialize regulatory-based run-time data */ |
| 4173 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 4174 | eeprom_ch_info[ch].max_power_avg; |
| 4175 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 4176 | ch_info->min_power = 0; |
| 4177 | |
Guy Cohen | fe7c404 | 2008-04-21 15:41:56 -0700 | [diff] [blame] | 4178 | 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] | 4179 | " %ddBm): Ad-Hoc %ssupported\n", |
| 4180 | ch_info->channel, |
| 4181 | is_channel_a_band(ch_info) ? |
| 4182 | "5.2" : "2.4", |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4183 | CHECK_AND_PRINT(VALID), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4184 | CHECK_AND_PRINT(IBSS), |
| 4185 | CHECK_AND_PRINT(ACTIVE), |
| 4186 | CHECK_AND_PRINT(RADAR), |
| 4187 | CHECK_AND_PRINT(WIDE), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4188 | CHECK_AND_PRINT(DFS), |
| 4189 | eeprom_ch_info[ch].flags, |
| 4190 | eeprom_ch_info[ch].max_power_avg, |
| 4191 | ((eeprom_ch_info[ch]. |
| 4192 | flags & EEPROM_CHANNEL_IBSS) |
| 4193 | && !(eeprom_ch_info[ch]. |
| 4194 | flags & EEPROM_CHANNEL_RADAR)) |
| 4195 | ? "" : "not "); |
| 4196 | |
| 4197 | /* Set the user_txpower_limit to the highest power |
| 4198 | * supported by any channel */ |
| 4199 | if (eeprom_ch_info[ch].max_power_avg > |
| 4200 | priv->user_txpower_limit) |
| 4201 | priv->user_txpower_limit = |
| 4202 | eeprom_ch_info[ch].max_power_avg; |
| 4203 | |
| 4204 | ch_info++; |
| 4205 | } |
| 4206 | } |
| 4207 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4208 | /* Set up txpower settings in driver for all channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4209 | if (iwl3945_txpower_set_from_eeprom(priv)) |
| 4210 | return -EIO; |
| 4211 | |
| 4212 | return 0; |
| 4213 | } |
| 4214 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4215 | /* |
| 4216 | * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map |
| 4217 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4218 | static void iwl3945_free_channel_map(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4219 | { |
| 4220 | kfree(priv->channel_info); |
| 4221 | priv->channel_count = 0; |
| 4222 | } |
| 4223 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4224 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 4225 | * sending probe req. This should be set long enough to hear probe responses |
| 4226 | * from more than one AP. */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4227 | #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */ |
| 4228 | #define IWL_ACTIVE_DWELL_TIME_52 (20) |
| 4229 | |
| 4230 | #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3) |
| 4231 | #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4232 | |
| 4233 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 4234 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 4235 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 4236 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 4237 | * no other traffic). |
| 4238 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 4239 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4240 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4241 | |
| 4242 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 4243 | * Must be set longer than active dwell time. |
| 4244 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 4245 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 4246 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 4247 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 4248 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 4249 | |
Kolekar, Abhijeet | e720ce9 | 2008-11-07 09:58:42 -0800 | [diff] [blame] | 4250 | #define IWL_SCAN_PROBE_MASK(n) (BIT(n) | (BIT(n) - BIT(1))) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4251 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4252 | static inline u16 iwl3945_get_active_dwell_time(struct iwl_priv *priv, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4253 | enum ieee80211_band band, |
| 4254 | u8 n_probes) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4255 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4256 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4257 | return IWL_ACTIVE_DWELL_TIME_52 + |
| 4258 | IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4259 | else |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4260 | return IWL_ACTIVE_DWELL_TIME_24 + |
| 4261 | IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4264 | static u16 iwl3945_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4265 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4266 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4267 | u16 passive = (band == IEEE80211_BAND_2GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4268 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 4269 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 4270 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4271 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4272 | /* If we're associated, we clamp the maximum passive |
| 4273 | * dwell time to be 98% of the beacon interval (minus |
| 4274 | * 2 * channel tune time) */ |
| 4275 | passive = priv->beacon_int; |
| 4276 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 4277 | passive = IWL_PASSIVE_DWELL_BASE; |
| 4278 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 4279 | } |
| 4280 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4281 | return passive; |
| 4282 | } |
| 4283 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4284 | static int iwl3945_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4285 | enum ieee80211_band band, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4286 | u8 is_active, u8 n_probes, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4287 | struct iwl3945_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4288 | { |
| 4289 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4290 | const struct ieee80211_supported_band *sband; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4291 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4292 | u16 passive_dwell = 0; |
| 4293 | u16 active_dwell = 0; |
| 4294 | int added, i; |
| 4295 | |
Kolekar, Abhijeet | cbba18c | 2008-12-19 10:37:42 +0800 | [diff] [blame] | 4296 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4297 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4298 | return 0; |
| 4299 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4300 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4301 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4302 | active_dwell = iwl3945_get_active_dwell_time(priv, band, n_probes); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4303 | passive_dwell = iwl3945_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4304 | |
Abhijeet Kolekar | 8f4807a | 2008-09-03 11:26:31 +0800 | [diff] [blame] | 4305 | if (passive_dwell <= active_dwell) |
| 4306 | passive_dwell = active_dwell + 1; |
| 4307 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4308 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 4309 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 4310 | continue; |
| 4311 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4312 | scan_ch->channel = channels[i].hw_value; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4313 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4314 | ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4315 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 4316 | IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4317 | scan_ch->channel); |
| 4318 | continue; |
| 4319 | } |
| 4320 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4321 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 4322 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 4323 | /* If passive , set up for auto-switch |
| 4324 | * and use long active_dwell time. |
| 4325 | */ |
| 4326 | if (!is_active || is_channel_passive(ch_info) || |
| 4327 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) { |
| 4328 | scan_ch->type = 0; /* passive */ |
| 4329 | if (IWL_UCODE_API(priv->ucode_ver) == 1) |
| 4330 | scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1); |
| 4331 | } else { |
| 4332 | scan_ch->type = 1; /* active */ |
| 4333 | } |
| 4334 | |
| 4335 | /* Set direct probe bits. These may be used both for active |
| 4336 | * scan channels (probes gets sent right away), |
| 4337 | * or for passive channels (probes get se sent only after |
| 4338 | * hearing clear Rx packet).*/ |
| 4339 | if (IWL_UCODE_API(priv->ucode_ver) >= 2) { |
| 4340 | if (n_probes) |
| 4341 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4342 | } else { |
| 4343 | /* uCode v1 does not allow setting direct probe bits on |
| 4344 | * passive channel. */ |
| 4345 | if ((scan_ch->type & 1) && n_probes) |
| 4346 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4347 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4348 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4349 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4350 | scan_ch->tpc.dsp_atten = 110; |
| 4351 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 4352 | |
| 4353 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4354 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4355 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 4356 | else { |
| 4357 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 4358 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4359 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 4360 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4361 | */ |
| 4362 | } |
| 4363 | |
| 4364 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 4365 | scan_ch->channel, |
| 4366 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 4367 | (scan_ch->type & 1) ? |
| 4368 | active_dwell : passive_dwell); |
| 4369 | |
| 4370 | scan_ch++; |
| 4371 | added++; |
| 4372 | } |
| 4373 | |
| 4374 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 4375 | return added; |
| 4376 | } |
| 4377 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4378 | static void iwl3945_init_hw_rates(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4379 | struct ieee80211_rate *rates) |
| 4380 | { |
| 4381 | int i; |
| 4382 | |
| 4383 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4384 | rates[i].bitrate = iwl3945_rates[i].ieee * 5; |
| 4385 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 4386 | rates[i].hw_value_short = i; |
| 4387 | rates[i].flags = 0; |
Samuel Ortiz | d9829a6 | 2008-12-19 10:37:12 +0800 | [diff] [blame] | 4388 | if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4389 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4390 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4391 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4392 | rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4393 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4394 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4395 | } |
| 4396 | } |
| 4397 | |
| 4398 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4399 | * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4400 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4401 | static int iwl3945_init_geos(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4402 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4403 | struct iwl_channel_info *ch; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4404 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4405 | struct ieee80211_channel *channels; |
| 4406 | struct ieee80211_channel *geo_ch; |
| 4407 | struct ieee80211_rate *rates; |
| 4408 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4409 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4410 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 4411 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4412 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 4413 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4414 | return 0; |
| 4415 | } |
| 4416 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4417 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 4418 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4419 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4420 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4421 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4422 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4423 | GFP_KERNEL); |
| 4424 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4425 | kfree(channels); |
| 4426 | return -ENOMEM; |
| 4427 | } |
| 4428 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4429 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4430 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 4431 | sband->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)]; |
| 4432 | /* just OFDM */ |
| 4433 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
| 4434 | sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4435 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4436 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4437 | sband->channels = channels; |
| 4438 | /* OFDM & CCK */ |
| 4439 | sband->bitrates = rates; |
| 4440 | sband->n_bitrates = IWL_RATE_COUNT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4441 | |
| 4442 | priv->ieee_channels = channels; |
| 4443 | priv->ieee_rates = rates; |
| 4444 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4445 | iwl3945_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4446 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4447 | for (i = 0; i < priv->channel_count; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4448 | ch = &priv->channel_info[i]; |
| 4449 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4450 | /* FIXME: might be removed if scan is OK*/ |
| 4451 | if (!is_channel_valid(ch)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4452 | continue; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4453 | |
| 4454 | if (is_channel_a_band(ch)) |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4455 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4456 | else |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4457 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4458 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4459 | geo_ch = &sband->channels[sband->n_channels++]; |
| 4460 | |
| 4461 | geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4462 | geo_ch->max_power = ch->max_power_avg; |
| 4463 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 4464 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4465 | |
| 4466 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4467 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 4468 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4469 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4470 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 4471 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4472 | |
| 4473 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4474 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4475 | |
| 4476 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 4477 | priv->max_channel_txpower_limit = |
| 4478 | ch->max_power_avg; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4479 | } else { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4480 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | /* Save flags for reg domain usage */ |
| 4484 | geo_ch->orig_flags = geo_ch->flags; |
| 4485 | |
| 4486 | IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n", |
| 4487 | ch->channel, geo_ch->center_freq, |
| 4488 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 4489 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 4490 | "restricted" : "valid", |
| 4491 | geo_ch->flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4492 | } |
| 4493 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4494 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && |
| 4495 | priv->cfg->sku & IWL_SKU_A) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4496 | IWL_INFO(priv, "Incorrectly detected BG card as ABG. " |
| 4497 | "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 4498 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4499 | priv->cfg->sku &= ~IWL_SKU_A; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4502 | 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] | 4503 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 4504 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4505 | |
John W. Linville | e0e0a67 | 2008-03-25 15:58:40 -0400 | [diff] [blame] | 4506 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 4507 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 4508 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4509 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 4510 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 4511 | &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4512 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4513 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4514 | |
| 4515 | return 0; |
| 4516 | } |
| 4517 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4518 | /* |
| 4519 | * iwl3945_free_geos - undo allocations in iwl3945_init_geos |
| 4520 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4521 | static void iwl3945_free_geos(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4522 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4523 | kfree(priv->ieee_channels); |
| 4524 | kfree(priv->ieee_rates); |
| 4525 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4526 | } |
| 4527 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4528 | /****************************************************************************** |
| 4529 | * |
| 4530 | * uCode download functions |
| 4531 | * |
| 4532 | ******************************************************************************/ |
| 4533 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4534 | static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4535 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4536 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 4537 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 4538 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 4539 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 4540 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 4541 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4545 | * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4546 | * looking at all data. |
| 4547 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4548 | 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] | 4549 | { |
| 4550 | u32 val; |
| 4551 | u32 save_len = len; |
| 4552 | int rc = 0; |
| 4553 | u32 errcnt; |
| 4554 | |
| 4555 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4556 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4557 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4558 | if (rc) |
| 4559 | return rc; |
| 4560 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4561 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4562 | IWL39_RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4563 | |
| 4564 | errcnt = 0; |
| 4565 | for (; len > 0; len -= sizeof(u32), image++) { |
| 4566 | /* read data comes through single port, auto-incr addr */ |
| 4567 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4568 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4569 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4570 | if (val != le32_to_cpu(*image)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4571 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4572 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4573 | save_len - len, val, le32_to_cpu(*image)); |
| 4574 | rc = -EIO; |
| 4575 | errcnt++; |
| 4576 | if (errcnt >= 20) |
| 4577 | break; |
| 4578 | } |
| 4579 | } |
| 4580 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4581 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4582 | |
| 4583 | if (!errcnt) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 4584 | IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4585 | |
| 4586 | return rc; |
| 4587 | } |
| 4588 | |
| 4589 | |
| 4590 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4591 | * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4592 | * using sample data 100 bytes apart. If these sample points are good, |
| 4593 | * it's a pretty good bet that everything between them is good, too. |
| 4594 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4595 | 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] | 4596 | { |
| 4597 | u32 val; |
| 4598 | int rc = 0; |
| 4599 | u32 errcnt = 0; |
| 4600 | u32 i; |
| 4601 | |
| 4602 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4603 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4604 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4605 | if (rc) |
| 4606 | return rc; |
| 4607 | |
| 4608 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 4609 | /* read data comes through single port, auto-incr addr */ |
| 4610 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4611 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4612 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4613 | i + IWL39_RTC_INST_LOWER_BOUND); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4614 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4615 | if (val != le32_to_cpu(*image)) { |
| 4616 | #if 0 /* Enable this if you want to see details */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4617 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4618 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4619 | i, val, *image); |
| 4620 | #endif |
| 4621 | rc = -EIO; |
| 4622 | errcnt++; |
| 4623 | if (errcnt >= 3) |
| 4624 | break; |
| 4625 | } |
| 4626 | } |
| 4627 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4628 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4629 | |
| 4630 | return rc; |
| 4631 | } |
| 4632 | |
| 4633 | |
| 4634 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4635 | * iwl3945_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4636 | * and verify its contents |
| 4637 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4638 | static int iwl3945_verify_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4639 | { |
| 4640 | __le32 *image; |
| 4641 | u32 len; |
| 4642 | int rc = 0; |
| 4643 | |
| 4644 | /* Try bootstrap */ |
| 4645 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4646 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4647 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4648 | if (rc == 0) { |
| 4649 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 4650 | return 0; |
| 4651 | } |
| 4652 | |
| 4653 | /* Try initialize */ |
| 4654 | image = (__le32 *)priv->ucode_init.v_addr; |
| 4655 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4656 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4657 | if (rc == 0) { |
| 4658 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 4659 | return 0; |
| 4660 | } |
| 4661 | |
| 4662 | /* Try runtime/protocol */ |
| 4663 | image = (__le32 *)priv->ucode_code.v_addr; |
| 4664 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4665 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4666 | if (rc == 0) { |
| 4667 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 4668 | return 0; |
| 4669 | } |
| 4670 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4671 | IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4672 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4673 | /* Since nothing seems to match, show first several data entries in |
| 4674 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 4675 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4676 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4677 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4678 | rc = iwl3945_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4679 | |
| 4680 | return rc; |
| 4681 | } |
| 4682 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4683 | static void iwl3945_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4684 | { |
| 4685 | /* Remove all resets to allow NIC to operate */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4686 | iwl_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4690 | * iwl3945_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4691 | * |
| 4692 | * Copy into buffers for card to fetch via bus-mastering |
| 4693 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4694 | static int iwl3945_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4695 | { |
Kolekar, Abhijeet | a78fe75 | 2008-12-19 10:37:21 +0800 | [diff] [blame] | 4696 | struct iwl_ucode *ucode; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4697 | int ret = -EINVAL, index; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4698 | const struct firmware *ucode_raw; |
| 4699 | /* firmware file name contains uCode/driver compatibility version */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4700 | const char *name_pre = priv->cfg->fw_name_pre; |
| 4701 | const unsigned int api_max = priv->cfg->ucode_api_max; |
| 4702 | const unsigned int api_min = priv->cfg->ucode_api_min; |
| 4703 | char buf[25]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4704 | u8 *src; |
| 4705 | size_t len; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4706 | 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] | 4707 | |
| 4708 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 4709 | * request_firmware() is synchronous, file is in memory on return. */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4710 | for (index = api_max; index >= api_min; index--) { |
| 4711 | sprintf(buf, "%s%u%s", name_pre, index, ".ucode"); |
| 4712 | ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev); |
| 4713 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4714 | IWL_ERR(priv, "%s firmware file req failed: %d\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4715 | buf, ret); |
| 4716 | if (ret == -ENOENT) |
| 4717 | continue; |
| 4718 | else |
| 4719 | goto error; |
| 4720 | } else { |
| 4721 | if (index < api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4722 | IWL_ERR(priv, "Loaded firmware %s, " |
| 4723 | "which is deprecated. " |
| 4724 | " Please use API v%u instead.\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4725 | buf, api_max); |
| 4726 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 4727 | buf, ucode_raw->size); |
| 4728 | break; |
| 4729 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4730 | } |
| 4731 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4732 | if (ret < 0) |
| 4733 | goto error; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4734 | |
| 4735 | /* Make sure that we got at least our header! */ |
| 4736 | if (ucode_raw->size < sizeof(*ucode)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4737 | IWL_ERR(priv, "File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4738 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4739 | goto err_release; |
| 4740 | } |
| 4741 | |
| 4742 | /* Data from ucode file: header followed by uCode images */ |
| 4743 | ucode = (void *)ucode_raw->data; |
| 4744 | |
Chatre, Reinette | c02b3ac | 2008-12-02 12:14:05 -0800 | [diff] [blame] | 4745 | priv->ucode_ver = le32_to_cpu(ucode->ver); |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4746 | api_ver = IWL_UCODE_API(priv->ucode_ver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4747 | inst_size = le32_to_cpu(ucode->inst_size); |
| 4748 | data_size = le32_to_cpu(ucode->data_size); |
| 4749 | init_size = le32_to_cpu(ucode->init_size); |
| 4750 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 4751 | boot_size = le32_to_cpu(ucode->boot_size); |
| 4752 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4753 | /* api_ver should match the api version forming part of the |
| 4754 | * firmware filename ... but we don't check for that and only rely |
| 4755 | * on the API version read from firware header from here on forward */ |
| 4756 | |
| 4757 | if (api_ver < api_min || api_ver > api_max) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4758 | IWL_ERR(priv, "Driver unable to support your firmware API. " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4759 | "Driver supports v%u, firmware is v%u.\n", |
| 4760 | api_max, api_ver); |
| 4761 | priv->ucode_ver = 0; |
| 4762 | ret = -EINVAL; |
| 4763 | goto err_release; |
| 4764 | } |
| 4765 | if (api_ver != api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4766 | IWL_ERR(priv, "Firmware has old API version. Expected %u, " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4767 | "got %u. New firmware can be obtained " |
| 4768 | "from http://www.intellinuxwireless.org.\n", |
| 4769 | api_max, api_ver); |
| 4770 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4771 | IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n", |
| 4772 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 4773 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 4774 | IWL_UCODE_API(priv->ucode_ver), |
| 4775 | IWL_UCODE_SERIAL(priv->ucode_ver)); |
| 4776 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4777 | IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n", |
| 4778 | priv->ucode_ver); |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 4779 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size); |
| 4780 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size); |
| 4781 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size); |
| 4782 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size); |
| 4783 | 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] | 4784 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4785 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4786 | /* Verify size of file vs. image size info in file's header */ |
| 4787 | if (ucode_raw->size < sizeof(*ucode) + |
| 4788 | inst_size + data_size + init_size + |
| 4789 | init_data_size + boot_size) { |
| 4790 | |
| 4791 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 4792 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4793 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4794 | goto err_release; |
| 4795 | } |
| 4796 | |
| 4797 | /* Verify that uCode images will fit in card's SRAM */ |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4798 | if (inst_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4799 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 4800 | inst_size); |
| 4801 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4802 | goto err_release; |
| 4803 | } |
| 4804 | |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4805 | if (data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4806 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 4807 | data_size); |
| 4808 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4809 | goto err_release; |
| 4810 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4811 | if (init_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4812 | IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n", |
| 4813 | init_size); |
| 4814 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4815 | goto err_release; |
| 4816 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4817 | if (init_data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4818 | IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n", |
| 4819 | init_data_size); |
| 4820 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4821 | goto err_release; |
| 4822 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4823 | if (boot_size > IWL39_MAX_BSM_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4824 | IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n", |
| 4825 | boot_size); |
| 4826 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4827 | goto err_release; |
| 4828 | } |
| 4829 | |
| 4830 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 4831 | |
| 4832 | /* Runtime instructions and 2 copies of data: |
| 4833 | * 1) unmodified from disk |
| 4834 | * 2) backup cache for save/restore during power-downs */ |
| 4835 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4836 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4837 | |
| 4838 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4839 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4840 | |
| 4841 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4842 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4843 | |
| 4844 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4845 | !priv->ucode_data_backup.v_addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4846 | goto err_pci_alloc; |
| 4847 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4848 | /* Initialization instructions and data */ |
| 4849 | if (init_size && init_data_size) { |
| 4850 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4851 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4852 | |
| 4853 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4854 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4855 | |
| 4856 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 4857 | goto err_pci_alloc; |
| 4858 | } |
| 4859 | |
| 4860 | /* Bootstrap (instructions only, no data) */ |
| 4861 | if (boot_size) { |
| 4862 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4863 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4864 | |
| 4865 | if (!priv->ucode_boot.v_addr) |
| 4866 | goto err_pci_alloc; |
| 4867 | } |
| 4868 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4869 | /* Copy images into buffers for card's bus-master reads ... */ |
| 4870 | |
| 4871 | /* Runtime instructions (first block of data in file) */ |
| 4872 | src = &ucode->data[0]; |
| 4873 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4874 | 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] | 4875 | memcpy(priv->ucode_code.v_addr, src, len); |
| 4876 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 4877 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 4878 | |
| 4879 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4880 | * NOTE: Copy into backup buffer will be done in iwl3945_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4881 | src = &ucode->data[inst_size]; |
| 4882 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4883 | 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] | 4884 | memcpy(priv->ucode_data.v_addr, src, len); |
| 4885 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 4886 | |
| 4887 | /* Initialization instructions (3rd block) */ |
| 4888 | if (init_size) { |
| 4889 | src = &ucode->data[inst_size + data_size]; |
| 4890 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4891 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 4892 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4893 | memcpy(priv->ucode_init.v_addr, src, len); |
| 4894 | } |
| 4895 | |
| 4896 | /* Initialization data (4th block) */ |
| 4897 | if (init_data_size) { |
| 4898 | src = &ucode->data[inst_size + data_size + init_size]; |
| 4899 | len = priv->ucode_init_data.len; |
| 4900 | IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n", |
| 4901 | (int)len); |
| 4902 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 4903 | } |
| 4904 | |
| 4905 | /* Bootstrap instructions (5th block) */ |
| 4906 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 4907 | len = priv->ucode_boot.len; |
| 4908 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n", |
| 4909 | (int)len); |
| 4910 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 4911 | |
| 4912 | /* We have our copies now, allow OS release its copies */ |
| 4913 | release_firmware(ucode_raw); |
| 4914 | return 0; |
| 4915 | |
| 4916 | err_pci_alloc: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4917 | IWL_ERR(priv, "failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4918 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4919 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4920 | |
| 4921 | err_release: |
| 4922 | release_firmware(ucode_raw); |
| 4923 | |
| 4924 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4925 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | |
| 4929 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4930 | * iwl3945_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4931 | * |
| 4932 | * Tell initialization uCode where to find runtime uCode. |
| 4933 | * |
| 4934 | * BSM registers initially contain pointers to initialization uCode. |
| 4935 | * We need to replace them to load runtime uCode inst and data, |
| 4936 | * and to save runtime data when powering down. |
| 4937 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4938 | static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4939 | { |
| 4940 | dma_addr_t pinst; |
| 4941 | dma_addr_t pdata; |
| 4942 | int rc = 0; |
| 4943 | unsigned long flags; |
| 4944 | |
| 4945 | /* bits 31:0 for 3945 */ |
| 4946 | pinst = priv->ucode_code.p_addr; |
| 4947 | pdata = priv->ucode_data_backup.p_addr; |
| 4948 | |
| 4949 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4950 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4951 | if (rc) { |
| 4952 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4953 | return rc; |
| 4954 | } |
| 4955 | |
| 4956 | /* Tell bootstrap uCode where to find image to load */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4957 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 4958 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 4959 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4960 | priv->ucode_data.len); |
| 4961 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 4962 | /* 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] | 4963 | * that all new ptr/size info is in place */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4964 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4965 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 4966 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4967 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4968 | |
| 4969 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4970 | |
| 4971 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 4972 | |
| 4973 | return rc; |
| 4974 | } |
| 4975 | |
| 4976 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4977 | * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4978 | * |
| 4979 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 4980 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4981 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4982 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4983 | static void iwl3945_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4984 | { |
| 4985 | /* Check alive response for "valid" sign from uCode */ |
| 4986 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 4987 | /* We had an error bringing up the hardware, so take it |
| 4988 | * all the way back down so we can try again */ |
| 4989 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 4990 | goto restart; |
| 4991 | } |
| 4992 | |
| 4993 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 4994 | * This is a paranoid check, because we would not have gotten the |
| 4995 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4996 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4997 | /* Runtime instruction load was bad; |
| 4998 | * take it all the way back down so we can try again */ |
| 4999 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 5000 | goto restart; |
| 5001 | } |
| 5002 | |
| 5003 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 5004 | * load and launch runtime uCode, which will send us another "Alive" |
| 5005 | * notification. */ |
| 5006 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5007 | if (iwl3945_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5008 | /* Runtime instruction load won't happen; |
| 5009 | * take it all the way back down so we can try again */ |
| 5010 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 5011 | goto restart; |
| 5012 | } |
| 5013 | return; |
| 5014 | |
| 5015 | restart: |
| 5016 | queue_work(priv->workqueue, &priv->restart); |
| 5017 | } |
| 5018 | |
| 5019 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5020 | /* temporary */ |
| 5021 | static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, |
| 5022 | struct sk_buff *skb); |
| 5023 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5024 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5025 | * iwl3945_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5026 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5027 | * Alive gets handled by iwl3945_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5028 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5029 | static void iwl3945_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5030 | { |
| 5031 | int rc = 0; |
| 5032 | int thermal_spin = 0; |
| 5033 | u32 rfkill; |
| 5034 | |
| 5035 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 5036 | |
| 5037 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 5038 | /* We had an error bringing up the hardware, so take it |
| 5039 | * all the way back down so we can try again */ |
| 5040 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 5041 | goto restart; |
| 5042 | } |
| 5043 | |
| 5044 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 5045 | * This is a paranoid check, because we would not have gotten the |
| 5046 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5047 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5048 | /* Runtime instruction load was bad; |
| 5049 | * take it all the way back down so we can try again */ |
| 5050 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 5051 | goto restart; |
| 5052 | } |
| 5053 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5054 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5055 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5056 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5057 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5058 | IWL_WARN(priv, "Can not read RFKILL status from adapter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5059 | return; |
| 5060 | } |
| 5061 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5062 | rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5063 | IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5064 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5065 | |
| 5066 | if (rfkill & 0x1) { |
| 5067 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5068 | /* if RFKILL is not on, then wait for thermal |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5069 | * sensor in adapter to kick in */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5070 | while (iwl3945_hw_get_temperature(priv) == 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5071 | thermal_spin++; |
| 5072 | udelay(10); |
| 5073 | } |
| 5074 | |
| 5075 | if (thermal_spin) |
| 5076 | IWL_DEBUG_INFO("Thermal calibration took %dus\n", |
| 5077 | thermal_spin * 10); |
| 5078 | } else |
| 5079 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5080 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5081 | /* After the ALIVE response, we can send commands to 3945 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5082 | set_bit(STATUS_ALIVE, &priv->status); |
| 5083 | |
| 5084 | /* Clear out the uCode error bit if it is set */ |
| 5085 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 5086 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5087 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5088 | return; |
| 5089 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 5090 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5091 | |
| 5092 | priv->active_rate = priv->rates_mask; |
| 5093 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 5094 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5095 | iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5096 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5097 | if (iwl3945_is_associated(priv)) { |
| 5098 | struct iwl3945_rxon_cmd *active_rxon = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5099 | (struct iwl3945_rxon_cmd *)(&priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5100 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5101 | memcpy(&priv->staging39_rxon, &priv->active39_rxon, |
| 5102 | sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5103 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5104 | } else { |
| 5105 | /* Initialize our rx_config data */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 5106 | iwl3945_connection_init_rx_config(priv, priv->iw_mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5107 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5108 | } |
| 5109 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5110 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5111 | iwl3945_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5112 | |
| 5113 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5114 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5115 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5116 | iwl3945_reg_txpower_periodic(priv); |
| 5117 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 5118 | iwl3945_led_register(priv); |
| 5119 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5120 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 5121 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5122 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5123 | |
| 5124 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5125 | iwl3945_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5126 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5127 | /* reassociate for ADHOC mode */ |
| 5128 | if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) { |
| 5129 | struct sk_buff *beacon = ieee80211_beacon_get(priv->hw, |
| 5130 | priv->vif); |
| 5131 | if (beacon) |
| 5132 | iwl3945_mac_beacon_update(priv->hw, beacon); |
| 5133 | } |
| 5134 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5135 | return; |
| 5136 | |
| 5137 | restart: |
| 5138 | queue_work(priv->workqueue, &priv->restart); |
| 5139 | } |
| 5140 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5141 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5142 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5143 | static void __iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5144 | { |
| 5145 | unsigned long flags; |
| 5146 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5147 | struct ieee80211_conf *conf = NULL; |
| 5148 | |
| 5149 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 5150 | |
| 5151 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5152 | |
| 5153 | if (!exit_pending) |
| 5154 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5155 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 5156 | iwl3945_led_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5157 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5158 | |
| 5159 | /* Unblock any waiting calls */ |
| 5160 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 5161 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5162 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 5163 | * exiting the module */ |
| 5164 | if (!exit_pending) |
| 5165 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5166 | |
| 5167 | /* stop and reset the on-board processor */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5168 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5169 | |
| 5170 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5171 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5172 | iwl3945_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5173 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5174 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5175 | |
| 5176 | if (priv->mac80211_registered) |
| 5177 | ieee80211_stop_queues(priv->hw); |
| 5178 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5179 | /* If we have not previously called iwl3945_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5180 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5181 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5182 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5183 | STATUS_RF_KILL_HW | |
| 5184 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5185 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5186 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5187 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5188 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5189 | STATUS_IN_SUSPEND | |
| 5190 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5191 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5192 | goto exit; |
| 5193 | } |
| 5194 | |
| 5195 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 5196 | * SUSPEND bits and continue taking the NIC down. */ |
| 5197 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5198 | STATUS_RF_KILL_HW | |
| 5199 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5200 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5201 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5202 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5203 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 5204 | STATUS_IN_SUSPEND | |
| 5205 | test_bit(STATUS_FW_ERROR, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5206 | STATUS_FW_ERROR | |
| 5207 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5208 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5209 | |
| 5210 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5211 | 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] | 5212 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5213 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5214 | iwl3945_hw_txq_ctx_stop(priv); |
| 5215 | iwl3945_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5216 | |
| 5217 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5218 | if (!iwl_grab_nic_access(priv)) { |
| 5219 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5220 | APMG_CLK_VAL_DMA_CLK_RQT); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5221 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5222 | } |
| 5223 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5224 | |
| 5225 | udelay(5); |
| 5226 | |
Kolekar, Abhijeet | 01ec616 | 2008-12-19 10:37:38 +0800 | [diff] [blame] | 5227 | priv->cfg->ops->lib->apm_ops.reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5228 | exit: |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 5229 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5230 | |
| 5231 | if (priv->ibss_beacon) |
| 5232 | dev_kfree_skb(priv->ibss_beacon); |
| 5233 | priv->ibss_beacon = NULL; |
| 5234 | |
| 5235 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5236 | iwl3945_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5237 | } |
| 5238 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5239 | static void iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5240 | { |
| 5241 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5242 | __iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5243 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5244 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5245 | iwl3945_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | #define MAX_HW_RESTARTS 5 |
| 5249 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5250 | static int __iwl3945_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5251 | { |
| 5252 | int rc, i; |
| 5253 | |
| 5254 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5255 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5256 | return -EIO; |
| 5257 | } |
| 5258 | |
| 5259 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5260 | IWL_WARN(priv, "Radio disabled by SW RF kill (module " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5261 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5262 | return -ENODEV; |
| 5263 | } |
| 5264 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5265 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5266 | IWL_ERR(priv, "ucode not available for device bring up\n"); |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5267 | return -EIO; |
| 5268 | } |
| 5269 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5270 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5271 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5272 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 5273 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5274 | else { |
| 5275 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5276 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5277 | IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5278 | return -ENODEV; |
| 5279 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5280 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5281 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5282 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5283 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5284 | rc = iwl3945_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5285 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5286 | IWL_ERR(priv, "Unable to int nic\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5287 | return rc; |
| 5288 | } |
| 5289 | |
| 5290 | /* make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5291 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5292 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5293 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 5294 | |
| 5295 | /* clear (again), then enable host interrupts */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5296 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5297 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5298 | |
| 5299 | /* really make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5300 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5301 | 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] | 5302 | |
| 5303 | /* Copy original ucode data image from disk into backup cache. |
| 5304 | * This will be used to initialize the on-board processor's |
| 5305 | * data SRAM for a clean start when the runtime program first loads. */ |
| 5306 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5307 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5308 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5309 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 5310 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5311 | return 0; |
| 5312 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5313 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 5314 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5315 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5316 | |
| 5317 | /* load bootstrap state machine, |
| 5318 | * load bootstrap program into processor's memory, |
| 5319 | * prepare to load the "initialize" uCode */ |
Kolekar, Abhijeet | 0164b9b | 2008-12-19 10:37:37 +0800 | [diff] [blame] | 5320 | priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5321 | |
| 5322 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5323 | IWL_ERR(priv, |
| 5324 | "Unable to set up bootstrap uCode: %d\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5325 | continue; |
| 5326 | } |
| 5327 | |
| 5328 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5329 | iwl3945_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5330 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5331 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 5332 | |
| 5333 | return 0; |
| 5334 | } |
| 5335 | |
| 5336 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5337 | __iwl3945_down(priv); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5338 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5339 | |
| 5340 | /* tried to restart and config the device for as long as our |
| 5341 | * patience could withstand */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5342 | IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5343 | return -EIO; |
| 5344 | } |
| 5345 | |
| 5346 | |
| 5347 | /***************************************************************************** |
| 5348 | * |
| 5349 | * Workqueue callbacks |
| 5350 | * |
| 5351 | *****************************************************************************/ |
| 5352 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5353 | static void iwl3945_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5354 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5355 | struct iwl_priv *priv = |
| 5356 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5357 | |
| 5358 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5359 | return; |
| 5360 | |
| 5361 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5362 | iwl3945_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5363 | mutex_unlock(&priv->mutex); |
| 5364 | } |
| 5365 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5366 | static void iwl3945_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5367 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5368 | struct iwl_priv *priv = |
| 5369 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5370 | |
| 5371 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5372 | return; |
| 5373 | |
| 5374 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5375 | iwl3945_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5376 | mutex_unlock(&priv->mutex); |
| 5377 | } |
| 5378 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5379 | static void iwl3945_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5380 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5381 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5382 | |
| 5383 | wake_up_interruptible(&priv->wait_command_queue); |
| 5384 | |
| 5385 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5386 | return; |
| 5387 | |
| 5388 | mutex_lock(&priv->mutex); |
| 5389 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5390 | if (!iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5391 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 5392 | "HW and/or SW RF Kill no longer active, restarting " |
| 5393 | "device\n"); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5394 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status) && |
| 5395 | test_bit(STATUS_ALIVE, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5396 | queue_work(priv->workqueue, &priv->restart); |
| 5397 | } else { |
| 5398 | |
| 5399 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5400 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 5401 | "disabled by SW switch\n"); |
| 5402 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5403 | IWL_WARN(priv, "Radio Frequency Kill Switch is On:\n" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5404 | "Kill switch must be turned off for " |
| 5405 | "wireless networking to work.\n"); |
| 5406 | } |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5407 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5408 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5409 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5410 | } |
| 5411 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5412 | static void iwl3945_rfkill_poll(struct work_struct *data) |
| 5413 | { |
| 5414 | struct iwl_priv *priv = |
| 5415 | container_of(data, struct iwl_priv, rfkill_poll.work); |
| 5416 | unsigned long status = priv->status; |
| 5417 | |
| 5418 | if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 5419 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5420 | else |
| 5421 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5422 | |
| 5423 | if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5424 | queue_work(priv->workqueue, &priv->rf_kill); |
| 5425 | |
| 5426 | queue_delayed_work(priv->workqueue, &priv->rfkill_poll, |
| 5427 | round_jiffies_relative(2 * HZ)); |
| 5428 | |
| 5429 | } |
| 5430 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5431 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 5432 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5433 | static void iwl3945_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5434 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5435 | struct iwl_priv *priv = |
| 5436 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5437 | |
| 5438 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5439 | return; |
| 5440 | |
| 5441 | mutex_lock(&priv->mutex); |
| 5442 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 5443 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5444 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 5445 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 5446 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5447 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5448 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5449 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5450 | } |
| 5451 | mutex_unlock(&priv->mutex); |
| 5452 | } |
| 5453 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5454 | static void iwl3945_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5455 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5456 | struct iwl_priv *priv = |
| 5457 | container_of(data, struct iwl_priv, request_scan); |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 5458 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5459 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5460 | .len = sizeof(struct iwl3945_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5461 | .meta.flags = CMD_SIZE_HUGE, |
| 5462 | }; |
| 5463 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5464 | struct iwl3945_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5465 | struct ieee80211_conf *conf = NULL; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5466 | u8 n_probes = 2; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5467 | enum ieee80211_band band; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5468 | DECLARE_SSID_BUF(ssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5469 | |
| 5470 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5471 | |
| 5472 | mutex_lock(&priv->mutex); |
| 5473 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5474 | if (!iwl_is_ready(priv)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5475 | IWL_WARN(priv, "request scan called when driver not ready.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5476 | goto done; |
| 5477 | } |
| 5478 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5479 | /* Make sure the scan wasn't canceled before this queued work |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5480 | * was given the chance to run... */ |
| 5481 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 5482 | goto done; |
| 5483 | |
| 5484 | /* This should never be called or scheduled if there is currently |
| 5485 | * a scan active in the hardware. */ |
| 5486 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 5487 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 5488 | "Ignoring second request.\n"); |
| 5489 | rc = -EIO; |
| 5490 | goto done; |
| 5491 | } |
| 5492 | |
| 5493 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 5494 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 5495 | goto done; |
| 5496 | } |
| 5497 | |
| 5498 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5499 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 5500 | goto done; |
| 5501 | } |
| 5502 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5503 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5504 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 5505 | goto done; |
| 5506 | } |
| 5507 | |
| 5508 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 5509 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 5510 | goto done; |
| 5511 | } |
| 5512 | |
| 5513 | if (!priv->scan_bands) { |
| 5514 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 5515 | goto done; |
| 5516 | } |
| 5517 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5518 | if (!priv->scan39) { |
| 5519 | priv->scan39 = kmalloc(sizeof(struct iwl3945_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5520 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5521 | if (!priv->scan39) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5522 | rc = -ENOMEM; |
| 5523 | goto done; |
| 5524 | } |
| 5525 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5526 | scan = priv->scan39; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5527 | memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5528 | |
| 5529 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 5530 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 5531 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5532 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5533 | u16 interval = 0; |
| 5534 | u32 extra; |
| 5535 | u32 suspend_time = 100; |
| 5536 | u32 scan_suspend_time = 100; |
| 5537 | unsigned long flags; |
| 5538 | |
| 5539 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 5540 | |
| 5541 | spin_lock_irqsave(&priv->lock, flags); |
| 5542 | interval = priv->beacon_int; |
| 5543 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5544 | |
| 5545 | scan->suspend_time = 0; |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5546 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5547 | if (!interval) |
| 5548 | interval = suspend_time; |
| 5549 | /* |
| 5550 | * suspend time format: |
| 5551 | * 0-19: beacon interval in usec (time before exec.) |
| 5552 | * 20-23: 0 |
| 5553 | * 24-31: number of beacons (suspend between channels) |
| 5554 | */ |
| 5555 | |
| 5556 | extra = (suspend_time / interval) << 24; |
| 5557 | scan_suspend_time = 0xFF0FFFFF & |
| 5558 | (extra | ((suspend_time % interval) * 1024)); |
| 5559 | |
| 5560 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 5561 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 5562 | scan_suspend_time, interval); |
| 5563 | } |
| 5564 | |
| 5565 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 5566 | if (priv->one_direct_scan) { |
| 5567 | IWL_DEBUG_SCAN |
| 5568 | ("Kicking off one direct scan for '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5569 | print_ssid(ssid, priv->direct_ssid, |
| 5570 | priv->direct_ssid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5571 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 5572 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 5573 | memcpy(scan->direct_scan[0].ssid, |
| 5574 | priv->direct_ssid, priv->direct_ssid_len); |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5575 | n_probes++; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5576 | } else |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5577 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5578 | |
| 5579 | /* We don't build a direct scan probe request; the uCode will do |
| 5580 | * that based on the direct_mask added to each channel entry */ |
| 5581 | scan->tx_cmd.len = cpu_to_le16( |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5582 | iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 5583 | IWL_MAX_SCAN_SIZE - sizeof(*scan))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5584 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 5585 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5586 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 5587 | |
| 5588 | /* flags + rate selection */ |
| 5589 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5590 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5591 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 5592 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; |
| 5593 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5594 | band = IEEE80211_BAND_2GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5595 | } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5596 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; |
| 5597 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5598 | band = IEEE80211_BAND_5GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5599 | } else { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5600 | IWL_WARN(priv, "Invalid scan band count\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5601 | goto done; |
| 5602 | } |
| 5603 | |
| 5604 | /* select Rx antennas */ |
| 5605 | scan->flags |= iwl3945_get_antenna_flags(priv); |
| 5606 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5607 | if (priv->iw_mode == NL80211_IFTYPE_MONITOR) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5608 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 5609 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5610 | scan->channel_count = |
| 5611 | iwl3945_get_channels_for_scan(priv, band, 1, /* active */ |
| 5612 | n_probes, |
| 5613 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5614 | |
Reinette Chatre | 14b5433 | 2008-11-04 12:21:35 -0800 | [diff] [blame] | 5615 | if (scan->channel_count == 0) { |
| 5616 | IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count); |
| 5617 | goto done; |
| 5618 | } |
| 5619 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5620 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5621 | scan->channel_count * sizeof(struct iwl3945_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5622 | cmd.data = scan; |
| 5623 | scan->len = cpu_to_le16(cmd.len); |
| 5624 | |
| 5625 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5626 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5627 | if (rc) |
| 5628 | goto done; |
| 5629 | |
| 5630 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 5631 | IWL_SCAN_CHECK_WATCHDOG); |
| 5632 | |
| 5633 | mutex_unlock(&priv->mutex); |
| 5634 | return; |
| 5635 | |
| 5636 | done: |
Mohamed Abbas | 2420ebc | 2008-11-04 12:21:34 -0800 | [diff] [blame] | 5637 | /* can not perform scan make sure we clear scanning |
| 5638 | * bits from status so next scan request can be performed. |
| 5639 | * if we dont clear scanning status bit here all next scan |
| 5640 | * will fail |
| 5641 | */ |
| 5642 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 5643 | clear_bit(STATUS_SCANNING, &priv->status); |
| 5644 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 5645 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5646 | queue_work(priv->workqueue, &priv->scan_completed); |
| 5647 | mutex_unlock(&priv->mutex); |
| 5648 | } |
| 5649 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5650 | static void iwl3945_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5651 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5652 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5653 | |
| 5654 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5655 | return; |
| 5656 | |
| 5657 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5658 | __iwl3945_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5659 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5660 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5661 | } |
| 5662 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5663 | static void iwl3945_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5664 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5665 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5666 | |
| 5667 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5668 | return; |
| 5669 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5670 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5671 | queue_work(priv->workqueue, &priv->up); |
| 5672 | } |
| 5673 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5674 | static void iwl3945_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5675 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5676 | struct iwl_priv *priv = |
| 5677 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5678 | |
| 5679 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5680 | return; |
| 5681 | |
| 5682 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5683 | iwl3945_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5684 | mutex_unlock(&priv->mutex); |
| 5685 | } |
| 5686 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5687 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 5688 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5689 | static void iwl3945_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5690 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5691 | int rc = 0; |
| 5692 | struct ieee80211_conf *conf = NULL; |
| 5693 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5694 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5695 | 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] | 5696 | return; |
| 5697 | } |
| 5698 | |
| 5699 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5700 | IWL_DEBUG_ASSOC("Associated as %d to: %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5701 | priv->assoc_id, priv->active39_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5702 | |
| 5703 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5704 | return; |
| 5705 | |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 5706 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5707 | return; |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 5708 | |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 5709 | iwl_scan_cancel_timeout(priv, 200); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5710 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5711 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5712 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5713 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5714 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5715 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 5716 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5717 | iwl3945_setup_rxon_timing(priv); |
| 5718 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5719 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 5720 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5721 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5722 | "Attempting to continue.\n"); |
| 5723 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5724 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5725 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5726 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5727 | |
| 5728 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 5729 | priv->assoc_id, priv->beacon_int); |
| 5730 | |
| 5731 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5732 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5733 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5734 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5735 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5736 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5737 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5738 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5739 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5740 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5741 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5742 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5743 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5744 | |
| 5745 | } |
| 5746 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5747 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5748 | |
| 5749 | switch (priv->iw_mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5750 | case NL80211_IFTYPE_STATION: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5751 | iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5752 | break; |
| 5753 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5754 | case NL80211_IFTYPE_ADHOC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5755 | |
Abhijeet Kolekar | ce546fd | 2008-11-19 15:32:22 -0800 | [diff] [blame] | 5756 | priv->assoc_id = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5757 | iwl3945_add_station(priv, priv->bssid, 0, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5758 | iwl3945_sync_sta(priv, IWL_STA_ID, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5759 | (priv->band == IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5760 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, |
| 5761 | CMD_ASYNC); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5762 | iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); |
| 5763 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5764 | |
| 5765 | break; |
| 5766 | |
| 5767 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5768 | IWL_ERR(priv, "%s Should not be called in %d mode\n", |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 5769 | __func__, priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5770 | break; |
| 5771 | } |
| 5772 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5773 | iwl3945_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 5774 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5775 | /* we have just associated, don't start scan too early */ |
| 5776 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 5777 | } |
| 5778 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5779 | static void iwl3945_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5780 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5781 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5782 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5783 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5784 | return; |
| 5785 | |
| 5786 | mutex_lock(&priv->mutex); |
| 5787 | |
| 5788 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5789 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5790 | |
| 5791 | mutex_unlock(&priv->mutex); |
| 5792 | } |
| 5793 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 5794 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5795 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5796 | static void iwl3945_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5797 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5798 | struct iwl_priv *priv = |
| 5799 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5800 | |
| 5801 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 5802 | |
| 5803 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5804 | return; |
| 5805 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5806 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 5807 | iwl3945_mac_config(priv->hw, 0); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5808 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5809 | ieee80211_scan_completed(priv->hw); |
| 5810 | |
| 5811 | /* Since setting the TXPOWER may have been deferred while |
| 5812 | * performing the scan, fire one off */ |
| 5813 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5814 | iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5815 | mutex_unlock(&priv->mutex); |
| 5816 | } |
| 5817 | |
| 5818 | /***************************************************************************** |
| 5819 | * |
| 5820 | * mac80211 entry point functions |
| 5821 | * |
| 5822 | *****************************************************************************/ |
| 5823 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5824 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 5825 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5826 | static int iwl3945_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5827 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5828 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5829 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5830 | |
| 5831 | IWL_DEBUG_MAC80211("enter\n"); |
| 5832 | |
| 5833 | /* we should be verifying the device is ready to be opened */ |
| 5834 | mutex_lock(&priv->mutex); |
| 5835 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5836 | memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5837 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 5838 | * ucode filename and max sizes are card-specific. */ |
| 5839 | |
| 5840 | if (!priv->ucode_code.len) { |
| 5841 | ret = iwl3945_read_ucode(priv); |
| 5842 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5843 | IWL_ERR(priv, "Could not read microcode: %d\n", ret); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5844 | mutex_unlock(&priv->mutex); |
| 5845 | goto out_release_irq; |
| 5846 | } |
| 5847 | } |
| 5848 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5849 | ret = __iwl3945_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5850 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5851 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5852 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5853 | iwl3945_rfkill_set_hw_state(priv); |
| 5854 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5855 | if (ret) |
| 5856 | goto out_release_irq; |
| 5857 | |
| 5858 | IWL_DEBUG_INFO("Start UP work.\n"); |
| 5859 | |
| 5860 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 5861 | return 0; |
| 5862 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5863 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 5864 | * mac80211 will not be run successfully. */ |
| 5865 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 5866 | test_bit(STATUS_READY, &priv->status), |
| 5867 | UCODE_READY_TIMEOUT); |
| 5868 | if (!ret) { |
| 5869 | if (!test_bit(STATUS_READY, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5870 | IWL_ERR(priv, |
| 5871 | "Wait for START_ALIVE timeout after %dms.\n", |
| 5872 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5873 | ret = -ETIMEDOUT; |
| 5874 | goto out_release_irq; |
| 5875 | } |
| 5876 | } |
| 5877 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5878 | /* ucode is running and will send rfkill notifications, |
| 5879 | * no need to poll the killswitch state anymore */ |
| 5880 | cancel_delayed_work(&priv->rfkill_poll); |
| 5881 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5882 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5883 | IWL_DEBUG_MAC80211("leave\n"); |
| 5884 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5885 | |
| 5886 | out_release_irq: |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5887 | priv->is_open = 0; |
| 5888 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5889 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5890 | } |
| 5891 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5892 | static void iwl3945_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5893 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5894 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5895 | |
| 5896 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5897 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5898 | if (!priv->is_open) { |
| 5899 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 5900 | return; |
| 5901 | } |
| 5902 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5903 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5904 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5905 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5906 | /* stop mac, cancel any scan request and clear |
| 5907 | * RXON_FILTER_ASSOC_MSK BIT |
| 5908 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5909 | mutex_lock(&priv->mutex); |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 5910 | iwl_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5911 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5912 | } |
| 5913 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5914 | iwl3945_down(priv); |
| 5915 | |
| 5916 | flush_workqueue(priv->workqueue); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5917 | |
| 5918 | /* start polling the killswitch state again */ |
| 5919 | queue_delayed_work(priv->workqueue, &priv->rfkill_poll, |
| 5920 | round_jiffies_relative(2 * HZ)); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5921 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5922 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 5925 | 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] | 5926 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5927 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5928 | |
| 5929 | IWL_DEBUG_MAC80211("enter\n"); |
| 5930 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5931 | 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] | 5932 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5933 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 5934 | if (iwl3945_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5935 | dev_kfree_skb_any(skb); |
| 5936 | |
| 5937 | IWL_DEBUG_MAC80211("leave\n"); |
Reinette Chatre | 637f883 | 2009-01-19 15:30:32 -0800 | [diff] [blame] | 5938 | return NETDEV_TX_OK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5939 | } |
| 5940 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5941 | static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5942 | struct ieee80211_if_init_conf *conf) |
| 5943 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5944 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5945 | unsigned long flags; |
| 5946 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5947 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5948 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5949 | if (priv->vif) { |
| 5950 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 5951 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5952 | } |
| 5953 | |
| 5954 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5955 | priv->vif = conf->vif; |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 5956 | priv->iw_mode = conf->type; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5957 | |
| 5958 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5959 | |
| 5960 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 5961 | |
| 5962 | if (conf->mac_addr) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5963 | IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 5964 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 5965 | } |
| 5966 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5967 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5968 | iwl3945_set_mode(priv, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5969 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5970 | mutex_unlock(&priv->mutex); |
| 5971 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5972 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5973 | return 0; |
| 5974 | } |
| 5975 | |
| 5976 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5977 | * iwl3945_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5978 | * |
| 5979 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 5980 | * be set inappropriately and the driver currently sets the hardware up to |
| 5981 | * use it whenever needed. |
| 5982 | */ |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 5983 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5984 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5985 | struct iwl_priv *priv = hw->priv; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 5986 | const struct iwl_channel_info *ch_info; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 5987 | struct ieee80211_conf *conf = &hw->conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5988 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5989 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5990 | |
| 5991 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5992 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5993 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5994 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5995 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5996 | ret = -EIO; |
| 5997 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5998 | } |
| 5999 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 6000 | if (unlikely(!iwl3945_mod_params.disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6001 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6002 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 6003 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6004 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6005 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6006 | } |
| 6007 | |
| 6008 | spin_lock_irqsave(&priv->lock, flags); |
| 6009 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6010 | ch_info = iwl3945_get_channel_info(priv, conf->channel->band, |
| 6011 | conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6012 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 6013 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6014 | conf->channel->hw_value, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6015 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 6016 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6017 | ret = -EINVAL; |
| 6018 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6019 | } |
| 6020 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6021 | iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6022 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6023 | iwl3945_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6024 | |
| 6025 | /* The list of supported rates and rate mask can be different |
| 6026 | * for each phymode; since the phymode may have changed, reset |
| 6027 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6028 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6029 | |
| 6030 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6031 | |
| 6032 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 6033 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6034 | iwl3945_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6035 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6036 | } |
| 6037 | #endif |
| 6038 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6039 | iwl3945_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6040 | |
| 6041 | if (!conf->radio_enabled) { |
| 6042 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6043 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6044 | } |
| 6045 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6046 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6047 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6048 | ret = -EIO; |
| 6049 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6050 | } |
| 6051 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6052 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6053 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6054 | if (memcmp(&priv->active39_rxon, |
| 6055 | &priv->staging39_rxon, sizeof(priv->staging39_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6056 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6057 | else |
| 6058 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 6059 | |
| 6060 | IWL_DEBUG_MAC80211("leave\n"); |
| 6061 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6062 | out: |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6063 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6064 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6065 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6066 | } |
| 6067 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6068 | static void iwl3945_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6069 | { |
| 6070 | int rc = 0; |
| 6071 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 6072 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6073 | return; |
| 6074 | |
| 6075 | /* The following should be done only at AP bring up */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 6076 | if (!(iwl3945_is_associated(priv))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6077 | |
| 6078 | /* RXON - unassoc (to set timing command) */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6079 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6080 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6081 | |
| 6082 | /* RXON Timing */ |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6083 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6084 | iwl3945_setup_rxon_timing(priv); |
| 6085 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6086 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 6087 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6088 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6089 | "Attempting to continue.\n"); |
| 6090 | |
| 6091 | /* FIXME: what should be the assoc_id for AP? */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6092 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6093 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6094 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6095 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6096 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6097 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6098 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6099 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6100 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6101 | if (priv->assoc_capability & |
| 6102 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6103 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6104 | RXON_FLG_SHORT_SLOT_MSK; |
| 6105 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6106 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6107 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6108 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6109 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6110 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6111 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6112 | } |
| 6113 | /* restore RXON assoc */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6114 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6115 | iwl3945_commit_rxon(priv); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 6116 | iwl3945_add_station(priv, iwl_bcast_addr, 0, 0); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 6117 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6118 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6119 | |
| 6120 | /* FIXME - we need to add code here to detect a totally new |
| 6121 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 6122 | * clear sta table, add BCAST sta... */ |
| 6123 | } |
| 6124 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6125 | static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, |
| 6126 | struct ieee80211_vif *vif, |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6127 | struct ieee80211_if_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6128 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6129 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6130 | int rc; |
| 6131 | |
| 6132 | if (conf == NULL) |
| 6133 | return -EIO; |
| 6134 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6135 | if (priv->vif != vif) { |
| 6136 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6137 | return 0; |
| 6138 | } |
| 6139 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6140 | /* handle this temporarily here */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6141 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6142 | conf->changed & IEEE80211_IFCC_BEACON) { |
| 6143 | struct sk_buff *beacon = ieee80211_beacon_get(hw, vif); |
| 6144 | if (!beacon) |
| 6145 | return -ENOMEM; |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6146 | mutex_lock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6147 | rc = iwl3945_mac_beacon_update(hw, beacon); |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6148 | mutex_unlock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6149 | if (rc) |
| 6150 | return rc; |
| 6151 | } |
| 6152 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6153 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6154 | return -EAGAIN; |
| 6155 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6156 | mutex_lock(&priv->mutex); |
| 6157 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6158 | if (conf->bssid) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6159 | IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6160 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6161 | /* |
| 6162 | * very dubious code was here; the probe filtering flag is never set: |
| 6163 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6164 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 6165 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6166 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6167 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6168 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6169 | if (!conf->bssid) { |
| 6170 | conf->bssid = priv->mac_addr; |
| 6171 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6172 | IWL_DEBUG_MAC80211("bssid was set to: %pM\n", |
| 6173 | conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6174 | } |
| 6175 | if (priv->ibss_beacon) |
| 6176 | dev_kfree_skb(priv->ibss_beacon); |
| 6177 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6178 | priv->ibss_beacon = ieee80211_beacon_get(hw, vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6179 | } |
| 6180 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6181 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6182 | goto done; |
| 6183 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6184 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 6185 | !is_multicast_ether_addr(conf->bssid)) { |
| 6186 | /* If there is currently a HW scan going on in the background |
| 6187 | * then we need to cancel it else the RXON below will fail. */ |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 6188 | if (iwl_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6189 | IWL_WARN(priv, "Aborted scan still in progress " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6190 | "after 100ms\n"); |
| 6191 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 6192 | mutex_unlock(&priv->mutex); |
| 6193 | return -EAGAIN; |
| 6194 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6195 | memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6196 | |
| 6197 | /* TODO: Audit driver for usage of these members and see |
| 6198 | * if mac80211 deprecates them (priv->bssid looks like it |
| 6199 | * shouldn't be there, but I haven't scanned the IBSS code |
| 6200 | * to verify) - jpk */ |
| 6201 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 6202 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6203 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6204 | iwl3945_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6205 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6206 | rc = iwl3945_commit_rxon(priv); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6207 | if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6208 | iwl3945_add_station(priv, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6209 | priv->active39_rxon.bssid_addr, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6210 | } |
| 6211 | |
| 6212 | } else { |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 6213 | iwl_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6214 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6215 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6216 | } |
| 6217 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6218 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6219 | IWL_DEBUG_MAC80211("leave\n"); |
| 6220 | mutex_unlock(&priv->mutex); |
| 6221 | |
| 6222 | return 0; |
| 6223 | } |
| 6224 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6225 | static void iwl3945_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6226 | unsigned int changed_flags, |
| 6227 | unsigned int *total_flags, |
| 6228 | int mc_count, struct dev_addr_list *mc_list) |
| 6229 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6230 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6231 | __le32 *filter_flags = &priv->staging39_rxon.filter_flags; |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6232 | |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6233 | IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n", |
| 6234 | changed_flags, *total_flags); |
| 6235 | |
| 6236 | if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) { |
| 6237 | if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) |
| 6238 | *filter_flags |= RXON_FILTER_PROMISC_MSK; |
| 6239 | else |
| 6240 | *filter_flags &= ~RXON_FILTER_PROMISC_MSK; |
Abhijeet Kolekar | 5ec0397 | 2008-05-05 10:22:48 +0800 | [diff] [blame] | 6241 | } |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6242 | if (changed_flags & FIF_ALLMULTI) { |
| 6243 | if (*total_flags & FIF_ALLMULTI) |
| 6244 | *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK; |
| 6245 | else |
| 6246 | *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK; |
| 6247 | } |
| 6248 | if (changed_flags & FIF_CONTROL) { |
| 6249 | if (*total_flags & FIF_CONTROL) |
| 6250 | *filter_flags |= RXON_FILTER_CTL2HOST_MSK; |
| 6251 | else |
| 6252 | *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK; |
| 6253 | } |
| 6254 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 6255 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
| 6256 | *filter_flags |= RXON_FILTER_BCON_AWARE_MSK; |
| 6257 | else |
| 6258 | *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK; |
| 6259 | } |
| 6260 | |
| 6261 | /* We avoid iwl_commit_rxon here to commit the new filter flags |
| 6262 | * since mac80211 will call ieee80211_hw_config immediately. |
| 6263 | * (mc_list is not supported at this time). Otherwise, we need to |
| 6264 | * queue a background iwl_commit_rxon work. |
| 6265 | */ |
| 6266 | |
| 6267 | *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6268 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6269 | } |
| 6270 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6271 | static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6272 | struct ieee80211_if_init_conf *conf) |
| 6273 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6274 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6275 | |
| 6276 | IWL_DEBUG_MAC80211("enter\n"); |
| 6277 | |
| 6278 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6279 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6280 | if (iwl_is_ready_rf(priv)) { |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 6281 | iwl_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6282 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6283 | iwl3945_commit_rxon(priv); |
| 6284 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6285 | if (priv->vif == conf->vif) { |
| 6286 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6287 | memset(priv->bssid, 0, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6288 | } |
| 6289 | mutex_unlock(&priv->mutex); |
| 6290 | |
| 6291 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6292 | } |
| 6293 | |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6294 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
| 6295 | |
| 6296 | static void iwl3945_bss_info_changed(struct ieee80211_hw *hw, |
| 6297 | struct ieee80211_vif *vif, |
| 6298 | struct ieee80211_bss_conf *bss_conf, |
| 6299 | u32 changes) |
| 6300 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6301 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6302 | |
| 6303 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 6304 | |
| 6305 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 6306 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 6307 | bss_conf->use_short_preamble); |
| 6308 | if (bss_conf->use_short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6309 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6310 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6311 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6312 | } |
| 6313 | |
| 6314 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
| 6315 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
| 6316 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6317 | priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6318 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6319 | priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6320 | } |
| 6321 | |
| 6322 | if (changes & BSS_CHANGED_ASSOC) { |
| 6323 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
| 6324 | /* This should never happen as this function should |
| 6325 | * never be called from interrupt context. */ |
| 6326 | if (WARN_ON_ONCE(in_interrupt())) |
| 6327 | return; |
| 6328 | if (bss_conf->assoc) { |
| 6329 | priv->assoc_id = bss_conf->aid; |
| 6330 | priv->beacon_int = bss_conf->beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6331 | priv->timestamp = bss_conf->timestamp; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6332 | priv->assoc_capability = bss_conf->assoc_capability; |
| 6333 | priv->next_scan_jiffies = jiffies + |
| 6334 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
| 6335 | mutex_lock(&priv->mutex); |
| 6336 | iwl3945_post_associate(priv); |
| 6337 | mutex_unlock(&priv->mutex); |
| 6338 | } else { |
| 6339 | priv->assoc_id = 0; |
| 6340 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 6341 | } |
| 6342 | } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) { |
| 6343 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
| 6344 | iwl3945_send_rxon_assoc(priv); |
| 6345 | } |
| 6346 | |
| 6347 | } |
| 6348 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6349 | 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] | 6350 | { |
| 6351 | int rc = 0; |
| 6352 | unsigned long flags; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6353 | struct iwl_priv *priv = hw->priv; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6354 | DECLARE_SSID_BUF(ssid_buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6355 | |
| 6356 | IWL_DEBUG_MAC80211("enter\n"); |
| 6357 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6358 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6359 | spin_lock_irqsave(&priv->lock, flags); |
| 6360 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6361 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6362 | rc = -EIO; |
| 6363 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 6364 | goto out_unlock; |
| 6365 | } |
| 6366 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6367 | /* we don't schedule scan within next_scan_jiffies period */ |
| 6368 | if (priv->next_scan_jiffies && |
| 6369 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 6370 | rc = -EAGAIN; |
| 6371 | goto out_unlock; |
| 6372 | } |
Bill Moss | 15dbf1b | 2008-05-06 11:05:15 +0800 | [diff] [blame] | 6373 | /* if we just finished scan ask for delay for a broadcast scan */ |
| 6374 | if ((len == 0) && priv->last_scan_jiffies && |
| 6375 | time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, |
| 6376 | jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6377 | rc = -EAGAIN; |
| 6378 | goto out_unlock; |
| 6379 | } |
| 6380 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6381 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6382 | print_ssid(ssid_buf, ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6383 | |
| 6384 | priv->one_direct_scan = 1; |
| 6385 | priv->direct_ssid_len = (u8) |
| 6386 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 6387 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6388 | } else |
| 6389 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6390 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6391 | rc = iwl3945_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6392 | |
| 6393 | IWL_DEBUG_MAC80211("leave\n"); |
| 6394 | |
| 6395 | out_unlock: |
| 6396 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6397 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6398 | |
| 6399 | return rc; |
| 6400 | } |
| 6401 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6402 | 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] | 6403 | struct ieee80211_vif *vif, |
| 6404 | struct ieee80211_sta *sta, |
| 6405 | struct ieee80211_key_conf *key) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6406 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6407 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 6408 | const u8 *addr; |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 6409 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6410 | u8 sta_id; |
| 6411 | |
| 6412 | IWL_DEBUG_MAC80211("enter\n"); |
| 6413 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 6414 | if (iwl3945_mod_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6415 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 6416 | return -EOPNOTSUPP; |
| 6417 | } |
| 6418 | |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 6419 | addr = sta ? sta->addr : iwl_bcast_addr; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6420 | sta_id = iwl3945_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6421 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6422 | IWL_DEBUG_MAC80211("leave - %pM not in station map.\n", |
| 6423 | addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6424 | return -EINVAL; |
| 6425 | } |
| 6426 | |
| 6427 | mutex_lock(&priv->mutex); |
| 6428 | |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 6429 | iwl_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6430 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6431 | switch (cmd) { |
| 6432 | case SET_KEY: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 6433 | ret = iwl3945_update_sta_key_info(priv, key, sta_id); |
| 6434 | if (!ret) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6435 | iwl3945_set_rxon_hwcrypto(priv, 1); |
| 6436 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6437 | key->hw_key_idx = sta_id; |
| 6438 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 6439 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 6440 | } |
| 6441 | break; |
| 6442 | case DISABLE_KEY: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 6443 | ret = iwl3945_clear_sta_key_info(priv, sta_id); |
| 6444 | if (!ret) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6445 | iwl3945_set_rxon_hwcrypto(priv, 0); |
| 6446 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6447 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 6448 | } |
| 6449 | break; |
| 6450 | default: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 6451 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6452 | } |
| 6453 | |
| 6454 | IWL_DEBUG_MAC80211("leave\n"); |
| 6455 | mutex_unlock(&priv->mutex); |
| 6456 | |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 6457 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6458 | } |
| 6459 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 6460 | static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6461 | const struct ieee80211_tx_queue_params *params) |
| 6462 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6463 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6464 | unsigned long flags; |
| 6465 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6466 | |
| 6467 | IWL_DEBUG_MAC80211("enter\n"); |
| 6468 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6469 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6470 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6471 | return -EIO; |
| 6472 | } |
| 6473 | |
| 6474 | if (queue >= AC_NUM) { |
| 6475 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 6476 | return 0; |
| 6477 | } |
| 6478 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6479 | q = AC_NUM - 1 - queue; |
| 6480 | |
| 6481 | spin_lock_irqsave(&priv->lock, flags); |
| 6482 | |
| 6483 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 6484 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 6485 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 6486 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 6487 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6488 | |
| 6489 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 6490 | priv->qos_data.qos_active = 1; |
| 6491 | |
| 6492 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6493 | |
| 6494 | mutex_lock(&priv->mutex); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6495 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6496 | iwl3945_activate_qos(priv, 1); |
| 6497 | else if (priv->assoc_id && iwl3945_is_associated(priv)) |
| 6498 | iwl3945_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6499 | |
| 6500 | mutex_unlock(&priv->mutex); |
| 6501 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6502 | IWL_DEBUG_MAC80211("leave\n"); |
| 6503 | return 0; |
| 6504 | } |
| 6505 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6506 | static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6507 | struct ieee80211_tx_queue_stats *stats) |
| 6508 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6509 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6510 | int i, avail; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 6511 | struct iwl_tx_queue *txq; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6512 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6513 | unsigned long flags; |
| 6514 | |
| 6515 | IWL_DEBUG_MAC80211("enter\n"); |
| 6516 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6517 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6518 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6519 | return -EIO; |
| 6520 | } |
| 6521 | |
| 6522 | spin_lock_irqsave(&priv->lock, flags); |
| 6523 | |
| 6524 | for (i = 0; i < AC_NUM; i++) { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 6525 | txq = &priv->txq[i]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6526 | q = &txq->q; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6527 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6528 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 6529 | stats[i].len = q->n_window - avail; |
| 6530 | stats[i].limit = q->n_window - q->high_mark; |
| 6531 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6532 | |
| 6533 | } |
| 6534 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6535 | |
| 6536 | IWL_DEBUG_MAC80211("leave\n"); |
| 6537 | |
| 6538 | return 0; |
| 6539 | } |
| 6540 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6541 | static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6542 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6543 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6544 | unsigned long flags; |
| 6545 | |
| 6546 | mutex_lock(&priv->mutex); |
| 6547 | IWL_DEBUG_MAC80211("enter\n"); |
| 6548 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6549 | iwl_reset_qos(priv); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 6550 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6551 | spin_lock_irqsave(&priv->lock, flags); |
| 6552 | priv->assoc_id = 0; |
| 6553 | priv->assoc_capability = 0; |
| 6554 | priv->call_post_assoc_from_beacon = 0; |
| 6555 | |
| 6556 | /* new association get rid of ibss beacon skb */ |
| 6557 | if (priv->ibss_beacon) |
| 6558 | dev_kfree_skb(priv->ibss_beacon); |
| 6559 | |
| 6560 | priv->ibss_beacon = NULL; |
| 6561 | |
| 6562 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6563 | priv->timestamp = 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6564 | if ((priv->iw_mode == NL80211_IFTYPE_STATION)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6565 | priv->beacon_int = 0; |
| 6566 | |
| 6567 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6568 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6569 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6570 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 6571 | mutex_unlock(&priv->mutex); |
| 6572 | return; |
| 6573 | } |
| 6574 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6575 | /* we are restarting association process |
| 6576 | * clear RXON_FILTER_ASSOC_MSK bit |
| 6577 | */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6578 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 6579 | iwl_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6580 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6581 | iwl3945_commit_rxon(priv); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6582 | } |
| 6583 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6584 | /* Per mac80211.h: This is only used in IBSS mode... */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6585 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6586 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6587 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 6588 | mutex_unlock(&priv->mutex); |
| 6589 | return; |
| 6590 | } |
| 6591 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6592 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6593 | |
| 6594 | mutex_unlock(&priv->mutex); |
| 6595 | |
| 6596 | IWL_DEBUG_MAC80211("leave\n"); |
| 6597 | |
| 6598 | } |
| 6599 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6600 | 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] | 6601 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6602 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6603 | unsigned long flags; |
| 6604 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6605 | IWL_DEBUG_MAC80211("enter\n"); |
| 6606 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6607 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6608 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6609 | return -EIO; |
| 6610 | } |
| 6611 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6612 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6613 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6614 | return -EIO; |
| 6615 | } |
| 6616 | |
| 6617 | spin_lock_irqsave(&priv->lock, flags); |
| 6618 | |
| 6619 | if (priv->ibss_beacon) |
| 6620 | dev_kfree_skb(priv->ibss_beacon); |
| 6621 | |
| 6622 | priv->ibss_beacon = skb; |
| 6623 | |
| 6624 | priv->assoc_id = 0; |
| 6625 | |
| 6626 | IWL_DEBUG_MAC80211("leave\n"); |
| 6627 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6628 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6629 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6630 | |
Abhijeet Kolekar | dc4b1e7 | 2008-09-03 11:26:30 +0800 | [diff] [blame] | 6631 | iwl3945_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6632 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6633 | |
| 6634 | return 0; |
| 6635 | } |
| 6636 | |
| 6637 | /***************************************************************************** |
| 6638 | * |
| 6639 | * sysfs attributes |
| 6640 | * |
| 6641 | *****************************************************************************/ |
| 6642 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6643 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6644 | |
| 6645 | /* |
| 6646 | * The following adds a new attribute to the sysfs representation |
| 6647 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 6648 | * used for controlling the debug level. |
| 6649 | * |
| 6650 | * See the level definitions in iwl for details. |
| 6651 | */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6652 | static ssize_t show_debug_level(struct device *d, |
| 6653 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6654 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6655 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6656 | |
| 6657 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6658 | } |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6659 | static ssize_t store_debug_level(struct device *d, |
| 6660 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6661 | const char *buf, size_t count) |
| 6662 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6663 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6664 | unsigned long val; |
| 6665 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6666 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6667 | ret = strict_strtoul(buf, 0, &val); |
| 6668 | if (ret) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 6669 | 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] | 6670 | else |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6671 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6672 | |
| 6673 | return strnlen(buf, count); |
| 6674 | } |
| 6675 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6676 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 6677 | show_debug_level, store_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6678 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6679 | #endif /* CONFIG_IWL3945_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6680 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6681 | static ssize_t show_temperature(struct device *d, |
| 6682 | struct device_attribute *attr, char *buf) |
| 6683 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6684 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6685 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6686 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6687 | return -EAGAIN; |
| 6688 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6689 | return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6690 | } |
| 6691 | |
| 6692 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 6693 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6694 | static ssize_t show_tx_power(struct device *d, |
| 6695 | struct device_attribute *attr, char *buf) |
| 6696 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6697 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6698 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 6699 | } |
| 6700 | |
| 6701 | static ssize_t store_tx_power(struct device *d, |
| 6702 | struct device_attribute *attr, |
| 6703 | const char *buf, size_t count) |
| 6704 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6705 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6706 | char *p = (char *)buf; |
| 6707 | u32 val; |
| 6708 | |
| 6709 | val = simple_strtoul(p, &p, 10); |
| 6710 | if (p == buf) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 6711 | IWL_INFO(priv, ": %s is not in decimal form.\n", buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6712 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6713 | iwl3945_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6714 | |
| 6715 | return count; |
| 6716 | } |
| 6717 | |
| 6718 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 6719 | |
| 6720 | static ssize_t show_flags(struct device *d, |
| 6721 | struct device_attribute *attr, char *buf) |
| 6722 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6723 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6724 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6725 | return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | static ssize_t store_flags(struct device *d, |
| 6729 | struct device_attribute *attr, |
| 6730 | const char *buf, size_t count) |
| 6731 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6732 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6733 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 6734 | |
| 6735 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6736 | if (le32_to_cpu(priv->staging39_rxon.flags) != flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6737 | /* Cancel any currently running scans... */ |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 6738 | if (iwl_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6739 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6740 | else { |
| 6741 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 6742 | flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6743 | priv->staging39_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6744 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6745 | } |
| 6746 | } |
| 6747 | mutex_unlock(&priv->mutex); |
| 6748 | |
| 6749 | return count; |
| 6750 | } |
| 6751 | |
| 6752 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 6753 | |
| 6754 | static ssize_t show_filter_flags(struct device *d, |
| 6755 | struct device_attribute *attr, char *buf) |
| 6756 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6757 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6758 | |
| 6759 | return sprintf(buf, "0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6760 | le32_to_cpu(priv->active39_rxon.filter_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | static ssize_t store_filter_flags(struct device *d, |
| 6764 | struct device_attribute *attr, |
| 6765 | const char *buf, size_t count) |
| 6766 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6767 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6768 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 6769 | |
| 6770 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6771 | if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6772 | /* Cancel any currently running scans... */ |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 6773 | if (iwl_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6774 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6775 | else { |
| 6776 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 6777 | "0x%04X\n", filter_flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6778 | priv->staging39_rxon.filter_flags = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6779 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6780 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6781 | } |
| 6782 | } |
| 6783 | mutex_unlock(&priv->mutex); |
| 6784 | |
| 6785 | return count; |
| 6786 | } |
| 6787 | |
| 6788 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 6789 | store_filter_flags); |
| 6790 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6791 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6792 | |
| 6793 | static ssize_t show_measurement(struct device *d, |
| 6794 | struct device_attribute *attr, char *buf) |
| 6795 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6796 | struct iwl_priv *priv = dev_get_drvdata(d); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 6797 | struct iwl_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6798 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 6799 | u8 *data = (u8 *)&measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6800 | unsigned long flags; |
| 6801 | |
| 6802 | spin_lock_irqsave(&priv->lock, flags); |
| 6803 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 6804 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6805 | return 0; |
| 6806 | } |
| 6807 | memcpy(&measure_report, &priv->measure_report, size); |
| 6808 | priv->measurement_status = 0; |
| 6809 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6810 | |
| 6811 | while (size && (PAGE_SIZE - len)) { |
| 6812 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 6813 | PAGE_SIZE - len, 1); |
| 6814 | len = strlen(buf); |
| 6815 | if (PAGE_SIZE - len) |
| 6816 | buf[len++] = '\n'; |
| 6817 | |
| 6818 | ofs += 16; |
| 6819 | size -= min(size, 16U); |
| 6820 | } |
| 6821 | |
| 6822 | return len; |
| 6823 | } |
| 6824 | |
| 6825 | static ssize_t store_measurement(struct device *d, |
| 6826 | struct device_attribute *attr, |
| 6827 | const char *buf, size_t count) |
| 6828 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6829 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6830 | struct ieee80211_measurement_params params = { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6831 | .channel = le16_to_cpu(priv->active39_rxon.channel), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6832 | .start_time = cpu_to_le64(priv->last_tsf), |
| 6833 | .duration = cpu_to_le16(1), |
| 6834 | }; |
| 6835 | u8 type = IWL_MEASURE_BASIC; |
| 6836 | u8 buffer[32]; |
| 6837 | u8 channel; |
| 6838 | |
| 6839 | if (count) { |
| 6840 | char *p = buffer; |
| 6841 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 6842 | channel = simple_strtoul(p, NULL, 0); |
| 6843 | if (channel) |
| 6844 | params.channel = channel; |
| 6845 | |
| 6846 | p = buffer; |
| 6847 | while (*p && *p != ' ') |
| 6848 | p++; |
| 6849 | if (*p) |
| 6850 | type = simple_strtoul(p + 1, NULL, 0); |
| 6851 | } |
| 6852 | |
| 6853 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 6854 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6855 | iwl3945_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6856 | |
| 6857 | return count; |
| 6858 | } |
| 6859 | |
| 6860 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 6861 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6862 | #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6863 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6864 | static ssize_t store_retry_rate(struct device *d, |
| 6865 | struct device_attribute *attr, |
| 6866 | const char *buf, size_t count) |
| 6867 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6868 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6869 | |
| 6870 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 6871 | if (priv->retry_rate <= 0) |
| 6872 | priv->retry_rate = 1; |
| 6873 | |
| 6874 | return count; |
| 6875 | } |
| 6876 | |
| 6877 | static ssize_t show_retry_rate(struct device *d, |
| 6878 | struct device_attribute *attr, char *buf) |
| 6879 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6880 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6881 | return sprintf(buf, "%d", priv->retry_rate); |
| 6882 | } |
| 6883 | |
| 6884 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 6885 | store_retry_rate); |
| 6886 | |
| 6887 | static ssize_t store_power_level(struct device *d, |
| 6888 | struct device_attribute *attr, |
| 6889 | const char *buf, size_t count) |
| 6890 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6891 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6892 | int rc; |
| 6893 | int mode; |
| 6894 | |
| 6895 | mode = simple_strtoul(buf, NULL, 0); |
| 6896 | mutex_lock(&priv->mutex); |
| 6897 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6898 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6899 | rc = -EAGAIN; |
| 6900 | goto out; |
| 6901 | } |
| 6902 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 6903 | if ((mode < 1) || (mode > IWL39_POWER_LIMIT) || |
| 6904 | (mode == IWL39_POWER_AC)) |
| 6905 | mode = IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6906 | else |
| 6907 | mode |= IWL_POWER_ENABLED; |
| 6908 | |
| 6909 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6910 | rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6911 | if (rc) { |
| 6912 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 6913 | goto out; |
| 6914 | } |
| 6915 | priv->power_mode = mode; |
| 6916 | } |
| 6917 | |
| 6918 | rc = count; |
| 6919 | |
| 6920 | out: |
| 6921 | mutex_unlock(&priv->mutex); |
| 6922 | return rc; |
| 6923 | } |
| 6924 | |
| 6925 | #define MAX_WX_STRING 80 |
| 6926 | |
| 6927 | /* Values are in microsecond */ |
| 6928 | static const s32 timeout_duration[] = { |
| 6929 | 350000, |
| 6930 | 250000, |
| 6931 | 75000, |
| 6932 | 37000, |
| 6933 | 25000, |
| 6934 | }; |
| 6935 | static const s32 period_duration[] = { |
| 6936 | 400000, |
| 6937 | 700000, |
| 6938 | 1000000, |
| 6939 | 1000000, |
| 6940 | 1000000 |
| 6941 | }; |
| 6942 | |
| 6943 | static ssize_t show_power_level(struct device *d, |
| 6944 | struct device_attribute *attr, char *buf) |
| 6945 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6946 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6947 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 6948 | char *p = buf; |
| 6949 | |
| 6950 | p += sprintf(p, "%d ", level); |
| 6951 | switch (level) { |
| 6952 | case IWL_POWER_MODE_CAM: |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 6953 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6954 | p += sprintf(p, "(AC)"); |
| 6955 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 6956 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6957 | p += sprintf(p, "(BATTERY)"); |
| 6958 | break; |
| 6959 | default: |
| 6960 | p += sprintf(p, |
| 6961 | "(Timeout %dms, Period %dms)", |
| 6962 | timeout_duration[level - 1] / 1000, |
| 6963 | period_duration[level - 1] / 1000); |
| 6964 | } |
| 6965 | |
| 6966 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 6967 | p += sprintf(p, " OFF\n"); |
| 6968 | else |
| 6969 | p += sprintf(p, " \n"); |
| 6970 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 6971 | return p - buf + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6972 | |
| 6973 | } |
| 6974 | |
| 6975 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 6976 | store_power_level); |
| 6977 | |
| 6978 | static ssize_t show_channels(struct device *d, |
| 6979 | struct device_attribute *attr, char *buf) |
| 6980 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6981 | /* all this shit doesn't belong into sysfs anyway */ |
| 6982 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6983 | } |
| 6984 | |
| 6985 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 6986 | |
| 6987 | static ssize_t show_statistics(struct device *d, |
| 6988 | struct device_attribute *attr, char *buf) |
| 6989 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6990 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6991 | u32 size = sizeof(struct iwl3945_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6992 | u32 len = 0, ofs = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6993 | u8 *data = (u8 *)&priv->statistics_39; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6994 | int rc = 0; |
| 6995 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6996 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6997 | return -EAGAIN; |
| 6998 | |
| 6999 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7000 | rc = iwl3945_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7001 | mutex_unlock(&priv->mutex); |
| 7002 | |
| 7003 | if (rc) { |
| 7004 | len = sprintf(buf, |
| 7005 | "Error sending statistics request: 0x%08X\n", rc); |
| 7006 | return len; |
| 7007 | } |
| 7008 | |
| 7009 | while (size && (PAGE_SIZE - len)) { |
| 7010 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7011 | PAGE_SIZE - len, 1); |
| 7012 | len = strlen(buf); |
| 7013 | if (PAGE_SIZE - len) |
| 7014 | buf[len++] = '\n'; |
| 7015 | |
| 7016 | ofs += 16; |
| 7017 | size -= min(size, 16U); |
| 7018 | } |
| 7019 | |
| 7020 | return len; |
| 7021 | } |
| 7022 | |
| 7023 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 7024 | |
| 7025 | static ssize_t show_antenna(struct device *d, |
| 7026 | struct device_attribute *attr, char *buf) |
| 7027 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7028 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7029 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7030 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7031 | return -EAGAIN; |
| 7032 | |
| 7033 | return sprintf(buf, "%d\n", priv->antenna); |
| 7034 | } |
| 7035 | |
| 7036 | static ssize_t store_antenna(struct device *d, |
| 7037 | struct device_attribute *attr, |
| 7038 | const char *buf, size_t count) |
| 7039 | { |
| 7040 | int ant; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7041 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7042 | |
| 7043 | if (count == 0) |
| 7044 | return 0; |
| 7045 | |
| 7046 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 7047 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 7048 | return count; |
| 7049 | } |
| 7050 | |
| 7051 | if ((ant >= 0) && (ant <= 2)) { |
| 7052 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7053 | priv->antenna = (enum iwl3945_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7054 | } else |
| 7055 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 7056 | |
| 7057 | |
| 7058 | return count; |
| 7059 | } |
| 7060 | |
| 7061 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 7062 | |
| 7063 | static ssize_t show_status(struct device *d, |
| 7064 | struct device_attribute *attr, char *buf) |
| 7065 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7066 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7067 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7068 | return -EAGAIN; |
| 7069 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 7070 | } |
| 7071 | |
| 7072 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 7073 | |
| 7074 | static ssize_t dump_error_log(struct device *d, |
| 7075 | struct device_attribute *attr, |
| 7076 | const char *buf, size_t count) |
| 7077 | { |
| 7078 | char *p = (char *)buf; |
| 7079 | |
| 7080 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7081 | iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7082 | |
| 7083 | return strnlen(buf, count); |
| 7084 | } |
| 7085 | |
| 7086 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 7087 | |
| 7088 | static ssize_t dump_event_log(struct device *d, |
| 7089 | struct device_attribute *attr, |
| 7090 | const char *buf, size_t count) |
| 7091 | { |
| 7092 | char *p = (char *)buf; |
| 7093 | |
| 7094 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7095 | iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7096 | |
| 7097 | return strnlen(buf, count); |
| 7098 | } |
| 7099 | |
| 7100 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 7101 | |
| 7102 | /***************************************************************************** |
| 7103 | * |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 7104 | * driver setup and tear down |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7105 | * |
| 7106 | *****************************************************************************/ |
| 7107 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7108 | static void iwl3945_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7109 | { |
| 7110 | priv->workqueue = create_workqueue(DRV_NAME); |
| 7111 | |
| 7112 | init_waitqueue_head(&priv->wait_command_queue); |
| 7113 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7114 | INIT_WORK(&priv->up, iwl3945_bg_up); |
| 7115 | INIT_WORK(&priv->restart, iwl3945_bg_restart); |
| 7116 | INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); |
| 7117 | INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed); |
| 7118 | INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan); |
| 7119 | INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan); |
| 7120 | INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill); |
| 7121 | INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7122 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); |
| 7123 | INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); |
| 7124 | INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7125 | INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7126 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7127 | iwl3945_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7128 | |
| 7129 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7130 | iwl3945_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7131 | } |
| 7132 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7133 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7134 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7135 | iwl3945_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7136 | |
Joonwoo Park | e47eb6a | 2007-11-29 10:42:49 +0900 | [diff] [blame] | 7137 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7138 | cancel_delayed_work(&priv->scan_check); |
| 7139 | cancel_delayed_work(&priv->alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7140 | cancel_work_sync(&priv->beacon_update); |
| 7141 | } |
| 7142 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7143 | static struct attribute *iwl3945_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7144 | &dev_attr_antenna.attr, |
| 7145 | &dev_attr_channels.attr, |
| 7146 | &dev_attr_dump_errors.attr, |
| 7147 | &dev_attr_dump_events.attr, |
| 7148 | &dev_attr_flags.attr, |
| 7149 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7150 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7151 | &dev_attr_measurement.attr, |
| 7152 | #endif |
| 7153 | &dev_attr_power_level.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7154 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7155 | &dev_attr_statistics.attr, |
| 7156 | &dev_attr_status.attr, |
| 7157 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7158 | &dev_attr_tx_power.attr, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7159 | #ifdef CONFIG_IWL3945_DEBUG |
| 7160 | &dev_attr_debug_level.attr, |
| 7161 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7162 | NULL |
| 7163 | }; |
| 7164 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7165 | static struct attribute_group iwl3945_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7166 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7167 | .attrs = iwl3945_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7168 | }; |
| 7169 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7170 | static struct ieee80211_ops iwl3945_hw_ops = { |
| 7171 | .tx = iwl3945_mac_tx, |
| 7172 | .start = iwl3945_mac_start, |
| 7173 | .stop = iwl3945_mac_stop, |
| 7174 | .add_interface = iwl3945_mac_add_interface, |
| 7175 | .remove_interface = iwl3945_mac_remove_interface, |
| 7176 | .config = iwl3945_mac_config, |
| 7177 | .config_interface = iwl3945_mac_config_interface, |
| 7178 | .configure_filter = iwl3945_configure_filter, |
| 7179 | .set_key = iwl3945_mac_set_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7180 | .get_tx_stats = iwl3945_mac_get_tx_stats, |
| 7181 | .conf_tx = iwl3945_mac_conf_tx, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7182 | .reset_tsf = iwl3945_mac_reset_tsf, |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 7183 | .bss_info_changed = iwl3945_bss_info_changed, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7184 | .hw_scan = iwl3945_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7185 | }; |
| 7186 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 7187 | static int iwl3945_init_drv(struct iwl_priv *priv) |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7188 | { |
| 7189 | int ret; |
| 7190 | |
| 7191 | priv->retry_rate = 1; |
| 7192 | priv->ibss_beacon = NULL; |
| 7193 | |
| 7194 | spin_lock_init(&priv->lock); |
Samuel Ortiz | c7a7c8e | 2009-01-08 10:20:01 -0800 | [diff] [blame] | 7195 | spin_lock_init(&priv->power_data_39.lock); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7196 | spin_lock_init(&priv->sta_lock); |
| 7197 | spin_lock_init(&priv->hcmd_lock); |
| 7198 | |
| 7199 | INIT_LIST_HEAD(&priv->free_frames); |
| 7200 | |
| 7201 | mutex_init(&priv->mutex); |
| 7202 | |
| 7203 | /* Clear the driver's (not device's) station table */ |
| 7204 | iwl3945_clear_stations_table(priv); |
| 7205 | |
| 7206 | priv->data_retry_limit = -1; |
| 7207 | priv->ieee_channels = NULL; |
| 7208 | priv->ieee_rates = NULL; |
| 7209 | priv->band = IEEE80211_BAND_2GHZ; |
| 7210 | |
| 7211 | priv->iw_mode = NL80211_IFTYPE_STATION; |
| 7212 | |
| 7213 | iwl_reset_qos(priv); |
| 7214 | |
| 7215 | priv->qos_data.qos_active = 0; |
| 7216 | priv->qos_data.qos_cap.val = 0; |
| 7217 | |
| 7218 | priv->rates_mask = IWL_RATES_MASK; |
| 7219 | /* If power management is turned on, default to AC mode */ |
Samuel Ortiz | c7a7c8e | 2009-01-08 10:20:01 -0800 | [diff] [blame] | 7220 | priv->power_mode = IWL39_POWER_AC; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7221 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 7222 | |
| 7223 | ret = iwl3945_init_channel_map(priv); |
| 7224 | if (ret) { |
| 7225 | IWL_ERR(priv, "initializing regulatory failed: %d\n", ret); |
| 7226 | goto err; |
| 7227 | } |
| 7228 | |
| 7229 | ret = iwl3945_init_geos(priv); |
| 7230 | if (ret) { |
| 7231 | IWL_ERR(priv, "initializing geos failed: %d\n", ret); |
| 7232 | goto err_free_channel_map; |
| 7233 | } |
| 7234 | |
| 7235 | return 0; |
| 7236 | |
| 7237 | err_free_channel_map: |
| 7238 | iwl3945_free_channel_map(priv); |
| 7239 | err: |
| 7240 | return ret; |
| 7241 | } |
| 7242 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7243 | 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] | 7244 | { |
| 7245 | int err = 0; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7246 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7247 | struct ieee80211_hw *hw; |
Kolekar, Abhijeet | c0f20d9 | 2008-12-19 10:37:19 +0800 | [diff] [blame] | 7248 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7249 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7250 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7251 | /*********************** |
| 7252 | * 1. Allocating HW data |
| 7253 | * ********************/ |
| 7254 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7255 | /* mac80211 allocates memory for this device instance, including |
| 7256 | * space for this driver's private structure */ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7257 | hw = iwl_alloc_all(cfg, &iwl3945_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7258 | if (hw == NULL) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7259 | printk(KERN_ERR DRV_NAME "Can not allocate network device\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7260 | err = -ENOMEM; |
| 7261 | goto out; |
| 7262 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7263 | priv = hw->priv; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7264 | SET_IEEE80211_DEV(hw, &pdev->dev); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7265 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7266 | if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) || |
| 7267 | (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7268 | IWL_ERR(priv, |
| 7269 | "invalid queues_num, should be between %d and %d\n", |
| 7270 | IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES); |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7271 | err = -EINVAL; |
| 7272 | goto out; |
| 7273 | } |
| 7274 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7275 | /* |
| 7276 | * Disabling hardware scan means that mac80211 will perform scans |
| 7277 | * "the hard way", rather than using device's scan. |
| 7278 | */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7279 | if (iwl3945_mod_params.disable_hw_scan) { |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7280 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
| 7281 | iwl3945_hw_ops.hw_scan = NULL; |
| 7282 | } |
| 7283 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7284 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7285 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7286 | priv->cfg = cfg; |
| 7287 | priv->pci_dev = pdev; |
| 7288 | |
| 7289 | #ifdef CONFIG_IWL3945_DEBUG |
| 7290 | priv->debug_level = iwl3945_mod_params.debug; |
| 7291 | atomic_set(&priv->restrict_refcnt, 0); |
| 7292 | #endif |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7293 | hw->rate_control_algorithm = "iwl-3945-rs"; |
| 7294 | hw->sta_data_size = sizeof(struct iwl3945_sta_priv); |
| 7295 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7296 | /* Select antenna (may be helpful if only one antenna is connected) */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7297 | priv->antenna = (enum iwl3945_antenna)iwl3945_mod_params.antenna; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7298 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7299 | /* Tell mac80211 our characteristics */ |
Johannes Berg | 605a0bd | 2008-07-15 10:10:01 +0200 | [diff] [blame] | 7300 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7301 | IEEE80211_HW_NOISE_DBM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7302 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7303 | hw->wiphy->interface_modes = |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7304 | BIT(NL80211_IFTYPE_STATION) | |
| 7305 | BIT(NL80211_IFTYPE_ADHOC); |
| 7306 | |
Luis R. Rodriguez | ea4a82dc | 2008-11-12 14:22:04 -0800 | [diff] [blame] | 7307 | hw->wiphy->fw_handles_regulatory = true; |
| 7308 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7309 | /* 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7310 | hw->queues = 4; |
| 7311 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7312 | /*************************** |
| 7313 | * 2. Initializing PCI bus |
| 7314 | * *************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7315 | if (pci_enable_device(pdev)) { |
| 7316 | err = -ENODEV; |
| 7317 | goto out_ieee80211_free_hw; |
| 7318 | } |
| 7319 | |
| 7320 | pci_set_master(pdev); |
| 7321 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7322 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 7323 | if (!err) |
| 7324 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 7325 | if (err) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7326 | IWL_WARN(priv, "No suitable DMA available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7327 | goto out_pci_disable_device; |
| 7328 | } |
| 7329 | |
| 7330 | pci_set_drvdata(pdev, priv); |
| 7331 | err = pci_request_regions(pdev, DRV_NAME); |
| 7332 | if (err) |
| 7333 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7334 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7335 | /*********************** |
| 7336 | * 3. Read REV Register |
| 7337 | * ********************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7338 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 7339 | if (!priv->hw_base) { |
| 7340 | err = -ENODEV; |
| 7341 | goto out_pci_release_regions; |
| 7342 | } |
| 7343 | |
| 7344 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 7345 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 7346 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 7347 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7348 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 7349 | * PCI Tx retries from interfering with C3 CPU state */ |
| 7350 | pci_write_config_byte(pdev, 0x41, 0x00); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7351 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7352 | /* amp init */ |
| 7353 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7354 | if (err < 0) { |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7355 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 7356 | goto out_iounmap; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7357 | } |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7358 | |
| 7359 | /*********************** |
| 7360 | * 4. Read EEPROM |
| 7361 | * ********************/ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7362 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7363 | /* Read the EEPROM */ |
| 7364 | err = iwl3945_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7365 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7366 | IWL_ERR(priv, "Unable to init EEPROM\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7367 | goto out_remove_sysfs; |
| 7368 | } |
| 7369 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 7370 | get_eeprom_mac(priv, priv->mac_addr); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7371 | IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7372 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 7373 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7374 | /*********************** |
| 7375 | * 5. Setup HW Constants |
| 7376 | * ********************/ |
| 7377 | /* Device-specific setup */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7378 | if (iwl3945_hw_set_hw_params(priv)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7379 | IWL_ERR(priv, "failed to set hw settings\n"); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7380 | goto out_iounmap; |
| 7381 | } |
| 7382 | |
| 7383 | /*********************** |
| 7384 | * 6. Setup priv |
| 7385 | * ********************/ |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7386 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7387 | err = iwl3945_init_drv(priv); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7388 | if (err) { |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7389 | IWL_ERR(priv, "initializing driver failed\n"); |
| 7390 | goto out_free_geos; |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7391 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7392 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7393 | IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n", |
| 7394 | priv->cfg->name); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7395 | |
| 7396 | /*********************************** |
| 7397 | * 7. Initialize Module Parameters |
| 7398 | * **********************************/ |
| 7399 | |
| 7400 | /* Initialize module parameter values here */ |
| 7401 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7402 | if (iwl3945_mod_params.disable) { |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7403 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 7404 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 7405 | } |
| 7406 | |
| 7407 | |
| 7408 | /*********************** |
| 7409 | * 8. Setup Services |
| 7410 | * ********************/ |
| 7411 | |
| 7412 | spin_lock_irqsave(&priv->lock, flags); |
| 7413 | iwl3945_disable_interrupts(priv); |
| 7414 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7415 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7416 | pci_enable_msi(priv->pci_dev); |
| 7417 | |
| 7418 | err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED, |
| 7419 | DRV_NAME, priv); |
| 7420 | if (err) { |
| 7421 | IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 7422 | goto out_disable_msi; |
| 7423 | } |
| 7424 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7425 | err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
| 7426 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7427 | IWL_ERR(priv, "failed to create sysfs device attributes\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 7428 | goto out_release_irq; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7429 | } |
| 7430 | |
| 7431 | iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
| 7432 | iwl3945_setup_deferred_work(priv); |
| 7433 | iwl3945_setup_rx_handlers(priv); |
| 7434 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7435 | /********************************* |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7436 | * 9. Setup and Register mac80211 |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7437 | * *******************************/ |
| 7438 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7439 | err = ieee80211_register_hw(priv->hw); |
| 7440 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7441 | IWL_ERR(priv, "Failed to register network device: %d\n", err); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7442 | goto out_remove_sysfs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7443 | } |
| 7444 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7445 | priv->hw->conf.beacon_int = 100; |
| 7446 | priv->mac80211_registered = 1; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7447 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7448 | err = iwl3945_rfkill_init(priv); |
| 7449 | if (err) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7450 | IWL_ERR(priv, "Unable to initialize RFKILL system. " |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7451 | "Ignoring error: %d\n", err); |
| 7452 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7453 | /* Start monitoring the killswitch */ |
| 7454 | queue_delayed_work(priv->workqueue, &priv->rfkill_poll, |
| 7455 | 2 * HZ); |
| 7456 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7457 | return 0; |
| 7458 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7459 | out_remove_sysfs: |
| 7460 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7461 | out_free_geos: |
| 7462 | iwl3945_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7463 | |
| 7464 | out_release_irq: |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7465 | free_irq(priv->pci_dev->irq, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7466 | destroy_workqueue(priv->workqueue); |
| 7467 | priv->workqueue = NULL; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7468 | iwl3945_unset_hw_params(priv); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7469 | out_disable_msi: |
| 7470 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7471 | out_iounmap: |
| 7472 | pci_iounmap(pdev, priv->hw_base); |
| 7473 | out_pci_release_regions: |
| 7474 | pci_release_regions(pdev); |
| 7475 | out_pci_disable_device: |
| 7476 | pci_disable_device(pdev); |
| 7477 | pci_set_drvdata(pdev, NULL); |
| 7478 | out_ieee80211_free_hw: |
| 7479 | ieee80211_free_hw(priv->hw); |
| 7480 | out: |
| 7481 | return err; |
| 7482 | } |
| 7483 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 7484 | static void __devexit iwl3945_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7485 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7486 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7487 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7488 | |
| 7489 | if (!priv) |
| 7490 | return; |
| 7491 | |
| 7492 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 7493 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7494 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 7495 | |
Kolekar, Abhijeet | d552bfb | 2008-12-19 10:37:41 +0800 | [diff] [blame] | 7496 | if (priv->mac80211_registered) { |
| 7497 | ieee80211_unregister_hw(priv->hw); |
| 7498 | priv->mac80211_registered = 0; |
| 7499 | } else { |
| 7500 | iwl3945_down(priv); |
| 7501 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7502 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7503 | /* make sure we flush any pending irq or |
| 7504 | * tasklet for the driver |
| 7505 | */ |
| 7506 | spin_lock_irqsave(&priv->lock, flags); |
| 7507 | iwl3945_disable_interrupts(priv); |
| 7508 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7509 | |
| 7510 | iwl_synchronize_irq(priv); |
| 7511 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7512 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7513 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7514 | iwl3945_rfkill_unregister(priv); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7515 | cancel_delayed_work(&priv->rfkill_poll); |
| 7516 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7517 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7518 | |
| 7519 | if (priv->rxq.bd) |
Winkler, Tomas | 51af3d3 | 2008-12-22 11:31:23 +0800 | [diff] [blame] | 7520 | iwl_rx_queue_free(priv, &priv->rxq); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7521 | iwl3945_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7522 | |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7523 | iwl3945_unset_hw_params(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7524 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7525 | |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 7526 | /*netif_stop_queue(dev); */ |
| 7527 | flush_workqueue(priv->workqueue); |
| 7528 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7529 | /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7530 | * priv->workqueue... so we can't take down the workqueue |
| 7531 | * until now... */ |
| 7532 | destroy_workqueue(priv->workqueue); |
| 7533 | priv->workqueue = NULL; |
| 7534 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7535 | free_irq(pdev->irq, priv); |
| 7536 | pci_disable_msi(pdev); |
| 7537 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7538 | pci_iounmap(pdev, priv->hw_base); |
| 7539 | pci_release_regions(pdev); |
| 7540 | pci_disable_device(pdev); |
| 7541 | pci_set_drvdata(pdev, NULL); |
| 7542 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7543 | iwl3945_free_channel_map(priv); |
| 7544 | iwl3945_free_geos(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7545 | kfree(priv->scan39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7546 | if (priv->ibss_beacon) |
| 7547 | dev_kfree_skb(priv->ibss_beacon); |
| 7548 | |
| 7549 | ieee80211_free_hw(priv->hw); |
| 7550 | } |
| 7551 | |
| 7552 | #ifdef CONFIG_PM |
| 7553 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7554 | 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] | 7555 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7556 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7557 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7558 | if (priv->is_open) { |
| 7559 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 7560 | iwl3945_mac_stop(priv->hw); |
| 7561 | priv->is_open = 1; |
| 7562 | } |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7563 | pci_save_state(pdev); |
| 7564 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7565 | pci_set_power_state(pdev, PCI_D3hot); |
| 7566 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7567 | return 0; |
| 7568 | } |
| 7569 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7570 | static int iwl3945_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7571 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7572 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7573 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7574 | pci_set_power_state(pdev, PCI_D0); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 7575 | pci_enable_device(pdev); |
| 7576 | pci_restore_state(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7577 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7578 | if (priv->is_open) |
| 7579 | iwl3945_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7580 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7581 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7582 | return 0; |
| 7583 | } |
| 7584 | |
| 7585 | #endif /* CONFIG_PM */ |
| 7586 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7587 | /*************** RFKILL FUNCTIONS **********/ |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7588 | #ifdef CONFIG_IWL3945_RFKILL |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7589 | /* software rf-kill from user */ |
| 7590 | static int iwl3945_rfkill_soft_rf_kill(void *data, enum rfkill_state state) |
| 7591 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7592 | struct iwl_priv *priv = data; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7593 | int err = 0; |
| 7594 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7595 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7596 | return 0; |
| 7597 | |
| 7598 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7599 | return 0; |
| 7600 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 7601 | 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] | 7602 | mutex_lock(&priv->mutex); |
| 7603 | |
| 7604 | switch (state) { |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7605 | case RFKILL_STATE_UNBLOCKED: |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7606 | if (iwl_is_rfkill_hw(priv)) { |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7607 | err = -EBUSY; |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7608 | goto out_unlock; |
| 7609 | } |
| 7610 | iwl3945_radio_kill_sw(priv, 0); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7611 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7612 | case RFKILL_STATE_SOFT_BLOCKED: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7613 | iwl3945_radio_kill_sw(priv, 1); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7614 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7615 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 7616 | IWL_WARN(priv, "received unexpected RFKILL state %d\n", state); |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7617 | break; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7618 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7619 | out_unlock: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7620 | mutex_unlock(&priv->mutex); |
| 7621 | |
| 7622 | return err; |
| 7623 | } |
| 7624 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7625 | int iwl3945_rfkill_init(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7626 | { |
| 7627 | struct device *device = wiphy_dev(priv->hw->wiphy); |
| 7628 | int ret = 0; |
| 7629 | |
| 7630 | BUG_ON(device == NULL); |
| 7631 | |
| 7632 | IWL_DEBUG_RF_KILL("Initializing RFKILL.\n"); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7633 | priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN); |
| 7634 | if (!priv->rfkill) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7635 | IWL_ERR(priv, "Unable to allocate rfkill device.\n"); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7636 | ret = -ENOMEM; |
| 7637 | goto error; |
| 7638 | } |
| 7639 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7640 | priv->rfkill->name = priv->cfg->name; |
| 7641 | priv->rfkill->data = priv; |
| 7642 | priv->rfkill->state = RFKILL_STATE_UNBLOCKED; |
| 7643 | priv->rfkill->toggle_radio = iwl3945_rfkill_soft_rf_kill; |
| 7644 | priv->rfkill->user_claim_unsupported = 1; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7645 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7646 | priv->rfkill->dev.class->suspend = NULL; |
| 7647 | priv->rfkill->dev.class->resume = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7648 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7649 | ret = rfkill_register(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7650 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7651 | IWL_ERR(priv, "Unable to register rfkill: %d\n", ret); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7652 | goto freed_rfkill; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7653 | } |
| 7654 | |
| 7655 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 7656 | return ret; |
| 7657 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7658 | freed_rfkill: |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7659 | if (priv->rfkill != NULL) |
| 7660 | rfkill_free(priv->rfkill); |
| 7661 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7662 | |
| 7663 | error: |
| 7664 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 7665 | return ret; |
| 7666 | } |
| 7667 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7668 | void iwl3945_rfkill_unregister(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7669 | { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7670 | if (priv->rfkill) |
| 7671 | rfkill_unregister(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7672 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7673 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7674 | } |
| 7675 | |
| 7676 | /* set rf-kill to the right state. */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7677 | void iwl3945_rfkill_set_hw_state(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7678 | { |
| 7679 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7680 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7681 | return; |
| 7682 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7683 | if (iwl_is_rfkill_hw(priv)) { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7684 | rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED); |
| 7685 | return; |
| 7686 | } |
| 7687 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7688 | if (!iwl_is_rfkill_sw(priv)) |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7689 | rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7690 | else |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7691 | rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7692 | } |
| 7693 | #endif |
| 7694 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7695 | /***************************************************************************** |
| 7696 | * |
| 7697 | * driver and module entry point |
| 7698 | * |
| 7699 | *****************************************************************************/ |
| 7700 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7701 | static struct pci_driver iwl3945_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7702 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7703 | .id_table = iwl3945_hw_card_ids, |
| 7704 | .probe = iwl3945_pci_probe, |
| 7705 | .remove = __devexit_p(iwl3945_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7706 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7707 | .suspend = iwl3945_pci_suspend, |
| 7708 | .resume = iwl3945_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7709 | #endif |
| 7710 | }; |
| 7711 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7712 | static int __init iwl3945_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7713 | { |
| 7714 | |
| 7715 | int ret; |
| 7716 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 7717 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7718 | |
| 7719 | ret = iwl3945_rate_control_register(); |
| 7720 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7721 | printk(KERN_ERR DRV_NAME |
| 7722 | "Unable to register rate control algorithm: %d\n", ret); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7723 | return ret; |
| 7724 | } |
| 7725 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7726 | ret = pci_register_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7727 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7728 | printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7729 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7730 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7731 | |
| 7732 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7733 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7734 | error_register: |
| 7735 | iwl3945_rate_control_unregister(); |
| 7736 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7737 | } |
| 7738 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7739 | static void __exit iwl3945_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7740 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7741 | pci_unregister_driver(&iwl3945_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7742 | iwl3945_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7743 | } |
| 7744 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 7745 | MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX)); |
Zhu Yi | 25cb6ca | 2008-09-11 11:45:22 +0800 | [diff] [blame] | 7746 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7747 | module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7748 | 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] | 7749 | module_param_named(disable, iwl3945_mod_params.disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7750 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Samuel Ortiz | 9c74d9f | 2009-01-08 10:19:59 -0800 | [diff] [blame] | 7751 | module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444); |
| 7752 | MODULE_PARM_DESC(swcrypto, |
| 7753 | "using software crypto (default 1 [software])\n"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7754 | module_param_named(debug, iwl3945_mod_params.debug, uint, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7755 | MODULE_PARM_DESC(debug, "debug output mask"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7756 | 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] | 7757 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 7758 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7759 | 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] | 7760 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 7761 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7762 | module_exit(iwl3945_exit); |
| 7763 | module_init(iwl3945_init); |