Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/dma-mapping.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/skbuff.h> |
| 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/wireless.h> |
| 39 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 40 | #include <linux/etherdevice.h> |
| 41 | #include <linux/if_arp.h> |
| 42 | |
| 43 | #include <net/ieee80211_radiotap.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 44 | #include <net/lib80211.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 45 | #include <net/mac80211.h> |
| 46 | |
| 47 | #include <asm/div64.h> |
| 48 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 49 | #define DRV_NAME "iwl3945" |
| 50 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 51 | #include "iwl-commands.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 52 | #include "iwl-3945.h" |
Tomas Winkler | bddadf8 | 2008-12-19 10:37:01 +0800 | [diff] [blame] | 53 | #include "iwl-3945-fh.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 54 | #include "iwl-helpers.h" |
Kolekar, Abhijeet | 5747d47 | 2008-12-19 10:37:18 +0800 | [diff] [blame] | 55 | #include "iwl-core.h" |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 56 | #include "iwl-dev.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 57 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 58 | static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 59 | struct iwl3945_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 60 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 61 | /* |
| 62 | * module name, copyright, version, etc. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 63 | */ |
| 64 | |
| 65 | #define DRV_DESCRIPTION \ |
| 66 | "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux" |
| 67 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 68 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 69 | #define VD "d" |
| 70 | #else |
| 71 | #define VD |
| 72 | #endif |
| 73 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 74 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 75 | #define VS "s" |
| 76 | #else |
| 77 | #define VS |
| 78 | #endif |
| 79 | |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 80 | #define IWL39_VERSION "1.2.26k" VD VS |
Reinette Chatre | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 81 | #define DRV_COPYRIGHT "Copyright(c) 2003-2008 Intel Corporation" |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 82 | #define DRV_AUTHOR "<ilw@linux.intel.com>" |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 83 | #define DRV_VERSION IWL39_VERSION |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 84 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 85 | |
| 86 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 87 | MODULE_VERSION(DRV_VERSION); |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 88 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 89 | MODULE_LICENSE("GPL"); |
| 90 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 91 | /* module parameters */ |
| 92 | struct iwl_mod_params iwl3945_mod_params = { |
| 93 | .num_of_queues = IWL39_MAX_NUM_QUEUES, |
| 94 | /* the rest are 0 by default */ |
| 95 | }; |
| 96 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 97 | static const struct ieee80211_supported_band *iwl3945_get_band( |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 98 | struct iwl_priv *priv, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 99 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 100 | return priv->hw->wiphy->bands[band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 103 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 104 | * DMA services |
| 105 | * |
| 106 | * Theory of operation |
| 107 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 108 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 109 | * of buffer descriptors, each of which points to one or more data buffers for |
| 110 | * the device to read from or fill. Driver and device exchange status of each |
| 111 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 112 | * entries in each circular buffer, to protect against confusing empty and full |
| 113 | * queue states. |
| 114 | * |
| 115 | * The device reads or writes the data in the queues via the device's several |
| 116 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 117 | * |
| 118 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 119 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 120 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 121 | * Tx queue resumed. |
| 122 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 123 | * The 3945 operates with six queues: One receive queue, one transmit queue |
| 124 | * (#4) for sending commands to the device firmware, and four transmit queues |
| 125 | * (#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] | 126 | ***************************************************/ |
| 127 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 128 | int iwl3945_x2_queue_used(const struct iwl_queue *q, int i) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 129 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 130 | return q->write_ptr > q->read_ptr ? |
| 131 | (i >= q->read_ptr && i < q->write_ptr) : |
| 132 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 135 | /** |
| 136 | * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes |
| 137 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 138 | 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] | 139 | int count, int slots_num, u32 id) |
| 140 | { |
| 141 | q->n_bd = count; |
| 142 | q->n_window = slots_num; |
| 143 | q->id = id; |
| 144 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 145 | /* count must be power-of-two size, otherwise iwl_queue_inc_wrap |
| 146 | * and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 147 | BUG_ON(!is_power_of_2(count)); |
| 148 | |
| 149 | /* slots_num must be power-of-two size, otherwise |
| 150 | * get_cmd_index is broken. */ |
| 151 | BUG_ON(!is_power_of_2(slots_num)); |
| 152 | |
| 153 | q->low_mark = q->n_window / 4; |
| 154 | if (q->low_mark < 4) |
| 155 | q->low_mark = 4; |
| 156 | |
| 157 | q->high_mark = q->n_window / 8; |
| 158 | if (q->high_mark < 2) |
| 159 | q->high_mark = 2; |
| 160 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 161 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 166 | /** |
| 167 | * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 168 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 169 | static int iwl3945_tx_queue_alloc(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 170 | struct iwl3945_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 171 | { |
| 172 | struct pci_dev *dev = priv->pci_dev; |
| 173 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 174 | /* Driver private data, only for Tx (not command) queues, |
| 175 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 176 | if (id != IWL_CMD_QUEUE_NUM) { |
| 177 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 178 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 179 | if (!txq->txb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 180 | IWL_ERR(priv, "kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 181 | "structures failed\n"); |
| 182 | goto error; |
| 183 | } |
| 184 | } else |
| 185 | txq->txb = NULL; |
| 186 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 187 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 188 | * shared with device */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 189 | txq->bd = pci_alloc_consistent(dev, |
| 190 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 191 | &txq->q.dma_addr); |
| 192 | |
| 193 | if (!txq->bd) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 194 | IWL_ERR(priv, "pci_alloc_consistent(%zd) failed\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 195 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 196 | goto error; |
| 197 | } |
| 198 | txq->q.id = id; |
| 199 | |
| 200 | return 0; |
| 201 | |
| 202 | error: |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 203 | kfree(txq->txb); |
| 204 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 205 | |
| 206 | return -ENOMEM; |
| 207 | } |
| 208 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 209 | /** |
| 210 | * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 211 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 212 | int iwl3945_tx_queue_init(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 213 | struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 214 | { |
| 215 | struct pci_dev *dev = priv->pci_dev; |
| 216 | int len; |
| 217 | int rc = 0; |
| 218 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 219 | /* |
| 220 | * Alloc buffer array for commands (Tx or other types of commands). |
| 221 | * For the command queue (#4), allocate command space + one big |
| 222 | * command for scan, since scan command is very huge; the system will |
| 223 | * not have two scans at the same time, so only one is needed. |
| 224 | * For data Tx queues (all other queues), no super-size command |
| 225 | * space is needed. |
| 226 | */ |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 227 | len = sizeof(struct iwl_cmd) * slots_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 228 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 229 | len += IWL_MAX_SCAN_SIZE; |
| 230 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 231 | if (!txq->cmd) |
| 232 | return -ENOMEM; |
| 233 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 234 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 235 | rc = iwl3945_tx_queue_alloc(priv, txq, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 236 | if (rc) { |
| 237 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 238 | |
| 239 | return -ENOMEM; |
| 240 | } |
| 241 | txq->need_update = 0; |
| 242 | |
| 243 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 244 | * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 245 | 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] | 246 | |
| 247 | /* Initialize queue high/low-water, head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 248 | 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] | 249 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 250 | /* Tell device where to find queue, enable DMA channel. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 251 | iwl3945_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 257 | * iwl3945_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 258 | * @txq: Transmit queue to deallocate. |
| 259 | * |
| 260 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 261 | * Free all buffers. |
| 262 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 263 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 264 | void iwl3945_tx_queue_free(struct iwl_priv *priv, struct iwl3945_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 265 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 266 | struct iwl_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 267 | struct pci_dev *dev = priv->pci_dev; |
| 268 | int len; |
| 269 | |
| 270 | if (q->n_bd == 0) |
| 271 | return; |
| 272 | |
| 273 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 274 | for (; q->write_ptr != q->read_ptr; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 275 | 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] | 276 | iwl3945_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 277 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 278 | len = sizeof(struct iwl_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 279 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 280 | len += IWL_MAX_SCAN_SIZE; |
| 281 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 282 | /* De-alloc array of command/tx buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 283 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 284 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 285 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 286 | if (txq->q.n_bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 287 | pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 288 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 289 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 290 | /* De-alloc array of per-TFD driver data */ |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 291 | kfree(txq->txb); |
| 292 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 293 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 294 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 295 | memset(txq, 0, sizeof(*txq)); |
| 296 | } |
| 297 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 298 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 299 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 300 | * the functionality provided here |
| 301 | */ |
| 302 | |
| 303 | /**************************************************************/ |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 304 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 305 | /** |
| 306 | * iwl3945_remove_station - Remove driver's knowledge of station. |
| 307 | * |
| 308 | * NOTE: This does not remove station from device's station table. |
| 309 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 310 | 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] | 311 | { |
| 312 | int index = IWL_INVALID_STATION; |
| 313 | int i; |
| 314 | unsigned long flags; |
| 315 | |
| 316 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 317 | |
| 318 | if (is_ap) |
| 319 | index = IWL_AP_ID; |
| 320 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 321 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 322 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 323 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 324 | if (priv->stations_39[i].used && |
| 325 | !compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 326 | addr)) { |
| 327 | index = i; |
| 328 | break; |
| 329 | } |
| 330 | |
| 331 | if (unlikely(index == IWL_INVALID_STATION)) |
| 332 | goto out; |
| 333 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 334 | if (priv->stations_39[index].used) { |
| 335 | priv->stations_39[index].used = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 336 | priv->num_stations--; |
| 337 | } |
| 338 | |
| 339 | BUG_ON(priv->num_stations < 0); |
| 340 | |
| 341 | out: |
| 342 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 343 | return 0; |
| 344 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 345 | #endif |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 346 | |
| 347 | /** |
| 348 | * iwl3945_clear_stations_table - Clear the driver's station table |
| 349 | * |
| 350 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 351 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 352 | static void iwl3945_clear_stations_table(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 353 | { |
| 354 | unsigned long flags; |
| 355 | |
| 356 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 357 | |
| 358 | priv->num_stations = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 359 | memset(priv->stations_39, 0, sizeof(priv->stations_39)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 360 | |
| 361 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 362 | } |
| 363 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 364 | /** |
| 365 | * iwl3945_add_station - Add station to station tables in driver and device |
| 366 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 367 | 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] | 368 | { |
| 369 | int i; |
| 370 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 371 | struct iwl3945_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 372 | unsigned long flags_spin; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 373 | u8 rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 374 | |
| 375 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 376 | if (is_ap) |
| 377 | index = IWL_AP_ID; |
| 378 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 379 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 381 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 382 | if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 383 | addr)) { |
| 384 | index = i; |
| 385 | break; |
| 386 | } |
| 387 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 388 | if (!priv->stations_39[i].used && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 389 | index == IWL_INVALID_STATION) |
| 390 | index = i; |
| 391 | } |
| 392 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 393 | /* These two conditions has the same outcome but keep them separate |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 394 | since they have different meaning */ |
| 395 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 396 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 397 | return index; |
| 398 | } |
| 399 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 400 | if (priv->stations_39[index].used && |
| 401 | !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 402 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 403 | return index; |
| 404 | } |
| 405 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 406 | IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 407 | station = &priv->stations_39[index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 408 | station->used = 1; |
| 409 | priv->num_stations++; |
| 410 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 411 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 412 | memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 413 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 414 | station->sta.mode = 0; |
| 415 | station->sta.sta.sta_id = index; |
| 416 | station->sta.station_flags = 0; |
| 417 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 418 | if (priv->band == IEEE80211_BAND_5GHZ) |
Tomas Winkler | 6994633 | 2007-10-25 17:15:27 +0800 | [diff] [blame] | 419 | rate = IWL_RATE_6M_PLCP; |
| 420 | else |
| 421 | rate = IWL_RATE_1M_PLCP; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 422 | |
| 423 | /* Turn on both antennas for the station... */ |
| 424 | station->sta.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 425 | iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 426 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 427 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 428 | |
| 429 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 430 | iwl3945_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 431 | return index; |
| 432 | |
| 433 | } |
| 434 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 435 | |
| 436 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 437 | |
Abhijeet Kolekar | c305606 | 2008-11-12 13:14:08 -0800 | [diff] [blame] | 438 | #define IWL_CMD(x) case x: return #x |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 439 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 440 | |
| 441 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 442 | * iwl3945_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 443 | * @priv: device private data point |
| 444 | * @cmd: a point to the ucode command structure |
| 445 | * |
| 446 | * The function returns < 0 values to indicate the operation is |
| 447 | * failed. On success, it turns the index (> 0) of command in the |
| 448 | * command queue. |
| 449 | */ |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 450 | 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] | 451 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 452 | struct iwl3945_tx_queue *txq = &priv->txq39[IWL_CMD_QUEUE_NUM]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 453 | struct iwl_queue *q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 454 | struct iwl3945_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 455 | u32 *control_flags; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 456 | struct iwl_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 457 | u32 idx; |
| 458 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 459 | dma_addr_t phys_addr; |
| 460 | int pad; |
| 461 | u16 count; |
| 462 | int ret; |
| 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 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 484 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 485 | memset(tfd, 0, sizeof(*tfd)); |
| 486 | |
| 487 | control_flags = (u32 *) tfd; |
| 488 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 489 | idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 490 | out_cmd = &txq->cmd[idx]; |
| 491 | |
| 492 | out_cmd->hdr.cmd = cmd->id; |
| 493 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 494 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 495 | |
| 496 | /* At this point, the out_cmd now has all of the incoming cmd |
| 497 | * information */ |
| 498 | |
| 499 | out_cmd->hdr.flags = 0; |
| 500 | out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 501 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 502 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 503 | out_cmd->hdr.sequence |= SEQ_HUGE_FRAME; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 504 | |
| 505 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 506 | offsetof(struct iwl_cmd, hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 507 | 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] | 508 | |
| 509 | pad = U32_PAD(cmd->len); |
| 510 | count = TFD_CTL_COUNT_GET(*control_flags); |
| 511 | *control_flags = TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad); |
| 512 | |
| 513 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 514 | "%d bytes at %d[%d]:%d\n", |
| 515 | get_cmd_string(out_cmd->hdr.cmd), |
| 516 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 517 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 518 | |
| 519 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 520 | |
| 521 | /* Increment and update queue's write index */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 522 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 523 | ret = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 524 | |
| 525 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 526 | return ret ? ret : idx; |
| 527 | } |
| 528 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 529 | static int iwl3945_send_cmd_async(struct iwl_priv *priv, |
| 530 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 531 | { |
| 532 | int ret; |
| 533 | |
| 534 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 535 | |
| 536 | /* An asynchronous command can not expect an SKB to be set. */ |
| 537 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 538 | |
| 539 | /* An asynchronous command MUST have a callback. */ |
| 540 | BUG_ON(!cmd->meta.u.callback); |
| 541 | |
| 542 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 543 | return -EBUSY; |
| 544 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 545 | ret = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 546 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 547 | IWL_ERR(priv, |
| 548 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 549 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 550 | return ret; |
| 551 | } |
| 552 | return 0; |
| 553 | } |
| 554 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 555 | static int iwl3945_send_cmd_sync(struct iwl_priv *priv, |
| 556 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 557 | { |
| 558 | int cmd_idx; |
| 559 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 560 | |
| 561 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 562 | |
| 563 | /* A synchronous command can not have a callback set. */ |
| 564 | BUG_ON(cmd->meta.u.callback != NULL); |
| 565 | |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 566 | if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 567 | IWL_ERR(priv, |
| 568 | "Error sending %s: Already sending a host command\n", |
| 569 | get_cmd_string(cmd->id)); |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 570 | ret = -EBUSY; |
| 571 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 575 | |
| 576 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 577 | cmd->meta.source = &cmd->meta; |
| 578 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 579 | cmd_idx = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 580 | if (cmd_idx < 0) { |
| 581 | ret = cmd_idx; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 582 | IWL_ERR(priv, |
| 583 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 584 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 585 | goto out; |
| 586 | } |
| 587 | |
| 588 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 589 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 590 | HOST_COMPLETE_TIMEOUT); |
| 591 | if (!ret) { |
| 592 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 593 | IWL_ERR(priv, "Error sending %s: time out after %dms\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 594 | get_cmd_string(cmd->id), |
| 595 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 596 | |
| 597 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 598 | ret = -ETIMEDOUT; |
| 599 | goto cancel; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 604 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 605 | get_cmd_string(cmd->id)); |
| 606 | ret = -ECANCELED; |
| 607 | goto fail; |
| 608 | } |
| 609 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 610 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 611 | get_cmd_string(cmd->id)); |
| 612 | ret = -EIO; |
| 613 | goto fail; |
| 614 | } |
| 615 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 616 | IWL_ERR(priv, "Error: Response NULL in '%s'\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 617 | get_cmd_string(cmd->id)); |
| 618 | ret = -EIO; |
Zhu Yi | 73e1a65 | 2009-01-08 10:19:58 -0800 | [diff] [blame] | 619 | goto cancel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | ret = 0; |
| 623 | goto out; |
| 624 | |
| 625 | cancel: |
| 626 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 627 | struct iwl_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 628 | |
| 629 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 630 | * TX cmd queue. Otherwise in case the cmd comes |
| 631 | * in later, it will possibly set an invalid |
| 632 | * address (cmd->meta.source). */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 633 | qcmd = &priv->txq39[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 634 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 635 | } |
| 636 | fail: |
| 637 | if (cmd->meta.u.skb) { |
| 638 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 639 | cmd->meta.u.skb = NULL; |
| 640 | } |
| 641 | out: |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 642 | clear_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 643 | return ret; |
| 644 | } |
| 645 | |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 646 | 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] | 647 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 648 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 649 | return iwl3945_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 650 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 651 | return iwl3945_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 654 | 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] | 655 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 656 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 657 | .id = id, |
| 658 | .len = len, |
| 659 | .data = data, |
| 660 | }; |
| 661 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 662 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 665 | 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] | 666 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 667 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 668 | .id = id, |
| 669 | .len = sizeof(val), |
| 670 | .data = &val, |
| 671 | }; |
| 672 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 673 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 676 | int iwl3945_send_statistics_request(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 677 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 678 | return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 682 | * 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] | 683 | * @band: 2.4 or 5 GHz band |
| 684 | * @channel: Any channel valid for the requested band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 685 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 686 | * In addition to setting the staging RXON, priv->band is also set. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 687 | * |
| 688 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 689 | * in the staging RXON flag structure based on the band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 690 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 691 | static int iwl3945_set_rxon_channel(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 692 | enum ieee80211_band band, |
| 693 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 694 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 695 | if (!iwl3945_get_channel_info(priv, band, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 696 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 697 | channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 698 | return -EINVAL; |
| 699 | } |
| 700 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 701 | if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 702 | (priv->band == band)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 703 | return 0; |
| 704 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 705 | priv->staging39_rxon.channel = cpu_to_le16(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 706 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 707 | priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 708 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 709 | priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 710 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 711 | priv->band = band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 712 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 713 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 719 | * iwl3945_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 720 | * |
| 721 | * NOTE: This is really only useful during development and can eventually |
| 722 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 723 | * making changes |
| 724 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 725 | static int iwl3945_check_rxon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 726 | { |
| 727 | int error = 0; |
| 728 | int counter = 1; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 729 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 730 | |
| 731 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 732 | error |= le32_to_cpu(rxon->flags & |
| 733 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 734 | RXON_FLG_RADAR_DETECT_MSK)); |
| 735 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 736 | IWL_WARN(priv, "check 24G fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 737 | counter++, error); |
| 738 | } else { |
| 739 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 740 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 741 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 742 | IWL_WARN(priv, "check 52 fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 743 | counter++, error); |
| 744 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 745 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 746 | IWL_WARN(priv, "check 52 CCK %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 747 | counter++, error); |
| 748 | } |
| 749 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 750 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 751 | IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 752 | |
| 753 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 754 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 755 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 756 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 757 | IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 758 | |
| 759 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 760 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 761 | IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 762 | |
| 763 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 764 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 765 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 766 | IWL_WARN(priv, "check CCK and short slot %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 767 | counter++, error); |
| 768 | |
| 769 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 770 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 771 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 772 | IWL_WARN(priv, "check CCK & auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 773 | counter++, error); |
| 774 | |
| 775 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 776 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 777 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 778 | IWL_WARN(priv, "check TGG and auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 779 | counter++, error); |
| 780 | |
| 781 | if ((rxon->flags & RXON_FLG_DIS_DIV_MSK)) |
| 782 | error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK | |
| 783 | RXON_FLG_ANT_A_MSK)) == 0); |
| 784 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 785 | IWL_WARN(priv, "check antenna %d %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 786 | |
| 787 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 788 | IWL_WARN(priv, "Tuning to channel %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 789 | le16_to_cpu(rxon->channel)); |
| 790 | |
| 791 | if (error) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 792 | IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 793 | return -1; |
| 794 | } |
| 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 799 | * 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] | 800 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 801 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 802 | * If the RXON structure is changing enough to require a new tune, |
| 803 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 804 | * 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] | 805 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 806 | static int iwl3945_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 807 | { |
| 808 | |
| 809 | /* These items are only settable from the full RXON command */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 810 | if (!(iwl3945_is_associated(priv)) || |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 811 | compare_ether_addr(priv->staging39_rxon.bssid_addr, |
| 812 | priv->active39_rxon.bssid_addr) || |
| 813 | compare_ether_addr(priv->staging39_rxon.node_addr, |
| 814 | priv->active39_rxon.node_addr) || |
| 815 | compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr, |
| 816 | priv->active39_rxon.wlap_bssid_addr) || |
| 817 | (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) || |
| 818 | (priv->staging39_rxon.channel != priv->active39_rxon.channel) || |
| 819 | (priv->staging39_rxon.air_propagation != |
| 820 | priv->active39_rxon.air_propagation) || |
| 821 | (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 822 | return 1; |
| 823 | |
| 824 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 825 | * be updated with the RXON_ASSOC command -- however only some |
| 826 | * flag transitions are allowed using RXON_ASSOC */ |
| 827 | |
| 828 | /* Check if we are not switching bands */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 829 | if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 830 | (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 831 | return 1; |
| 832 | |
| 833 | /* Check if we are switching association toggle */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 834 | if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 835 | (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 836 | return 1; |
| 837 | |
| 838 | return 0; |
| 839 | } |
| 840 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 841 | static int iwl3945_send_rxon_assoc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 842 | { |
| 843 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 844 | struct iwl_rx_packet *res = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 845 | struct iwl3945_rxon_assoc_cmd rxon_assoc; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 846 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 847 | .id = REPLY_RXON_ASSOC, |
| 848 | .len = sizeof(rxon_assoc), |
| 849 | .meta.flags = CMD_WANT_SKB, |
| 850 | .data = &rxon_assoc, |
| 851 | }; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 852 | const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon; |
| 853 | const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 854 | |
| 855 | if ((rxon1->flags == rxon2->flags) && |
| 856 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 857 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 858 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 859 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 860 | return 0; |
| 861 | } |
| 862 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 863 | rxon_assoc.flags = priv->staging39_rxon.flags; |
| 864 | rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags; |
| 865 | rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates; |
| 866 | rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 867 | rxon_assoc.reserved = 0; |
| 868 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 869 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 870 | if (rc) |
| 871 | return rc; |
| 872 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 873 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 874 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 875 | IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 876 | rc = -EIO; |
| 877 | } |
| 878 | |
| 879 | priv->alloc_rxb_skb--; |
| 880 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 881 | |
| 882 | return rc; |
| 883 | } |
| 884 | |
| 885 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 886 | * iwl3945_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 887 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 888 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 889 | * the active_rxon structure is updated with the new data. This |
| 890 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 891 | * a HW tune is required based on the RXON structure changes. |
| 892 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 893 | static int iwl3945_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 894 | { |
| 895 | /* cast away the const for active_rxon in this function */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 896 | struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 897 | int rc = 0; |
| 898 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 899 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 900 | return -1; |
| 901 | |
| 902 | /* always get timestamp with Rx frame */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 903 | priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 904 | |
| 905 | /* select antenna */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 906 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 907 | ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 908 | priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 909 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 910 | rc = iwl3945_check_rxon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 911 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 912 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 913 | return -EINVAL; |
| 914 | } |
| 915 | |
| 916 | /* 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] | 917 | * iwl3945_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 918 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 919 | if (!iwl3945_full_rxon_required(priv)) { |
| 920 | rc = iwl3945_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 921 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 922 | IWL_ERR(priv, "Error setting RXON_ASSOC " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 923 | "configuration (%d).\n", rc); |
| 924 | return rc; |
| 925 | } |
| 926 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 927 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 928 | |
| 929 | return 0; |
| 930 | } |
| 931 | |
| 932 | /* If we are currently associated and the new config requires |
| 933 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 934 | * we must clear the associated from the active configuration |
| 935 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 936 | if (iwl3945_is_associated(priv) && |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 937 | (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 938 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 939 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 940 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 941 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
| 942 | sizeof(struct iwl3945_rxon_cmd), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 943 | &priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 944 | |
| 945 | /* If the mask clearing failed then we set |
| 946 | * active_rxon back to what it was previously */ |
| 947 | if (rc) { |
| 948 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 949 | IWL_ERR(priv, "Error clearing ASSOC_MSK on current " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 950 | "configuration (%d).\n", rc); |
| 951 | return rc; |
| 952 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | IWL_DEBUG_INFO("Sending RXON\n" |
| 956 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 957 | "* channel = %d\n" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 958 | "* bssid = %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 959 | ((priv->staging39_rxon.filter_flags & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 960 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 961 | le16_to_cpu(priv->staging39_rxon.channel), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 962 | priv->staging_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 963 | |
| 964 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 965 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 966 | sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 967 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 968 | IWL_ERR(priv, "Error setting new configuration (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 969 | return rc; |
| 970 | } |
| 971 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 972 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 973 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 974 | iwl3945_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 975 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 976 | /* If we issue a new RXON command which required a tune then we must |
| 977 | * 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] | 978 | rc = iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 979 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 980 | IWL_ERR(priv, "Error setting Tx power (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 981 | return rc; |
| 982 | } |
| 983 | |
| 984 | /* Add the broadcast address so we can send broadcast frames */ |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 985 | if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 986 | IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 987 | IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 988 | return -EIO; |
| 989 | } |
| 990 | |
| 991 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 992 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 993 | if (iwl3945_is_associated(priv) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 994 | (priv->iw_mode == NL80211_IFTYPE_STATION)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 995 | if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 996 | == IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 997 | IWL_ERR(priv, "Error adding AP address for transmit\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 998 | return -EIO; |
| 999 | } |
| 1000 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1001 | /* Init the hardware's rate fallback order based on the band */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1002 | rc = iwl3945_init_hw_rate_table(priv); |
| 1003 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1004 | IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1005 | return -EIO; |
| 1006 | } |
| 1007 | |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1011 | static int iwl3945_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1012 | { |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1013 | struct iwl_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1014 | .flags = 3, |
| 1015 | .lead_time = 0xAA, |
| 1016 | .max_kill = 1, |
| 1017 | .kill_ack_mask = 0, |
| 1018 | .kill_cts_mask = 0, |
| 1019 | }; |
| 1020 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1021 | return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1022 | sizeof(bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1025 | static int iwl3945_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1026 | { |
| 1027 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1028 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1029 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1030 | .id = REPLY_SCAN_ABORT_CMD, |
| 1031 | .meta.flags = CMD_WANT_SKB, |
| 1032 | }; |
| 1033 | |
| 1034 | /* If there isn't a scan actively going on in the hardware |
| 1035 | * then we are in between scan bands and not actually |
| 1036 | * actively scanning, so don't send the abort command */ |
| 1037 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1038 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1042 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1043 | if (rc) { |
| 1044 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1045 | return rc; |
| 1046 | } |
| 1047 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1048 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1049 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1050 | /* The scan abort will return 1 for success or |
| 1051 | * 2 for "failure". A failure condition can be |
| 1052 | * due to simply not being in an active scan which |
| 1053 | * can occur if we send the scan abort before we |
| 1054 | * the microcode has notified us that a scan is |
| 1055 | * completed. */ |
| 1056 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1057 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1058 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1059 | } |
| 1060 | |
| 1061 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1062 | |
| 1063 | return rc; |
| 1064 | } |
| 1065 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1066 | static int iwl3945_card_state_sync_callback(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1067 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1068 | struct sk_buff *skb) |
| 1069 | { |
| 1070 | return 1; |
| 1071 | } |
| 1072 | |
| 1073 | /* |
| 1074 | * CARD_STATE_CMD |
| 1075 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1076 | * Use: Sets the device's internal card state to enable, disable, or halt |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1077 | * |
| 1078 | * When in the 'enable' state the card operates as normal. |
| 1079 | * When in the 'disable' state, the card enters into a low power mode. |
| 1080 | * When in the 'halt' state, the card is shut down and must be fully |
| 1081 | * restarted to come back on. |
| 1082 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1083 | static int iwl3945_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1084 | { |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1085 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1086 | .id = REPLY_CARD_STATE_CMD, |
| 1087 | .len = sizeof(u32), |
| 1088 | .data = &flags, |
| 1089 | .meta.flags = meta_flag, |
| 1090 | }; |
| 1091 | |
| 1092 | if (meta_flag & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1093 | cmd.meta.u.callback = iwl3945_card_state_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1094 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1095 | return iwl3945_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1098 | static int iwl3945_add_sta_sync_callback(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1099 | struct iwl_cmd *cmd, struct sk_buff *skb) |
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 | |
| 1103 | if (!skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1104 | IWL_ERR(priv, "Error: Response NULL in REPLY_ADD_STA.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1105 | return 1; |
| 1106 | } |
| 1107 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1108 | res = (struct iwl_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1109 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1110 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1111 | res->hdr.flags); |
| 1112 | return 1; |
| 1113 | } |
| 1114 | |
| 1115 | switch (res->u.add_sta.status) { |
| 1116 | case ADD_STA_SUCCESS_MSK: |
| 1117 | break; |
| 1118 | default: |
| 1119 | break; |
| 1120 | } |
| 1121 | |
| 1122 | /* We didn't cache the SKB; let the caller free it */ |
| 1123 | return 1; |
| 1124 | } |
| 1125 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1126 | int iwl3945_send_add_station(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1127 | struct iwl3945_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1128 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1129 | struct iwl_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1130 | int rc = 0; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1131 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1132 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1133 | .len = sizeof(struct iwl3945_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1134 | .meta.flags = flags, |
| 1135 | .data = sta, |
| 1136 | }; |
| 1137 | |
| 1138 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1139 | cmd.meta.u.callback = iwl3945_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1140 | else |
| 1141 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1142 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1143 | rc = iwl3945_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1144 | |
| 1145 | if (rc || (flags & CMD_ASYNC)) |
| 1146 | return rc; |
| 1147 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1148 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1149 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1150 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1151 | res->hdr.flags); |
| 1152 | rc = -EIO; |
| 1153 | } |
| 1154 | |
| 1155 | if (rc == 0) { |
| 1156 | switch (res->u.add_sta.status) { |
| 1157 | case ADD_STA_SUCCESS_MSK: |
| 1158 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1159 | break; |
| 1160 | default: |
| 1161 | rc = -EIO; |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1162 | IWL_WARN(priv, "REPLY_ADD_STA failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1163 | break; |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | priv->alloc_rxb_skb--; |
| 1168 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1169 | |
| 1170 | return rc; |
| 1171 | } |
| 1172 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1173 | static int iwl3945_update_sta_key_info(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1174 | struct ieee80211_key_conf *keyconf, |
| 1175 | u8 sta_id) |
| 1176 | { |
| 1177 | unsigned long flags; |
| 1178 | __le16 key_flags = 0; |
| 1179 | |
| 1180 | switch (keyconf->alg) { |
| 1181 | case ALG_CCMP: |
| 1182 | key_flags |= STA_KEY_FLG_CCMP; |
| 1183 | key_flags |= cpu_to_le16( |
| 1184 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1185 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1186 | break; |
| 1187 | case ALG_TKIP: |
| 1188 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1189 | default: |
| 1190 | return -EINVAL; |
| 1191 | } |
| 1192 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1193 | priv->stations_39[sta_id].keyinfo.alg = keyconf->alg; |
| 1194 | priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1195 | memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1196 | keyconf->keylen); |
| 1197 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1198 | memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1199 | keyconf->keylen); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1200 | priv->stations_39[sta_id].sta.key.key_flags = key_flags; |
| 1201 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1202 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1203 | |
| 1204 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1205 | |
| 1206 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1207 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1208 | return 0; |
| 1209 | } |
| 1210 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1211 | 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] | 1212 | { |
| 1213 | unsigned long flags; |
| 1214 | |
| 1215 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1216 | memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key)); |
| 1217 | memset(&priv->stations_39[sta_id].sta.key, 0, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1218 | sizeof(struct iwl4965_keyinfo)); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1219 | priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1220 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1221 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1222 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1223 | |
| 1224 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1225 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1226 | return 0; |
| 1227 | } |
| 1228 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1229 | static void iwl3945_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1230 | { |
| 1231 | struct list_head *element; |
| 1232 | |
| 1233 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1234 | priv->frames_count); |
| 1235 | |
| 1236 | while (!list_empty(&priv->free_frames)) { |
| 1237 | element = priv->free_frames.next; |
| 1238 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1239 | kfree(list_entry(element, struct iwl3945_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1240 | priv->frames_count--; |
| 1241 | } |
| 1242 | |
| 1243 | if (priv->frames_count) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1244 | 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] | 1245 | priv->frames_count); |
| 1246 | priv->frames_count = 0; |
| 1247 | } |
| 1248 | } |
| 1249 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1250 | static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1251 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1252 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1253 | struct list_head *element; |
| 1254 | if (list_empty(&priv->free_frames)) { |
| 1255 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1256 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1257 | IWL_ERR(priv, "Could not allocate frame!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1258 | return NULL; |
| 1259 | } |
| 1260 | |
| 1261 | priv->frames_count++; |
| 1262 | return frame; |
| 1263 | } |
| 1264 | |
| 1265 | element = priv->free_frames.next; |
| 1266 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1267 | return list_entry(element, struct iwl3945_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1270 | 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] | 1271 | { |
| 1272 | memset(frame, 0, sizeof(*frame)); |
| 1273 | list_add(&frame->list, &priv->free_frames); |
| 1274 | } |
| 1275 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1276 | unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1277 | struct ieee80211_hdr *hdr, |
Rami Rosen | 73ec1cc | 2008-12-16 09:37:07 +0200 | [diff] [blame] | 1278 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1279 | { |
| 1280 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1281 | if (!iwl3945_is_associated(priv) || !priv->ibss_beacon || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1282 | ((priv->iw_mode != NL80211_IFTYPE_ADHOC) && |
| 1283 | (priv->iw_mode != NL80211_IFTYPE_AP))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1284 | return 0; |
| 1285 | |
| 1286 | if (priv->ibss_beacon->len > left) |
| 1287 | return 0; |
| 1288 | |
| 1289 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1290 | |
| 1291 | return priv->ibss_beacon->len; |
| 1292 | } |
| 1293 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1294 | static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1295 | { |
| 1296 | u8 i; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1297 | int rate_mask; |
| 1298 | |
| 1299 | /* Set rate mask*/ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1300 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1301 | rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1302 | else |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1303 | rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1304 | |
| 1305 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1306 | i = iwl3945_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1307 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1308 | return iwl3945_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1311 | /* No valid rate was found. Assign the lowest one */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1312 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1313 | return IWL_RATE_1M_PLCP; |
| 1314 | else |
| 1315 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1318 | static int iwl3945_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1319 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1320 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1321 | unsigned int frame_size; |
| 1322 | int rc; |
| 1323 | u8 rate; |
| 1324 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1325 | frame = iwl3945_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1326 | |
| 1327 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1328 | IWL_ERR(priv, "Could not obtain free frame buffer for beacon " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1329 | "command.\n"); |
| 1330 | return -ENOMEM; |
| 1331 | } |
| 1332 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1333 | rate = iwl3945_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1334 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1335 | frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1336 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1337 | rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1338 | &frame->u.cmd[0]); |
| 1339 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1340 | iwl3945_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1341 | |
| 1342 | return rc; |
| 1343 | } |
| 1344 | |
| 1345 | /****************************************************************************** |
| 1346 | * |
| 1347 | * EEPROM related functions |
| 1348 | * |
| 1349 | ******************************************************************************/ |
| 1350 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1351 | static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1352 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1353 | memcpy(mac, priv->eeprom39.mac_address, 6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1354 | } |
| 1355 | |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1356 | /* |
| 1357 | * Clear the OWNER_MSK, to establish driver (instead of uCode running on |
| 1358 | * embedded controller) as EEPROM reader; each read is a series of pulses |
| 1359 | * to/from the EEPROM chip, not a single event, so even reads could conflict |
| 1360 | * if they weren't arbitrated by some ownership mechanism. Here, the driver |
| 1361 | * simply claims ownership, which should be safe when this function is called |
| 1362 | * (i.e. before loading uCode!). |
| 1363 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1364 | static inline int iwl3945_eeprom_acquire_semaphore(struct iwl_priv *priv) |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1365 | { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1366 | _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] | 1367 | return 0; |
| 1368 | } |
| 1369 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1370 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1371 | * iwl3945_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1372 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1373 | * Load the EEPROM contents from adapter into priv->eeprom39 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1374 | * |
| 1375 | * NOTE: This routine uses the non-debug IO access functions. |
| 1376 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1377 | int iwl3945_eeprom_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1378 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1379 | u16 *e = (u16 *)&priv->eeprom39; |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1380 | u32 gp = iwl_read32(priv, CSR_EEPROM_GP); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1381 | int sz = sizeof(priv->eeprom39); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1382 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1383 | u16 addr; |
| 1384 | |
| 1385 | /* The EEPROM structure has several padding buffers within it |
| 1386 | * and when adding new EEPROM maps is subject to programmer errors |
| 1387 | * which may be very difficult to identify without explicitly |
| 1388 | * checking the resulting size of the eeprom map. */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1389 | BUILD_BUG_ON(sizeof(priv->eeprom39) != IWL_EEPROM_IMAGE_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1390 | |
| 1391 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1392 | IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1393 | return -ENOENT; |
| 1394 | } |
| 1395 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1396 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1397 | ret = iwl3945_eeprom_acquire_semaphore(priv); |
| 1398 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1399 | IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1400 | return -ENOENT; |
| 1401 | } |
| 1402 | |
| 1403 | /* eeprom is an array of 16bit values */ |
| 1404 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1405 | u32 r; |
| 1406 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1407 | _iwl_write32(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1408 | CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1409 | _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
| 1410 | ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1411 | CSR_EEPROM_REG_READ_VALID_MSK, |
| 1412 | IWL_EEPROM_ACCESS_TIMEOUT); |
| 1413 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1414 | IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1415 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1416 | } |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1417 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1418 | r = _iwl_read_direct32(priv, CSR_EEPROM_REG); |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1419 | e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1425 | static void iwl3945_unset_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1426 | { |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1427 | if (priv->shared_virt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1428 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1429 | sizeof(struct iwl3945_shared), |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1430 | priv->shared_virt, |
| 1431 | priv->shared_phys); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1435 | * 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] | 1436 | * |
| 1437 | * return : set the bit for each supported rate insert in ie |
| 1438 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1439 | static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1440 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1441 | { |
| 1442 | u16 ret_rates = 0, bit; |
| 1443 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1444 | u8 *cnt = ie; |
| 1445 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1446 | |
| 1447 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1448 | if (bit & supported_rate) { |
| 1449 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1450 | rates[*cnt] = iwl3945_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1451 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1452 | (*cnt)++; |
| 1453 | (*left)--; |
| 1454 | if ((*left <= 0) || |
| 1455 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1456 | break; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | return ret_rates; |
| 1461 | } |
| 1462 | |
| 1463 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1464 | * 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] | 1465 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1466 | static u16 iwl3945_fill_probe_req(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1467 | struct ieee80211_mgmt *frame, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 1468 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1469 | { |
| 1470 | int len = 0; |
| 1471 | u8 *pos = NULL; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1472 | u16 active_rates, ret_rates, cck_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1473 | |
| 1474 | /* Make sure there is enough space for the probe request, |
| 1475 | * two mandatory IEs and the data */ |
| 1476 | left -= 24; |
| 1477 | if (left < 0) |
| 1478 | return 0; |
| 1479 | len += 24; |
| 1480 | |
| 1481 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1482 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1483 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1484 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1485 | frame->seq_ctrl = 0; |
| 1486 | |
| 1487 | /* fill in our indirect SSID IE */ |
| 1488 | /* ...next IE... */ |
| 1489 | |
| 1490 | left -= 2; |
| 1491 | if (left < 0) |
| 1492 | return 0; |
| 1493 | len += 2; |
| 1494 | pos = &(frame->u.probe_req.variable[0]); |
| 1495 | *pos++ = WLAN_EID_SSID; |
| 1496 | *pos++ = 0; |
| 1497 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1498 | /* fill in supported rate */ |
| 1499 | /* ...next IE... */ |
| 1500 | left -= 2; |
| 1501 | if (left < 0) |
| 1502 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1503 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1504 | /* ... fill it in... */ |
| 1505 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1506 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1507 | |
| 1508 | priv->active_rate = priv->rates_mask; |
| 1509 | active_rates = priv->active_rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1510 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 1511 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1512 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1513 | ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1514 | priv->active_rate_basic, &left); |
| 1515 | active_rates &= ~ret_rates; |
| 1516 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1517 | ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1518 | priv->active_rate_basic, &left); |
| 1519 | active_rates &= ~ret_rates; |
| 1520 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1521 | len += 2 + *pos; |
| 1522 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1523 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1524 | goto fill_end; |
| 1525 | |
| 1526 | /* fill in supported extended rate */ |
| 1527 | /* ...next IE... */ |
| 1528 | left -= 2; |
| 1529 | if (left < 0) |
| 1530 | return 0; |
| 1531 | /* ... fill it in... */ |
| 1532 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1533 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1534 | iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1535 | priv->active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1536 | if (*pos > 0) |
| 1537 | len += 2 + *pos; |
| 1538 | |
| 1539 | fill_end: |
| 1540 | return (u16)len; |
| 1541 | } |
| 1542 | |
| 1543 | /* |
| 1544 | * QoS support |
| 1545 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1546 | static int iwl3945_send_qos_params_command(struct iwl_priv *priv, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1547 | struct iwl_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1548 | { |
| 1549 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1550 | return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1551 | sizeof(struct iwl_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1554 | static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1555 | { |
| 1556 | unsigned long flags; |
| 1557 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1558 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1559 | return; |
| 1560 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1561 | spin_lock_irqsave(&priv->lock, flags); |
| 1562 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1563 | |
| 1564 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1565 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1566 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1567 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
| 1568 | |
| 1569 | if (priv->qos_data.qos_active) |
| 1570 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1571 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1572 | |
| 1573 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1574 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1575 | if (force || iwl3945_is_associated(priv)) { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1576 | IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | priv->qos_data.qos_active); |
| 1578 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1579 | iwl3945_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1580 | &(priv->qos_data.def_qos_parm)); |
| 1581 | } |
| 1582 | } |
| 1583 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1584 | /* |
| 1585 | * Power management (not Tx power!) functions |
| 1586 | */ |
| 1587 | #define MSEC_TO_USEC 1024 |
| 1588 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1589 | |
| 1590 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 1591 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1592 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 1593 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 1594 | __constant_cpu_to_le32(X1), \ |
| 1595 | __constant_cpu_to_le32(X2), \ |
| 1596 | __constant_cpu_to_le32(X3), \ |
| 1597 | __constant_cpu_to_le32(X4)} |
| 1598 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1599 | /* default power management (not Tx power) table values */ |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1600 | /* for TIM 0-10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1601 | static struct iwl_power_vec_entry range_0[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1602 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1603 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 1604 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 1605 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 1606 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 1607 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 1608 | }; |
| 1609 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1610 | /* for TIM > 10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1611 | static struct iwl_power_vec_entry range_1[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1612 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1613 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 1614 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 1615 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 1616 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 1617 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 1618 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 1619 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 1620 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 1621 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 1622 | }; |
| 1623 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1624 | int iwl3945_power_init_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1625 | { |
| 1626 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1627 | struct iwl3945_power_mgr *pow_data; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1628 | int size = sizeof(struct iwl_power_vec_entry) * IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1629 | u16 pci_pm; |
| 1630 | |
| 1631 | IWL_DEBUG_POWER("Initialize power \n"); |
| 1632 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1633 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1634 | |
| 1635 | memset(pow_data, 0, sizeof(*pow_data)); |
| 1636 | |
| 1637 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 1638 | pow_data->dtim_val = 0xffff; |
| 1639 | |
| 1640 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 1641 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 1642 | |
| 1643 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 1644 | if (rc != 0) |
| 1645 | return 0; |
| 1646 | else { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1647 | struct iwl_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1648 | |
| 1649 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 1650 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1651 | for (i = 0; i < IWL39_POWER_AC; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1652 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 1653 | |
| 1654 | if (pci_pm & 0x1) |
| 1655 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 1656 | else |
| 1657 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 1658 | } |
| 1659 | } |
| 1660 | return rc; |
| 1661 | } |
| 1662 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1663 | static int iwl3945_update_power_cmd(struct iwl_priv *priv, |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1664 | struct iwl_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1665 | { |
| 1666 | int rc = 0, i; |
| 1667 | u8 skip; |
| 1668 | u32 max_sleep = 0; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1669 | struct iwl_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1670 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1671 | struct iwl3945_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1672 | |
| 1673 | if (mode > IWL_POWER_INDEX_5) { |
| 1674 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 1675 | return -1; |
| 1676 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1677 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1678 | |
| 1679 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 1680 | range = &pow_data->pwr_range_0[0]; |
| 1681 | else |
| 1682 | range = &pow_data->pwr_range_1[1]; |
| 1683 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1684 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1685 | |
| 1686 | #ifdef IWL_MAC80211_DISABLE |
| 1687 | if (priv->assoc_network != NULL) { |
| 1688 | unsigned long flags; |
| 1689 | |
| 1690 | period = priv->assoc_network->tim.tim_period; |
| 1691 | } |
| 1692 | #endif /*IWL_MAC80211_DISABLE */ |
| 1693 | skip = range[mode].no_dtim; |
| 1694 | |
| 1695 | if (period == 0) { |
| 1696 | period = 1; |
| 1697 | skip = 0; |
| 1698 | } |
| 1699 | |
| 1700 | if (skip == 0) { |
| 1701 | max_sleep = period; |
| 1702 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1703 | } else { |
| 1704 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 1705 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 1706 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1707 | } |
| 1708 | |
| 1709 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 1710 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 1711 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 1712 | } |
| 1713 | |
| 1714 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 1715 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 1716 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 1717 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 1718 | le32_to_cpu(cmd->sleep_interval[0]), |
| 1719 | le32_to_cpu(cmd->sleep_interval[1]), |
| 1720 | le32_to_cpu(cmd->sleep_interval[2]), |
| 1721 | le32_to_cpu(cmd->sleep_interval[3]), |
| 1722 | le32_to_cpu(cmd->sleep_interval[4])); |
| 1723 | |
| 1724 | return rc; |
| 1725 | } |
| 1726 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1727 | static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1728 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 1729 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1730 | int rc; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1731 | struct iwl_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1732 | |
| 1733 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1734 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1735 | * else user level */ |
| 1736 | switch (mode) { |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1737 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1738 | final_mode = IWL_POWER_INDEX_3; |
| 1739 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1740 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1741 | final_mode = IWL_POWER_MODE_CAM; |
| 1742 | break; |
| 1743 | default: |
| 1744 | final_mode = mode; |
| 1745 | break; |
| 1746 | } |
| 1747 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1748 | iwl3945_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1749 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1750 | /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */ |
| 1751 | rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, |
| 1752 | sizeof(struct iwl3945_powertable_cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1753 | |
| 1754 | if (final_mode == IWL_POWER_MODE_CAM) |
| 1755 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 1756 | else |
| 1757 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 1758 | |
| 1759 | return rc; |
| 1760 | } |
| 1761 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1762 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1763 | * iwl3945_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1764 | * |
| 1765 | * NOTE: priv->mutex is not required before calling this function |
| 1766 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1767 | static int iwl3945_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1768 | { |
| 1769 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1770 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1771 | return 0; |
| 1772 | } |
| 1773 | |
| 1774 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1775 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1776 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 1777 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1778 | queue_work(priv->workqueue, &priv->abort_scan); |
| 1779 | |
| 1780 | } else |
| 1781 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 1782 | |
| 1783 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1784 | } |
| 1785 | |
| 1786 | return 0; |
| 1787 | } |
| 1788 | |
| 1789 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1790 | * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1791 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 1792 | * |
| 1793 | * NOTE: priv->mutex must be held before calling this function |
| 1794 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1795 | static int iwl3945_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1796 | { |
| 1797 | unsigned long now = jiffies; |
| 1798 | int ret; |
| 1799 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1800 | ret = iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1801 | if (ret && ms) { |
| 1802 | mutex_unlock(&priv->mutex); |
| 1803 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 1804 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1805 | msleep(1); |
| 1806 | mutex_lock(&priv->mutex); |
| 1807 | |
| 1808 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1809 | } |
| 1810 | |
| 1811 | return ret; |
| 1812 | } |
| 1813 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1814 | #define MAX_UCODE_BEACON_INTERVAL 1024 |
| 1815 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1816 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1817 | static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1818 | { |
| 1819 | u16 new_val = 0; |
| 1820 | u16 beacon_factor = 0; |
| 1821 | |
| 1822 | beacon_factor = |
| 1823 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1824 | / MAX_UCODE_BEACON_INTERVAL; |
| 1825 | new_val = beacon_val / beacon_factor; |
| 1826 | |
| 1827 | return cpu_to_le16(new_val); |
| 1828 | } |
| 1829 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1830 | static void iwl3945_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1831 | { |
| 1832 | u64 interval_tm_unit; |
| 1833 | u64 tsf, result; |
| 1834 | unsigned long flags; |
| 1835 | struct ieee80211_conf *conf = NULL; |
| 1836 | u16 beacon_int = 0; |
| 1837 | |
| 1838 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1839 | |
| 1840 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1841 | priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1842 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1843 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1844 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1845 | |
| 1846 | beacon_int = priv->beacon_int; |
| 1847 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1848 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1849 | if (priv->iw_mode == NL80211_IFTYPE_STATION) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1850 | if (beacon_int == 0) { |
| 1851 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1852 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1853 | } else { |
| 1854 | priv->rxon_timing.beacon_interval = |
| 1855 | cpu_to_le16(beacon_int); |
| 1856 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1857 | iwl3945_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1858 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1859 | } |
| 1860 | |
| 1861 | priv->rxon_timing.atim_window = 0; |
| 1862 | } else { |
| 1863 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1864 | iwl3945_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1865 | /* TODO: we need to get atim_window from upper stack |
| 1866 | * for now we set to 0 */ |
| 1867 | priv->rxon_timing.atim_window = 0; |
| 1868 | } |
| 1869 | |
| 1870 | interval_tm_unit = |
| 1871 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1872 | result = do_div(tsf, interval_tm_unit); |
| 1873 | priv->rxon_timing.beacon_init_val = |
| 1874 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1875 | |
| 1876 | IWL_DEBUG_ASSOC |
| 1877 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1878 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1879 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1880 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1881 | } |
| 1882 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1883 | static int iwl3945_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1884 | { |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 1885 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1886 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1887 | return -EIO; |
| 1888 | } |
| 1889 | |
| 1890 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1891 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1892 | return -EAGAIN; |
| 1893 | } |
| 1894 | |
| 1895 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1896 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1897 | "Queuing.\n"); |
| 1898 | return -EAGAIN; |
| 1899 | } |
| 1900 | |
| 1901 | IWL_DEBUG_INFO("Starting scan...\n"); |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 1902 | if (priv->cfg->sku & IWL_SKU_G) |
| 1903 | priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ); |
| 1904 | if (priv->cfg->sku & IWL_SKU_A) |
| 1905 | priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1906 | set_bit(STATUS_SCANNING, &priv->status); |
| 1907 | priv->scan_start = jiffies; |
| 1908 | priv->scan_pass_start = priv->scan_start; |
| 1909 | |
| 1910 | queue_work(priv->workqueue, &priv->request_scan); |
| 1911 | |
| 1912 | return 0; |
| 1913 | } |
| 1914 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1915 | 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] | 1916 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1917 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1918 | |
| 1919 | if (hw_decrypt) |
| 1920 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 1921 | else |
| 1922 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 1923 | |
| 1924 | return 0; |
| 1925 | } |
| 1926 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1927 | static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1928 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1929 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1930 | if (band == IEEE80211_BAND_5GHZ) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1931 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1932 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1933 | | RXON_FLG_CCK_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1934 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1935 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1936 | /* Copied from iwl3945_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1937 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1938 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1939 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1940 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1941 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1942 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1943 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1944 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1945 | priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1946 | priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1947 | priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1952 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1953 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1954 | static void iwl3945_connection_init_rx_config(struct iwl_priv *priv, |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1955 | int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1956 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 1957 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1958 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1959 | memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1960 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 1961 | switch (mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1962 | case NL80211_IFTYPE_AP: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1963 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1964 | break; |
| 1965 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1966 | case NL80211_IFTYPE_STATION: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1967 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1968 | priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1969 | break; |
| 1970 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1971 | case NL80211_IFTYPE_ADHOC: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1972 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1973 | priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1974 | priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1975 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1976 | break; |
| 1977 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1978 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1979 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1980 | priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1981 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1982 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1983 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1984 | IWL_ERR(priv, "Unsupported interface type %d\n", mode); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1985 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | #if 0 |
| 1989 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1990 | * that */ |
| 1991 | if (!hw_to_local(priv->hw)->short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1992 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1993 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1994 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1995 | #endif |
| 1996 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1997 | ch_info = iwl3945_get_channel_info(priv, priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1998 | le16_to_cpu(priv->active39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1999 | |
| 2000 | if (!ch_info) |
| 2001 | ch_info = &priv->channel_info[0]; |
| 2002 | |
| 2003 | /* |
| 2004 | * in some case A channels are all non IBSS |
| 2005 | * in this case force B/G channel |
| 2006 | */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 2007 | if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2008 | ch_info = &priv->channel_info[0]; |
| 2009 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2010 | priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2011 | if (is_channel_a_band(ch_info)) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2012 | priv->band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2013 | else |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2014 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2015 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2016 | iwl3945_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2017 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2018 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2019 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2020 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2021 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2022 | } |
| 2023 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2024 | static int iwl3945_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2025 | { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2026 | if (mode == NL80211_IFTYPE_ADHOC) { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2027 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2028 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2029 | ch_info = iwl3945_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2030 | priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2031 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2032 | |
| 2033 | if (!ch_info || !is_channel_ibss(ch_info)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2034 | IWL_ERR(priv, "channel %d not IBSS channel\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2035 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2036 | return -EINVAL; |
| 2037 | } |
| 2038 | } |
| 2039 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 2040 | iwl3945_connection_init_rx_config(priv, mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2041 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2042 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2043 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2044 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2045 | /* don't commit rxon if rf-kill is on*/ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2046 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2047 | return -EAGAIN; |
| 2048 | |
| 2049 | cancel_delayed_work(&priv->scan_check); |
| 2050 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2051 | IWL_WARN(priv, "Aborted scan still in progress after 100ms\n"); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2052 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2053 | return -EAGAIN; |
| 2054 | } |
| 2055 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2056 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2057 | |
| 2058 | return 0; |
| 2059 | } |
| 2060 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2061 | static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2062 | struct ieee80211_tx_info *info, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2063 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2064 | struct sk_buff *skb_frag, |
| 2065 | int last_frag) |
| 2066 | { |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 2067 | struct iwl3945_hw_key *keyinfo = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2068 | &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2069 | |
| 2070 | switch (keyinfo->alg) { |
| 2071 | case ALG_CCMP: |
| 2072 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2073 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2074 | IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2075 | break; |
| 2076 | |
| 2077 | case ALG_TKIP: |
| 2078 | #if 0 |
| 2079 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2080 | |
| 2081 | if (last_frag) |
| 2082 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2083 | 8); |
| 2084 | else |
| 2085 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2086 | #endif |
| 2087 | break; |
| 2088 | |
| 2089 | case ALG_WEP: |
| 2090 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2091 | (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] | 2092 | |
| 2093 | if (keyinfo->keylen == 13) |
| 2094 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2095 | |
| 2096 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2097 | |
| 2098 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2099 | "with key %d\n", info->control.hw_key->hw_key_idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2100 | break; |
| 2101 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2102 | default: |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2103 | IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2104 | break; |
| 2105 | } |
| 2106 | } |
| 2107 | |
| 2108 | /* |
| 2109 | * handle build REPLY_TX command notification. |
| 2110 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2111 | static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2112 | struct iwl_cmd *cmd, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2113 | struct ieee80211_tx_info *info, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2114 | struct ieee80211_hdr *hdr, |
| 2115 | int is_unicast, u8 std_id) |
| 2116 | { |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2117 | __le16 fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2118 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2119 | u8 rc_flags = info->control.rates[0].flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2120 | |
| 2121 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2122 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2123 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2124 | if (ieee80211_is_mgmt(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2125 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2126 | if (ieee80211_is_probe_resp(fc) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2127 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2128 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2129 | } else { |
| 2130 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2131 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2132 | } |
| 2133 | |
| 2134 | cmd->cmd.tx.sta_id = std_id; |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2135 | if (ieee80211_has_morefrags(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2136 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2137 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2138 | if (ieee80211_is_data_qos(fc)) { |
| 2139 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2140 | cmd->cmd.tx.tid_tspec = qc[0] & 0xf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2141 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2142 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2143 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2144 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2145 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2146 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2147 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2148 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2149 | } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2150 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2151 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2152 | } |
| 2153 | |
| 2154 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2155 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2156 | |
| 2157 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2158 | if (ieee80211_is_mgmt(fc)) { |
| 2159 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2160 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2161 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2162 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2163 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2164 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2165 | #ifdef CONFIG_IWL3945_LEDS |
| 2166 | priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len); |
| 2167 | #endif |
| 2168 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2169 | |
| 2170 | cmd->cmd.tx.driver_txop = 0; |
| 2171 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2172 | cmd->cmd.tx.next_frame_len = 0; |
| 2173 | } |
| 2174 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2175 | /** |
| 2176 | * iwl3945_get_sta_id - Find station's index within station table |
| 2177 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2178 | 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] | 2179 | { |
| 2180 | int sta_id; |
| 2181 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2182 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2183 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2184 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2185 | is_multicast_ether_addr(hdr->addr1)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2186 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2187 | |
| 2188 | switch (priv->iw_mode) { |
| 2189 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2190 | /* If we are a client station in a BSS network, use the special |
| 2191 | * AP station entry (that's the only station we communicate with) */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2192 | case NL80211_IFTYPE_STATION: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2193 | return IWL_AP_ID; |
| 2194 | |
| 2195 | /* If we are an AP, then find the station, or use BCAST */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2196 | case NL80211_IFTYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2197 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2198 | if (sta_id != IWL_INVALID_STATION) |
| 2199 | return sta_id; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2200 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2201 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2202 | /* If this frame is going out to an IBSS network, find the station, |
| 2203 | * or create a new station table entry */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2204 | case NL80211_IFTYPE_ADHOC: { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2205 | /* Create new station table entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2206 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2207 | if (sta_id != IWL_INVALID_STATION) |
| 2208 | return sta_id; |
| 2209 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2210 | sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2211 | |
| 2212 | if (sta_id != IWL_INVALID_STATION) |
| 2213 | return sta_id; |
| 2214 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2215 | IWL_DEBUG_DROP("Station %pM not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2216 | "Defaulting to broadcast...\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2217 | hdr->addr1); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2218 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2219 | return priv->hw_params.bcast_sta_id; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2220 | } |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2221 | /* If we are in monitor mode, use BCAST. This is required for |
| 2222 | * packet injection. */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2223 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2224 | return priv->hw_params.bcast_sta_id; |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2225 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2226 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2227 | IWL_WARN(priv, "Unknown mode of operation: %d\n", |
| 2228 | priv->iw_mode); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2229 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2230 | } |
| 2231 | } |
| 2232 | |
| 2233 | /* |
| 2234 | * start REPLY_TX command process |
| 2235 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2236 | 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] | 2237 | { |
| 2238 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2239 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2240 | struct iwl3945_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2241 | u32 *control_flags; |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 2242 | int txq_id = skb_get_queue_mapping(skb); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2243 | struct iwl3945_tx_queue *txq = NULL; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2244 | struct iwl_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2245 | dma_addr_t phys_addr; |
| 2246 | dma_addr_t txcmd_phys; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2247 | struct iwl_cmd *out_cmd = NULL; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2248 | u16 len, idx, len_org, hdr_len; |
| 2249 | u8 id; |
| 2250 | u8 unicast; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2251 | u8 sta_id; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2252 | u8 tid = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2253 | u16 seq_number = 0; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2254 | __le16 fc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2255 | u8 wait_write_ptr = 0; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2256 | u8 *qc = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2257 | unsigned long flags; |
| 2258 | int rc; |
| 2259 | |
| 2260 | spin_lock_irqsave(&priv->lock, flags); |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2261 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2262 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2263 | goto drop_unlock; |
| 2264 | } |
| 2265 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2266 | 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] | 2267 | IWL_ERR(priv, "ERROR: No TX rate available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2268 | goto drop_unlock; |
| 2269 | } |
| 2270 | |
| 2271 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2272 | id = 0; |
| 2273 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2274 | fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2275 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2276 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2277 | if (ieee80211_is_auth(fc)) |
| 2278 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2279 | else if (ieee80211_is_assoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2280 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2281 | else if (ieee80211_is_reassoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2282 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2283 | #endif |
| 2284 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2285 | /* drop all data frame if we are not associated */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2286 | if (ieee80211_is_data(fc) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2287 | (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2288 | (!iwl3945_is_associated(priv) || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2289 | ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2290 | IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2291 | goto drop_unlock; |
| 2292 | } |
| 2293 | |
| 2294 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2295 | |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2296 | hdr_len = ieee80211_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2297 | |
| 2298 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2299 | sta_id = iwl3945_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2300 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2301 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n", |
| 2302 | hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2303 | goto drop; |
| 2304 | } |
| 2305 | |
| 2306 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2307 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2308 | if (ieee80211_is_data_qos(fc)) { |
| 2309 | qc = ieee80211_get_qos_ctl(hdr); |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2310 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2311 | seq_number = priv->stations_39[sta_id].tid[tid].seq_number & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2312 | IEEE80211_SCTL_SEQ; |
| 2313 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2314 | (hdr->seq_ctrl & |
| 2315 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2316 | seq_number += 0x10; |
| 2317 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2318 | |
| 2319 | /* Descriptor for chosen Tx queue */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2320 | txq = &priv->txq39[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2321 | q = &txq->q; |
| 2322 | |
| 2323 | spin_lock_irqsave(&priv->lock, flags); |
| 2324 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2325 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2326 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2327 | memset(tfd, 0, sizeof(*tfd)); |
| 2328 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2329 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2330 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2331 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2332 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2333 | txq->txb[q->write_ptr].skb[0] = skb; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2334 | |
| 2335 | /* Init first empty entry in queue's array of Tx/cmd buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2336 | out_cmd = &txq->cmd[idx]; |
| 2337 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2338 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2339 | |
| 2340 | /* |
| 2341 | * Set up the Tx-command (not MAC!) header. |
| 2342 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2343 | * after Tx, uCode's Tx response will return this value so driver can |
| 2344 | * locate the frame within the tx queue and do post-tx processing. |
| 2345 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2346 | out_cmd->hdr.cmd = REPLY_TX; |
| 2347 | 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] | 2348 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2349 | |
| 2350 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2351 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 2352 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2353 | /* |
| 2354 | * Use the first empty entry in this queue's command buffer array |
| 2355 | * to contain the Tx command and MAC header concatenated together |
| 2356 | * (payload data will be in another buffer). |
| 2357 | * Size of this varies, due to varying MAC header length. |
| 2358 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2359 | * of the MAC header (device reads on dword boundaries). |
| 2360 | * We'll tell device about this padding later. |
| 2361 | */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2362 | len = sizeof(struct iwl3945_tx_cmd) + |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2363 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2364 | |
| 2365 | len_org = len; |
| 2366 | len = (len + 3) & ~3; |
| 2367 | |
| 2368 | if (len_org != len) |
| 2369 | len_org = 1; |
| 2370 | else |
| 2371 | len_org = 0; |
| 2372 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2373 | /* Physical address of this Tx command's header (not MAC header!), |
| 2374 | * within command buffer array. */ |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2375 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx + |
| 2376 | offsetof(struct iwl_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2377 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2378 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2379 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2380 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2381 | |
Johannes Berg | d0f0980 | 2008-07-29 11:32:07 +0200 | [diff] [blame] | 2382 | if (info->control.hw_key) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2383 | iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2384 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2385 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2386 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2387 | len = skb->len - hdr_len; |
| 2388 | if (len) { |
| 2389 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2390 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2391 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2394 | if (!len) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2395 | /* If there is no payload, then we use only one Tx buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2396 | *control_flags = TFD_CTL_COUNT_SET(1); |
| 2397 | else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2398 | /* Else use 2 buffers. |
| 2399 | * Tell 3945 about any padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2400 | *control_flags = TFD_CTL_COUNT_SET(2) | |
| 2401 | TFD_CTL_PAD_SET(U32_PAD(len)); |
| 2402 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2403 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2404 | len = (u16)skb->len; |
| 2405 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 2406 | |
| 2407 | /* TODO need this for burst mode later on */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2408 | iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, unicast, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2409 | |
| 2410 | /* set is_hcca to 0; it probably will never be implemented */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2411 | 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] | 2412 | |
| 2413 | out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; |
| 2414 | out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; |
| 2415 | |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2416 | if (!ieee80211_has_morefrags(hdr->frame_control)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2417 | txq->need_update = 1; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 2418 | if (qc) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2419 | priv->stations_39[sta_id].tid[tid].seq_number = seq_number; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2420 | } else { |
| 2421 | wait_write_ptr = 1; |
| 2422 | txq->need_update = 0; |
| 2423 | } |
| 2424 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2425 | iwl_print_hex_dump(priv, IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2426 | sizeof(out_cmd->cmd.tx)); |
| 2427 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2428 | iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2429 | ieee80211_hdrlen(fc)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2430 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2431 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2432 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2433 | rc = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2434 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2435 | |
| 2436 | if (rc) |
| 2437 | return rc; |
| 2438 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2439 | if ((iwl_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2440 | && priv->mac80211_registered) { |
| 2441 | if (wait_write_ptr) { |
| 2442 | spin_lock_irqsave(&priv->lock, flags); |
| 2443 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2444 | iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2445 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2446 | } |
| 2447 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 2448 | ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | return 0; |
| 2452 | |
| 2453 | drop_unlock: |
| 2454 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2455 | drop: |
| 2456 | return -1; |
| 2457 | } |
| 2458 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2459 | static void iwl3945_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2460 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2461 | const struct ieee80211_supported_band *sband = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2462 | struct ieee80211_rate *rate; |
| 2463 | int i; |
| 2464 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2465 | sband = iwl3945_get_band(priv, priv->band); |
| 2466 | if (!sband) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2467 | 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] | 2468 | return; |
| 2469 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2470 | |
| 2471 | priv->active_rate = 0; |
| 2472 | priv->active_rate_basic = 0; |
| 2473 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2474 | IWL_DEBUG_RATE("Setting rates for %s GHz\n", |
| 2475 | sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2476 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2477 | for (i = 0; i < sband->n_bitrates; i++) { |
| 2478 | rate = &sband->bitrates[i]; |
| 2479 | if ((rate->hw_value < IWL_RATE_COUNT) && |
| 2480 | !(rate->flags & IEEE80211_CHAN_DISABLED)) { |
| 2481 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n", |
| 2482 | rate->hw_value, iwl3945_rates[rate->hw_value].plcp); |
| 2483 | priv->active_rate |= (1 << rate->hw_value); |
| 2484 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2488 | priv->active_rate, priv->active_rate_basic); |
| 2489 | |
| 2490 | /* |
| 2491 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2492 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2493 | * OFDM |
| 2494 | */ |
| 2495 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2496 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2497 | ((priv->active_rate_basic & |
| 2498 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2499 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2500 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2501 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2502 | |
| 2503 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2504 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2505 | ((priv->active_rate_basic & |
| 2506 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2507 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2508 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2509 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2510 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2511 | } |
| 2512 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2513 | 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] | 2514 | { |
| 2515 | unsigned long flags; |
| 2516 | |
| 2517 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2518 | return; |
| 2519 | |
| 2520 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2521 | disable_radio ? "OFF" : "ON"); |
| 2522 | |
| 2523 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2524 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2525 | /* FIXME: This is a workaround for AP */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2526 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2527 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2528 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2529 | CSR_UCODE_SW_BIT_RFKILL); |
| 2530 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2531 | iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2532 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2533 | } |
| 2534 | return; |
| 2535 | } |
| 2536 | |
| 2537 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2538 | 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] | 2539 | |
| 2540 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2541 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2542 | |
| 2543 | /* wake up ucode */ |
| 2544 | msleep(10); |
| 2545 | |
| 2546 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2547 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2548 | if (!iwl_grab_nic_access(priv)) |
| 2549 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2550 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2551 | |
| 2552 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2553 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2554 | "disabled by HW switch\n"); |
| 2555 | return; |
| 2556 | } |
| 2557 | |
Zhu Yi | 808e72a | 2008-06-12 09:47:17 +0800 | [diff] [blame] | 2558 | if (priv->is_open) |
| 2559 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2560 | return; |
| 2561 | } |
| 2562 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2563 | 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] | 2564 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 2565 | { |
| 2566 | u16 fc = |
| 2567 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 2568 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2569 | if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2570 | return; |
| 2571 | |
| 2572 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 2573 | return; |
| 2574 | |
| 2575 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 2576 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2577 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2578 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2579 | RX_RES_STATUS_BAD_ICV_MIC) |
| 2580 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 2581 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 2582 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2583 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2584 | RX_RES_STATUS_DECRYPT_OK) { |
| 2585 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 2586 | stats->flag |= RX_FLAG_DECRYPTED; |
| 2587 | } |
| 2588 | break; |
| 2589 | |
| 2590 | default: |
| 2591 | break; |
| 2592 | } |
| 2593 | } |
| 2594 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2595 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2596 | |
| 2597 | #include "iwl-spectrum.h" |
| 2598 | |
| 2599 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 2600 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 2601 | #define TIME_UNIT 1024 |
| 2602 | |
| 2603 | /* |
| 2604 | * extended beacon time format |
| 2605 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 2606 | * the high 1 byte is the beacon counts |
| 2607 | * the lower 3 bytes is the time in usec within one beacon interval |
| 2608 | */ |
| 2609 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2610 | static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2611 | { |
| 2612 | u32 quot; |
| 2613 | u32 rem; |
| 2614 | u32 interval = beacon_interval * 1024; |
| 2615 | |
| 2616 | if (!interval || !usec) |
| 2617 | return 0; |
| 2618 | |
| 2619 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 2620 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 2621 | |
| 2622 | return (quot << 24) + rem; |
| 2623 | } |
| 2624 | |
| 2625 | /* base is usually what we get from ucode with each received frame, |
| 2626 | * the same as HW timer counter counting down |
| 2627 | */ |
| 2628 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2629 | 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] | 2630 | { |
| 2631 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 2632 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 2633 | u32 interval = beacon_interval * TIME_UNIT; |
| 2634 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 2635 | (addon & BEACON_TIME_MASK_HIGH); |
| 2636 | |
| 2637 | if (base_low > addon_low) |
| 2638 | res += base_low - addon_low; |
| 2639 | else if (base_low < addon_low) { |
| 2640 | res += interval + base_low - addon_low; |
| 2641 | res += (1 << 24); |
| 2642 | } else |
| 2643 | res += (1 << 24); |
| 2644 | |
| 2645 | return cpu_to_le32(res); |
| 2646 | } |
| 2647 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2648 | static int iwl3945_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2649 | struct ieee80211_measurement_params *params, |
| 2650 | u8 type) |
| 2651 | { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2652 | struct iwl_spectrum_cmd spectrum; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2653 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2654 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2655 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 2656 | .data = (void *)&spectrum, |
| 2657 | .meta.flags = CMD_WANT_SKB, |
| 2658 | }; |
| 2659 | u32 add_time = le64_to_cpu(params->start_time); |
| 2660 | int rc; |
| 2661 | int spectrum_resp_status; |
| 2662 | int duration = le16_to_cpu(params->duration); |
| 2663 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2664 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2665 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2666 | iwl3945_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2667 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 2668 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2669 | |
| 2670 | memset(&spectrum, 0, sizeof(spectrum)); |
| 2671 | |
| 2672 | spectrum.channel_count = cpu_to_le16(1); |
| 2673 | spectrum.flags = |
| 2674 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 2675 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 2676 | cmd.len = sizeof(spectrum); |
| 2677 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 2678 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2679 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2680 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2681 | iwl3945_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2682 | add_time, |
| 2683 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2684 | else |
| 2685 | spectrum.start_time = 0; |
| 2686 | |
| 2687 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 2688 | spectrum.channels[0].channel = params->channel; |
| 2689 | spectrum.channels[0].type = type; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2690 | if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2691 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 2692 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 2693 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2694 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2695 | if (rc) |
| 2696 | return rc; |
| 2697 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2698 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2699 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2700 | IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2701 | rc = -EIO; |
| 2702 | } |
| 2703 | |
| 2704 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 2705 | switch (spectrum_resp_status) { |
| 2706 | case 0: /* Command will be handled */ |
| 2707 | if (res->u.spectrum.id != 0xff) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2708 | IWL_DEBUG_INFO("Replaced existing measurement: %d\n", |
| 2709 | res->u.spectrum.id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2710 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 2711 | } |
| 2712 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 2713 | rc = 0; |
| 2714 | break; |
| 2715 | |
| 2716 | case 1: /* Command will not be handled */ |
| 2717 | rc = -EAGAIN; |
| 2718 | break; |
| 2719 | } |
| 2720 | |
| 2721 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 2722 | |
| 2723 | return rc; |
| 2724 | } |
| 2725 | #endif |
| 2726 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2727 | static void iwl3945_rx_reply_alive(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 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2730 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 2731 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2732 | struct delayed_work *pwork; |
| 2733 | |
| 2734 | palive = &pkt->u.alive_frame; |
| 2735 | |
| 2736 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 2737 | "0x%01X 0x%01X\n", |
| 2738 | palive->is_valid, palive->ver_type, |
| 2739 | palive->ver_subtype); |
| 2740 | |
| 2741 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 2742 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2743 | memcpy(&priv->card_alive_init, &pkt->u.alive_frame, |
| 2744 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2745 | pwork = &priv->init_alive_start; |
| 2746 | } else { |
| 2747 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2748 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2749 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2750 | pwork = &priv->alive_start; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2751 | iwl3945_disable_events(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | /* We delay the ALIVE response by 5ms to |
| 2755 | * give the HW RF Kill time to activate... */ |
| 2756 | if (palive->is_valid == UCODE_VALID_OK) |
| 2757 | queue_delayed_work(priv->workqueue, pwork, |
| 2758 | msecs_to_jiffies(5)); |
| 2759 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2760 | IWL_WARN(priv, "uCode did not respond OK.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2761 | } |
| 2762 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2763 | static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2764 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2765 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2766 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2767 | |
| 2768 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 2769 | return; |
| 2770 | } |
| 2771 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2772 | static void iwl3945_rx_reply_error(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2773 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2774 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2775 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2776 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2777 | IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2778 | "seq 0x%04X ser 0x%08X\n", |
| 2779 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 2780 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 2781 | pkt->u.err_resp.cmd_id, |
| 2782 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 2783 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 2784 | } |
| 2785 | |
| 2786 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2787 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2788 | 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] | 2789 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2790 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2791 | struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2792 | struct iwl_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2793 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 2794 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 2795 | rxon->channel = csa->channel; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2796 | priv->staging39_rxon.channel = csa->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2799 | static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2800 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2801 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2802 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2803 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2804 | struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2805 | |
| 2806 | if (!report->state) { |
| 2807 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 2808 | "Spectrum Measure Notification: Start\n"); |
| 2809 | return; |
| 2810 | } |
| 2811 | |
| 2812 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2813 | priv->measurement_status |= MEASUREMENT_READY; |
| 2814 | #endif |
| 2815 | } |
| 2816 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2817 | static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2818 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2819 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2820 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2821 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2822 | struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2823 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2824 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2825 | #endif |
| 2826 | } |
| 2827 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2828 | static void iwl3945_rx_pm_debug_statistics_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; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2832 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2833 | "notification for %s:\n", |
| 2834 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2835 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, |
| 2836 | le32_to_cpu(pkt->len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2839 | static void iwl3945_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2840 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2841 | struct iwl_priv *priv = |
| 2842 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2843 | struct sk_buff *beacon; |
| 2844 | |
| 2845 | /* 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] | 2846 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2847 | |
| 2848 | if (!beacon) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2849 | IWL_ERR(priv, "update beacon failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2850 | return; |
| 2851 | } |
| 2852 | |
| 2853 | mutex_lock(&priv->mutex); |
| 2854 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2855 | if (priv->ibss_beacon) |
| 2856 | dev_kfree_skb(priv->ibss_beacon); |
| 2857 | |
| 2858 | priv->ibss_beacon = beacon; |
| 2859 | mutex_unlock(&priv->mutex); |
| 2860 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2861 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2862 | } |
| 2863 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2864 | static void iwl3945_rx_beacon_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2865 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2866 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2867 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2868 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2869 | struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2870 | u8 rate = beacon->beacon_notify_hdr.rate; |
| 2871 | |
| 2872 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2873 | "tsf %d %d rate %d\n", |
| 2874 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2875 | beacon->beacon_notify_hdr.failure_frame, |
| 2876 | le32_to_cpu(beacon->ibss_mgr_status), |
| 2877 | le32_to_cpu(beacon->high_tsf), |
| 2878 | le32_to_cpu(beacon->low_tsf), rate); |
| 2879 | #endif |
| 2880 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2881 | if ((priv->iw_mode == NL80211_IFTYPE_AP) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2882 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 2883 | queue_work(priv->workqueue, &priv->beacon_update); |
| 2884 | } |
| 2885 | |
| 2886 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2887 | static void iwl3945_rx_reply_scan(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2888 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2889 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2890 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2891 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2892 | struct iwl_scanreq_notification *notif = |
| 2893 | (struct iwl_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2894 | |
| 2895 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 2896 | #endif |
| 2897 | } |
| 2898 | |
| 2899 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2900 | static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2901 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2902 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2903 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2904 | struct iwl_scanstart_notification *notif = |
| 2905 | (struct iwl_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2906 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 2907 | IWL_DEBUG_SCAN("Scan start: " |
| 2908 | "%d [802.11%s] " |
| 2909 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 2910 | notif->channel, |
| 2911 | notif->band ? "bg" : "a", |
| 2912 | notif->tsf_high, |
| 2913 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 2914 | } |
| 2915 | |
| 2916 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2917 | static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2918 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2919 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2920 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2921 | struct iwl_scanresults_notification *notif = |
| 2922 | (struct iwl_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2923 | |
| 2924 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 2925 | "%d [802.11%s] " |
| 2926 | "(TSF: 0x%08X:%08X) - %d " |
| 2927 | "elapsed=%lu usec (%dms since last)\n", |
| 2928 | notif->channel, |
| 2929 | notif->band ? "bg" : "a", |
| 2930 | le32_to_cpu(notif->tsf_high), |
| 2931 | le32_to_cpu(notif->tsf_low), |
| 2932 | le32_to_cpu(notif->statistics[0]), |
| 2933 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 2934 | jiffies_to_msecs(elapsed_jiffies |
| 2935 | (priv->last_scan_jiffies, jiffies))); |
| 2936 | |
| 2937 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2938 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2942 | static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2943 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2944 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2945 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2946 | struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2947 | |
| 2948 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 2949 | scan_notif->scanned_channels, |
| 2950 | scan_notif->tsf_low, |
| 2951 | scan_notif->tsf_high, scan_notif->status); |
| 2952 | |
| 2953 | /* The HW is no longer scanning */ |
| 2954 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 2955 | |
| 2956 | /* The scan completion notification came in, so kill that timer... */ |
| 2957 | cancel_delayed_work(&priv->scan_check); |
| 2958 | |
| 2959 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 2960 | (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ? |
| 2961 | "2.4" : "5.2", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2962 | jiffies_to_msecs(elapsed_jiffies |
| 2963 | (priv->scan_pass_start, jiffies))); |
| 2964 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 2965 | /* Remove this scanned band from the list of pending |
| 2966 | * bands to scan, band G precedes A in order of scanning |
| 2967 | * as seen in iwl3945_bg_request_scan */ |
| 2968 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) |
| 2969 | priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ); |
| 2970 | else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) |
| 2971 | priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2972 | |
| 2973 | /* If a request to abort was given, or the scan did not succeed |
| 2974 | * then we reset the scan state machine and terminate, |
| 2975 | * re-queuing another scan if one has been requested */ |
| 2976 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2977 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 2978 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2979 | } else { |
| 2980 | /* If there are more bands on this scan pass reschedule */ |
| 2981 | if (priv->scan_bands > 0) |
| 2982 | goto reschedule; |
| 2983 | } |
| 2984 | |
| 2985 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2986 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2987 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 2988 | |
| 2989 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2990 | |
| 2991 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 2992 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 2993 | |
| 2994 | queue_work(priv->workqueue, &priv->scan_completed); |
| 2995 | |
| 2996 | return; |
| 2997 | |
| 2998 | reschedule: |
| 2999 | priv->scan_pass_start = jiffies; |
| 3000 | queue_work(priv->workqueue, &priv->request_scan); |
| 3001 | } |
| 3002 | |
| 3003 | /* Handle notification from uCode that card's power state is changing |
| 3004 | * due to software, hardware, or critical temperature RFKILL */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3005 | static void iwl3945_rx_card_state_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3006 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3007 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3008 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3009 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 3010 | unsigned long status = priv->status; |
| 3011 | |
| 3012 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 3013 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3014 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 3015 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3016 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3017 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3018 | |
| 3019 | if (flags & HW_CARD_DISABLED) |
| 3020 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3021 | else |
| 3022 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3023 | |
| 3024 | |
| 3025 | if (flags & SW_CARD_DISABLED) |
| 3026 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3027 | else |
| 3028 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3029 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3030 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3031 | |
| 3032 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 3033 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 3034 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 3035 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 3036 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3037 | else |
| 3038 | wake_up_interruptible(&priv->wait_command_queue); |
| 3039 | } |
| 3040 | |
| 3041 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3042 | * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3043 | * |
| 3044 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3045 | * to the host. |
| 3046 | * |
| 3047 | * This function chains into the hardware specific files for them to setup |
| 3048 | * any hardware specific handlers as well. |
| 3049 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3050 | static void iwl3945_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3051 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3052 | priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive; |
| 3053 | priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta; |
| 3054 | priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error; |
| 3055 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3056 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3057 | iwl3945_rx_spectrum_measure_notif; |
| 3058 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3059 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3060 | iwl3945_rx_pm_debug_statistics_notif; |
| 3061 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3062 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3063 | /* |
| 3064 | * The same handler is used for both the REPLY to a discrete |
| 3065 | * statistics request from the host as well as for the periodic |
| 3066 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3067 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3068 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics; |
| 3069 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3070 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3071 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan; |
| 3072 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3073 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3074 | iwl3945_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3075 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3076 | iwl3945_rx_scan_complete_notif; |
| 3077 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3078 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3079 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3080 | iwl3945_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | /** |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3084 | * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries |
| 3085 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3086 | * need to be reclaimed. |
| 3087 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3088 | static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3089 | int txq_id, int index) |
| 3090 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3091 | struct iwl3945_tx_queue *txq = &priv->txq39[txq_id]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 3092 | struct iwl_queue *q = &txq->q; |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3093 | int nfreed = 0; |
| 3094 | |
| 3095 | if ((index >= q->n_bd) || (iwl3945_x2_queue_used(q, index) == 0)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3096 | 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] | 3097 | "is out of range [0-%d] %d %d.\n", txq_id, |
| 3098 | index, q->n_bd, q->write_ptr, q->read_ptr); |
| 3099 | return; |
| 3100 | } |
| 3101 | |
| 3102 | for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index; |
| 3103 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
| 3104 | if (nfreed > 1) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3105 | IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3106 | q->write_ptr, q->read_ptr); |
| 3107 | queue_work(priv->workqueue, &priv->restart); |
| 3108 | break; |
| 3109 | } |
| 3110 | nfreed++; |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | |
| 3115 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3116 | * 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] | 3117 | * @rxb: Rx buffer to reclaim |
| 3118 | * |
| 3119 | * If an Rx buffer has an async callback associated with it the callback |
| 3120 | * will be executed. The attached skb (if present) will only be freed |
| 3121 | * if the callback returns 1 |
| 3122 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3123 | static void iwl3945_tx_cmd_complete(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3124 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3125 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3126 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3127 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3128 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3129 | int index = SEQ_TO_INDEX(sequence); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 3130 | int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3131 | int cmd_index; |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 3132 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3133 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3134 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3135 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3136 | cmd_index = get_cmd_index(&priv->txq39[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3137 | cmd = &priv->txq39[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3138 | |
| 3139 | /* Input error checking is done when commands are added to queue. */ |
| 3140 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3141 | cmd->meta.source->u.skb = rxb->skb; |
| 3142 | rxb->skb = NULL; |
| 3143 | } else if (cmd->meta.u.callback && |
| 3144 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3145 | rxb->skb = NULL; |
| 3146 | |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3147 | iwl3945_cmd_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3148 | |
| 3149 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3150 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3151 | wake_up_interruptible(&priv->wait_command_queue); |
| 3152 | } |
| 3153 | } |
| 3154 | |
| 3155 | /************************** RX-FUNCTIONS ****************************/ |
| 3156 | /* |
| 3157 | * Rx theory of operation |
| 3158 | * |
| 3159 | * The host allocates 32 DMA target addresses and passes the host address |
| 3160 | * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
| 3161 | * 0 to 31 |
| 3162 | * |
| 3163 | * Rx Queue Indexes |
| 3164 | * The host/firmware share two index registers for managing the Rx buffers. |
| 3165 | * |
| 3166 | * The READ index maps to the first position that the firmware may be writing |
| 3167 | * to -- the driver can read up to (but not including) this position and get |
| 3168 | * good data. |
| 3169 | * The READ index is managed by the firmware once the card is enabled. |
| 3170 | * |
| 3171 | * The WRITE index maps to the last position the driver has read from -- the |
| 3172 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 3173 | * |
| 3174 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 3175 | * WRITE = READ. |
| 3176 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3177 | * 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] | 3178 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 3179 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3180 | * 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] | 3181 | * and fire the RX interrupt. The driver can then query the READ index and |
| 3182 | * process as many packets as possible, moving the WRITE index forward as it |
| 3183 | * resets the Rx queue buffers with new memory. |
| 3184 | * |
| 3185 | * The management in the driver is as follows: |
| 3186 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 3187 | * 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] | 3188 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3189 | * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3190 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 3191 | * 'processed' and 'read' driver indexes as well) |
| 3192 | * + A received packet is processed and handed to the kernel network stack, |
| 3193 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 3194 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 3195 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 3196 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 3197 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 3198 | * |
| 3199 | * |
| 3200 | * Driver sequence: |
| 3201 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3202 | * iwl3945_rx_queue_alloc() Allocates rx_free |
| 3203 | * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3204 | * iwl3945_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3205 | * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3206 | * queue, updates firmware pointers, and updates |
| 3207 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3208 | * are available, schedules iwl3945_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3209 | * |
| 3210 | * -- enable interrupts -- |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3211 | * 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] | 3212 | * READ INDEX, detaching the SKB from the pool. |
| 3213 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3214 | * Calls iwl3945_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3215 | * slots. |
| 3216 | * ... |
| 3217 | * |
| 3218 | */ |
| 3219 | |
| 3220 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3221 | * iwl3945_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3222 | */ |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3223 | static int iwl3945_rx_queue_space(const struct iwl_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3224 | { |
| 3225 | int s = q->read - q->write; |
| 3226 | if (s <= 0) |
| 3227 | s += RX_QUEUE_SIZE; |
| 3228 | /* keep some buffer to not confuse full and empty queue */ |
| 3229 | s -= 2; |
| 3230 | if (s < 0) |
| 3231 | s = 0; |
| 3232 | return s; |
| 3233 | } |
| 3234 | |
| 3235 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3236 | * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3237 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3238 | int iwl3945_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3239 | { |
| 3240 | u32 reg = 0; |
| 3241 | int rc = 0; |
| 3242 | unsigned long flags; |
| 3243 | |
| 3244 | spin_lock_irqsave(&q->lock, flags); |
| 3245 | |
| 3246 | if (q->need_update == 0) |
| 3247 | goto exit_unlock; |
| 3248 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3249 | /* If power-saving is in use, make sure device is awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3250 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3251 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3252 | |
| 3253 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3254 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3255 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3256 | goto exit_unlock; |
| 3257 | } |
| 3258 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3259 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3260 | if (rc) |
| 3261 | goto exit_unlock; |
| 3262 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3263 | /* Device expects a multiple of 8 */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3264 | iwl_write_direct32(priv, FH39_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3265 | q->write & ~0x7); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3266 | iwl_release_nic_access(priv); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3267 | |
| 3268 | /* Else device is assumed to be awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3269 | } else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3270 | /* Device expects a multiple of 8 */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3271 | iwl_write32(priv, FH39_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3272 | |
| 3273 | |
| 3274 | q->need_update = 0; |
| 3275 | |
| 3276 | exit_unlock: |
| 3277 | spin_unlock_irqrestore(&q->lock, flags); |
| 3278 | return rc; |
| 3279 | } |
| 3280 | |
| 3281 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3282 | * 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] | 3283 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3284 | static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3285 | dma_addr_t dma_addr) |
| 3286 | { |
| 3287 | return cpu_to_le32((u32)dma_addr); |
| 3288 | } |
| 3289 | |
| 3290 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3291 | * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3292 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3293 | * 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] | 3294 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3295 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3296 | * |
| 3297 | * This moves the 'write' index forward to catch up with 'processed', and |
| 3298 | * also updates the memory address in the firmware to reference the new |
| 3299 | * target buffer. |
| 3300 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3301 | static int iwl3945_rx_queue_restock(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3302 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3303 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3304 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3305 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3306 | unsigned long flags; |
| 3307 | int write, rc; |
| 3308 | |
| 3309 | spin_lock_irqsave(&rxq->lock, flags); |
| 3310 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3311 | while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3312 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3313 | element = rxq->rx_free.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3314 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3315 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3316 | |
| 3317 | /* Point to Rx buffer via next RBD in circular buffer */ |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3318 | 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] | 3319 | rxq->queue[rxq->write] = rxb; |
| 3320 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 3321 | rxq->free_count--; |
| 3322 | } |
| 3323 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3324 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 3325 | * refill it */ |
| 3326 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 3327 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 3328 | |
| 3329 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3330 | /* If we've added more space for the firmware to place data, tell it. |
| 3331 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3332 | if ((write != (rxq->write & ~0x7)) |
| 3333 | || (abs(rxq->write - rxq->read) > 7)) { |
| 3334 | spin_lock_irqsave(&rxq->lock, flags); |
| 3335 | rxq->need_update = 1; |
| 3336 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3337 | rc = iwl3945_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3338 | if (rc) |
| 3339 | return rc; |
| 3340 | } |
| 3341 | |
| 3342 | return 0; |
| 3343 | } |
| 3344 | |
| 3345 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3346 | * 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] | 3347 | * |
| 3348 | * When moving to rx_free an SKB is allocated for the slot. |
| 3349 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3350 | * Also restock the Rx queue via iwl3945_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3351 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3352 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3353 | static void iwl3945_rx_allocate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3354 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3355 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3356 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3357 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3358 | unsigned long flags; |
| 3359 | spin_lock_irqsave(&rxq->lock, flags); |
| 3360 | while (!list_empty(&rxq->rx_used)) { |
| 3361 | element = rxq->rx_used.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3362 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3363 | |
| 3364 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3365 | rxb->skb = |
| 3366 | alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC); |
| 3367 | if (!rxb->skb) { |
| 3368 | if (net_ratelimit()) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 3369 | IWL_CRIT(priv, ": Can not allocate SKB buffers\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3370 | /* We don't reschedule replenish work here -- we will |
| 3371 | * call the restock method and if it still needs |
| 3372 | * more buffers it will schedule replenish */ |
| 3373 | break; |
| 3374 | } |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 3375 | |
| 3376 | /* If radiotap head is required, reserve some headroom here. |
| 3377 | * The physical head count is a variable rx_stats->phy_count. |
| 3378 | * We reserve 4 bytes here. Plus these extra bytes, the |
| 3379 | * headroom of the physical head should be enough for the |
| 3380 | * radiotap head that iwl3945 supported. See iwl3945_rt. |
| 3381 | */ |
| 3382 | skb_reserve(rxb->skb, 4); |
| 3383 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3384 | priv->alloc_rxb_skb++; |
| 3385 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3386 | |
| 3387 | /* Get physical address of RB/SKB */ |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3388 | rxb->real_dma_addr = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3389 | pci_map_single(priv->pci_dev, rxb->skb->data, |
| 3390 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3391 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 3392 | rxq->free_count++; |
| 3393 | } |
| 3394 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | /* |
| 3398 | * this should be called while priv->lock is locked |
| 3399 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 3400 | static void __iwl3945_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3401 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3402 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3403 | |
| 3404 | iwl3945_rx_allocate(priv); |
| 3405 | iwl3945_rx_queue_restock(priv); |
| 3406 | } |
| 3407 | |
| 3408 | |
| 3409 | void iwl3945_rx_replenish(void *data) |
| 3410 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3411 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3412 | unsigned long flags; |
| 3413 | |
| 3414 | iwl3945_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3415 | |
| 3416 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3417 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3418 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3419 | } |
| 3420 | |
| 3421 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3422 | * If an SKB has been detached, the POOL needs to have its SKB set to NULL |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3423 | * This free routine walks the list of POOL entries and if SKB is set to |
| 3424 | * non NULL it is unmapped and freed |
| 3425 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3426 | static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3427 | { |
| 3428 | int i; |
| 3429 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 3430 | if (rxq->pool[i].skb != NULL) { |
| 3431 | pci_unmap_single(priv->pci_dev, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3432 | rxq->pool[i].real_dma_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3433 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3434 | dev_kfree_skb(rxq->pool[i].skb); |
| 3435 | } |
| 3436 | } |
| 3437 | |
| 3438 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 3439 | rxq->dma_addr); |
| 3440 | rxq->bd = NULL; |
| 3441 | } |
| 3442 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3443 | int iwl3945_rx_queue_alloc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3444 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3445 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3446 | struct pci_dev *dev = priv->pci_dev; |
| 3447 | int i; |
| 3448 | |
| 3449 | spin_lock_init(&rxq->lock); |
| 3450 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3451 | INIT_LIST_HEAD(&rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3452 | |
| 3453 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3454 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 3455 | if (!rxq->bd) |
| 3456 | return -ENOMEM; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3457 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3458 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3459 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 3460 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3461 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3462 | /* Set us so that we have processed and used all buffers, but have |
| 3463 | * not restocked the Rx queue with fresh buffers */ |
| 3464 | rxq->read = rxq->write = 0; |
| 3465 | rxq->free_count = 0; |
| 3466 | rxq->need_update = 0; |
| 3467 | return 0; |
| 3468 | } |
| 3469 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3470 | void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3471 | { |
| 3472 | unsigned long flags; |
| 3473 | int i; |
| 3474 | spin_lock_irqsave(&rxq->lock, flags); |
| 3475 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3476 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3477 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3478 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3479 | /* In the reset function, these buffers may have been allocated |
| 3480 | * to an SKB, so we need to unmap and free potential storage */ |
| 3481 | if (rxq->pool[i].skb != NULL) { |
| 3482 | pci_unmap_single(priv->pci_dev, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3483 | rxq->pool[i].real_dma_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3484 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3485 | priv->alloc_rxb_skb--; |
| 3486 | dev_kfree_skb(rxq->pool[i].skb); |
| 3487 | rxq->pool[i].skb = NULL; |
| 3488 | } |
| 3489 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3490 | } |
| 3491 | |
| 3492 | /* Set us so that we have processed and used all buffers, but have |
| 3493 | * not restocked the Rx queue with fresh buffers */ |
| 3494 | rxq->read = rxq->write = 0; |
| 3495 | rxq->free_count = 0; |
| 3496 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3497 | } |
| 3498 | |
| 3499 | /* Convert linear signal-to-noise ratio into dB */ |
| 3500 | static u8 ratio2dB[100] = { |
| 3501 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 3502 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 3503 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 3504 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 3505 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 3506 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 3507 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 3508 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 3509 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 3510 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 3511 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 3512 | }; |
| 3513 | |
| 3514 | /* Calculates a relative dB value from a ratio of linear |
| 3515 | * (i.e. not dB) signal levels. |
| 3516 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3517 | int iwl3945_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3518 | { |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3519 | /* 1000:1 or higher just report as 60 dB */ |
| 3520 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3521 | return 60; |
| 3522 | |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3523 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3524 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3525 | if (sig_ratio >= 100) |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 3526 | return 20 + (int)ratio2dB[sig_ratio/10]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3527 | |
| 3528 | /* We shouldn't see this */ |
| 3529 | if (sig_ratio < 1) |
| 3530 | return 0; |
| 3531 | |
| 3532 | /* Use table for ratios 1:1 - 99:1 */ |
| 3533 | return (int)ratio2dB[sig_ratio]; |
| 3534 | } |
| 3535 | |
| 3536 | #define PERFECT_RSSI (-20) /* dBm */ |
| 3537 | #define WORST_RSSI (-95) /* dBm */ |
| 3538 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 3539 | |
| 3540 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 3541 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 3542 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3543 | int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3544 | { |
| 3545 | int sig_qual; |
| 3546 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 3547 | |
| 3548 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 3549 | * as indicator; formula is (signal dbm - noise dbm). |
| 3550 | * SNR at or above 40 is a great signal (100%). |
| 3551 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 3552 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 3553 | if (noise_dbm) { |
| 3554 | if (rssi_dbm - noise_dbm >= 40) |
| 3555 | return 100; |
| 3556 | else if (rssi_dbm < noise_dbm) |
| 3557 | return 0; |
| 3558 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 3559 | |
| 3560 | /* Else use just the signal level. |
| 3561 | * This formula is a least squares fit of data points collected and |
| 3562 | * compared with a reference system that had a percentage (%) display |
| 3563 | * for signal quality. */ |
| 3564 | } else |
| 3565 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 3566 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 3567 | (RSSI_RANGE * RSSI_RANGE); |
| 3568 | |
| 3569 | if (sig_qual > 100) |
| 3570 | sig_qual = 100; |
| 3571 | else if (sig_qual < 1) |
| 3572 | sig_qual = 0; |
| 3573 | |
| 3574 | return sig_qual; |
| 3575 | } |
| 3576 | |
| 3577 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3578 | * iwl3945_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3579 | * |
| 3580 | * Uses the priv->rx_handlers callback function array to invoke |
| 3581 | * the appropriate handlers, including command responses, |
| 3582 | * frame-received notifications, and other notifications. |
| 3583 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3584 | static void iwl3945_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3585 | { |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3586 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3587 | struct iwl_rx_packet *pkt; |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3588 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3589 | u32 r, i; |
| 3590 | int reclaim; |
| 3591 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3592 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 3593 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3594 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3595 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 3596 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3597 | r = iwl3945_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3598 | i = rxq->read; |
| 3599 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3600 | if (iwl3945_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
| 3601 | fill_rx = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3602 | /* Rx interrupt, but nothing sent from uCode */ |
| 3603 | if (i == r) |
| 3604 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 3605 | |
| 3606 | while (i != r) { |
| 3607 | rxb = rxq->queue[i]; |
| 3608 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3609 | /* 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] | 3610 | * then a bug has been introduced in the queue refilling |
| 3611 | * routines -- catch it here */ |
| 3612 | BUG_ON(rxb == NULL); |
| 3613 | |
| 3614 | rxq->queue[i] = NULL; |
| 3615 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3616 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3617 | IWL_RX_BUF_SIZE, |
| 3618 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3619 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3620 | |
| 3621 | /* Reclaim a command buffer only if this packet is a response |
| 3622 | * to a (driver-originated) command. |
| 3623 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3624 | * there is no command buffer to reclaim. |
| 3625 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3626 | * but apparently a few don't get set; catch them here. */ |
| 3627 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 3628 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 3629 | (pkt->hdr.cmd != REPLY_TX); |
| 3630 | |
| 3631 | /* Based on type of command response or notification, |
| 3632 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3633 | * rx_handlers table. See iwl3945_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3634 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3635 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3636 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 3637 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 3638 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 3639 | } else { |
| 3640 | /* No handling needed */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3641 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3642 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 3643 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 3644 | pkt->hdr.cmd); |
| 3645 | } |
| 3646 | |
| 3647 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3648 | /* Invoke any callbacks, transfer the skb to caller, and |
| 3649 | * fire off the (possibly) blocking iwl3945_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3650 | * as we reclaim the driver command queue */ |
| 3651 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3652 | iwl3945_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3653 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3654 | IWL_WARN(priv, "Claim null rxb?\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | /* For now we just don't re-use anything. We can tweak this |
| 3658 | * later to try and re-use notification packets and SKBs that |
| 3659 | * fail to Rx correctly */ |
| 3660 | if (rxb->skb != NULL) { |
| 3661 | priv->alloc_rxb_skb--; |
| 3662 | dev_kfree_skb_any(rxb->skb); |
| 3663 | rxb->skb = NULL; |
| 3664 | } |
| 3665 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3666 | pci_unmap_single(priv->pci_dev, rxb->real_dma_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3667 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3668 | spin_lock_irqsave(&rxq->lock, flags); |
| 3669 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 3670 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3671 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3672 | /* If there are a lot of unused frames, |
| 3673 | * restock the Rx queue so ucode won't assert. */ |
| 3674 | if (fill_rx) { |
| 3675 | count++; |
| 3676 | if (count >= 8) { |
| 3677 | priv->rxq.read = i; |
| 3678 | __iwl3945_rx_replenish(priv); |
| 3679 | count = 0; |
| 3680 | } |
| 3681 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | /* Backtrack one entry */ |
| 3685 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3686 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3689 | /** |
| 3690 | * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware |
| 3691 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3692 | static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3693 | struct iwl3945_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3694 | { |
| 3695 | u32 reg = 0; |
| 3696 | int rc = 0; |
| 3697 | int txq_id = txq->q.id; |
| 3698 | |
| 3699 | if (txq->need_update == 0) |
| 3700 | return rc; |
| 3701 | |
| 3702 | /* if we're trying to save power */ |
| 3703 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 3704 | /* wake up nic if it's powered down ... |
| 3705 | * uCode will wake up, and interrupt us again, so next |
| 3706 | * time we'll skip this part. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3707 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3708 | |
| 3709 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 3710 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3711 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3712 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3713 | return rc; |
| 3714 | } |
| 3715 | |
| 3716 | /* restore this queue's parameters in nic hardware. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3717 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3718 | if (rc) |
| 3719 | return rc; |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3720 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3721 | txq->q.write_ptr | (txq_id << 8)); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3722 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3723 | |
| 3724 | /* else not in power-save mode, uCode will never sleep when we're |
| 3725 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 3726 | } else |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3727 | iwl_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3728 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3729 | |
| 3730 | txq->need_update = 0; |
| 3731 | |
| 3732 | return rc; |
| 3733 | } |
| 3734 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3735 | #ifdef CONFIG_IWL3945_DEBUG |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3736 | static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3737 | struct iwl3945_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3738 | { |
| 3739 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3740 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3741 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 3742 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 3743 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 3744 | le32_to_cpu(rxon->filter_flags)); |
| 3745 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 3746 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 3747 | rxon->ofdm_basic_rates); |
| 3748 | 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] | 3749 | IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr); |
| 3750 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3751 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 3752 | } |
| 3753 | #endif |
| 3754 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3755 | static void iwl3945_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3756 | { |
| 3757 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 3758 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3759 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3760 | } |
| 3761 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3762 | |
| 3763 | /* call this function to flush any scheduled tasklet */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3764 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3765 | { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 3766 | /* wait to make sure we flush pending tasklet*/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3767 | synchronize_irq(priv->pci_dev->irq); |
| 3768 | tasklet_kill(&priv->irq_tasklet); |
| 3769 | } |
| 3770 | |
| 3771 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3772 | static inline void iwl3945_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3773 | { |
| 3774 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 3775 | |
| 3776 | /* disable interrupts from uCode/NIC to host */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3777 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3778 | |
| 3779 | /* acknowledge/clear/reset any interrupts still pending |
| 3780 | * from uCode or flow handler (Rx/Tx DMA) */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3781 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 3782 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3783 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 3784 | } |
| 3785 | |
| 3786 | static const char *desc_lookup(int i) |
| 3787 | { |
| 3788 | switch (i) { |
| 3789 | case 1: |
| 3790 | return "FAIL"; |
| 3791 | case 2: |
| 3792 | return "BAD_PARAM"; |
| 3793 | case 3: |
| 3794 | return "BAD_CHECKSUM"; |
| 3795 | case 4: |
| 3796 | return "NMI_INTERRUPT"; |
| 3797 | case 5: |
| 3798 | return "SYSASSERT"; |
| 3799 | case 6: |
| 3800 | return "FATAL_ERROR"; |
| 3801 | } |
| 3802 | |
| 3803 | return "UNKNOWN"; |
| 3804 | } |
| 3805 | |
| 3806 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 3807 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 3808 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3809 | static void iwl3945_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3810 | { |
| 3811 | u32 i; |
| 3812 | u32 desc, time, count, base, data1; |
| 3813 | u32 blink1, blink2, ilink1, ilink2; |
| 3814 | int rc; |
| 3815 | |
| 3816 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 3817 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3818 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3819 | IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3820 | return; |
| 3821 | } |
| 3822 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3823 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3824 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3825 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3826 | return; |
| 3827 | } |
| 3828 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3829 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3830 | |
| 3831 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3832 | IWL_ERR(priv, "Start IWL Error Log Dump:\n"); |
| 3833 | IWL_ERR(priv, "Status: 0x%08lX, count: %d\n", |
| 3834 | priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3835 | } |
| 3836 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3837 | IWL_ERR(priv, "Desc Time asrtPC blink2 " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3838 | "ilink1 nmiPC Line\n"); |
| 3839 | for (i = ERROR_START_OFFSET; |
| 3840 | i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET; |
| 3841 | i += ERROR_ELEM_SIZE) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3842 | desc = iwl_read_targ_mem(priv, base + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3843 | time = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3844 | iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3845 | blink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3846 | iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3847 | blink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3848 | iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3849 | ilink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3850 | iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3851 | ilink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3852 | iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3853 | data1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3854 | iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3855 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3856 | IWL_ERR(priv, |
| 3857 | "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n", |
| 3858 | desc_lookup(desc), desc, time, blink1, blink2, |
| 3859 | ilink1, ilink2, data1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3860 | } |
| 3861 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3862 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3863 | |
| 3864 | } |
| 3865 | |
Ben Cahill | f58177b | 2007-11-29 11:09:43 +0800 | [diff] [blame] | 3866 | #define EVENT_START_OFFSET (6 * sizeof(u32)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3867 | |
| 3868 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3869 | * iwl3945_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3870 | * |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3871 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3872 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3873 | 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] | 3874 | u32 num_events, u32 mode) |
| 3875 | { |
| 3876 | u32 i; |
| 3877 | u32 base; /* SRAM byte address of event log header */ |
| 3878 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 3879 | u32 ptr; /* SRAM byte address of log data */ |
| 3880 | u32 ev, time, data; /* event log data */ |
| 3881 | |
| 3882 | if (num_events == 0) |
| 3883 | return; |
| 3884 | |
| 3885 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 3886 | |
| 3887 | if (mode == 0) |
| 3888 | event_size = 2 * sizeof(u32); |
| 3889 | else |
| 3890 | event_size = 3 * sizeof(u32); |
| 3891 | |
| 3892 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 3893 | |
| 3894 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 3895 | * place event id # at far right for easier visual parsing. */ |
| 3896 | for (i = 0; i < num_events; i++) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3897 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3898 | ptr += sizeof(u32); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3899 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3900 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3901 | if (mode == 0) { |
| 3902 | /* data, ev */ |
| 3903 | IWL_ERR(priv, "0x%08x\t%04u\n", time, ev); |
| 3904 | } else { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3905 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3906 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3907 | IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3908 | } |
| 3909 | } |
| 3910 | } |
| 3911 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3912 | static void iwl3945_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3913 | { |
| 3914 | int rc; |
| 3915 | u32 base; /* SRAM byte address of event log header */ |
| 3916 | u32 capacity; /* event log capacity in # entries */ |
| 3917 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 3918 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 3919 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 3920 | u32 size; /* # entries that we'll print */ |
| 3921 | |
| 3922 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3923 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3924 | IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3925 | return; |
| 3926 | } |
| 3927 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3928 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3929 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3930 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3931 | return; |
| 3932 | } |
| 3933 | |
| 3934 | /* event log header */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3935 | capacity = iwl_read_targ_mem(priv, base); |
| 3936 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 3937 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 3938 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3939 | |
| 3940 | size = num_wraps ? capacity : next_entry; |
| 3941 | |
| 3942 | /* bail out if nothing in log */ |
| 3943 | if (size == 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3944 | IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3945 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3946 | return; |
| 3947 | } |
| 3948 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3949 | 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] | 3950 | size, num_wraps); |
| 3951 | |
| 3952 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 3953 | * i.e the next one that uCode would fill. */ |
| 3954 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3955 | iwl3945_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3956 | capacity - next_entry, mode); |
| 3957 | |
| 3958 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3959 | iwl3945_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3960 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3961 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3965 | * 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] | 3966 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3967 | static void iwl3945_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3968 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3969 | /* Set the FW error flag -- cleared on iwl3945_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3970 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 3971 | |
| 3972 | /* Cancel currently queued command. */ |
| 3973 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3974 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3975 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3976 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3977 | iwl3945_dump_nic_error_log(priv); |
| 3978 | iwl3945_dump_nic_event_log(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3979 | iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3980 | } |
| 3981 | #endif |
| 3982 | |
| 3983 | wake_up_interruptible(&priv->wait_command_queue); |
| 3984 | |
| 3985 | /* Keep the restart process from trying to send host |
| 3986 | * commands by clearing the INIT status bit */ |
| 3987 | clear_bit(STATUS_READY, &priv->status); |
| 3988 | |
| 3989 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3990 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 3991 | "Restarting adapter due to uCode error.\n"); |
| 3992 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3993 | if (iwl3945_is_associated(priv)) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3994 | memcpy(&priv->recovery39_rxon, &priv->active39_rxon, |
| 3995 | sizeof(priv->recovery39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3996 | priv->error_recovering = 1; |
| 3997 | } |
| 3998 | queue_work(priv->workqueue, &priv->restart); |
| 3999 | } |
| 4000 | } |
| 4001 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4002 | static void iwl3945_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4003 | { |
| 4004 | unsigned long flags; |
| 4005 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4006 | memcpy(&priv->staging39_rxon, &priv->recovery39_rxon, |
| 4007 | sizeof(priv->staging39_rxon)); |
| 4008 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4009 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4010 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4011 | iwl3945_add_station(priv, priv->bssid, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4012 | |
| 4013 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4014 | priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4015 | priv->error_recovering = 0; |
| 4016 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4017 | } |
| 4018 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4019 | static void iwl3945_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4020 | { |
| 4021 | u32 inta, handled = 0; |
| 4022 | u32 inta_fh; |
| 4023 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4024 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4025 | u32 inta_mask; |
| 4026 | #endif |
| 4027 | |
| 4028 | spin_lock_irqsave(&priv->lock, flags); |
| 4029 | |
| 4030 | /* Ack/clear/reset pending uCode interrupts. |
| 4031 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4032 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4033 | inta = iwl_read32(priv, CSR_INT); |
| 4034 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4035 | |
| 4036 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4037 | * Any new interrupts that happen after this, either while we're |
| 4038 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4039 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 4040 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4041 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4042 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4043 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4044 | /* just for debug */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4045 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4046 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4047 | inta, inta_mask, inta_fh); |
| 4048 | } |
| 4049 | #endif |
| 4050 | |
| 4051 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 4052 | * atomic, make sure that inta covers all the interrupts that |
| 4053 | * we've discovered, even if FH interrupt came in just after |
| 4054 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4055 | if (inta_fh & CSR39_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4056 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4057 | if (inta_fh & CSR39_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4058 | inta |= CSR_INT_BIT_FH_TX; |
| 4059 | |
| 4060 | /* Now service all interrupt bits discovered above. */ |
| 4061 | if (inta & CSR_INT_BIT_HW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4062 | IWL_ERR(priv, "Microcode HW error detected. Restarting.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4063 | |
| 4064 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4065 | iwl3945_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4066 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4067 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4068 | |
| 4069 | handled |= CSR_INT_BIT_HW_ERR; |
| 4070 | |
| 4071 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4072 | |
| 4073 | return; |
| 4074 | } |
| 4075 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4076 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4077 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4078 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4079 | if (inta & CSR_INT_BIT_SCD) |
| 4080 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 4081 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4082 | |
| 4083 | /* Alive notification via Rx interrupt will do the real work */ |
| 4084 | if (inta & CSR_INT_BIT_ALIVE) |
| 4085 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 4086 | } |
| 4087 | #endif |
| 4088 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4089 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4090 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4091 | /* Error detected by uCode */ |
| 4092 | if (inta & CSR_INT_BIT_SW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4093 | IWL_ERR(priv, "Microcode SW error detected. " |
| 4094 | "Restarting 0x%X.\n", inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4095 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4096 | handled |= CSR_INT_BIT_SW_ERR; |
| 4097 | } |
| 4098 | |
| 4099 | /* uCode wakes up after power-down sleep */ |
| 4100 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 4101 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4102 | iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4103 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[0]); |
| 4104 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[1]); |
| 4105 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[2]); |
| 4106 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[3]); |
| 4107 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[4]); |
| 4108 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4109 | |
| 4110 | handled |= CSR_INT_BIT_WAKEUP; |
| 4111 | } |
| 4112 | |
| 4113 | /* All uCode command responses, including Tx command responses, |
| 4114 | * Rx "responses" (frame-received notification), and other |
| 4115 | * notifications from uCode come through here*/ |
| 4116 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4117 | iwl3945_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4118 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 4119 | } |
| 4120 | |
| 4121 | if (inta & CSR_INT_BIT_FH_TX) { |
| 4122 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 4123 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4124 | iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); |
| 4125 | if (!iwl_grab_nic_access(priv)) { |
| 4126 | iwl_write_direct32(priv, FH39_TCSR_CREDIT |
Tomas Winkler | bddadf8 | 2008-12-19 10:37:01 +0800 | [diff] [blame] | 4127 | (FH39_SRVC_CHNL), 0x0); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4128 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4129 | } |
| 4130 | handled |= CSR_INT_BIT_FH_TX; |
| 4131 | } |
| 4132 | |
| 4133 | if (inta & ~handled) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4134 | IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4135 | |
| 4136 | if (inta & ~CSR_INI_SET_MASK) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4137 | IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4138 | inta & ~CSR_INI_SET_MASK); |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4139 | IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4143 | /* only Re-enable if disabled by irq */ |
| 4144 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 4145 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4146 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4147 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4148 | if (priv->debug_level & (IWL_DL_ISR)) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4149 | inta = iwl_read32(priv, CSR_INT); |
| 4150 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 4151 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4152 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 4153 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 4154 | } |
| 4155 | #endif |
| 4156 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4157 | } |
| 4158 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4159 | static irqreturn_t iwl3945_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4160 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4161 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4162 | u32 inta, inta_mask; |
| 4163 | u32 inta_fh; |
| 4164 | if (!priv) |
| 4165 | return IRQ_NONE; |
| 4166 | |
| 4167 | spin_lock(&priv->lock); |
| 4168 | |
| 4169 | /* Disable (but don't clear!) interrupts here to avoid |
| 4170 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 4171 | * If we have something to service, the tasklet will re-enable ints. |
| 4172 | * 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] | 4173 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 4174 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4175 | |
| 4176 | /* Discover which interrupts are active/pending */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4177 | inta = iwl_read32(priv, CSR_INT); |
| 4178 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4179 | |
| 4180 | /* Ignore interrupt if there's nothing in NIC to service. |
| 4181 | * This may be due to IRQ shared with another device, |
| 4182 | * or due to sporadic interrupts thrown from our NIC. */ |
| 4183 | if (!inta && !inta_fh) { |
| 4184 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 4185 | goto none; |
| 4186 | } |
| 4187 | |
| 4188 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
| 4189 | /* Hardware disappeared */ |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4190 | IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4191 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4195 | inta, inta_mask, inta_fh); |
| 4196 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4197 | inta &= ~CSR_INT_BIT_SCD; |
| 4198 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4199 | /* iwl3945_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4200 | if (likely(inta || inta_fh)) |
| 4201 | tasklet_schedule(&priv->irq_tasklet); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4202 | unplugged: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4203 | spin_unlock(&priv->lock); |
| 4204 | |
| 4205 | return IRQ_HANDLED; |
| 4206 | |
| 4207 | none: |
| 4208 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4209 | /* only Re-enable if disabled by irq */ |
| 4210 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 4211 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4212 | spin_unlock(&priv->lock); |
| 4213 | return IRQ_NONE; |
| 4214 | } |
| 4215 | |
| 4216 | /************************** EEPROM BANDS **************************** |
| 4217 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4218 | * The iwl3945_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4219 | * EEPROM contents to the specific channel number supported for each |
| 4220 | * band. |
| 4221 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4222 | * 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] | 4223 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 4224 | * The specific geography and calibration information for that channel |
| 4225 | * is contained in the eeprom map itself. |
| 4226 | * |
| 4227 | * During init, we copy the eeprom information and channel map |
| 4228 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 4229 | * |
| 4230 | * channel_map_24/52 provides the index in the channel_info array for a |
| 4231 | * given channel. We have to have two separate maps as there is channel |
| 4232 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 4233 | * band_2 |
| 4234 | * |
| 4235 | * A value of 0xff stored in the channel_map indicates that the channel |
| 4236 | * is not supported by the hardware at all. |
| 4237 | * |
| 4238 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 4239 | * valid for Tx with the current hardware. This means that |
| 4240 | * while the system can tune and receive on a given channel, it may not |
| 4241 | * be able to associate or transmit any frames on that |
| 4242 | * channel. There is no corresponding channel information for that |
| 4243 | * entry. |
| 4244 | * |
| 4245 | *********************************************************************/ |
| 4246 | |
| 4247 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4248 | static const u8 iwl3945_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4249 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 4250 | }; |
| 4251 | |
| 4252 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4253 | static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4254 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 4255 | }; |
| 4256 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4257 | static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4258 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 4259 | }; |
| 4260 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4261 | static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4262 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 4263 | }; |
| 4264 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4265 | static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4266 | 145, 149, 153, 157, 161, 165 |
| 4267 | }; |
| 4268 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4269 | 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] | 4270 | int *eeprom_ch_count, |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4271 | const struct iwl_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4272 | **eeprom_ch_info, |
| 4273 | const u8 **eeprom_ch_index) |
| 4274 | { |
| 4275 | switch (band) { |
| 4276 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4277 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4278 | *eeprom_ch_info = priv->eeprom39.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4279 | *eeprom_ch_index = iwl3945_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4280 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4281 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4282 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4283 | *eeprom_ch_info = priv->eeprom39.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4284 | *eeprom_ch_index = iwl3945_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4285 | break; |
| 4286 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4287 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4288 | *eeprom_ch_info = priv->eeprom39.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4289 | *eeprom_ch_index = iwl3945_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4290 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4291 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4292 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4293 | *eeprom_ch_info = priv->eeprom39.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4294 | *eeprom_ch_index = iwl3945_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4295 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4296 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4297 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4298 | *eeprom_ch_info = priv->eeprom39.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4299 | *eeprom_ch_index = iwl3945_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4300 | break; |
| 4301 | default: |
| 4302 | BUG(); |
| 4303 | return; |
| 4304 | } |
| 4305 | } |
| 4306 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4307 | /** |
| 4308 | * iwl3945_get_channel_info - Find driver's private channel info |
| 4309 | * |
| 4310 | * Based on band and channel number. |
| 4311 | */ |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4312 | const struct iwl_channel_info * |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4313 | iwl3945_get_channel_info(const struct iwl_priv *priv, |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4314 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4315 | { |
| 4316 | int i; |
| 4317 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4318 | switch (band) { |
| 4319 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4320 | for (i = 14; i < priv->channel_count; i++) { |
| 4321 | if (priv->channel_info[i].channel == channel) |
| 4322 | return &priv->channel_info[i]; |
| 4323 | } |
| 4324 | break; |
| 4325 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4326 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4327 | if (channel >= 1 && channel <= 14) |
| 4328 | return &priv->channel_info[channel - 1]; |
| 4329 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4330 | case IEEE80211_NUM_BANDS: |
| 4331 | WARN_ON(1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | return NULL; |
| 4335 | } |
| 4336 | |
| 4337 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 4338 | ? # x " " : "") |
| 4339 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4340 | /** |
| 4341 | * iwl3945_init_channel_map - Set up driver's info for all possible channels |
| 4342 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4343 | static int iwl3945_init_channel_map(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4344 | { |
| 4345 | int eeprom_ch_count = 0; |
| 4346 | const u8 *eeprom_ch_index = NULL; |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4347 | const struct iwl_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4348 | int band, ch; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4349 | struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4350 | |
| 4351 | if (priv->channel_count) { |
| 4352 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 4353 | return 0; |
| 4354 | } |
| 4355 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4356 | if (priv->eeprom39.version < 0x2f) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4357 | IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4358 | priv->eeprom39.version); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4359 | return -EINVAL; |
| 4360 | } |
| 4361 | |
| 4362 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 4363 | |
| 4364 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4365 | ARRAY_SIZE(iwl3945_eeprom_band_1) + |
| 4366 | ARRAY_SIZE(iwl3945_eeprom_band_2) + |
| 4367 | ARRAY_SIZE(iwl3945_eeprom_band_3) + |
| 4368 | ARRAY_SIZE(iwl3945_eeprom_band_4) + |
| 4369 | ARRAY_SIZE(iwl3945_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4370 | |
| 4371 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 4372 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4373 | priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4374 | priv->channel_count, GFP_KERNEL); |
| 4375 | if (!priv->channel_info) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4376 | IWL_ERR(priv, "Could not allocate channel_info\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4377 | priv->channel_count = 0; |
| 4378 | return -ENOMEM; |
| 4379 | } |
| 4380 | |
| 4381 | ch_info = priv->channel_info; |
| 4382 | |
| 4383 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 4384 | * channel map we maintain (that contains additional information than |
| 4385 | * what just in the EEPROM) */ |
| 4386 | for (band = 1; band <= 5; band++) { |
| 4387 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4388 | iwl3945_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4389 | &eeprom_ch_info, &eeprom_ch_index); |
| 4390 | |
| 4391 | /* Loop through each band adding each of the channels */ |
| 4392 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 4393 | ch_info->channel = eeprom_ch_index[ch]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4394 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 4395 | IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4396 | |
| 4397 | /* permanently store EEPROM's channel regulatory flags |
| 4398 | * and max power in channel info database. */ |
| 4399 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 4400 | |
| 4401 | /* Copy the run-time flags so they are there even on |
| 4402 | * invalid channels */ |
| 4403 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 4404 | |
| 4405 | if (!(is_channel_valid(ch_info))) { |
| 4406 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 4407 | "No traffic\n", |
| 4408 | ch_info->channel, |
| 4409 | ch_info->flags, |
| 4410 | is_channel_a_band(ch_info) ? |
| 4411 | "5.2" : "2.4"); |
| 4412 | ch_info++; |
| 4413 | continue; |
| 4414 | } |
| 4415 | |
| 4416 | /* Initialize regulatory-based run-time data */ |
| 4417 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 4418 | eeprom_ch_info[ch].max_power_avg; |
| 4419 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 4420 | ch_info->min_power = 0; |
| 4421 | |
Guy Cohen | fe7c404 | 2008-04-21 15:41:56 -0700 | [diff] [blame] | 4422 | 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] | 4423 | " %ddBm): Ad-Hoc %ssupported\n", |
| 4424 | ch_info->channel, |
| 4425 | is_channel_a_band(ch_info) ? |
| 4426 | "5.2" : "2.4", |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4427 | CHECK_AND_PRINT(VALID), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4428 | CHECK_AND_PRINT(IBSS), |
| 4429 | CHECK_AND_PRINT(ACTIVE), |
| 4430 | CHECK_AND_PRINT(RADAR), |
| 4431 | CHECK_AND_PRINT(WIDE), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4432 | CHECK_AND_PRINT(DFS), |
| 4433 | eeprom_ch_info[ch].flags, |
| 4434 | eeprom_ch_info[ch].max_power_avg, |
| 4435 | ((eeprom_ch_info[ch]. |
| 4436 | flags & EEPROM_CHANNEL_IBSS) |
| 4437 | && !(eeprom_ch_info[ch]. |
| 4438 | flags & EEPROM_CHANNEL_RADAR)) |
| 4439 | ? "" : "not "); |
| 4440 | |
| 4441 | /* Set the user_txpower_limit to the highest power |
| 4442 | * supported by any channel */ |
| 4443 | if (eeprom_ch_info[ch].max_power_avg > |
| 4444 | priv->user_txpower_limit) |
| 4445 | priv->user_txpower_limit = |
| 4446 | eeprom_ch_info[ch].max_power_avg; |
| 4447 | |
| 4448 | ch_info++; |
| 4449 | } |
| 4450 | } |
| 4451 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4452 | /* Set up txpower settings in driver for all channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4453 | if (iwl3945_txpower_set_from_eeprom(priv)) |
| 4454 | return -EIO; |
| 4455 | |
| 4456 | return 0; |
| 4457 | } |
| 4458 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4459 | /* |
| 4460 | * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map |
| 4461 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4462 | static void iwl3945_free_channel_map(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4463 | { |
| 4464 | kfree(priv->channel_info); |
| 4465 | priv->channel_count = 0; |
| 4466 | } |
| 4467 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4468 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 4469 | * sending probe req. This should be set long enough to hear probe responses |
| 4470 | * from more than one AP. */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4471 | #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */ |
| 4472 | #define IWL_ACTIVE_DWELL_TIME_52 (20) |
| 4473 | |
| 4474 | #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3) |
| 4475 | #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4476 | |
| 4477 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 4478 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 4479 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 4480 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 4481 | * no other traffic). |
| 4482 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 4483 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4484 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4485 | |
| 4486 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 4487 | * Must be set longer than active dwell time. |
| 4488 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 4489 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 4490 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 4491 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 4492 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 4493 | |
Kolekar, Abhijeet | e720ce9 | 2008-11-07 09:58:42 -0800 | [diff] [blame] | 4494 | #define IWL_SCAN_PROBE_MASK(n) (BIT(n) | (BIT(n) - BIT(1))) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4495 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4496 | static inline u16 iwl3945_get_active_dwell_time(struct iwl_priv *priv, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4497 | enum ieee80211_band band, |
| 4498 | u8 n_probes) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4499 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4500 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4501 | return IWL_ACTIVE_DWELL_TIME_52 + |
| 4502 | IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4503 | else |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4504 | return IWL_ACTIVE_DWELL_TIME_24 + |
| 4505 | IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4506 | } |
| 4507 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4508 | static u16 iwl3945_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4509 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4510 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4511 | u16 passive = (band == IEEE80211_BAND_2GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4512 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 4513 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 4514 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4515 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4516 | /* If we're associated, we clamp the maximum passive |
| 4517 | * dwell time to be 98% of the beacon interval (minus |
| 4518 | * 2 * channel tune time) */ |
| 4519 | passive = priv->beacon_int; |
| 4520 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 4521 | passive = IWL_PASSIVE_DWELL_BASE; |
| 4522 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 4523 | } |
| 4524 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4525 | return passive; |
| 4526 | } |
| 4527 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4528 | static int iwl3945_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4529 | enum ieee80211_band band, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4530 | u8 is_active, u8 n_probes, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4531 | struct iwl3945_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4532 | { |
| 4533 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4534 | const struct ieee80211_supported_band *sband; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4535 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4536 | u16 passive_dwell = 0; |
| 4537 | u16 active_dwell = 0; |
| 4538 | int added, i; |
| 4539 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4540 | sband = iwl3945_get_band(priv, band); |
| 4541 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4542 | return 0; |
| 4543 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4544 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4545 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4546 | active_dwell = iwl3945_get_active_dwell_time(priv, band, n_probes); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4547 | passive_dwell = iwl3945_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4548 | |
Abhijeet Kolekar | 8f4807a | 2008-09-03 11:26:31 +0800 | [diff] [blame] | 4549 | if (passive_dwell <= active_dwell) |
| 4550 | passive_dwell = active_dwell + 1; |
| 4551 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4552 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 4553 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 4554 | continue; |
| 4555 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4556 | scan_ch->channel = channels[i].hw_value; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4557 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4558 | ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4559 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 4560 | IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4561 | scan_ch->channel); |
| 4562 | continue; |
| 4563 | } |
| 4564 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4565 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 4566 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 4567 | /* If passive , set up for auto-switch |
| 4568 | * and use long active_dwell time. |
| 4569 | */ |
| 4570 | if (!is_active || is_channel_passive(ch_info) || |
| 4571 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) { |
| 4572 | scan_ch->type = 0; /* passive */ |
| 4573 | if (IWL_UCODE_API(priv->ucode_ver) == 1) |
| 4574 | scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1); |
| 4575 | } else { |
| 4576 | scan_ch->type = 1; /* active */ |
| 4577 | } |
| 4578 | |
| 4579 | /* Set direct probe bits. These may be used both for active |
| 4580 | * scan channels (probes gets sent right away), |
| 4581 | * or for passive channels (probes get se sent only after |
| 4582 | * hearing clear Rx packet).*/ |
| 4583 | if (IWL_UCODE_API(priv->ucode_ver) >= 2) { |
| 4584 | if (n_probes) |
| 4585 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4586 | } else { |
| 4587 | /* uCode v1 does not allow setting direct probe bits on |
| 4588 | * passive channel. */ |
| 4589 | if ((scan_ch->type & 1) && n_probes) |
| 4590 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4591 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4592 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4593 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4594 | scan_ch->tpc.dsp_atten = 110; |
| 4595 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 4596 | |
| 4597 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4598 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4599 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 4600 | else { |
| 4601 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 4602 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4603 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 4604 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4605 | */ |
| 4606 | } |
| 4607 | |
| 4608 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 4609 | scan_ch->channel, |
| 4610 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 4611 | (scan_ch->type & 1) ? |
| 4612 | active_dwell : passive_dwell); |
| 4613 | |
| 4614 | scan_ch++; |
| 4615 | added++; |
| 4616 | } |
| 4617 | |
| 4618 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 4619 | return added; |
| 4620 | } |
| 4621 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4622 | static void iwl3945_init_hw_rates(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4623 | struct ieee80211_rate *rates) |
| 4624 | { |
| 4625 | int i; |
| 4626 | |
| 4627 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4628 | rates[i].bitrate = iwl3945_rates[i].ieee * 5; |
| 4629 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 4630 | rates[i].hw_value_short = i; |
| 4631 | rates[i].flags = 0; |
Samuel Ortiz | d9829a6 | 2008-12-19 10:37:12 +0800 | [diff] [blame] | 4632 | if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4633 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4634 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4635 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4636 | rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4637 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4638 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4639 | } |
| 4640 | } |
| 4641 | |
| 4642 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4643 | * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4644 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4645 | static int iwl3945_init_geos(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4646 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4647 | struct iwl_channel_info *ch; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4648 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4649 | struct ieee80211_channel *channels; |
| 4650 | struct ieee80211_channel *geo_ch; |
| 4651 | struct ieee80211_rate *rates; |
| 4652 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4653 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4654 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 4655 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4656 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 4657 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4658 | return 0; |
| 4659 | } |
| 4660 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4661 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 4662 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4663 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4664 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4665 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4666 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4667 | GFP_KERNEL); |
| 4668 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4669 | kfree(channels); |
| 4670 | return -ENOMEM; |
| 4671 | } |
| 4672 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4673 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4674 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 4675 | sband->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)]; |
| 4676 | /* just OFDM */ |
| 4677 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
| 4678 | sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4679 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4680 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4681 | sband->channels = channels; |
| 4682 | /* OFDM & CCK */ |
| 4683 | sband->bitrates = rates; |
| 4684 | sband->n_bitrates = IWL_RATE_COUNT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4685 | |
| 4686 | priv->ieee_channels = channels; |
| 4687 | priv->ieee_rates = rates; |
| 4688 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4689 | iwl3945_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4690 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4691 | for (i = 0; i < priv->channel_count; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4692 | ch = &priv->channel_info[i]; |
| 4693 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4694 | /* FIXME: might be removed if scan is OK*/ |
| 4695 | if (!is_channel_valid(ch)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4696 | continue; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4697 | |
| 4698 | if (is_channel_a_band(ch)) |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4699 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4700 | else |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4701 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4702 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4703 | geo_ch = &sband->channels[sband->n_channels++]; |
| 4704 | |
| 4705 | geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4706 | geo_ch->max_power = ch->max_power_avg; |
| 4707 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 4708 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4709 | |
| 4710 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4711 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 4712 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4713 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4714 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 4715 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4716 | |
| 4717 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4718 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4719 | |
| 4720 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 4721 | priv->max_channel_txpower_limit = |
| 4722 | ch->max_power_avg; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4723 | } else { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4724 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | /* Save flags for reg domain usage */ |
| 4728 | geo_ch->orig_flags = geo_ch->flags; |
| 4729 | |
| 4730 | IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n", |
| 4731 | ch->channel, geo_ch->center_freq, |
| 4732 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 4733 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 4734 | "restricted" : "valid", |
| 4735 | geo_ch->flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4736 | } |
| 4737 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4738 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && |
| 4739 | priv->cfg->sku & IWL_SKU_A) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4740 | IWL_INFO(priv, "Incorrectly detected BG card as ABG. " |
| 4741 | "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 4742 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4743 | priv->cfg->sku &= ~IWL_SKU_A; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4744 | } |
| 4745 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4746 | 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] | 4747 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 4748 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4749 | |
John W. Linville | e0e0a67 | 2008-03-25 15:58:40 -0400 | [diff] [blame] | 4750 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 4751 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 4752 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4753 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 4754 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 4755 | &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4756 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4757 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4758 | |
| 4759 | return 0; |
| 4760 | } |
| 4761 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4762 | /* |
| 4763 | * iwl3945_free_geos - undo allocations in iwl3945_init_geos |
| 4764 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4765 | static void iwl3945_free_geos(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4766 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4767 | kfree(priv->ieee_channels); |
| 4768 | kfree(priv->ieee_rates); |
| 4769 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4770 | } |
| 4771 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4772 | /****************************************************************************** |
| 4773 | * |
| 4774 | * uCode download functions |
| 4775 | * |
| 4776 | ******************************************************************************/ |
| 4777 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4778 | static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4779 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4780 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 4781 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 4782 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 4783 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 4784 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 4785 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4789 | * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4790 | * looking at all data. |
| 4791 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4792 | 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] | 4793 | { |
| 4794 | u32 val; |
| 4795 | u32 save_len = len; |
| 4796 | int rc = 0; |
| 4797 | u32 errcnt; |
| 4798 | |
| 4799 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4800 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4801 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4802 | if (rc) |
| 4803 | return rc; |
| 4804 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4805 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4806 | IWL39_RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4807 | |
| 4808 | errcnt = 0; |
| 4809 | for (; len > 0; len -= sizeof(u32), image++) { |
| 4810 | /* read data comes through single port, auto-incr addr */ |
| 4811 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4812 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4813 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4814 | if (val != le32_to_cpu(*image)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4815 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4816 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4817 | save_len - len, val, le32_to_cpu(*image)); |
| 4818 | rc = -EIO; |
| 4819 | errcnt++; |
| 4820 | if (errcnt >= 20) |
| 4821 | break; |
| 4822 | } |
| 4823 | } |
| 4824 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4825 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4826 | |
| 4827 | if (!errcnt) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 4828 | IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4829 | |
| 4830 | return rc; |
| 4831 | } |
| 4832 | |
| 4833 | |
| 4834 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4835 | * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4836 | * using sample data 100 bytes apart. If these sample points are good, |
| 4837 | * it's a pretty good bet that everything between them is good, too. |
| 4838 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4839 | 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] | 4840 | { |
| 4841 | u32 val; |
| 4842 | int rc = 0; |
| 4843 | u32 errcnt = 0; |
| 4844 | u32 i; |
| 4845 | |
| 4846 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4847 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4848 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4849 | if (rc) |
| 4850 | return rc; |
| 4851 | |
| 4852 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 4853 | /* read data comes through single port, auto-incr addr */ |
| 4854 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4855 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4856 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4857 | i + IWL39_RTC_INST_LOWER_BOUND); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4858 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4859 | if (val != le32_to_cpu(*image)) { |
| 4860 | #if 0 /* Enable this if you want to see details */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4861 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4862 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4863 | i, val, *image); |
| 4864 | #endif |
| 4865 | rc = -EIO; |
| 4866 | errcnt++; |
| 4867 | if (errcnt >= 3) |
| 4868 | break; |
| 4869 | } |
| 4870 | } |
| 4871 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4872 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4873 | |
| 4874 | return rc; |
| 4875 | } |
| 4876 | |
| 4877 | |
| 4878 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4879 | * iwl3945_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4880 | * and verify its contents |
| 4881 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4882 | static int iwl3945_verify_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4883 | { |
| 4884 | __le32 *image; |
| 4885 | u32 len; |
| 4886 | int rc = 0; |
| 4887 | |
| 4888 | /* Try bootstrap */ |
| 4889 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4890 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4891 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4892 | if (rc == 0) { |
| 4893 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 4894 | return 0; |
| 4895 | } |
| 4896 | |
| 4897 | /* Try initialize */ |
| 4898 | image = (__le32 *)priv->ucode_init.v_addr; |
| 4899 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4900 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4901 | if (rc == 0) { |
| 4902 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 4903 | return 0; |
| 4904 | } |
| 4905 | |
| 4906 | /* Try runtime/protocol */ |
| 4907 | image = (__le32 *)priv->ucode_code.v_addr; |
| 4908 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4909 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4910 | if (rc == 0) { |
| 4911 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 4912 | return 0; |
| 4913 | } |
| 4914 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4915 | IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4916 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4917 | /* Since nothing seems to match, show first several data entries in |
| 4918 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 4919 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4920 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4921 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4922 | rc = iwl3945_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4923 | |
| 4924 | return rc; |
| 4925 | } |
| 4926 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4927 | static void iwl3945_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4928 | { |
| 4929 | /* Remove all resets to allow NIC to operate */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4930 | iwl_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4931 | } |
| 4932 | |
| 4933 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4934 | * iwl3945_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4935 | * |
| 4936 | * Copy into buffers for card to fetch via bus-mastering |
| 4937 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4938 | static int iwl3945_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4939 | { |
Kolekar, Abhijeet | a78fe75 | 2008-12-19 10:37:21 +0800 | [diff] [blame] | 4940 | struct iwl_ucode *ucode; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4941 | int ret = -EINVAL, index; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4942 | const struct firmware *ucode_raw; |
| 4943 | /* firmware file name contains uCode/driver compatibility version */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4944 | const char *name_pre = priv->cfg->fw_name_pre; |
| 4945 | const unsigned int api_max = priv->cfg->ucode_api_max; |
| 4946 | const unsigned int api_min = priv->cfg->ucode_api_min; |
| 4947 | char buf[25]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4948 | u8 *src; |
| 4949 | size_t len; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4950 | 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] | 4951 | |
| 4952 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 4953 | * request_firmware() is synchronous, file is in memory on return. */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4954 | for (index = api_max; index >= api_min; index--) { |
| 4955 | sprintf(buf, "%s%u%s", name_pre, index, ".ucode"); |
| 4956 | ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev); |
| 4957 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4958 | IWL_ERR(priv, "%s firmware file req failed: %d\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4959 | buf, ret); |
| 4960 | if (ret == -ENOENT) |
| 4961 | continue; |
| 4962 | else |
| 4963 | goto error; |
| 4964 | } else { |
| 4965 | if (index < api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4966 | IWL_ERR(priv, "Loaded firmware %s, " |
| 4967 | "which is deprecated. " |
| 4968 | " Please use API v%u instead.\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4969 | buf, api_max); |
| 4970 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 4971 | buf, ucode_raw->size); |
| 4972 | break; |
| 4973 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4974 | } |
| 4975 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4976 | if (ret < 0) |
| 4977 | goto error; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4978 | |
| 4979 | /* Make sure that we got at least our header! */ |
| 4980 | if (ucode_raw->size < sizeof(*ucode)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4981 | IWL_ERR(priv, "File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4982 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4983 | goto err_release; |
| 4984 | } |
| 4985 | |
| 4986 | /* Data from ucode file: header followed by uCode images */ |
| 4987 | ucode = (void *)ucode_raw->data; |
| 4988 | |
Chatre, Reinette | c02b3ac | 2008-12-02 12:14:05 -0800 | [diff] [blame] | 4989 | priv->ucode_ver = le32_to_cpu(ucode->ver); |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4990 | api_ver = IWL_UCODE_API(priv->ucode_ver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4991 | inst_size = le32_to_cpu(ucode->inst_size); |
| 4992 | data_size = le32_to_cpu(ucode->data_size); |
| 4993 | init_size = le32_to_cpu(ucode->init_size); |
| 4994 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 4995 | boot_size = le32_to_cpu(ucode->boot_size); |
| 4996 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4997 | /* api_ver should match the api version forming part of the |
| 4998 | * firmware filename ... but we don't check for that and only rely |
| 4999 | * on the API version read from firware header from here on forward */ |
| 5000 | |
| 5001 | if (api_ver < api_min || api_ver > api_max) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5002 | IWL_ERR(priv, "Driver unable to support your firmware API. " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5003 | "Driver supports v%u, firmware is v%u.\n", |
| 5004 | api_max, api_ver); |
| 5005 | priv->ucode_ver = 0; |
| 5006 | ret = -EINVAL; |
| 5007 | goto err_release; |
| 5008 | } |
| 5009 | if (api_ver != api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5010 | IWL_ERR(priv, "Firmware has old API version. Expected %u, " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5011 | "got %u. New firmware can be obtained " |
| 5012 | "from http://www.intellinuxwireless.org.\n", |
| 5013 | api_max, api_ver); |
| 5014 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 5015 | IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n", |
| 5016 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 5017 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 5018 | IWL_UCODE_API(priv->ucode_ver), |
| 5019 | IWL_UCODE_SERIAL(priv->ucode_ver)); |
| 5020 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5021 | IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n", |
| 5022 | priv->ucode_ver); |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 5023 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size); |
| 5024 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size); |
| 5025 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size); |
| 5026 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size); |
| 5027 | 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] | 5028 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5029 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5030 | /* Verify size of file vs. image size info in file's header */ |
| 5031 | if (ucode_raw->size < sizeof(*ucode) + |
| 5032 | inst_size + data_size + init_size + |
| 5033 | init_data_size + boot_size) { |
| 5034 | |
| 5035 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 5036 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5037 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5038 | goto err_release; |
| 5039 | } |
| 5040 | |
| 5041 | /* Verify that uCode images will fit in card's SRAM */ |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5042 | if (inst_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5043 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 5044 | inst_size); |
| 5045 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5046 | goto err_release; |
| 5047 | } |
| 5048 | |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5049 | if (data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5050 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 5051 | data_size); |
| 5052 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5053 | goto err_release; |
| 5054 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5055 | if (init_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5056 | IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n", |
| 5057 | init_size); |
| 5058 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5059 | goto err_release; |
| 5060 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5061 | if (init_data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5062 | IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n", |
| 5063 | init_data_size); |
| 5064 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5065 | goto err_release; |
| 5066 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5067 | if (boot_size > IWL39_MAX_BSM_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5068 | IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n", |
| 5069 | boot_size); |
| 5070 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5071 | goto err_release; |
| 5072 | } |
| 5073 | |
| 5074 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 5075 | |
| 5076 | /* Runtime instructions and 2 copies of data: |
| 5077 | * 1) unmodified from disk |
| 5078 | * 2) backup cache for save/restore during power-downs */ |
| 5079 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5080 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5081 | |
| 5082 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5083 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5084 | |
| 5085 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5086 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5087 | |
| 5088 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5089 | !priv->ucode_data_backup.v_addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5090 | goto err_pci_alloc; |
| 5091 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5092 | /* Initialization instructions and data */ |
| 5093 | if (init_size && init_data_size) { |
| 5094 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5095 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5096 | |
| 5097 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5098 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5099 | |
| 5100 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 5101 | goto err_pci_alloc; |
| 5102 | } |
| 5103 | |
| 5104 | /* Bootstrap (instructions only, no data) */ |
| 5105 | if (boot_size) { |
| 5106 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5107 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5108 | |
| 5109 | if (!priv->ucode_boot.v_addr) |
| 5110 | goto err_pci_alloc; |
| 5111 | } |
| 5112 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5113 | /* Copy images into buffers for card's bus-master reads ... */ |
| 5114 | |
| 5115 | /* Runtime instructions (first block of data in file) */ |
| 5116 | src = &ucode->data[0]; |
| 5117 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5118 | 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] | 5119 | memcpy(priv->ucode_code.v_addr, src, len); |
| 5120 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 5121 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 5122 | |
| 5123 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5124 | * NOTE: Copy into backup buffer will be done in iwl3945_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5125 | src = &ucode->data[inst_size]; |
| 5126 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5127 | 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] | 5128 | memcpy(priv->ucode_data.v_addr, src, len); |
| 5129 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 5130 | |
| 5131 | /* Initialization instructions (3rd block) */ |
| 5132 | if (init_size) { |
| 5133 | src = &ucode->data[inst_size + data_size]; |
| 5134 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5135 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 5136 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5137 | memcpy(priv->ucode_init.v_addr, src, len); |
| 5138 | } |
| 5139 | |
| 5140 | /* Initialization data (4th block) */ |
| 5141 | if (init_data_size) { |
| 5142 | src = &ucode->data[inst_size + data_size + init_size]; |
| 5143 | len = priv->ucode_init_data.len; |
| 5144 | IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n", |
| 5145 | (int)len); |
| 5146 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 5147 | } |
| 5148 | |
| 5149 | /* Bootstrap instructions (5th block) */ |
| 5150 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 5151 | len = priv->ucode_boot.len; |
| 5152 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n", |
| 5153 | (int)len); |
| 5154 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 5155 | |
| 5156 | /* We have our copies now, allow OS release its copies */ |
| 5157 | release_firmware(ucode_raw); |
| 5158 | return 0; |
| 5159 | |
| 5160 | err_pci_alloc: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5161 | IWL_ERR(priv, "failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5162 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5163 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5164 | |
| 5165 | err_release: |
| 5166 | release_firmware(ucode_raw); |
| 5167 | |
| 5168 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5169 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5170 | } |
| 5171 | |
| 5172 | |
| 5173 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5174 | * iwl3945_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5175 | * |
| 5176 | * Tell initialization uCode where to find runtime uCode. |
| 5177 | * |
| 5178 | * BSM registers initially contain pointers to initialization uCode. |
| 5179 | * We need to replace them to load runtime uCode inst and data, |
| 5180 | * and to save runtime data when powering down. |
| 5181 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5182 | static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5183 | { |
| 5184 | dma_addr_t pinst; |
| 5185 | dma_addr_t pdata; |
| 5186 | int rc = 0; |
| 5187 | unsigned long flags; |
| 5188 | |
| 5189 | /* bits 31:0 for 3945 */ |
| 5190 | pinst = priv->ucode_code.p_addr; |
| 5191 | pdata = priv->ucode_data_backup.p_addr; |
| 5192 | |
| 5193 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5194 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5195 | if (rc) { |
| 5196 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5197 | return rc; |
| 5198 | } |
| 5199 | |
| 5200 | /* Tell bootstrap uCode where to find image to load */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5201 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 5202 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 5203 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5204 | priv->ucode_data.len); |
| 5205 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5206 | /* 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] | 5207 | * that all new ptr/size info is in place */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5208 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5209 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 5210 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5211 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5212 | |
| 5213 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5214 | |
| 5215 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 5216 | |
| 5217 | return rc; |
| 5218 | } |
| 5219 | |
| 5220 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5221 | * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5222 | * |
| 5223 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 5224 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5225 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5226 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5227 | static void iwl3945_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5228 | { |
| 5229 | /* Check alive response for "valid" sign from uCode */ |
| 5230 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 5231 | /* We had an error bringing up the hardware, so take it |
| 5232 | * all the way back down so we can try again */ |
| 5233 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 5234 | goto restart; |
| 5235 | } |
| 5236 | |
| 5237 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 5238 | * This is a paranoid check, because we would not have gotten the |
| 5239 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5240 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5241 | /* Runtime instruction load was bad; |
| 5242 | * take it all the way back down so we can try again */ |
| 5243 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 5244 | goto restart; |
| 5245 | } |
| 5246 | |
| 5247 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 5248 | * load and launch runtime uCode, which will send us another "Alive" |
| 5249 | * notification. */ |
| 5250 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5251 | if (iwl3945_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5252 | /* Runtime instruction load won't happen; |
| 5253 | * take it all the way back down so we can try again */ |
| 5254 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 5255 | goto restart; |
| 5256 | } |
| 5257 | return; |
| 5258 | |
| 5259 | restart: |
| 5260 | queue_work(priv->workqueue, &priv->restart); |
| 5261 | } |
| 5262 | |
| 5263 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5264 | /* temporary */ |
| 5265 | static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, |
| 5266 | struct sk_buff *skb); |
| 5267 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5268 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5269 | * iwl3945_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5270 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5271 | * Alive gets handled by iwl3945_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5272 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5273 | static void iwl3945_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5274 | { |
| 5275 | int rc = 0; |
| 5276 | int thermal_spin = 0; |
| 5277 | u32 rfkill; |
| 5278 | |
| 5279 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 5280 | |
| 5281 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 5282 | /* We had an error bringing up the hardware, so take it |
| 5283 | * all the way back down so we can try again */ |
| 5284 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 5285 | goto restart; |
| 5286 | } |
| 5287 | |
| 5288 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 5289 | * This is a paranoid check, because we would not have gotten the |
| 5290 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5291 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5292 | /* Runtime instruction load was bad; |
| 5293 | * take it all the way back down so we can try again */ |
| 5294 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 5295 | goto restart; |
| 5296 | } |
| 5297 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5298 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5299 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5300 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5301 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5302 | IWL_WARN(priv, "Can not read RFKILL status from adapter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5303 | return; |
| 5304 | } |
| 5305 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5306 | rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5307 | IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5308 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5309 | |
| 5310 | if (rfkill & 0x1) { |
| 5311 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5312 | /* if RFKILL is not on, then wait for thermal |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5313 | * sensor in adapter to kick in */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5314 | while (iwl3945_hw_get_temperature(priv) == 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5315 | thermal_spin++; |
| 5316 | udelay(10); |
| 5317 | } |
| 5318 | |
| 5319 | if (thermal_spin) |
| 5320 | IWL_DEBUG_INFO("Thermal calibration took %dus\n", |
| 5321 | thermal_spin * 10); |
| 5322 | } else |
| 5323 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5324 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5325 | /* After the ALIVE response, we can send commands to 3945 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5326 | set_bit(STATUS_ALIVE, &priv->status); |
| 5327 | |
| 5328 | /* Clear out the uCode error bit if it is set */ |
| 5329 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 5330 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5331 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5332 | return; |
| 5333 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 5334 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5335 | |
| 5336 | priv->active_rate = priv->rates_mask; |
| 5337 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 5338 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5339 | iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5340 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5341 | if (iwl3945_is_associated(priv)) { |
| 5342 | struct iwl3945_rxon_cmd *active_rxon = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5343 | (struct iwl3945_rxon_cmd *)(&priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5344 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5345 | memcpy(&priv->staging39_rxon, &priv->active39_rxon, |
| 5346 | sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5347 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5348 | } else { |
| 5349 | /* Initialize our rx_config data */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 5350 | iwl3945_connection_init_rx_config(priv, priv->iw_mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5351 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5352 | } |
| 5353 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5354 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5355 | iwl3945_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5356 | |
| 5357 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5358 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5359 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5360 | iwl3945_reg_txpower_periodic(priv); |
| 5361 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 5362 | iwl3945_led_register(priv); |
| 5363 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5364 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 5365 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5366 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5367 | |
| 5368 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5369 | iwl3945_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5370 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5371 | /* reassociate for ADHOC mode */ |
| 5372 | if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) { |
| 5373 | struct sk_buff *beacon = ieee80211_beacon_get(priv->hw, |
| 5374 | priv->vif); |
| 5375 | if (beacon) |
| 5376 | iwl3945_mac_beacon_update(priv->hw, beacon); |
| 5377 | } |
| 5378 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5379 | return; |
| 5380 | |
| 5381 | restart: |
| 5382 | queue_work(priv->workqueue, &priv->restart); |
| 5383 | } |
| 5384 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5385 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5386 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5387 | static void __iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5388 | { |
| 5389 | unsigned long flags; |
| 5390 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5391 | struct ieee80211_conf *conf = NULL; |
| 5392 | |
| 5393 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 5394 | |
| 5395 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5396 | |
| 5397 | if (!exit_pending) |
| 5398 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5399 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 5400 | iwl3945_led_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5401 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5402 | |
| 5403 | /* Unblock any waiting calls */ |
| 5404 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 5405 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5406 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 5407 | * exiting the module */ |
| 5408 | if (!exit_pending) |
| 5409 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5410 | |
| 5411 | /* stop and reset the on-board processor */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5412 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5413 | |
| 5414 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5415 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5416 | iwl3945_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5417 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5418 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5419 | |
| 5420 | if (priv->mac80211_registered) |
| 5421 | ieee80211_stop_queues(priv->hw); |
| 5422 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5423 | /* If we have not previously called iwl3945_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5424 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5425 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5426 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5427 | STATUS_RF_KILL_HW | |
| 5428 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5429 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5430 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5431 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5432 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5433 | STATUS_IN_SUSPEND | |
| 5434 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5435 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5436 | goto exit; |
| 5437 | } |
| 5438 | |
| 5439 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 5440 | * SUSPEND bits and continue taking the NIC down. */ |
| 5441 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5442 | STATUS_RF_KILL_HW | |
| 5443 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5444 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5445 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5446 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5447 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 5448 | STATUS_IN_SUSPEND | |
| 5449 | test_bit(STATUS_FW_ERROR, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5450 | STATUS_FW_ERROR | |
| 5451 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5452 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5453 | |
| 5454 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5455 | 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] | 5456 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5457 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5458 | iwl3945_hw_txq_ctx_stop(priv); |
| 5459 | iwl3945_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5460 | |
| 5461 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5462 | if (!iwl_grab_nic_access(priv)) { |
| 5463 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5464 | APMG_CLK_VAL_DMA_CLK_RQT); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5465 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5466 | } |
| 5467 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5468 | |
| 5469 | udelay(5); |
| 5470 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5471 | iwl3945_hw_nic_stop_master(priv); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5472 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5473 | iwl3945_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5474 | |
| 5475 | exit: |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 5476 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5477 | |
| 5478 | if (priv->ibss_beacon) |
| 5479 | dev_kfree_skb(priv->ibss_beacon); |
| 5480 | priv->ibss_beacon = NULL; |
| 5481 | |
| 5482 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5483 | iwl3945_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5484 | } |
| 5485 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5486 | static void iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5487 | { |
| 5488 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5489 | __iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5490 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5491 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5492 | iwl3945_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | #define MAX_HW_RESTARTS 5 |
| 5496 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5497 | static int __iwl3945_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5498 | { |
| 5499 | int rc, i; |
| 5500 | |
| 5501 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5502 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5503 | return -EIO; |
| 5504 | } |
| 5505 | |
| 5506 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5507 | IWL_WARN(priv, "Radio disabled by SW RF kill (module " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5508 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5509 | return -ENODEV; |
| 5510 | } |
| 5511 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5512 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5513 | IWL_ERR(priv, "ucode not available for device bring up\n"); |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5514 | return -EIO; |
| 5515 | } |
| 5516 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5517 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5518 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5519 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 5520 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5521 | else { |
| 5522 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5523 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5524 | IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5525 | return -ENODEV; |
| 5526 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5527 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5528 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5529 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5530 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5531 | rc = iwl3945_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5532 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5533 | IWL_ERR(priv, "Unable to int nic\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5534 | return rc; |
| 5535 | } |
| 5536 | |
| 5537 | /* make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5538 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5539 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5540 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 5541 | |
| 5542 | /* clear (again), then enable host interrupts */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5543 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5544 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5545 | |
| 5546 | /* really make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5547 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5548 | 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] | 5549 | |
| 5550 | /* Copy original ucode data image from disk into backup cache. |
| 5551 | * This will be used to initialize the on-board processor's |
| 5552 | * data SRAM for a clean start when the runtime program first loads. */ |
| 5553 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5554 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5555 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5556 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 5557 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5558 | return 0; |
| 5559 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5560 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 5561 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5562 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5563 | |
| 5564 | /* load bootstrap state machine, |
| 5565 | * load bootstrap program into processor's memory, |
| 5566 | * prepare to load the "initialize" uCode */ |
Kolekar, Abhijeet | 0164b9b | 2008-12-19 10:37:37 +0800 | [diff] [blame^] | 5567 | priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5568 | |
| 5569 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5570 | IWL_ERR(priv, |
| 5571 | "Unable to set up bootstrap uCode: %d\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5572 | continue; |
| 5573 | } |
| 5574 | |
| 5575 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5576 | iwl3945_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5577 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5578 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 5579 | |
| 5580 | return 0; |
| 5581 | } |
| 5582 | |
| 5583 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5584 | __iwl3945_down(priv); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5585 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5586 | |
| 5587 | /* tried to restart and config the device for as long as our |
| 5588 | * patience could withstand */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5589 | IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5590 | return -EIO; |
| 5591 | } |
| 5592 | |
| 5593 | |
| 5594 | /***************************************************************************** |
| 5595 | * |
| 5596 | * Workqueue callbacks |
| 5597 | * |
| 5598 | *****************************************************************************/ |
| 5599 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5600 | static void iwl3945_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5601 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5602 | struct iwl_priv *priv = |
| 5603 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5604 | |
| 5605 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5606 | return; |
| 5607 | |
| 5608 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5609 | iwl3945_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5610 | mutex_unlock(&priv->mutex); |
| 5611 | } |
| 5612 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5613 | static void iwl3945_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5614 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5615 | struct iwl_priv *priv = |
| 5616 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5617 | |
| 5618 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5619 | return; |
| 5620 | |
| 5621 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5622 | iwl3945_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5623 | mutex_unlock(&priv->mutex); |
| 5624 | } |
| 5625 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5626 | static void iwl3945_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5627 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5628 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5629 | |
| 5630 | wake_up_interruptible(&priv->wait_command_queue); |
| 5631 | |
| 5632 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5633 | return; |
| 5634 | |
| 5635 | mutex_lock(&priv->mutex); |
| 5636 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5637 | if (!iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5638 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 5639 | "HW and/or SW RF Kill no longer active, restarting " |
| 5640 | "device\n"); |
| 5641 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5642 | queue_work(priv->workqueue, &priv->restart); |
| 5643 | } else { |
| 5644 | |
| 5645 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5646 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 5647 | "disabled by SW switch\n"); |
| 5648 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5649 | IWL_WARN(priv, "Radio Frequency Kill Switch is On:\n" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5650 | "Kill switch must be turned off for " |
| 5651 | "wireless networking to work.\n"); |
| 5652 | } |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5653 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5654 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5655 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 5659 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5660 | static void iwl3945_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5661 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5662 | struct iwl_priv *priv = |
| 5663 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5664 | |
| 5665 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5666 | return; |
| 5667 | |
| 5668 | mutex_lock(&priv->mutex); |
| 5669 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 5670 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5671 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 5672 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 5673 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5674 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5675 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5676 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5677 | } |
| 5678 | mutex_unlock(&priv->mutex); |
| 5679 | } |
| 5680 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5681 | static void iwl3945_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5682 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5683 | struct iwl_priv *priv = |
| 5684 | container_of(data, struct iwl_priv, request_scan); |
Winkler, Tomas | c2d79b48 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 5685 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5686 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5687 | .len = sizeof(struct iwl3945_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5688 | .meta.flags = CMD_SIZE_HUGE, |
| 5689 | }; |
| 5690 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5691 | struct iwl3945_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5692 | struct ieee80211_conf *conf = NULL; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5693 | u8 n_probes = 2; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5694 | enum ieee80211_band band; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5695 | DECLARE_SSID_BUF(ssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5696 | |
| 5697 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5698 | |
| 5699 | mutex_lock(&priv->mutex); |
| 5700 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5701 | if (!iwl_is_ready(priv)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5702 | IWL_WARN(priv, "request scan called when driver not ready.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5703 | goto done; |
| 5704 | } |
| 5705 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5706 | /* Make sure the scan wasn't canceled before this queued work |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5707 | * was given the chance to run... */ |
| 5708 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 5709 | goto done; |
| 5710 | |
| 5711 | /* This should never be called or scheduled if there is currently |
| 5712 | * a scan active in the hardware. */ |
| 5713 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 5714 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 5715 | "Ignoring second request.\n"); |
| 5716 | rc = -EIO; |
| 5717 | goto done; |
| 5718 | } |
| 5719 | |
| 5720 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 5721 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 5722 | goto done; |
| 5723 | } |
| 5724 | |
| 5725 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5726 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 5727 | goto done; |
| 5728 | } |
| 5729 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 5730 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5731 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 5732 | goto done; |
| 5733 | } |
| 5734 | |
| 5735 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 5736 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 5737 | goto done; |
| 5738 | } |
| 5739 | |
| 5740 | if (!priv->scan_bands) { |
| 5741 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 5742 | goto done; |
| 5743 | } |
| 5744 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5745 | if (!priv->scan39) { |
| 5746 | priv->scan39 = kmalloc(sizeof(struct iwl3945_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5747 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5748 | if (!priv->scan39) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5749 | rc = -ENOMEM; |
| 5750 | goto done; |
| 5751 | } |
| 5752 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5753 | scan = priv->scan39; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5754 | memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5755 | |
| 5756 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 5757 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 5758 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5759 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5760 | u16 interval = 0; |
| 5761 | u32 extra; |
| 5762 | u32 suspend_time = 100; |
| 5763 | u32 scan_suspend_time = 100; |
| 5764 | unsigned long flags; |
| 5765 | |
| 5766 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 5767 | |
| 5768 | spin_lock_irqsave(&priv->lock, flags); |
| 5769 | interval = priv->beacon_int; |
| 5770 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5771 | |
| 5772 | scan->suspend_time = 0; |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5773 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5774 | if (!interval) |
| 5775 | interval = suspend_time; |
| 5776 | /* |
| 5777 | * suspend time format: |
| 5778 | * 0-19: beacon interval in usec (time before exec.) |
| 5779 | * 20-23: 0 |
| 5780 | * 24-31: number of beacons (suspend between channels) |
| 5781 | */ |
| 5782 | |
| 5783 | extra = (suspend_time / interval) << 24; |
| 5784 | scan_suspend_time = 0xFF0FFFFF & |
| 5785 | (extra | ((suspend_time % interval) * 1024)); |
| 5786 | |
| 5787 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 5788 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 5789 | scan_suspend_time, interval); |
| 5790 | } |
| 5791 | |
| 5792 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 5793 | if (priv->one_direct_scan) { |
| 5794 | IWL_DEBUG_SCAN |
| 5795 | ("Kicking off one direct scan for '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5796 | print_ssid(ssid, priv->direct_ssid, |
| 5797 | priv->direct_ssid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5798 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 5799 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 5800 | memcpy(scan->direct_scan[0].ssid, |
| 5801 | priv->direct_ssid, priv->direct_ssid_len); |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5802 | n_probes++; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5803 | } else |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5804 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5805 | |
| 5806 | /* We don't build a direct scan probe request; the uCode will do |
| 5807 | * that based on the direct_mask added to each channel entry */ |
| 5808 | scan->tx_cmd.len = cpu_to_le16( |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5809 | iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 5810 | IWL_MAX_SCAN_SIZE - sizeof(*scan))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5811 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 5812 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5813 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 5814 | |
| 5815 | /* flags + rate selection */ |
| 5816 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5817 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5818 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 5819 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; |
| 5820 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5821 | band = IEEE80211_BAND_2GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5822 | } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5823 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; |
| 5824 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5825 | band = IEEE80211_BAND_5GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 5826 | } else { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5827 | IWL_WARN(priv, "Invalid scan band count\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5828 | goto done; |
| 5829 | } |
| 5830 | |
| 5831 | /* select Rx antennas */ |
| 5832 | scan->flags |= iwl3945_get_antenna_flags(priv); |
| 5833 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5834 | if (priv->iw_mode == NL80211_IFTYPE_MONITOR) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5835 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 5836 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5837 | scan->channel_count = |
| 5838 | iwl3945_get_channels_for_scan(priv, band, 1, /* active */ |
| 5839 | n_probes, |
| 5840 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5841 | |
Reinette Chatre | 14b5433 | 2008-11-04 12:21:35 -0800 | [diff] [blame] | 5842 | if (scan->channel_count == 0) { |
| 5843 | IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count); |
| 5844 | goto done; |
| 5845 | } |
| 5846 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5847 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5848 | scan->channel_count * sizeof(struct iwl3945_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5849 | cmd.data = scan; |
| 5850 | scan->len = cpu_to_le16(cmd.len); |
| 5851 | |
| 5852 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5853 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5854 | if (rc) |
| 5855 | goto done; |
| 5856 | |
| 5857 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 5858 | IWL_SCAN_CHECK_WATCHDOG); |
| 5859 | |
| 5860 | mutex_unlock(&priv->mutex); |
| 5861 | return; |
| 5862 | |
| 5863 | done: |
Mohamed Abbas | 2420ebc | 2008-11-04 12:21:34 -0800 | [diff] [blame] | 5864 | /* can not perform scan make sure we clear scanning |
| 5865 | * bits from status so next scan request can be performed. |
| 5866 | * if we dont clear scanning status bit here all next scan |
| 5867 | * will fail |
| 5868 | */ |
| 5869 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 5870 | clear_bit(STATUS_SCANNING, &priv->status); |
| 5871 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 5872 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5873 | queue_work(priv->workqueue, &priv->scan_completed); |
| 5874 | mutex_unlock(&priv->mutex); |
| 5875 | } |
| 5876 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5877 | static void iwl3945_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5878 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5879 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5880 | |
| 5881 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5882 | return; |
| 5883 | |
| 5884 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5885 | __iwl3945_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5886 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5887 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5888 | } |
| 5889 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5890 | static void iwl3945_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5891 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5892 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5893 | |
| 5894 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5895 | return; |
| 5896 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5897 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5898 | queue_work(priv->workqueue, &priv->up); |
| 5899 | } |
| 5900 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5901 | static void iwl3945_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5902 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5903 | struct iwl_priv *priv = |
| 5904 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5905 | |
| 5906 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5907 | return; |
| 5908 | |
| 5909 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5910 | iwl3945_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5911 | mutex_unlock(&priv->mutex); |
| 5912 | } |
| 5913 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5914 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 5915 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5916 | static void iwl3945_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5917 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5918 | int rc = 0; |
| 5919 | struct ieee80211_conf *conf = NULL; |
| 5920 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5921 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5922 | 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] | 5923 | return; |
| 5924 | } |
| 5925 | |
| 5926 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 5927 | IWL_DEBUG_ASSOC("Associated as %d to: %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5928 | priv->assoc_id, priv->active39_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5929 | |
| 5930 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5931 | return; |
| 5932 | |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 5933 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5934 | return; |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 5935 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5936 | iwl3945_scan_cancel_timeout(priv, 200); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5937 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5938 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5939 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5940 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5941 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5942 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 5943 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5944 | iwl3945_setup_rxon_timing(priv); |
| 5945 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5946 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 5947 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5948 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5949 | "Attempting to continue.\n"); |
| 5950 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5951 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5952 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5953 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5954 | |
| 5955 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 5956 | priv->assoc_id, priv->beacon_int); |
| 5957 | |
| 5958 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5959 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5960 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5961 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5962 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5963 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5964 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5965 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5966 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5967 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5968 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5969 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5970 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5971 | |
| 5972 | } |
| 5973 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5974 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5975 | |
| 5976 | switch (priv->iw_mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5977 | case NL80211_IFTYPE_STATION: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5978 | iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5979 | break; |
| 5980 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 5981 | case NL80211_IFTYPE_ADHOC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5982 | |
Abhijeet Kolekar | ce546fd | 2008-11-19 15:32:22 -0800 | [diff] [blame] | 5983 | priv->assoc_id = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5984 | iwl3945_add_station(priv, priv->bssid, 0, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5985 | iwl3945_sync_sta(priv, IWL_STA_ID, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5986 | (priv->band == IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5987 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, |
| 5988 | CMD_ASYNC); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5989 | iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); |
| 5990 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5991 | |
| 5992 | break; |
| 5993 | |
| 5994 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5995 | IWL_ERR(priv, "%s Should not be called in %d mode\n", |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 5996 | __func__, priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5997 | break; |
| 5998 | } |
| 5999 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6000 | iwl3945_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 6001 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6002 | /* we have just associated, don't start scan too early */ |
| 6003 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6004 | } |
| 6005 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6006 | static void iwl3945_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6007 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6008 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6009 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6010 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6011 | return; |
| 6012 | |
| 6013 | mutex_lock(&priv->mutex); |
| 6014 | |
| 6015 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6016 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6017 | |
| 6018 | mutex_unlock(&priv->mutex); |
| 6019 | } |
| 6020 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6021 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6022 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6023 | static void iwl3945_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6024 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6025 | struct iwl_priv *priv = |
| 6026 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6027 | |
| 6028 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 6029 | |
| 6030 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6031 | return; |
| 6032 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6033 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6034 | iwl3945_mac_config(priv->hw, 0); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6035 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6036 | ieee80211_scan_completed(priv->hw); |
| 6037 | |
| 6038 | /* Since setting the TXPOWER may have been deferred while |
| 6039 | * performing the scan, fire one off */ |
| 6040 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6041 | iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6042 | mutex_unlock(&priv->mutex); |
| 6043 | } |
| 6044 | |
| 6045 | /***************************************************************************** |
| 6046 | * |
| 6047 | * mac80211 entry point functions |
| 6048 | * |
| 6049 | *****************************************************************************/ |
| 6050 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6051 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 6052 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6053 | static int iwl3945_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6054 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6055 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6056 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6057 | |
| 6058 | IWL_DEBUG_MAC80211("enter\n"); |
| 6059 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6060 | if (pci_enable_device(priv->pci_dev)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6061 | IWL_ERR(priv, "Fail to pci_enable_device\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6062 | return -ENODEV; |
| 6063 | } |
| 6064 | pci_restore_state(priv->pci_dev); |
| 6065 | pci_enable_msi(priv->pci_dev); |
| 6066 | |
| 6067 | ret = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED, |
| 6068 | DRV_NAME, priv); |
| 6069 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6070 | IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6071 | goto out_disable_msi; |
| 6072 | } |
| 6073 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6074 | /* we should be verifying the device is ready to be opened */ |
| 6075 | mutex_lock(&priv->mutex); |
| 6076 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6077 | memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6078 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 6079 | * ucode filename and max sizes are card-specific. */ |
| 6080 | |
| 6081 | if (!priv->ucode_code.len) { |
| 6082 | ret = iwl3945_read_ucode(priv); |
| 6083 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6084 | IWL_ERR(priv, "Could not read microcode: %d\n", ret); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6085 | mutex_unlock(&priv->mutex); |
| 6086 | goto out_release_irq; |
| 6087 | } |
| 6088 | } |
| 6089 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6090 | ret = __iwl3945_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6091 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6092 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6093 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 6094 | iwl3945_rfkill_set_hw_state(priv); |
| 6095 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6096 | if (ret) |
| 6097 | goto out_release_irq; |
| 6098 | |
| 6099 | IWL_DEBUG_INFO("Start UP work.\n"); |
| 6100 | |
| 6101 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 6102 | return 0; |
| 6103 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6104 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 6105 | * mac80211 will not be run successfully. */ |
| 6106 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 6107 | test_bit(STATUS_READY, &priv->status), |
| 6108 | UCODE_READY_TIMEOUT); |
| 6109 | if (!ret) { |
| 6110 | if (!test_bit(STATUS_READY, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6111 | IWL_ERR(priv, |
| 6112 | "Wait for START_ALIVE timeout after %dms.\n", |
| 6113 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6114 | ret = -ETIMEDOUT; |
| 6115 | goto out_release_irq; |
| 6116 | } |
| 6117 | } |
| 6118 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6119 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6120 | IWL_DEBUG_MAC80211("leave\n"); |
| 6121 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6122 | |
| 6123 | out_release_irq: |
| 6124 | free_irq(priv->pci_dev->irq, priv); |
| 6125 | out_disable_msi: |
| 6126 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6127 | pci_disable_device(priv->pci_dev); |
| 6128 | priv->is_open = 0; |
| 6129 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6130 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6131 | } |
| 6132 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6133 | static void iwl3945_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6134 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6135 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6136 | |
| 6137 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6138 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6139 | if (!priv->is_open) { |
| 6140 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 6141 | return; |
| 6142 | } |
| 6143 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6144 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6145 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6146 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6147 | /* stop mac, cancel any scan request and clear |
| 6148 | * RXON_FILTER_ASSOC_MSK BIT |
| 6149 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6150 | mutex_lock(&priv->mutex); |
| 6151 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6152 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6153 | } |
| 6154 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6155 | iwl3945_down(priv); |
| 6156 | |
| 6157 | flush_workqueue(priv->workqueue); |
| 6158 | free_irq(priv->pci_dev->irq, priv); |
| 6159 | pci_disable_msi(priv->pci_dev); |
| 6160 | pci_save_state(priv->pci_dev); |
| 6161 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6162 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6163 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6164 | } |
| 6165 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6166 | 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] | 6167 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6168 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6169 | |
| 6170 | IWL_DEBUG_MAC80211("enter\n"); |
| 6171 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6172 | 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] | 6173 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6174 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6175 | if (iwl3945_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6176 | dev_kfree_skb_any(skb); |
| 6177 | |
| 6178 | IWL_DEBUG_MAC80211("leave\n"); |
Reinette Chatre | 637f883 | 2009-01-19 15:30:32 -0800 | [diff] [blame] | 6179 | return NETDEV_TX_OK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6180 | } |
| 6181 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6182 | static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6183 | struct ieee80211_if_init_conf *conf) |
| 6184 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6185 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6186 | unsigned long flags; |
| 6187 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6188 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6189 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6190 | if (priv->vif) { |
| 6191 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6192 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6196 | priv->vif = conf->vif; |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 6197 | priv->iw_mode = conf->type; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6198 | |
| 6199 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6200 | |
| 6201 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6202 | |
| 6203 | if (conf->mac_addr) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6204 | IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6205 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 6206 | } |
| 6207 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6208 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6209 | iwl3945_set_mode(priv, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6210 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6211 | mutex_unlock(&priv->mutex); |
| 6212 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6213 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6214 | return 0; |
| 6215 | } |
| 6216 | |
| 6217 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6218 | * iwl3945_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6219 | * |
| 6220 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 6221 | * be set inappropriately and the driver currently sets the hardware up to |
| 6222 | * use it whenever needed. |
| 6223 | */ |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6224 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6225 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6226 | struct iwl_priv *priv = hw->priv; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6227 | const struct iwl_channel_info *ch_info; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6228 | struct ieee80211_conf *conf = &hw->conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6229 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6230 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6231 | |
| 6232 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6233 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6234 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6235 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6236 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6237 | ret = -EIO; |
| 6238 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6239 | } |
| 6240 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 6241 | if (unlikely(!iwl3945_mod_params.disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6242 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6243 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 6244 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6245 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6246 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6247 | } |
| 6248 | |
| 6249 | spin_lock_irqsave(&priv->lock, flags); |
| 6250 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6251 | ch_info = iwl3945_get_channel_info(priv, conf->channel->band, |
| 6252 | conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6253 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 6254 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6255 | conf->channel->hw_value, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6256 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 6257 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6258 | ret = -EINVAL; |
| 6259 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6260 | } |
| 6261 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6262 | iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6263 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6264 | iwl3945_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6265 | |
| 6266 | /* The list of supported rates and rate mask can be different |
| 6267 | * for each phymode; since the phymode may have changed, reset |
| 6268 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6269 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6270 | |
| 6271 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6272 | |
| 6273 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 6274 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6275 | iwl3945_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6276 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6277 | } |
| 6278 | #endif |
| 6279 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6280 | iwl3945_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6281 | |
| 6282 | if (!conf->radio_enabled) { |
| 6283 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6284 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6285 | } |
| 6286 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6287 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6288 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6289 | ret = -EIO; |
| 6290 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6291 | } |
| 6292 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6293 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6294 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6295 | if (memcmp(&priv->active39_rxon, |
| 6296 | &priv->staging39_rxon, sizeof(priv->staging39_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6297 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6298 | else |
| 6299 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 6300 | |
| 6301 | IWL_DEBUG_MAC80211("leave\n"); |
| 6302 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6303 | out: |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6304 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6305 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6306 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6307 | } |
| 6308 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6309 | static void iwl3945_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6310 | { |
| 6311 | int rc = 0; |
| 6312 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 6313 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6314 | return; |
| 6315 | |
| 6316 | /* The following should be done only at AP bring up */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 6317 | if (!(iwl3945_is_associated(priv))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6318 | |
| 6319 | /* RXON - unassoc (to set timing command) */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6320 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6321 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6322 | |
| 6323 | /* RXON Timing */ |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6324 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6325 | iwl3945_setup_rxon_timing(priv); |
| 6326 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6327 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 6328 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6329 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6330 | "Attempting to continue.\n"); |
| 6331 | |
| 6332 | /* FIXME: what should be the assoc_id for AP? */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6333 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6334 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6335 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6336 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6337 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6338 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6339 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6340 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6341 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6342 | if (priv->assoc_capability & |
| 6343 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6344 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6345 | RXON_FLG_SHORT_SLOT_MSK; |
| 6346 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6347 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6348 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6349 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6350 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6351 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6352 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6353 | } |
| 6354 | /* restore RXON assoc */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6355 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6356 | iwl3945_commit_rxon(priv); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 6357 | iwl3945_add_station(priv, iwl_bcast_addr, 0, 0); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 6358 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6359 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6360 | |
| 6361 | /* FIXME - we need to add code here to detect a totally new |
| 6362 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 6363 | * clear sta table, add BCAST sta... */ |
| 6364 | } |
| 6365 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6366 | static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, |
| 6367 | struct ieee80211_vif *vif, |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6368 | struct ieee80211_if_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6369 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6370 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6371 | int rc; |
| 6372 | |
| 6373 | if (conf == NULL) |
| 6374 | return -EIO; |
| 6375 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6376 | if (priv->vif != vif) { |
| 6377 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6378 | return 0; |
| 6379 | } |
| 6380 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6381 | /* handle this temporarily here */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6382 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6383 | conf->changed & IEEE80211_IFCC_BEACON) { |
| 6384 | struct sk_buff *beacon = ieee80211_beacon_get(hw, vif); |
| 6385 | if (!beacon) |
| 6386 | return -ENOMEM; |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6387 | mutex_lock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6388 | rc = iwl3945_mac_beacon_update(hw, beacon); |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6389 | mutex_unlock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6390 | if (rc) |
| 6391 | return rc; |
| 6392 | } |
| 6393 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6394 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6395 | return -EAGAIN; |
| 6396 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6397 | mutex_lock(&priv->mutex); |
| 6398 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6399 | if (conf->bssid) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6400 | IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6401 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6402 | /* |
| 6403 | * very dubious code was here; the probe filtering flag is never set: |
| 6404 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6405 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 6406 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6407 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6408 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6409 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6410 | if (!conf->bssid) { |
| 6411 | conf->bssid = priv->mac_addr; |
| 6412 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6413 | IWL_DEBUG_MAC80211("bssid was set to: %pM\n", |
| 6414 | conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6415 | } |
| 6416 | if (priv->ibss_beacon) |
| 6417 | dev_kfree_skb(priv->ibss_beacon); |
| 6418 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6419 | priv->ibss_beacon = ieee80211_beacon_get(hw, vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6420 | } |
| 6421 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6422 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6423 | goto done; |
| 6424 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6425 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 6426 | !is_multicast_ether_addr(conf->bssid)) { |
| 6427 | /* If there is currently a HW scan going on in the background |
| 6428 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6429 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6430 | IWL_WARN(priv, "Aborted scan still in progress " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6431 | "after 100ms\n"); |
| 6432 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 6433 | mutex_unlock(&priv->mutex); |
| 6434 | return -EAGAIN; |
| 6435 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6436 | memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6437 | |
| 6438 | /* TODO: Audit driver for usage of these members and see |
| 6439 | * if mac80211 deprecates them (priv->bssid looks like it |
| 6440 | * shouldn't be there, but I haven't scanned the IBSS code |
| 6441 | * to verify) - jpk */ |
| 6442 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 6443 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6444 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6445 | iwl3945_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6446 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6447 | rc = iwl3945_commit_rxon(priv); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6448 | if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6449 | iwl3945_add_station(priv, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6450 | priv->active39_rxon.bssid_addr, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6451 | } |
| 6452 | |
| 6453 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6454 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6455 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6456 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6457 | } |
| 6458 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6459 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6460 | IWL_DEBUG_MAC80211("leave\n"); |
| 6461 | mutex_unlock(&priv->mutex); |
| 6462 | |
| 6463 | return 0; |
| 6464 | } |
| 6465 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6466 | static void iwl3945_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6467 | unsigned int changed_flags, |
| 6468 | unsigned int *total_flags, |
| 6469 | int mc_count, struct dev_addr_list *mc_list) |
| 6470 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6471 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6472 | __le32 *filter_flags = &priv->staging39_rxon.filter_flags; |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6473 | |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6474 | IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n", |
| 6475 | changed_flags, *total_flags); |
| 6476 | |
| 6477 | if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) { |
| 6478 | if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) |
| 6479 | *filter_flags |= RXON_FILTER_PROMISC_MSK; |
| 6480 | else |
| 6481 | *filter_flags &= ~RXON_FILTER_PROMISC_MSK; |
Abhijeet Kolekar | 5ec0397 | 2008-05-05 10:22:48 +0800 | [diff] [blame] | 6482 | } |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6483 | if (changed_flags & FIF_ALLMULTI) { |
| 6484 | if (*total_flags & FIF_ALLMULTI) |
| 6485 | *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK; |
| 6486 | else |
| 6487 | *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK; |
| 6488 | } |
| 6489 | if (changed_flags & FIF_CONTROL) { |
| 6490 | if (*total_flags & FIF_CONTROL) |
| 6491 | *filter_flags |= RXON_FILTER_CTL2HOST_MSK; |
| 6492 | else |
| 6493 | *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK; |
| 6494 | } |
| 6495 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 6496 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
| 6497 | *filter_flags |= RXON_FILTER_BCON_AWARE_MSK; |
| 6498 | else |
| 6499 | *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK; |
| 6500 | } |
| 6501 | |
| 6502 | /* We avoid iwl_commit_rxon here to commit the new filter flags |
| 6503 | * since mac80211 will call ieee80211_hw_config immediately. |
| 6504 | * (mc_list is not supported at this time). Otherwise, we need to |
| 6505 | * queue a background iwl_commit_rxon work. |
| 6506 | */ |
| 6507 | |
| 6508 | *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6509 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6510 | } |
| 6511 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6512 | static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6513 | struct ieee80211_if_init_conf *conf) |
| 6514 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6515 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6516 | |
| 6517 | IWL_DEBUG_MAC80211("enter\n"); |
| 6518 | |
| 6519 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6520 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6521 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6522 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6523 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6524 | iwl3945_commit_rxon(priv); |
| 6525 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6526 | if (priv->vif == conf->vif) { |
| 6527 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6528 | memset(priv->bssid, 0, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6529 | } |
| 6530 | mutex_unlock(&priv->mutex); |
| 6531 | |
| 6532 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6533 | } |
| 6534 | |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6535 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
| 6536 | |
| 6537 | static void iwl3945_bss_info_changed(struct ieee80211_hw *hw, |
| 6538 | struct ieee80211_vif *vif, |
| 6539 | struct ieee80211_bss_conf *bss_conf, |
| 6540 | u32 changes) |
| 6541 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6542 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6543 | |
| 6544 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 6545 | |
| 6546 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 6547 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 6548 | bss_conf->use_short_preamble); |
| 6549 | if (bss_conf->use_short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6550 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6551 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6552 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6553 | } |
| 6554 | |
| 6555 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
| 6556 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
| 6557 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6558 | priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6559 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6560 | priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6561 | } |
| 6562 | |
| 6563 | if (changes & BSS_CHANGED_ASSOC) { |
| 6564 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
| 6565 | /* This should never happen as this function should |
| 6566 | * never be called from interrupt context. */ |
| 6567 | if (WARN_ON_ONCE(in_interrupt())) |
| 6568 | return; |
| 6569 | if (bss_conf->assoc) { |
| 6570 | priv->assoc_id = bss_conf->aid; |
| 6571 | priv->beacon_int = bss_conf->beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6572 | priv->timestamp = bss_conf->timestamp; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6573 | priv->assoc_capability = bss_conf->assoc_capability; |
| 6574 | priv->next_scan_jiffies = jiffies + |
| 6575 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
| 6576 | mutex_lock(&priv->mutex); |
| 6577 | iwl3945_post_associate(priv); |
| 6578 | mutex_unlock(&priv->mutex); |
| 6579 | } else { |
| 6580 | priv->assoc_id = 0; |
| 6581 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 6582 | } |
| 6583 | } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) { |
| 6584 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
| 6585 | iwl3945_send_rxon_assoc(priv); |
| 6586 | } |
| 6587 | |
| 6588 | } |
| 6589 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6590 | 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] | 6591 | { |
| 6592 | int rc = 0; |
| 6593 | unsigned long flags; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6594 | struct iwl_priv *priv = hw->priv; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6595 | DECLARE_SSID_BUF(ssid_buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6596 | |
| 6597 | IWL_DEBUG_MAC80211("enter\n"); |
| 6598 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6599 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6600 | spin_lock_irqsave(&priv->lock, flags); |
| 6601 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6602 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6603 | rc = -EIO; |
| 6604 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 6605 | goto out_unlock; |
| 6606 | } |
| 6607 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6608 | /* we don't schedule scan within next_scan_jiffies period */ |
| 6609 | if (priv->next_scan_jiffies && |
| 6610 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 6611 | rc = -EAGAIN; |
| 6612 | goto out_unlock; |
| 6613 | } |
Bill Moss | 15dbf1b | 2008-05-06 11:05:15 +0800 | [diff] [blame] | 6614 | /* if we just finished scan ask for delay for a broadcast scan */ |
| 6615 | if ((len == 0) && priv->last_scan_jiffies && |
| 6616 | time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, |
| 6617 | jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6618 | rc = -EAGAIN; |
| 6619 | goto out_unlock; |
| 6620 | } |
| 6621 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6622 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6623 | print_ssid(ssid_buf, ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6624 | |
| 6625 | priv->one_direct_scan = 1; |
| 6626 | priv->direct_ssid_len = (u8) |
| 6627 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 6628 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6629 | } else |
| 6630 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6631 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6632 | rc = iwl3945_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6633 | |
| 6634 | IWL_DEBUG_MAC80211("leave\n"); |
| 6635 | |
| 6636 | out_unlock: |
| 6637 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6638 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6639 | |
| 6640 | return rc; |
| 6641 | } |
| 6642 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6643 | static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6644 | const u8 *local_addr, const u8 *addr, |
| 6645 | struct ieee80211_key_conf *key) |
| 6646 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6647 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6648 | int rc = 0; |
| 6649 | u8 sta_id; |
| 6650 | |
| 6651 | IWL_DEBUG_MAC80211("enter\n"); |
| 6652 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 6653 | if (iwl3945_mod_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6654 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 6655 | return -EOPNOTSUPP; |
| 6656 | } |
| 6657 | |
| 6658 | if (is_zero_ether_addr(addr)) |
| 6659 | /* only support pairwise keys */ |
| 6660 | return -EOPNOTSUPP; |
| 6661 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6662 | sta_id = iwl3945_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6663 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6664 | IWL_DEBUG_MAC80211("leave - %pM not in station map.\n", |
| 6665 | addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6666 | return -EINVAL; |
| 6667 | } |
| 6668 | |
| 6669 | mutex_lock(&priv->mutex); |
| 6670 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6671 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6672 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6673 | switch (cmd) { |
| 6674 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6675 | rc = iwl3945_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6676 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6677 | iwl3945_set_rxon_hwcrypto(priv, 1); |
| 6678 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6679 | key->hw_key_idx = sta_id; |
| 6680 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 6681 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 6682 | } |
| 6683 | break; |
| 6684 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6685 | rc = iwl3945_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6686 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6687 | iwl3945_set_rxon_hwcrypto(priv, 0); |
| 6688 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6689 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 6690 | } |
| 6691 | break; |
| 6692 | default: |
| 6693 | rc = -EINVAL; |
| 6694 | } |
| 6695 | |
| 6696 | IWL_DEBUG_MAC80211("leave\n"); |
| 6697 | mutex_unlock(&priv->mutex); |
| 6698 | |
| 6699 | return rc; |
| 6700 | } |
| 6701 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 6702 | static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6703 | const struct ieee80211_tx_queue_params *params) |
| 6704 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6705 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6706 | unsigned long flags; |
| 6707 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6708 | |
| 6709 | IWL_DEBUG_MAC80211("enter\n"); |
| 6710 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6711 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6712 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6713 | return -EIO; |
| 6714 | } |
| 6715 | |
| 6716 | if (queue >= AC_NUM) { |
| 6717 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 6718 | return 0; |
| 6719 | } |
| 6720 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6721 | q = AC_NUM - 1 - queue; |
| 6722 | |
| 6723 | spin_lock_irqsave(&priv->lock, flags); |
| 6724 | |
| 6725 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 6726 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 6727 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 6728 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 6729 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6730 | |
| 6731 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 6732 | priv->qos_data.qos_active = 1; |
| 6733 | |
| 6734 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6735 | |
| 6736 | mutex_lock(&priv->mutex); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6737 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6738 | iwl3945_activate_qos(priv, 1); |
| 6739 | else if (priv->assoc_id && iwl3945_is_associated(priv)) |
| 6740 | iwl3945_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6741 | |
| 6742 | mutex_unlock(&priv->mutex); |
| 6743 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6744 | IWL_DEBUG_MAC80211("leave\n"); |
| 6745 | return 0; |
| 6746 | } |
| 6747 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6748 | static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6749 | struct ieee80211_tx_queue_stats *stats) |
| 6750 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6751 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6752 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6753 | struct iwl3945_tx_queue *txq; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6754 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6755 | unsigned long flags; |
| 6756 | |
| 6757 | IWL_DEBUG_MAC80211("enter\n"); |
| 6758 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6759 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6760 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6761 | return -EIO; |
| 6762 | } |
| 6763 | |
| 6764 | spin_lock_irqsave(&priv->lock, flags); |
| 6765 | |
| 6766 | for (i = 0; i < AC_NUM; i++) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6767 | txq = &priv->txq39[i]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6768 | q = &txq->q; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6769 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6770 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 6771 | stats[i].len = q->n_window - avail; |
| 6772 | stats[i].limit = q->n_window - q->high_mark; |
| 6773 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6774 | |
| 6775 | } |
| 6776 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6777 | |
| 6778 | IWL_DEBUG_MAC80211("leave\n"); |
| 6779 | |
| 6780 | return 0; |
| 6781 | } |
| 6782 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6783 | static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6784 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6785 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6786 | unsigned long flags; |
| 6787 | |
| 6788 | mutex_lock(&priv->mutex); |
| 6789 | IWL_DEBUG_MAC80211("enter\n"); |
| 6790 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6791 | iwl_reset_qos(priv); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 6792 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6793 | spin_lock_irqsave(&priv->lock, flags); |
| 6794 | priv->assoc_id = 0; |
| 6795 | priv->assoc_capability = 0; |
| 6796 | priv->call_post_assoc_from_beacon = 0; |
| 6797 | |
| 6798 | /* new association get rid of ibss beacon skb */ |
| 6799 | if (priv->ibss_beacon) |
| 6800 | dev_kfree_skb(priv->ibss_beacon); |
| 6801 | |
| 6802 | priv->ibss_beacon = NULL; |
| 6803 | |
| 6804 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6805 | priv->timestamp = 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6806 | if ((priv->iw_mode == NL80211_IFTYPE_STATION)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6807 | priv->beacon_int = 0; |
| 6808 | |
| 6809 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6810 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6811 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6812 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 6813 | mutex_unlock(&priv->mutex); |
| 6814 | return; |
| 6815 | } |
| 6816 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6817 | /* we are restarting association process |
| 6818 | * clear RXON_FILTER_ASSOC_MSK bit |
| 6819 | */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6820 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6821 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6822 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6823 | iwl3945_commit_rxon(priv); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6824 | } |
| 6825 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6826 | /* Per mac80211.h: This is only used in IBSS mode... */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6827 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6828 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6829 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 6830 | mutex_unlock(&priv->mutex); |
| 6831 | return; |
| 6832 | } |
| 6833 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6834 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6835 | |
| 6836 | mutex_unlock(&priv->mutex); |
| 6837 | |
| 6838 | IWL_DEBUG_MAC80211("leave\n"); |
| 6839 | |
| 6840 | } |
| 6841 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6842 | 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] | 6843 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6844 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6845 | unsigned long flags; |
| 6846 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6847 | IWL_DEBUG_MAC80211("enter\n"); |
| 6848 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6849 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6850 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6851 | return -EIO; |
| 6852 | } |
| 6853 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6854 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6855 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6856 | return -EIO; |
| 6857 | } |
| 6858 | |
| 6859 | spin_lock_irqsave(&priv->lock, flags); |
| 6860 | |
| 6861 | if (priv->ibss_beacon) |
| 6862 | dev_kfree_skb(priv->ibss_beacon); |
| 6863 | |
| 6864 | priv->ibss_beacon = skb; |
| 6865 | |
| 6866 | priv->assoc_id = 0; |
| 6867 | |
| 6868 | IWL_DEBUG_MAC80211("leave\n"); |
| 6869 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6870 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6871 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6872 | |
Abhijeet Kolekar | dc4b1e7 | 2008-09-03 11:26:30 +0800 | [diff] [blame] | 6873 | iwl3945_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6874 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6875 | |
| 6876 | return 0; |
| 6877 | } |
| 6878 | |
| 6879 | /***************************************************************************** |
| 6880 | * |
| 6881 | * sysfs attributes |
| 6882 | * |
| 6883 | *****************************************************************************/ |
| 6884 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6885 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6886 | |
| 6887 | /* |
| 6888 | * The following adds a new attribute to the sysfs representation |
| 6889 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 6890 | * used for controlling the debug level. |
| 6891 | * |
| 6892 | * See the level definitions in iwl for details. |
| 6893 | */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6894 | static ssize_t show_debug_level(struct device *d, |
| 6895 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6896 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6897 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6898 | |
| 6899 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6900 | } |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6901 | static ssize_t store_debug_level(struct device *d, |
| 6902 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6903 | const char *buf, size_t count) |
| 6904 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6905 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6906 | unsigned long val; |
| 6907 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6908 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6909 | ret = strict_strtoul(buf, 0, &val); |
| 6910 | if (ret) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 6911 | 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] | 6912 | else |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6913 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6914 | |
| 6915 | return strnlen(buf, count); |
| 6916 | } |
| 6917 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 6918 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 6919 | show_debug_level, store_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6920 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6921 | #endif /* CONFIG_IWL3945_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6922 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6923 | static ssize_t show_temperature(struct device *d, |
| 6924 | struct device_attribute *attr, char *buf) |
| 6925 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6926 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6927 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 6928 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6929 | return -EAGAIN; |
| 6930 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6931 | return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6932 | } |
| 6933 | |
| 6934 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 6935 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6936 | static ssize_t show_tx_power(struct device *d, |
| 6937 | struct device_attribute *attr, char *buf) |
| 6938 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6939 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6940 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 6941 | } |
| 6942 | |
| 6943 | static ssize_t store_tx_power(struct device *d, |
| 6944 | struct device_attribute *attr, |
| 6945 | const char *buf, size_t count) |
| 6946 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6947 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6948 | char *p = (char *)buf; |
| 6949 | u32 val; |
| 6950 | |
| 6951 | val = simple_strtoul(p, &p, 10); |
| 6952 | if (p == buf) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 6953 | IWL_INFO(priv, ": %s is not in decimal form.\n", buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6954 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6955 | iwl3945_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6956 | |
| 6957 | return count; |
| 6958 | } |
| 6959 | |
| 6960 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 6961 | |
| 6962 | static ssize_t show_flags(struct device *d, |
| 6963 | struct device_attribute *attr, char *buf) |
| 6964 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6965 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6966 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6967 | return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | static ssize_t store_flags(struct device *d, |
| 6971 | struct device_attribute *attr, |
| 6972 | const char *buf, size_t count) |
| 6973 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6974 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6975 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 6976 | |
| 6977 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6978 | if (le32_to_cpu(priv->staging39_rxon.flags) != flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6979 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6980 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6981 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6982 | else { |
| 6983 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 6984 | flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6985 | priv->staging39_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6986 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6987 | } |
| 6988 | } |
| 6989 | mutex_unlock(&priv->mutex); |
| 6990 | |
| 6991 | return count; |
| 6992 | } |
| 6993 | |
| 6994 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 6995 | |
| 6996 | static ssize_t show_filter_flags(struct device *d, |
| 6997 | struct device_attribute *attr, char *buf) |
| 6998 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6999 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7000 | |
| 7001 | return sprintf(buf, "0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7002 | le32_to_cpu(priv->active39_rxon.filter_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7003 | } |
| 7004 | |
| 7005 | static ssize_t store_filter_flags(struct device *d, |
| 7006 | struct device_attribute *attr, |
| 7007 | const char *buf, size_t count) |
| 7008 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7009 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7010 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 7011 | |
| 7012 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7013 | if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7014 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7015 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 7016 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7017 | else { |
| 7018 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 7019 | "0x%04X\n", filter_flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7020 | priv->staging39_rxon.filter_flags = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7021 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7022 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7023 | } |
| 7024 | } |
| 7025 | mutex_unlock(&priv->mutex); |
| 7026 | |
| 7027 | return count; |
| 7028 | } |
| 7029 | |
| 7030 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 7031 | store_filter_flags); |
| 7032 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7033 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7034 | |
| 7035 | static ssize_t show_measurement(struct device *d, |
| 7036 | struct device_attribute *attr, char *buf) |
| 7037 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7038 | struct iwl_priv *priv = dev_get_drvdata(d); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 7039 | struct iwl_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7040 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7041 | u8 *data = (u8 *)&measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7042 | unsigned long flags; |
| 7043 | |
| 7044 | spin_lock_irqsave(&priv->lock, flags); |
| 7045 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 7046 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7047 | return 0; |
| 7048 | } |
| 7049 | memcpy(&measure_report, &priv->measure_report, size); |
| 7050 | priv->measurement_status = 0; |
| 7051 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7052 | |
| 7053 | while (size && (PAGE_SIZE - len)) { |
| 7054 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7055 | PAGE_SIZE - len, 1); |
| 7056 | len = strlen(buf); |
| 7057 | if (PAGE_SIZE - len) |
| 7058 | buf[len++] = '\n'; |
| 7059 | |
| 7060 | ofs += 16; |
| 7061 | size -= min(size, 16U); |
| 7062 | } |
| 7063 | |
| 7064 | return len; |
| 7065 | } |
| 7066 | |
| 7067 | static ssize_t store_measurement(struct device *d, |
| 7068 | struct device_attribute *attr, |
| 7069 | const char *buf, size_t count) |
| 7070 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7071 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7072 | struct ieee80211_measurement_params params = { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7073 | .channel = le16_to_cpu(priv->active39_rxon.channel), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7074 | .start_time = cpu_to_le64(priv->last_tsf), |
| 7075 | .duration = cpu_to_le16(1), |
| 7076 | }; |
| 7077 | u8 type = IWL_MEASURE_BASIC; |
| 7078 | u8 buffer[32]; |
| 7079 | u8 channel; |
| 7080 | |
| 7081 | if (count) { |
| 7082 | char *p = buffer; |
| 7083 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 7084 | channel = simple_strtoul(p, NULL, 0); |
| 7085 | if (channel) |
| 7086 | params.channel = channel; |
| 7087 | |
| 7088 | p = buffer; |
| 7089 | while (*p && *p != ' ') |
| 7090 | p++; |
| 7091 | if (*p) |
| 7092 | type = simple_strtoul(p + 1, NULL, 0); |
| 7093 | } |
| 7094 | |
| 7095 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 7096 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7097 | iwl3945_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7098 | |
| 7099 | return count; |
| 7100 | } |
| 7101 | |
| 7102 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 7103 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7104 | #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7105 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7106 | static ssize_t store_retry_rate(struct device *d, |
| 7107 | struct device_attribute *attr, |
| 7108 | const char *buf, size_t count) |
| 7109 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7110 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7111 | |
| 7112 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 7113 | if (priv->retry_rate <= 0) |
| 7114 | priv->retry_rate = 1; |
| 7115 | |
| 7116 | return count; |
| 7117 | } |
| 7118 | |
| 7119 | static ssize_t show_retry_rate(struct device *d, |
| 7120 | struct device_attribute *attr, char *buf) |
| 7121 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7122 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7123 | return sprintf(buf, "%d", priv->retry_rate); |
| 7124 | } |
| 7125 | |
| 7126 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 7127 | store_retry_rate); |
| 7128 | |
| 7129 | static ssize_t store_power_level(struct device *d, |
| 7130 | struct device_attribute *attr, |
| 7131 | const char *buf, size_t count) |
| 7132 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7133 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7134 | int rc; |
| 7135 | int mode; |
| 7136 | |
| 7137 | mode = simple_strtoul(buf, NULL, 0); |
| 7138 | mutex_lock(&priv->mutex); |
| 7139 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7140 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7141 | rc = -EAGAIN; |
| 7142 | goto out; |
| 7143 | } |
| 7144 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7145 | if ((mode < 1) || (mode > IWL39_POWER_LIMIT) || |
| 7146 | (mode == IWL39_POWER_AC)) |
| 7147 | mode = IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7148 | else |
| 7149 | mode |= IWL_POWER_ENABLED; |
| 7150 | |
| 7151 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7152 | rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7153 | if (rc) { |
| 7154 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 7155 | goto out; |
| 7156 | } |
| 7157 | priv->power_mode = mode; |
| 7158 | } |
| 7159 | |
| 7160 | rc = count; |
| 7161 | |
| 7162 | out: |
| 7163 | mutex_unlock(&priv->mutex); |
| 7164 | return rc; |
| 7165 | } |
| 7166 | |
| 7167 | #define MAX_WX_STRING 80 |
| 7168 | |
| 7169 | /* Values are in microsecond */ |
| 7170 | static const s32 timeout_duration[] = { |
| 7171 | 350000, |
| 7172 | 250000, |
| 7173 | 75000, |
| 7174 | 37000, |
| 7175 | 25000, |
| 7176 | }; |
| 7177 | static const s32 period_duration[] = { |
| 7178 | 400000, |
| 7179 | 700000, |
| 7180 | 1000000, |
| 7181 | 1000000, |
| 7182 | 1000000 |
| 7183 | }; |
| 7184 | |
| 7185 | static ssize_t show_power_level(struct device *d, |
| 7186 | struct device_attribute *attr, char *buf) |
| 7187 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7188 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7189 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 7190 | char *p = buf; |
| 7191 | |
| 7192 | p += sprintf(p, "%d ", level); |
| 7193 | switch (level) { |
| 7194 | case IWL_POWER_MODE_CAM: |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7195 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7196 | p += sprintf(p, "(AC)"); |
| 7197 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7198 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7199 | p += sprintf(p, "(BATTERY)"); |
| 7200 | break; |
| 7201 | default: |
| 7202 | p += sprintf(p, |
| 7203 | "(Timeout %dms, Period %dms)", |
| 7204 | timeout_duration[level - 1] / 1000, |
| 7205 | period_duration[level - 1] / 1000); |
| 7206 | } |
| 7207 | |
| 7208 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 7209 | p += sprintf(p, " OFF\n"); |
| 7210 | else |
| 7211 | p += sprintf(p, " \n"); |
| 7212 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7213 | return p - buf + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7214 | |
| 7215 | } |
| 7216 | |
| 7217 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 7218 | store_power_level); |
| 7219 | |
| 7220 | static ssize_t show_channels(struct device *d, |
| 7221 | struct device_attribute *attr, char *buf) |
| 7222 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7223 | /* all this shit doesn't belong into sysfs anyway */ |
| 7224 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7225 | } |
| 7226 | |
| 7227 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 7228 | |
| 7229 | static ssize_t show_statistics(struct device *d, |
| 7230 | struct device_attribute *attr, char *buf) |
| 7231 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7232 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7233 | u32 size = sizeof(struct iwl3945_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7234 | u32 len = 0, ofs = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7235 | u8 *data = (u8 *)&priv->statistics_39; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7236 | int rc = 0; |
| 7237 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7238 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7239 | return -EAGAIN; |
| 7240 | |
| 7241 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7242 | rc = iwl3945_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7243 | mutex_unlock(&priv->mutex); |
| 7244 | |
| 7245 | if (rc) { |
| 7246 | len = sprintf(buf, |
| 7247 | "Error sending statistics request: 0x%08X\n", rc); |
| 7248 | return len; |
| 7249 | } |
| 7250 | |
| 7251 | while (size && (PAGE_SIZE - len)) { |
| 7252 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7253 | PAGE_SIZE - len, 1); |
| 7254 | len = strlen(buf); |
| 7255 | if (PAGE_SIZE - len) |
| 7256 | buf[len++] = '\n'; |
| 7257 | |
| 7258 | ofs += 16; |
| 7259 | size -= min(size, 16U); |
| 7260 | } |
| 7261 | |
| 7262 | return len; |
| 7263 | } |
| 7264 | |
| 7265 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 7266 | |
| 7267 | static ssize_t show_antenna(struct device *d, |
| 7268 | struct device_attribute *attr, char *buf) |
| 7269 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7270 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7271 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7272 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7273 | return -EAGAIN; |
| 7274 | |
| 7275 | return sprintf(buf, "%d\n", priv->antenna); |
| 7276 | } |
| 7277 | |
| 7278 | static ssize_t store_antenna(struct device *d, |
| 7279 | struct device_attribute *attr, |
| 7280 | const char *buf, size_t count) |
| 7281 | { |
| 7282 | int ant; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7283 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7284 | |
| 7285 | if (count == 0) |
| 7286 | return 0; |
| 7287 | |
| 7288 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 7289 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 7290 | return count; |
| 7291 | } |
| 7292 | |
| 7293 | if ((ant >= 0) && (ant <= 2)) { |
| 7294 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7295 | priv->antenna = (enum iwl3945_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7296 | } else |
| 7297 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 7298 | |
| 7299 | |
| 7300 | return count; |
| 7301 | } |
| 7302 | |
| 7303 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 7304 | |
| 7305 | static ssize_t show_status(struct device *d, |
| 7306 | struct device_attribute *attr, char *buf) |
| 7307 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7308 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7309 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7310 | return -EAGAIN; |
| 7311 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 7312 | } |
| 7313 | |
| 7314 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 7315 | |
| 7316 | static ssize_t dump_error_log(struct device *d, |
| 7317 | struct device_attribute *attr, |
| 7318 | const char *buf, size_t count) |
| 7319 | { |
| 7320 | char *p = (char *)buf; |
| 7321 | |
| 7322 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7323 | iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7324 | |
| 7325 | return strnlen(buf, count); |
| 7326 | } |
| 7327 | |
| 7328 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 7329 | |
| 7330 | static ssize_t dump_event_log(struct device *d, |
| 7331 | struct device_attribute *attr, |
| 7332 | const char *buf, size_t count) |
| 7333 | { |
| 7334 | char *p = (char *)buf; |
| 7335 | |
| 7336 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7337 | iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7338 | |
| 7339 | return strnlen(buf, count); |
| 7340 | } |
| 7341 | |
| 7342 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 7343 | |
| 7344 | /***************************************************************************** |
| 7345 | * |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 7346 | * driver setup and tear down |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7347 | * |
| 7348 | *****************************************************************************/ |
| 7349 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7350 | static void iwl3945_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7351 | { |
| 7352 | priv->workqueue = create_workqueue(DRV_NAME); |
| 7353 | |
| 7354 | init_waitqueue_head(&priv->wait_command_queue); |
| 7355 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7356 | INIT_WORK(&priv->up, iwl3945_bg_up); |
| 7357 | INIT_WORK(&priv->restart, iwl3945_bg_restart); |
| 7358 | INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); |
| 7359 | INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed); |
| 7360 | INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan); |
| 7361 | INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan); |
| 7362 | INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill); |
| 7363 | INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7364 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); |
| 7365 | INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); |
| 7366 | INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7367 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7368 | iwl3945_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7369 | |
| 7370 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7371 | iwl3945_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7372 | } |
| 7373 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7374 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7375 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7376 | iwl3945_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7377 | |
Joonwoo Park | e47eb6a | 2007-11-29 10:42:49 +0900 | [diff] [blame] | 7378 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7379 | cancel_delayed_work(&priv->scan_check); |
| 7380 | cancel_delayed_work(&priv->alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7381 | cancel_work_sync(&priv->beacon_update); |
| 7382 | } |
| 7383 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7384 | static struct attribute *iwl3945_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7385 | &dev_attr_antenna.attr, |
| 7386 | &dev_attr_channels.attr, |
| 7387 | &dev_attr_dump_errors.attr, |
| 7388 | &dev_attr_dump_events.attr, |
| 7389 | &dev_attr_flags.attr, |
| 7390 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7391 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7392 | &dev_attr_measurement.attr, |
| 7393 | #endif |
| 7394 | &dev_attr_power_level.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7395 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7396 | &dev_attr_statistics.attr, |
| 7397 | &dev_attr_status.attr, |
| 7398 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7399 | &dev_attr_tx_power.attr, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7400 | #ifdef CONFIG_IWL3945_DEBUG |
| 7401 | &dev_attr_debug_level.attr, |
| 7402 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7403 | NULL |
| 7404 | }; |
| 7405 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7406 | static struct attribute_group iwl3945_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7407 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7408 | .attrs = iwl3945_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7409 | }; |
| 7410 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7411 | static struct ieee80211_ops iwl3945_hw_ops = { |
| 7412 | .tx = iwl3945_mac_tx, |
| 7413 | .start = iwl3945_mac_start, |
| 7414 | .stop = iwl3945_mac_stop, |
| 7415 | .add_interface = iwl3945_mac_add_interface, |
| 7416 | .remove_interface = iwl3945_mac_remove_interface, |
| 7417 | .config = iwl3945_mac_config, |
| 7418 | .config_interface = iwl3945_mac_config_interface, |
| 7419 | .configure_filter = iwl3945_configure_filter, |
| 7420 | .set_key = iwl3945_mac_set_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7421 | .get_tx_stats = iwl3945_mac_get_tx_stats, |
| 7422 | .conf_tx = iwl3945_mac_conf_tx, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7423 | .reset_tsf = iwl3945_mac_reset_tsf, |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 7424 | .bss_info_changed = iwl3945_bss_info_changed, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7425 | .hw_scan = iwl3945_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7426 | }; |
| 7427 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7428 | 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] | 7429 | { |
| 7430 | int err = 0; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7431 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7432 | struct ieee80211_hw *hw; |
Kolekar, Abhijeet | c0f20d9 | 2008-12-19 10:37:19 +0800 | [diff] [blame] | 7433 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7434 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7435 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7436 | /*********************** |
| 7437 | * 1. Allocating HW data |
| 7438 | * ********************/ |
| 7439 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7440 | /* mac80211 allocates memory for this device instance, including |
| 7441 | * space for this driver's private structure */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7442 | hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwl3945_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7443 | if (hw == NULL) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7444 | printk(KERN_ERR DRV_NAME "Can not allocate network device\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7445 | err = -ENOMEM; |
| 7446 | goto out; |
| 7447 | } |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7448 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7449 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 7450 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7451 | priv = hw->priv; |
| 7452 | priv->hw = hw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7453 | priv->pci_dev = pdev; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 7454 | priv->cfg = cfg; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7455 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7456 | if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) || |
| 7457 | (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7458 | IWL_ERR(priv, |
| 7459 | "invalid queues_num, should be between %d and %d\n", |
| 7460 | IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES); |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7461 | err = -EINVAL; |
| 7462 | goto out; |
| 7463 | } |
| 7464 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7465 | /* Disabling hardware scan means that mac80211 will perform scans |
| 7466 | * "the hard way", rather than using device's scan. */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7467 | if (iwl3945_mod_params.disable_hw_scan) { |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7468 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
| 7469 | iwl3945_hw_ops.hw_scan = NULL; |
| 7470 | } |
| 7471 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7472 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 7473 | hw->rate_control_algorithm = "iwl-3945-rs"; |
| 7474 | hw->sta_data_size = sizeof(struct iwl3945_sta_priv); |
| 7475 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7476 | /* Select antenna (may be helpful if only one antenna is connected) */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7477 | priv->antenna = (enum iwl3945_antenna)iwl3945_mod_params.antenna; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7478 | #ifdef CONFIG_IWL3945_DEBUG |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7479 | priv->debug_level = iwl3945_mod_params.debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7480 | atomic_set(&priv->restrict_refcnt, 0); |
| 7481 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7482 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7483 | /* Tell mac80211 our characteristics */ |
Johannes Berg | 605a0bd | 2008-07-15 10:10:01 +0200 | [diff] [blame] | 7484 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7485 | IEEE80211_HW_NOISE_DBM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7486 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7487 | hw->wiphy->interface_modes = |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7488 | BIT(NL80211_IFTYPE_STATION) | |
| 7489 | BIT(NL80211_IFTYPE_ADHOC); |
| 7490 | |
Luis R. Rodriguez | ea4a82dc | 2008-11-12 14:22:04 -0800 | [diff] [blame] | 7491 | hw->wiphy->fw_handles_regulatory = true; |
| 7492 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7493 | /* 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7494 | hw->queues = 4; |
| 7495 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7496 | /*************************** |
| 7497 | * 2. Initializing PCI bus |
| 7498 | * *************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7499 | if (pci_enable_device(pdev)) { |
| 7500 | err = -ENODEV; |
| 7501 | goto out_ieee80211_free_hw; |
| 7502 | } |
| 7503 | |
| 7504 | pci_set_master(pdev); |
| 7505 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7506 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 7507 | if (!err) |
| 7508 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 7509 | if (err) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7510 | IWL_WARN(priv, "No suitable DMA available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7511 | goto out_pci_disable_device; |
| 7512 | } |
| 7513 | |
| 7514 | pci_set_drvdata(pdev, priv); |
| 7515 | err = pci_request_regions(pdev, DRV_NAME); |
| 7516 | if (err) |
| 7517 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7518 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7519 | /*********************** |
| 7520 | * 3. Read REV Register |
| 7521 | * ********************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7522 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 7523 | if (!priv->hw_base) { |
| 7524 | err = -ENODEV; |
| 7525 | goto out_pci_release_regions; |
| 7526 | } |
| 7527 | |
| 7528 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 7529 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 7530 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 7531 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7532 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 7533 | * PCI Tx retries from interfering with C3 CPU state */ |
| 7534 | pci_write_config_byte(pdev, 0x41, 0x00); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7535 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7536 | /* nic init */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 7537 | iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7538 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7539 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 7540 | iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 7541 | err = iwl_poll_direct_bit(priv, CSR_GP_CNTRL, |
Zhu, Yi | 73d7b5a | 2008-12-05 07:58:40 -0800 | [diff] [blame] | 7542 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7543 | if (err < 0) { |
| 7544 | IWL_DEBUG_INFO("Failed to init the card\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7545 | goto out_remove_sysfs; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7546 | } |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7547 | |
| 7548 | /*********************** |
| 7549 | * 4. Read EEPROM |
| 7550 | * ********************/ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7551 | /* Read the EEPROM */ |
| 7552 | err = iwl3945_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7553 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7554 | IWL_ERR(priv, "Unable to init EEPROM\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7555 | goto out_remove_sysfs; |
| 7556 | } |
| 7557 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 7558 | get_eeprom_mac(priv, priv->mac_addr); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7559 | IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7560 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 7561 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7562 | /*********************** |
| 7563 | * 5. Setup HW Constants |
| 7564 | * ********************/ |
| 7565 | /* Device-specific setup */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7566 | if (iwl3945_hw_set_hw_params(priv)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7567 | IWL_ERR(priv, "failed to set hw settings\n"); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7568 | goto out_iounmap; |
| 7569 | } |
| 7570 | |
| 7571 | /*********************** |
| 7572 | * 6. Setup priv |
| 7573 | * ********************/ |
| 7574 | priv->retry_rate = 1; |
| 7575 | priv->ibss_beacon = NULL; |
| 7576 | |
| 7577 | spin_lock_init(&priv->lock); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7578 | spin_lock_init(&priv->power_data_39.lock); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7579 | spin_lock_init(&priv->sta_lock); |
| 7580 | spin_lock_init(&priv->hcmd_lock); |
| 7581 | |
| 7582 | INIT_LIST_HEAD(&priv->free_frames); |
| 7583 | mutex_init(&priv->mutex); |
| 7584 | |
| 7585 | /* Clear the driver's (not device's) station table */ |
| 7586 | iwl3945_clear_stations_table(priv); |
| 7587 | |
| 7588 | priv->data_retry_limit = -1; |
| 7589 | priv->ieee_channels = NULL; |
| 7590 | priv->ieee_rates = NULL; |
| 7591 | priv->band = IEEE80211_BAND_2GHZ; |
| 7592 | |
| 7593 | priv->iw_mode = NL80211_IFTYPE_STATION; |
| 7594 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7595 | iwl_reset_qos(priv); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7596 | |
| 7597 | priv->qos_data.qos_active = 0; |
| 7598 | priv->qos_data.qos_cap.val = 0; |
| 7599 | |
| 7600 | |
| 7601 | priv->rates_mask = IWL_RATES_MASK; |
| 7602 | /* If power management is turned on, default to AC mode */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7603 | priv->power_mode = IWL39_POWER_AC; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7604 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 7605 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7606 | err = iwl3945_init_channel_map(priv); |
| 7607 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7608 | IWL_ERR(priv, "initializing regulatory failed: %d\n", err); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7609 | goto out_release_irq; |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7610 | } |
| 7611 | |
| 7612 | err = iwl3945_init_geos(priv); |
| 7613 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7614 | IWL_ERR(priv, "initializing geos failed: %d\n", err); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7615 | goto out_free_channel_map; |
| 7616 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7617 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7618 | IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n", |
| 7619 | priv->cfg->name); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7620 | |
| 7621 | /*********************************** |
| 7622 | * 7. Initialize Module Parameters |
| 7623 | * **********************************/ |
| 7624 | |
| 7625 | /* Initialize module parameter values here */ |
| 7626 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7627 | if (iwl3945_mod_params.disable) { |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7628 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 7629 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 7630 | } |
| 7631 | |
| 7632 | |
| 7633 | /*********************** |
| 7634 | * 8. Setup Services |
| 7635 | * ********************/ |
| 7636 | |
| 7637 | spin_lock_irqsave(&priv->lock, flags); |
| 7638 | iwl3945_disable_interrupts(priv); |
| 7639 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7640 | |
| 7641 | err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
| 7642 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7643 | IWL_ERR(priv, "failed to create sysfs device attributes\n"); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7644 | goto out_free_geos; |
| 7645 | } |
| 7646 | |
| 7647 | iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
| 7648 | iwl3945_setup_deferred_work(priv); |
| 7649 | iwl3945_setup_rx_handlers(priv); |
| 7650 | |
| 7651 | /*********************** |
| 7652 | * 9. Conclude |
| 7653 | * ********************/ |
| 7654 | pci_save_state(pdev); |
| 7655 | pci_disable_device(pdev); |
| 7656 | |
| 7657 | /********************************* |
| 7658 | * 10. Setup and Register mac80211 |
| 7659 | * *******************************/ |
| 7660 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7661 | err = ieee80211_register_hw(priv->hw); |
| 7662 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7663 | IWL_ERR(priv, "Failed to register network device: %d\n", err); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7664 | goto out_remove_sysfs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7665 | } |
| 7666 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7667 | priv->hw->conf.beacon_int = 100; |
| 7668 | priv->mac80211_registered = 1; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7669 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7670 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7671 | err = iwl3945_rfkill_init(priv); |
| 7672 | if (err) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7673 | IWL_ERR(priv, "Unable to initialize RFKILL system. " |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7674 | "Ignoring error: %d\n", err); |
| 7675 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7676 | return 0; |
| 7677 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7678 | out_remove_sysfs: |
| 7679 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7680 | out_free_geos: |
| 7681 | iwl3945_free_geos(priv); |
| 7682 | out_free_channel_map: |
| 7683 | iwl3945_free_channel_map(priv); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7684 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7685 | |
| 7686 | out_release_irq: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7687 | destroy_workqueue(priv->workqueue); |
| 7688 | priv->workqueue = NULL; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7689 | iwl3945_unset_hw_params(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7690 | |
| 7691 | out_iounmap: |
| 7692 | pci_iounmap(pdev, priv->hw_base); |
| 7693 | out_pci_release_regions: |
| 7694 | pci_release_regions(pdev); |
| 7695 | out_pci_disable_device: |
| 7696 | pci_disable_device(pdev); |
| 7697 | pci_set_drvdata(pdev, NULL); |
| 7698 | out_ieee80211_free_hw: |
| 7699 | ieee80211_free_hw(priv->hw); |
| 7700 | out: |
| 7701 | return err; |
| 7702 | } |
| 7703 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 7704 | static void __devexit iwl3945_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7705 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7706 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7707 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7708 | |
| 7709 | if (!priv) |
| 7710 | return; |
| 7711 | |
| 7712 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 7713 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7714 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 7715 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7716 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7717 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7718 | /* make sure we flush any pending irq or |
| 7719 | * tasklet for the driver |
| 7720 | */ |
| 7721 | spin_lock_irqsave(&priv->lock, flags); |
| 7722 | iwl3945_disable_interrupts(priv); |
| 7723 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7724 | |
| 7725 | iwl_synchronize_irq(priv); |
| 7726 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7727 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7728 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7729 | iwl3945_rfkill_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7730 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7731 | |
| 7732 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7733 | iwl3945_rx_queue_free(priv, &priv->rxq); |
| 7734 | iwl3945_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7735 | |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7736 | iwl3945_unset_hw_params(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7737 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7738 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7739 | if (priv->mac80211_registered) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7740 | ieee80211_unregister_hw(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7741 | |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 7742 | /*netif_stop_queue(dev); */ |
| 7743 | flush_workqueue(priv->workqueue); |
| 7744 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7745 | /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7746 | * priv->workqueue... so we can't take down the workqueue |
| 7747 | * until now... */ |
| 7748 | destroy_workqueue(priv->workqueue); |
| 7749 | priv->workqueue = NULL; |
| 7750 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7751 | pci_iounmap(pdev, priv->hw_base); |
| 7752 | pci_release_regions(pdev); |
| 7753 | pci_disable_device(pdev); |
| 7754 | pci_set_drvdata(pdev, NULL); |
| 7755 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7756 | iwl3945_free_channel_map(priv); |
| 7757 | iwl3945_free_geos(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7758 | kfree(priv->scan39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7759 | if (priv->ibss_beacon) |
| 7760 | dev_kfree_skb(priv->ibss_beacon); |
| 7761 | |
| 7762 | ieee80211_free_hw(priv->hw); |
| 7763 | } |
| 7764 | |
| 7765 | #ifdef CONFIG_PM |
| 7766 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7767 | 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] | 7768 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7769 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7770 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7771 | if (priv->is_open) { |
| 7772 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 7773 | iwl3945_mac_stop(priv->hw); |
| 7774 | priv->is_open = 1; |
| 7775 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7776 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7777 | pci_set_power_state(pdev, PCI_D3hot); |
| 7778 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7779 | return 0; |
| 7780 | } |
| 7781 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7782 | static int iwl3945_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7783 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7784 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7785 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7786 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7787 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7788 | if (priv->is_open) |
| 7789 | iwl3945_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7790 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7791 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7792 | return 0; |
| 7793 | } |
| 7794 | |
| 7795 | #endif /* CONFIG_PM */ |
| 7796 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7797 | /*************** RFKILL FUNCTIONS **********/ |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7798 | #ifdef CONFIG_IWL3945_RFKILL |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7799 | /* software rf-kill from user */ |
| 7800 | static int iwl3945_rfkill_soft_rf_kill(void *data, enum rfkill_state state) |
| 7801 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7802 | struct iwl_priv *priv = data; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7803 | int err = 0; |
| 7804 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7805 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7806 | return 0; |
| 7807 | |
| 7808 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7809 | return 0; |
| 7810 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 7811 | 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] | 7812 | mutex_lock(&priv->mutex); |
| 7813 | |
| 7814 | switch (state) { |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7815 | case RFKILL_STATE_UNBLOCKED: |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7816 | if (iwl_is_rfkill_hw(priv)) { |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7817 | err = -EBUSY; |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7818 | goto out_unlock; |
| 7819 | } |
| 7820 | iwl3945_radio_kill_sw(priv, 0); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7821 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7822 | case RFKILL_STATE_SOFT_BLOCKED: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7823 | iwl3945_radio_kill_sw(priv, 1); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7824 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7825 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 7826 | IWL_WARN(priv, "received unexpected RFKILL state %d\n", state); |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 7827 | break; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7828 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7829 | out_unlock: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7830 | mutex_unlock(&priv->mutex); |
| 7831 | |
| 7832 | return err; |
| 7833 | } |
| 7834 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7835 | int iwl3945_rfkill_init(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7836 | { |
| 7837 | struct device *device = wiphy_dev(priv->hw->wiphy); |
| 7838 | int ret = 0; |
| 7839 | |
| 7840 | BUG_ON(device == NULL); |
| 7841 | |
| 7842 | IWL_DEBUG_RF_KILL("Initializing RFKILL.\n"); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7843 | priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN); |
| 7844 | if (!priv->rfkill) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7845 | IWL_ERR(priv, "Unable to allocate rfkill device.\n"); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7846 | ret = -ENOMEM; |
| 7847 | goto error; |
| 7848 | } |
| 7849 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7850 | priv->rfkill->name = priv->cfg->name; |
| 7851 | priv->rfkill->data = priv; |
| 7852 | priv->rfkill->state = RFKILL_STATE_UNBLOCKED; |
| 7853 | priv->rfkill->toggle_radio = iwl3945_rfkill_soft_rf_kill; |
| 7854 | priv->rfkill->user_claim_unsupported = 1; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7855 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7856 | priv->rfkill->dev.class->suspend = NULL; |
| 7857 | priv->rfkill->dev.class->resume = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7858 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7859 | ret = rfkill_register(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7860 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7861 | IWL_ERR(priv, "Unable to register rfkill: %d\n", ret); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7862 | goto freed_rfkill; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7863 | } |
| 7864 | |
| 7865 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 7866 | return ret; |
| 7867 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7868 | freed_rfkill: |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7869 | if (priv->rfkill != NULL) |
| 7870 | rfkill_free(priv->rfkill); |
| 7871 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7872 | |
| 7873 | error: |
| 7874 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 7875 | return ret; |
| 7876 | } |
| 7877 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7878 | void iwl3945_rfkill_unregister(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7879 | { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7880 | if (priv->rfkill) |
| 7881 | rfkill_unregister(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7882 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7883 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7884 | } |
| 7885 | |
| 7886 | /* set rf-kill to the right state. */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7887 | void iwl3945_rfkill_set_hw_state(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7888 | { |
| 7889 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7890 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7891 | return; |
| 7892 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7893 | if (iwl_is_rfkill_hw(priv)) { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7894 | rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED); |
| 7895 | return; |
| 7896 | } |
| 7897 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 7898 | if (!iwl_is_rfkill_sw(priv)) |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7899 | rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7900 | else |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 7901 | rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7902 | } |
| 7903 | #endif |
| 7904 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7905 | /***************************************************************************** |
| 7906 | * |
| 7907 | * driver and module entry point |
| 7908 | * |
| 7909 | *****************************************************************************/ |
| 7910 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7911 | static struct pci_driver iwl3945_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7912 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7913 | .id_table = iwl3945_hw_card_ids, |
| 7914 | .probe = iwl3945_pci_probe, |
| 7915 | .remove = __devexit_p(iwl3945_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7916 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7917 | .suspend = iwl3945_pci_suspend, |
| 7918 | .resume = iwl3945_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7919 | #endif |
| 7920 | }; |
| 7921 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7922 | static int __init iwl3945_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7923 | { |
| 7924 | |
| 7925 | int ret; |
| 7926 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 7927 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7928 | |
| 7929 | ret = iwl3945_rate_control_register(); |
| 7930 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7931 | printk(KERN_ERR DRV_NAME |
| 7932 | "Unable to register rate control algorithm: %d\n", ret); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7933 | return ret; |
| 7934 | } |
| 7935 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7936 | ret = pci_register_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7937 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7938 | printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7939 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7940 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7941 | |
| 7942 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7943 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7944 | error_register: |
| 7945 | iwl3945_rate_control_unregister(); |
| 7946 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7947 | } |
| 7948 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7949 | static void __exit iwl3945_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7950 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7951 | pci_unregister_driver(&iwl3945_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7952 | iwl3945_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7953 | } |
| 7954 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 7955 | MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX)); |
Zhu Yi | 25cb6ca | 2008-09-11 11:45:22 +0800 | [diff] [blame] | 7956 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7957 | module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7958 | 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] | 7959 | module_param_named(disable, iwl3945_mod_params.disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7960 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7961 | module_param_named(hwcrypto, iwl3945_mod_params.sw_crypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7962 | MODULE_PARM_DESC(hwcrypto, |
| 7963 | "using hardware crypto engine (default 0 [software])\n"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7964 | module_param_named(debug, iwl3945_mod_params.debug, uint, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7965 | MODULE_PARM_DESC(debug, "debug output mask"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7966 | 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] | 7967 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 7968 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 7969 | 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] | 7970 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 7971 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7972 | module_exit(iwl3945_exit); |
| 7973 | module_init(iwl3945_init); |