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 | * |
| 63 | * module boiler plate |
| 64 | * |
| 65 | ******************************************************************************/ |
| 66 | |
| 67 | /* module parameters */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 68 | static int iwl3945_param_disable_hw_scan; /* def: 0 = use 3945's h/w scan */ |
Wu, Fengguang | 95aa194 | 2008-12-17 16:52:30 +0800 | [diff] [blame] | 69 | static u32 iwl3945_param_debug; /* def: 0 = minimal debug log messages */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 70 | static int iwl3945_param_disable; /* def: 0 = enable radio */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 71 | static int iwl3945_param_antenna; /* def: 0 = both antennas (use diversity) */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 72 | int iwl3945_param_hwcrypto; /* def: 0 = use software encryption */ |
Ron Rindjunsky | dfe7d45 | 2008-04-15 16:01:45 -0700 | [diff] [blame] | 73 | int iwl3945_param_queues_num = IWL39_MAX_NUM_QUEUES; /* def: 8 Tx queues */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * module name, copyright, version, etc. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 77 | */ |
| 78 | |
| 79 | #define DRV_DESCRIPTION \ |
| 80 | "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux" |
| 81 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 82 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 83 | #define VD "d" |
| 84 | #else |
| 85 | #define VD |
| 86 | #endif |
| 87 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 88 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 89 | #define VS "s" |
| 90 | #else |
| 91 | #define VS |
| 92 | #endif |
| 93 | |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 94 | #define IWL39_VERSION "1.2.26k" VD VS |
Reinette Chatre | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 95 | #define DRV_COPYRIGHT "Copyright(c) 2003-2008 Intel Corporation" |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 96 | #define DRV_AUTHOR "<ilw@linux.intel.com>" |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 97 | #define DRV_VERSION IWL39_VERSION |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 98 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 99 | |
| 100 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 101 | MODULE_VERSION(DRV_VERSION); |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 102 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 103 | MODULE_LICENSE("GPL"); |
| 104 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 105 | static const struct ieee80211_supported_band *iwl3945_get_band( |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 106 | struct iwl_priv *priv, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 107 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 108 | return priv->hw->wiphy->bands[band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 111 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 112 | * DMA services |
| 113 | * |
| 114 | * Theory of operation |
| 115 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 116 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 117 | * of buffer descriptors, each of which points to one or more data buffers for |
| 118 | * the device to read from or fill. Driver and device exchange status of each |
| 119 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 120 | * entries in each circular buffer, to protect against confusing empty and full |
| 121 | * queue states. |
| 122 | * |
| 123 | * The device reads or writes the data in the queues via the device's several |
| 124 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 125 | * |
| 126 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 127 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 128 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 129 | * Tx queue resumed. |
| 130 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 131 | * The 3945 operates with six queues: One receive queue, one transmit queue |
| 132 | * (#4) for sending commands to the device firmware, and four transmit queues |
| 133 | * (#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] | 134 | ***************************************************/ |
| 135 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 136 | int iwl3945_x2_queue_used(const struct iwl_queue *q, int i) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 137 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 138 | return q->write_ptr > q->read_ptr ? |
| 139 | (i >= q->read_ptr && i < q->write_ptr) : |
| 140 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 143 | /** |
| 144 | * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes |
| 145 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 146 | 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] | 147 | int count, int slots_num, u32 id) |
| 148 | { |
| 149 | q->n_bd = count; |
| 150 | q->n_window = slots_num; |
| 151 | q->id = id; |
| 152 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 153 | /* count must be power-of-two size, otherwise iwl_queue_inc_wrap |
| 154 | * and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 155 | BUG_ON(!is_power_of_2(count)); |
| 156 | |
| 157 | /* slots_num must be power-of-two size, otherwise |
| 158 | * get_cmd_index is broken. */ |
| 159 | BUG_ON(!is_power_of_2(slots_num)); |
| 160 | |
| 161 | q->low_mark = q->n_window / 4; |
| 162 | if (q->low_mark < 4) |
| 163 | q->low_mark = 4; |
| 164 | |
| 165 | q->high_mark = q->n_window / 8; |
| 166 | if (q->high_mark < 2) |
| 167 | q->high_mark = 2; |
| 168 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 169 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 174 | /** |
| 175 | * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 176 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 177 | static int iwl3945_tx_queue_alloc(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 178 | struct iwl3945_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 179 | { |
| 180 | struct pci_dev *dev = priv->pci_dev; |
| 181 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 182 | /* Driver private data, only for Tx (not command) queues, |
| 183 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 184 | if (id != IWL_CMD_QUEUE_NUM) { |
| 185 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 186 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 187 | if (!txq->txb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 188 | IWL_ERR(priv, "kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 189 | "structures failed\n"); |
| 190 | goto error; |
| 191 | } |
| 192 | } else |
| 193 | txq->txb = NULL; |
| 194 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 195 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 196 | * shared with device */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 197 | txq->bd = pci_alloc_consistent(dev, |
| 198 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 199 | &txq->q.dma_addr); |
| 200 | |
| 201 | if (!txq->bd) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 202 | IWL_ERR(priv, "pci_alloc_consistent(%zd) failed\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 203 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 204 | goto error; |
| 205 | } |
| 206 | txq->q.id = id; |
| 207 | |
| 208 | return 0; |
| 209 | |
| 210 | error: |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 211 | kfree(txq->txb); |
| 212 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 213 | |
| 214 | return -ENOMEM; |
| 215 | } |
| 216 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 217 | /** |
| 218 | * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 219 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 220 | int iwl3945_tx_queue_init(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 221 | struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 222 | { |
| 223 | struct pci_dev *dev = priv->pci_dev; |
| 224 | int len; |
| 225 | int rc = 0; |
| 226 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 227 | /* |
| 228 | * Alloc buffer array for commands (Tx or other types of commands). |
| 229 | * For the command queue (#4), allocate command space + one big |
| 230 | * command for scan, since scan command is very huge; the system will |
| 231 | * not have two scans at the same time, so only one is needed. |
| 232 | * For data Tx queues (all other queues), no super-size command |
| 233 | * space is needed. |
| 234 | */ |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 235 | len = sizeof(struct iwl_cmd) * slots_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 236 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 237 | len += IWL_MAX_SCAN_SIZE; |
| 238 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 239 | if (!txq->cmd) |
| 240 | return -ENOMEM; |
| 241 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 242 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 243 | rc = iwl3945_tx_queue_alloc(priv, txq, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 244 | if (rc) { |
| 245 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 246 | |
| 247 | return -ENOMEM; |
| 248 | } |
| 249 | txq->need_update = 0; |
| 250 | |
| 251 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 252 | * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 253 | 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] | 254 | |
| 255 | /* Initialize queue high/low-water, head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 256 | 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] | 257 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 258 | /* Tell device where to find queue, enable DMA channel. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 259 | iwl3945_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 265 | * iwl3945_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 266 | * @txq: Transmit queue to deallocate. |
| 267 | * |
| 268 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 269 | * Free all buffers. |
| 270 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 271 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 272 | 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] | 273 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 274 | struct iwl_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 275 | struct pci_dev *dev = priv->pci_dev; |
| 276 | int len; |
| 277 | |
| 278 | if (q->n_bd == 0) |
| 279 | return; |
| 280 | |
| 281 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 282 | for (; q->write_ptr != q->read_ptr; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 283 | 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] | 284 | iwl3945_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 285 | |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 286 | len = sizeof(struct iwl_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 287 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 288 | len += IWL_MAX_SCAN_SIZE; |
| 289 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 290 | /* De-alloc array of command/tx buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 291 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 292 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 293 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 294 | if (txq->q.n_bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 295 | pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 296 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 297 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 298 | /* De-alloc array of per-TFD driver data */ |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 299 | kfree(txq->txb); |
| 300 | txq->txb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 301 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 302 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 303 | memset(txq, 0, sizeof(*txq)); |
| 304 | } |
| 305 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 306 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 307 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 308 | * the functionality provided here |
| 309 | */ |
| 310 | |
| 311 | /**************************************************************/ |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 312 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 313 | /** |
| 314 | * iwl3945_remove_station - Remove driver's knowledge of station. |
| 315 | * |
| 316 | * NOTE: This does not remove station from device's station table. |
| 317 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 318 | 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] | 319 | { |
| 320 | int index = IWL_INVALID_STATION; |
| 321 | int i; |
| 322 | unsigned long flags; |
| 323 | |
| 324 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 325 | |
| 326 | if (is_ap) |
| 327 | index = IWL_AP_ID; |
| 328 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 329 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 330 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 331 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 332 | if (priv->stations_39[i].used && |
| 333 | !compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 334 | addr)) { |
| 335 | index = i; |
| 336 | break; |
| 337 | } |
| 338 | |
| 339 | if (unlikely(index == IWL_INVALID_STATION)) |
| 340 | goto out; |
| 341 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 342 | if (priv->stations_39[index].used) { |
| 343 | priv->stations_39[index].used = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 344 | priv->num_stations--; |
| 345 | } |
| 346 | |
| 347 | BUG_ON(priv->num_stations < 0); |
| 348 | |
| 349 | out: |
| 350 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 351 | return 0; |
| 352 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 353 | #endif |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 354 | |
| 355 | /** |
| 356 | * iwl3945_clear_stations_table - Clear the driver's station table |
| 357 | * |
| 358 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 359 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 360 | static void iwl3945_clear_stations_table(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 361 | { |
| 362 | unsigned long flags; |
| 363 | |
| 364 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 365 | |
| 366 | priv->num_stations = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 367 | memset(priv->stations_39, 0, sizeof(priv->stations_39)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 368 | |
| 369 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 370 | } |
| 371 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 372 | /** |
| 373 | * iwl3945_add_station - Add station to station tables in driver and device |
| 374 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 375 | 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] | 376 | { |
| 377 | int i; |
| 378 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 379 | struct iwl3945_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | unsigned long flags_spin; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 381 | u8 rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 382 | |
| 383 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 384 | if (is_ap) |
| 385 | index = IWL_AP_ID; |
| 386 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 387 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 388 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 389 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 390 | if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 391 | addr)) { |
| 392 | index = i; |
| 393 | break; |
| 394 | } |
| 395 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 396 | if (!priv->stations_39[i].used && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 397 | index == IWL_INVALID_STATION) |
| 398 | index = i; |
| 399 | } |
| 400 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 401 | /* These two conditions has the same outcome but keep them separate |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 402 | since they have different meaning */ |
| 403 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 404 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 405 | return index; |
| 406 | } |
| 407 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 408 | if (priv->stations_39[index].used && |
| 409 | !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 410 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 411 | return index; |
| 412 | } |
| 413 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 414 | IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 415 | station = &priv->stations_39[index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 416 | station->used = 1; |
| 417 | priv->num_stations++; |
| 418 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 419 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 420 | memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 421 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 422 | station->sta.mode = 0; |
| 423 | station->sta.sta.sta_id = index; |
| 424 | station->sta.station_flags = 0; |
| 425 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 426 | if (priv->band == IEEE80211_BAND_5GHZ) |
Tomas Winkler | 6994633 | 2007-10-25 17:15:27 +0800 | [diff] [blame] | 427 | rate = IWL_RATE_6M_PLCP; |
| 428 | else |
| 429 | rate = IWL_RATE_1M_PLCP; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 430 | |
| 431 | /* Turn on both antennas for the station... */ |
| 432 | station->sta.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 433 | iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 434 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 435 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 436 | |
| 437 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 438 | iwl3945_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 439 | return index; |
| 440 | |
| 441 | } |
| 442 | |
| 443 | /*************** DRIVER STATUS FUNCTIONS *****/ |
| 444 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 445 | static inline int iwl3945_is_ready(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 446 | { |
| 447 | /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are |
| 448 | * set but EXIT_PENDING is not */ |
| 449 | return test_bit(STATUS_READY, &priv->status) && |
| 450 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) && |
| 451 | !test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 452 | } |
| 453 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 454 | static inline int iwl3945_is_alive(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 455 | { |
| 456 | return test_bit(STATUS_ALIVE, &priv->status); |
| 457 | } |
| 458 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 459 | static inline int iwl3945_is_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 460 | { |
| 461 | return test_bit(STATUS_INIT, &priv->status); |
| 462 | } |
| 463 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 464 | static inline int iwl3945_is_rfkill_sw(struct iwl_priv *priv) |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 465 | { |
| 466 | return test_bit(STATUS_RF_KILL_SW, &priv->status); |
| 467 | } |
| 468 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 469 | static inline int iwl3945_is_rfkill_hw(struct iwl_priv *priv) |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 470 | { |
| 471 | return test_bit(STATUS_RF_KILL_HW, &priv->status); |
| 472 | } |
| 473 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 474 | static inline int iwl3945_is_rfkill(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 475 | { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 476 | return iwl3945_is_rfkill_hw(priv) || |
| 477 | iwl3945_is_rfkill_sw(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 480 | static inline int iwl3945_is_ready_rf(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 481 | { |
| 482 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 483 | if (iwl3945_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 484 | return 0; |
| 485 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 486 | return iwl3945_is_ready(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 490 | |
Abhijeet Kolekar | c305606 | 2008-11-12 13:14:08 -0800 | [diff] [blame] | 491 | #define IWL_CMD(x) case x: return #x |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 492 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 493 | |
| 494 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 495 | * iwl3945_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 496 | * @priv: device private data point |
| 497 | * @cmd: a point to the ucode command structure |
| 498 | * |
| 499 | * The function returns < 0 values to indicate the operation is |
| 500 | * failed. On success, it turns the index (> 0) of command in the |
| 501 | * command queue. |
| 502 | */ |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 503 | 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] | 504 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 505 | struct iwl3945_tx_queue *txq = &priv->txq39[IWL_CMD_QUEUE_NUM]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 506 | struct iwl_queue *q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 507 | struct iwl3945_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 508 | u32 *control_flags; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 509 | struct iwl_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 510 | u32 idx; |
| 511 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 512 | dma_addr_t phys_addr; |
| 513 | int pad; |
| 514 | u16 count; |
| 515 | int ret; |
| 516 | unsigned long flags; |
| 517 | |
| 518 | /* If any of the command structures end up being larger than |
| 519 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 520 | * we will need to increase the size of the TFD entries */ |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 521 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 522 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 523 | |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 524 | |
| 525 | if (iwl3945_is_rfkill(priv)) { |
| 526 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 527 | return -EIO; |
| 528 | } |
| 529 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 530 | if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 531 | IWL_ERR(priv, "No space for Tx\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 532 | return -ENOSPC; |
| 533 | } |
| 534 | |
| 535 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 536 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 537 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 538 | memset(tfd, 0, sizeof(*tfd)); |
| 539 | |
| 540 | control_flags = (u32 *) tfd; |
| 541 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 542 | 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] | 543 | out_cmd = &txq->cmd[idx]; |
| 544 | |
| 545 | out_cmd->hdr.cmd = cmd->id; |
| 546 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 547 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 548 | |
| 549 | /* At this point, the out_cmd now has all of the incoming cmd |
| 550 | * information */ |
| 551 | |
| 552 | out_cmd->hdr.flags = 0; |
| 553 | 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] | 554 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 555 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 556 | out_cmd->hdr.sequence |= SEQ_HUGE_FRAME; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 557 | |
| 558 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 559 | offsetof(struct iwl_cmd, hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 560 | 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] | 561 | |
| 562 | pad = U32_PAD(cmd->len); |
| 563 | count = TFD_CTL_COUNT_GET(*control_flags); |
| 564 | *control_flags = TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad); |
| 565 | |
| 566 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 567 | "%d bytes at %d[%d]:%d\n", |
| 568 | get_cmd_string(out_cmd->hdr.cmd), |
| 569 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 570 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 571 | |
| 572 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 573 | |
| 574 | /* Increment and update queue's write index */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 575 | 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] | 576 | ret = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 577 | |
| 578 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 579 | return ret ? ret : idx; |
| 580 | } |
| 581 | |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 582 | static int iwl3945_send_cmd_async(struct iwl_priv *priv, |
| 583 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 584 | { |
| 585 | int ret; |
| 586 | |
| 587 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 588 | |
| 589 | /* An asynchronous command can not expect an SKB to be set. */ |
| 590 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 591 | |
| 592 | /* An asynchronous command MUST have a callback. */ |
| 593 | BUG_ON(!cmd->meta.u.callback); |
| 594 | |
| 595 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 596 | return -EBUSY; |
| 597 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 598 | ret = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 599 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 600 | IWL_ERR(priv, |
| 601 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 602 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 603 | return ret; |
| 604 | } |
| 605 | return 0; |
| 606 | } |
| 607 | |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 608 | static int iwl3945_send_cmd_sync(struct iwl_priv *priv, |
| 609 | struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 610 | { |
| 611 | int cmd_idx; |
| 612 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 613 | |
| 614 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 615 | |
| 616 | /* A synchronous command can not have a callback set. */ |
| 617 | BUG_ON(cmd->meta.u.callback != NULL); |
| 618 | |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 619 | if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 620 | IWL_ERR(priv, |
| 621 | "Error sending %s: Already sending a host command\n", |
| 622 | get_cmd_string(cmd->id)); |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 623 | ret = -EBUSY; |
| 624 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 628 | |
| 629 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 630 | cmd->meta.source = &cmd->meta; |
| 631 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 632 | cmd_idx = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 633 | if (cmd_idx < 0) { |
| 634 | ret = cmd_idx; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 635 | IWL_ERR(priv, |
| 636 | "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
| 637 | get_cmd_string(cmd->id), ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 638 | goto out; |
| 639 | } |
| 640 | |
| 641 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 642 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 643 | HOST_COMPLETE_TIMEOUT); |
| 644 | if (!ret) { |
| 645 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 646 | IWL_ERR(priv, "Error sending %s: time out after %dms\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 647 | get_cmd_string(cmd->id), |
| 648 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 649 | |
| 650 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 651 | ret = -ETIMEDOUT; |
| 652 | goto cancel; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 657 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 658 | get_cmd_string(cmd->id)); |
| 659 | ret = -ECANCELED; |
| 660 | goto fail; |
| 661 | } |
| 662 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 663 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 664 | get_cmd_string(cmd->id)); |
| 665 | ret = -EIO; |
| 666 | goto fail; |
| 667 | } |
| 668 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 669 | IWL_ERR(priv, "Error: Response NULL in '%s'\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 670 | get_cmd_string(cmd->id)); |
| 671 | ret = -EIO; |
Zhu Yi | 73e1a65 | 2009-01-08 10:19:58 -0800 | [diff] [blame] | 672 | goto cancel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | ret = 0; |
| 676 | goto out; |
| 677 | |
| 678 | cancel: |
| 679 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 680 | struct iwl_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 681 | |
| 682 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 683 | * TX cmd queue. Otherwise in case the cmd comes |
| 684 | * in later, it will possibly set an invalid |
| 685 | * address (cmd->meta.source). */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 686 | qcmd = &priv->txq39[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 687 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 688 | } |
| 689 | fail: |
| 690 | if (cmd->meta.u.skb) { |
| 691 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 692 | cmd->meta.u.skb = NULL; |
| 693 | } |
| 694 | out: |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 695 | clear_bit(STATUS_HCMD_SYNC_ACTIVE, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 696 | return ret; |
| 697 | } |
| 698 | |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 699 | 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] | 700 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 701 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 702 | return iwl3945_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 703 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 704 | return iwl3945_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 707 | 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] | 708 | { |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 709 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 710 | .id = id, |
| 711 | .len = len, |
| 712 | .data = data, |
| 713 | }; |
| 714 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 715 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 718 | 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] | 719 | { |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 720 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 721 | .id = id, |
| 722 | .len = sizeof(val), |
| 723 | .data = &val, |
| 724 | }; |
| 725 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 726 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 729 | int iwl3945_send_statistics_request(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 730 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 731 | return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 735 | * 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] | 736 | * @band: 2.4 or 5 GHz band |
| 737 | * @channel: Any channel valid for the requested band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 738 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 739 | * In addition to setting the staging RXON, priv->band is also set. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 740 | * |
| 741 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 742 | * in the staging RXON flag structure based on the band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 743 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 744 | static int iwl3945_set_rxon_channel(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 745 | enum ieee80211_band band, |
| 746 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 747 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 748 | if (!iwl3945_get_channel_info(priv, band, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 749 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 750 | channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 751 | return -EINVAL; |
| 752 | } |
| 753 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 754 | if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 755 | (priv->band == band)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 756 | return 0; |
| 757 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 758 | priv->staging39_rxon.channel = cpu_to_le16(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 759 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 760 | priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 761 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 762 | priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 763 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 764 | priv->band = band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 765 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 766 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 772 | * iwl3945_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 773 | * |
| 774 | * NOTE: This is really only useful during development and can eventually |
| 775 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 776 | * making changes |
| 777 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 778 | static int iwl3945_check_rxon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 779 | { |
| 780 | int error = 0; |
| 781 | int counter = 1; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 782 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 783 | |
| 784 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 785 | error |= le32_to_cpu(rxon->flags & |
| 786 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 787 | RXON_FLG_RADAR_DETECT_MSK)); |
| 788 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 789 | IWL_WARN(priv, "check 24G fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 790 | counter++, error); |
| 791 | } else { |
| 792 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 793 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 794 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 795 | IWL_WARN(priv, "check 52 fields %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 796 | counter++, error); |
| 797 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 798 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 799 | IWL_WARN(priv, "check 52 CCK %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 800 | counter++, error); |
| 801 | } |
| 802 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 803 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 804 | IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 805 | |
| 806 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 807 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 808 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 809 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 810 | IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 811 | |
| 812 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 813 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 814 | IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 815 | |
| 816 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 817 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 818 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 819 | IWL_WARN(priv, "check CCK and short slot %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 820 | counter++, error); |
| 821 | |
| 822 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 823 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 824 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 825 | IWL_WARN(priv, "check CCK & auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 826 | counter++, error); |
| 827 | |
| 828 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 829 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 830 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 831 | IWL_WARN(priv, "check TGG and auto detect %d | %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 832 | counter++, error); |
| 833 | |
| 834 | if ((rxon->flags & RXON_FLG_DIS_DIV_MSK)) |
| 835 | error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK | |
| 836 | RXON_FLG_ANT_A_MSK)) == 0); |
| 837 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 838 | IWL_WARN(priv, "check antenna %d %d\n", counter++, error); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 839 | |
| 840 | if (error) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 841 | IWL_WARN(priv, "Tuning to channel %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 842 | le16_to_cpu(rxon->channel)); |
| 843 | |
| 844 | if (error) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 845 | IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 846 | return -1; |
| 847 | } |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 852 | * 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] | 853 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 854 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 855 | * If the RXON structure is changing enough to require a new tune, |
| 856 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 857 | * 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] | 858 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 859 | static int iwl3945_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 860 | { |
| 861 | |
| 862 | /* These items are only settable from the full RXON command */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 863 | if (!(iwl3945_is_associated(priv)) || |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 864 | compare_ether_addr(priv->staging39_rxon.bssid_addr, |
| 865 | priv->active39_rxon.bssid_addr) || |
| 866 | compare_ether_addr(priv->staging39_rxon.node_addr, |
| 867 | priv->active39_rxon.node_addr) || |
| 868 | compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr, |
| 869 | priv->active39_rxon.wlap_bssid_addr) || |
| 870 | (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) || |
| 871 | (priv->staging39_rxon.channel != priv->active39_rxon.channel) || |
| 872 | (priv->staging39_rxon.air_propagation != |
| 873 | priv->active39_rxon.air_propagation) || |
| 874 | (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 875 | return 1; |
| 876 | |
| 877 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 878 | * be updated with the RXON_ASSOC command -- however only some |
| 879 | * flag transitions are allowed using RXON_ASSOC */ |
| 880 | |
| 881 | /* Check if we are not switching bands */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 882 | if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 883 | (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 884 | return 1; |
| 885 | |
| 886 | /* Check if we are switching association toggle */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 887 | if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 888 | (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 889 | return 1; |
| 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 894 | static int iwl3945_send_rxon_assoc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 895 | { |
| 896 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 897 | struct iwl_rx_packet *res = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 898 | struct iwl3945_rxon_assoc_cmd rxon_assoc; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 899 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 900 | .id = REPLY_RXON_ASSOC, |
| 901 | .len = sizeof(rxon_assoc), |
| 902 | .meta.flags = CMD_WANT_SKB, |
| 903 | .data = &rxon_assoc, |
| 904 | }; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 905 | const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon; |
| 906 | const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 907 | |
| 908 | if ((rxon1->flags == rxon2->flags) && |
| 909 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 910 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 911 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 912 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 913 | return 0; |
| 914 | } |
| 915 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 916 | rxon_assoc.flags = priv->staging39_rxon.flags; |
| 917 | rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags; |
| 918 | rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates; |
| 919 | rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 920 | rxon_assoc.reserved = 0; |
| 921 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 922 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 923 | if (rc) |
| 924 | return rc; |
| 925 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 926 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 927 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 928 | IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 929 | rc = -EIO; |
| 930 | } |
| 931 | |
| 932 | priv->alloc_rxb_skb--; |
| 933 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 934 | |
| 935 | return rc; |
| 936 | } |
| 937 | |
| 938 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 939 | * iwl3945_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 940 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 941 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 942 | * the active_rxon structure is updated with the new data. This |
| 943 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 944 | * a HW tune is required based on the RXON structure changes. |
| 945 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 946 | static int iwl3945_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 947 | { |
| 948 | /* cast away the const for active_rxon in this function */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 949 | struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 950 | int rc = 0; |
| 951 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 952 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 953 | return -1; |
| 954 | |
| 955 | /* always get timestamp with Rx frame */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 956 | priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 957 | |
| 958 | /* select antenna */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 959 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 960 | ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 961 | priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 962 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 963 | rc = iwl3945_check_rxon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 964 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 965 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 966 | return -EINVAL; |
| 967 | } |
| 968 | |
| 969 | /* 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] | 970 | * iwl3945_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 971 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 972 | if (!iwl3945_full_rxon_required(priv)) { |
| 973 | rc = iwl3945_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 974 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 975 | IWL_ERR(priv, "Error setting RXON_ASSOC " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 976 | "configuration (%d).\n", rc); |
| 977 | return rc; |
| 978 | } |
| 979 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 980 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 981 | |
| 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | /* If we are currently associated and the new config requires |
| 986 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 987 | * we must clear the associated from the active configuration |
| 988 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 989 | if (iwl3945_is_associated(priv) && |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 990 | (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 991 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 992 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 993 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 994 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
| 995 | sizeof(struct iwl3945_rxon_cmd), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 996 | &priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 997 | |
| 998 | /* If the mask clearing failed then we set |
| 999 | * active_rxon back to what it was previously */ |
| 1000 | if (rc) { |
| 1001 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1002 | IWL_ERR(priv, "Error clearing ASSOC_MSK on current " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1003 | "configuration (%d).\n", rc); |
| 1004 | return rc; |
| 1005 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | IWL_DEBUG_INFO("Sending RXON\n" |
| 1009 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 1010 | "* channel = %d\n" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1011 | "* bssid = %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1012 | ((priv->staging39_rxon.filter_flags & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1013 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1014 | le16_to_cpu(priv->staging39_rxon.channel), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1015 | priv->staging_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1016 | |
| 1017 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1018 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1019 | sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1020 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1021 | IWL_ERR(priv, "Error setting new configuration (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1022 | return rc; |
| 1023 | } |
| 1024 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1025 | memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1026 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1027 | iwl3945_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 1028 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1029 | /* If we issue a new RXON command which required a tune then we must |
| 1030 | * 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] | 1031 | rc = iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1032 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1033 | IWL_ERR(priv, "Error setting Tx power (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1034 | return rc; |
| 1035 | } |
| 1036 | |
| 1037 | /* Add the broadcast address so we can send broadcast frames */ |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1038 | if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1039 | IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1040 | IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1041 | return -EIO; |
| 1042 | } |
| 1043 | |
| 1044 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 1045 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1046 | if (iwl3945_is_associated(priv) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1047 | (priv->iw_mode == NL80211_IFTYPE_STATION)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1048 | if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1049 | == IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1050 | IWL_ERR(priv, "Error adding AP address for transmit\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1051 | return -EIO; |
| 1052 | } |
| 1053 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1054 | /* Init the hardware's rate fallback order based on the band */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1055 | rc = iwl3945_init_hw_rate_table(priv); |
| 1056 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1057 | IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1058 | return -EIO; |
| 1059 | } |
| 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1064 | static int iwl3945_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1065 | { |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1066 | struct iwl_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1067 | .flags = 3, |
| 1068 | .lead_time = 0xAA, |
| 1069 | .max_kill = 1, |
| 1070 | .kill_ack_mask = 0, |
| 1071 | .kill_cts_mask = 0, |
| 1072 | }; |
| 1073 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1074 | return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1075 | sizeof(bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1078 | static int iwl3945_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1079 | { |
| 1080 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1081 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 1082 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1083 | .id = REPLY_SCAN_ABORT_CMD, |
| 1084 | .meta.flags = CMD_WANT_SKB, |
| 1085 | }; |
| 1086 | |
| 1087 | /* If there isn't a scan actively going on in the hardware |
| 1088 | * then we are in between scan bands and not actually |
| 1089 | * actively scanning, so don't send the abort command */ |
| 1090 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1091 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1095 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1096 | if (rc) { |
| 1097 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1098 | return rc; |
| 1099 | } |
| 1100 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1101 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1102 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1103 | /* The scan abort will return 1 for success or |
| 1104 | * 2 for "failure". A failure condition can be |
| 1105 | * due to simply not being in an active scan which |
| 1106 | * can occur if we send the scan abort before we |
| 1107 | * the microcode has notified us that a scan is |
| 1108 | * completed. */ |
| 1109 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1110 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1111 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1112 | } |
| 1113 | |
| 1114 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1115 | |
| 1116 | return rc; |
| 1117 | } |
| 1118 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1119 | static int iwl3945_card_state_sync_callback(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 1120 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | struct sk_buff *skb) |
| 1122 | { |
| 1123 | return 1; |
| 1124 | } |
| 1125 | |
| 1126 | /* |
| 1127 | * CARD_STATE_CMD |
| 1128 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1129 | * 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] | 1130 | * |
| 1131 | * When in the 'enable' state the card operates as normal. |
| 1132 | * When in the 'disable' state, the card enters into a low power mode. |
| 1133 | * When in the 'halt' state, the card is shut down and must be fully |
| 1134 | * restarted to come back on. |
| 1135 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1136 | 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] | 1137 | { |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 1138 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1139 | .id = REPLY_CARD_STATE_CMD, |
| 1140 | .len = sizeof(u32), |
| 1141 | .data = &flags, |
| 1142 | .meta.flags = meta_flag, |
| 1143 | }; |
| 1144 | |
| 1145 | if (meta_flag & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1146 | cmd.meta.u.callback = iwl3945_card_state_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1147 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1148 | return iwl3945_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1151 | static int iwl3945_add_sta_sync_callback(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 1152 | struct iwl_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1153 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1154 | struct iwl_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1155 | |
| 1156 | if (!skb) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1157 | IWL_ERR(priv, "Error: Response NULL in REPLY_ADD_STA.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1158 | return 1; |
| 1159 | } |
| 1160 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1161 | res = (struct iwl_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1162 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1163 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1164 | res->hdr.flags); |
| 1165 | return 1; |
| 1166 | } |
| 1167 | |
| 1168 | switch (res->u.add_sta.status) { |
| 1169 | case ADD_STA_SUCCESS_MSK: |
| 1170 | break; |
| 1171 | default: |
| 1172 | break; |
| 1173 | } |
| 1174 | |
| 1175 | /* We didn't cache the SKB; let the caller free it */ |
| 1176 | return 1; |
| 1177 | } |
| 1178 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1179 | int iwl3945_send_add_station(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1180 | struct iwl3945_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1181 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1182 | struct iwl_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1183 | int rc = 0; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 1184 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1185 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1186 | .len = sizeof(struct iwl3945_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1187 | .meta.flags = flags, |
| 1188 | .data = sta, |
| 1189 | }; |
| 1190 | |
| 1191 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1192 | cmd.meta.u.callback = iwl3945_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1193 | else |
| 1194 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1195 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1196 | rc = iwl3945_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1197 | |
| 1198 | if (rc || (flags & CMD_ASYNC)) |
| 1199 | return rc; |
| 1200 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1201 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1202 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1203 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1204 | res->hdr.flags); |
| 1205 | rc = -EIO; |
| 1206 | } |
| 1207 | |
| 1208 | if (rc == 0) { |
| 1209 | switch (res->u.add_sta.status) { |
| 1210 | case ADD_STA_SUCCESS_MSK: |
| 1211 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1212 | break; |
| 1213 | default: |
| 1214 | rc = -EIO; |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1215 | IWL_WARN(priv, "REPLY_ADD_STA failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1216 | break; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | priv->alloc_rxb_skb--; |
| 1221 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1222 | |
| 1223 | return rc; |
| 1224 | } |
| 1225 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1226 | static int iwl3945_update_sta_key_info(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1227 | struct ieee80211_key_conf *keyconf, |
| 1228 | u8 sta_id) |
| 1229 | { |
| 1230 | unsigned long flags; |
| 1231 | __le16 key_flags = 0; |
| 1232 | |
| 1233 | switch (keyconf->alg) { |
| 1234 | case ALG_CCMP: |
| 1235 | key_flags |= STA_KEY_FLG_CCMP; |
| 1236 | key_flags |= cpu_to_le16( |
| 1237 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1238 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1239 | break; |
| 1240 | case ALG_TKIP: |
| 1241 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1242 | default: |
| 1243 | return -EINVAL; |
| 1244 | } |
| 1245 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1246 | priv->stations_39[sta_id].keyinfo.alg = keyconf->alg; |
| 1247 | priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1248 | memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1249 | keyconf->keylen); |
| 1250 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1251 | memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1252 | keyconf->keylen); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1253 | priv->stations_39[sta_id].sta.key.key_flags = key_flags; |
| 1254 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1255 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1256 | |
| 1257 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1258 | |
| 1259 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1260 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1261 | return 0; |
| 1262 | } |
| 1263 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1264 | 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] | 1265 | { |
| 1266 | unsigned long flags; |
| 1267 | |
| 1268 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1269 | memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key)); |
| 1270 | memset(&priv->stations_39[sta_id].sta.key, 0, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1271 | sizeof(struct iwl4965_keyinfo)); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1272 | priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1273 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1274 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1275 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1276 | |
| 1277 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1278 | iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1279 | return 0; |
| 1280 | } |
| 1281 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1282 | static void iwl3945_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1283 | { |
| 1284 | struct list_head *element; |
| 1285 | |
| 1286 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1287 | priv->frames_count); |
| 1288 | |
| 1289 | while (!list_empty(&priv->free_frames)) { |
| 1290 | element = priv->free_frames.next; |
| 1291 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1292 | kfree(list_entry(element, struct iwl3945_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1293 | priv->frames_count--; |
| 1294 | } |
| 1295 | |
| 1296 | if (priv->frames_count) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1297 | 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] | 1298 | priv->frames_count); |
| 1299 | priv->frames_count = 0; |
| 1300 | } |
| 1301 | } |
| 1302 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1303 | static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1304 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1305 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1306 | struct list_head *element; |
| 1307 | if (list_empty(&priv->free_frames)) { |
| 1308 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1309 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1310 | IWL_ERR(priv, "Could not allocate frame!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1311 | return NULL; |
| 1312 | } |
| 1313 | |
| 1314 | priv->frames_count++; |
| 1315 | return frame; |
| 1316 | } |
| 1317 | |
| 1318 | element = priv->free_frames.next; |
| 1319 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1320 | return list_entry(element, struct iwl3945_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1323 | 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] | 1324 | { |
| 1325 | memset(frame, 0, sizeof(*frame)); |
| 1326 | list_add(&frame->list, &priv->free_frames); |
| 1327 | } |
| 1328 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1329 | unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1330 | struct ieee80211_hdr *hdr, |
Rami Rosen | 73ec1cc | 2008-12-16 09:37:07 +0200 | [diff] [blame] | 1331 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1332 | { |
| 1333 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1334 | if (!iwl3945_is_associated(priv) || !priv->ibss_beacon || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1335 | ((priv->iw_mode != NL80211_IFTYPE_ADHOC) && |
| 1336 | (priv->iw_mode != NL80211_IFTYPE_AP))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1337 | return 0; |
| 1338 | |
| 1339 | if (priv->ibss_beacon->len > left) |
| 1340 | return 0; |
| 1341 | |
| 1342 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1343 | |
| 1344 | return priv->ibss_beacon->len; |
| 1345 | } |
| 1346 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1347 | static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1348 | { |
| 1349 | u8 i; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1350 | int rate_mask; |
| 1351 | |
| 1352 | /* Set rate mask*/ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1353 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1354 | rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK; |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1355 | else |
Chatre, Reinette | dbce56a | 2008-11-12 13:14:07 -0800 | [diff] [blame] | 1356 | rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1357 | |
| 1358 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1359 | i = iwl3945_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1360 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1361 | return iwl3945_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1364 | /* No valid rate was found. Assign the lowest one */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1365 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1366 | return IWL_RATE_1M_PLCP; |
| 1367 | else |
| 1368 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1371 | static int iwl3945_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1372 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1373 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1374 | unsigned int frame_size; |
| 1375 | int rc; |
| 1376 | u8 rate; |
| 1377 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1378 | frame = iwl3945_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1379 | |
| 1380 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1381 | IWL_ERR(priv, "Could not obtain free frame buffer for beacon " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1382 | "command.\n"); |
| 1383 | return -ENOMEM; |
| 1384 | } |
| 1385 | |
Kolekar, Abhijeet | c24f081 | 2008-11-07 09:58:44 -0800 | [diff] [blame] | 1386 | rate = iwl3945_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1387 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1388 | frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1389 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1390 | rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1391 | &frame->u.cmd[0]); |
| 1392 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1393 | iwl3945_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1394 | |
| 1395 | return rc; |
| 1396 | } |
| 1397 | |
| 1398 | /****************************************************************************** |
| 1399 | * |
| 1400 | * EEPROM related functions |
| 1401 | * |
| 1402 | ******************************************************************************/ |
| 1403 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1404 | static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1405 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1406 | memcpy(mac, priv->eeprom39.mac_address, 6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1409 | /* |
| 1410 | * Clear the OWNER_MSK, to establish driver (instead of uCode running on |
| 1411 | * embedded controller) as EEPROM reader; each read is a series of pulses |
| 1412 | * to/from the EEPROM chip, not a single event, so even reads could conflict |
| 1413 | * if they weren't arbitrated by some ownership mechanism. Here, the driver |
| 1414 | * simply claims ownership, which should be safe when this function is called |
| 1415 | * (i.e. before loading uCode!). |
| 1416 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1417 | static inline int iwl3945_eeprom_acquire_semaphore(struct iwl_priv *priv) |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1418 | { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1419 | _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] | 1420 | return 0; |
| 1421 | } |
| 1422 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1423 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1424 | * iwl3945_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1425 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1426 | * Load the EEPROM contents from adapter into priv->eeprom39 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1427 | * |
| 1428 | * NOTE: This routine uses the non-debug IO access functions. |
| 1429 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1430 | int iwl3945_eeprom_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1431 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1432 | u16 *e = (u16 *)&priv->eeprom39; |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1433 | u32 gp = iwl_read32(priv, CSR_EEPROM_GP); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1434 | int sz = sizeof(priv->eeprom39); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1435 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1436 | u16 addr; |
| 1437 | |
| 1438 | /* The EEPROM structure has several padding buffers within it |
| 1439 | * and when adding new EEPROM maps is subject to programmer errors |
| 1440 | * which may be very difficult to identify without explicitly |
| 1441 | * checking the resulting size of the eeprom map. */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1442 | BUILD_BUG_ON(sizeof(priv->eeprom39) != IWL_EEPROM_IMAGE_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1443 | |
| 1444 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1445 | IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1446 | return -ENOENT; |
| 1447 | } |
| 1448 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1449 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1450 | ret = iwl3945_eeprom_acquire_semaphore(priv); |
| 1451 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1452 | IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1453 | return -ENOENT; |
| 1454 | } |
| 1455 | |
| 1456 | /* eeprom is an array of 16bit values */ |
| 1457 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1458 | u32 r; |
| 1459 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1460 | _iwl_write32(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1461 | CSR_EEPROM_REG_MSK_ADDR & (addr << 1)); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1462 | _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
| 1463 | ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG, |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1464 | CSR_EEPROM_REG_READ_VALID_MSK, |
| 1465 | IWL_EEPROM_ACCESS_TIMEOUT); |
| 1466 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1467 | IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr); |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1468 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1469 | } |
Zhu, Yi | 3d5717a | 2008-12-11 10:33:36 -0800 | [diff] [blame] | 1470 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1471 | r = _iwl_read_direct32(priv, CSR_EEPROM_REG); |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1472 | e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | return 0; |
| 1476 | } |
| 1477 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1478 | static void iwl3945_unset_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1479 | { |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1480 | if (priv->shared_virt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1481 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1482 | sizeof(struct iwl3945_shared), |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1483 | priv->shared_virt, |
| 1484 | priv->shared_phys); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1488 | * 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] | 1489 | * |
| 1490 | * return : set the bit for each supported rate insert in ie |
| 1491 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1492 | static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1493 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1494 | { |
| 1495 | u16 ret_rates = 0, bit; |
| 1496 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1497 | u8 *cnt = ie; |
| 1498 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1499 | |
| 1500 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1501 | if (bit & supported_rate) { |
| 1502 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1503 | rates[*cnt] = iwl3945_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1504 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1505 | (*cnt)++; |
| 1506 | (*left)--; |
| 1507 | if ((*left <= 0) || |
| 1508 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1509 | break; |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | return ret_rates; |
| 1514 | } |
| 1515 | |
| 1516 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1517 | * 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] | 1518 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1519 | static u16 iwl3945_fill_probe_req(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1520 | struct ieee80211_mgmt *frame, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 1521 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1522 | { |
| 1523 | int len = 0; |
| 1524 | u8 *pos = NULL; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1525 | u16 active_rates, ret_rates, cck_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1526 | |
| 1527 | /* Make sure there is enough space for the probe request, |
| 1528 | * two mandatory IEs and the data */ |
| 1529 | left -= 24; |
| 1530 | if (left < 0) |
| 1531 | return 0; |
| 1532 | len += 24; |
| 1533 | |
| 1534 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1535 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1536 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 1537 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1538 | frame->seq_ctrl = 0; |
| 1539 | |
| 1540 | /* fill in our indirect SSID IE */ |
| 1541 | /* ...next IE... */ |
| 1542 | |
| 1543 | left -= 2; |
| 1544 | if (left < 0) |
| 1545 | return 0; |
| 1546 | len += 2; |
| 1547 | pos = &(frame->u.probe_req.variable[0]); |
| 1548 | *pos++ = WLAN_EID_SSID; |
| 1549 | *pos++ = 0; |
| 1550 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1551 | /* fill in supported rate */ |
| 1552 | /* ...next IE... */ |
| 1553 | left -= 2; |
| 1554 | if (left < 0) |
| 1555 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1556 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1557 | /* ... fill it in... */ |
| 1558 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1559 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1560 | |
| 1561 | priv->active_rate = priv->rates_mask; |
| 1562 | active_rates = priv->active_rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1563 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 1564 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1565 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1566 | ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1567 | priv->active_rate_basic, &left); |
| 1568 | active_rates &= ~ret_rates; |
| 1569 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1570 | ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1571 | priv->active_rate_basic, &left); |
| 1572 | active_rates &= ~ret_rates; |
| 1573 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1574 | len += 2 + *pos; |
| 1575 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1576 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | goto fill_end; |
| 1578 | |
| 1579 | /* fill in supported extended rate */ |
| 1580 | /* ...next IE... */ |
| 1581 | left -= 2; |
| 1582 | if (left < 0) |
| 1583 | return 0; |
| 1584 | /* ... fill it in... */ |
| 1585 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1586 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1587 | iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1588 | priv->active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1589 | if (*pos > 0) |
| 1590 | len += 2 + *pos; |
| 1591 | |
| 1592 | fill_end: |
| 1593 | return (u16)len; |
| 1594 | } |
| 1595 | |
| 1596 | /* |
| 1597 | * QoS support |
| 1598 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1599 | static int iwl3945_send_qos_params_command(struct iwl_priv *priv, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1600 | struct iwl_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1601 | { |
| 1602 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1603 | return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1604 | sizeof(struct iwl_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1607 | static void iwl3945_reset_qos(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1608 | { |
| 1609 | u16 cw_min = 15; |
| 1610 | u16 cw_max = 1023; |
| 1611 | u8 aifs = 2; |
| 1612 | u8 is_legacy = 0; |
| 1613 | unsigned long flags; |
| 1614 | int i; |
| 1615 | |
| 1616 | spin_lock_irqsave(&priv->lock, flags); |
| 1617 | priv->qos_data.qos_active = 0; |
| 1618 | |
Winkler, Tomas | 6d1ef1a | 2008-12-09 11:29:00 -0800 | [diff] [blame] | 1619 | /* QoS always active in AP and ADHOC mode |
| 1620 | * In STA mode wait for association |
| 1621 | */ |
| 1622 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC || |
| 1623 | priv->iw_mode == NL80211_IFTYPE_AP) |
| 1624 | priv->qos_data.qos_active = 1; |
| 1625 | else |
| 1626 | priv->qos_data.qos_active = 0; |
| 1627 | |
| 1628 | |
| 1629 | /* check for legacy mode */ |
| 1630 | if ((priv->iw_mode == NL80211_IFTYPE_ADHOC && |
| 1631 | (priv->active_rate & IWL_OFDM_RATES_MASK) == 0) || |
| 1632 | (priv->iw_mode == NL80211_IFTYPE_STATION && |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1633 | (priv->staging39_rxon.flags & RXON_FLG_SHORT_SLOT_MSK) == 0)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1634 | cw_min = 31; |
| 1635 | is_legacy = 1; |
| 1636 | } |
| 1637 | |
| 1638 | if (priv->qos_data.qos_active) |
| 1639 | aifs = 3; |
| 1640 | |
| 1641 | priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); |
| 1642 | priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); |
| 1643 | priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; |
| 1644 | priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; |
| 1645 | priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; |
| 1646 | |
| 1647 | if (priv->qos_data.qos_active) { |
| 1648 | i = 1; |
| 1649 | priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); |
| 1650 | priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); |
| 1651 | priv->qos_data.def_qos_parm.ac[i].aifsn = 7; |
| 1652 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 1653 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1654 | |
| 1655 | i = 2; |
| 1656 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1657 | cpu_to_le16((cw_min + 1) / 2 - 1); |
| 1658 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1659 | cpu_to_le16(cw_max); |
| 1660 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 1661 | if (is_legacy) |
| 1662 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1663 | cpu_to_le16(6016); |
| 1664 | else |
| 1665 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1666 | cpu_to_le16(3008); |
| 1667 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1668 | |
| 1669 | i = 3; |
| 1670 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1671 | cpu_to_le16((cw_min + 1) / 4 - 1); |
| 1672 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1673 | cpu_to_le16((cw_max + 1) / 2 - 1); |
| 1674 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 1675 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1676 | if (is_legacy) |
| 1677 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1678 | cpu_to_le16(3264); |
| 1679 | else |
| 1680 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1681 | cpu_to_le16(1504); |
| 1682 | } else { |
| 1683 | for (i = 1; i < 4; i++) { |
| 1684 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1685 | cpu_to_le16(cw_min); |
| 1686 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1687 | cpu_to_le16(cw_max); |
| 1688 | priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; |
| 1689 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 1690 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1691 | } |
| 1692 | } |
| 1693 | IWL_DEBUG_QOS("set QoS to default \n"); |
| 1694 | |
| 1695 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1696 | } |
| 1697 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1698 | static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1699 | { |
| 1700 | unsigned long flags; |
| 1701 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1702 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1703 | return; |
| 1704 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1705 | spin_lock_irqsave(&priv->lock, flags); |
| 1706 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1707 | |
| 1708 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1709 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1710 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1711 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
| 1712 | |
| 1713 | if (priv->qos_data.qos_active) |
| 1714 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1715 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1716 | |
| 1717 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1718 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1719 | if (force || iwl3945_is_associated(priv)) { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1720 | IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1721 | priv->qos_data.qos_active); |
| 1722 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1723 | iwl3945_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1724 | &(priv->qos_data.def_qos_parm)); |
| 1725 | } |
| 1726 | } |
| 1727 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1728 | /* |
| 1729 | * Power management (not Tx power!) functions |
| 1730 | */ |
| 1731 | #define MSEC_TO_USEC 1024 |
| 1732 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1733 | |
| 1734 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 1735 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1736 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 1737 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 1738 | __constant_cpu_to_le32(X1), \ |
| 1739 | __constant_cpu_to_le32(X2), \ |
| 1740 | __constant_cpu_to_le32(X3), \ |
| 1741 | __constant_cpu_to_le32(X4)} |
| 1742 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1743 | /* default power management (not Tx power) table values */ |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1744 | /* for TIM 0-10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1745 | static struct iwl_power_vec_entry range_0[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1746 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1747 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 1748 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 1749 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 1750 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 1751 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 1752 | }; |
| 1753 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1754 | /* for TIM > 10 */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1755 | static struct iwl_power_vec_entry range_1[IWL39_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1756 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1757 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 1758 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 1759 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 1760 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 1761 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 1762 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 1763 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 1764 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 1765 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 1766 | }; |
| 1767 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1768 | int iwl3945_power_init_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1769 | { |
| 1770 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1771 | struct iwl3945_power_mgr *pow_data; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1772 | int size = sizeof(struct iwl_power_vec_entry) * IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1773 | u16 pci_pm; |
| 1774 | |
| 1775 | IWL_DEBUG_POWER("Initialize power \n"); |
| 1776 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1777 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1778 | |
| 1779 | memset(pow_data, 0, sizeof(*pow_data)); |
| 1780 | |
| 1781 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 1782 | pow_data->dtim_val = 0xffff; |
| 1783 | |
| 1784 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 1785 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 1786 | |
| 1787 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 1788 | if (rc != 0) |
| 1789 | return 0; |
| 1790 | else { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1791 | struct iwl_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1792 | |
| 1793 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 1794 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1795 | for (i = 0; i < IWL39_POWER_AC; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1796 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 1797 | |
| 1798 | if (pci_pm & 0x1) |
| 1799 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 1800 | else |
| 1801 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 1802 | } |
| 1803 | } |
| 1804 | return rc; |
| 1805 | } |
| 1806 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1807 | static int iwl3945_update_power_cmd(struct iwl_priv *priv, |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1808 | struct iwl_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1809 | { |
| 1810 | int rc = 0, i; |
| 1811 | u8 skip; |
| 1812 | u32 max_sleep = 0; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1813 | struct iwl_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1814 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1815 | struct iwl3945_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1816 | |
| 1817 | if (mode > IWL_POWER_INDEX_5) { |
| 1818 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 1819 | return -1; |
| 1820 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1821 | pow_data = &(priv->power_data_39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1822 | |
| 1823 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 1824 | range = &pow_data->pwr_range_0[0]; |
| 1825 | else |
| 1826 | range = &pow_data->pwr_range_1[1]; |
| 1827 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1828 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1829 | |
| 1830 | #ifdef IWL_MAC80211_DISABLE |
| 1831 | if (priv->assoc_network != NULL) { |
| 1832 | unsigned long flags; |
| 1833 | |
| 1834 | period = priv->assoc_network->tim.tim_period; |
| 1835 | } |
| 1836 | #endif /*IWL_MAC80211_DISABLE */ |
| 1837 | skip = range[mode].no_dtim; |
| 1838 | |
| 1839 | if (period == 0) { |
| 1840 | period = 1; |
| 1841 | skip = 0; |
| 1842 | } |
| 1843 | |
| 1844 | if (skip == 0) { |
| 1845 | max_sleep = period; |
| 1846 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1847 | } else { |
| 1848 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 1849 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 1850 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1851 | } |
| 1852 | |
| 1853 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 1854 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 1855 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 1856 | } |
| 1857 | |
| 1858 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 1859 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 1860 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 1861 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 1862 | le32_to_cpu(cmd->sleep_interval[0]), |
| 1863 | le32_to_cpu(cmd->sleep_interval[1]), |
| 1864 | le32_to_cpu(cmd->sleep_interval[2]), |
| 1865 | le32_to_cpu(cmd->sleep_interval[3]), |
| 1866 | le32_to_cpu(cmd->sleep_interval[4])); |
| 1867 | |
| 1868 | return rc; |
| 1869 | } |
| 1870 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1871 | static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1872 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 1873 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1874 | int rc; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1875 | struct iwl_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1876 | |
| 1877 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1878 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1879 | * else user level */ |
| 1880 | switch (mode) { |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1881 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1882 | final_mode = IWL_POWER_INDEX_3; |
| 1883 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 1884 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1885 | final_mode = IWL_POWER_MODE_CAM; |
| 1886 | break; |
| 1887 | default: |
| 1888 | final_mode = mode; |
| 1889 | break; |
| 1890 | } |
| 1891 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1892 | iwl3945_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1893 | |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1894 | /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */ |
| 1895 | rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, |
| 1896 | sizeof(struct iwl3945_powertable_cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1897 | |
| 1898 | if (final_mode == IWL_POWER_MODE_CAM) |
| 1899 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 1900 | else |
| 1901 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 1902 | |
| 1903 | return rc; |
| 1904 | } |
| 1905 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1906 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1907 | * iwl3945_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1908 | * |
| 1909 | * NOTE: priv->mutex is not required before calling this function |
| 1910 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1911 | static int iwl3945_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1912 | { |
| 1913 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1914 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1915 | return 0; |
| 1916 | } |
| 1917 | |
| 1918 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1919 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1920 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 1921 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1922 | queue_work(priv->workqueue, &priv->abort_scan); |
| 1923 | |
| 1924 | } else |
| 1925 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 1926 | |
| 1927 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1928 | } |
| 1929 | |
| 1930 | return 0; |
| 1931 | } |
| 1932 | |
| 1933 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1934 | * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1935 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 1936 | * |
| 1937 | * NOTE: priv->mutex must be held before calling this function |
| 1938 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1939 | 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] | 1940 | { |
| 1941 | unsigned long now = jiffies; |
| 1942 | int ret; |
| 1943 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1944 | ret = iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1945 | if (ret && ms) { |
| 1946 | mutex_unlock(&priv->mutex); |
| 1947 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 1948 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1949 | msleep(1); |
| 1950 | mutex_lock(&priv->mutex); |
| 1951 | |
| 1952 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1953 | } |
| 1954 | |
| 1955 | return ret; |
| 1956 | } |
| 1957 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1958 | #define MAX_UCODE_BEACON_INTERVAL 1024 |
| 1959 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1960 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1961 | static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1962 | { |
| 1963 | u16 new_val = 0; |
| 1964 | u16 beacon_factor = 0; |
| 1965 | |
| 1966 | beacon_factor = |
| 1967 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1968 | / MAX_UCODE_BEACON_INTERVAL; |
| 1969 | new_val = beacon_val / beacon_factor; |
| 1970 | |
| 1971 | return cpu_to_le16(new_val); |
| 1972 | } |
| 1973 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1974 | static void iwl3945_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1975 | { |
| 1976 | u64 interval_tm_unit; |
| 1977 | u64 tsf, result; |
| 1978 | unsigned long flags; |
| 1979 | struct ieee80211_conf *conf = NULL; |
| 1980 | u16 beacon_int = 0; |
| 1981 | |
| 1982 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1983 | |
| 1984 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1985 | priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1986 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1987 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 1988 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1989 | |
| 1990 | beacon_int = priv->beacon_int; |
| 1991 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1992 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1993 | if (priv->iw_mode == NL80211_IFTYPE_STATION) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1994 | if (beacon_int == 0) { |
| 1995 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1996 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1997 | } else { |
| 1998 | priv->rxon_timing.beacon_interval = |
| 1999 | cpu_to_le16(beacon_int); |
| 2000 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2001 | iwl3945_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2002 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2003 | } |
| 2004 | |
| 2005 | priv->rxon_timing.atim_window = 0; |
| 2006 | } else { |
| 2007 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2008 | iwl3945_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2009 | /* TODO: we need to get atim_window from upper stack |
| 2010 | * for now we set to 0 */ |
| 2011 | priv->rxon_timing.atim_window = 0; |
| 2012 | } |
| 2013 | |
| 2014 | interval_tm_unit = |
| 2015 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 2016 | result = do_div(tsf, interval_tm_unit); |
| 2017 | priv->rxon_timing.beacon_init_val = |
| 2018 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 2019 | |
| 2020 | IWL_DEBUG_ASSOC |
| 2021 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 2022 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 2023 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 2024 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 2025 | } |
| 2026 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2027 | static int iwl3945_scan_initiate(struct iwl_priv *priv) |
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 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2030 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 2031 | return -EIO; |
| 2032 | } |
| 2033 | |
| 2034 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2035 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 2036 | return -EAGAIN; |
| 2037 | } |
| 2038 | |
| 2039 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2040 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 2041 | "Queuing.\n"); |
| 2042 | return -EAGAIN; |
| 2043 | } |
| 2044 | |
| 2045 | IWL_DEBUG_INFO("Starting scan...\n"); |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 2046 | if (priv->cfg->sku & IWL_SKU_G) |
| 2047 | priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ); |
| 2048 | if (priv->cfg->sku & IWL_SKU_A) |
| 2049 | priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2050 | set_bit(STATUS_SCANNING, &priv->status); |
| 2051 | priv->scan_start = jiffies; |
| 2052 | priv->scan_pass_start = priv->scan_start; |
| 2053 | |
| 2054 | queue_work(priv->workqueue, &priv->request_scan); |
| 2055 | |
| 2056 | return 0; |
| 2057 | } |
| 2058 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2059 | 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] | 2060 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2061 | struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2062 | |
| 2063 | if (hw_decrypt) |
| 2064 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 2065 | else |
| 2066 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 2067 | |
| 2068 | return 0; |
| 2069 | } |
| 2070 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2071 | static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2072 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2073 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2074 | if (band == IEEE80211_BAND_5GHZ) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2075 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2076 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 2077 | | RXON_FLG_CCK_MSK); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2078 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2079 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2080 | /* Copied from iwl3945_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2081 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2082 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2083 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2084 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2085 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2086 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2087 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2088 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2089 | priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 2090 | priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 2091 | priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2096 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2097 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2098 | static void iwl3945_connection_init_rx_config(struct iwl_priv *priv, |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 2099 | int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2100 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2101 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2102 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2103 | memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2104 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 2105 | switch (mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2106 | case NL80211_IFTYPE_AP: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2107 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2108 | break; |
| 2109 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2110 | case NL80211_IFTYPE_STATION: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2111 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 2112 | priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2113 | break; |
| 2114 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2115 | case NL80211_IFTYPE_ADHOC: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2116 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 2117 | priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2118 | priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2119 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2120 | break; |
| 2121 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2122 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2123 | priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 2124 | priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2125 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2126 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 2127 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2128 | IWL_ERR(priv, "Unsupported interface type %d\n", mode); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 2129 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | #if 0 |
| 2133 | /* TODO: Figure out when short_preamble would be set and cache from |
| 2134 | * that */ |
| 2135 | if (!hw_to_local(priv->hw)->short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2136 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2137 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2138 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2139 | #endif |
| 2140 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2141 | ch_info = iwl3945_get_channel_info(priv, priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2142 | le16_to_cpu(priv->active39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2143 | |
| 2144 | if (!ch_info) |
| 2145 | ch_info = &priv->channel_info[0]; |
| 2146 | |
| 2147 | /* |
| 2148 | * in some case A channels are all non IBSS |
| 2149 | * in this case force B/G channel |
| 2150 | */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 2151 | if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2152 | ch_info = &priv->channel_info[0]; |
| 2153 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2154 | priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2155 | if (is_channel_a_band(ch_info)) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2156 | priv->band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2157 | else |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2158 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2159 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2160 | iwl3945_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2161 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2162 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2163 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2164 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2165 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2166 | } |
| 2167 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2168 | static int iwl3945_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2169 | { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2170 | if (mode == NL80211_IFTYPE_ADHOC) { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2171 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2172 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2173 | ch_info = iwl3945_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2174 | priv->band, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2175 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2176 | |
| 2177 | if (!ch_info || !is_channel_ibss(ch_info)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2178 | IWL_ERR(priv, "channel %d not IBSS channel\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2179 | le16_to_cpu(priv->staging39_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2180 | return -EINVAL; |
| 2181 | } |
| 2182 | } |
| 2183 | |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 2184 | iwl3945_connection_init_rx_config(priv, mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2185 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2186 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2187 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2188 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2189 | /* don't commit rxon if rf-kill is on*/ |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2190 | if (!iwl3945_is_ready_rf(priv)) |
| 2191 | return -EAGAIN; |
| 2192 | |
| 2193 | cancel_delayed_work(&priv->scan_check); |
| 2194 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2195 | IWL_WARN(priv, "Aborted scan still in progress after 100ms\n"); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2196 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2197 | return -EAGAIN; |
| 2198 | } |
| 2199 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2200 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2201 | |
| 2202 | return 0; |
| 2203 | } |
| 2204 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2205 | static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2206 | struct ieee80211_tx_info *info, |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 2207 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2208 | struct sk_buff *skb_frag, |
| 2209 | int last_frag) |
| 2210 | { |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 2211 | struct iwl3945_hw_key *keyinfo = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2212 | &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2213 | |
| 2214 | switch (keyinfo->alg) { |
| 2215 | case ALG_CCMP: |
| 2216 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2217 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2218 | IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2219 | break; |
| 2220 | |
| 2221 | case ALG_TKIP: |
| 2222 | #if 0 |
| 2223 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2224 | |
| 2225 | if (last_frag) |
| 2226 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2227 | 8); |
| 2228 | else |
| 2229 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2230 | #endif |
| 2231 | break; |
| 2232 | |
| 2233 | case ALG_WEP: |
| 2234 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2235 | (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] | 2236 | |
| 2237 | if (keyinfo->keylen == 13) |
| 2238 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2239 | |
| 2240 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2241 | |
| 2242 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2243 | "with key %d\n", info->control.hw_key->hw_key_idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2244 | break; |
| 2245 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2246 | default: |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2247 | IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2248 | break; |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | /* |
| 2253 | * handle build REPLY_TX command notification. |
| 2254 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2255 | static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 2256 | struct iwl_cmd *cmd, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2257 | struct ieee80211_tx_info *info, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2258 | struct ieee80211_hdr *hdr, |
| 2259 | int is_unicast, u8 std_id) |
| 2260 | { |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2261 | __le16 fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2262 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2263 | u8 rc_flags = info->control.rates[0].flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2264 | |
| 2265 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2266 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2267 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2268 | if (ieee80211_is_mgmt(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2269 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2270 | if (ieee80211_is_probe_resp(fc) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2271 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2272 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2273 | } else { |
| 2274 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2275 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2276 | } |
| 2277 | |
| 2278 | cmd->cmd.tx.sta_id = std_id; |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2279 | if (ieee80211_has_morefrags(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2280 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2281 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2282 | if (ieee80211_is_data_qos(fc)) { |
| 2283 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2284 | cmd->cmd.tx.tid_tspec = qc[0] & 0xf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2285 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2286 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2287 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2288 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2289 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2290 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2291 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2292 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 2293 | } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2294 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2295 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2296 | } |
| 2297 | |
| 2298 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2299 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2300 | |
| 2301 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2302 | if (ieee80211_is_mgmt(fc)) { |
| 2303 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2304 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2305 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2306 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2307 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2308 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2309 | #ifdef CONFIG_IWL3945_LEDS |
| 2310 | priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len); |
| 2311 | #endif |
| 2312 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2313 | |
| 2314 | cmd->cmd.tx.driver_txop = 0; |
| 2315 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2316 | cmd->cmd.tx.next_frame_len = 0; |
| 2317 | } |
| 2318 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2319 | /** |
| 2320 | * iwl3945_get_sta_id - Find station's index within station table |
| 2321 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2322 | 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] | 2323 | { |
| 2324 | int sta_id; |
| 2325 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2326 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2327 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2328 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2329 | is_multicast_ether_addr(hdr->addr1)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2330 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2331 | |
| 2332 | switch (priv->iw_mode) { |
| 2333 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2334 | /* If we are a client station in a BSS network, use the special |
| 2335 | * AP station entry (that's the only station we communicate with) */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2336 | case NL80211_IFTYPE_STATION: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2337 | return IWL_AP_ID; |
| 2338 | |
| 2339 | /* If we are an AP, then find the station, or use BCAST */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2340 | case NL80211_IFTYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2341 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2342 | if (sta_id != IWL_INVALID_STATION) |
| 2343 | return sta_id; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2344 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2345 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2346 | /* If this frame is going out to an IBSS network, find the station, |
| 2347 | * or create a new station table entry */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2348 | case NL80211_IFTYPE_ADHOC: { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2349 | /* Create new station table entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2350 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2351 | if (sta_id != IWL_INVALID_STATION) |
| 2352 | return sta_id; |
| 2353 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2354 | sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2355 | |
| 2356 | if (sta_id != IWL_INVALID_STATION) |
| 2357 | return sta_id; |
| 2358 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2359 | IWL_DEBUG_DROP("Station %pM not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2360 | "Defaulting to broadcast...\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2361 | hdr->addr1); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2362 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2363 | return priv->hw_params.bcast_sta_id; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2364 | } |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2365 | /* If we are in monitor mode, use BCAST. This is required for |
| 2366 | * packet injection. */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2367 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2368 | return priv->hw_params.bcast_sta_id; |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2369 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2370 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2371 | IWL_WARN(priv, "Unknown mode of operation: %d\n", |
| 2372 | priv->iw_mode); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2373 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2374 | } |
| 2375 | } |
| 2376 | |
| 2377 | /* |
| 2378 | * start REPLY_TX command process |
| 2379 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2380 | 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] | 2381 | { |
| 2382 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2383 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2384 | struct iwl3945_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2385 | u32 *control_flags; |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 2386 | int txq_id = skb_get_queue_mapping(skb); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2387 | struct iwl3945_tx_queue *txq = NULL; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2388 | struct iwl_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2389 | dma_addr_t phys_addr; |
| 2390 | dma_addr_t txcmd_phys; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 2391 | struct iwl_cmd *out_cmd = NULL; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2392 | u16 len, idx, len_org, hdr_len; |
| 2393 | u8 id; |
| 2394 | u8 unicast; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2395 | u8 sta_id; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2396 | u8 tid = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2397 | u16 seq_number = 0; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2398 | __le16 fc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2399 | u8 wait_write_ptr = 0; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 2400 | u8 *qc = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2401 | unsigned long flags; |
| 2402 | int rc; |
| 2403 | |
| 2404 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2405 | if (iwl3945_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2406 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2407 | goto drop_unlock; |
| 2408 | } |
| 2409 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2410 | 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] | 2411 | IWL_ERR(priv, "ERROR: No TX rate available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2412 | goto drop_unlock; |
| 2413 | } |
| 2414 | |
| 2415 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2416 | id = 0; |
| 2417 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2418 | fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2419 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2420 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2421 | if (ieee80211_is_auth(fc)) |
| 2422 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2423 | else if (ieee80211_is_assoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2424 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2425 | else if (ieee80211_is_reassoc_req(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2426 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2427 | #endif |
| 2428 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2429 | /* drop all data frame if we are not associated */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2430 | if (ieee80211_is_data(fc) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2431 | (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 2432 | (!iwl3945_is_associated(priv) || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2433 | ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2434 | IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2435 | goto drop_unlock; |
| 2436 | } |
| 2437 | |
| 2438 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2439 | |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2440 | hdr_len = ieee80211_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2441 | |
| 2442 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2443 | sta_id = iwl3945_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2444 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2445 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n", |
| 2446 | hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2447 | goto drop; |
| 2448 | } |
| 2449 | |
| 2450 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2451 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2452 | if (ieee80211_is_data_qos(fc)) { |
| 2453 | qc = ieee80211_get_qos_ctl(hdr); |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 2454 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2455 | seq_number = priv->stations_39[sta_id].tid[tid].seq_number & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2456 | IEEE80211_SCTL_SEQ; |
| 2457 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2458 | (hdr->seq_ctrl & |
| 2459 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2460 | seq_number += 0x10; |
| 2461 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2462 | |
| 2463 | /* Descriptor for chosen Tx queue */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2464 | txq = &priv->txq39[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2465 | q = &txq->q; |
| 2466 | |
| 2467 | spin_lock_irqsave(&priv->lock, flags); |
| 2468 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2469 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2470 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2471 | memset(tfd, 0, sizeof(*tfd)); |
| 2472 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2473 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2474 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2475 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2476 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2477 | txq->txb[q->write_ptr].skb[0] = skb; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2478 | |
| 2479 | /* Init first empty entry in queue's array of Tx/cmd buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2480 | out_cmd = &txq->cmd[idx]; |
| 2481 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2482 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2483 | |
| 2484 | /* |
| 2485 | * Set up the Tx-command (not MAC!) header. |
| 2486 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2487 | * after Tx, uCode's Tx response will return this value so driver can |
| 2488 | * locate the frame within the tx queue and do post-tx processing. |
| 2489 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2490 | out_cmd->hdr.cmd = REPLY_TX; |
| 2491 | 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] | 2492 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2493 | |
| 2494 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2495 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 2496 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2497 | /* |
| 2498 | * Use the first empty entry in this queue's command buffer array |
| 2499 | * to contain the Tx command and MAC header concatenated together |
| 2500 | * (payload data will be in another buffer). |
| 2501 | * Size of this varies, due to varying MAC header length. |
| 2502 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2503 | * of the MAC header (device reads on dword boundaries). |
| 2504 | * We'll tell device about this padding later. |
| 2505 | */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2506 | len = sizeof(struct iwl3945_tx_cmd) + |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 2507 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2508 | |
| 2509 | len_org = len; |
| 2510 | len = (len + 3) & ~3; |
| 2511 | |
| 2512 | if (len_org != len) |
| 2513 | len_org = 1; |
| 2514 | else |
| 2515 | len_org = 0; |
| 2516 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2517 | /* Physical address of this Tx command's header (not MAC header!), |
| 2518 | * within command buffer array. */ |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 2519 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx + |
| 2520 | offsetof(struct iwl_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2521 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2522 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2523 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2524 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2525 | |
Johannes Berg | d0f0980 | 2008-07-29 11:32:07 +0200 | [diff] [blame] | 2526 | if (info->control.hw_key) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2527 | iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2528 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2529 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2530 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2531 | len = skb->len - hdr_len; |
| 2532 | if (len) { |
| 2533 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2534 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2535 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2536 | } |
| 2537 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2538 | if (!len) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2539 | /* If there is no payload, then we use only one Tx buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2540 | *control_flags = TFD_CTL_COUNT_SET(1); |
| 2541 | else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2542 | /* Else use 2 buffers. |
| 2543 | * Tell 3945 about any padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2544 | *control_flags = TFD_CTL_COUNT_SET(2) | |
| 2545 | TFD_CTL_PAD_SET(U32_PAD(len)); |
| 2546 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2547 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2548 | len = (u16)skb->len; |
| 2549 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 2550 | |
| 2551 | /* TODO need this for burst mode later on */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2552 | 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] | 2553 | |
| 2554 | /* set is_hcca to 0; it probably will never be implemented */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2555 | 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] | 2556 | |
| 2557 | out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; |
| 2558 | out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; |
| 2559 | |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 2560 | if (!ieee80211_has_morefrags(hdr->frame_control)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2561 | txq->need_update = 1; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 2562 | if (qc) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2563 | priv->stations_39[sta_id].tid[tid].seq_number = seq_number; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2564 | } else { |
| 2565 | wait_write_ptr = 1; |
| 2566 | txq->need_update = 0; |
| 2567 | } |
| 2568 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2569 | iwl_print_hex_dump(priv, IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2570 | sizeof(out_cmd->cmd.tx)); |
| 2571 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2572 | 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] | 2573 | ieee80211_hdrlen(fc)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2574 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2575 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2576 | 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] | 2577 | rc = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2578 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2579 | |
| 2580 | if (rc) |
| 2581 | return rc; |
| 2582 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2583 | if ((iwl_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2584 | && priv->mac80211_registered) { |
| 2585 | if (wait_write_ptr) { |
| 2586 | spin_lock_irqsave(&priv->lock, flags); |
| 2587 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2588 | iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2589 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2590 | } |
| 2591 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 2592 | ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | return 0; |
| 2596 | |
| 2597 | drop_unlock: |
| 2598 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2599 | drop: |
| 2600 | return -1; |
| 2601 | } |
| 2602 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2603 | static void iwl3945_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2604 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2605 | const struct ieee80211_supported_band *sband = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2606 | struct ieee80211_rate *rate; |
| 2607 | int i; |
| 2608 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2609 | sband = iwl3945_get_band(priv, priv->band); |
| 2610 | if (!sband) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2611 | 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] | 2612 | return; |
| 2613 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2614 | |
| 2615 | priv->active_rate = 0; |
| 2616 | priv->active_rate_basic = 0; |
| 2617 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2618 | IWL_DEBUG_RATE("Setting rates for %s GHz\n", |
| 2619 | sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2620 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2621 | for (i = 0; i < sband->n_bitrates; i++) { |
| 2622 | rate = &sband->bitrates[i]; |
| 2623 | if ((rate->hw_value < IWL_RATE_COUNT) && |
| 2624 | !(rate->flags & IEEE80211_CHAN_DISABLED)) { |
| 2625 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n", |
| 2626 | rate->hw_value, iwl3945_rates[rate->hw_value].plcp); |
| 2627 | priv->active_rate |= (1 << rate->hw_value); |
| 2628 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2632 | priv->active_rate, priv->active_rate_basic); |
| 2633 | |
| 2634 | /* |
| 2635 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2636 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2637 | * OFDM |
| 2638 | */ |
| 2639 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2640 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2641 | ((priv->active_rate_basic & |
| 2642 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2643 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2644 | priv->staging39_rxon.cck_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2645 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2646 | |
| 2647 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2648 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2649 | ((priv->active_rate_basic & |
| 2650 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2651 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2652 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2653 | priv->staging39_rxon.ofdm_basic_rates = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2654 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2655 | } |
| 2656 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2657 | 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] | 2658 | { |
| 2659 | unsigned long flags; |
| 2660 | |
| 2661 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2662 | return; |
| 2663 | |
| 2664 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2665 | disable_radio ? "OFF" : "ON"); |
| 2666 | |
| 2667 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2668 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2669 | /* FIXME: This is a workaround for AP */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2670 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2671 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2672 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2673 | CSR_UCODE_SW_BIT_RFKILL); |
| 2674 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2675 | iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2676 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2677 | } |
| 2678 | return; |
| 2679 | } |
| 2680 | |
| 2681 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2682 | 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] | 2683 | |
| 2684 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2685 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2686 | |
| 2687 | /* wake up ucode */ |
| 2688 | msleep(10); |
| 2689 | |
| 2690 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2691 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2692 | if (!iwl_grab_nic_access(priv)) |
| 2693 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2694 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2695 | |
| 2696 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2697 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2698 | "disabled by HW switch\n"); |
| 2699 | return; |
| 2700 | } |
| 2701 | |
Zhu Yi | 808e72a | 2008-06-12 09:47:17 +0800 | [diff] [blame] | 2702 | if (priv->is_open) |
| 2703 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2704 | return; |
| 2705 | } |
| 2706 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2707 | 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] | 2708 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 2709 | { |
| 2710 | u16 fc = |
| 2711 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 2712 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2713 | if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2714 | return; |
| 2715 | |
| 2716 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 2717 | return; |
| 2718 | |
| 2719 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 2720 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2721 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2722 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2723 | RX_RES_STATUS_BAD_ICV_MIC) |
| 2724 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 2725 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 2726 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2727 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2728 | RX_RES_STATUS_DECRYPT_OK) { |
| 2729 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 2730 | stats->flag |= RX_FLAG_DECRYPTED; |
| 2731 | } |
| 2732 | break; |
| 2733 | |
| 2734 | default: |
| 2735 | break; |
| 2736 | } |
| 2737 | } |
| 2738 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2739 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2740 | |
| 2741 | #include "iwl-spectrum.h" |
| 2742 | |
| 2743 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 2744 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 2745 | #define TIME_UNIT 1024 |
| 2746 | |
| 2747 | /* |
| 2748 | * extended beacon time format |
| 2749 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 2750 | * the high 1 byte is the beacon counts |
| 2751 | * the lower 3 bytes is the time in usec within one beacon interval |
| 2752 | */ |
| 2753 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2754 | static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2755 | { |
| 2756 | u32 quot; |
| 2757 | u32 rem; |
| 2758 | u32 interval = beacon_interval * 1024; |
| 2759 | |
| 2760 | if (!interval || !usec) |
| 2761 | return 0; |
| 2762 | |
| 2763 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 2764 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 2765 | |
| 2766 | return (quot << 24) + rem; |
| 2767 | } |
| 2768 | |
| 2769 | /* base is usually what we get from ucode with each received frame, |
| 2770 | * the same as HW timer counter counting down |
| 2771 | */ |
| 2772 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2773 | 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] | 2774 | { |
| 2775 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 2776 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 2777 | u32 interval = beacon_interval * TIME_UNIT; |
| 2778 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 2779 | (addon & BEACON_TIME_MASK_HIGH); |
| 2780 | |
| 2781 | if (base_low > addon_low) |
| 2782 | res += base_low - addon_low; |
| 2783 | else if (base_low < addon_low) { |
| 2784 | res += interval + base_low - addon_low; |
| 2785 | res += (1 << 24); |
| 2786 | } else |
| 2787 | res += (1 << 24); |
| 2788 | |
| 2789 | return cpu_to_le32(res); |
| 2790 | } |
| 2791 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2792 | static int iwl3945_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2793 | struct ieee80211_measurement_params *params, |
| 2794 | u8 type) |
| 2795 | { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2796 | struct iwl_spectrum_cmd spectrum; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2797 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 2798 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2799 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 2800 | .data = (void *)&spectrum, |
| 2801 | .meta.flags = CMD_WANT_SKB, |
| 2802 | }; |
| 2803 | u32 add_time = le64_to_cpu(params->start_time); |
| 2804 | int rc; |
| 2805 | int spectrum_resp_status; |
| 2806 | int duration = le16_to_cpu(params->duration); |
| 2807 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2808 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2809 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2810 | iwl3945_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2811 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 2812 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2813 | |
| 2814 | memset(&spectrum, 0, sizeof(spectrum)); |
| 2815 | |
| 2816 | spectrum.channel_count = cpu_to_le16(1); |
| 2817 | spectrum.flags = |
| 2818 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 2819 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 2820 | cmd.len = sizeof(spectrum); |
| 2821 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 2822 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2823 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2824 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2825 | iwl3945_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2826 | add_time, |
| 2827 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2828 | else |
| 2829 | spectrum.start_time = 0; |
| 2830 | |
| 2831 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 2832 | spectrum.channels[0].channel = params->channel; |
| 2833 | spectrum.channels[0].type = type; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2834 | if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2835 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 2836 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 2837 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2838 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2839 | if (rc) |
| 2840 | return rc; |
| 2841 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2842 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2843 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2844 | IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2845 | rc = -EIO; |
| 2846 | } |
| 2847 | |
| 2848 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 2849 | switch (spectrum_resp_status) { |
| 2850 | case 0: /* Command will be handled */ |
| 2851 | if (res->u.spectrum.id != 0xff) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2852 | IWL_DEBUG_INFO("Replaced existing measurement: %d\n", |
| 2853 | res->u.spectrum.id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2854 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 2855 | } |
| 2856 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 2857 | rc = 0; |
| 2858 | break; |
| 2859 | |
| 2860 | case 1: /* Command will not be handled */ |
| 2861 | rc = -EAGAIN; |
| 2862 | break; |
| 2863 | } |
| 2864 | |
| 2865 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 2866 | |
| 2867 | return rc; |
| 2868 | } |
| 2869 | #endif |
| 2870 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2871 | static void iwl3945_rx_reply_alive(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2872 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2873 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2874 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 2875 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2876 | struct delayed_work *pwork; |
| 2877 | |
| 2878 | palive = &pkt->u.alive_frame; |
| 2879 | |
| 2880 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 2881 | "0x%01X 0x%01X\n", |
| 2882 | palive->is_valid, palive->ver_type, |
| 2883 | palive->ver_subtype); |
| 2884 | |
| 2885 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 2886 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2887 | memcpy(&priv->card_alive_init, &pkt->u.alive_frame, |
| 2888 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2889 | pwork = &priv->init_alive_start; |
| 2890 | } else { |
| 2891 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2892 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2893 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2894 | pwork = &priv->alive_start; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2895 | iwl3945_disable_events(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | /* We delay the ALIVE response by 5ms to |
| 2899 | * give the HW RF Kill time to activate... */ |
| 2900 | if (palive->is_valid == UCODE_VALID_OK) |
| 2901 | queue_delayed_work(priv->workqueue, pwork, |
| 2902 | msecs_to_jiffies(5)); |
| 2903 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2904 | IWL_WARN(priv, "uCode did not respond OK.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2907 | static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2908 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2909 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2910 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2911 | |
| 2912 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 2913 | return; |
| 2914 | } |
| 2915 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2916 | static void iwl3945_rx_reply_error(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2917 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2918 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2919 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2920 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2921 | IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2922 | "seq 0x%04X ser 0x%08X\n", |
| 2923 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 2924 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 2925 | pkt->u.err_resp.cmd_id, |
| 2926 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 2927 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 2928 | } |
| 2929 | |
| 2930 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2931 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2932 | 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] | 2933 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2934 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2935 | struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2936 | struct iwl_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2937 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 2938 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 2939 | rxon->channel = csa->channel; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 2940 | priv->staging39_rxon.channel = csa->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2943 | static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2944 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2945 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2946 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2947 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2948 | struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2949 | |
| 2950 | if (!report->state) { |
| 2951 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 2952 | "Spectrum Measure Notification: Start\n"); |
| 2953 | return; |
| 2954 | } |
| 2955 | |
| 2956 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2957 | priv->measurement_status |= MEASUREMENT_READY; |
| 2958 | #endif |
| 2959 | } |
| 2960 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2961 | static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2962 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2963 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2964 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2965 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 2966 | struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2967 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2968 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2969 | #endif |
| 2970 | } |
| 2971 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2972 | static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 2973 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2974 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2975 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2976 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2977 | "notification for %s:\n", |
| 2978 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2979 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, |
| 2980 | le32_to_cpu(pkt->len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2981 | } |
| 2982 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2983 | static void iwl3945_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2984 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2985 | struct iwl_priv *priv = |
| 2986 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2987 | struct sk_buff *beacon; |
| 2988 | |
| 2989 | /* 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] | 2990 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2991 | |
| 2992 | if (!beacon) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2993 | IWL_ERR(priv, "update beacon failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2994 | return; |
| 2995 | } |
| 2996 | |
| 2997 | mutex_lock(&priv->mutex); |
| 2998 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2999 | if (priv->ibss_beacon) |
| 3000 | dev_kfree_skb(priv->ibss_beacon); |
| 3001 | |
| 3002 | priv->ibss_beacon = beacon; |
| 3003 | mutex_unlock(&priv->mutex); |
| 3004 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3005 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3008 | static void iwl3945_rx_beacon_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3009 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3011 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3012 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3013 | struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3014 | u8 rate = beacon->beacon_notify_hdr.rate; |
| 3015 | |
| 3016 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 3017 | "tsf %d %d rate %d\n", |
| 3018 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 3019 | beacon->beacon_notify_hdr.failure_frame, |
| 3020 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3021 | le32_to_cpu(beacon->high_tsf), |
| 3022 | le32_to_cpu(beacon->low_tsf), rate); |
| 3023 | #endif |
| 3024 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3025 | if ((priv->iw_mode == NL80211_IFTYPE_AP) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3026 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 3027 | queue_work(priv->workqueue, &priv->beacon_update); |
| 3028 | } |
| 3029 | |
| 3030 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3031 | static void iwl3945_rx_reply_scan(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3032 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3033 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3034 | #ifdef CONFIG_IWL3945_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3035 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 3036 | struct iwl_scanreq_notification *notif = |
| 3037 | (struct iwl_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3038 | |
| 3039 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 3040 | #endif |
| 3041 | } |
| 3042 | |
| 3043 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3044 | static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3045 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3046 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3047 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 3048 | struct iwl_scanstart_notification *notif = |
| 3049 | (struct iwl_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3050 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 3051 | IWL_DEBUG_SCAN("Scan start: " |
| 3052 | "%d [802.11%s] " |
| 3053 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 3054 | notif->channel, |
| 3055 | notif->band ? "bg" : "a", |
| 3056 | notif->tsf_high, |
| 3057 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 3058 | } |
| 3059 | |
| 3060 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3061 | static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3062 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3063 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3064 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 3065 | struct iwl_scanresults_notification *notif = |
| 3066 | (struct iwl_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3067 | |
| 3068 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 3069 | "%d [802.11%s] " |
| 3070 | "(TSF: 0x%08X:%08X) - %d " |
| 3071 | "elapsed=%lu usec (%dms since last)\n", |
| 3072 | notif->channel, |
| 3073 | notif->band ? "bg" : "a", |
| 3074 | le32_to_cpu(notif->tsf_high), |
| 3075 | le32_to_cpu(notif->tsf_low), |
| 3076 | le32_to_cpu(notif->statistics[0]), |
| 3077 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 3078 | jiffies_to_msecs(elapsed_jiffies |
| 3079 | (priv->last_scan_jiffies, jiffies))); |
| 3080 | |
| 3081 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3082 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3086 | static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3087 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3088 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3089 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 3090 | struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3091 | |
| 3092 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 3093 | scan_notif->scanned_channels, |
| 3094 | scan_notif->tsf_low, |
| 3095 | scan_notif->tsf_high, scan_notif->status); |
| 3096 | |
| 3097 | /* The HW is no longer scanning */ |
| 3098 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3099 | |
| 3100 | /* The scan completion notification came in, so kill that timer... */ |
| 3101 | cancel_delayed_work(&priv->scan_check); |
| 3102 | |
| 3103 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 3104 | (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ? |
| 3105 | "2.4" : "5.2", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3106 | jiffies_to_msecs(elapsed_jiffies |
| 3107 | (priv->scan_pass_start, jiffies))); |
| 3108 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 3109 | /* Remove this scanned band from the list of pending |
| 3110 | * bands to scan, band G precedes A in order of scanning |
| 3111 | * as seen in iwl3945_bg_request_scan */ |
| 3112 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) |
| 3113 | priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ); |
| 3114 | else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) |
| 3115 | priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3116 | |
| 3117 | /* If a request to abort was given, or the scan did not succeed |
| 3118 | * then we reset the scan state machine and terminate, |
| 3119 | * re-queuing another scan if one has been requested */ |
| 3120 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3121 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 3122 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 3123 | } else { |
| 3124 | /* If there are more bands on this scan pass reschedule */ |
| 3125 | if (priv->scan_bands > 0) |
| 3126 | goto reschedule; |
| 3127 | } |
| 3128 | |
| 3129 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3130 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3131 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 3132 | |
| 3133 | clear_bit(STATUS_SCANNING, &priv->status); |
| 3134 | |
| 3135 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 3136 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 3137 | |
| 3138 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3139 | |
| 3140 | return; |
| 3141 | |
| 3142 | reschedule: |
| 3143 | priv->scan_pass_start = jiffies; |
| 3144 | queue_work(priv->workqueue, &priv->request_scan); |
| 3145 | } |
| 3146 | |
| 3147 | /* Handle notification from uCode that card's power state is changing |
| 3148 | * due to software, hardware, or critical temperature RFKILL */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3149 | static void iwl3945_rx_card_state_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3150 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3151 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3152 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3153 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 3154 | unsigned long status = priv->status; |
| 3155 | |
| 3156 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 3157 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3158 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 3159 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3160 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3161 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3162 | |
| 3163 | if (flags & HW_CARD_DISABLED) |
| 3164 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3165 | else |
| 3166 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3167 | |
| 3168 | |
| 3169 | if (flags & SW_CARD_DISABLED) |
| 3170 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3171 | else |
| 3172 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3173 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3174 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3175 | |
| 3176 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 3177 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 3178 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 3179 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 3180 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3181 | else |
| 3182 | wake_up_interruptible(&priv->wait_command_queue); |
| 3183 | } |
| 3184 | |
| 3185 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3186 | * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3187 | * |
| 3188 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3189 | * to the host. |
| 3190 | * |
| 3191 | * This function chains into the hardware specific files for them to setup |
| 3192 | * any hardware specific handlers as well. |
| 3193 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3194 | static void iwl3945_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3195 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3196 | priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive; |
| 3197 | priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta; |
| 3198 | priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error; |
| 3199 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3200 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3201 | iwl3945_rx_spectrum_measure_notif; |
| 3202 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3203 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3204 | iwl3945_rx_pm_debug_statistics_notif; |
| 3205 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3206 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3207 | /* |
| 3208 | * The same handler is used for both the REPLY to a discrete |
| 3209 | * statistics request from the host as well as for the periodic |
| 3210 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3211 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3212 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics; |
| 3213 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3214 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3215 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan; |
| 3216 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3217 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3218 | iwl3945_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3219 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3220 | iwl3945_rx_scan_complete_notif; |
| 3221 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3222 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3223 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3224 | iwl3945_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | /** |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3228 | * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries |
| 3229 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3230 | * need to be reclaimed. |
| 3231 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3232 | static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3233 | int txq_id, int index) |
| 3234 | { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3235 | struct iwl3945_tx_queue *txq = &priv->txq39[txq_id]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 3236 | struct iwl_queue *q = &txq->q; |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3237 | int nfreed = 0; |
| 3238 | |
| 3239 | if ((index >= q->n_bd) || (iwl3945_x2_queue_used(q, index) == 0)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3240 | 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] | 3241 | "is out of range [0-%d] %d %d.\n", txq_id, |
| 3242 | index, q->n_bd, q->write_ptr, q->read_ptr); |
| 3243 | return; |
| 3244 | } |
| 3245 | |
| 3246 | for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index; |
| 3247 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
| 3248 | if (nfreed > 1) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3249 | IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3250 | q->write_ptr, q->read_ptr); |
| 3251 | queue_work(priv->workqueue, &priv->restart); |
| 3252 | break; |
| 3253 | } |
| 3254 | nfreed++; |
| 3255 | } |
| 3256 | } |
| 3257 | |
| 3258 | |
| 3259 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3260 | * 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] | 3261 | * @rxb: Rx buffer to reclaim |
| 3262 | * |
| 3263 | * If an Rx buffer has an async callback associated with it the callback |
| 3264 | * will be executed. The attached skb (if present) will only be freed |
| 3265 | * if the callback returns 1 |
| 3266 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3267 | static void iwl3945_tx_cmd_complete(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3268 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3269 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3270 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3271 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3272 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3273 | int index = SEQ_TO_INDEX(sequence); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 3274 | int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3275 | int cmd_index; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 3276 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3277 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3278 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3279 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 3280 | cmd_index = get_cmd_index(&priv->txq39[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3281 | cmd = &priv->txq39[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3282 | |
| 3283 | /* Input error checking is done when commands are added to queue. */ |
| 3284 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3285 | cmd->meta.source->u.skb = rxb->skb; |
| 3286 | rxb->skb = NULL; |
| 3287 | } else if (cmd->meta.u.callback && |
| 3288 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3289 | rxb->skb = NULL; |
| 3290 | |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 3291 | iwl3945_cmd_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3292 | |
| 3293 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3294 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3295 | wake_up_interruptible(&priv->wait_command_queue); |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | /************************** RX-FUNCTIONS ****************************/ |
| 3300 | /* |
| 3301 | * Rx theory of operation |
| 3302 | * |
| 3303 | * The host allocates 32 DMA target addresses and passes the host address |
| 3304 | * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
| 3305 | * 0 to 31 |
| 3306 | * |
| 3307 | * Rx Queue Indexes |
| 3308 | * The host/firmware share two index registers for managing the Rx buffers. |
| 3309 | * |
| 3310 | * The READ index maps to the first position that the firmware may be writing |
| 3311 | * to -- the driver can read up to (but not including) this position and get |
| 3312 | * good data. |
| 3313 | * The READ index is managed by the firmware once the card is enabled. |
| 3314 | * |
| 3315 | * The WRITE index maps to the last position the driver has read from -- the |
| 3316 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 3317 | * |
| 3318 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 3319 | * WRITE = READ. |
| 3320 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3321 | * 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] | 3322 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 3323 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3324 | * 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] | 3325 | * and fire the RX interrupt. The driver can then query the READ index and |
| 3326 | * process as many packets as possible, moving the WRITE index forward as it |
| 3327 | * resets the Rx queue buffers with new memory. |
| 3328 | * |
| 3329 | * The management in the driver is as follows: |
| 3330 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 3331 | * 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] | 3332 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3333 | * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3334 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 3335 | * 'processed' and 'read' driver indexes as well) |
| 3336 | * + A received packet is processed and handed to the kernel network stack, |
| 3337 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 3338 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 3339 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 3340 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 3341 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 3342 | * |
| 3343 | * |
| 3344 | * Driver sequence: |
| 3345 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3346 | * iwl3945_rx_queue_alloc() Allocates rx_free |
| 3347 | * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3348 | * iwl3945_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3349 | * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3350 | * queue, updates firmware pointers, and updates |
| 3351 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3352 | * are available, schedules iwl3945_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3353 | * |
| 3354 | * -- enable interrupts -- |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3355 | * 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] | 3356 | * READ INDEX, detaching the SKB from the pool. |
| 3357 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3358 | * Calls iwl3945_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3359 | * slots. |
| 3360 | * ... |
| 3361 | * |
| 3362 | */ |
| 3363 | |
| 3364 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3365 | * iwl3945_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3366 | */ |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3367 | static int iwl3945_rx_queue_space(const struct iwl_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3368 | { |
| 3369 | int s = q->read - q->write; |
| 3370 | if (s <= 0) |
| 3371 | s += RX_QUEUE_SIZE; |
| 3372 | /* keep some buffer to not confuse full and empty queue */ |
| 3373 | s -= 2; |
| 3374 | if (s < 0) |
| 3375 | s = 0; |
| 3376 | return s; |
| 3377 | } |
| 3378 | |
| 3379 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3380 | * 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] | 3381 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3382 | 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] | 3383 | { |
| 3384 | u32 reg = 0; |
| 3385 | int rc = 0; |
| 3386 | unsigned long flags; |
| 3387 | |
| 3388 | spin_lock_irqsave(&q->lock, flags); |
| 3389 | |
| 3390 | if (q->need_update == 0) |
| 3391 | goto exit_unlock; |
| 3392 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3393 | /* If power-saving is in use, make sure device is awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3394 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3395 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3396 | |
| 3397 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3398 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3399 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3400 | goto exit_unlock; |
| 3401 | } |
| 3402 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3403 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3404 | if (rc) |
| 3405 | goto exit_unlock; |
| 3406 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3407 | /* Device expects a multiple of 8 */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3408 | iwl_write_direct32(priv, FH39_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3409 | q->write & ~0x7); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3410 | iwl_release_nic_access(priv); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3411 | |
| 3412 | /* Else device is assumed to be awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3413 | } else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3414 | /* Device expects a multiple of 8 */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3415 | iwl_write32(priv, FH39_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3416 | |
| 3417 | |
| 3418 | q->need_update = 0; |
| 3419 | |
| 3420 | exit_unlock: |
| 3421 | spin_unlock_irqrestore(&q->lock, flags); |
| 3422 | return rc; |
| 3423 | } |
| 3424 | |
| 3425 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3426 | * 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] | 3427 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3428 | static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3429 | dma_addr_t dma_addr) |
| 3430 | { |
| 3431 | return cpu_to_le32((u32)dma_addr); |
| 3432 | } |
| 3433 | |
| 3434 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3435 | * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3436 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3437 | * 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] | 3438 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3439 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3440 | * |
| 3441 | * This moves the 'write' index forward to catch up with 'processed', and |
| 3442 | * also updates the memory address in the firmware to reference the new |
| 3443 | * target buffer. |
| 3444 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3445 | static int iwl3945_rx_queue_restock(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3446 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3447 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3448 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3449 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3450 | unsigned long flags; |
| 3451 | int write, rc; |
| 3452 | |
| 3453 | spin_lock_irqsave(&rxq->lock, flags); |
| 3454 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3455 | while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3456 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3457 | element = rxq->rx_free.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3458 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3459 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3460 | |
| 3461 | /* Point to Rx buffer via next RBD in circular buffer */ |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3462 | 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] | 3463 | rxq->queue[rxq->write] = rxb; |
| 3464 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 3465 | rxq->free_count--; |
| 3466 | } |
| 3467 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3468 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 3469 | * refill it */ |
| 3470 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 3471 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 3472 | |
| 3473 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3474 | /* If we've added more space for the firmware to place data, tell it. |
| 3475 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3476 | if ((write != (rxq->write & ~0x7)) |
| 3477 | || (abs(rxq->write - rxq->read) > 7)) { |
| 3478 | spin_lock_irqsave(&rxq->lock, flags); |
| 3479 | rxq->need_update = 1; |
| 3480 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3481 | rc = iwl3945_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3482 | if (rc) |
| 3483 | return rc; |
| 3484 | } |
| 3485 | |
| 3486 | return 0; |
| 3487 | } |
| 3488 | |
| 3489 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3490 | * 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] | 3491 | * |
| 3492 | * When moving to rx_free an SKB is allocated for the slot. |
| 3493 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3494 | * Also restock the Rx queue via iwl3945_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3495 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3496 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3497 | static void iwl3945_rx_allocate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3498 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3499 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3500 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3501 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3502 | unsigned long flags; |
| 3503 | spin_lock_irqsave(&rxq->lock, flags); |
| 3504 | while (!list_empty(&rxq->rx_used)) { |
| 3505 | element = rxq->rx_used.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3506 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3507 | |
| 3508 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3509 | rxb->skb = |
| 3510 | alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC); |
| 3511 | if (!rxb->skb) { |
| 3512 | if (net_ratelimit()) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 3513 | IWL_CRIT(priv, ": Can not allocate SKB buffers\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3514 | /* We don't reschedule replenish work here -- we will |
| 3515 | * call the restock method and if it still needs |
| 3516 | * more buffers it will schedule replenish */ |
| 3517 | break; |
| 3518 | } |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 3519 | |
| 3520 | /* If radiotap head is required, reserve some headroom here. |
| 3521 | * The physical head count is a variable rx_stats->phy_count. |
| 3522 | * We reserve 4 bytes here. Plus these extra bytes, the |
| 3523 | * headroom of the physical head should be enough for the |
| 3524 | * radiotap head that iwl3945 supported. See iwl3945_rt. |
| 3525 | */ |
| 3526 | skb_reserve(rxb->skb, 4); |
| 3527 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3528 | priv->alloc_rxb_skb++; |
| 3529 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3530 | |
| 3531 | /* Get physical address of RB/SKB */ |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3532 | rxb->real_dma_addr = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3533 | pci_map_single(priv->pci_dev, rxb->skb->data, |
| 3534 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3535 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 3536 | rxq->free_count++; |
| 3537 | } |
| 3538 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | /* |
| 3542 | * this should be called while priv->lock is locked |
| 3543 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 3544 | static void __iwl3945_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3545 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3546 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3547 | |
| 3548 | iwl3945_rx_allocate(priv); |
| 3549 | iwl3945_rx_queue_restock(priv); |
| 3550 | } |
| 3551 | |
| 3552 | |
| 3553 | void iwl3945_rx_replenish(void *data) |
| 3554 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3555 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3556 | unsigned long flags; |
| 3557 | |
| 3558 | iwl3945_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3559 | |
| 3560 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3561 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3562 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3563 | } |
| 3564 | |
| 3565 | /* 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] | 3566 | * 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] | 3567 | * This free routine walks the list of POOL entries and if SKB is set to |
| 3568 | * non NULL it is unmapped and freed |
| 3569 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3570 | 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] | 3571 | { |
| 3572 | int i; |
| 3573 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 3574 | if (rxq->pool[i].skb != NULL) { |
| 3575 | pci_unmap_single(priv->pci_dev, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3576 | rxq->pool[i].real_dma_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3577 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3578 | dev_kfree_skb(rxq->pool[i].skb); |
| 3579 | } |
| 3580 | } |
| 3581 | |
| 3582 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 3583 | rxq->dma_addr); |
| 3584 | rxq->bd = NULL; |
| 3585 | } |
| 3586 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3587 | int iwl3945_rx_queue_alloc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3588 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3589 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3590 | struct pci_dev *dev = priv->pci_dev; |
| 3591 | int i; |
| 3592 | |
| 3593 | spin_lock_init(&rxq->lock); |
| 3594 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3595 | INIT_LIST_HEAD(&rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3596 | |
| 3597 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3598 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 3599 | if (!rxq->bd) |
| 3600 | return -ENOMEM; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3601 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3602 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3603 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 3604 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3605 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3606 | /* Set us so that we have processed and used all buffers, but have |
| 3607 | * not restocked the Rx queue with fresh buffers */ |
| 3608 | rxq->read = rxq->write = 0; |
| 3609 | rxq->free_count = 0; |
| 3610 | rxq->need_update = 0; |
| 3611 | return 0; |
| 3612 | } |
| 3613 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3614 | 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] | 3615 | { |
| 3616 | unsigned long flags; |
| 3617 | int i; |
| 3618 | spin_lock_irqsave(&rxq->lock, flags); |
| 3619 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3620 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3621 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3622 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3623 | /* In the reset function, these buffers may have been allocated |
| 3624 | * to an SKB, so we need to unmap and free potential storage */ |
| 3625 | if (rxq->pool[i].skb != NULL) { |
| 3626 | pci_unmap_single(priv->pci_dev, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3627 | rxq->pool[i].real_dma_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3628 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3629 | priv->alloc_rxb_skb--; |
| 3630 | dev_kfree_skb(rxq->pool[i].skb); |
| 3631 | rxq->pool[i].skb = NULL; |
| 3632 | } |
| 3633 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3634 | } |
| 3635 | |
| 3636 | /* Set us so that we have processed and used all buffers, but have |
| 3637 | * not restocked the Rx queue with fresh buffers */ |
| 3638 | rxq->read = rxq->write = 0; |
| 3639 | rxq->free_count = 0; |
| 3640 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3641 | } |
| 3642 | |
| 3643 | /* Convert linear signal-to-noise ratio into dB */ |
| 3644 | static u8 ratio2dB[100] = { |
| 3645 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 3646 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 3647 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 3648 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 3649 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 3650 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 3651 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 3652 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 3653 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 3654 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 3655 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 3656 | }; |
| 3657 | |
| 3658 | /* Calculates a relative dB value from a ratio of linear |
| 3659 | * (i.e. not dB) signal levels. |
| 3660 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3661 | int iwl3945_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3662 | { |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3663 | /* 1000:1 or higher just report as 60 dB */ |
| 3664 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3665 | return 60; |
| 3666 | |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3667 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3668 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 3669 | if (sig_ratio >= 100) |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 3670 | return 20 + (int)ratio2dB[sig_ratio/10]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3671 | |
| 3672 | /* We shouldn't see this */ |
| 3673 | if (sig_ratio < 1) |
| 3674 | return 0; |
| 3675 | |
| 3676 | /* Use table for ratios 1:1 - 99:1 */ |
| 3677 | return (int)ratio2dB[sig_ratio]; |
| 3678 | } |
| 3679 | |
| 3680 | #define PERFECT_RSSI (-20) /* dBm */ |
| 3681 | #define WORST_RSSI (-95) /* dBm */ |
| 3682 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 3683 | |
| 3684 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 3685 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 3686 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3687 | int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3688 | { |
| 3689 | int sig_qual; |
| 3690 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 3691 | |
| 3692 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 3693 | * as indicator; formula is (signal dbm - noise dbm). |
| 3694 | * SNR at or above 40 is a great signal (100%). |
| 3695 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 3696 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 3697 | if (noise_dbm) { |
| 3698 | if (rssi_dbm - noise_dbm >= 40) |
| 3699 | return 100; |
| 3700 | else if (rssi_dbm < noise_dbm) |
| 3701 | return 0; |
| 3702 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 3703 | |
| 3704 | /* Else use just the signal level. |
| 3705 | * This formula is a least squares fit of data points collected and |
| 3706 | * compared with a reference system that had a percentage (%) display |
| 3707 | * for signal quality. */ |
| 3708 | } else |
| 3709 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 3710 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 3711 | (RSSI_RANGE * RSSI_RANGE); |
| 3712 | |
| 3713 | if (sig_qual > 100) |
| 3714 | sig_qual = 100; |
| 3715 | else if (sig_qual < 1) |
| 3716 | sig_qual = 0; |
| 3717 | |
| 3718 | return sig_qual; |
| 3719 | } |
| 3720 | |
| 3721 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3722 | * iwl3945_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3723 | * |
| 3724 | * Uses the priv->rx_handlers callback function array to invoke |
| 3725 | * the appropriate handlers, including command responses, |
| 3726 | * frame-received notifications, and other notifications. |
| 3727 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3728 | static void iwl3945_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3729 | { |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3730 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3731 | struct iwl_rx_packet *pkt; |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 3732 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3733 | u32 r, i; |
| 3734 | int reclaim; |
| 3735 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3736 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 3737 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3738 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3739 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 3740 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3741 | r = iwl3945_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3742 | i = rxq->read; |
| 3743 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3744 | if (iwl3945_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
| 3745 | fill_rx = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3746 | /* Rx interrupt, but nothing sent from uCode */ |
| 3747 | if (i == r) |
| 3748 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 3749 | |
| 3750 | while (i != r) { |
| 3751 | rxb = rxq->queue[i]; |
| 3752 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3753 | /* 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] | 3754 | * then a bug has been introduced in the queue refilling |
| 3755 | * routines -- catch it here */ |
| 3756 | BUG_ON(rxb == NULL); |
| 3757 | |
| 3758 | rxq->queue[i] = NULL; |
| 3759 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3760 | 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] | 3761 | IWL_RX_BUF_SIZE, |
| 3762 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3763 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3764 | |
| 3765 | /* Reclaim a command buffer only if this packet is a response |
| 3766 | * to a (driver-originated) command. |
| 3767 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3768 | * there is no command buffer to reclaim. |
| 3769 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3770 | * but apparently a few don't get set; catch them here. */ |
| 3771 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 3772 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 3773 | (pkt->hdr.cmd != REPLY_TX); |
| 3774 | |
| 3775 | /* Based on type of command response or notification, |
| 3776 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3777 | * rx_handlers table. See iwl3945_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3778 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3779 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3780 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 3781 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 3782 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 3783 | } else { |
| 3784 | /* No handling needed */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3785 | IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3786 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 3787 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 3788 | pkt->hdr.cmd); |
| 3789 | } |
| 3790 | |
| 3791 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3792 | /* Invoke any callbacks, transfer the skb to caller, and |
| 3793 | * fire off the (possibly) blocking iwl3945_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3794 | * as we reclaim the driver command queue */ |
| 3795 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3796 | iwl3945_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3797 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3798 | IWL_WARN(priv, "Claim null rxb?\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | /* For now we just don't re-use anything. We can tweak this |
| 3802 | * later to try and re-use notification packets and SKBs that |
| 3803 | * fail to Rx correctly */ |
| 3804 | if (rxb->skb != NULL) { |
| 3805 | priv->alloc_rxb_skb--; |
| 3806 | dev_kfree_skb_any(rxb->skb); |
| 3807 | rxb->skb = NULL; |
| 3808 | } |
| 3809 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 3810 | pci_unmap_single(priv->pci_dev, rxb->real_dma_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3811 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 3812 | spin_lock_irqsave(&rxq->lock, flags); |
| 3813 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 3814 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3815 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3816 | /* If there are a lot of unused frames, |
| 3817 | * restock the Rx queue so ucode won't assert. */ |
| 3818 | if (fill_rx) { |
| 3819 | count++; |
| 3820 | if (count >= 8) { |
| 3821 | priv->rxq.read = i; |
| 3822 | __iwl3945_rx_replenish(priv); |
| 3823 | count = 0; |
| 3824 | } |
| 3825 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | /* Backtrack one entry */ |
| 3829 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3830 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3833 | /** |
| 3834 | * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware |
| 3835 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3836 | static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3837 | struct iwl3945_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3838 | { |
| 3839 | u32 reg = 0; |
| 3840 | int rc = 0; |
| 3841 | int txq_id = txq->q.id; |
| 3842 | |
| 3843 | if (txq->need_update == 0) |
| 3844 | return rc; |
| 3845 | |
| 3846 | /* if we're trying to save power */ |
| 3847 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 3848 | /* wake up nic if it's powered down ... |
| 3849 | * uCode will wake up, and interrupt us again, so next |
| 3850 | * time we'll skip this part. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3851 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3852 | |
| 3853 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 3854 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3855 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3856 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3857 | return rc; |
| 3858 | } |
| 3859 | |
| 3860 | /* restore this queue's parameters in nic hardware. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3861 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3862 | if (rc) |
| 3863 | return rc; |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3864 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3865 | txq->q.write_ptr | (txq_id << 8)); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3866 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3867 | |
| 3868 | /* else not in power-save mode, uCode will never sleep when we're |
| 3869 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 3870 | } else |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3871 | iwl_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3872 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3873 | |
| 3874 | txq->need_update = 0; |
| 3875 | |
| 3876 | return rc; |
| 3877 | } |
| 3878 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3879 | #ifdef CONFIG_IWL3945_DEBUG |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3880 | static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3881 | struct iwl3945_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3882 | { |
| 3883 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3884 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3885 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 3886 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 3887 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 3888 | le32_to_cpu(rxon->filter_flags)); |
| 3889 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 3890 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 3891 | rxon->ofdm_basic_rates); |
| 3892 | 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] | 3893 | IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr); |
| 3894 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3895 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 3896 | } |
| 3897 | #endif |
| 3898 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3899 | static void iwl3945_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3900 | { |
| 3901 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 3902 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3903 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3904 | } |
| 3905 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3906 | |
| 3907 | /* call this function to flush any scheduled tasklet */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3908 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3909 | { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 3910 | /* wait to make sure we flush pending tasklet*/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3911 | synchronize_irq(priv->pci_dev->irq); |
| 3912 | tasklet_kill(&priv->irq_tasklet); |
| 3913 | } |
| 3914 | |
| 3915 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3916 | static inline void iwl3945_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3917 | { |
| 3918 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 3919 | |
| 3920 | /* disable interrupts from uCode/NIC to host */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3921 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3922 | |
| 3923 | /* acknowledge/clear/reset any interrupts still pending |
| 3924 | * from uCode or flow handler (Rx/Tx DMA) */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3925 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 3926 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3927 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 3928 | } |
| 3929 | |
| 3930 | static const char *desc_lookup(int i) |
| 3931 | { |
| 3932 | switch (i) { |
| 3933 | case 1: |
| 3934 | return "FAIL"; |
| 3935 | case 2: |
| 3936 | return "BAD_PARAM"; |
| 3937 | case 3: |
| 3938 | return "BAD_CHECKSUM"; |
| 3939 | case 4: |
| 3940 | return "NMI_INTERRUPT"; |
| 3941 | case 5: |
| 3942 | return "SYSASSERT"; |
| 3943 | case 6: |
| 3944 | return "FATAL_ERROR"; |
| 3945 | } |
| 3946 | |
| 3947 | return "UNKNOWN"; |
| 3948 | } |
| 3949 | |
| 3950 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 3951 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 3952 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3953 | static void iwl3945_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3954 | { |
| 3955 | u32 i; |
| 3956 | u32 desc, time, count, base, data1; |
| 3957 | u32 blink1, blink2, ilink1, ilink2; |
| 3958 | int rc; |
| 3959 | |
| 3960 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 3961 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3962 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3963 | IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3964 | return; |
| 3965 | } |
| 3966 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3967 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3968 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3969 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3970 | return; |
| 3971 | } |
| 3972 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3973 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3974 | |
| 3975 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3976 | IWL_ERR(priv, "Start IWL Error Log Dump:\n"); |
| 3977 | IWL_ERR(priv, "Status: 0x%08lX, count: %d\n", |
| 3978 | priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3979 | } |
| 3980 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3981 | IWL_ERR(priv, "Desc Time asrtPC blink2 " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3982 | "ilink1 nmiPC Line\n"); |
| 3983 | for (i = ERROR_START_OFFSET; |
| 3984 | i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET; |
| 3985 | i += ERROR_ELEM_SIZE) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3986 | desc = iwl_read_targ_mem(priv, base + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3987 | time = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3988 | iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3989 | blink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3990 | iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3991 | blink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3992 | iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3993 | ilink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3994 | iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3995 | ilink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3996 | iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3997 | data1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3998 | iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3999 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4000 | IWL_ERR(priv, |
| 4001 | "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n", |
| 4002 | desc_lookup(desc), desc, time, blink1, blink2, |
| 4003 | ilink1, ilink2, data1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4004 | } |
| 4005 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4006 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4007 | |
| 4008 | } |
| 4009 | |
Ben Cahill | f58177b | 2007-11-29 11:09:43 +0800 | [diff] [blame] | 4010 | #define EVENT_START_OFFSET (6 * sizeof(u32)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4011 | |
| 4012 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4013 | * iwl3945_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4014 | * |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4015 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4016 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4017 | 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] | 4018 | u32 num_events, u32 mode) |
| 4019 | { |
| 4020 | u32 i; |
| 4021 | u32 base; /* SRAM byte address of event log header */ |
| 4022 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 4023 | u32 ptr; /* SRAM byte address of log data */ |
| 4024 | u32 ev, time, data; /* event log data */ |
| 4025 | |
| 4026 | if (num_events == 0) |
| 4027 | return; |
| 4028 | |
| 4029 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 4030 | |
| 4031 | if (mode == 0) |
| 4032 | event_size = 2 * sizeof(u32); |
| 4033 | else |
| 4034 | event_size = 3 * sizeof(u32); |
| 4035 | |
| 4036 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 4037 | |
| 4038 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 4039 | * place event id # at far right for easier visual parsing. */ |
| 4040 | for (i = 0; i < num_events; i++) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4041 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4042 | ptr += sizeof(u32); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4043 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4044 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4045 | if (mode == 0) { |
| 4046 | /* data, ev */ |
| 4047 | IWL_ERR(priv, "0x%08x\t%04u\n", time, ev); |
| 4048 | } else { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4049 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4050 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4051 | IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4052 | } |
| 4053 | } |
| 4054 | } |
| 4055 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4056 | static void iwl3945_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4057 | { |
| 4058 | int rc; |
| 4059 | u32 base; /* SRAM byte address of event log header */ |
| 4060 | u32 capacity; /* event log capacity in # entries */ |
| 4061 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 4062 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 4063 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 4064 | u32 size; /* # entries that we'll print */ |
| 4065 | |
| 4066 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4067 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4068 | IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4069 | return; |
| 4070 | } |
| 4071 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4072 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4073 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4074 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4075 | return; |
| 4076 | } |
| 4077 | |
| 4078 | /* event log header */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4079 | capacity = iwl_read_targ_mem(priv, base); |
| 4080 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 4081 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 4082 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4083 | |
| 4084 | size = num_wraps ? capacity : next_entry; |
| 4085 | |
| 4086 | /* bail out if nothing in log */ |
| 4087 | if (size == 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4088 | IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4089 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4090 | return; |
| 4091 | } |
| 4092 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4093 | 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] | 4094 | size, num_wraps); |
| 4095 | |
| 4096 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 4097 | * i.e the next one that uCode would fill. */ |
| 4098 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4099 | iwl3945_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4100 | capacity - next_entry, mode); |
| 4101 | |
| 4102 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4103 | iwl3945_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4104 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4105 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4109 | * 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] | 4110 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4111 | static void iwl3945_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4112 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4113 | /* Set the FW error flag -- cleared on iwl3945_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4114 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 4115 | |
| 4116 | /* Cancel currently queued command. */ |
| 4117 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4118 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4119 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4120 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4121 | iwl3945_dump_nic_error_log(priv); |
| 4122 | iwl3945_dump_nic_event_log(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4123 | iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4124 | } |
| 4125 | #endif |
| 4126 | |
| 4127 | wake_up_interruptible(&priv->wait_command_queue); |
| 4128 | |
| 4129 | /* Keep the restart process from trying to send host |
| 4130 | * commands by clearing the INIT status bit */ |
| 4131 | clear_bit(STATUS_READY, &priv->status); |
| 4132 | |
| 4133 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4134 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 4135 | "Restarting adapter due to uCode error.\n"); |
| 4136 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4137 | if (iwl3945_is_associated(priv)) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4138 | memcpy(&priv->recovery39_rxon, &priv->active39_rxon, |
| 4139 | sizeof(priv->recovery39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4140 | priv->error_recovering = 1; |
| 4141 | } |
| 4142 | queue_work(priv->workqueue, &priv->restart); |
| 4143 | } |
| 4144 | } |
| 4145 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4146 | static void iwl3945_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4147 | { |
| 4148 | unsigned long flags; |
| 4149 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4150 | memcpy(&priv->staging39_rxon, &priv->recovery39_rxon, |
| 4151 | sizeof(priv->staging39_rxon)); |
| 4152 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4153 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4154 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4155 | iwl3945_add_station(priv, priv->bssid, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4156 | |
| 4157 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4158 | priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4159 | priv->error_recovering = 0; |
| 4160 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4161 | } |
| 4162 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4163 | static void iwl3945_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4164 | { |
| 4165 | u32 inta, handled = 0; |
| 4166 | u32 inta_fh; |
| 4167 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4168 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4169 | u32 inta_mask; |
| 4170 | #endif |
| 4171 | |
| 4172 | spin_lock_irqsave(&priv->lock, flags); |
| 4173 | |
| 4174 | /* Ack/clear/reset pending uCode interrupts. |
| 4175 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4176 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4177 | inta = iwl_read32(priv, CSR_INT); |
| 4178 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4179 | |
| 4180 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4181 | * Any new interrupts that happen after this, either while we're |
| 4182 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4183 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 4184 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4185 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4186 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4187 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4188 | /* just for debug */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4189 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4190 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4191 | inta, inta_mask, inta_fh); |
| 4192 | } |
| 4193 | #endif |
| 4194 | |
| 4195 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 4196 | * atomic, make sure that inta covers all the interrupts that |
| 4197 | * we've discovered, even if FH interrupt came in just after |
| 4198 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4199 | if (inta_fh & CSR39_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4200 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4201 | if (inta_fh & CSR39_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4202 | inta |= CSR_INT_BIT_FH_TX; |
| 4203 | |
| 4204 | /* Now service all interrupt bits discovered above. */ |
| 4205 | if (inta & CSR_INT_BIT_HW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4206 | IWL_ERR(priv, "Microcode HW error detected. Restarting.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4207 | |
| 4208 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4209 | iwl3945_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4210 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4211 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4212 | |
| 4213 | handled |= CSR_INT_BIT_HW_ERR; |
| 4214 | |
| 4215 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4216 | |
| 4217 | return; |
| 4218 | } |
| 4219 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4220 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4221 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4222 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4223 | if (inta & CSR_INT_BIT_SCD) |
| 4224 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 4225 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4226 | |
| 4227 | /* Alive notification via Rx interrupt will do the real work */ |
| 4228 | if (inta & CSR_INT_BIT_ALIVE) |
| 4229 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 4230 | } |
| 4231 | #endif |
| 4232 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4233 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4234 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4235 | /* Error detected by uCode */ |
| 4236 | if (inta & CSR_INT_BIT_SW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4237 | IWL_ERR(priv, "Microcode SW error detected. " |
| 4238 | "Restarting 0x%X.\n", inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4239 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4240 | handled |= CSR_INT_BIT_SW_ERR; |
| 4241 | } |
| 4242 | |
| 4243 | /* uCode wakes up after power-down sleep */ |
| 4244 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 4245 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4246 | iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4247 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[0]); |
| 4248 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[1]); |
| 4249 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[2]); |
| 4250 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[3]); |
| 4251 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[4]); |
| 4252 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq39[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4253 | |
| 4254 | handled |= CSR_INT_BIT_WAKEUP; |
| 4255 | } |
| 4256 | |
| 4257 | /* All uCode command responses, including Tx command responses, |
| 4258 | * Rx "responses" (frame-received notification), and other |
| 4259 | * notifications from uCode come through here*/ |
| 4260 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4261 | iwl3945_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4262 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 4263 | } |
| 4264 | |
| 4265 | if (inta & CSR_INT_BIT_FH_TX) { |
| 4266 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 4267 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4268 | iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); |
| 4269 | if (!iwl_grab_nic_access(priv)) { |
| 4270 | iwl_write_direct32(priv, FH39_TCSR_CREDIT |
Tomas Winkler | bddadf8 | 2008-12-19 10:37:01 +0800 | [diff] [blame] | 4271 | (FH39_SRVC_CHNL), 0x0); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4272 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4273 | } |
| 4274 | handled |= CSR_INT_BIT_FH_TX; |
| 4275 | } |
| 4276 | |
| 4277 | if (inta & ~handled) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4278 | IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4279 | |
| 4280 | if (inta & ~CSR_INI_SET_MASK) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4281 | IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4282 | inta & ~CSR_INI_SET_MASK); |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4283 | IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4287 | /* only Re-enable if disabled by irq */ |
| 4288 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 4289 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4290 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4291 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4292 | if (priv->debug_level & (IWL_DL_ISR)) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4293 | inta = iwl_read32(priv, CSR_INT); |
| 4294 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 4295 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4296 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 4297 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 4298 | } |
| 4299 | #endif |
| 4300 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4301 | } |
| 4302 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4303 | static irqreturn_t iwl3945_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4304 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4305 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4306 | u32 inta, inta_mask; |
| 4307 | u32 inta_fh; |
| 4308 | if (!priv) |
| 4309 | return IRQ_NONE; |
| 4310 | |
| 4311 | spin_lock(&priv->lock); |
| 4312 | |
| 4313 | /* Disable (but don't clear!) interrupts here to avoid |
| 4314 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 4315 | * If we have something to service, the tasklet will re-enable ints. |
| 4316 | * 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] | 4317 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 4318 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4319 | |
| 4320 | /* Discover which interrupts are active/pending */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4321 | inta = iwl_read32(priv, CSR_INT); |
| 4322 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4323 | |
| 4324 | /* Ignore interrupt if there's nothing in NIC to service. |
| 4325 | * This may be due to IRQ shared with another device, |
| 4326 | * or due to sporadic interrupts thrown from our NIC. */ |
| 4327 | if (!inta && !inta_fh) { |
| 4328 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 4329 | goto none; |
| 4330 | } |
| 4331 | |
| 4332 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
| 4333 | /* Hardware disappeared */ |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4334 | IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4335 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4336 | } |
| 4337 | |
| 4338 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4339 | inta, inta_mask, inta_fh); |
| 4340 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4341 | inta &= ~CSR_INT_BIT_SCD; |
| 4342 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4343 | /* iwl3945_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4344 | if (likely(inta || inta_fh)) |
| 4345 | tasklet_schedule(&priv->irq_tasklet); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4346 | unplugged: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4347 | spin_unlock(&priv->lock); |
| 4348 | |
| 4349 | return IRQ_HANDLED; |
| 4350 | |
| 4351 | none: |
| 4352 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4353 | /* only Re-enable if disabled by irq */ |
| 4354 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 4355 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4356 | spin_unlock(&priv->lock); |
| 4357 | return IRQ_NONE; |
| 4358 | } |
| 4359 | |
| 4360 | /************************** EEPROM BANDS **************************** |
| 4361 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4362 | * The iwl3945_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4363 | * EEPROM contents to the specific channel number supported for each |
| 4364 | * band. |
| 4365 | * |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4366 | * 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] | 4367 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 4368 | * The specific geography and calibration information for that channel |
| 4369 | * is contained in the eeprom map itself. |
| 4370 | * |
| 4371 | * During init, we copy the eeprom information and channel map |
| 4372 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 4373 | * |
| 4374 | * channel_map_24/52 provides the index in the channel_info array for a |
| 4375 | * given channel. We have to have two separate maps as there is channel |
| 4376 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 4377 | * band_2 |
| 4378 | * |
| 4379 | * A value of 0xff stored in the channel_map indicates that the channel |
| 4380 | * is not supported by the hardware at all. |
| 4381 | * |
| 4382 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 4383 | * valid for Tx with the current hardware. This means that |
| 4384 | * while the system can tune and receive on a given channel, it may not |
| 4385 | * be able to associate or transmit any frames on that |
| 4386 | * channel. There is no corresponding channel information for that |
| 4387 | * entry. |
| 4388 | * |
| 4389 | *********************************************************************/ |
| 4390 | |
| 4391 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4392 | static const u8 iwl3945_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4393 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 4394 | }; |
| 4395 | |
| 4396 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4397 | static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4398 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 4399 | }; |
| 4400 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4401 | static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4402 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 4403 | }; |
| 4404 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4405 | static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4406 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 4407 | }; |
| 4408 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4409 | static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4410 | 145, 149, 153, 157, 161, 165 |
| 4411 | }; |
| 4412 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4413 | 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] | 4414 | int *eeprom_ch_count, |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4415 | const struct iwl_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4416 | **eeprom_ch_info, |
| 4417 | const u8 **eeprom_ch_index) |
| 4418 | { |
| 4419 | switch (band) { |
| 4420 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4421 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4422 | *eeprom_ch_info = priv->eeprom39.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4423 | *eeprom_ch_index = iwl3945_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4424 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4425 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4426 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4427 | *eeprom_ch_info = priv->eeprom39.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4428 | *eeprom_ch_index = iwl3945_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4429 | break; |
| 4430 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4431 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4432 | *eeprom_ch_info = priv->eeprom39.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4433 | *eeprom_ch_index = iwl3945_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4434 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4435 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4436 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4437 | *eeprom_ch_info = priv->eeprom39.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4438 | *eeprom_ch_index = iwl3945_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4439 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4440 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4441 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4442 | *eeprom_ch_info = priv->eeprom39.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4443 | *eeprom_ch_index = iwl3945_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4444 | break; |
| 4445 | default: |
| 4446 | BUG(); |
| 4447 | return; |
| 4448 | } |
| 4449 | } |
| 4450 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4451 | /** |
| 4452 | * iwl3945_get_channel_info - Find driver's private channel info |
| 4453 | * |
| 4454 | * Based on band and channel number. |
| 4455 | */ |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4456 | const struct iwl_channel_info * |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4457 | iwl3945_get_channel_info(const struct iwl_priv *priv, |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4458 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4459 | { |
| 4460 | int i; |
| 4461 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4462 | switch (band) { |
| 4463 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4464 | for (i = 14; i < priv->channel_count; i++) { |
| 4465 | if (priv->channel_info[i].channel == channel) |
| 4466 | return &priv->channel_info[i]; |
| 4467 | } |
| 4468 | break; |
| 4469 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4470 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4471 | if (channel >= 1 && channel <= 14) |
| 4472 | return &priv->channel_info[channel - 1]; |
| 4473 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4474 | case IEEE80211_NUM_BANDS: |
| 4475 | WARN_ON(1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | return NULL; |
| 4479 | } |
| 4480 | |
| 4481 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 4482 | ? # x " " : "") |
| 4483 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4484 | /** |
| 4485 | * iwl3945_init_channel_map - Set up driver's info for all possible channels |
| 4486 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4487 | static int iwl3945_init_channel_map(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4488 | { |
| 4489 | int eeprom_ch_count = 0; |
| 4490 | const u8 *eeprom_ch_index = NULL; |
Samuel Ortiz | 0f741d9 | 2008-12-19 10:37:10 +0800 | [diff] [blame] | 4491 | const struct iwl_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4492 | int band, ch; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4493 | struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4494 | |
| 4495 | if (priv->channel_count) { |
| 4496 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 4497 | return 0; |
| 4498 | } |
| 4499 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4500 | if (priv->eeprom39.version < 0x2f) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4501 | IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4502 | priv->eeprom39.version); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4503 | return -EINVAL; |
| 4504 | } |
| 4505 | |
| 4506 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 4507 | |
| 4508 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4509 | ARRAY_SIZE(iwl3945_eeprom_band_1) + |
| 4510 | ARRAY_SIZE(iwl3945_eeprom_band_2) + |
| 4511 | ARRAY_SIZE(iwl3945_eeprom_band_3) + |
| 4512 | ARRAY_SIZE(iwl3945_eeprom_band_4) + |
| 4513 | ARRAY_SIZE(iwl3945_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4514 | |
| 4515 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 4516 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4517 | priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4518 | priv->channel_count, GFP_KERNEL); |
| 4519 | if (!priv->channel_info) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4520 | IWL_ERR(priv, "Could not allocate channel_info\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4521 | priv->channel_count = 0; |
| 4522 | return -ENOMEM; |
| 4523 | } |
| 4524 | |
| 4525 | ch_info = priv->channel_info; |
| 4526 | |
| 4527 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 4528 | * channel map we maintain (that contains additional information than |
| 4529 | * what just in the EEPROM) */ |
| 4530 | for (band = 1; band <= 5; band++) { |
| 4531 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4532 | iwl3945_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4533 | &eeprom_ch_info, &eeprom_ch_index); |
| 4534 | |
| 4535 | /* Loop through each band adding each of the channels */ |
| 4536 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 4537 | ch_info->channel = eeprom_ch_index[ch]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4538 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 4539 | IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4540 | |
| 4541 | /* permanently store EEPROM's channel regulatory flags |
| 4542 | * and max power in channel info database. */ |
| 4543 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 4544 | |
| 4545 | /* Copy the run-time flags so they are there even on |
| 4546 | * invalid channels */ |
| 4547 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 4548 | |
| 4549 | if (!(is_channel_valid(ch_info))) { |
| 4550 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 4551 | "No traffic\n", |
| 4552 | ch_info->channel, |
| 4553 | ch_info->flags, |
| 4554 | is_channel_a_band(ch_info) ? |
| 4555 | "5.2" : "2.4"); |
| 4556 | ch_info++; |
| 4557 | continue; |
| 4558 | } |
| 4559 | |
| 4560 | /* Initialize regulatory-based run-time data */ |
| 4561 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 4562 | eeprom_ch_info[ch].max_power_avg; |
| 4563 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 4564 | ch_info->min_power = 0; |
| 4565 | |
Guy Cohen | fe7c404 | 2008-04-21 15:41:56 -0700 | [diff] [blame] | 4566 | 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] | 4567 | " %ddBm): Ad-Hoc %ssupported\n", |
| 4568 | ch_info->channel, |
| 4569 | is_channel_a_band(ch_info) ? |
| 4570 | "5.2" : "2.4", |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4571 | CHECK_AND_PRINT(VALID), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4572 | CHECK_AND_PRINT(IBSS), |
| 4573 | CHECK_AND_PRINT(ACTIVE), |
| 4574 | CHECK_AND_PRINT(RADAR), |
| 4575 | CHECK_AND_PRINT(WIDE), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4576 | CHECK_AND_PRINT(DFS), |
| 4577 | eeprom_ch_info[ch].flags, |
| 4578 | eeprom_ch_info[ch].max_power_avg, |
| 4579 | ((eeprom_ch_info[ch]. |
| 4580 | flags & EEPROM_CHANNEL_IBSS) |
| 4581 | && !(eeprom_ch_info[ch]. |
| 4582 | flags & EEPROM_CHANNEL_RADAR)) |
| 4583 | ? "" : "not "); |
| 4584 | |
| 4585 | /* Set the user_txpower_limit to the highest power |
| 4586 | * supported by any channel */ |
| 4587 | if (eeprom_ch_info[ch].max_power_avg > |
| 4588 | priv->user_txpower_limit) |
| 4589 | priv->user_txpower_limit = |
| 4590 | eeprom_ch_info[ch].max_power_avg; |
| 4591 | |
| 4592 | ch_info++; |
| 4593 | } |
| 4594 | } |
| 4595 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4596 | /* Set up txpower settings in driver for all channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4597 | if (iwl3945_txpower_set_from_eeprom(priv)) |
| 4598 | return -EIO; |
| 4599 | |
| 4600 | return 0; |
| 4601 | } |
| 4602 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4603 | /* |
| 4604 | * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map |
| 4605 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4606 | static void iwl3945_free_channel_map(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4607 | { |
| 4608 | kfree(priv->channel_info); |
| 4609 | priv->channel_count = 0; |
| 4610 | } |
| 4611 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4612 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 4613 | * sending probe req. This should be set long enough to hear probe responses |
| 4614 | * from more than one AP. */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4615 | #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */ |
| 4616 | #define IWL_ACTIVE_DWELL_TIME_52 (20) |
| 4617 | |
| 4618 | #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3) |
| 4619 | #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4620 | |
| 4621 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 4622 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 4623 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 4624 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 4625 | * no other traffic). |
| 4626 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 4627 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4628 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4629 | |
| 4630 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 4631 | * Must be set longer than active dwell time. |
| 4632 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 4633 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 4634 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 4635 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 4636 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 4637 | |
Kolekar, Abhijeet | e720ce9 | 2008-11-07 09:58:42 -0800 | [diff] [blame] | 4638 | #define IWL_SCAN_PROBE_MASK(n) (BIT(n) | (BIT(n) - BIT(1))) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4639 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4640 | static inline u16 iwl3945_get_active_dwell_time(struct iwl_priv *priv, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4641 | enum ieee80211_band band, |
| 4642 | u8 n_probes) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4643 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4644 | if (band == IEEE80211_BAND_5GHZ) |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4645 | return IWL_ACTIVE_DWELL_TIME_52 + |
| 4646 | IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4647 | else |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4648 | return IWL_ACTIVE_DWELL_TIME_24 + |
| 4649 | IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4650 | } |
| 4651 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4652 | static u16 iwl3945_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4653 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4654 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4655 | u16 passive = (band == IEEE80211_BAND_2GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4656 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 4657 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 4658 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4659 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4660 | /* If we're associated, we clamp the maximum passive |
| 4661 | * dwell time to be 98% of the beacon interval (minus |
| 4662 | * 2 * channel tune time) */ |
| 4663 | passive = priv->beacon_int; |
| 4664 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 4665 | passive = IWL_PASSIVE_DWELL_BASE; |
| 4666 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 4667 | } |
| 4668 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4669 | return passive; |
| 4670 | } |
| 4671 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4672 | static int iwl3945_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4673 | enum ieee80211_band band, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4674 | u8 is_active, u8 n_probes, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4675 | struct iwl3945_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4676 | { |
| 4677 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4678 | const struct ieee80211_supported_band *sband; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4679 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4680 | u16 passive_dwell = 0; |
| 4681 | u16 active_dwell = 0; |
| 4682 | int added, i; |
| 4683 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4684 | sband = iwl3945_get_band(priv, band); |
| 4685 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4686 | return 0; |
| 4687 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4688 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4689 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 4690 | active_dwell = iwl3945_get_active_dwell_time(priv, band, n_probes); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4691 | passive_dwell = iwl3945_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4692 | |
Abhijeet Kolekar | 8f4807a | 2008-09-03 11:26:31 +0800 | [diff] [blame] | 4693 | if (passive_dwell <= active_dwell) |
| 4694 | passive_dwell = active_dwell + 1; |
| 4695 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4696 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 4697 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 4698 | continue; |
| 4699 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4700 | scan_ch->channel = channels[i].hw_value; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4701 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4702 | ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4703 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 4704 | IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4705 | scan_ch->channel); |
| 4706 | continue; |
| 4707 | } |
| 4708 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4709 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 4710 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 4711 | /* If passive , set up for auto-switch |
| 4712 | * and use long active_dwell time. |
| 4713 | */ |
| 4714 | if (!is_active || is_channel_passive(ch_info) || |
| 4715 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) { |
| 4716 | scan_ch->type = 0; /* passive */ |
| 4717 | if (IWL_UCODE_API(priv->ucode_ver) == 1) |
| 4718 | scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1); |
| 4719 | } else { |
| 4720 | scan_ch->type = 1; /* active */ |
| 4721 | } |
| 4722 | |
| 4723 | /* Set direct probe bits. These may be used both for active |
| 4724 | * scan channels (probes gets sent right away), |
| 4725 | * or for passive channels (probes get se sent only after |
| 4726 | * hearing clear Rx packet).*/ |
| 4727 | if (IWL_UCODE_API(priv->ucode_ver) >= 2) { |
| 4728 | if (n_probes) |
| 4729 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4730 | } else { |
| 4731 | /* uCode v1 does not allow setting direct probe bits on |
| 4732 | * passive channel. */ |
| 4733 | if ((scan_ch->type & 1) && n_probes) |
| 4734 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 4735 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4736 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4737 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4738 | scan_ch->tpc.dsp_atten = 110; |
| 4739 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 4740 | |
| 4741 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4742 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4743 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 4744 | else { |
| 4745 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 4746 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4747 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 4748 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4749 | */ |
| 4750 | } |
| 4751 | |
| 4752 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 4753 | scan_ch->channel, |
| 4754 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 4755 | (scan_ch->type & 1) ? |
| 4756 | active_dwell : passive_dwell); |
| 4757 | |
| 4758 | scan_ch++; |
| 4759 | added++; |
| 4760 | } |
| 4761 | |
| 4762 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 4763 | return added; |
| 4764 | } |
| 4765 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4766 | static void iwl3945_init_hw_rates(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4767 | struct ieee80211_rate *rates) |
| 4768 | { |
| 4769 | int i; |
| 4770 | |
| 4771 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4772 | rates[i].bitrate = iwl3945_rates[i].ieee * 5; |
| 4773 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 4774 | rates[i].hw_value_short = i; |
| 4775 | rates[i].flags = 0; |
Samuel Ortiz | d9829a6 | 2008-12-19 10:37:12 +0800 | [diff] [blame] | 4776 | if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4777 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4778 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4779 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4780 | rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4781 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4782 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | |
| 4786 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4787 | * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4788 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4789 | static int iwl3945_init_geos(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4790 | { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4791 | struct iwl_channel_info *ch; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4792 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4793 | struct ieee80211_channel *channels; |
| 4794 | struct ieee80211_channel *geo_ch; |
| 4795 | struct ieee80211_rate *rates; |
| 4796 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4797 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4798 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 4799 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4800 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 4801 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4802 | return 0; |
| 4803 | } |
| 4804 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4805 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 4806 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4807 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4808 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4809 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4810 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4811 | GFP_KERNEL); |
| 4812 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4813 | kfree(channels); |
| 4814 | return -ENOMEM; |
| 4815 | } |
| 4816 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4817 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4818 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 4819 | sband->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)]; |
| 4820 | /* just OFDM */ |
| 4821 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
| 4822 | sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4823 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4824 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4825 | sband->channels = channels; |
| 4826 | /* OFDM & CCK */ |
| 4827 | sband->bitrates = rates; |
| 4828 | sband->n_bitrates = IWL_RATE_COUNT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4829 | |
| 4830 | priv->ieee_channels = channels; |
| 4831 | priv->ieee_rates = rates; |
| 4832 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4833 | iwl3945_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4834 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4835 | for (i = 0; i < priv->channel_count; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4836 | ch = &priv->channel_info[i]; |
| 4837 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4838 | /* FIXME: might be removed if scan is OK*/ |
| 4839 | if (!is_channel_valid(ch)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4840 | continue; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4841 | |
| 4842 | if (is_channel_a_band(ch)) |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4843 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4844 | else |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4845 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4846 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4847 | geo_ch = &sband->channels[sband->n_channels++]; |
| 4848 | |
| 4849 | geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4850 | geo_ch->max_power = ch->max_power_avg; |
| 4851 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 4852 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4853 | |
| 4854 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4855 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 4856 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4857 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4858 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 4859 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4860 | |
| 4861 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4862 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4863 | |
| 4864 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 4865 | priv->max_channel_txpower_limit = |
| 4866 | ch->max_power_avg; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4867 | } else { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4868 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | /* Save flags for reg domain usage */ |
| 4872 | geo_ch->orig_flags = geo_ch->flags; |
| 4873 | |
| 4874 | IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n", |
| 4875 | ch->channel, geo_ch->center_freq, |
| 4876 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 4877 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 4878 | "restricted" : "valid", |
| 4879 | geo_ch->flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4880 | } |
| 4881 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4882 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && |
| 4883 | priv->cfg->sku & IWL_SKU_A) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4884 | IWL_INFO(priv, "Incorrectly detected BG card as ABG. " |
| 4885 | "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 4886 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4887 | priv->cfg->sku &= ~IWL_SKU_A; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4888 | } |
| 4889 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4890 | 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] | 4891 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 4892 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4893 | |
John W. Linville | e0e0a67 | 2008-03-25 15:58:40 -0400 | [diff] [blame] | 4894 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 4895 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 4896 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4897 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 4898 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 4899 | &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4900 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4901 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4902 | |
| 4903 | return 0; |
| 4904 | } |
| 4905 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4906 | /* |
| 4907 | * iwl3945_free_geos - undo allocations in iwl3945_init_geos |
| 4908 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4909 | static void iwl3945_free_geos(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4910 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4911 | kfree(priv->ieee_channels); |
| 4912 | kfree(priv->ieee_rates); |
| 4913 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4914 | } |
| 4915 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4916 | /****************************************************************************** |
| 4917 | * |
| 4918 | * uCode download functions |
| 4919 | * |
| 4920 | ******************************************************************************/ |
| 4921 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4922 | static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4923 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4924 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 4925 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 4926 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 4927 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 4928 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 4929 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4933 | * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4934 | * looking at all data. |
| 4935 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4936 | 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] | 4937 | { |
| 4938 | u32 val; |
| 4939 | u32 save_len = len; |
| 4940 | int rc = 0; |
| 4941 | u32 errcnt; |
| 4942 | |
| 4943 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4944 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4945 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4946 | if (rc) |
| 4947 | return rc; |
| 4948 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4949 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 4950 | IWL39_RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4951 | |
| 4952 | errcnt = 0; |
| 4953 | for (; len > 0; len -= sizeof(u32), image++) { |
| 4954 | /* read data comes through single port, auto-incr addr */ |
| 4955 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4956 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4957 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4958 | if (val != le32_to_cpu(*image)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4959 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4960 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4961 | save_len - len, val, le32_to_cpu(*image)); |
| 4962 | rc = -EIO; |
| 4963 | errcnt++; |
| 4964 | if (errcnt >= 20) |
| 4965 | break; |
| 4966 | } |
| 4967 | } |
| 4968 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4969 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4970 | |
| 4971 | if (!errcnt) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 4972 | IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4973 | |
| 4974 | return rc; |
| 4975 | } |
| 4976 | |
| 4977 | |
| 4978 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4979 | * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4980 | * using sample data 100 bytes apart. If these sample points are good, |
| 4981 | * it's a pretty good bet that everything between them is good, too. |
| 4982 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4983 | 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] | 4984 | { |
| 4985 | u32 val; |
| 4986 | int rc = 0; |
| 4987 | u32 errcnt = 0; |
| 4988 | u32 i; |
| 4989 | |
| 4990 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4991 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 4992 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4993 | if (rc) |
| 4994 | return rc; |
| 4995 | |
| 4996 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 4997 | /* read data comes through single port, auto-incr addr */ |
| 4998 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4999 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5000 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5001 | i + IWL39_RTC_INST_LOWER_BOUND); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5002 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5003 | if (val != le32_to_cpu(*image)) { |
| 5004 | #if 0 /* Enable this if you want to see details */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5005 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5006 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5007 | i, val, *image); |
| 5008 | #endif |
| 5009 | rc = -EIO; |
| 5010 | errcnt++; |
| 5011 | if (errcnt >= 3) |
| 5012 | break; |
| 5013 | } |
| 5014 | } |
| 5015 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5016 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5017 | |
| 5018 | return rc; |
| 5019 | } |
| 5020 | |
| 5021 | |
| 5022 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5023 | * iwl3945_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5024 | * and verify its contents |
| 5025 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5026 | static int iwl3945_verify_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5027 | { |
| 5028 | __le32 *image; |
| 5029 | u32 len; |
| 5030 | int rc = 0; |
| 5031 | |
| 5032 | /* Try bootstrap */ |
| 5033 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5034 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5035 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5036 | if (rc == 0) { |
| 5037 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 5038 | return 0; |
| 5039 | } |
| 5040 | |
| 5041 | /* Try initialize */ |
| 5042 | image = (__le32 *)priv->ucode_init.v_addr; |
| 5043 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5044 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5045 | if (rc == 0) { |
| 5046 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 5047 | return 0; |
| 5048 | } |
| 5049 | |
| 5050 | /* Try runtime/protocol */ |
| 5051 | image = (__le32 *)priv->ucode_code.v_addr; |
| 5052 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5053 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5054 | if (rc == 0) { |
| 5055 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 5056 | return 0; |
| 5057 | } |
| 5058 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5059 | IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5060 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5061 | /* Since nothing seems to match, show first several data entries in |
| 5062 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 5063 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5064 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5065 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5066 | rc = iwl3945_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5067 | |
| 5068 | return rc; |
| 5069 | } |
| 5070 | |
| 5071 | |
| 5072 | /* check contents of special bootstrap uCode SRAM */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5073 | static int iwl3945_verify_bsm(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5074 | { |
| 5075 | __le32 *image = priv->ucode_boot.v_addr; |
| 5076 | u32 len = priv->ucode_boot.len; |
| 5077 | u32 reg; |
| 5078 | u32 val; |
| 5079 | |
| 5080 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 5081 | |
| 5082 | /* verify BSM SRAM contents */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5083 | val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5084 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 5085 | reg < BSM_SRAM_LOWER_BOUND + len; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 5086 | reg += sizeof(u32), image++) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5087 | val = iwl_read_prph(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5088 | if (val != le32_to_cpu(*image)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5089 | IWL_ERR(priv, "BSM uCode verification failed at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5090 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 5091 | BSM_SRAM_LOWER_BOUND, |
| 5092 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 5093 | val, le32_to_cpu(*image)); |
| 5094 | return -EIO; |
| 5095 | } |
| 5096 | } |
| 5097 | |
| 5098 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 5099 | |
| 5100 | return 0; |
| 5101 | } |
| 5102 | |
| 5103 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5104 | * iwl3945_load_bsm - Load bootstrap instructions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5105 | * |
| 5106 | * BSM operation: |
| 5107 | * |
| 5108 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 5109 | * in special SRAM that does not power down during RFKILL. When powering back |
| 5110 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 5111 | * the bootstrap program into the on-board processor, and starts it. |
| 5112 | * |
| 5113 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 5114 | * program from host DRAM locations indicated by the host driver in the |
| 5115 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 5116 | * automatically. |
| 5117 | * |
| 5118 | * When initializing the NIC, the host driver points the BSM to the |
| 5119 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 5120 | * notifies host via "initialize alive" that it is complete. |
| 5121 | * |
| 5122 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 5123 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 5124 | * (filled initially with starting data values for the on-board processor), |
| 5125 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 5126 | * which begins normal operation. |
| 5127 | * |
| 5128 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 5129 | * the backup data cache in DRAM before SRAM is powered down. |
| 5130 | * |
| 5131 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 5132 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 5133 | * and re-launches the runtime uCode from where it left off. |
| 5134 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5135 | static int iwl3945_load_bsm(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5136 | { |
| 5137 | __le32 *image = priv->ucode_boot.v_addr; |
| 5138 | u32 len = priv->ucode_boot.len; |
| 5139 | dma_addr_t pinst; |
| 5140 | dma_addr_t pdata; |
| 5141 | u32 inst_len; |
| 5142 | u32 data_len; |
| 5143 | int rc; |
| 5144 | int i; |
| 5145 | u32 done; |
| 5146 | u32 reg_offset; |
| 5147 | |
| 5148 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 5149 | |
| 5150 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5151 | if (len > IWL39_MAX_BSM_SIZE) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5152 | return -EINVAL; |
| 5153 | |
| 5154 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5155 | * in host DRAM ... host DRAM physical address bits 31:0 for 3945. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5156 | * NOTE: iwl3945_initialize_alive_start() will replace these values, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5157 | * after the "initialize" uCode has run, to point to |
| 5158 | * runtime/protocol instructions and backup data cache. */ |
| 5159 | pinst = priv->ucode_init.p_addr; |
| 5160 | pdata = priv->ucode_init_data.p_addr; |
| 5161 | inst_len = priv->ucode_init.len; |
| 5162 | data_len = priv->ucode_init_data.len; |
| 5163 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5164 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5165 | if (rc) |
| 5166 | return rc; |
| 5167 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5168 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 5169 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 5170 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 5171 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5172 | |
| 5173 | /* Fill BSM memory with bootstrap instructions */ |
| 5174 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 5175 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 5176 | reg_offset += sizeof(u32), image++) |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5177 | _iwl_write_prph(priv, reg_offset, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5178 | le32_to_cpu(*image)); |
| 5179 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5180 | rc = iwl3945_verify_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5181 | if (rc) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5182 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5183 | return rc; |
| 5184 | } |
| 5185 | |
| 5186 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5187 | iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 5188 | iwl_write_prph(priv, BSM_WR_MEM_DST_REG, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5189 | IWL39_RTC_INST_LOWER_BOUND); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5190 | iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5191 | |
| 5192 | /* Load bootstrap code into instruction SRAM now, |
| 5193 | * to prepare to load "initialize" uCode */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5194 | iwl_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5195 | BSM_WR_CTRL_REG_BIT_START); |
| 5196 | |
| 5197 | /* Wait for load of bootstrap uCode to finish */ |
| 5198 | for (i = 0; i < 100; i++) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5199 | done = iwl_read_prph(priv, BSM_WR_CTRL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5200 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 5201 | break; |
| 5202 | udelay(10); |
| 5203 | } |
| 5204 | if (i < 100) |
| 5205 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 5206 | else { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5207 | IWL_ERR(priv, "BSM write did not complete!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5208 | return -EIO; |
| 5209 | } |
| 5210 | |
| 5211 | /* Enable future boot loads whenever power management unit triggers it |
| 5212 | * (e.g. when powering back up after power-save shutdown) */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5213 | iwl_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5214 | BSM_WR_CTRL_REG_BIT_START_EN); |
| 5215 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5216 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5217 | |
| 5218 | return 0; |
| 5219 | } |
| 5220 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5221 | static void iwl3945_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5222 | { |
| 5223 | /* Remove all resets to allow NIC to operate */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5224 | iwl_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5228 | * iwl3945_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5229 | * |
| 5230 | * Copy into buffers for card to fetch via bus-mastering |
| 5231 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5232 | static int iwl3945_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5233 | { |
Kolekar, Abhijeet | a78fe75 | 2008-12-19 10:37:21 +0800 | [diff] [blame] | 5234 | struct iwl_ucode *ucode; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5235 | int ret = -EINVAL, index; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5236 | const struct firmware *ucode_raw; |
| 5237 | /* firmware file name contains uCode/driver compatibility version */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5238 | const char *name_pre = priv->cfg->fw_name_pre; |
| 5239 | const unsigned int api_max = priv->cfg->ucode_api_max; |
| 5240 | const unsigned int api_min = priv->cfg->ucode_api_min; |
| 5241 | char buf[25]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5242 | u8 *src; |
| 5243 | size_t len; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5244 | 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] | 5245 | |
| 5246 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 5247 | * request_firmware() is synchronous, file is in memory on return. */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5248 | for (index = api_max; index >= api_min; index--) { |
| 5249 | sprintf(buf, "%s%u%s", name_pre, index, ".ucode"); |
| 5250 | ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev); |
| 5251 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5252 | IWL_ERR(priv, "%s firmware file req failed: %d\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5253 | buf, ret); |
| 5254 | if (ret == -ENOENT) |
| 5255 | continue; |
| 5256 | else |
| 5257 | goto error; |
| 5258 | } else { |
| 5259 | if (index < api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5260 | IWL_ERR(priv, "Loaded firmware %s, " |
| 5261 | "which is deprecated. " |
| 5262 | " Please use API v%u instead.\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5263 | buf, api_max); |
| 5264 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 5265 | buf, ucode_raw->size); |
| 5266 | break; |
| 5267 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5268 | } |
| 5269 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5270 | if (ret < 0) |
| 5271 | goto error; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5272 | |
| 5273 | /* Make sure that we got at least our header! */ |
| 5274 | if (ucode_raw->size < sizeof(*ucode)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5275 | IWL_ERR(priv, "File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5276 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5277 | goto err_release; |
| 5278 | } |
| 5279 | |
| 5280 | /* Data from ucode file: header followed by uCode images */ |
| 5281 | ucode = (void *)ucode_raw->data; |
| 5282 | |
Chatre, Reinette | c02b3ac | 2008-12-02 12:14:05 -0800 | [diff] [blame] | 5283 | priv->ucode_ver = le32_to_cpu(ucode->ver); |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5284 | api_ver = IWL_UCODE_API(priv->ucode_ver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5285 | inst_size = le32_to_cpu(ucode->inst_size); |
| 5286 | data_size = le32_to_cpu(ucode->data_size); |
| 5287 | init_size = le32_to_cpu(ucode->init_size); |
| 5288 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 5289 | boot_size = le32_to_cpu(ucode->boot_size); |
| 5290 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5291 | /* api_ver should match the api version forming part of the |
| 5292 | * firmware filename ... but we don't check for that and only rely |
| 5293 | * on the API version read from firware header from here on forward */ |
| 5294 | |
| 5295 | if (api_ver < api_min || api_ver > api_max) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5296 | IWL_ERR(priv, "Driver unable to support your firmware API. " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5297 | "Driver supports v%u, firmware is v%u.\n", |
| 5298 | api_max, api_ver); |
| 5299 | priv->ucode_ver = 0; |
| 5300 | ret = -EINVAL; |
| 5301 | goto err_release; |
| 5302 | } |
| 5303 | if (api_ver != api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5304 | IWL_ERR(priv, "Firmware has old API version. Expected %u, " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5305 | "got %u. New firmware can be obtained " |
| 5306 | "from http://www.intellinuxwireless.org.\n", |
| 5307 | api_max, api_ver); |
| 5308 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 5309 | IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n", |
| 5310 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 5311 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 5312 | IWL_UCODE_API(priv->ucode_ver), |
| 5313 | IWL_UCODE_SERIAL(priv->ucode_ver)); |
| 5314 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5315 | IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n", |
| 5316 | priv->ucode_ver); |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 5317 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size); |
| 5318 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size); |
| 5319 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size); |
| 5320 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size); |
| 5321 | 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] | 5322 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5323 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5324 | /* Verify size of file vs. image size info in file's header */ |
| 5325 | if (ucode_raw->size < sizeof(*ucode) + |
| 5326 | inst_size + data_size + init_size + |
| 5327 | init_data_size + boot_size) { |
| 5328 | |
| 5329 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 5330 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5331 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5332 | goto err_release; |
| 5333 | } |
| 5334 | |
| 5335 | /* Verify that uCode images will fit in card's SRAM */ |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5336 | if (inst_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5337 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 5338 | inst_size); |
| 5339 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5340 | goto err_release; |
| 5341 | } |
| 5342 | |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5343 | if (data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5344 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 5345 | data_size); |
| 5346 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5347 | goto err_release; |
| 5348 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5349 | if (init_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5350 | IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n", |
| 5351 | init_size); |
| 5352 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5353 | goto err_release; |
| 5354 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5355 | if (init_data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5356 | IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n", |
| 5357 | init_data_size); |
| 5358 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5359 | goto err_release; |
| 5360 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 5361 | if (boot_size > IWL39_MAX_BSM_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5362 | IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n", |
| 5363 | boot_size); |
| 5364 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5365 | goto err_release; |
| 5366 | } |
| 5367 | |
| 5368 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 5369 | |
| 5370 | /* Runtime instructions and 2 copies of data: |
| 5371 | * 1) unmodified from disk |
| 5372 | * 2) backup cache for save/restore during power-downs */ |
| 5373 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5374 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5375 | |
| 5376 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5377 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5378 | |
| 5379 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5380 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5381 | |
| 5382 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5383 | !priv->ucode_data_backup.v_addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5384 | goto err_pci_alloc; |
| 5385 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5386 | /* Initialization instructions and data */ |
| 5387 | if (init_size && init_data_size) { |
| 5388 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5389 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5390 | |
| 5391 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5392 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5393 | |
| 5394 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 5395 | goto err_pci_alloc; |
| 5396 | } |
| 5397 | |
| 5398 | /* Bootstrap (instructions only, no data) */ |
| 5399 | if (boot_size) { |
| 5400 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5401 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5402 | |
| 5403 | if (!priv->ucode_boot.v_addr) |
| 5404 | goto err_pci_alloc; |
| 5405 | } |
| 5406 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5407 | /* Copy images into buffers for card's bus-master reads ... */ |
| 5408 | |
| 5409 | /* Runtime instructions (first block of data in file) */ |
| 5410 | src = &ucode->data[0]; |
| 5411 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5412 | 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] | 5413 | memcpy(priv->ucode_code.v_addr, src, len); |
| 5414 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 5415 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 5416 | |
| 5417 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5418 | * NOTE: Copy into backup buffer will be done in iwl3945_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5419 | src = &ucode->data[inst_size]; |
| 5420 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5421 | 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] | 5422 | memcpy(priv->ucode_data.v_addr, src, len); |
| 5423 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 5424 | |
| 5425 | /* Initialization instructions (3rd block) */ |
| 5426 | if (init_size) { |
| 5427 | src = &ucode->data[inst_size + data_size]; |
| 5428 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5429 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 5430 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5431 | memcpy(priv->ucode_init.v_addr, src, len); |
| 5432 | } |
| 5433 | |
| 5434 | /* Initialization data (4th block) */ |
| 5435 | if (init_data_size) { |
| 5436 | src = &ucode->data[inst_size + data_size + init_size]; |
| 5437 | len = priv->ucode_init_data.len; |
| 5438 | IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n", |
| 5439 | (int)len); |
| 5440 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 5441 | } |
| 5442 | |
| 5443 | /* Bootstrap instructions (5th block) */ |
| 5444 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 5445 | len = priv->ucode_boot.len; |
| 5446 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n", |
| 5447 | (int)len); |
| 5448 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 5449 | |
| 5450 | /* We have our copies now, allow OS release its copies */ |
| 5451 | release_firmware(ucode_raw); |
| 5452 | return 0; |
| 5453 | |
| 5454 | err_pci_alloc: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5455 | IWL_ERR(priv, "failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5456 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5457 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5458 | |
| 5459 | err_release: |
| 5460 | release_firmware(ucode_raw); |
| 5461 | |
| 5462 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5463 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | |
| 5467 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5468 | * iwl3945_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5469 | * |
| 5470 | * Tell initialization uCode where to find runtime uCode. |
| 5471 | * |
| 5472 | * BSM registers initially contain pointers to initialization uCode. |
| 5473 | * We need to replace them to load runtime uCode inst and data, |
| 5474 | * and to save runtime data when powering down. |
| 5475 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5476 | static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5477 | { |
| 5478 | dma_addr_t pinst; |
| 5479 | dma_addr_t pdata; |
| 5480 | int rc = 0; |
| 5481 | unsigned long flags; |
| 5482 | |
| 5483 | /* bits 31:0 for 3945 */ |
| 5484 | pinst = priv->ucode_code.p_addr; |
| 5485 | pdata = priv->ucode_data_backup.p_addr; |
| 5486 | |
| 5487 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5488 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5489 | if (rc) { |
| 5490 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5491 | return rc; |
| 5492 | } |
| 5493 | |
| 5494 | /* Tell bootstrap uCode where to find image to load */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5495 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 5496 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 5497 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5498 | priv->ucode_data.len); |
| 5499 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5500 | /* 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] | 5501 | * that all new ptr/size info is in place */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5502 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5503 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 5504 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5505 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5506 | |
| 5507 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5508 | |
| 5509 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 5510 | |
| 5511 | return rc; |
| 5512 | } |
| 5513 | |
| 5514 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5515 | * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5516 | * |
| 5517 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 5518 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5519 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5520 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5521 | static void iwl3945_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5522 | { |
| 5523 | /* Check alive response for "valid" sign from uCode */ |
| 5524 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 5525 | /* We had an error bringing up the hardware, so take it |
| 5526 | * all the way back down so we can try again */ |
| 5527 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 5528 | goto restart; |
| 5529 | } |
| 5530 | |
| 5531 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 5532 | * This is a paranoid check, because we would not have gotten the |
| 5533 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5534 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5535 | /* Runtime instruction load was bad; |
| 5536 | * take it all the way back down so we can try again */ |
| 5537 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 5538 | goto restart; |
| 5539 | } |
| 5540 | |
| 5541 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 5542 | * load and launch runtime uCode, which will send us another "Alive" |
| 5543 | * notification. */ |
| 5544 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5545 | if (iwl3945_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5546 | /* Runtime instruction load won't happen; |
| 5547 | * take it all the way back down so we can try again */ |
| 5548 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 5549 | goto restart; |
| 5550 | } |
| 5551 | return; |
| 5552 | |
| 5553 | restart: |
| 5554 | queue_work(priv->workqueue, &priv->restart); |
| 5555 | } |
| 5556 | |
| 5557 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5558 | /* temporary */ |
| 5559 | static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, |
| 5560 | struct sk_buff *skb); |
| 5561 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5562 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5563 | * iwl3945_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5564 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5565 | * Alive gets handled by iwl3945_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5566 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5567 | static void iwl3945_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5568 | { |
| 5569 | int rc = 0; |
| 5570 | int thermal_spin = 0; |
| 5571 | u32 rfkill; |
| 5572 | |
| 5573 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 5574 | |
| 5575 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 5576 | /* We had an error bringing up the hardware, so take it |
| 5577 | * all the way back down so we can try again */ |
| 5578 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 5579 | goto restart; |
| 5580 | } |
| 5581 | |
| 5582 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 5583 | * This is a paranoid check, because we would not have gotten the |
| 5584 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5585 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5586 | /* Runtime instruction load was bad; |
| 5587 | * take it all the way back down so we can try again */ |
| 5588 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 5589 | goto restart; |
| 5590 | } |
| 5591 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5592 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5593 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5594 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5595 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5596 | IWL_WARN(priv, "Can not read RFKILL status from adapter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5597 | return; |
| 5598 | } |
| 5599 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5600 | rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5601 | IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5602 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5603 | |
| 5604 | if (rfkill & 0x1) { |
| 5605 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 5606 | /* if RFKILL is not on, then wait for thermal |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5607 | * sensor in adapter to kick in */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5608 | while (iwl3945_hw_get_temperature(priv) == 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5609 | thermal_spin++; |
| 5610 | udelay(10); |
| 5611 | } |
| 5612 | |
| 5613 | if (thermal_spin) |
| 5614 | IWL_DEBUG_INFO("Thermal calibration took %dus\n", |
| 5615 | thermal_spin * 10); |
| 5616 | } else |
| 5617 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5618 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5619 | /* After the ALIVE response, we can send commands to 3945 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5620 | set_bit(STATUS_ALIVE, &priv->status); |
| 5621 | |
| 5622 | /* Clear out the uCode error bit if it is set */ |
| 5623 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 5624 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5625 | if (iwl3945_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5626 | return; |
| 5627 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 5628 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5629 | |
| 5630 | priv->active_rate = priv->rates_mask; |
| 5631 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 5632 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5633 | iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5634 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5635 | if (iwl3945_is_associated(priv)) { |
| 5636 | struct iwl3945_rxon_cmd *active_rxon = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5637 | (struct iwl3945_rxon_cmd *)(&priv->active39_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5638 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5639 | memcpy(&priv->staging39_rxon, &priv->active39_rxon, |
| 5640 | sizeof(priv->staging39_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5641 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5642 | } else { |
| 5643 | /* Initialize our rx_config data */ |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 5644 | iwl3945_connection_init_rx_config(priv, priv->iw_mode); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 5645 | memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5646 | } |
| 5647 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5648 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5649 | iwl3945_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5650 | |
| 5651 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5652 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5653 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5654 | iwl3945_reg_txpower_periodic(priv); |
| 5655 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 5656 | iwl3945_led_register(priv); |
| 5657 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5658 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 5659 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5660 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5661 | |
| 5662 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5663 | iwl3945_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5664 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 5665 | /* reassociate for ADHOC mode */ |
| 5666 | if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) { |
| 5667 | struct sk_buff *beacon = ieee80211_beacon_get(priv->hw, |
| 5668 | priv->vif); |
| 5669 | if (beacon) |
| 5670 | iwl3945_mac_beacon_update(priv->hw, beacon); |
| 5671 | } |
| 5672 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5673 | return; |
| 5674 | |
| 5675 | restart: |
| 5676 | queue_work(priv->workqueue, &priv->restart); |
| 5677 | } |
| 5678 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5679 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5680 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5681 | static void __iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5682 | { |
| 5683 | unsigned long flags; |
| 5684 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5685 | struct ieee80211_conf *conf = NULL; |
| 5686 | |
| 5687 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 5688 | |
| 5689 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5690 | |
| 5691 | if (!exit_pending) |
| 5692 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5693 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 5694 | iwl3945_led_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5695 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5696 | |
| 5697 | /* Unblock any waiting calls */ |
| 5698 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 5699 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5700 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 5701 | * exiting the module */ |
| 5702 | if (!exit_pending) |
| 5703 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5704 | |
| 5705 | /* stop and reset the on-board processor */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5706 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5707 | |
| 5708 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5709 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5710 | iwl3945_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5711 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5712 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5713 | |
| 5714 | if (priv->mac80211_registered) |
| 5715 | ieee80211_stop_queues(priv->hw); |
| 5716 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5717 | /* If we have not previously called iwl3945_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5718 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5719 | if (!iwl3945_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5720 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5721 | STATUS_RF_KILL_HW | |
| 5722 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5723 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5724 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5725 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5726 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5727 | STATUS_IN_SUSPEND | |
| 5728 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5729 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5730 | goto exit; |
| 5731 | } |
| 5732 | |
| 5733 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 5734 | * SUSPEND bits and continue taking the NIC down. */ |
| 5735 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5736 | STATUS_RF_KILL_HW | |
| 5737 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5738 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5739 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5740 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5741 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 5742 | STATUS_IN_SUSPEND | |
| 5743 | test_bit(STATUS_FW_ERROR, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5744 | STATUS_FW_ERROR | |
| 5745 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 5746 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5747 | |
| 5748 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5749 | 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] | 5750 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5751 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5752 | iwl3945_hw_txq_ctx_stop(priv); |
| 5753 | iwl3945_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5754 | |
| 5755 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5756 | if (!iwl_grab_nic_access(priv)) { |
| 5757 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5758 | APMG_CLK_VAL_DMA_CLK_RQT); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5759 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5760 | } |
| 5761 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5762 | |
| 5763 | udelay(5); |
| 5764 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5765 | iwl3945_hw_nic_stop_master(priv); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5766 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5767 | iwl3945_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5768 | |
| 5769 | exit: |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 5770 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5771 | |
| 5772 | if (priv->ibss_beacon) |
| 5773 | dev_kfree_skb(priv->ibss_beacon); |
| 5774 | priv->ibss_beacon = NULL; |
| 5775 | |
| 5776 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5777 | iwl3945_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5778 | } |
| 5779 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5780 | static void iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5781 | { |
| 5782 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5783 | __iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5784 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5785 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5786 | iwl3945_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | #define MAX_HW_RESTARTS 5 |
| 5790 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5791 | static int __iwl3945_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5792 | { |
| 5793 | int rc, i; |
| 5794 | |
| 5795 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5796 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5797 | return -EIO; |
| 5798 | } |
| 5799 | |
| 5800 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5801 | IWL_WARN(priv, "Radio disabled by SW RF kill (module " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5802 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5803 | return -ENODEV; |
| 5804 | } |
| 5805 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5806 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5807 | IWL_ERR(priv, "ucode not available for device bring up\n"); |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5808 | return -EIO; |
| 5809 | } |
| 5810 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5811 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5812 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5813 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 5814 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5815 | else { |
| 5816 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5817 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5818 | IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5819 | return -ENODEV; |
| 5820 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5821 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5822 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5823 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5824 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5825 | rc = iwl3945_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5826 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5827 | IWL_ERR(priv, "Unable to int nic\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5828 | return rc; |
| 5829 | } |
| 5830 | |
| 5831 | /* make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5832 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5833 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5834 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 5835 | |
| 5836 | /* clear (again), then enable host interrupts */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5837 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5838 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5839 | |
| 5840 | /* really make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 5841 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5842 | 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] | 5843 | |
| 5844 | /* Copy original ucode data image from disk into backup cache. |
| 5845 | * This will be used to initialize the on-board processor's |
| 5846 | * data SRAM for a clean start when the runtime program first loads. */ |
| 5847 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5848 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5849 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5850 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 5851 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5852 | return 0; |
| 5853 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5854 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 5855 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5856 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5857 | |
| 5858 | /* load bootstrap state machine, |
| 5859 | * load bootstrap program into processor's memory, |
| 5860 | * prepare to load the "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5861 | rc = iwl3945_load_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5862 | |
| 5863 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5864 | IWL_ERR(priv, |
| 5865 | "Unable to set up bootstrap uCode: %d\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5866 | continue; |
| 5867 | } |
| 5868 | |
| 5869 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5870 | iwl3945_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5871 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5872 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 5873 | |
| 5874 | return 0; |
| 5875 | } |
| 5876 | |
| 5877 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5878 | __iwl3945_down(priv); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5879 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5880 | |
| 5881 | /* tried to restart and config the device for as long as our |
| 5882 | * patience could withstand */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5883 | IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5884 | return -EIO; |
| 5885 | } |
| 5886 | |
| 5887 | |
| 5888 | /***************************************************************************** |
| 5889 | * |
| 5890 | * Workqueue callbacks |
| 5891 | * |
| 5892 | *****************************************************************************/ |
| 5893 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5894 | static void iwl3945_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5895 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5896 | struct iwl_priv *priv = |
| 5897 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5898 | |
| 5899 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5900 | return; |
| 5901 | |
| 5902 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5903 | iwl3945_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5904 | mutex_unlock(&priv->mutex); |
| 5905 | } |
| 5906 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5907 | static void iwl3945_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5908 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5909 | struct iwl_priv *priv = |
| 5910 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5911 | |
| 5912 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5913 | return; |
| 5914 | |
| 5915 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5916 | iwl3945_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5917 | mutex_unlock(&priv->mutex); |
| 5918 | } |
| 5919 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5920 | static void iwl3945_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5921 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5922 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5923 | |
| 5924 | wake_up_interruptible(&priv->wait_command_queue); |
| 5925 | |
| 5926 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5927 | return; |
| 5928 | |
| 5929 | mutex_lock(&priv->mutex); |
| 5930 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5931 | if (!iwl3945_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5932 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 5933 | "HW and/or SW RF Kill no longer active, restarting " |
| 5934 | "device\n"); |
| 5935 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5936 | queue_work(priv->workqueue, &priv->restart); |
| 5937 | } else { |
| 5938 | |
| 5939 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5940 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 5941 | "disabled by SW switch\n"); |
| 5942 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5943 | IWL_WARN(priv, "Radio Frequency Kill Switch is On:\n" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5944 | "Kill switch must be turned off for " |
| 5945 | "wireless networking to work.\n"); |
| 5946 | } |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5947 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5948 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 5949 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5950 | } |
| 5951 | |
| 5952 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 5953 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5954 | static void iwl3945_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5955 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5956 | struct iwl_priv *priv = |
| 5957 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5958 | |
| 5959 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5960 | return; |
| 5961 | |
| 5962 | mutex_lock(&priv->mutex); |
| 5963 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 5964 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5965 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 5966 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 5967 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 5968 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5969 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5970 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5971 | } |
| 5972 | mutex_unlock(&priv->mutex); |
| 5973 | } |
| 5974 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5975 | static void iwl3945_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5976 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5977 | struct iwl_priv *priv = |
| 5978 | container_of(data, struct iwl_priv, request_scan); |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame^] | 5979 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5980 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5981 | .len = sizeof(struct iwl3945_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5982 | .meta.flags = CMD_SIZE_HUGE, |
| 5983 | }; |
| 5984 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5985 | struct iwl3945_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5986 | struct ieee80211_conf *conf = NULL; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 5987 | u8 n_probes = 2; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5988 | enum ieee80211_band band; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 5989 | DECLARE_SSID_BUF(ssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5990 | |
| 5991 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5992 | |
| 5993 | mutex_lock(&priv->mutex); |
| 5994 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5995 | if (!iwl3945_is_ready(priv)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 5996 | IWL_WARN(priv, "request scan called when driver not ready.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5997 | goto done; |
| 5998 | } |
| 5999 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 6000 | /* Make sure the scan wasn't canceled before this queued work |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6001 | * was given the chance to run... */ |
| 6002 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 6003 | goto done; |
| 6004 | |
| 6005 | /* This should never be called or scheduled if there is currently |
| 6006 | * a scan active in the hardware. */ |
| 6007 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 6008 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 6009 | "Ignoring second request.\n"); |
| 6010 | rc = -EIO; |
| 6011 | goto done; |
| 6012 | } |
| 6013 | |
| 6014 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6015 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 6016 | goto done; |
| 6017 | } |
| 6018 | |
| 6019 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6020 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6021 | goto done; |
| 6022 | } |
| 6023 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6024 | if (iwl3945_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6025 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6026 | goto done; |
| 6027 | } |
| 6028 | |
| 6029 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 6030 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 6031 | goto done; |
| 6032 | } |
| 6033 | |
| 6034 | if (!priv->scan_bands) { |
| 6035 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 6036 | goto done; |
| 6037 | } |
| 6038 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6039 | if (!priv->scan39) { |
| 6040 | priv->scan39 = kmalloc(sizeof(struct iwl3945_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6041 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6042 | if (!priv->scan39) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6043 | rc = -ENOMEM; |
| 6044 | goto done; |
| 6045 | } |
| 6046 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6047 | scan = priv->scan39; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6048 | memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6049 | |
| 6050 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 6051 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 6052 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6053 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6054 | u16 interval = 0; |
| 6055 | u32 extra; |
| 6056 | u32 suspend_time = 100; |
| 6057 | u32 scan_suspend_time = 100; |
| 6058 | unsigned long flags; |
| 6059 | |
| 6060 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 6061 | |
| 6062 | spin_lock_irqsave(&priv->lock, flags); |
| 6063 | interval = priv->beacon_int; |
| 6064 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6065 | |
| 6066 | scan->suspend_time = 0; |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6067 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6068 | if (!interval) |
| 6069 | interval = suspend_time; |
| 6070 | /* |
| 6071 | * suspend time format: |
| 6072 | * 0-19: beacon interval in usec (time before exec.) |
| 6073 | * 20-23: 0 |
| 6074 | * 24-31: number of beacons (suspend between channels) |
| 6075 | */ |
| 6076 | |
| 6077 | extra = (suspend_time / interval) << 24; |
| 6078 | scan_suspend_time = 0xFF0FFFFF & |
| 6079 | (extra | ((suspend_time % interval) * 1024)); |
| 6080 | |
| 6081 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 6082 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 6083 | scan_suspend_time, interval); |
| 6084 | } |
| 6085 | |
| 6086 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 6087 | if (priv->one_direct_scan) { |
| 6088 | IWL_DEBUG_SCAN |
| 6089 | ("Kicking off one direct scan for '%s'\n", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6090 | print_ssid(ssid, priv->direct_ssid, |
| 6091 | priv->direct_ssid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6092 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6093 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 6094 | memcpy(scan->direct_scan[0].ssid, |
| 6095 | priv->direct_ssid, priv->direct_ssid_len); |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 6096 | n_probes++; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 6097 | } else |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 6098 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6099 | |
| 6100 | /* We don't build a direct scan probe request; the uCode will do |
| 6101 | * that based on the direct_mask added to each channel entry */ |
| 6102 | scan->tx_cmd.len = cpu_to_le16( |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6103 | iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
Johannes Berg | 430cfe9 | 2008-10-28 18:06:02 +0100 | [diff] [blame] | 6104 | IWL_MAX_SCAN_SIZE - sizeof(*scan))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6105 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 6106 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6107 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 6108 | |
| 6109 | /* flags + rate selection */ |
| 6110 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 6111 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6112 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 6113 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; |
| 6114 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6115 | band = IEEE80211_BAND_2GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 6116 | } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6117 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; |
| 6118 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6119 | band = IEEE80211_BAND_5GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 6120 | } else { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6121 | IWL_WARN(priv, "Invalid scan band count\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6122 | goto done; |
| 6123 | } |
| 6124 | |
| 6125 | /* select Rx antennas */ |
| 6126 | scan->flags |= iwl3945_get_antenna_flags(priv); |
| 6127 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6128 | if (priv->iw_mode == NL80211_IFTYPE_MONITOR) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6129 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 6130 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 6131 | scan->channel_count = |
| 6132 | iwl3945_get_channels_for_scan(priv, band, 1, /* active */ |
| 6133 | n_probes, |
| 6134 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6135 | |
Reinette Chatre | 14b5433 | 2008-11-04 12:21:35 -0800 | [diff] [blame] | 6136 | if (scan->channel_count == 0) { |
| 6137 | IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count); |
| 6138 | goto done; |
| 6139 | } |
| 6140 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6141 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6142 | scan->channel_count * sizeof(struct iwl3945_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6143 | cmd.data = scan; |
| 6144 | scan->len = cpu_to_le16(cmd.len); |
| 6145 | |
| 6146 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6147 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6148 | if (rc) |
| 6149 | goto done; |
| 6150 | |
| 6151 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6152 | IWL_SCAN_CHECK_WATCHDOG); |
| 6153 | |
| 6154 | mutex_unlock(&priv->mutex); |
| 6155 | return; |
| 6156 | |
| 6157 | done: |
Mohamed Abbas | 2420ebc | 2008-11-04 12:21:34 -0800 | [diff] [blame] | 6158 | /* can not perform scan make sure we clear scanning |
| 6159 | * bits from status so next scan request can be performed. |
| 6160 | * if we dont clear scanning status bit here all next scan |
| 6161 | * will fail |
| 6162 | */ |
| 6163 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 6164 | clear_bit(STATUS_SCANNING, &priv->status); |
| 6165 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 6166 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6167 | queue_work(priv->workqueue, &priv->scan_completed); |
| 6168 | mutex_unlock(&priv->mutex); |
| 6169 | } |
| 6170 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6171 | static void iwl3945_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6172 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6173 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6174 | |
| 6175 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6176 | return; |
| 6177 | |
| 6178 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6179 | __iwl3945_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6180 | mutex_unlock(&priv->mutex); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 6181 | iwl3945_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6182 | } |
| 6183 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6184 | static void iwl3945_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6185 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6186 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6187 | |
| 6188 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6189 | return; |
| 6190 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6191 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6192 | queue_work(priv->workqueue, &priv->up); |
| 6193 | } |
| 6194 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6195 | static void iwl3945_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6196 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6197 | struct iwl_priv *priv = |
| 6198 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6199 | |
| 6200 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6201 | return; |
| 6202 | |
| 6203 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6204 | iwl3945_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6205 | mutex_unlock(&priv->mutex); |
| 6206 | } |
| 6207 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6208 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 6209 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6210 | static void iwl3945_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6211 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6212 | int rc = 0; |
| 6213 | struct ieee80211_conf *conf = NULL; |
| 6214 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6215 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6216 | 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] | 6217 | return; |
| 6218 | } |
| 6219 | |
| 6220 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6221 | IWL_DEBUG_ASSOC("Associated as %d to: %pM\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6222 | priv->assoc_id, priv->active39_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6223 | |
| 6224 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6225 | return; |
| 6226 | |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 6227 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6228 | return; |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 6229 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6230 | iwl3945_scan_cancel_timeout(priv, 200); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6231 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6232 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6233 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6234 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6235 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6236 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6237 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6238 | iwl3945_setup_rxon_timing(priv); |
| 6239 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6240 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 6241 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6242 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6243 | "Attempting to continue.\n"); |
| 6244 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6245 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6246 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6247 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6248 | |
| 6249 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 6250 | priv->assoc_id, priv->beacon_int); |
| 6251 | |
| 6252 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6253 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6254 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6255 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6256 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6257 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6258 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6259 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6260 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6261 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6262 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6263 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6264 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6265 | |
| 6266 | } |
| 6267 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6268 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6269 | |
| 6270 | switch (priv->iw_mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6271 | case NL80211_IFTYPE_STATION: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6272 | iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6273 | break; |
| 6274 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6275 | case NL80211_IFTYPE_ADHOC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6276 | |
Abhijeet Kolekar | ce546fd | 2008-11-19 15:32:22 -0800 | [diff] [blame] | 6277 | priv->assoc_id = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6278 | iwl3945_add_station(priv, priv->bssid, 0, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6279 | iwl3945_sync_sta(priv, IWL_STA_ID, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6280 | (priv->band == IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6281 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, |
| 6282 | CMD_ASYNC); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6283 | iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); |
| 6284 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6285 | |
| 6286 | break; |
| 6287 | |
| 6288 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6289 | IWL_ERR(priv, "%s Should not be called in %d mode\n", |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 6290 | __func__, priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6291 | break; |
| 6292 | } |
| 6293 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6294 | iwl3945_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 6295 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6296 | /* we have just associated, don't start scan too early */ |
| 6297 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6298 | } |
| 6299 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6300 | static void iwl3945_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6301 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6302 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6303 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6304 | if (!iwl3945_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6305 | return; |
| 6306 | |
| 6307 | mutex_lock(&priv->mutex); |
| 6308 | |
| 6309 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6310 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6311 | |
| 6312 | mutex_unlock(&priv->mutex); |
| 6313 | } |
| 6314 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6315 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6316 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6317 | static void iwl3945_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6318 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6319 | struct iwl_priv *priv = |
| 6320 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6321 | |
| 6322 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 6323 | |
| 6324 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6325 | return; |
| 6326 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6327 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6328 | iwl3945_mac_config(priv->hw, 0); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6329 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6330 | ieee80211_scan_completed(priv->hw); |
| 6331 | |
| 6332 | /* Since setting the TXPOWER may have been deferred while |
| 6333 | * performing the scan, fire one off */ |
| 6334 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6335 | iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6336 | mutex_unlock(&priv->mutex); |
| 6337 | } |
| 6338 | |
| 6339 | /***************************************************************************** |
| 6340 | * |
| 6341 | * mac80211 entry point functions |
| 6342 | * |
| 6343 | *****************************************************************************/ |
| 6344 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6345 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 6346 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6347 | static int iwl3945_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6348 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6349 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6350 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6351 | |
| 6352 | IWL_DEBUG_MAC80211("enter\n"); |
| 6353 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6354 | if (pci_enable_device(priv->pci_dev)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6355 | IWL_ERR(priv, "Fail to pci_enable_device\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6356 | return -ENODEV; |
| 6357 | } |
| 6358 | pci_restore_state(priv->pci_dev); |
| 6359 | pci_enable_msi(priv->pci_dev); |
| 6360 | |
| 6361 | ret = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED, |
| 6362 | DRV_NAME, priv); |
| 6363 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6364 | IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6365 | goto out_disable_msi; |
| 6366 | } |
| 6367 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6368 | /* we should be verifying the device is ready to be opened */ |
| 6369 | mutex_lock(&priv->mutex); |
| 6370 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6371 | memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd)); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6372 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 6373 | * ucode filename and max sizes are card-specific. */ |
| 6374 | |
| 6375 | if (!priv->ucode_code.len) { |
| 6376 | ret = iwl3945_read_ucode(priv); |
| 6377 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6378 | IWL_ERR(priv, "Could not read microcode: %d\n", ret); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6379 | mutex_unlock(&priv->mutex); |
| 6380 | goto out_release_irq; |
| 6381 | } |
| 6382 | } |
| 6383 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6384 | ret = __iwl3945_up(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6385 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6386 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6387 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 6388 | iwl3945_rfkill_set_hw_state(priv); |
| 6389 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6390 | if (ret) |
| 6391 | goto out_release_irq; |
| 6392 | |
| 6393 | IWL_DEBUG_INFO("Start UP work.\n"); |
| 6394 | |
| 6395 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 6396 | return 0; |
| 6397 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6398 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 6399 | * mac80211 will not be run successfully. */ |
| 6400 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 6401 | test_bit(STATUS_READY, &priv->status), |
| 6402 | UCODE_READY_TIMEOUT); |
| 6403 | if (!ret) { |
| 6404 | if (!test_bit(STATUS_READY, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 6405 | IWL_ERR(priv, |
| 6406 | "Wait for START_ALIVE timeout after %dms.\n", |
| 6407 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6408 | ret = -ETIMEDOUT; |
| 6409 | goto out_release_irq; |
| 6410 | } |
| 6411 | } |
| 6412 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6413 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6414 | IWL_DEBUG_MAC80211("leave\n"); |
| 6415 | return 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6416 | |
| 6417 | out_release_irq: |
| 6418 | free_irq(priv->pci_dev->irq, priv); |
| 6419 | out_disable_msi: |
| 6420 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6421 | pci_disable_device(priv->pci_dev); |
| 6422 | priv->is_open = 0; |
| 6423 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6424 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6425 | } |
| 6426 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6427 | static void iwl3945_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6428 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6429 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6430 | |
| 6431 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6432 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6433 | if (!priv->is_open) { |
| 6434 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 6435 | return; |
| 6436 | } |
| 6437 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6438 | priv->is_open = 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6439 | |
| 6440 | if (iwl3945_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6441 | /* stop mac, cancel any scan request and clear |
| 6442 | * RXON_FILTER_ASSOC_MSK BIT |
| 6443 | */ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6444 | mutex_lock(&priv->mutex); |
| 6445 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6446 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6447 | } |
| 6448 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6449 | iwl3945_down(priv); |
| 6450 | |
| 6451 | flush_workqueue(priv->workqueue); |
| 6452 | free_irq(priv->pci_dev->irq, priv); |
| 6453 | pci_disable_msi(priv->pci_dev); |
| 6454 | pci_save_state(priv->pci_dev); |
| 6455 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6456 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6457 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6458 | } |
| 6459 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6460 | 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] | 6461 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6462 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6463 | |
| 6464 | IWL_DEBUG_MAC80211("enter\n"); |
| 6465 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6466 | 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] | 6467 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6468 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 6469 | if (iwl3945_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6470 | dev_kfree_skb_any(skb); |
| 6471 | |
| 6472 | IWL_DEBUG_MAC80211("leave\n"); |
Reinette Chatre | 637f883 | 2009-01-19 15:30:32 -0800 | [diff] [blame] | 6473 | return NETDEV_TX_OK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6474 | } |
| 6475 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6476 | static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6477 | struct ieee80211_if_init_conf *conf) |
| 6478 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6479 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6480 | unsigned long flags; |
| 6481 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6482 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6483 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6484 | if (priv->vif) { |
| 6485 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6486 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6490 | priv->vif = conf->vif; |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 6491 | priv->iw_mode = conf->type; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6492 | |
| 6493 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6494 | |
| 6495 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6496 | |
| 6497 | if (conf->mac_addr) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6498 | IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6499 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 6500 | } |
| 6501 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6502 | if (iwl3945_is_ready(priv)) |
| 6503 | iwl3945_set_mode(priv, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6504 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6505 | mutex_unlock(&priv->mutex); |
| 6506 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6507 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6508 | return 0; |
| 6509 | } |
| 6510 | |
| 6511 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6512 | * iwl3945_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6513 | * |
| 6514 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 6515 | * be set inappropriately and the driver currently sets the hardware up to |
| 6516 | * use it whenever needed. |
| 6517 | */ |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6518 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6519 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6520 | struct iwl_priv *priv = hw->priv; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 6521 | const struct iwl_channel_info *ch_info; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 6522 | struct ieee80211_conf *conf = &hw->conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6523 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6524 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6525 | |
| 6526 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6527 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6528 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6529 | if (!iwl3945_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6530 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6531 | ret = -EIO; |
| 6532 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6533 | } |
| 6534 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6535 | if (unlikely(!iwl3945_param_disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6536 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6537 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 6538 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6539 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6540 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6541 | } |
| 6542 | |
| 6543 | spin_lock_irqsave(&priv->lock, flags); |
| 6544 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6545 | ch_info = iwl3945_get_channel_info(priv, conf->channel->band, |
| 6546 | conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6547 | if (!is_channel_valid(ch_info)) { |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 6548 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6549 | conf->channel->hw_value, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6550 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 6551 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6552 | ret = -EINVAL; |
| 6553 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6554 | } |
| 6555 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6556 | iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6557 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6558 | iwl3945_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6559 | |
| 6560 | /* The list of supported rates and rate mask can be different |
| 6561 | * for each phymode; since the phymode may have changed, reset |
| 6562 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6563 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6564 | |
| 6565 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6566 | |
| 6567 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 6568 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6569 | iwl3945_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6570 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6571 | } |
| 6572 | #endif |
| 6573 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6574 | iwl3945_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6575 | |
| 6576 | if (!conf->radio_enabled) { |
| 6577 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6578 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6579 | } |
| 6580 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6581 | if (iwl3945_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6582 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6583 | ret = -EIO; |
| 6584 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6585 | } |
| 6586 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6587 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6588 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6589 | if (memcmp(&priv->active39_rxon, |
| 6590 | &priv->staging39_rxon, sizeof(priv->staging39_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6591 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6592 | else |
| 6593 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 6594 | |
| 6595 | IWL_DEBUG_MAC80211("leave\n"); |
| 6596 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6597 | out: |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6598 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6599 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6600 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6601 | } |
| 6602 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6603 | static void iwl3945_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6604 | { |
| 6605 | int rc = 0; |
| 6606 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 6607 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6608 | return; |
| 6609 | |
| 6610 | /* The following should be done only at AP bring up */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 6611 | if (!(iwl3945_is_associated(priv))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6612 | |
| 6613 | /* RXON - unassoc (to set timing command) */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6614 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6615 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6616 | |
| 6617 | /* RXON Timing */ |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6618 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6619 | iwl3945_setup_rxon_timing(priv); |
| 6620 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6621 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 6622 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6623 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6624 | "Attempting to continue.\n"); |
| 6625 | |
| 6626 | /* FIXME: what should be the assoc_id for AP? */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6627 | priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6628 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6629 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6630 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6631 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6632 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6633 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6634 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6635 | if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6636 | if (priv->assoc_capability & |
| 6637 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6638 | priv->staging39_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6639 | RXON_FLG_SHORT_SLOT_MSK; |
| 6640 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6641 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6642 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6643 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6644 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6645 | priv->staging39_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6646 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6647 | } |
| 6648 | /* restore RXON assoc */ |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6649 | priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6650 | iwl3945_commit_rxon(priv); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 6651 | iwl3945_add_station(priv, iwl_bcast_addr, 0, 0); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 6652 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6653 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6654 | |
| 6655 | /* FIXME - we need to add code here to detect a totally new |
| 6656 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 6657 | * clear sta table, add BCAST sta... */ |
| 6658 | } |
| 6659 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6660 | static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, |
| 6661 | struct ieee80211_vif *vif, |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6662 | struct ieee80211_if_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6663 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6664 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6665 | int rc; |
| 6666 | |
| 6667 | if (conf == NULL) |
| 6668 | return -EIO; |
| 6669 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6670 | if (priv->vif != vif) { |
| 6671 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6672 | return 0; |
| 6673 | } |
| 6674 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6675 | /* handle this temporarily here */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6676 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6677 | conf->changed & IEEE80211_IFCC_BEACON) { |
| 6678 | struct sk_buff *beacon = ieee80211_beacon_get(hw, vif); |
| 6679 | if (!beacon) |
| 6680 | return -ENOMEM; |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6681 | mutex_lock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6682 | rc = iwl3945_mac_beacon_update(hw, beacon); |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 6683 | mutex_unlock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6684 | if (rc) |
| 6685 | return rc; |
| 6686 | } |
| 6687 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6688 | if (!iwl3945_is_alive(priv)) |
| 6689 | return -EAGAIN; |
| 6690 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6691 | mutex_lock(&priv->mutex); |
| 6692 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6693 | if (conf->bssid) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6694 | IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6695 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6696 | /* |
| 6697 | * very dubious code was here; the probe filtering flag is never set: |
| 6698 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6699 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 6700 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6701 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6702 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6703 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6704 | if (!conf->bssid) { |
| 6705 | conf->bssid = priv->mac_addr; |
| 6706 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6707 | IWL_DEBUG_MAC80211("bssid was set to: %pM\n", |
| 6708 | conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6709 | } |
| 6710 | if (priv->ibss_beacon) |
| 6711 | dev_kfree_skb(priv->ibss_beacon); |
| 6712 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 6713 | priv->ibss_beacon = ieee80211_beacon_get(hw, vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6714 | } |
| 6715 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6716 | if (iwl3945_is_rfkill(priv)) |
| 6717 | goto done; |
| 6718 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6719 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 6720 | !is_multicast_ether_addr(conf->bssid)) { |
| 6721 | /* If there is currently a HW scan going on in the background |
| 6722 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6723 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 6724 | IWL_WARN(priv, "Aborted scan still in progress " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6725 | "after 100ms\n"); |
| 6726 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 6727 | mutex_unlock(&priv->mutex); |
| 6728 | return -EAGAIN; |
| 6729 | } |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6730 | memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6731 | |
| 6732 | /* TODO: Audit driver for usage of these members and see |
| 6733 | * if mac80211 deprecates them (priv->bssid looks like it |
| 6734 | * shouldn't be there, but I haven't scanned the IBSS code |
| 6735 | * to verify) - jpk */ |
| 6736 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 6737 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6738 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6739 | iwl3945_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6740 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6741 | rc = iwl3945_commit_rxon(priv); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 6742 | if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6743 | iwl3945_add_station(priv, |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6744 | priv->active39_rxon.bssid_addr, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6745 | } |
| 6746 | |
| 6747 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6748 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6749 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6750 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6751 | } |
| 6752 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6753 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6754 | IWL_DEBUG_MAC80211("leave\n"); |
| 6755 | mutex_unlock(&priv->mutex); |
| 6756 | |
| 6757 | return 0; |
| 6758 | } |
| 6759 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6760 | static void iwl3945_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6761 | unsigned int changed_flags, |
| 6762 | unsigned int *total_flags, |
| 6763 | int mc_count, struct dev_addr_list *mc_list) |
| 6764 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6765 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6766 | __le32 *filter_flags = &priv->staging39_rxon.filter_flags; |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6767 | |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6768 | IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n", |
| 6769 | changed_flags, *total_flags); |
| 6770 | |
| 6771 | if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) { |
| 6772 | if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) |
| 6773 | *filter_flags |= RXON_FILTER_PROMISC_MSK; |
| 6774 | else |
| 6775 | *filter_flags &= ~RXON_FILTER_PROMISC_MSK; |
Abhijeet Kolekar | 5ec0397 | 2008-05-05 10:22:48 +0800 | [diff] [blame] | 6776 | } |
Zhu, Yi | 352bc8d | 2008-11-12 13:14:09 -0800 | [diff] [blame] | 6777 | if (changed_flags & FIF_ALLMULTI) { |
| 6778 | if (*total_flags & FIF_ALLMULTI) |
| 6779 | *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK; |
| 6780 | else |
| 6781 | *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK; |
| 6782 | } |
| 6783 | if (changed_flags & FIF_CONTROL) { |
| 6784 | if (*total_flags & FIF_CONTROL) |
| 6785 | *filter_flags |= RXON_FILTER_CTL2HOST_MSK; |
| 6786 | else |
| 6787 | *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK; |
| 6788 | } |
| 6789 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 6790 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
| 6791 | *filter_flags |= RXON_FILTER_BCON_AWARE_MSK; |
| 6792 | else |
| 6793 | *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK; |
| 6794 | } |
| 6795 | |
| 6796 | /* We avoid iwl_commit_rxon here to commit the new filter flags |
| 6797 | * since mac80211 will call ieee80211_hw_config immediately. |
| 6798 | * (mc_list is not supported at this time). Otherwise, we need to |
| 6799 | * queue a background iwl_commit_rxon work. |
| 6800 | */ |
| 6801 | |
| 6802 | *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | |
Rick Farrington | 25b3f57 | 2008-06-30 17:23:28 +0800 | [diff] [blame] | 6803 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6804 | } |
| 6805 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6806 | static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6807 | struct ieee80211_if_init_conf *conf) |
| 6808 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6809 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6810 | |
| 6811 | IWL_DEBUG_MAC80211("enter\n"); |
| 6812 | |
| 6813 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6814 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6815 | if (iwl3945_is_ready_rf(priv)) { |
| 6816 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6817 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6818 | iwl3945_commit_rxon(priv); |
| 6819 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6820 | if (priv->vif == conf->vif) { |
| 6821 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6822 | memset(priv->bssid, 0, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6823 | } |
| 6824 | mutex_unlock(&priv->mutex); |
| 6825 | |
| 6826 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6827 | } |
| 6828 | |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6829 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
| 6830 | |
| 6831 | static void iwl3945_bss_info_changed(struct ieee80211_hw *hw, |
| 6832 | struct ieee80211_vif *vif, |
| 6833 | struct ieee80211_bss_conf *bss_conf, |
| 6834 | u32 changes) |
| 6835 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6836 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6837 | |
| 6838 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 6839 | |
| 6840 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 6841 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 6842 | bss_conf->use_short_preamble); |
| 6843 | if (bss_conf->use_short_preamble) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6844 | priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6845 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6846 | priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6847 | } |
| 6848 | |
| 6849 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
| 6850 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
| 6851 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6852 | priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6853 | else |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 6854 | priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6855 | } |
| 6856 | |
| 6857 | if (changes & BSS_CHANGED_ASSOC) { |
| 6858 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
| 6859 | /* This should never happen as this function should |
| 6860 | * never be called from interrupt context. */ |
| 6861 | if (WARN_ON_ONCE(in_interrupt())) |
| 6862 | return; |
| 6863 | if (bss_conf->assoc) { |
| 6864 | priv->assoc_id = bss_conf->aid; |
| 6865 | priv->beacon_int = bss_conf->beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 6866 | priv->timestamp = bss_conf->timestamp; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 6867 | priv->assoc_capability = bss_conf->assoc_capability; |
| 6868 | priv->next_scan_jiffies = jiffies + |
| 6869 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
| 6870 | mutex_lock(&priv->mutex); |
| 6871 | iwl3945_post_associate(priv); |
| 6872 | mutex_unlock(&priv->mutex); |
| 6873 | } else { |
| 6874 | priv->assoc_id = 0; |
| 6875 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 6876 | } |
| 6877 | } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) { |
| 6878 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
| 6879 | iwl3945_send_rxon_assoc(priv); |
| 6880 | } |
| 6881 | |
| 6882 | } |
| 6883 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6884 | 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] | 6885 | { |
| 6886 | int rc = 0; |
| 6887 | unsigned long flags; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6888 | struct iwl_priv *priv = hw->priv; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6889 | DECLARE_SSID_BUF(ssid_buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6890 | |
| 6891 | IWL_DEBUG_MAC80211("enter\n"); |
| 6892 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6893 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6894 | spin_lock_irqsave(&priv->lock, flags); |
| 6895 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6896 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6897 | rc = -EIO; |
| 6898 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 6899 | goto out_unlock; |
| 6900 | } |
| 6901 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6902 | /* we don't schedule scan within next_scan_jiffies period */ |
| 6903 | if (priv->next_scan_jiffies && |
| 6904 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 6905 | rc = -EAGAIN; |
| 6906 | goto out_unlock; |
| 6907 | } |
Bill Moss | 15dbf1b | 2008-05-06 11:05:15 +0800 | [diff] [blame] | 6908 | /* if we just finished scan ask for delay for a broadcast scan */ |
| 6909 | if ((len == 0) && priv->last_scan_jiffies && |
| 6910 | time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, |
| 6911 | jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6912 | rc = -EAGAIN; |
| 6913 | goto out_unlock; |
| 6914 | } |
| 6915 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6916 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 6917 | print_ssid(ssid_buf, ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6918 | |
| 6919 | priv->one_direct_scan = 1; |
| 6920 | priv->direct_ssid_len = (u8) |
| 6921 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 6922 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6923 | } else |
| 6924 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6925 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6926 | rc = iwl3945_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6927 | |
| 6928 | IWL_DEBUG_MAC80211("leave\n"); |
| 6929 | |
| 6930 | out_unlock: |
| 6931 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6932 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6933 | |
| 6934 | return rc; |
| 6935 | } |
| 6936 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6937 | 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] | 6938 | const u8 *local_addr, const u8 *addr, |
| 6939 | struct ieee80211_key_conf *key) |
| 6940 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6941 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6942 | int rc = 0; |
| 6943 | u8 sta_id; |
| 6944 | |
| 6945 | IWL_DEBUG_MAC80211("enter\n"); |
| 6946 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6947 | if (!iwl3945_param_hwcrypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6948 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 6949 | return -EOPNOTSUPP; |
| 6950 | } |
| 6951 | |
| 6952 | if (is_zero_ether_addr(addr)) |
| 6953 | /* only support pairwise keys */ |
| 6954 | return -EOPNOTSUPP; |
| 6955 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6956 | sta_id = iwl3945_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6957 | if (sta_id == IWL_INVALID_STATION) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 6958 | IWL_DEBUG_MAC80211("leave - %pM not in station map.\n", |
| 6959 | addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6960 | return -EINVAL; |
| 6961 | } |
| 6962 | |
| 6963 | mutex_lock(&priv->mutex); |
| 6964 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6965 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6966 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6967 | switch (cmd) { |
| 6968 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6969 | rc = iwl3945_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6970 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6971 | iwl3945_set_rxon_hwcrypto(priv, 1); |
| 6972 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6973 | key->hw_key_idx = sta_id; |
| 6974 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 6975 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 6976 | } |
| 6977 | break; |
| 6978 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6979 | rc = iwl3945_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6980 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6981 | iwl3945_set_rxon_hwcrypto(priv, 0); |
| 6982 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6983 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 6984 | } |
| 6985 | break; |
| 6986 | default: |
| 6987 | rc = -EINVAL; |
| 6988 | } |
| 6989 | |
| 6990 | IWL_DEBUG_MAC80211("leave\n"); |
| 6991 | mutex_unlock(&priv->mutex); |
| 6992 | |
| 6993 | return rc; |
| 6994 | } |
| 6995 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 6996 | static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6997 | const struct ieee80211_tx_queue_params *params) |
| 6998 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 6999 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7000 | unsigned long flags; |
| 7001 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7002 | |
| 7003 | IWL_DEBUG_MAC80211("enter\n"); |
| 7004 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7005 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7006 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7007 | return -EIO; |
| 7008 | } |
| 7009 | |
| 7010 | if (queue >= AC_NUM) { |
| 7011 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 7012 | return 0; |
| 7013 | } |
| 7014 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7015 | q = AC_NUM - 1 - queue; |
| 7016 | |
| 7017 | spin_lock_irqsave(&priv->lock, flags); |
| 7018 | |
| 7019 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 7020 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 7021 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 7022 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 7023 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7024 | |
| 7025 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 7026 | priv->qos_data.qos_active = 1; |
| 7027 | |
| 7028 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7029 | |
| 7030 | mutex_lock(&priv->mutex); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 7031 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7032 | iwl3945_activate_qos(priv, 1); |
| 7033 | else if (priv->assoc_id && iwl3945_is_associated(priv)) |
| 7034 | iwl3945_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7035 | |
| 7036 | mutex_unlock(&priv->mutex); |
| 7037 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7038 | IWL_DEBUG_MAC80211("leave\n"); |
| 7039 | return 0; |
| 7040 | } |
| 7041 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7042 | static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7043 | struct ieee80211_tx_queue_stats *stats) |
| 7044 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7045 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7046 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7047 | struct iwl3945_tx_queue *txq; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 7048 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7049 | unsigned long flags; |
| 7050 | |
| 7051 | IWL_DEBUG_MAC80211("enter\n"); |
| 7052 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7053 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7054 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7055 | return -EIO; |
| 7056 | } |
| 7057 | |
| 7058 | spin_lock_irqsave(&priv->lock, flags); |
| 7059 | |
| 7060 | for (i = 0; i < AC_NUM; i++) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7061 | txq = &priv->txq39[i]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7062 | q = &txq->q; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 7063 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7064 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 7065 | stats[i].len = q->n_window - avail; |
| 7066 | stats[i].limit = q->n_window - q->high_mark; |
| 7067 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7068 | |
| 7069 | } |
| 7070 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7071 | |
| 7072 | IWL_DEBUG_MAC80211("leave\n"); |
| 7073 | |
| 7074 | return 0; |
| 7075 | } |
| 7076 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7077 | static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7078 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7079 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7080 | unsigned long flags; |
| 7081 | |
| 7082 | mutex_lock(&priv->mutex); |
| 7083 | IWL_DEBUG_MAC80211("enter\n"); |
| 7084 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7085 | iwl3945_reset_qos(priv); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 7086 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7087 | spin_lock_irqsave(&priv->lock, flags); |
| 7088 | priv->assoc_id = 0; |
| 7089 | priv->assoc_capability = 0; |
| 7090 | priv->call_post_assoc_from_beacon = 0; |
| 7091 | |
| 7092 | /* new association get rid of ibss beacon skb */ |
| 7093 | if (priv->ibss_beacon) |
| 7094 | dev_kfree_skb(priv->ibss_beacon); |
| 7095 | |
| 7096 | priv->ibss_beacon = NULL; |
| 7097 | |
| 7098 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 7099 | priv->timestamp = 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 7100 | if ((priv->iw_mode == NL80211_IFTYPE_STATION)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7101 | priv->beacon_int = 0; |
| 7102 | |
| 7103 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7104 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7105 | if (!iwl3945_is_ready_rf(priv)) { |
| 7106 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 7107 | mutex_unlock(&priv->mutex); |
| 7108 | return; |
| 7109 | } |
| 7110 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7111 | /* we are restarting association process |
| 7112 | * clear RXON_FILTER_ASSOC_MSK bit |
| 7113 | */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 7114 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7115 | iwl3945_scan_cancel_timeout(priv, 100); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7116 | priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7117 | iwl3945_commit_rxon(priv); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7118 | } |
| 7119 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7120 | /* Per mac80211.h: This is only used in IBSS mode... */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 7121 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7122 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7123 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 7124 | mutex_unlock(&priv->mutex); |
| 7125 | return; |
| 7126 | } |
| 7127 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7128 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7129 | |
| 7130 | mutex_unlock(&priv->mutex); |
| 7131 | |
| 7132 | IWL_DEBUG_MAC80211("leave\n"); |
| 7133 | |
| 7134 | } |
| 7135 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 7136 | 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] | 7137 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7138 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7139 | unsigned long flags; |
| 7140 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7141 | IWL_DEBUG_MAC80211("enter\n"); |
| 7142 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7143 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7144 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7145 | return -EIO; |
| 7146 | } |
| 7147 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 7148 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7149 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7150 | return -EIO; |
| 7151 | } |
| 7152 | |
| 7153 | spin_lock_irqsave(&priv->lock, flags); |
| 7154 | |
| 7155 | if (priv->ibss_beacon) |
| 7156 | dev_kfree_skb(priv->ibss_beacon); |
| 7157 | |
| 7158 | priv->ibss_beacon = skb; |
| 7159 | |
| 7160 | priv->assoc_id = 0; |
| 7161 | |
| 7162 | IWL_DEBUG_MAC80211("leave\n"); |
| 7163 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7164 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7165 | iwl3945_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7166 | |
Abhijeet Kolekar | dc4b1e7 | 2008-09-03 11:26:30 +0800 | [diff] [blame] | 7167 | iwl3945_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7168 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7169 | |
| 7170 | return 0; |
| 7171 | } |
| 7172 | |
| 7173 | /***************************************************************************** |
| 7174 | * |
| 7175 | * sysfs attributes |
| 7176 | * |
| 7177 | *****************************************************************************/ |
| 7178 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7179 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7180 | |
| 7181 | /* |
| 7182 | * The following adds a new attribute to the sysfs representation |
| 7183 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 7184 | * used for controlling the debug level. |
| 7185 | * |
| 7186 | * See the level definitions in iwl for details. |
| 7187 | */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7188 | static ssize_t show_debug_level(struct device *d, |
| 7189 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7190 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7191 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7192 | |
| 7193 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7194 | } |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7195 | static ssize_t store_debug_level(struct device *d, |
| 7196 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7197 | const char *buf, size_t count) |
| 7198 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7199 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7200 | unsigned long val; |
| 7201 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7202 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7203 | ret = strict_strtoul(buf, 0, &val); |
| 7204 | if (ret) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7205 | 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] | 7206 | else |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7207 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7208 | |
| 7209 | return strnlen(buf, count); |
| 7210 | } |
| 7211 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7212 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 7213 | show_debug_level, store_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7214 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7215 | #endif /* CONFIG_IWL3945_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7216 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7217 | static ssize_t show_temperature(struct device *d, |
| 7218 | struct device_attribute *attr, char *buf) |
| 7219 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7220 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7221 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7222 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7223 | return -EAGAIN; |
| 7224 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7225 | return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7226 | } |
| 7227 | |
| 7228 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 7229 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7230 | static ssize_t show_tx_power(struct device *d, |
| 7231 | struct device_attribute *attr, char *buf) |
| 7232 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7233 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7234 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 7235 | } |
| 7236 | |
| 7237 | static ssize_t store_tx_power(struct device *d, |
| 7238 | struct device_attribute *attr, |
| 7239 | const char *buf, size_t count) |
| 7240 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7241 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7242 | char *p = (char *)buf; |
| 7243 | u32 val; |
| 7244 | |
| 7245 | val = simple_strtoul(p, &p, 10); |
| 7246 | if (p == buf) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7247 | IWL_INFO(priv, ": %s is not in decimal form.\n", buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7248 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7249 | iwl3945_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7250 | |
| 7251 | return count; |
| 7252 | } |
| 7253 | |
| 7254 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 7255 | |
| 7256 | static ssize_t show_flags(struct device *d, |
| 7257 | struct device_attribute *attr, char *buf) |
| 7258 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7259 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7260 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7261 | return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7262 | } |
| 7263 | |
| 7264 | static ssize_t store_flags(struct device *d, |
| 7265 | struct device_attribute *attr, |
| 7266 | const char *buf, size_t count) |
| 7267 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7268 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7269 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 7270 | |
| 7271 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7272 | if (le32_to_cpu(priv->staging39_rxon.flags) != flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7273 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7274 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 7275 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7276 | else { |
| 7277 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 7278 | flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7279 | priv->staging39_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7280 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7281 | } |
| 7282 | } |
| 7283 | mutex_unlock(&priv->mutex); |
| 7284 | |
| 7285 | return count; |
| 7286 | } |
| 7287 | |
| 7288 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 7289 | |
| 7290 | static ssize_t show_filter_flags(struct device *d, |
| 7291 | struct device_attribute *attr, char *buf) |
| 7292 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7293 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7294 | |
| 7295 | return sprintf(buf, "0x%04X\n", |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7296 | le32_to_cpu(priv->active39_rxon.filter_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7297 | } |
| 7298 | |
| 7299 | static ssize_t store_filter_flags(struct device *d, |
| 7300 | struct device_attribute *attr, |
| 7301 | const char *buf, size_t count) |
| 7302 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7303 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7304 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 7305 | |
| 7306 | mutex_lock(&priv->mutex); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7307 | if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7308 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7309 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 7310 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7311 | else { |
| 7312 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 7313 | "0x%04X\n", filter_flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7314 | priv->staging39_rxon.filter_flags = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7315 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7316 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7317 | } |
| 7318 | } |
| 7319 | mutex_unlock(&priv->mutex); |
| 7320 | |
| 7321 | return count; |
| 7322 | } |
| 7323 | |
| 7324 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 7325 | store_filter_flags); |
| 7326 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7327 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7328 | |
| 7329 | static ssize_t show_measurement(struct device *d, |
| 7330 | struct device_attribute *attr, char *buf) |
| 7331 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7332 | struct iwl_priv *priv = dev_get_drvdata(d); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 7333 | struct iwl_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7334 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7335 | u8 *data = (u8 *)&measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7336 | unsigned long flags; |
| 7337 | |
| 7338 | spin_lock_irqsave(&priv->lock, flags); |
| 7339 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 7340 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7341 | return 0; |
| 7342 | } |
| 7343 | memcpy(&measure_report, &priv->measure_report, size); |
| 7344 | priv->measurement_status = 0; |
| 7345 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7346 | |
| 7347 | while (size && (PAGE_SIZE - len)) { |
| 7348 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7349 | PAGE_SIZE - len, 1); |
| 7350 | len = strlen(buf); |
| 7351 | if (PAGE_SIZE - len) |
| 7352 | buf[len++] = '\n'; |
| 7353 | |
| 7354 | ofs += 16; |
| 7355 | size -= min(size, 16U); |
| 7356 | } |
| 7357 | |
| 7358 | return len; |
| 7359 | } |
| 7360 | |
| 7361 | static ssize_t store_measurement(struct device *d, |
| 7362 | struct device_attribute *attr, |
| 7363 | const char *buf, size_t count) |
| 7364 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7365 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7366 | struct ieee80211_measurement_params params = { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7367 | .channel = le16_to_cpu(priv->active39_rxon.channel), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7368 | .start_time = cpu_to_le64(priv->last_tsf), |
| 7369 | .duration = cpu_to_le16(1), |
| 7370 | }; |
| 7371 | u8 type = IWL_MEASURE_BASIC; |
| 7372 | u8 buffer[32]; |
| 7373 | u8 channel; |
| 7374 | |
| 7375 | if (count) { |
| 7376 | char *p = buffer; |
| 7377 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 7378 | channel = simple_strtoul(p, NULL, 0); |
| 7379 | if (channel) |
| 7380 | params.channel = channel; |
| 7381 | |
| 7382 | p = buffer; |
| 7383 | while (*p && *p != ' ') |
| 7384 | p++; |
| 7385 | if (*p) |
| 7386 | type = simple_strtoul(p + 1, NULL, 0); |
| 7387 | } |
| 7388 | |
| 7389 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 7390 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7391 | iwl3945_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7392 | |
| 7393 | return count; |
| 7394 | } |
| 7395 | |
| 7396 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 7397 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7398 | #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7399 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7400 | static ssize_t store_retry_rate(struct device *d, |
| 7401 | struct device_attribute *attr, |
| 7402 | const char *buf, size_t count) |
| 7403 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7404 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7405 | |
| 7406 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 7407 | if (priv->retry_rate <= 0) |
| 7408 | priv->retry_rate = 1; |
| 7409 | |
| 7410 | return count; |
| 7411 | } |
| 7412 | |
| 7413 | static ssize_t show_retry_rate(struct device *d, |
| 7414 | struct device_attribute *attr, char *buf) |
| 7415 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7416 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7417 | return sprintf(buf, "%d", priv->retry_rate); |
| 7418 | } |
| 7419 | |
| 7420 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 7421 | store_retry_rate); |
| 7422 | |
| 7423 | static ssize_t store_power_level(struct device *d, |
| 7424 | struct device_attribute *attr, |
| 7425 | const char *buf, size_t count) |
| 7426 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7427 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7428 | int rc; |
| 7429 | int mode; |
| 7430 | |
| 7431 | mode = simple_strtoul(buf, NULL, 0); |
| 7432 | mutex_lock(&priv->mutex); |
| 7433 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7434 | if (!iwl3945_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7435 | rc = -EAGAIN; |
| 7436 | goto out; |
| 7437 | } |
| 7438 | |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7439 | if ((mode < 1) || (mode > IWL39_POWER_LIMIT) || |
| 7440 | (mode == IWL39_POWER_AC)) |
| 7441 | mode = IWL39_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7442 | else |
| 7443 | mode |= IWL_POWER_ENABLED; |
| 7444 | |
| 7445 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7446 | rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7447 | if (rc) { |
| 7448 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 7449 | goto out; |
| 7450 | } |
| 7451 | priv->power_mode = mode; |
| 7452 | } |
| 7453 | |
| 7454 | rc = count; |
| 7455 | |
| 7456 | out: |
| 7457 | mutex_unlock(&priv->mutex); |
| 7458 | return rc; |
| 7459 | } |
| 7460 | |
| 7461 | #define MAX_WX_STRING 80 |
| 7462 | |
| 7463 | /* Values are in microsecond */ |
| 7464 | static const s32 timeout_duration[] = { |
| 7465 | 350000, |
| 7466 | 250000, |
| 7467 | 75000, |
| 7468 | 37000, |
| 7469 | 25000, |
| 7470 | }; |
| 7471 | static const s32 period_duration[] = { |
| 7472 | 400000, |
| 7473 | 700000, |
| 7474 | 1000000, |
| 7475 | 1000000, |
| 7476 | 1000000 |
| 7477 | }; |
| 7478 | |
| 7479 | static ssize_t show_power_level(struct device *d, |
| 7480 | struct device_attribute *attr, char *buf) |
| 7481 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7482 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7483 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 7484 | char *p = buf; |
| 7485 | |
| 7486 | p += sprintf(p, "%d ", level); |
| 7487 | switch (level) { |
| 7488 | case IWL_POWER_MODE_CAM: |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7489 | case IWL39_POWER_AC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7490 | p += sprintf(p, "(AC)"); |
| 7491 | break; |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7492 | case IWL39_POWER_BATTERY: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7493 | p += sprintf(p, "(BATTERY)"); |
| 7494 | break; |
| 7495 | default: |
| 7496 | p += sprintf(p, |
| 7497 | "(Timeout %dms, Period %dms)", |
| 7498 | timeout_duration[level - 1] / 1000, |
| 7499 | period_duration[level - 1] / 1000); |
| 7500 | } |
| 7501 | |
| 7502 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 7503 | p += sprintf(p, " OFF\n"); |
| 7504 | else |
| 7505 | p += sprintf(p, " \n"); |
| 7506 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7507 | return p - buf + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7508 | |
| 7509 | } |
| 7510 | |
| 7511 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 7512 | store_power_level); |
| 7513 | |
| 7514 | static ssize_t show_channels(struct device *d, |
| 7515 | struct device_attribute *attr, char *buf) |
| 7516 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7517 | /* all this shit doesn't belong into sysfs anyway */ |
| 7518 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7519 | } |
| 7520 | |
| 7521 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 7522 | |
| 7523 | static ssize_t show_statistics(struct device *d, |
| 7524 | struct device_attribute *attr, char *buf) |
| 7525 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7526 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7527 | u32 size = sizeof(struct iwl3945_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7528 | u32 len = 0, ofs = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7529 | u8 *data = (u8 *)&priv->statistics_39; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7530 | int rc = 0; |
| 7531 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7532 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7533 | return -EAGAIN; |
| 7534 | |
| 7535 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7536 | rc = iwl3945_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7537 | mutex_unlock(&priv->mutex); |
| 7538 | |
| 7539 | if (rc) { |
| 7540 | len = sprintf(buf, |
| 7541 | "Error sending statistics request: 0x%08X\n", rc); |
| 7542 | return len; |
| 7543 | } |
| 7544 | |
| 7545 | while (size && (PAGE_SIZE - len)) { |
| 7546 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7547 | PAGE_SIZE - len, 1); |
| 7548 | len = strlen(buf); |
| 7549 | if (PAGE_SIZE - len) |
| 7550 | buf[len++] = '\n'; |
| 7551 | |
| 7552 | ofs += 16; |
| 7553 | size -= min(size, 16U); |
| 7554 | } |
| 7555 | |
| 7556 | return len; |
| 7557 | } |
| 7558 | |
| 7559 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 7560 | |
| 7561 | static ssize_t show_antenna(struct device *d, |
| 7562 | struct device_attribute *attr, char *buf) |
| 7563 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7564 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7565 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7566 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7567 | return -EAGAIN; |
| 7568 | |
| 7569 | return sprintf(buf, "%d\n", priv->antenna); |
| 7570 | } |
| 7571 | |
| 7572 | static ssize_t store_antenna(struct device *d, |
| 7573 | struct device_attribute *attr, |
| 7574 | const char *buf, size_t count) |
| 7575 | { |
| 7576 | int ant; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7577 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7578 | |
| 7579 | if (count == 0) |
| 7580 | return 0; |
| 7581 | |
| 7582 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 7583 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 7584 | return count; |
| 7585 | } |
| 7586 | |
| 7587 | if ((ant >= 0) && (ant <= 2)) { |
| 7588 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7589 | priv->antenna = (enum iwl3945_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7590 | } else |
| 7591 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 7592 | |
| 7593 | |
| 7594 | return count; |
| 7595 | } |
| 7596 | |
| 7597 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 7598 | |
| 7599 | static ssize_t show_status(struct device *d, |
| 7600 | struct device_attribute *attr, char *buf) |
| 7601 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7602 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7603 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7604 | return -EAGAIN; |
| 7605 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 7606 | } |
| 7607 | |
| 7608 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 7609 | |
| 7610 | static ssize_t dump_error_log(struct device *d, |
| 7611 | struct device_attribute *attr, |
| 7612 | const char *buf, size_t count) |
| 7613 | { |
| 7614 | char *p = (char *)buf; |
| 7615 | |
| 7616 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7617 | iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7618 | |
| 7619 | return strnlen(buf, count); |
| 7620 | } |
| 7621 | |
| 7622 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 7623 | |
| 7624 | static ssize_t dump_event_log(struct device *d, |
| 7625 | struct device_attribute *attr, |
| 7626 | const char *buf, size_t count) |
| 7627 | { |
| 7628 | char *p = (char *)buf; |
| 7629 | |
| 7630 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7631 | iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7632 | |
| 7633 | return strnlen(buf, count); |
| 7634 | } |
| 7635 | |
| 7636 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 7637 | |
| 7638 | /***************************************************************************** |
| 7639 | * |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 7640 | * driver setup and tear down |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7641 | * |
| 7642 | *****************************************************************************/ |
| 7643 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7644 | static void iwl3945_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7645 | { |
| 7646 | priv->workqueue = create_workqueue(DRV_NAME); |
| 7647 | |
| 7648 | init_waitqueue_head(&priv->wait_command_queue); |
| 7649 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7650 | INIT_WORK(&priv->up, iwl3945_bg_up); |
| 7651 | INIT_WORK(&priv->restart, iwl3945_bg_restart); |
| 7652 | INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); |
| 7653 | INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed); |
| 7654 | INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan); |
| 7655 | INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan); |
| 7656 | INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill); |
| 7657 | INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7658 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); |
| 7659 | INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); |
| 7660 | INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7661 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7662 | iwl3945_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7663 | |
| 7664 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7665 | iwl3945_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7666 | } |
| 7667 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7668 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7669 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7670 | iwl3945_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7671 | |
Joonwoo Park | e47eb6a | 2007-11-29 10:42:49 +0900 | [diff] [blame] | 7672 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7673 | cancel_delayed_work(&priv->scan_check); |
| 7674 | cancel_delayed_work(&priv->alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7675 | cancel_work_sync(&priv->beacon_update); |
| 7676 | } |
| 7677 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7678 | static struct attribute *iwl3945_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7679 | &dev_attr_antenna.attr, |
| 7680 | &dev_attr_channels.attr, |
| 7681 | &dev_attr_dump_errors.attr, |
| 7682 | &dev_attr_dump_events.attr, |
| 7683 | &dev_attr_flags.attr, |
| 7684 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7685 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7686 | &dev_attr_measurement.attr, |
| 7687 | #endif |
| 7688 | &dev_attr_power_level.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7689 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7690 | &dev_attr_statistics.attr, |
| 7691 | &dev_attr_status.attr, |
| 7692 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7693 | &dev_attr_tx_power.attr, |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7694 | #ifdef CONFIG_IWL3945_DEBUG |
| 7695 | &dev_attr_debug_level.attr, |
| 7696 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7697 | NULL |
| 7698 | }; |
| 7699 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7700 | static struct attribute_group iwl3945_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7701 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7702 | .attrs = iwl3945_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7703 | }; |
| 7704 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7705 | static struct ieee80211_ops iwl3945_hw_ops = { |
| 7706 | .tx = iwl3945_mac_tx, |
| 7707 | .start = iwl3945_mac_start, |
| 7708 | .stop = iwl3945_mac_stop, |
| 7709 | .add_interface = iwl3945_mac_add_interface, |
| 7710 | .remove_interface = iwl3945_mac_remove_interface, |
| 7711 | .config = iwl3945_mac_config, |
| 7712 | .config_interface = iwl3945_mac_config_interface, |
| 7713 | .configure_filter = iwl3945_configure_filter, |
| 7714 | .set_key = iwl3945_mac_set_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7715 | .get_tx_stats = iwl3945_mac_get_tx_stats, |
| 7716 | .conf_tx = iwl3945_mac_conf_tx, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7717 | .reset_tsf = iwl3945_mac_reset_tsf, |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 7718 | .bss_info_changed = iwl3945_bss_info_changed, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7719 | .hw_scan = iwl3945_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7720 | }; |
| 7721 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7722 | 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] | 7723 | { |
| 7724 | int err = 0; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7725 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7726 | struct ieee80211_hw *hw; |
Kolekar, Abhijeet | c0f20d9 | 2008-12-19 10:37:19 +0800 | [diff] [blame] | 7727 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7728 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7729 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7730 | /*********************** |
| 7731 | * 1. Allocating HW data |
| 7732 | * ********************/ |
| 7733 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7734 | /* mac80211 allocates memory for this device instance, including |
| 7735 | * space for this driver's private structure */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 7736 | hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwl3945_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7737 | if (hw == NULL) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7738 | printk(KERN_ERR DRV_NAME "Can not allocate network device\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7739 | err = -ENOMEM; |
| 7740 | goto out; |
| 7741 | } |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7742 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7743 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 7744 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7745 | priv = hw->priv; |
| 7746 | priv->hw = hw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7747 | priv->pci_dev = pdev; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 7748 | priv->cfg = cfg; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7749 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7750 | if ((iwl3945_param_queues_num > IWL39_MAX_NUM_QUEUES) || |
| 7751 | (iwl3945_param_queues_num < IWL_MIN_NUM_QUEUES)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7752 | IWL_ERR(priv, |
| 7753 | "invalid queues_num, should be between %d and %d\n", |
| 7754 | IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES); |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 7755 | err = -EINVAL; |
| 7756 | goto out; |
| 7757 | } |
| 7758 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7759 | /* Disabling hardware scan means that mac80211 will perform scans |
| 7760 | * "the hard way", rather than using device's scan. */ |
| 7761 | if (iwl3945_param_disable_hw_scan) { |
| 7762 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
| 7763 | iwl3945_hw_ops.hw_scan = NULL; |
| 7764 | } |
| 7765 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7766 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 7767 | hw->rate_control_algorithm = "iwl-3945-rs"; |
| 7768 | hw->sta_data_size = sizeof(struct iwl3945_sta_priv); |
| 7769 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7770 | /* Select antenna (may be helpful if only one antenna is connected) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7771 | priv->antenna = (enum iwl3945_antenna)iwl3945_param_antenna; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7772 | #ifdef CONFIG_IWL3945_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 7773 | priv->debug_level = iwl3945_param_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7774 | atomic_set(&priv->restrict_refcnt, 0); |
| 7775 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7776 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7777 | /* Tell mac80211 our characteristics */ |
Johannes Berg | 605a0bd | 2008-07-15 10:10:01 +0200 | [diff] [blame] | 7778 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 7779 | IEEE80211_HW_NOISE_DBM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7780 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7781 | hw->wiphy->interface_modes = |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 7782 | BIT(NL80211_IFTYPE_STATION) | |
| 7783 | BIT(NL80211_IFTYPE_ADHOC); |
| 7784 | |
Luis R. Rodriguez | ea4a82dc | 2008-11-12 14:22:04 -0800 | [diff] [blame] | 7785 | hw->wiphy->fw_handles_regulatory = true; |
| 7786 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7787 | /* 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7788 | hw->queues = 4; |
| 7789 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7790 | /*************************** |
| 7791 | * 2. Initializing PCI bus |
| 7792 | * *************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7793 | if (pci_enable_device(pdev)) { |
| 7794 | err = -ENODEV; |
| 7795 | goto out_ieee80211_free_hw; |
| 7796 | } |
| 7797 | |
| 7798 | pci_set_master(pdev); |
| 7799 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7800 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 7801 | if (!err) |
| 7802 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 7803 | if (err) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7804 | IWL_WARN(priv, "No suitable DMA available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7805 | goto out_pci_disable_device; |
| 7806 | } |
| 7807 | |
| 7808 | pci_set_drvdata(pdev, priv); |
| 7809 | err = pci_request_regions(pdev, DRV_NAME); |
| 7810 | if (err) |
| 7811 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7812 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7813 | /*********************** |
| 7814 | * 3. Read REV Register |
| 7815 | * ********************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7816 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 7817 | if (!priv->hw_base) { |
| 7818 | err = -ENODEV; |
| 7819 | goto out_pci_release_regions; |
| 7820 | } |
| 7821 | |
| 7822 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 7823 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 7824 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 7825 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7826 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 7827 | * PCI Tx retries from interfering with C3 CPU state */ |
| 7828 | pci_write_config_byte(pdev, 0x41, 0x00); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7829 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7830 | /* nic init */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 7831 | iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7832 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7833 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 7834 | iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 7835 | err = iwl_poll_direct_bit(priv, CSR_GP_CNTRL, |
Zhu, Yi | 73d7b5a | 2008-12-05 07:58:40 -0800 | [diff] [blame] | 7836 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7837 | if (err < 0) { |
| 7838 | IWL_DEBUG_INFO("Failed to init the card\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7839 | goto out_remove_sysfs; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 7840 | } |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7841 | |
| 7842 | /*********************** |
| 7843 | * 4. Read EEPROM |
| 7844 | * ********************/ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7845 | /* Read the EEPROM */ |
| 7846 | err = iwl3945_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7847 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7848 | IWL_ERR(priv, "Unable to init EEPROM\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7849 | goto out_remove_sysfs; |
| 7850 | } |
| 7851 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 7852 | get_eeprom_mac(priv, priv->mac_addr); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 7853 | IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7854 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 7855 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7856 | /*********************** |
| 7857 | * 5. Setup HW Constants |
| 7858 | * ********************/ |
| 7859 | /* Device-specific setup */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7860 | if (iwl3945_hw_set_hw_params(priv)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7861 | IWL_ERR(priv, "failed to set hw settings\n"); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7862 | goto out_iounmap; |
| 7863 | } |
| 7864 | |
| 7865 | /*********************** |
| 7866 | * 6. Setup priv |
| 7867 | * ********************/ |
| 7868 | priv->retry_rate = 1; |
| 7869 | priv->ibss_beacon = NULL; |
| 7870 | |
| 7871 | spin_lock_init(&priv->lock); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 7872 | spin_lock_init(&priv->power_data_39.lock); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7873 | spin_lock_init(&priv->sta_lock); |
| 7874 | spin_lock_init(&priv->hcmd_lock); |
| 7875 | |
| 7876 | INIT_LIST_HEAD(&priv->free_frames); |
| 7877 | mutex_init(&priv->mutex); |
| 7878 | |
| 7879 | /* Clear the driver's (not device's) station table */ |
| 7880 | iwl3945_clear_stations_table(priv); |
| 7881 | |
| 7882 | priv->data_retry_limit = -1; |
| 7883 | priv->ieee_channels = NULL; |
| 7884 | priv->ieee_rates = NULL; |
| 7885 | priv->band = IEEE80211_BAND_2GHZ; |
| 7886 | |
| 7887 | priv->iw_mode = NL80211_IFTYPE_STATION; |
| 7888 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7889 | iwl3945_reset_qos(priv); |
| 7890 | |
| 7891 | priv->qos_data.qos_active = 0; |
| 7892 | priv->qos_data.qos_cap.val = 0; |
| 7893 | |
| 7894 | |
| 7895 | priv->rates_mask = IWL_RATES_MASK; |
| 7896 | /* If power management is turned on, default to AC mode */ |
Samuel Ortiz | 1125eff | 2008-12-19 10:37:14 +0800 | [diff] [blame] | 7897 | priv->power_mode = IWL39_POWER_AC; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7898 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 7899 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7900 | err = iwl3945_init_channel_map(priv); |
| 7901 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7902 | IWL_ERR(priv, "initializing regulatory failed: %d\n", err); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7903 | goto out_release_irq; |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7904 | } |
| 7905 | |
| 7906 | err = iwl3945_init_geos(priv); |
| 7907 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7908 | IWL_ERR(priv, "initializing geos failed: %d\n", err); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7909 | goto out_free_channel_map; |
| 7910 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7911 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 7912 | IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n", |
| 7913 | priv->cfg->name); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7914 | |
| 7915 | /*********************************** |
| 7916 | * 7. Initialize Module Parameters |
| 7917 | * **********************************/ |
| 7918 | |
| 7919 | /* Initialize module parameter values here */ |
| 7920 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
| 7921 | if (iwl3945_param_disable) { |
| 7922 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 7923 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 7924 | } |
| 7925 | |
| 7926 | |
| 7927 | /*********************** |
| 7928 | * 8. Setup Services |
| 7929 | * ********************/ |
| 7930 | |
| 7931 | spin_lock_irqsave(&priv->lock, flags); |
| 7932 | iwl3945_disable_interrupts(priv); |
| 7933 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7934 | |
| 7935 | err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
| 7936 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7937 | IWL_ERR(priv, "failed to create sysfs device attributes\n"); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7938 | goto out_free_geos; |
| 7939 | } |
| 7940 | |
| 7941 | iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
| 7942 | iwl3945_setup_deferred_work(priv); |
| 7943 | iwl3945_setup_rx_handlers(priv); |
| 7944 | |
| 7945 | /*********************** |
| 7946 | * 9. Conclude |
| 7947 | * ********************/ |
| 7948 | pci_save_state(pdev); |
| 7949 | pci_disable_device(pdev); |
| 7950 | |
| 7951 | /********************************* |
| 7952 | * 10. Setup and Register mac80211 |
| 7953 | * *******************************/ |
| 7954 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7955 | err = ieee80211_register_hw(priv->hw); |
| 7956 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7957 | IWL_ERR(priv, "Failed to register network device: %d\n", err); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7958 | goto out_remove_sysfs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7959 | } |
| 7960 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7961 | priv->hw->conf.beacon_int = 100; |
| 7962 | priv->mac80211_registered = 1; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7963 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7964 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7965 | err = iwl3945_rfkill_init(priv); |
| 7966 | if (err) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 7967 | IWL_ERR(priv, "Unable to initialize RFKILL system. " |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 7968 | "Ignoring error: %d\n", err); |
| 7969 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7970 | return 0; |
| 7971 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7972 | out_remove_sysfs: |
| 7973 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7974 | out_free_geos: |
| 7975 | iwl3945_free_geos(priv); |
| 7976 | out_free_channel_map: |
| 7977 | iwl3945_free_channel_map(priv); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 7978 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7979 | |
| 7980 | out_release_irq: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7981 | destroy_workqueue(priv->workqueue); |
| 7982 | priv->workqueue = NULL; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 7983 | iwl3945_unset_hw_params(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7984 | |
| 7985 | out_iounmap: |
| 7986 | pci_iounmap(pdev, priv->hw_base); |
| 7987 | out_pci_release_regions: |
| 7988 | pci_release_regions(pdev); |
| 7989 | out_pci_disable_device: |
| 7990 | pci_disable_device(pdev); |
| 7991 | pci_set_drvdata(pdev, NULL); |
| 7992 | out_ieee80211_free_hw: |
| 7993 | ieee80211_free_hw(priv->hw); |
| 7994 | out: |
| 7995 | return err; |
| 7996 | } |
| 7997 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 7998 | static void __devexit iwl3945_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7999 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 8000 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 8001 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8002 | |
| 8003 | if (!priv) |
| 8004 | return; |
| 8005 | |
| 8006 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 8007 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8008 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 8009 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8010 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8011 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 8012 | /* make sure we flush any pending irq or |
| 8013 | * tasklet for the driver |
| 8014 | */ |
| 8015 | spin_lock_irqsave(&priv->lock, flags); |
| 8016 | iwl3945_disable_interrupts(priv); |
| 8017 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8018 | |
| 8019 | iwl_synchronize_irq(priv); |
| 8020 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8021 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8022 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8023 | iwl3945_rfkill_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8024 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8025 | |
| 8026 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8027 | iwl3945_rx_queue_free(priv, &priv->rxq); |
| 8028 | iwl3945_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8029 | |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 8030 | iwl3945_unset_hw_params(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8031 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8032 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 8033 | if (priv->mac80211_registered) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8034 | ieee80211_unregister_hw(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8035 | |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 8036 | /*netif_stop_queue(dev); */ |
| 8037 | flush_workqueue(priv->workqueue); |
| 8038 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8039 | /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8040 | * priv->workqueue... so we can't take down the workqueue |
| 8041 | * until now... */ |
| 8042 | destroy_workqueue(priv->workqueue); |
| 8043 | priv->workqueue = NULL; |
| 8044 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8045 | pci_iounmap(pdev, priv->hw_base); |
| 8046 | pci_release_regions(pdev); |
| 8047 | pci_disable_device(pdev); |
| 8048 | pci_set_drvdata(pdev, NULL); |
| 8049 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8050 | iwl3945_free_channel_map(priv); |
| 8051 | iwl3945_free_geos(priv); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 8052 | kfree(priv->scan39); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8053 | if (priv->ibss_beacon) |
| 8054 | dev_kfree_skb(priv->ibss_beacon); |
| 8055 | |
| 8056 | ieee80211_free_hw(priv->hw); |
| 8057 | } |
| 8058 | |
| 8059 | #ifdef CONFIG_PM |
| 8060 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8061 | 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] | 8062 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 8063 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8064 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8065 | if (priv->is_open) { |
| 8066 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 8067 | iwl3945_mac_stop(priv->hw); |
| 8068 | priv->is_open = 1; |
| 8069 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8070 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8071 | pci_set_power_state(pdev, PCI_D3hot); |
| 8072 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8073 | return 0; |
| 8074 | } |
| 8075 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8076 | static int iwl3945_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8077 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 8078 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8079 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8080 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8081 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8082 | if (priv->is_open) |
| 8083 | iwl3945_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8084 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8085 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8086 | return 0; |
| 8087 | } |
| 8088 | |
| 8089 | #endif /* CONFIG_PM */ |
| 8090 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8091 | /*************** RFKILL FUNCTIONS **********/ |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8092 | #ifdef CONFIG_IWL3945_RFKILL |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8093 | /* software rf-kill from user */ |
| 8094 | static int iwl3945_rfkill_soft_rf_kill(void *data, enum rfkill_state state) |
| 8095 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 8096 | struct iwl_priv *priv = data; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8097 | int err = 0; |
| 8098 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8099 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8100 | return 0; |
| 8101 | |
| 8102 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 8103 | return 0; |
| 8104 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 8105 | 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] | 8106 | mutex_lock(&priv->mutex); |
| 8107 | |
| 8108 | switch (state) { |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 8109 | case RFKILL_STATE_UNBLOCKED: |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8110 | if (iwl3945_is_rfkill_hw(priv)) { |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8111 | err = -EBUSY; |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8112 | goto out_unlock; |
| 8113 | } |
| 8114 | iwl3945_radio_kill_sw(priv, 0); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8115 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 8116 | case RFKILL_STATE_SOFT_BLOCKED: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8117 | iwl3945_radio_kill_sw(priv, 1); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8118 | break; |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 8119 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 8120 | IWL_WARN(priv, "received unexpected RFKILL state %d\n", state); |
Zhu Yi | acdfe9b | 2008-06-30 17:23:32 +0800 | [diff] [blame] | 8121 | break; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8122 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8123 | out_unlock: |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8124 | mutex_unlock(&priv->mutex); |
| 8125 | |
| 8126 | return err; |
| 8127 | } |
| 8128 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 8129 | int iwl3945_rfkill_init(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8130 | { |
| 8131 | struct device *device = wiphy_dev(priv->hw->wiphy); |
| 8132 | int ret = 0; |
| 8133 | |
| 8134 | BUG_ON(device == NULL); |
| 8135 | |
| 8136 | IWL_DEBUG_RF_KILL("Initializing RFKILL.\n"); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8137 | priv->rfkill = rfkill_allocate(device, RFKILL_TYPE_WLAN); |
| 8138 | if (!priv->rfkill) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 8139 | IWL_ERR(priv, "Unable to allocate rfkill device.\n"); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8140 | ret = -ENOMEM; |
| 8141 | goto error; |
| 8142 | } |
| 8143 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8144 | priv->rfkill->name = priv->cfg->name; |
| 8145 | priv->rfkill->data = priv; |
| 8146 | priv->rfkill->state = RFKILL_STATE_UNBLOCKED; |
| 8147 | priv->rfkill->toggle_radio = iwl3945_rfkill_soft_rf_kill; |
| 8148 | priv->rfkill->user_claim_unsupported = 1; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8149 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8150 | priv->rfkill->dev.class->suspend = NULL; |
| 8151 | priv->rfkill->dev.class->resume = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8152 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8153 | ret = rfkill_register(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8154 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 8155 | IWL_ERR(priv, "Unable to register rfkill: %d\n", ret); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8156 | goto freed_rfkill; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8157 | } |
| 8158 | |
| 8159 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 8160 | return ret; |
| 8161 | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8162 | freed_rfkill: |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8163 | if (priv->rfkill != NULL) |
| 8164 | rfkill_free(priv->rfkill); |
| 8165 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8166 | |
| 8167 | error: |
| 8168 | IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n"); |
| 8169 | return ret; |
| 8170 | } |
| 8171 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 8172 | void iwl3945_rfkill_unregister(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8173 | { |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8174 | if (priv->rfkill) |
| 8175 | rfkill_unregister(priv->rfkill); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8176 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8177 | priv->rfkill = NULL; |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8178 | } |
| 8179 | |
| 8180 | /* set rf-kill to the right state. */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 8181 | void iwl3945_rfkill_set_hw_state(struct iwl_priv *priv) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8182 | { |
| 8183 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8184 | if (!priv->rfkill) |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8185 | return; |
| 8186 | |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8187 | if (iwl3945_is_rfkill_hw(priv)) { |
| 8188 | rfkill_force_state(priv->rfkill, RFKILL_STATE_HARD_BLOCKED); |
| 8189 | return; |
| 8190 | } |
| 8191 | |
| 8192 | if (!iwl3945_is_rfkill_sw(priv)) |
| 8193 | rfkill_force_state(priv->rfkill, RFKILL_STATE_UNBLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8194 | else |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 8195 | rfkill_force_state(priv->rfkill, RFKILL_STATE_SOFT_BLOCKED); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 8196 | } |
| 8197 | #endif |
| 8198 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8199 | /***************************************************************************** |
| 8200 | * |
| 8201 | * driver and module entry point |
| 8202 | * |
| 8203 | *****************************************************************************/ |
| 8204 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8205 | static struct pci_driver iwl3945_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8206 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8207 | .id_table = iwl3945_hw_card_ids, |
| 8208 | .probe = iwl3945_pci_probe, |
| 8209 | .remove = __devexit_p(iwl3945_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8210 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8211 | .suspend = iwl3945_pci_suspend, |
| 8212 | .resume = iwl3945_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8213 | #endif |
| 8214 | }; |
| 8215 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8216 | static int __init iwl3945_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8217 | { |
| 8218 | |
| 8219 | int ret; |
| 8220 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 8221 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 8222 | |
| 8223 | ret = iwl3945_rate_control_register(); |
| 8224 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 8225 | printk(KERN_ERR DRV_NAME |
| 8226 | "Unable to register rate control algorithm: %d\n", ret); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 8227 | return ret; |
| 8228 | } |
| 8229 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8230 | ret = pci_register_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8231 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 8232 | printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 8233 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8234 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8235 | |
| 8236 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 8237 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 8238 | error_register: |
| 8239 | iwl3945_rate_control_unregister(); |
| 8240 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8241 | } |
| 8242 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8243 | static void __exit iwl3945_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8244 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8245 | pci_unregister_driver(&iwl3945_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 8246 | iwl3945_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8247 | } |
| 8248 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 8249 | MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX)); |
Zhu Yi | 25cb6ca | 2008-09-11 11:45:22 +0800 | [diff] [blame] | 8250 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8251 | module_param_named(antenna, iwl3945_param_antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8252 | MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8253 | module_param_named(disable, iwl3945_param_disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8254 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8255 | module_param_named(hwcrypto, iwl3945_param_hwcrypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8256 | MODULE_PARM_DESC(hwcrypto, |
| 8257 | "using hardware crypto engine (default 0 [software])\n"); |
Wu, Fengguang | 95aa194 | 2008-12-17 16:52:30 +0800 | [diff] [blame] | 8258 | module_param_named(debug, iwl3945_param_debug, uint, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8259 | MODULE_PARM_DESC(debug, "debug output mask"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8260 | module_param_named(disable_hw_scan, iwl3945_param_disable_hw_scan, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8261 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 8262 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8263 | module_param_named(queues_num, iwl3945_param_queues_num, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8264 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 8265 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8266 | module_exit(iwl3945_exit); |
| 8267 | module_init(iwl3945_init); |