Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. |
| 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: |
| 25 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 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> |
| 32 | #include <linux/version.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/skbuff.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/wireless.h> |
| 40 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 41 | #include <linux/etherdevice.h> |
| 42 | #include <linux/if_arp.h> |
| 43 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 44 | #include <net/mac80211.h> |
| 45 | |
| 46 | #include <asm/div64.h> |
| 47 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 48 | #include "iwl-core.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 49 | #include "iwl-4965.h" |
| 50 | #include "iwl-helpers.h" |
| 51 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 52 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 53 | struct iwl4965_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 54 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 55 | /****************************************************************************** |
| 56 | * |
| 57 | * module boiler plate |
| 58 | * |
| 59 | ******************************************************************************/ |
| 60 | |
| 61 | /* module parameters */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 62 | static int iwl4965_param_disable_hw_scan; /* def: 0 = use 4965's h/w scan */ |
| 63 | static int iwl4965_param_debug; /* def: 0 = minimal debug log messages */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 64 | static int iwl4965_param_disable; /* def: enable radio */ |
| 65 | static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */ |
| 66 | int iwl4965_param_hwcrypto; /* def: using software encryption */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 67 | static int iwl4965_param_qos_enable = 1; /* def: 1 = use quality of service */ |
| 68 | int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 16 Tx queues */ |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 69 | int iwl4965_param_amsdu_size_8K; /* def: enable 8K amsdu size */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * module name, copyright, version, etc. |
| 73 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 74 | */ |
| 75 | |
| 76 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" |
| 77 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 78 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 79 | #define VD "d" |
| 80 | #else |
| 81 | #define VD |
| 82 | #endif |
| 83 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 84 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 85 | #define VS "s" |
| 86 | #else |
| 87 | #define VS |
| 88 | #endif |
| 89 | |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame^] | 90 | #define DRV_VERSION IWLWIFI_VERSION VD VS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 91 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 92 | |
| 93 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 94 | MODULE_VERSION(DRV_VERSION); |
| 95 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 96 | MODULE_LICENSE("GPL"); |
| 97 | |
| 98 | __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) |
| 99 | { |
| 100 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 101 | int hdr_len = ieee80211_get_hdrlen(fc); |
| 102 | |
| 103 | if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA)) |
| 104 | return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN); |
| 105 | return NULL; |
| 106 | } |
| 107 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 108 | static const struct ieee80211_supported_band *iwl4965_get_hw_mode( |
| 109 | struct iwl4965_priv *priv, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 110 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 111 | return priv->hw->wiphy->bands[band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 114 | static int iwl4965_is_empty_essid(const char *essid, int essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 115 | { |
| 116 | /* Single white space is for Linksys APs */ |
| 117 | if (essid_len == 1 && essid[0] == ' ') |
| 118 | return 1; |
| 119 | |
| 120 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 121 | while (essid_len) { |
| 122 | essid_len--; |
| 123 | if (essid[essid_len] != '\0') |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | return 1; |
| 128 | } |
| 129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 130 | static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 131 | { |
| 132 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 133 | const char *s = essid; |
| 134 | char *d = escaped; |
| 135 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 136 | if (iwl4965_is_empty_essid(essid, essid_len)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 137 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 138 | return escaped; |
| 139 | } |
| 140 | |
| 141 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 142 | while (essid_len--) { |
| 143 | if (*s == '\0') { |
| 144 | *d++ = '\\'; |
| 145 | *d++ = '0'; |
| 146 | s++; |
| 147 | } else |
| 148 | *d++ = *s++; |
| 149 | } |
| 150 | *d = '\0'; |
| 151 | return escaped; |
| 152 | } |
| 153 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 154 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 155 | * DMA services |
| 156 | * |
| 157 | * Theory of operation |
| 158 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 159 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 160 | * of buffer descriptors, each of which points to one or more data buffers for |
| 161 | * the device to read from or fill. Driver and device exchange status of each |
| 162 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 163 | * entries in each circular buffer, to protect against confusing empty and full |
| 164 | * queue states. |
| 165 | * |
| 166 | * The device reads or writes the data in the queues via the device's several |
| 167 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 168 | * |
| 169 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 170 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 171 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 172 | * Tx queue resumed. |
| 173 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 174 | * The 4965 operates with up to 17 queues: One receive queue, one transmit |
| 175 | * queue (#4) for sending commands to the device firmware, and 15 other |
| 176 | * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels. |
Ben Cahill | e385144 | 2007-11-29 11:10:07 +0800 | [diff] [blame] | 177 | * |
| 178 | * See more detailed info in iwl-4965-hw.h. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 179 | ***************************************************/ |
| 180 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 181 | int iwl4965_queue_space(const struct iwl4965_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 182 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 183 | int s = q->read_ptr - q->write_ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 184 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 185 | if (q->read_ptr > q->write_ptr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 186 | s -= q->n_bd; |
| 187 | |
| 188 | if (s <= 0) |
| 189 | s += q->n_window; |
| 190 | /* keep some reserve to not confuse empty and full situations */ |
| 191 | s -= 2; |
| 192 | if (s < 0) |
| 193 | s = 0; |
| 194 | return s; |
| 195 | } |
| 196 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 197 | /** |
| 198 | * iwl4965_queue_inc_wrap - increment queue index, wrap back to beginning |
| 199 | * @index -- current index |
| 200 | * @n_bd -- total number of entries in queue (must be power of 2) |
| 201 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 202 | static inline int iwl4965_queue_inc_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 203 | { |
| 204 | return ++index & (n_bd - 1); |
| 205 | } |
| 206 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 207 | /** |
| 208 | * iwl4965_queue_dec_wrap - decrement queue index, wrap back to end |
| 209 | * @index -- current index |
| 210 | * @n_bd -- total number of entries in queue (must be power of 2) |
| 211 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 212 | static inline int iwl4965_queue_dec_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 213 | { |
| 214 | return --index & (n_bd - 1); |
| 215 | } |
| 216 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 217 | static inline int x2_queue_used(const struct iwl4965_queue *q, int i) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 218 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 219 | return q->write_ptr > q->read_ptr ? |
| 220 | (i >= q->read_ptr && i < q->write_ptr) : |
| 221 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 224 | static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 225 | { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 226 | /* This is for scan command, the big buffer at end of command array */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 227 | if (is_huge) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 228 | return q->n_window; /* must be power of 2 */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 229 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 230 | /* Otherwise, use normal size buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 231 | return index & (q->n_window - 1); |
| 232 | } |
| 233 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 234 | /** |
| 235 | * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes |
| 236 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 237 | static int iwl4965_queue_init(struct iwl4965_priv *priv, struct iwl4965_queue *q, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 238 | int count, int slots_num, u32 id) |
| 239 | { |
| 240 | q->n_bd = count; |
| 241 | q->n_window = slots_num; |
| 242 | q->id = id; |
| 243 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 244 | /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap |
| 245 | * and iwl4965_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 246 | BUG_ON(!is_power_of_2(count)); |
| 247 | |
| 248 | /* slots_num must be power-of-two size, otherwise |
| 249 | * get_cmd_index is broken. */ |
| 250 | BUG_ON(!is_power_of_2(slots_num)); |
| 251 | |
| 252 | q->low_mark = q->n_window / 4; |
| 253 | if (q->low_mark < 4) |
| 254 | q->low_mark = 4; |
| 255 | |
| 256 | q->high_mark = q->n_window / 8; |
| 257 | if (q->high_mark < 2) |
| 258 | q->high_mark = 2; |
| 259 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 260 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 265 | /** |
| 266 | * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 267 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 268 | static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv, |
| 269 | struct iwl4965_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 270 | { |
| 271 | struct pci_dev *dev = priv->pci_dev; |
| 272 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 273 | /* Driver private data, only for Tx (not command) queues, |
| 274 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 275 | if (id != IWL_CMD_QUEUE_NUM) { |
| 276 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 277 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 278 | if (!txq->txb) { |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 279 | IWL_ERROR("kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 280 | "structures failed\n"); |
| 281 | goto error; |
| 282 | } |
| 283 | } else |
| 284 | txq->txb = NULL; |
| 285 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 286 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 287 | * shared with device */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 288 | txq->bd = pci_alloc_consistent(dev, |
| 289 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 290 | &txq->q.dma_addr); |
| 291 | |
| 292 | if (!txq->bd) { |
| 293 | IWL_ERROR("pci_alloc_consistent(%zd) failed\n", |
| 294 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 295 | goto error; |
| 296 | } |
| 297 | txq->q.id = id; |
| 298 | |
| 299 | return 0; |
| 300 | |
| 301 | error: |
| 302 | if (txq->txb) { |
| 303 | kfree(txq->txb); |
| 304 | txq->txb = NULL; |
| 305 | } |
| 306 | |
| 307 | return -ENOMEM; |
| 308 | } |
| 309 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 310 | /** |
| 311 | * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 312 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 313 | int iwl4965_tx_queue_init(struct iwl4965_priv *priv, |
| 314 | struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 315 | { |
| 316 | struct pci_dev *dev = priv->pci_dev; |
| 317 | int len; |
| 318 | int rc = 0; |
| 319 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 320 | /* |
| 321 | * Alloc buffer array for commands (Tx or other types of commands). |
| 322 | * For the command queue (#4), allocate command space + one big |
| 323 | * command for scan, since scan command is very huge; the system will |
| 324 | * not have two scans at the same time, so only one is needed. |
Tomas Winkler | bb54244 | 2007-12-05 20:59:59 +0200 | [diff] [blame] | 325 | * For normal Tx queues (all other queues), no super-size command |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 326 | * space is needed. |
| 327 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 328 | len = sizeof(struct iwl4965_cmd) * slots_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 329 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 330 | len += IWL_MAX_SCAN_SIZE; |
| 331 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 332 | if (!txq->cmd) |
| 333 | return -ENOMEM; |
| 334 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 335 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 336 | rc = iwl4965_tx_queue_alloc(priv, txq, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 337 | if (rc) { |
| 338 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 339 | |
| 340 | return -ENOMEM; |
| 341 | } |
| 342 | txq->need_update = 0; |
| 343 | |
| 344 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 345 | * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 346 | BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 347 | |
| 348 | /* Initialize queue's high/low-water marks, and head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 349 | iwl4965_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] | 350 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 351 | /* Tell device where to find queue */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 352 | iwl4965_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 358 | * iwl4965_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 359 | * @txq: Transmit queue to deallocate. |
| 360 | * |
| 361 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 362 | * Free all buffers. |
| 363 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 364 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 365 | void iwl4965_tx_queue_free(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 366 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 367 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 368 | struct pci_dev *dev = priv->pci_dev; |
| 369 | int len; |
| 370 | |
| 371 | if (q->n_bd == 0) |
| 372 | return; |
| 373 | |
| 374 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 375 | for (; q->write_ptr != q->read_ptr; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 376 | q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) |
| 377 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 378 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 379 | len = sizeof(struct iwl4965_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 381 | len += IWL_MAX_SCAN_SIZE; |
| 382 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 383 | /* De-alloc array of command/tx buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 384 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 385 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 386 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 387 | if (txq->q.n_bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 388 | pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 389 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 390 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 391 | /* De-alloc array of per-TFD driver data */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 392 | if (txq->txb) { |
| 393 | kfree(txq->txb); |
| 394 | txq->txb = NULL; |
| 395 | } |
| 396 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 397 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 398 | memset(txq, 0, sizeof(*txq)); |
| 399 | } |
| 400 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 401 | const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 402 | |
| 403 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 404 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 405 | * the functionality provided here |
| 406 | */ |
| 407 | |
| 408 | /**************************************************************/ |
| 409 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 410 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 411 | /** |
| 412 | * iwl4965_remove_station - Remove driver's knowledge of station. |
| 413 | * |
| 414 | * NOTE: This does not remove station from device's station table. |
| 415 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 416 | static u8 iwl4965_remove_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 417 | { |
| 418 | int index = IWL_INVALID_STATION; |
| 419 | int i; |
| 420 | unsigned long flags; |
| 421 | |
| 422 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 423 | |
| 424 | if (is_ap) |
| 425 | index = IWL_AP_ID; |
| 426 | else if (is_broadcast_ether_addr(addr)) |
| 427 | index = priv->hw_setting.bcast_sta_id; |
| 428 | else |
| 429 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) |
| 430 | if (priv->stations[i].used && |
| 431 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 432 | addr)) { |
| 433 | index = i; |
| 434 | break; |
| 435 | } |
| 436 | |
| 437 | if (unlikely(index == IWL_INVALID_STATION)) |
| 438 | goto out; |
| 439 | |
| 440 | if (priv->stations[index].used) { |
| 441 | priv->stations[index].used = 0; |
| 442 | priv->num_stations--; |
| 443 | } |
| 444 | |
| 445 | BUG_ON(priv->num_stations < 0); |
| 446 | |
| 447 | out: |
| 448 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 449 | return 0; |
| 450 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 451 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 452 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 453 | /** |
| 454 | * iwl4965_clear_stations_table - Clear the driver's station table |
| 455 | * |
| 456 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 457 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 458 | static void iwl4965_clear_stations_table(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 459 | { |
| 460 | unsigned long flags; |
| 461 | |
| 462 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 463 | |
| 464 | priv->num_stations = 0; |
| 465 | memset(priv->stations, 0, sizeof(priv->stations)); |
| 466 | |
| 467 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 468 | } |
| 469 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 470 | /** |
| 471 | * iwl4965_add_station_flags - Add station to tables in driver and device |
| 472 | */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 473 | u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr, |
| 474 | int is_ap, u8 flags, void *ht_data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 475 | { |
| 476 | int i; |
| 477 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 478 | struct iwl4965_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 479 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 480 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 481 | |
| 482 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 483 | if (is_ap) |
| 484 | index = IWL_AP_ID; |
| 485 | else if (is_broadcast_ether_addr(addr)) |
| 486 | index = priv->hw_setting.bcast_sta_id; |
| 487 | else |
| 488 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) { |
| 489 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 490 | addr)) { |
| 491 | index = i; |
| 492 | break; |
| 493 | } |
| 494 | |
| 495 | if (!priv->stations[i].used && |
| 496 | index == IWL_INVALID_STATION) |
| 497 | index = i; |
| 498 | } |
| 499 | |
| 500 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 501 | /* These two conditions have the same outcome, but keep them separate |
| 502 | since they have different meanings */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 503 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 504 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 505 | return index; |
| 506 | } |
| 507 | |
| 508 | if (priv->stations[index].used && |
| 509 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 510 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 511 | return index; |
| 512 | } |
| 513 | |
| 514 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 515 | IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 516 | station = &priv->stations[index]; |
| 517 | station->used = 1; |
| 518 | priv->num_stations++; |
| 519 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 520 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 521 | memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 522 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 523 | station->sta.mode = 0; |
| 524 | station->sta.sta.sta_id = index; |
| 525 | station->sta.station_flags = 0; |
| 526 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 527 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 528 | /* BCAST station and IBSS stations do not work in HT mode */ |
| 529 | if (index != priv->hw_setting.bcast_sta_id && |
| 530 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 531 | iwl4965_set_ht_add_station(priv, index, |
| 532 | (struct ieee80211_ht_info *) ht_data); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 533 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 534 | |
| 535 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 536 | |
| 537 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 538 | iwl4965_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 539 | return index; |
| 540 | |
| 541 | } |
| 542 | |
| 543 | /*************** DRIVER STATUS FUNCTIONS *****/ |
| 544 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 545 | static inline int iwl4965_is_ready(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 546 | { |
| 547 | /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are |
| 548 | * set but EXIT_PENDING is not */ |
| 549 | return test_bit(STATUS_READY, &priv->status) && |
| 550 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) && |
| 551 | !test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 552 | } |
| 553 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 554 | static inline int iwl4965_is_alive(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 555 | { |
| 556 | return test_bit(STATUS_ALIVE, &priv->status); |
| 557 | } |
| 558 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 559 | static inline int iwl4965_is_init(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 560 | { |
| 561 | return test_bit(STATUS_INIT, &priv->status); |
| 562 | } |
| 563 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 564 | static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 565 | { |
| 566 | return test_bit(STATUS_RF_KILL_HW, &priv->status) || |
| 567 | test_bit(STATUS_RF_KILL_SW, &priv->status); |
| 568 | } |
| 569 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 570 | static inline int iwl4965_is_ready_rf(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 571 | { |
| 572 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 573 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 574 | return 0; |
| 575 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 576 | return iwl4965_is_ready(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 580 | |
| 581 | #define IWL_CMD(x) case x : return #x |
| 582 | |
| 583 | static const char *get_cmd_string(u8 cmd) |
| 584 | { |
| 585 | switch (cmd) { |
| 586 | IWL_CMD(REPLY_ALIVE); |
| 587 | IWL_CMD(REPLY_ERROR); |
| 588 | IWL_CMD(REPLY_RXON); |
| 589 | IWL_CMD(REPLY_RXON_ASSOC); |
| 590 | IWL_CMD(REPLY_QOS_PARAM); |
| 591 | IWL_CMD(REPLY_RXON_TIMING); |
| 592 | IWL_CMD(REPLY_ADD_STA); |
| 593 | IWL_CMD(REPLY_REMOVE_STA); |
| 594 | IWL_CMD(REPLY_REMOVE_ALL_STA); |
| 595 | IWL_CMD(REPLY_TX); |
| 596 | IWL_CMD(REPLY_RATE_SCALE); |
| 597 | IWL_CMD(REPLY_LEDS_CMD); |
| 598 | IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); |
| 599 | IWL_CMD(RADAR_NOTIFICATION); |
| 600 | IWL_CMD(REPLY_QUIET_CMD); |
| 601 | IWL_CMD(REPLY_CHANNEL_SWITCH); |
| 602 | IWL_CMD(CHANNEL_SWITCH_NOTIFICATION); |
| 603 | IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD); |
| 604 | IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION); |
| 605 | IWL_CMD(POWER_TABLE_CMD); |
| 606 | IWL_CMD(PM_SLEEP_NOTIFICATION); |
| 607 | IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC); |
| 608 | IWL_CMD(REPLY_SCAN_CMD); |
| 609 | IWL_CMD(REPLY_SCAN_ABORT_CMD); |
| 610 | IWL_CMD(SCAN_START_NOTIFICATION); |
| 611 | IWL_CMD(SCAN_RESULTS_NOTIFICATION); |
| 612 | IWL_CMD(SCAN_COMPLETE_NOTIFICATION); |
| 613 | IWL_CMD(BEACON_NOTIFICATION); |
| 614 | IWL_CMD(REPLY_TX_BEACON); |
| 615 | IWL_CMD(WHO_IS_AWAKE_NOTIFICATION); |
| 616 | IWL_CMD(QUIET_NOTIFICATION); |
| 617 | IWL_CMD(REPLY_TX_PWR_TABLE_CMD); |
| 618 | IWL_CMD(MEASURE_ABORT_NOTIFICATION); |
| 619 | IWL_CMD(REPLY_BT_CONFIG); |
| 620 | IWL_CMD(REPLY_STATISTICS_CMD); |
| 621 | IWL_CMD(STATISTICS_NOTIFICATION); |
| 622 | IWL_CMD(REPLY_CARD_STATE_CMD); |
| 623 | IWL_CMD(CARD_STATE_NOTIFICATION); |
| 624 | IWL_CMD(MISSED_BEACONS_NOTIFICATION); |
| 625 | IWL_CMD(REPLY_CT_KILL_CONFIG_CMD); |
| 626 | IWL_CMD(SENSITIVITY_CMD); |
| 627 | IWL_CMD(REPLY_PHY_CALIBRATION_CMD); |
| 628 | IWL_CMD(REPLY_RX_PHY_CMD); |
| 629 | IWL_CMD(REPLY_RX_MPDU_CMD); |
| 630 | IWL_CMD(REPLY_4965_RX); |
| 631 | IWL_CMD(REPLY_COMPRESSED_BA); |
| 632 | default: |
| 633 | return "UNKNOWN"; |
| 634 | |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 639 | |
| 640 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 641 | * iwl4965_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 642 | * @priv: device private data point |
| 643 | * @cmd: a point to the ucode command structure |
| 644 | * |
| 645 | * The function returns < 0 values to indicate the operation is |
| 646 | * failed. On success, it turns the index (> 0) of command in the |
| 647 | * command queue. |
| 648 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 649 | static int iwl4965_enqueue_hcmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 650 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 651 | struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 652 | struct iwl4965_queue *q = &txq->q; |
| 653 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 654 | u32 *control_flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 655 | struct iwl4965_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 656 | u32 idx; |
| 657 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 658 | dma_addr_t phys_addr; |
| 659 | int ret; |
| 660 | unsigned long flags; |
| 661 | |
| 662 | /* If any of the command structures end up being larger than |
| 663 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 664 | * we will need to increase the size of the TFD entries */ |
| 665 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 666 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 667 | |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 668 | if (iwl4965_is_rfkill(priv)) { |
| 669 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 670 | return -EIO; |
| 671 | } |
| 672 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 673 | if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 674 | IWL_ERROR("No space for Tx\n"); |
| 675 | return -ENOSPC; |
| 676 | } |
| 677 | |
| 678 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 679 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 680 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 681 | memset(tfd, 0, sizeof(*tfd)); |
| 682 | |
| 683 | control_flags = (u32 *) tfd; |
| 684 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 685 | 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] | 686 | out_cmd = &txq->cmd[idx]; |
| 687 | |
| 688 | out_cmd->hdr.cmd = cmd->id; |
| 689 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 690 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 691 | |
| 692 | /* At this point, the out_cmd now has all of the incoming cmd |
| 693 | * information */ |
| 694 | |
| 695 | out_cmd->hdr.flags = 0; |
| 696 | 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] | 697 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 698 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 699 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 700 | |
| 701 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 702 | offsetof(struct iwl4965_cmd, hdr); |
| 703 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 704 | |
| 705 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 706 | "%d bytes at %d[%d]:%d\n", |
| 707 | get_cmd_string(out_cmd->hdr.cmd), |
| 708 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 709 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 710 | |
| 711 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 712 | |
| 713 | /* Set up entry in queue's byte count circular buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 714 | ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 715 | |
| 716 | /* Increment and update queue's write index */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 717 | q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 718 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 719 | |
| 720 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 721 | return ret ? ret : idx; |
| 722 | } |
| 723 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 724 | static int iwl4965_send_cmd_async(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 725 | { |
| 726 | int ret; |
| 727 | |
| 728 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 729 | |
| 730 | /* An asynchronous command can not expect an SKB to be set. */ |
| 731 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 732 | |
| 733 | /* An asynchronous command MUST have a callback. */ |
| 734 | BUG_ON(!cmd->meta.u.callback); |
| 735 | |
| 736 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 737 | return -EBUSY; |
| 738 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 739 | ret = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 740 | if (ret < 0) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 741 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 742 | get_cmd_string(cmd->id), ret); |
| 743 | return ret; |
| 744 | } |
| 745 | return 0; |
| 746 | } |
| 747 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 748 | static int iwl4965_send_cmd_sync(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 749 | { |
| 750 | int cmd_idx; |
| 751 | int ret; |
| 752 | static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */ |
| 753 | |
| 754 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 755 | |
| 756 | /* A synchronous command can not have a callback set. */ |
| 757 | BUG_ON(cmd->meta.u.callback != NULL); |
| 758 | |
| 759 | if (atomic_xchg(&entry, 1)) { |
| 760 | IWL_ERROR("Error sending %s: Already sending a host command\n", |
| 761 | get_cmd_string(cmd->id)); |
| 762 | return -EBUSY; |
| 763 | } |
| 764 | |
| 765 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 766 | |
| 767 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 768 | cmd->meta.source = &cmd->meta; |
| 769 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 770 | cmd_idx = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 771 | if (cmd_idx < 0) { |
| 772 | ret = cmd_idx; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 773 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 774 | get_cmd_string(cmd->id), ret); |
| 775 | goto out; |
| 776 | } |
| 777 | |
| 778 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 779 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 780 | HOST_COMPLETE_TIMEOUT); |
| 781 | if (!ret) { |
| 782 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
| 783 | IWL_ERROR("Error sending %s: time out after %dms.\n", |
| 784 | get_cmd_string(cmd->id), |
| 785 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 786 | |
| 787 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 788 | ret = -ETIMEDOUT; |
| 789 | goto cancel; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 794 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 795 | get_cmd_string(cmd->id)); |
| 796 | ret = -ECANCELED; |
| 797 | goto fail; |
| 798 | } |
| 799 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 800 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 801 | get_cmd_string(cmd->id)); |
| 802 | ret = -EIO; |
| 803 | goto fail; |
| 804 | } |
| 805 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
| 806 | IWL_ERROR("Error: Response NULL in '%s'\n", |
| 807 | get_cmd_string(cmd->id)); |
| 808 | ret = -EIO; |
| 809 | goto out; |
| 810 | } |
| 811 | |
| 812 | ret = 0; |
| 813 | goto out; |
| 814 | |
| 815 | cancel: |
| 816 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 817 | struct iwl4965_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 818 | |
| 819 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 820 | * TX cmd queue. Otherwise in case the cmd comes |
| 821 | * in later, it will possibly set an invalid |
| 822 | * address (cmd->meta.source). */ |
| 823 | qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
| 824 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 825 | } |
| 826 | fail: |
| 827 | if (cmd->meta.u.skb) { |
| 828 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 829 | cmd->meta.u.skb = NULL; |
| 830 | } |
| 831 | out: |
| 832 | atomic_set(&entry, 0); |
| 833 | return ret; |
| 834 | } |
| 835 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 836 | int iwl4965_send_cmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 837 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 838 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 839 | return iwl4965_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 840 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 841 | return iwl4965_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 844 | int iwl4965_send_cmd_pdu(struct iwl4965_priv *priv, u8 id, u16 len, const void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 845 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 846 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 847 | .id = id, |
| 848 | .len = len, |
| 849 | .data = data, |
| 850 | }; |
| 851 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 852 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 855 | static int __must_check iwl4965_send_cmd_u32(struct iwl4965_priv *priv, u8 id, u32 val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 856 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 857 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 858 | .id = id, |
| 859 | .len = sizeof(val), |
| 860 | .data = &val, |
| 861 | }; |
| 862 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 863 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 866 | int iwl4965_send_statistics_request(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 867 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 868 | return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 872 | * iwl4965_rxon_add_station - add station into station table. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 873 | * |
| 874 | * there is only one AP station with id= IWL_AP_ID |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 875 | * NOTE: mutex must be held before calling this fnction |
| 876 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 877 | static int iwl4965_rxon_add_station(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 878 | const u8 *addr, int is_ap) |
| 879 | { |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 880 | u8 sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 881 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 882 | /* Add station to device's station table */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 883 | #ifdef CONFIG_IWL4965_HT |
| 884 | struct ieee80211_conf *conf = &priv->hw->conf; |
| 885 | struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf; |
| 886 | |
| 887 | if ((is_ap) && |
| 888 | (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && |
| 889 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 890 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 891 | 0, cur_ht_config); |
| 892 | else |
| 893 | #endif /* CONFIG_IWL4965_HT */ |
| 894 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 895 | 0, NULL); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 896 | |
| 897 | /* Set up default rate scaling table in device's station table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 898 | iwl4965_add_station(priv, addr, is_ap); |
| 899 | |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 900 | return sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 904 | * iwl4965_set_rxon_channel - Set the phymode and channel values in staging RXON |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 905 | * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz |
| 906 | * @channel: Any channel valid for the requested phymode |
| 907 | |
| 908 | * In addition to setting the staging RXON, priv->phymode is also set. |
| 909 | * |
| 910 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
| 911 | * in the staging RXON flag structure based on the phymode |
| 912 | */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 913 | static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, |
| 914 | enum ieee80211_band band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 915 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 916 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 917 | if (!iwl4965_get_channel_info(priv, band, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 918 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 919 | channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 920 | return -EINVAL; |
| 921 | } |
| 922 | |
| 923 | if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 924 | (priv->band == band)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 925 | return 0; |
| 926 | |
| 927 | priv->staging_rxon.channel = cpu_to_le16(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 928 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 929 | priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
| 930 | else |
| 931 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 932 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 933 | priv->band = band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 934 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 935 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 936 | |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 941 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 942 | * |
| 943 | * NOTE: This is really only useful during development and can eventually |
| 944 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 945 | * making changes |
| 946 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 947 | static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 948 | { |
| 949 | int error = 0; |
| 950 | int counter = 1; |
| 951 | |
| 952 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 953 | error |= le32_to_cpu(rxon->flags & |
| 954 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 955 | RXON_FLG_RADAR_DETECT_MSK)); |
| 956 | if (error) |
| 957 | IWL_WARNING("check 24G fields %d | %d\n", |
| 958 | counter++, error); |
| 959 | } else { |
| 960 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 961 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 962 | if (error) |
| 963 | IWL_WARNING("check 52 fields %d | %d\n", |
| 964 | counter++, error); |
| 965 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 966 | if (error) |
| 967 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 968 | counter++, error); |
| 969 | } |
| 970 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 971 | if (error) |
| 972 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 973 | |
| 974 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 975 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 976 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 977 | if (error) |
| 978 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 979 | |
| 980 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 981 | if (error) |
| 982 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 983 | |
| 984 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 985 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 986 | if (error) |
| 987 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 988 | counter++, error); |
| 989 | |
| 990 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 991 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 992 | if (error) |
| 993 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 994 | counter++, error); |
| 995 | |
| 996 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 997 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 998 | if (error) |
| 999 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 1000 | counter++, error); |
| 1001 | |
| 1002 | if (error) |
| 1003 | IWL_WARNING("Tuning to channel %d\n", |
| 1004 | le16_to_cpu(rxon->channel)); |
| 1005 | |
| 1006 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1007 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1008 | return -1; |
| 1009 | } |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1014 | * iwl4965_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] | 1015 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1016 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1017 | * If the RXON structure is changing enough to require a new tune, |
| 1018 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 1019 | * 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] | 1020 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1021 | static int iwl4965_full_rxon_required(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1022 | { |
| 1023 | |
| 1024 | /* These items are only settable from the full RXON command */ |
| 1025 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 1026 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 1027 | priv->active_rxon.bssid_addr) || |
| 1028 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 1029 | priv->active_rxon.node_addr) || |
| 1030 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 1031 | priv->active_rxon.wlap_bssid_addr) || |
| 1032 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 1033 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 1034 | (priv->staging_rxon.air_propagation != |
| 1035 | priv->active_rxon.air_propagation) || |
| 1036 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 1037 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 1038 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 1039 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 1040 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 1041 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 1042 | return 1; |
| 1043 | |
| 1044 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 1045 | * be updated with the RXON_ASSOC command -- however only some |
| 1046 | * flag transitions are allowed using RXON_ASSOC */ |
| 1047 | |
| 1048 | /* Check if we are not switching bands */ |
| 1049 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 1050 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 1051 | return 1; |
| 1052 | |
| 1053 | /* Check if we are switching association toggle */ |
| 1054 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 1055 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 1056 | return 1; |
| 1057 | |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1061 | static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1062 | { |
| 1063 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1064 | struct iwl4965_rx_packet *res = NULL; |
| 1065 | struct iwl4965_rxon_assoc_cmd rxon_assoc; |
| 1066 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1067 | .id = REPLY_RXON_ASSOC, |
| 1068 | .len = sizeof(rxon_assoc), |
| 1069 | .meta.flags = CMD_WANT_SKB, |
| 1070 | .data = &rxon_assoc, |
| 1071 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1072 | const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 1073 | const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1074 | |
| 1075 | if ((rxon1->flags == rxon2->flags) && |
| 1076 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 1077 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 1078 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 1079 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 1080 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 1081 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 1082 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 1083 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 1084 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
| 1088 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 1089 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 1090 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 1091 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
| 1092 | rxon_assoc.reserved = 0; |
| 1093 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 1094 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates; |
| 1095 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 1096 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; |
| 1097 | rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; |
| 1098 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1099 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1100 | if (rc) |
| 1101 | return rc; |
| 1102 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1103 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1104 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1105 | IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n"); |
| 1106 | rc = -EIO; |
| 1107 | } |
| 1108 | |
| 1109 | priv->alloc_rxb_skb--; |
| 1110 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1111 | |
| 1112 | return rc; |
| 1113 | } |
| 1114 | |
| 1115 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1116 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1117 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1118 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1119 | * the active_rxon structure is updated with the new data. This |
| 1120 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 1121 | * a HW tune is required based on the RXON structure changes. |
| 1122 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1123 | static int iwl4965_commit_rxon(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1124 | { |
| 1125 | /* cast away the const for active_rxon in this function */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1126 | struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1127 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1128 | int rc = 0; |
| 1129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1130 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1131 | return -1; |
| 1132 | |
| 1133 | /* always get timestamp with Rx frame */ |
| 1134 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 1135 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1136 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1137 | if (rc) { |
| 1138 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 1139 | return -EINVAL; |
| 1140 | } |
| 1141 | |
| 1142 | /* 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] | 1143 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1144 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1145 | if (!iwl4965_full_rxon_required(priv)) { |
| 1146 | rc = iwl4965_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1147 | if (rc) { |
| 1148 | IWL_ERROR("Error setting RXON_ASSOC " |
| 1149 | "configuration (%d).\n", rc); |
| 1150 | return rc; |
| 1151 | } |
| 1152 | |
| 1153 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | /* station table will be cleared */ |
| 1159 | priv->assoc_station_added = 0; |
| 1160 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1161 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1162 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1163 | if (!priv->error_recovering) |
| 1164 | priv->start_calib = 0; |
| 1165 | |
| 1166 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1167 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1168 | |
| 1169 | /* If we are currently associated and the new config requires |
| 1170 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 1171 | * we must clear the associated from the active configuration |
| 1172 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1173 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1174 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 1175 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 1176 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1177 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1178 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1179 | sizeof(struct iwl4965_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1180 | &priv->active_rxon); |
| 1181 | |
| 1182 | /* If the mask clearing failed then we set |
| 1183 | * active_rxon back to what it was previously */ |
| 1184 | if (rc) { |
| 1185 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1186 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 1187 | "configuration (%d).\n", rc); |
| 1188 | return rc; |
| 1189 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | IWL_DEBUG_INFO("Sending RXON\n" |
| 1193 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 1194 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1195 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1196 | ((priv->staging_rxon.filter_flags & |
| 1197 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 1198 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1199 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1200 | |
| 1201 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1202 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1203 | sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1204 | if (rc) { |
| 1205 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 1206 | return rc; |
| 1207 | } |
| 1208 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1209 | iwl4965_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 1210 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1211 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1212 | if (!priv->error_recovering) |
| 1213 | priv->start_calib = 0; |
| 1214 | |
| 1215 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1216 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1217 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1218 | |
| 1219 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1220 | |
| 1221 | /* If we issue a new RXON command which required a tune then we must |
| 1222 | * 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] | 1223 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1224 | if (rc) { |
| 1225 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 1226 | return rc; |
| 1227 | } |
| 1228 | |
| 1229 | /* Add the broadcast address so we can send broadcast frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1230 | if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1231 | IWL_INVALID_STATION) { |
| 1232 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 1233 | return -EIO; |
| 1234 | } |
| 1235 | |
| 1236 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 1237 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1238 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1239 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1240 | if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1241 | == IWL_INVALID_STATION) { |
| 1242 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 1243 | return -EIO; |
| 1244 | } |
| 1245 | priv->assoc_station_added = 1; |
| 1246 | } |
| 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1251 | static int iwl4965_send_bt_config(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1252 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1253 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1254 | .flags = 3, |
| 1255 | .lead_time = 0xAA, |
| 1256 | .max_kill = 1, |
| 1257 | .kill_ack_mask = 0, |
| 1258 | .kill_cts_mask = 0, |
| 1259 | }; |
| 1260 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1261 | return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
| 1262 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1265 | static int iwl4965_send_scan_abort(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1266 | { |
| 1267 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1268 | struct iwl4965_rx_packet *res; |
| 1269 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1270 | .id = REPLY_SCAN_ABORT_CMD, |
| 1271 | .meta.flags = CMD_WANT_SKB, |
| 1272 | }; |
| 1273 | |
| 1274 | /* If there isn't a scan actively going on in the hardware |
| 1275 | * then we are in between scan bands and not actually |
| 1276 | * actively scanning, so don't send the abort command */ |
| 1277 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1278 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1282 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1283 | if (rc) { |
| 1284 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1285 | return rc; |
| 1286 | } |
| 1287 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1288 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1289 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1290 | /* The scan abort will return 1 for success or |
| 1291 | * 2 for "failure". A failure condition can be |
| 1292 | * due to simply not being in an active scan which |
| 1293 | * can occur if we send the scan abort before we |
| 1294 | * the microcode has notified us that a scan is |
| 1295 | * completed. */ |
| 1296 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1297 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1298 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1299 | } |
| 1300 | |
| 1301 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1302 | |
| 1303 | return rc; |
| 1304 | } |
| 1305 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1306 | static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv, |
| 1307 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1308 | struct sk_buff *skb) |
| 1309 | { |
| 1310 | return 1; |
| 1311 | } |
| 1312 | |
| 1313 | /* |
| 1314 | * CARD_STATE_CMD |
| 1315 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1316 | * 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] | 1317 | * |
| 1318 | * When in the 'enable' state the card operates as normal. |
| 1319 | * When in the 'disable' state, the card enters into a low power mode. |
| 1320 | * When in the 'halt' state, the card is shut down and must be fully |
| 1321 | * restarted to come back on. |
| 1322 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1323 | static int iwl4965_send_card_state(struct iwl4965_priv *priv, u32 flags, u8 meta_flag) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1324 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1325 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1326 | .id = REPLY_CARD_STATE_CMD, |
| 1327 | .len = sizeof(u32), |
| 1328 | .data = &flags, |
| 1329 | .meta.flags = meta_flag, |
| 1330 | }; |
| 1331 | |
| 1332 | if (meta_flag & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1333 | cmd.meta.u.callback = iwl4965_card_state_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1334 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1335 | return iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1338 | static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv, |
| 1339 | struct iwl4965_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1340 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1341 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1342 | |
| 1343 | if (!skb) { |
| 1344 | IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); |
| 1345 | return 1; |
| 1346 | } |
| 1347 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1348 | res = (struct iwl4965_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1349 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1350 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1351 | res->hdr.flags); |
| 1352 | return 1; |
| 1353 | } |
| 1354 | |
| 1355 | switch (res->u.add_sta.status) { |
| 1356 | case ADD_STA_SUCCESS_MSK: |
| 1357 | break; |
| 1358 | default: |
| 1359 | break; |
| 1360 | } |
| 1361 | |
| 1362 | /* We didn't cache the SKB; let the caller free it */ |
| 1363 | return 1; |
| 1364 | } |
| 1365 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1366 | int iwl4965_send_add_station(struct iwl4965_priv *priv, |
| 1367 | struct iwl4965_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1368 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1369 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1370 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1371 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1372 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1373 | .len = sizeof(struct iwl4965_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1374 | .meta.flags = flags, |
| 1375 | .data = sta, |
| 1376 | }; |
| 1377 | |
| 1378 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1379 | cmd.meta.u.callback = iwl4965_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1380 | else |
| 1381 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1382 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1383 | rc = iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1384 | |
| 1385 | if (rc || (flags & CMD_ASYNC)) |
| 1386 | return rc; |
| 1387 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1388 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1389 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1390 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1391 | res->hdr.flags); |
| 1392 | rc = -EIO; |
| 1393 | } |
| 1394 | |
| 1395 | if (rc == 0) { |
| 1396 | switch (res->u.add_sta.status) { |
| 1397 | case ADD_STA_SUCCESS_MSK: |
| 1398 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1399 | break; |
| 1400 | default: |
| 1401 | rc = -EIO; |
| 1402 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 1403 | break; |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | priv->alloc_rxb_skb--; |
| 1408 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1409 | |
| 1410 | return rc; |
| 1411 | } |
| 1412 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1413 | static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1414 | struct ieee80211_key_conf *keyconf, |
| 1415 | u8 sta_id) |
| 1416 | { |
| 1417 | unsigned long flags; |
| 1418 | __le16 key_flags = 0; |
| 1419 | |
| 1420 | switch (keyconf->alg) { |
| 1421 | case ALG_CCMP: |
| 1422 | key_flags |= STA_KEY_FLG_CCMP; |
| 1423 | key_flags |= cpu_to_le16( |
| 1424 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1425 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1426 | break; |
| 1427 | case ALG_TKIP: |
| 1428 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1429 | default: |
| 1430 | return -EINVAL; |
| 1431 | } |
| 1432 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1433 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 1434 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1435 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 1436 | keyconf->keylen); |
| 1437 | |
| 1438 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 1439 | keyconf->keylen); |
| 1440 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 1441 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1442 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1443 | |
| 1444 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1445 | |
| 1446 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1447 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1448 | return 0; |
| 1449 | } |
| 1450 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1451 | static int iwl4965_clear_sta_key_info(struct iwl4965_priv *priv, u8 sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1452 | { |
| 1453 | unsigned long flags; |
| 1454 | |
| 1455 | spin_lock_irqsave(&priv->sta_lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1456 | memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key)); |
| 1457 | memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1458 | priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1459 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1460 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1461 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1462 | |
| 1463 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1464 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1465 | return 0; |
| 1466 | } |
| 1467 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1468 | static void iwl4965_clear_free_frames(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1469 | { |
| 1470 | struct list_head *element; |
| 1471 | |
| 1472 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1473 | priv->frames_count); |
| 1474 | |
| 1475 | while (!list_empty(&priv->free_frames)) { |
| 1476 | element = priv->free_frames.next; |
| 1477 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1478 | kfree(list_entry(element, struct iwl4965_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1479 | priv->frames_count--; |
| 1480 | } |
| 1481 | |
| 1482 | if (priv->frames_count) { |
| 1483 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 1484 | priv->frames_count); |
| 1485 | priv->frames_count = 0; |
| 1486 | } |
| 1487 | } |
| 1488 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1489 | static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1490 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1491 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1492 | struct list_head *element; |
| 1493 | if (list_empty(&priv->free_frames)) { |
| 1494 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1495 | if (!frame) { |
| 1496 | IWL_ERROR("Could not allocate frame!\n"); |
| 1497 | return NULL; |
| 1498 | } |
| 1499 | |
| 1500 | priv->frames_count++; |
| 1501 | return frame; |
| 1502 | } |
| 1503 | |
| 1504 | element = priv->free_frames.next; |
| 1505 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1506 | return list_entry(element, struct iwl4965_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1509 | static void iwl4965_free_frame(struct iwl4965_priv *priv, struct iwl4965_frame *frame) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1510 | { |
| 1511 | memset(frame, 0, sizeof(*frame)); |
| 1512 | list_add(&frame->list, &priv->free_frames); |
| 1513 | } |
| 1514 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1515 | unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1516 | struct ieee80211_hdr *hdr, |
| 1517 | const u8 *dest, int left) |
| 1518 | { |
| 1519 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1520 | if (!iwl4965_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1521 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 1522 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 1523 | return 0; |
| 1524 | |
| 1525 | if (priv->ibss_beacon->len > left) |
| 1526 | return 0; |
| 1527 | |
| 1528 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1529 | |
| 1530 | return priv->ibss_beacon->len; |
| 1531 | } |
| 1532 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1533 | static u8 iwl4965_rate_get_lowest_plcp(int rate_mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1534 | { |
| 1535 | u8 i; |
| 1536 | |
| 1537 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1538 | i = iwl4965_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1539 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1540 | return iwl4965_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | return IWL_RATE_INVALID; |
| 1544 | } |
| 1545 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1546 | static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1547 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1548 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1549 | unsigned int frame_size; |
| 1550 | int rc; |
| 1551 | u8 rate; |
| 1552 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1553 | frame = iwl4965_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1554 | |
| 1555 | if (!frame) { |
| 1556 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 1557 | "command.\n"); |
| 1558 | return -ENOMEM; |
| 1559 | } |
| 1560 | |
| 1561 | if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1562 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1563 | 0xFF0); |
| 1564 | if (rate == IWL_INVALID_RATE) |
| 1565 | rate = IWL_RATE_6M_PLCP; |
| 1566 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1567 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1568 | if (rate == IWL_INVALID_RATE) |
| 1569 | rate = IWL_RATE_1M_PLCP; |
| 1570 | } |
| 1571 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1572 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1573 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1574 | rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1575 | &frame->u.cmd[0]); |
| 1576 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1577 | iwl4965_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1578 | |
| 1579 | return rc; |
| 1580 | } |
| 1581 | |
| 1582 | /****************************************************************************** |
| 1583 | * |
| 1584 | * EEPROM related functions |
| 1585 | * |
| 1586 | ******************************************************************************/ |
| 1587 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1588 | static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1589 | { |
| 1590 | memcpy(mac, priv->eeprom.mac_address, 6); |
| 1591 | } |
| 1592 | |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1593 | static inline void iwl4965_eeprom_release_semaphore(struct iwl4965_priv *priv) |
| 1594 | { |
| 1595 | iwl4965_clear_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 1596 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); |
| 1597 | } |
| 1598 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1599 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1600 | * iwl4965_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1601 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1602 | * Load the EEPROM contents from adapter into priv->eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1603 | * |
| 1604 | * NOTE: This routine uses the non-debug IO access functions. |
| 1605 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1606 | int iwl4965_eeprom_init(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1607 | { |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1608 | u16 *e = (u16 *)&priv->eeprom; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1609 | u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1610 | u32 r; |
| 1611 | int sz = sizeof(priv->eeprom); |
| 1612 | int rc; |
| 1613 | int i; |
| 1614 | u16 addr; |
| 1615 | |
| 1616 | /* The EEPROM structure has several padding buffers within it |
| 1617 | * and when adding new EEPROM maps is subject to programmer errors |
| 1618 | * which may be very difficult to identify without explicitly |
| 1619 | * checking the resulting size of the eeprom map. */ |
| 1620 | BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); |
| 1621 | |
| 1622 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
| 1623 | IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); |
| 1624 | return -ENOENT; |
| 1625 | } |
| 1626 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1627 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1628 | rc = iwl4965_eeprom_acquire_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1629 | if (rc < 0) { |
Ian Schram | 91e1747 | 2007-10-25 17:15:23 +0800 | [diff] [blame] | 1630 | IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1631 | return -ENOENT; |
| 1632 | } |
| 1633 | |
| 1634 | /* eeprom is an array of 16bit values */ |
| 1635 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1636 | _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1); |
| 1637 | _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1638 | |
| 1639 | for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; |
| 1640 | i += IWL_EEPROM_ACCESS_DELAY) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1641 | r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1642 | if (r & CSR_EEPROM_REG_READ_VALID_MSK) |
| 1643 | break; |
| 1644 | udelay(IWL_EEPROM_ACCESS_DELAY); |
| 1645 | } |
| 1646 | |
| 1647 | if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { |
| 1648 | IWL_ERROR("Time out reading EEPROM[%d]", addr); |
| 1649 | rc = -ETIMEDOUT; |
| 1650 | goto done; |
| 1651 | } |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1652 | e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1653 | } |
| 1654 | rc = 0; |
| 1655 | |
| 1656 | done: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1657 | iwl4965_eeprom_release_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1658 | return rc; |
| 1659 | } |
| 1660 | |
| 1661 | /****************************************************************************** |
| 1662 | * |
| 1663 | * Misc. internal state and helper functions |
| 1664 | * |
| 1665 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1666 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1667 | static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1668 | { |
| 1669 | if (priv->hw_setting.shared_virt) |
| 1670 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1671 | sizeof(struct iwl4965_shared), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1672 | priv->hw_setting.shared_virt, |
| 1673 | priv->hw_setting.shared_phys); |
| 1674 | } |
| 1675 | |
| 1676 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1677 | * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1678 | * |
| 1679 | * return : set the bit for each supported rate insert in ie |
| 1680 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1681 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1682 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1683 | { |
| 1684 | u16 ret_rates = 0, bit; |
| 1685 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1686 | u8 *cnt = ie; |
| 1687 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1688 | |
| 1689 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1690 | if (bit & supported_rate) { |
| 1691 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1692 | rates[*cnt] = iwl4965_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1693 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1694 | (*cnt)++; |
| 1695 | (*left)--; |
| 1696 | if ((*left <= 0) || |
| 1697 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1698 | break; |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | return ret_rates; |
| 1703 | } |
| 1704 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1705 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1706 | * iwl4965_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] | 1707 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1708 | static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1709 | enum ieee80211_band band, |
| 1710 | struct ieee80211_mgmt *frame, |
| 1711 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1712 | { |
| 1713 | int len = 0; |
| 1714 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1715 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1716 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1717 | const struct ieee80211_supported_band *sband = |
| 1718 | iwl4965_get_hw_mode(priv, band); |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1719 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1720 | |
| 1721 | /* Make sure there is enough space for the probe request, |
| 1722 | * two mandatory IEs and the data */ |
| 1723 | left -= 24; |
| 1724 | if (left < 0) |
| 1725 | return 0; |
| 1726 | len += 24; |
| 1727 | |
| 1728 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1729 | memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1730 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1731 | memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1732 | frame->seq_ctrl = 0; |
| 1733 | |
| 1734 | /* fill in our indirect SSID IE */ |
| 1735 | /* ...next IE... */ |
| 1736 | |
| 1737 | left -= 2; |
| 1738 | if (left < 0) |
| 1739 | return 0; |
| 1740 | len += 2; |
| 1741 | pos = &(frame->u.probe_req.variable[0]); |
| 1742 | *pos++ = WLAN_EID_SSID; |
| 1743 | *pos++ = 0; |
| 1744 | |
| 1745 | /* fill in our direct SSID IE... */ |
| 1746 | if (is_direct) { |
| 1747 | /* ...next IE... */ |
| 1748 | left -= 2 + priv->essid_len; |
| 1749 | if (left < 0) |
| 1750 | return 0; |
| 1751 | /* ... fill it in... */ |
| 1752 | *pos++ = WLAN_EID_SSID; |
| 1753 | *pos++ = priv->essid_len; |
| 1754 | memcpy(pos, priv->essid, priv->essid_len); |
| 1755 | pos += priv->essid_len; |
| 1756 | len += 2 + priv->essid_len; |
| 1757 | } |
| 1758 | |
| 1759 | /* fill in supported rate */ |
| 1760 | /* ...next IE... */ |
| 1761 | left -= 2; |
| 1762 | if (left < 0) |
| 1763 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1764 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1765 | /* ... fill it in... */ |
| 1766 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1767 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1768 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1769 | /* exclude 60M rate */ |
| 1770 | active_rates = priv->rates_mask; |
| 1771 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1772 | |
| 1773 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1774 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1775 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1776 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1777 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1778 | active_rates &= ~ret_rates; |
| 1779 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1780 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1781 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1782 | active_rates &= ~ret_rates; |
| 1783 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1784 | len += 2 + *pos; |
| 1785 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1786 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1787 | goto fill_end; |
| 1788 | |
| 1789 | /* fill in supported extended rate */ |
| 1790 | /* ...next IE... */ |
| 1791 | left -= 2; |
| 1792 | if (left < 0) |
| 1793 | return 0; |
| 1794 | /* ... fill it in... */ |
| 1795 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1796 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1797 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1798 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1799 | if (*pos > 0) |
| 1800 | len += 2 + *pos; |
| 1801 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1802 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1803 | if (sband && sband->ht_info.ht_supported) { |
| 1804 | struct ieee80211_ht_cap *ht_cap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1805 | pos += (*pos) + 1; |
| 1806 | *pos++ = WLAN_EID_HT_CAPABILITY; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1807 | *pos++ = sizeof(struct ieee80211_ht_cap); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1808 | ht_cap = (struct ieee80211_ht_cap *)pos; |
| 1809 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 1810 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 1811 | ht_cap->ampdu_params_info =(sband->ht_info.ampdu_factor & |
| 1812 | IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 1813 | ((sband->ht_info.ampdu_density << 2) & |
| 1814 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1815 | len += 2 + sizeof(struct ieee80211_ht_cap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1816 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1817 | #endif /*CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1818 | |
| 1819 | fill_end: |
| 1820 | return (u16)len; |
| 1821 | } |
| 1822 | |
| 1823 | /* |
| 1824 | * QoS support |
| 1825 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1826 | static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv, |
| 1827 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1828 | { |
| 1829 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1830 | return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
| 1831 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1834 | static void iwl4965_reset_qos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1835 | { |
| 1836 | u16 cw_min = 15; |
| 1837 | u16 cw_max = 1023; |
| 1838 | u8 aifs = 2; |
| 1839 | u8 is_legacy = 0; |
| 1840 | unsigned long flags; |
| 1841 | int i; |
| 1842 | |
| 1843 | spin_lock_irqsave(&priv->lock, flags); |
| 1844 | priv->qos_data.qos_active = 0; |
| 1845 | |
| 1846 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { |
| 1847 | if (priv->qos_data.qos_enable) |
| 1848 | priv->qos_data.qos_active = 1; |
| 1849 | if (!(priv->active_rate & 0xfff0)) { |
| 1850 | cw_min = 31; |
| 1851 | is_legacy = 1; |
| 1852 | } |
| 1853 | } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1854 | if (priv->qos_data.qos_enable) |
| 1855 | priv->qos_data.qos_active = 1; |
| 1856 | } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 1857 | cw_min = 31; |
| 1858 | is_legacy = 1; |
| 1859 | } |
| 1860 | |
| 1861 | if (priv->qos_data.qos_active) |
| 1862 | aifs = 3; |
| 1863 | |
| 1864 | priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); |
| 1865 | priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); |
| 1866 | priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; |
| 1867 | priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; |
| 1868 | priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; |
| 1869 | |
| 1870 | if (priv->qos_data.qos_active) { |
| 1871 | i = 1; |
| 1872 | priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); |
| 1873 | priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); |
| 1874 | priv->qos_data.def_qos_parm.ac[i].aifsn = 7; |
| 1875 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 1876 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1877 | |
| 1878 | i = 2; |
| 1879 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1880 | cpu_to_le16((cw_min + 1) / 2 - 1); |
| 1881 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1882 | cpu_to_le16(cw_max); |
| 1883 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 1884 | if (is_legacy) |
| 1885 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1886 | cpu_to_le16(6016); |
| 1887 | else |
| 1888 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1889 | cpu_to_le16(3008); |
| 1890 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1891 | |
| 1892 | i = 3; |
| 1893 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1894 | cpu_to_le16((cw_min + 1) / 4 - 1); |
| 1895 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1896 | cpu_to_le16((cw_max + 1) / 2 - 1); |
| 1897 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 1898 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1899 | if (is_legacy) |
| 1900 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1901 | cpu_to_le16(3264); |
| 1902 | else |
| 1903 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1904 | cpu_to_le16(1504); |
| 1905 | } else { |
| 1906 | for (i = 1; i < 4; i++) { |
| 1907 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1908 | cpu_to_le16(cw_min); |
| 1909 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1910 | cpu_to_le16(cw_max); |
| 1911 | priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; |
| 1912 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 1913 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1914 | } |
| 1915 | } |
| 1916 | IWL_DEBUG_QOS("set QoS to default \n"); |
| 1917 | |
| 1918 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1919 | } |
| 1920 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1921 | static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1922 | { |
| 1923 | unsigned long flags; |
| 1924 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1925 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1926 | return; |
| 1927 | |
| 1928 | if (!priv->qos_data.qos_enable) |
| 1929 | return; |
| 1930 | |
| 1931 | spin_lock_irqsave(&priv->lock, flags); |
| 1932 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1933 | |
| 1934 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1935 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1936 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1937 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1938 | if (priv->qos_data.qos_active) |
| 1939 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1940 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1941 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1942 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 1943 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1944 | priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1945 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1946 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1947 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1948 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1949 | if (force || iwl4965_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1950 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 1951 | priv->qos_data.qos_active, |
| 1952 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1953 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1954 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1955 | &(priv->qos_data.def_qos_parm)); |
| 1956 | } |
| 1957 | } |
| 1958 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1959 | /* |
| 1960 | * Power management (not Tx power!) functions |
| 1961 | */ |
| 1962 | #define MSEC_TO_USEC 1024 |
| 1963 | |
| 1964 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 1965 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
| 1966 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 1967 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 1968 | __constant_cpu_to_le32(X1), \ |
| 1969 | __constant_cpu_to_le32(X2), \ |
| 1970 | __constant_cpu_to_le32(X3), \ |
| 1971 | __constant_cpu_to_le32(X4)} |
| 1972 | |
| 1973 | |
| 1974 | /* default power management (not Tx power) table values */ |
| 1975 | /* for tim 0-10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1976 | static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1977 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1978 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 1979 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 1980 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 1981 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 1982 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 1983 | }; |
| 1984 | |
| 1985 | /* for tim > 10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1986 | static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1987 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1988 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 1989 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 1990 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 1991 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 1992 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 1993 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 1994 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 1995 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 1996 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 1997 | }; |
| 1998 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1999 | int iwl4965_power_init_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2000 | { |
| 2001 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2002 | struct iwl4965_power_mgr *pow_data; |
| 2003 | int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2004 | u16 pci_pm; |
| 2005 | |
| 2006 | IWL_DEBUG_POWER("Initialize power \n"); |
| 2007 | |
| 2008 | pow_data = &(priv->power_data); |
| 2009 | |
| 2010 | memset(pow_data, 0, sizeof(*pow_data)); |
| 2011 | |
| 2012 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 2013 | pow_data->dtim_val = 0xffff; |
| 2014 | |
| 2015 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 2016 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 2017 | |
| 2018 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 2019 | if (rc != 0) |
| 2020 | return 0; |
| 2021 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2022 | struct iwl4965_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2023 | |
| 2024 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 2025 | |
| 2026 | for (i = 0; i < IWL_POWER_AC; i++) { |
| 2027 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 2028 | |
| 2029 | if (pci_pm & 0x1) |
| 2030 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 2031 | else |
| 2032 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 2033 | } |
| 2034 | } |
| 2035 | return rc; |
| 2036 | } |
| 2037 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2038 | static int iwl4965_update_power_cmd(struct iwl4965_priv *priv, |
| 2039 | struct iwl4965_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2040 | { |
| 2041 | int rc = 0, i; |
| 2042 | u8 skip; |
| 2043 | u32 max_sleep = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2044 | struct iwl4965_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2045 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2046 | struct iwl4965_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2047 | |
| 2048 | if (mode > IWL_POWER_INDEX_5) { |
| 2049 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 2050 | return -1; |
| 2051 | } |
| 2052 | pow_data = &(priv->power_data); |
| 2053 | |
| 2054 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 2055 | range = &pow_data->pwr_range_0[0]; |
| 2056 | else |
| 2057 | range = &pow_data->pwr_range_1[1]; |
| 2058 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2059 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2060 | |
| 2061 | #ifdef IWL_MAC80211_DISABLE |
| 2062 | if (priv->assoc_network != NULL) { |
| 2063 | unsigned long flags; |
| 2064 | |
| 2065 | period = priv->assoc_network->tim.tim_period; |
| 2066 | } |
| 2067 | #endif /*IWL_MAC80211_DISABLE */ |
| 2068 | skip = range[mode].no_dtim; |
| 2069 | |
| 2070 | if (period == 0) { |
| 2071 | period = 1; |
| 2072 | skip = 0; |
| 2073 | } |
| 2074 | |
| 2075 | if (skip == 0) { |
| 2076 | max_sleep = period; |
| 2077 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2078 | } else { |
| 2079 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 2080 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 2081 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2082 | } |
| 2083 | |
| 2084 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 2085 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 2086 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 2087 | } |
| 2088 | |
| 2089 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 2090 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 2091 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 2092 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 2093 | le32_to_cpu(cmd->sleep_interval[0]), |
| 2094 | le32_to_cpu(cmd->sleep_interval[1]), |
| 2095 | le32_to_cpu(cmd->sleep_interval[2]), |
| 2096 | le32_to_cpu(cmd->sleep_interval[3]), |
| 2097 | le32_to_cpu(cmd->sleep_interval[4])); |
| 2098 | |
| 2099 | return rc; |
| 2100 | } |
| 2101 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2102 | static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2103 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 2104 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2105 | int rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2106 | struct iwl4965_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2107 | |
| 2108 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2109 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2110 | * else user level */ |
| 2111 | switch (mode) { |
| 2112 | case IWL_POWER_BATTERY: |
| 2113 | final_mode = IWL_POWER_INDEX_3; |
| 2114 | break; |
| 2115 | case IWL_POWER_AC: |
| 2116 | final_mode = IWL_POWER_MODE_CAM; |
| 2117 | break; |
| 2118 | default: |
| 2119 | final_mode = mode; |
| 2120 | break; |
| 2121 | } |
| 2122 | |
| 2123 | cmd.keep_alive_beacons = 0; |
| 2124 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2125 | iwl4965_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2126 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2127 | rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2128 | |
| 2129 | if (final_mode == IWL_POWER_MODE_CAM) |
| 2130 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 2131 | else |
| 2132 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 2133 | |
| 2134 | return rc; |
| 2135 | } |
| 2136 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2137 | int iwl4965_is_network_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2138 | { |
| 2139 | /* Filter incoming packets to determine if they are targeted toward |
| 2140 | * this network, discarding packets coming from ourselves */ |
| 2141 | switch (priv->iw_mode) { |
| 2142 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 2143 | /* packets from our adapter are dropped (echo) */ |
| 2144 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 2145 | return 0; |
| 2146 | /* {broad,multi}cast packets to our IBSS go through */ |
| 2147 | if (is_multicast_ether_addr(header->addr1)) |
| 2148 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 2149 | /* packets to our adapter go through */ |
| 2150 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2151 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 2152 | /* packets from our adapter are dropped (echo) */ |
| 2153 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 2154 | return 0; |
| 2155 | /* {broad,multi}cast packets to our BSS go through */ |
| 2156 | if (is_multicast_ether_addr(header->addr1)) |
| 2157 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 2158 | /* packets to our adapter go through */ |
| 2159 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2160 | } |
| 2161 | |
| 2162 | return 1; |
| 2163 | } |
| 2164 | |
| 2165 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2166 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2167 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2168 | { |
| 2169 | switch (status & TX_STATUS_MSK) { |
| 2170 | case TX_STATUS_SUCCESS: |
| 2171 | return "SUCCESS"; |
| 2172 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 2173 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 2174 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 2175 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 2176 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 2177 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 2178 | TX_STATUS_ENTRY(DEST_PS); |
| 2179 | TX_STATUS_ENTRY(ABORTED); |
| 2180 | TX_STATUS_ENTRY(BT_RETRY); |
| 2181 | TX_STATUS_ENTRY(STA_INVALID); |
| 2182 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 2183 | TX_STATUS_ENTRY(TID_DISABLE); |
| 2184 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 2185 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 2186 | TX_STATUS_ENTRY(TX_LOCKED); |
| 2187 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 2188 | } |
| 2189 | |
| 2190 | return "UNKNOWN"; |
| 2191 | } |
| 2192 | |
| 2193 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2194 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2195 | * |
| 2196 | * NOTE: priv->mutex is not required before calling this function |
| 2197 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2198 | static int iwl4965_scan_cancel(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2199 | { |
| 2200 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 2201 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2202 | return 0; |
| 2203 | } |
| 2204 | |
| 2205 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2206 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2207 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 2208 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2209 | queue_work(priv->workqueue, &priv->abort_scan); |
| 2210 | |
| 2211 | } else |
| 2212 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 2213 | |
| 2214 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2215 | } |
| 2216 | |
| 2217 | return 0; |
| 2218 | } |
| 2219 | |
| 2220 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2221 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2222 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 2223 | * |
| 2224 | * NOTE: priv->mutex must be held before calling this function |
| 2225 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2226 | static int iwl4965_scan_cancel_timeout(struct iwl4965_priv *priv, unsigned long ms) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2227 | { |
| 2228 | unsigned long now = jiffies; |
| 2229 | int ret; |
| 2230 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2231 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2232 | if (ret && ms) { |
| 2233 | mutex_unlock(&priv->mutex); |
| 2234 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 2235 | test_bit(STATUS_SCANNING, &priv->status)) |
| 2236 | msleep(1); |
| 2237 | mutex_lock(&priv->mutex); |
| 2238 | |
| 2239 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2240 | } |
| 2241 | |
| 2242 | return ret; |
| 2243 | } |
| 2244 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2245 | static void iwl4965_sequence_reset(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2246 | { |
| 2247 | /* Reset ieee stats */ |
| 2248 | |
| 2249 | /* We don't reset the net_device_stats (ieee->stats) on |
| 2250 | * re-association */ |
| 2251 | |
| 2252 | priv->last_seq_num = -1; |
| 2253 | priv->last_frag_num = -1; |
| 2254 | priv->last_packet_time = 0; |
| 2255 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2256 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 2260 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 2261 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2262 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2263 | { |
| 2264 | u16 new_val = 0; |
| 2265 | u16 beacon_factor = 0; |
| 2266 | |
| 2267 | beacon_factor = |
| 2268 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 2269 | / MAX_UCODE_BEACON_INTERVAL; |
| 2270 | new_val = beacon_val / beacon_factor; |
| 2271 | |
| 2272 | return cpu_to_le16(new_val); |
| 2273 | } |
| 2274 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2275 | static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2276 | { |
| 2277 | u64 interval_tm_unit; |
| 2278 | u64 tsf, result; |
| 2279 | unsigned long flags; |
| 2280 | struct ieee80211_conf *conf = NULL; |
| 2281 | u16 beacon_int = 0; |
| 2282 | |
| 2283 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2284 | |
| 2285 | spin_lock_irqsave(&priv->lock, flags); |
| 2286 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1); |
| 2287 | priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0); |
| 2288 | |
| 2289 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 2290 | |
| 2291 | tsf = priv->timestamp1; |
| 2292 | tsf = ((tsf << 32) | priv->timestamp0); |
| 2293 | |
| 2294 | beacon_int = priv->beacon_int; |
| 2295 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2296 | |
| 2297 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 2298 | if (beacon_int == 0) { |
| 2299 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 2300 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 2301 | } else { |
| 2302 | priv->rxon_timing.beacon_interval = |
| 2303 | cpu_to_le16(beacon_int); |
| 2304 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2305 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2306 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2307 | } |
| 2308 | |
| 2309 | priv->rxon_timing.atim_window = 0; |
| 2310 | } else { |
| 2311 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2312 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2313 | /* TODO: we need to get atim_window from upper stack |
| 2314 | * for now we set to 0 */ |
| 2315 | priv->rxon_timing.atim_window = 0; |
| 2316 | } |
| 2317 | |
| 2318 | interval_tm_unit = |
| 2319 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 2320 | result = do_div(tsf, interval_tm_unit); |
| 2321 | priv->rxon_timing.beacon_init_val = |
| 2322 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 2323 | |
| 2324 | IWL_DEBUG_ASSOC |
| 2325 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 2326 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 2327 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 2328 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 2329 | } |
| 2330 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2331 | static int iwl4965_scan_initiate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2332 | { |
| 2333 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2334 | IWL_ERROR("APs don't scan.\n"); |
| 2335 | return 0; |
| 2336 | } |
| 2337 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2338 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2339 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 2340 | return -EIO; |
| 2341 | } |
| 2342 | |
| 2343 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2344 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 2345 | return -EAGAIN; |
| 2346 | } |
| 2347 | |
| 2348 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2349 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 2350 | "Queuing.\n"); |
| 2351 | return -EAGAIN; |
| 2352 | } |
| 2353 | |
| 2354 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 2355 | priv->scan_bands = 2; |
| 2356 | set_bit(STATUS_SCANNING, &priv->status); |
| 2357 | priv->scan_start = jiffies; |
| 2358 | priv->scan_pass_start = priv->scan_start; |
| 2359 | |
| 2360 | queue_work(priv->workqueue, &priv->request_scan); |
| 2361 | |
| 2362 | return 0; |
| 2363 | } |
| 2364 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2365 | static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv *priv, int hw_decrypt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2366 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2367 | struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2368 | |
| 2369 | if (hw_decrypt) |
| 2370 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 2371 | else |
| 2372 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 2373 | |
| 2374 | return 0; |
| 2375 | } |
| 2376 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2377 | static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, |
| 2378 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2379 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2380 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2381 | priv->staging_rxon.flags &= |
| 2382 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 2383 | | RXON_FLG_CCK_MSK); |
| 2384 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2385 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2386 | /* Copied from iwl4965_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2387 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2388 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2389 | else |
| 2390 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2391 | |
| 2392 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2393 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2394 | |
| 2395 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 2396 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 2397 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2402 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2403 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2404 | static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2405 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2406 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2407 | |
| 2408 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 2409 | |
| 2410 | switch (priv->iw_mode) { |
| 2411 | case IEEE80211_IF_TYPE_AP: |
| 2412 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 2413 | break; |
| 2414 | |
| 2415 | case IEEE80211_IF_TYPE_STA: |
| 2416 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 2417 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 2418 | break; |
| 2419 | |
| 2420 | case IEEE80211_IF_TYPE_IBSS: |
| 2421 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 2422 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2423 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 2424 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2425 | break; |
| 2426 | |
| 2427 | case IEEE80211_IF_TYPE_MNTR: |
| 2428 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 2429 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 2430 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2431 | break; |
| 2432 | } |
| 2433 | |
| 2434 | #if 0 |
| 2435 | /* TODO: Figure out when short_preamble would be set and cache from |
| 2436 | * that */ |
| 2437 | if (!hw_to_local(priv->hw)->short_preamble) |
| 2438 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2439 | else |
| 2440 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2441 | #endif |
| 2442 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2443 | ch_info = iwl4965_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2444 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2445 | |
| 2446 | if (!ch_info) |
| 2447 | ch_info = &priv->channel_info[0]; |
| 2448 | |
| 2449 | /* |
| 2450 | * in some case A channels are all non IBSS |
| 2451 | * in this case force B/G channel |
| 2452 | */ |
| 2453 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 2454 | !(is_channel_ibss(ch_info))) |
| 2455 | ch_info = &priv->channel_info[0]; |
| 2456 | |
| 2457 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2458 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2459 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2460 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2461 | |
| 2462 | priv->staging_rxon.ofdm_basic_rates = |
| 2463 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2464 | priv->staging_rxon.cck_basic_rates = |
| 2465 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2466 | |
| 2467 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 2468 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 2469 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2470 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 2471 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 2472 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 2473 | iwl4965_set_rxon_chain(priv); |
| 2474 | } |
| 2475 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2476 | static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2477 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2478 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2479 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2480 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2481 | ch_info = iwl4965_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2482 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2483 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2484 | |
| 2485 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 2486 | IWL_ERROR("channel %d not IBSS channel\n", |
| 2487 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2488 | return -EINVAL; |
| 2489 | } |
| 2490 | } |
| 2491 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2492 | priv->iw_mode = mode; |
| 2493 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2494 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2495 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2496 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2497 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2498 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2499 | /* dont commit rxon if rf-kill is on*/ |
| 2500 | if (!iwl4965_is_ready_rf(priv)) |
| 2501 | return -EAGAIN; |
| 2502 | |
| 2503 | cancel_delayed_work(&priv->scan_check); |
| 2504 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 2505 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 2506 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2507 | return -EAGAIN; |
| 2508 | } |
| 2509 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2510 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2511 | |
| 2512 | return 0; |
| 2513 | } |
| 2514 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2515 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2516 | struct ieee80211_tx_control *ctl, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2517 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2518 | struct sk_buff *skb_frag, |
| 2519 | int last_frag) |
| 2520 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2521 | struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2522 | |
| 2523 | switch (keyinfo->alg) { |
| 2524 | case ALG_CCMP: |
| 2525 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2526 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
| 2527 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 2528 | break; |
| 2529 | |
| 2530 | case ALG_TKIP: |
| 2531 | #if 0 |
| 2532 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2533 | |
| 2534 | if (last_frag) |
| 2535 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2536 | 8); |
| 2537 | else |
| 2538 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2539 | #endif |
| 2540 | break; |
| 2541 | |
| 2542 | case ALG_WEP: |
| 2543 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
| 2544 | (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
| 2545 | |
| 2546 | if (keyinfo->keylen == 13) |
| 2547 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2548 | |
| 2549 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2550 | |
| 2551 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
| 2552 | "with key %d\n", ctl->key_idx); |
| 2553 | break; |
| 2554 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2555 | default: |
| 2556 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 2557 | break; |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | /* |
| 2562 | * handle build REPLY_TX command notification. |
| 2563 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2564 | static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv, |
| 2565 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2566 | struct ieee80211_tx_control *ctrl, |
| 2567 | struct ieee80211_hdr *hdr, |
| 2568 | int is_unicast, u8 std_id) |
| 2569 | { |
| 2570 | __le16 *qc; |
| 2571 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2572 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 2573 | |
| 2574 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2575 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 2576 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 2577 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 2578 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2579 | if (ieee80211_is_probe_response(fc) && |
| 2580 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2581 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2582 | } else { |
| 2583 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2584 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2585 | } |
| 2586 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2587 | if (ieee80211_is_back_request(fc)) |
| 2588 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 2589 | |
| 2590 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2591 | cmd->cmd.tx.sta_id = std_id; |
| 2592 | if (ieee80211_get_morefrag(hdr)) |
| 2593 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2594 | |
| 2595 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2596 | if (qc) { |
| 2597 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 2598 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 2599 | } else |
| 2600 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2601 | |
| 2602 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 2603 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2604 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 2605 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 2606 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2607 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2608 | } |
| 2609 | |
| 2610 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2611 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2612 | |
| 2613 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 2614 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 2615 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 2616 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2617 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2618 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2619 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2620 | } else |
| 2621 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
| 2622 | |
| 2623 | cmd->cmd.tx.driver_txop = 0; |
| 2624 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2625 | cmd->cmd.tx.next_frame_len = 0; |
| 2626 | } |
| 2627 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2628 | /** |
| 2629 | * iwl4965_get_sta_id - Find station's index within station table |
| 2630 | * |
| 2631 | * If new IBSS station, create new entry in station table |
| 2632 | */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2633 | static int iwl4965_get_sta_id(struct iwl4965_priv *priv, |
| 2634 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2635 | { |
| 2636 | int sta_id; |
| 2637 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2638 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2639 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2640 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2641 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2642 | is_multicast_ether_addr(hdr->addr1)) |
| 2643 | return priv->hw_setting.bcast_sta_id; |
| 2644 | |
| 2645 | switch (priv->iw_mode) { |
| 2646 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2647 | /* If we are a client station in a BSS network, use the special |
| 2648 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2649 | case IEEE80211_IF_TYPE_STA: |
| 2650 | return IWL_AP_ID; |
| 2651 | |
| 2652 | /* If we are an AP, then find the station, or use BCAST */ |
| 2653 | case IEEE80211_IF_TYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2654 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2655 | if (sta_id != IWL_INVALID_STATION) |
| 2656 | return sta_id; |
| 2657 | return priv->hw_setting.bcast_sta_id; |
| 2658 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2659 | /* If this frame is going out to an IBSS network, find the station, |
| 2660 | * or create a new station table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2661 | case IEEE80211_IF_TYPE_IBSS: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2662 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2663 | if (sta_id != IWL_INVALID_STATION) |
| 2664 | return sta_id; |
| 2665 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2666 | /* Create new station table entry */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 2667 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, |
| 2668 | 0, CMD_ASYNC, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2669 | |
| 2670 | if (sta_id != IWL_INVALID_STATION) |
| 2671 | return sta_id; |
| 2672 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2673 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2674 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2675 | print_mac(mac, hdr->addr1)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2676 | iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2677 | return priv->hw_setting.bcast_sta_id; |
| 2678 | |
| 2679 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2680 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2681 | return priv->hw_setting.bcast_sta_id; |
| 2682 | } |
| 2683 | } |
| 2684 | |
| 2685 | /* |
| 2686 | * start REPLY_TX command process |
| 2687 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2688 | static int iwl4965_tx_skb(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2689 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 2690 | { |
| 2691 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2692 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2693 | u32 *control_flags; |
| 2694 | int txq_id = ctl->queue; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2695 | struct iwl4965_tx_queue *txq = NULL; |
| 2696 | struct iwl4965_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2697 | dma_addr_t phys_addr; |
| 2698 | dma_addr_t txcmd_phys; |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2699 | dma_addr_t scratch_phys; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2700 | struct iwl4965_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2701 | u16 len, idx, len_org; |
| 2702 | u8 id, hdr_len, unicast; |
| 2703 | u8 sta_id; |
| 2704 | u16 seq_number = 0; |
| 2705 | u16 fc; |
| 2706 | __le16 *qc; |
| 2707 | u8 wait_write_ptr = 0; |
| 2708 | unsigned long flags; |
| 2709 | int rc; |
| 2710 | |
| 2711 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2712 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2713 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2714 | goto drop_unlock; |
| 2715 | } |
| 2716 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2717 | if (!priv->vif) { |
| 2718 | IWL_DEBUG_DROP("Dropping - !priv->vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2719 | goto drop_unlock; |
| 2720 | } |
| 2721 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2722 | if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2723 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 2724 | goto drop_unlock; |
| 2725 | } |
| 2726 | |
| 2727 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2728 | id = 0; |
| 2729 | |
| 2730 | fc = le16_to_cpu(hdr->frame_control); |
| 2731 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2732 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2733 | if (ieee80211_is_auth(fc)) |
| 2734 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 2735 | else if (ieee80211_is_assoc_request(fc)) |
| 2736 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 2737 | else if (ieee80211_is_reassoc_request(fc)) |
| 2738 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2739 | #endif |
| 2740 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2741 | /* drop all data frame if we are not associated */ |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 2742 | if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && |
| 2743 | (!iwl4965_is_associated(priv) || |
Reinette Chatre | a647724 | 2008-02-14 10:40:28 -0800 | [diff] [blame] | 2744 | ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) || |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 2745 | !priv->assoc_station_added)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2746 | IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2747 | goto drop_unlock; |
| 2748 | } |
| 2749 | |
| 2750 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2751 | |
| 2752 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2753 | |
| 2754 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2755 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2756 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2757 | DECLARE_MAC_BUF(mac); |
| 2758 | |
| 2759 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 2760 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2761 | goto drop; |
| 2762 | } |
| 2763 | |
| 2764 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2765 | |
| 2766 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2767 | if (qc) { |
| 2768 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2769 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 2770 | IEEE80211_SCTL_SEQ; |
| 2771 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2772 | (hdr->seq_ctrl & |
| 2773 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2774 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2775 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2776 | /* aggregation is on for this <sta,tid> */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2777 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2778 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2779 | priv->stations[sta_id].tid[tid].tfds_in_queue++; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2780 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2781 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2782 | |
| 2783 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2784 | txq = &priv->txq[txq_id]; |
| 2785 | q = &txq->q; |
| 2786 | |
| 2787 | spin_lock_irqsave(&priv->lock, flags); |
| 2788 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2789 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2790 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2791 | memset(tfd, 0, sizeof(*tfd)); |
| 2792 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2793 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2794 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2795 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2796 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2797 | txq->txb[q->write_ptr].skb[0] = skb; |
| 2798 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2799 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2800 | |
| 2801 | /* Set up first empty entry in queue's array of Tx/cmd buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2802 | out_cmd = &txq->cmd[idx]; |
| 2803 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2804 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2805 | |
| 2806 | /* |
| 2807 | * Set up the Tx-command (not MAC!) header. |
| 2808 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2809 | * after Tx, uCode's Tx response will return this value so driver can |
| 2810 | * locate the frame within the tx queue and do post-tx processing. |
| 2811 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2812 | out_cmd->hdr.cmd = REPLY_TX; |
| 2813 | 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] | 2814 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2815 | |
| 2816 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2817 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 2818 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2819 | /* |
| 2820 | * Use the first empty entry in this queue's command buffer array |
| 2821 | * to contain the Tx command and MAC header concatenated together |
| 2822 | * (payload data will be in another buffer). |
| 2823 | * Size of this varies, due to varying MAC header length. |
| 2824 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2825 | * of the MAC header (device reads on dword boundaries). |
| 2826 | * We'll tell device about this padding later. |
| 2827 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2828 | len = priv->hw_setting.tx_cmd_len + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2829 | sizeof(struct iwl4965_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2830 | |
| 2831 | len_org = len; |
| 2832 | len = (len + 3) & ~3; |
| 2833 | |
| 2834 | if (len_org != len) |
| 2835 | len_org = 1; |
| 2836 | else |
| 2837 | len_org = 0; |
| 2838 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2839 | /* Physical address of this Tx command's header (not MAC header!), |
| 2840 | * within command buffer array. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2841 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx + |
| 2842 | offsetof(struct iwl4965_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2843 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2844 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2845 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2846 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2847 | |
| 2848 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2849 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2850 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2851 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2852 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2853 | len = skb->len - hdr_len; |
| 2854 | if (len) { |
| 2855 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2856 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2857 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2860 | /* Tell 4965 about any 2-byte padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2861 | if (len_org) |
| 2862 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 2863 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2864 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2865 | len = (u16)skb->len; |
| 2866 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 2867 | |
| 2868 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2869 | iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2870 | |
| 2871 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2872 | iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2873 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2874 | scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) + |
| 2875 | offsetof(struct iwl4965_tx_cmd, scratch); |
| 2876 | out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 2877 | out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys); |
| 2878 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2879 | if (!ieee80211_get_morefrag(hdr)) { |
| 2880 | txq->need_update = 1; |
| 2881 | if (qc) { |
| 2882 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2883 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 2884 | } |
| 2885 | } else { |
| 2886 | wait_write_ptr = 1; |
| 2887 | txq->need_update = 0; |
| 2888 | } |
| 2889 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2890 | iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2891 | sizeof(out_cmd->cmd.tx)); |
| 2892 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2893 | iwl4965_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2894 | ieee80211_get_hdrlen(fc)); |
| 2895 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2896 | /* Set up entry for this TFD in Tx byte-count array */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2897 | iwl4965_tx_queue_update_wr_ptr(priv, txq, len); |
| 2898 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2899 | /* Tell device the write index *just past* this latest filled TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2900 | q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 2901 | rc = iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2902 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2903 | |
| 2904 | if (rc) |
| 2905 | return rc; |
| 2906 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2907 | if ((iwl4965_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2908 | && priv->mac80211_registered) { |
| 2909 | if (wait_write_ptr) { |
| 2910 | spin_lock_irqsave(&priv->lock, flags); |
| 2911 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2912 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2913 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2914 | } |
| 2915 | |
| 2916 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 2917 | } |
| 2918 | |
| 2919 | return 0; |
| 2920 | |
| 2921 | drop_unlock: |
| 2922 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2923 | drop: |
| 2924 | return -1; |
| 2925 | } |
| 2926 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2927 | static void iwl4965_set_rate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2928 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2929 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2930 | struct ieee80211_rate *rate; |
| 2931 | int i; |
| 2932 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2933 | hw = iwl4965_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 2934 | if (!hw) { |
| 2935 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 2936 | return; |
| 2937 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2938 | |
| 2939 | priv->active_rate = 0; |
| 2940 | priv->active_rate_basic = 0; |
| 2941 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2942 | for (i = 0; i < hw->n_bitrates; i++) { |
| 2943 | rate = &(hw->bitrates[i]); |
| 2944 | if (rate->hw_value < IWL_RATE_COUNT) |
| 2945 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2949 | priv->active_rate, priv->active_rate_basic); |
| 2950 | |
| 2951 | /* |
| 2952 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2953 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2954 | * OFDM |
| 2955 | */ |
| 2956 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 2957 | priv->staging_rxon.cck_basic_rates = |
| 2958 | ((priv->active_rate_basic & |
| 2959 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2960 | else |
| 2961 | priv->staging_rxon.cck_basic_rates = |
| 2962 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2963 | |
| 2964 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 2965 | priv->staging_rxon.ofdm_basic_rates = |
| 2966 | ((priv->active_rate_basic & |
| 2967 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2968 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2969 | else |
| 2970 | priv->staging_rxon.ofdm_basic_rates = |
| 2971 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2972 | } |
| 2973 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2974 | static void iwl4965_radio_kill_sw(struct iwl4965_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2975 | { |
| 2976 | unsigned long flags; |
| 2977 | |
| 2978 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2979 | return; |
| 2980 | |
| 2981 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2982 | disable_radio ? "OFF" : "ON"); |
| 2983 | |
| 2984 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2985 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2986 | /* FIXME: This is a workaround for AP */ |
| 2987 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 2988 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2989 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2990 | CSR_UCODE_SW_BIT_RFKILL); |
| 2991 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2992 | iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2993 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2994 | } |
| 2995 | return; |
| 2996 | } |
| 2997 | |
| 2998 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2999 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3000 | |
| 3001 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3002 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3003 | |
| 3004 | /* wake up ucode */ |
| 3005 | msleep(10); |
| 3006 | |
| 3007 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3008 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 3009 | if (!iwl4965_grab_nic_access(priv)) |
| 3010 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3011 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3012 | |
| 3013 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 3014 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3015 | "disabled by HW switch\n"); |
| 3016 | return; |
| 3017 | } |
| 3018 | |
| 3019 | queue_work(priv->workqueue, &priv->restart); |
| 3020 | return; |
| 3021 | } |
| 3022 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3023 | void iwl4965_set_decrypted_flag(struct iwl4965_priv *priv, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3024 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 3025 | { |
| 3026 | u16 fc = |
| 3027 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 3028 | |
| 3029 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 3030 | return; |
| 3031 | |
| 3032 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 3033 | return; |
| 3034 | |
| 3035 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 3036 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 3037 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 3038 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3039 | RX_RES_STATUS_BAD_ICV_MIC) |
| 3040 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 3041 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 3042 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 3043 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3044 | RX_RES_STATUS_DECRYPT_OK) { |
| 3045 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 3046 | stats->flag |= RX_FLAG_DECRYPTED; |
| 3047 | } |
| 3048 | break; |
| 3049 | |
| 3050 | default: |
| 3051 | break; |
| 3052 | } |
| 3053 | } |
| 3054 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3055 | |
| 3056 | #define IWL_PACKET_RETRY_TIME HZ |
| 3057 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3058 | int iwl4965_is_duplicate_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3059 | { |
| 3060 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 3061 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 3062 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 3063 | u16 *last_seq, *last_frag; |
| 3064 | unsigned long *last_time; |
| 3065 | |
| 3066 | switch (priv->iw_mode) { |
| 3067 | case IEEE80211_IF_TYPE_IBSS:{ |
| 3068 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3069 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3070 | u8 *mac = header->addr2; |
| 3071 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 3072 | |
| 3073 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3074 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3075 | if (!compare_ether_addr(entry->mac, mac)) |
| 3076 | break; |
| 3077 | } |
| 3078 | if (p == &priv->ibss_mac_hash[index]) { |
| 3079 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 3080 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3081 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3082 | return 0; |
| 3083 | } |
| 3084 | memcpy(entry->mac, mac, ETH_ALEN); |
| 3085 | entry->seq_num = seq; |
| 3086 | entry->frag_num = frag; |
| 3087 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3088 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3089 | return 0; |
| 3090 | } |
| 3091 | last_seq = &entry->seq_num; |
| 3092 | last_frag = &entry->frag_num; |
| 3093 | last_time = &entry->packet_time; |
| 3094 | break; |
| 3095 | } |
| 3096 | case IEEE80211_IF_TYPE_STA: |
| 3097 | last_seq = &priv->last_seq_num; |
| 3098 | last_frag = &priv->last_frag_num; |
| 3099 | last_time = &priv->last_packet_time; |
| 3100 | break; |
| 3101 | default: |
| 3102 | return 0; |
| 3103 | } |
| 3104 | if ((*last_seq == seq) && |
| 3105 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 3106 | if (*last_frag == frag) |
| 3107 | goto drop; |
| 3108 | if (*last_frag + 1 != frag) |
| 3109 | /* out-of-order fragment */ |
| 3110 | goto drop; |
| 3111 | } else |
| 3112 | *last_seq = seq; |
| 3113 | |
| 3114 | *last_frag = frag; |
| 3115 | *last_time = jiffies; |
| 3116 | return 0; |
| 3117 | |
| 3118 | drop: |
| 3119 | return 1; |
| 3120 | } |
| 3121 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3122 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3123 | |
| 3124 | #include "iwl-spectrum.h" |
| 3125 | |
| 3126 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 3127 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 3128 | #define TIME_UNIT 1024 |
| 3129 | |
| 3130 | /* |
| 3131 | * extended beacon time format |
| 3132 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 3133 | * the high 1 byte is the beacon counts |
| 3134 | * the lower 3 bytes is the time in usec within one beacon interval |
| 3135 | */ |
| 3136 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3137 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3138 | { |
| 3139 | u32 quot; |
| 3140 | u32 rem; |
| 3141 | u32 interval = beacon_interval * 1024; |
| 3142 | |
| 3143 | if (!interval || !usec) |
| 3144 | return 0; |
| 3145 | |
| 3146 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 3147 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 3148 | |
| 3149 | return (quot << 24) + rem; |
| 3150 | } |
| 3151 | |
| 3152 | /* base is usually what we get from ucode with each received frame, |
| 3153 | * the same as HW timer counter counting down |
| 3154 | */ |
| 3155 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3156 | static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3157 | { |
| 3158 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 3159 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 3160 | u32 interval = beacon_interval * TIME_UNIT; |
| 3161 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 3162 | (addon & BEACON_TIME_MASK_HIGH); |
| 3163 | |
| 3164 | if (base_low > addon_low) |
| 3165 | res += base_low - addon_low; |
| 3166 | else if (base_low < addon_low) { |
| 3167 | res += interval + base_low - addon_low; |
| 3168 | res += (1 << 24); |
| 3169 | } else |
| 3170 | res += (1 << 24); |
| 3171 | |
| 3172 | return cpu_to_le32(res); |
| 3173 | } |
| 3174 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3175 | static int iwl4965_get_measurement(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3176 | struct ieee80211_measurement_params *params, |
| 3177 | u8 type) |
| 3178 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3179 | struct iwl4965_spectrum_cmd spectrum; |
| 3180 | struct iwl4965_rx_packet *res; |
| 3181 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3182 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 3183 | .data = (void *)&spectrum, |
| 3184 | .meta.flags = CMD_WANT_SKB, |
| 3185 | }; |
| 3186 | u32 add_time = le64_to_cpu(params->start_time); |
| 3187 | int rc; |
| 3188 | int spectrum_resp_status; |
| 3189 | int duration = le16_to_cpu(params->duration); |
| 3190 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3191 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3192 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3193 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3194 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 3195 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3196 | |
| 3197 | memset(&spectrum, 0, sizeof(spectrum)); |
| 3198 | |
| 3199 | spectrum.channel_count = cpu_to_le16(1); |
| 3200 | spectrum.flags = |
| 3201 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 3202 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 3203 | cmd.len = sizeof(spectrum); |
| 3204 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 3205 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3206 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3207 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3208 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3209 | add_time, |
| 3210 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3211 | else |
| 3212 | spectrum.start_time = 0; |
| 3213 | |
| 3214 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 3215 | spectrum.channels[0].channel = params->channel; |
| 3216 | spectrum.channels[0].type = type; |
| 3217 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 3218 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 3219 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 3220 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3221 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3222 | if (rc) |
| 3223 | return rc; |
| 3224 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3225 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3226 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 3227 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 3228 | rc = -EIO; |
| 3229 | } |
| 3230 | |
| 3231 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 3232 | switch (spectrum_resp_status) { |
| 3233 | case 0: /* Command will be handled */ |
| 3234 | if (res->u.spectrum.id != 0xff) { |
| 3235 | IWL_DEBUG_INFO |
| 3236 | ("Replaced existing measurement: %d\n", |
| 3237 | res->u.spectrum.id); |
| 3238 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 3239 | } |
| 3240 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 3241 | rc = 0; |
| 3242 | break; |
| 3243 | |
| 3244 | case 1: /* Command will not be handled */ |
| 3245 | rc = -EAGAIN; |
| 3246 | break; |
| 3247 | } |
| 3248 | |
| 3249 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 3250 | |
| 3251 | return rc; |
| 3252 | } |
| 3253 | #endif |
| 3254 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3255 | static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv, |
| 3256 | struct iwl4965_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3257 | { |
| 3258 | |
| 3259 | tx_sta->status.ack_signal = 0; |
| 3260 | tx_sta->status.excessive_retries = 0; |
| 3261 | tx_sta->status.queue_length = 0; |
| 3262 | tx_sta->status.queue_number = 0; |
| 3263 | |
| 3264 | if (in_interrupt()) |
| 3265 | ieee80211_tx_status_irqsafe(priv->hw, |
| 3266 | tx_sta->skb[0], &(tx_sta->status)); |
| 3267 | else |
| 3268 | ieee80211_tx_status(priv->hw, |
| 3269 | tx_sta->skb[0], &(tx_sta->status)); |
| 3270 | |
| 3271 | tx_sta->skb[0] = NULL; |
| 3272 | } |
| 3273 | |
| 3274 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3275 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3276 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3277 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3278 | * need to be reclaimed. As result, some free space forms. If there is |
| 3279 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3280 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3281 | int iwl4965_tx_queue_reclaim(struct iwl4965_priv *priv, int txq_id, int index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3282 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3283 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
| 3284 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3285 | int nfreed = 0; |
| 3286 | |
| 3287 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 3288 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 3289 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3290 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3291 | return 0; |
| 3292 | } |
| 3293 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3294 | for (index = iwl4965_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3295 | q->read_ptr != index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3296 | q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3298 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3299 | &(txq->txb[txq->q.read_ptr])); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3300 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3301 | } else if (nfreed > 1) { |
| 3302 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3303 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3304 | queue_work(priv->workqueue, &priv->restart); |
| 3305 | } |
| 3306 | nfreed++; |
| 3307 | } |
| 3308 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3309 | /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3310 | (txq_id != IWL_CMD_QUEUE_NUM) && |
| 3311 | priv->mac80211_registered) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3312 | ieee80211_wake_queue(priv->hw, txq_id); */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3313 | |
| 3314 | |
| 3315 | return nfreed; |
| 3316 | } |
| 3317 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3318 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3319 | { |
| 3320 | status &= TX_STATUS_MSK; |
| 3321 | return (status == TX_STATUS_SUCCESS) |
| 3322 | || (status == TX_STATUS_DIRECT_DONE); |
| 3323 | } |
| 3324 | |
| 3325 | /****************************************************************************** |
| 3326 | * |
| 3327 | * Generic RX handler implementations |
| 3328 | * |
| 3329 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3330 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3331 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3332 | static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3333 | struct ieee80211_hdr *hdr) |
| 3334 | { |
| 3335 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 3336 | return IWL_AP_ID; |
| 3337 | else { |
| 3338 | u8 *da = ieee80211_get_DA(hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3339 | return iwl4965_hw_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3340 | } |
| 3341 | } |
| 3342 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3343 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
| 3344 | struct iwl4965_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3345 | { |
| 3346 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 3347 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 3348 | txb[idx].skb[0]->data; |
| 3349 | return NULL; |
| 3350 | } |
| 3351 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3352 | static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3353 | { |
| 3354 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 3355 | tx_resp->frame_count); |
| 3356 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 3357 | |
| 3358 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3359 | |
| 3360 | /** |
| 3361 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 3362 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3363 | static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv, |
| 3364 | struct iwl4965_ht_agg *agg, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3365 | struct iwl4965_tx_resp_agg *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3366 | u16 start_idx) |
| 3367 | { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3368 | u16 status; |
| 3369 | struct agg_tx_status *frame_status = &tx_resp->status; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3370 | struct ieee80211_tx_status *tx_status = NULL; |
| 3371 | struct ieee80211_hdr *hdr = NULL; |
| 3372 | int i, sh; |
| 3373 | int txq_id, idx; |
| 3374 | u16 seq; |
| 3375 | |
| 3376 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3377 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3378 | |
| 3379 | agg->frame_count = tx_resp->frame_count; |
| 3380 | agg->start_idx = start_idx; |
| 3381 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3382 | agg->bitmap = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3383 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3384 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3385 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3386 | /* Only one frame was attempted; no block-ack will arrive */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3387 | status = le16_to_cpu(frame_status[0].status); |
| 3388 | seq = le16_to_cpu(frame_status[0].sequence); |
| 3389 | idx = SEQ_TO_INDEX(seq); |
| 3390 | txq_id = SEQ_TO_QUEUE(seq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3391 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3392 | /* FIXME: code repetition */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3393 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 3394 | agg->frame_count, agg->start_idx, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3395 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3396 | tx_status = &(priv->txq[txq_id].txb[idx].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3397 | tx_status->retry_count = tx_resp->failure_frame; |
| 3398 | tx_status->queue_number = status & 0xff; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3399 | tx_status->queue_length = tx_resp->failure_rts; |
| 3400 | tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3401 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3402 | IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 3403 | iwl4965_hwrate_to_tx_control(priv, |
| 3404 | le32_to_cpu(tx_resp->rate_n_flags), |
| 3405 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3406 | /* FIXME: code repetition end */ |
| 3407 | |
| 3408 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 3409 | status & 0xff, tx_resp->failure_frame); |
| 3410 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3411 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3412 | |
| 3413 | agg->wait_for_ba = 0; |
| 3414 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3415 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3416 | u64 bitmap = 0; |
| 3417 | int start = agg->start_idx; |
| 3418 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3419 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3420 | for (i = 0; i < agg->frame_count; i++) { |
| 3421 | u16 sc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3422 | status = le16_to_cpu(frame_status[i].status); |
| 3423 | seq = le16_to_cpu(frame_status[i].sequence); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3424 | idx = SEQ_TO_INDEX(seq); |
| 3425 | txq_id = SEQ_TO_QUEUE(seq); |
| 3426 | |
| 3427 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 3428 | AGG_TX_STATE_ABORT_MSK)) |
| 3429 | continue; |
| 3430 | |
| 3431 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 3432 | agg->frame_count, txq_id, idx); |
| 3433 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3434 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3435 | |
| 3436 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 3437 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 3438 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 3439 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 3440 | idx, SEQ_TO_SN(sc), |
| 3441 | hdr->seq_ctrl); |
| 3442 | return -1; |
| 3443 | } |
| 3444 | |
| 3445 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 3446 | i, idx, SEQ_TO_SN(sc)); |
| 3447 | |
| 3448 | sh = idx - start; |
| 3449 | if (sh > 64) { |
| 3450 | sh = (start - idx) + 0xff; |
| 3451 | bitmap = bitmap << sh; |
| 3452 | sh = 0; |
| 3453 | start = idx; |
| 3454 | } else if (sh < -64) |
| 3455 | sh = 0xff - (start - idx); |
| 3456 | else if (sh < 0) { |
| 3457 | sh = start - idx; |
| 3458 | start = idx; |
| 3459 | bitmap = bitmap << sh; |
| 3460 | sh = 0; |
| 3461 | } |
| 3462 | bitmap |= (1 << sh); |
| 3463 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 3464 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 3465 | } |
| 3466 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3467 | agg->bitmap = bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3468 | agg->start_idx = start; |
| 3469 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3470 | IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3471 | agg->frame_count, agg->start_idx, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3472 | agg->bitmap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3473 | |
| 3474 | if (bitmap) |
| 3475 | agg->wait_for_ba = 1; |
| 3476 | } |
| 3477 | return 0; |
| 3478 | } |
| 3479 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3480 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3481 | /** |
| 3482 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 3483 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3484 | static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv, |
| 3485 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3486 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3487 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3488 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3489 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3490 | int index = SEQ_TO_INDEX(sequence); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3491 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3492 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3493 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3494 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3495 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3496 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
| 3497 | struct ieee80211_hdr *hdr; |
| 3498 | __le16 *qc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3499 | #endif |
| 3500 | |
| 3501 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 3502 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 3503 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3504 | index, txq->q.n_bd, txq->q.write_ptr, |
| 3505 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3506 | return; |
| 3507 | } |
| 3508 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3509 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3510 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 3511 | qc = ieee80211_get_qos_ctrl(hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3512 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3513 | if (qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3514 | tid = le16_to_cpu(*qc) & 0xf; |
| 3515 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3516 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
| 3517 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 3518 | IWL_ERROR("Station not known\n"); |
| 3519 | return; |
| 3520 | } |
| 3521 | |
| 3522 | if (txq->sched_retry) { |
| 3523 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
| 3524 | struct iwl4965_ht_agg *agg = NULL; |
| 3525 | |
| 3526 | if (!qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3527 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3528 | |
| 3529 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 3530 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3531 | iwl4965_tx_status_reply_tx(priv, agg, |
| 3532 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3533 | |
| 3534 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3535 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3536 | /* TODO: send BAR */ |
| 3537 | } |
| 3538 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3539 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
| 3540 | int freed; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3541 | index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3542 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 3543 | "%d index %d\n", scd_ssn , index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3544 | freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
| 3545 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 3546 | |
| 3547 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 3548 | txq_id >= 0 && priv->mac80211_registered && |
| 3549 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) |
| 3550 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3551 | |
| 3552 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3553 | } |
| 3554 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3555 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3556 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3557 | |
| 3558 | tx_status->retry_count = tx_resp->failure_frame; |
| 3559 | tx_status->queue_number = status; |
| 3560 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3561 | tx_status->queue_length |= tx_resp->failure_rts; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3562 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3563 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 3564 | iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), |
| 3565 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3566 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3567 | IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x " |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3568 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3569 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 3570 | tx_resp->failure_frame); |
| 3571 | |
| 3572 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3573 | if (index != -1) { |
| 3574 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3575 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3576 | if (tid != MAX_TID_COUNT) |
| 3577 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 3578 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 3579 | (txq_id >= 0) && |
| 3580 | priv->mac80211_registered) |
| 3581 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3582 | if (tid != MAX_TID_COUNT) |
| 3583 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
| 3584 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3585 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3586 | #ifdef CONFIG_IWL4965_HT |
| 3587 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3588 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3589 | |
| 3590 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 3591 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 3592 | } |
| 3593 | |
| 3594 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3595 | static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv, |
| 3596 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3597 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3598 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3599 | struct iwl4965_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3600 | struct delayed_work *pwork; |
| 3601 | |
| 3602 | palive = &pkt->u.alive_frame; |
| 3603 | |
| 3604 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 3605 | "0x%01X 0x%01X\n", |
| 3606 | palive->is_valid, palive->ver_type, |
| 3607 | palive->ver_subtype); |
| 3608 | |
| 3609 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 3610 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 3611 | memcpy(&priv->card_alive_init, |
| 3612 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3613 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3614 | pwork = &priv->init_alive_start; |
| 3615 | } else { |
| 3616 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3617 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3618 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3619 | pwork = &priv->alive_start; |
| 3620 | } |
| 3621 | |
| 3622 | /* We delay the ALIVE response by 5ms to |
| 3623 | * give the HW RF Kill time to activate... */ |
| 3624 | if (palive->is_valid == UCODE_VALID_OK) |
| 3625 | queue_delayed_work(priv->workqueue, pwork, |
| 3626 | msecs_to_jiffies(5)); |
| 3627 | else |
| 3628 | IWL_WARNING("uCode did not respond OK.\n"); |
| 3629 | } |
| 3630 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3631 | static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv, |
| 3632 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3633 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3634 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3635 | |
| 3636 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 3637 | return; |
| 3638 | } |
| 3639 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3640 | static void iwl4965_rx_reply_error(struct iwl4965_priv *priv, |
| 3641 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3642 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3643 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3644 | |
| 3645 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 3646 | "seq 0x%04X ser 0x%08X\n", |
| 3647 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 3648 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 3649 | pkt->u.err_resp.cmd_id, |
| 3650 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 3651 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 3652 | } |
| 3653 | |
| 3654 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 3655 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3656 | static void iwl4965_rx_csa(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3657 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3658 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3659 | struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 3660 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3661 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 3662 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 3663 | rxon->channel = csa->channel; |
| 3664 | priv->staging_rxon.channel = csa->channel; |
| 3665 | } |
| 3666 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3667 | static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv, |
| 3668 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3669 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3670 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3671 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3672 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3673 | |
| 3674 | if (!report->state) { |
| 3675 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 3676 | "Spectrum Measure Notification: Start\n"); |
| 3677 | return; |
| 3678 | } |
| 3679 | |
| 3680 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 3681 | priv->measurement_status |= MEASUREMENT_READY; |
| 3682 | #endif |
| 3683 | } |
| 3684 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3685 | static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv, |
| 3686 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3687 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3688 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3689 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3690 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3691 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 3692 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 3693 | #endif |
| 3694 | } |
| 3695 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3696 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv, |
| 3697 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3698 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3699 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3700 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 3701 | "notification for %s:\n", |
| 3702 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3703 | iwl4965_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3704 | } |
| 3705 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3706 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3707 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3708 | struct iwl4965_priv *priv = |
| 3709 | container_of(work, struct iwl4965_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3710 | struct sk_buff *beacon; |
| 3711 | |
| 3712 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3713 | beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3714 | |
| 3715 | if (!beacon) { |
| 3716 | IWL_ERROR("update beacon failed\n"); |
| 3717 | return; |
| 3718 | } |
| 3719 | |
| 3720 | mutex_lock(&priv->mutex); |
| 3721 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 3722 | if (priv->ibss_beacon) |
| 3723 | dev_kfree_skb(priv->ibss_beacon); |
| 3724 | |
| 3725 | priv->ibss_beacon = beacon; |
| 3726 | mutex_unlock(&priv->mutex); |
| 3727 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3728 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3729 | } |
| 3730 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3731 | static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv, |
| 3732 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3733 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3734 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3735 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3736 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 3737 | u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3738 | |
| 3739 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 3740 | "tsf %d %d rate %d\n", |
| 3741 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 3742 | beacon->beacon_notify_hdr.failure_frame, |
| 3743 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3744 | le32_to_cpu(beacon->high_tsf), |
| 3745 | le32_to_cpu(beacon->low_tsf), rate); |
| 3746 | #endif |
| 3747 | |
| 3748 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3749 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 3750 | queue_work(priv->workqueue, &priv->beacon_update); |
| 3751 | } |
| 3752 | |
| 3753 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3754 | static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv, |
| 3755 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3756 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3757 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3758 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3759 | struct iwl4965_scanreq_notification *notif = |
| 3760 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3761 | |
| 3762 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 3763 | #endif |
| 3764 | } |
| 3765 | |
| 3766 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3767 | static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv, |
| 3768 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3769 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3770 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3771 | struct iwl4965_scanstart_notification *notif = |
| 3772 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3773 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 3774 | IWL_DEBUG_SCAN("Scan start: " |
| 3775 | "%d [802.11%s] " |
| 3776 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 3777 | notif->channel, |
| 3778 | notif->band ? "bg" : "a", |
| 3779 | notif->tsf_high, |
| 3780 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 3781 | } |
| 3782 | |
| 3783 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3784 | static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv, |
| 3785 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3786 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3787 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3788 | struct iwl4965_scanresults_notification *notif = |
| 3789 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3790 | |
| 3791 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 3792 | "%d [802.11%s] " |
| 3793 | "(TSF: 0x%08X:%08X) - %d " |
| 3794 | "elapsed=%lu usec (%dms since last)\n", |
| 3795 | notif->channel, |
| 3796 | notif->band ? "bg" : "a", |
| 3797 | le32_to_cpu(notif->tsf_high), |
| 3798 | le32_to_cpu(notif->tsf_low), |
| 3799 | le32_to_cpu(notif->statistics[0]), |
| 3800 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 3801 | jiffies_to_msecs(elapsed_jiffies |
| 3802 | (priv->last_scan_jiffies, jiffies))); |
| 3803 | |
| 3804 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3805 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3809 | static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv, |
| 3810 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3811 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3812 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3813 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3814 | |
| 3815 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 3816 | scan_notif->scanned_channels, |
| 3817 | scan_notif->tsf_low, |
| 3818 | scan_notif->tsf_high, scan_notif->status); |
| 3819 | |
| 3820 | /* The HW is no longer scanning */ |
| 3821 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3822 | |
| 3823 | /* The scan completion notification came in, so kill that timer... */ |
| 3824 | cancel_delayed_work(&priv->scan_check); |
| 3825 | |
| 3826 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 3827 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 3828 | jiffies_to_msecs(elapsed_jiffies |
| 3829 | (priv->scan_pass_start, jiffies))); |
| 3830 | |
| 3831 | /* Remove this scanned band from the list |
| 3832 | * of pending bands to scan */ |
| 3833 | priv->scan_bands--; |
| 3834 | |
| 3835 | /* If a request to abort was given, or the scan did not succeed |
| 3836 | * then we reset the scan state machine and terminate, |
| 3837 | * re-queuing another scan if one has been requested */ |
| 3838 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3839 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 3840 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 3841 | } else { |
| 3842 | /* If there are more bands on this scan pass reschedule */ |
| 3843 | if (priv->scan_bands > 0) |
| 3844 | goto reschedule; |
| 3845 | } |
| 3846 | |
| 3847 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3848 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3849 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 3850 | |
| 3851 | clear_bit(STATUS_SCANNING, &priv->status); |
| 3852 | |
| 3853 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 3854 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 3855 | |
| 3856 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3857 | |
| 3858 | return; |
| 3859 | |
| 3860 | reschedule: |
| 3861 | priv->scan_pass_start = jiffies; |
| 3862 | queue_work(priv->workqueue, &priv->request_scan); |
| 3863 | } |
| 3864 | |
| 3865 | /* Handle notification from uCode that card's power state is changing |
| 3866 | * due to software, hardware, or critical temperature RFKILL */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3867 | static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv, |
| 3868 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3869 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3870 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3871 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 3872 | unsigned long status = priv->status; |
| 3873 | |
| 3874 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 3875 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3876 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 3877 | |
| 3878 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 3879 | RF_CARD_DISABLED)) { |
| 3880 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3881 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3882 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3883 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3884 | if (!iwl4965_grab_nic_access(priv)) { |
| 3885 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3886 | priv, HBUS_TARG_MBX_C, |
| 3887 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 3888 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3889 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | if (!(flags & RXON_CARD_DISABLED)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3893 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3894 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3895 | if (!iwl4965_grab_nic_access(priv)) { |
| 3896 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3897 | priv, HBUS_TARG_MBX_C, |
| 3898 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 3899 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3900 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3901 | } |
| 3902 | } |
| 3903 | |
| 3904 | if (flags & RF_CARD_DISABLED) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3905 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3906 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3907 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 3908 | if (!iwl4965_grab_nic_access(priv)) |
| 3909 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | if (flags & HW_CARD_DISABLED) |
| 3914 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3915 | else |
| 3916 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3917 | |
| 3918 | |
| 3919 | if (flags & SW_CARD_DISABLED) |
| 3920 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3921 | else |
| 3922 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3923 | |
| 3924 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3925 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3926 | |
| 3927 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 3928 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 3929 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 3930 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 3931 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3932 | else |
| 3933 | wake_up_interruptible(&priv->wait_command_queue); |
| 3934 | } |
| 3935 | |
| 3936 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3937 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3938 | * |
| 3939 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3940 | * to the host. |
| 3941 | * |
| 3942 | * This function chains into the hardware specific files for them to setup |
| 3943 | * any hardware specific handlers as well. |
| 3944 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3945 | static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3946 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3947 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 3948 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 3949 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 3950 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3951 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3952 | iwl4965_rx_spectrum_measure_notif; |
| 3953 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3954 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3955 | iwl4965_rx_pm_debug_statistics_notif; |
| 3956 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3957 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3958 | /* |
| 3959 | * The same handler is used for both the REPLY to a discrete |
| 3960 | * statistics request from the host as well as for the periodic |
| 3961 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3962 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3963 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 3964 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3965 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3966 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 3967 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3968 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3969 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3970 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3971 | iwl4965_rx_scan_complete_notif; |
| 3972 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 3973 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3974 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3975 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3976 | iwl4965_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3980 | * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3981 | * @rxb: Rx buffer to reclaim |
| 3982 | * |
| 3983 | * If an Rx buffer has an async callback associated with it the callback |
| 3984 | * will be executed. The attached skb (if present) will only be freed |
| 3985 | * if the callback returns 1 |
| 3986 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3987 | static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv, |
| 3988 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3989 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3990 | struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3991 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3992 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3993 | int index = SEQ_TO_INDEX(sequence); |
| 3994 | int huge = sequence & SEQ_HUGE_FRAME; |
| 3995 | int cmd_index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3996 | struct iwl4965_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3997 | |
| 3998 | /* If a Tx command is being handled and it isn't in the actual |
| 3999 | * command queue then there a command routing bug has been introduced |
| 4000 | * in the queue management code. */ |
| 4001 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 4002 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 4003 | txq_id, pkt->hdr.cmd); |
| 4004 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 4005 | |
| 4006 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 4007 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 4008 | |
| 4009 | /* Input error checking is done when commands are added to queue. */ |
| 4010 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 4011 | cmd->meta.source->u.skb = rxb->skb; |
| 4012 | rxb->skb = NULL; |
| 4013 | } else if (cmd->meta.u.callback && |
| 4014 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 4015 | rxb->skb = NULL; |
| 4016 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4017 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4018 | |
| 4019 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 4020 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4021 | wake_up_interruptible(&priv->wait_command_queue); |
| 4022 | } |
| 4023 | } |
| 4024 | |
| 4025 | /************************** RX-FUNCTIONS ****************************/ |
| 4026 | /* |
| 4027 | * Rx theory of operation |
| 4028 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4029 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), |
| 4030 | * each of which point to Receive Buffers to be filled by 4965. These get |
| 4031 | * used not only for Rx frames, but for any command response or notification |
| 4032 | * from the 4965. The driver and 4965 manage the Rx buffers by means |
| 4033 | * of indexes into the circular buffer. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4034 | * |
| 4035 | * Rx Queue Indexes |
| 4036 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4037 | * |
| 4038 | * The READ index maps to the first position that the firmware may be writing |
| 4039 | * to -- the driver can read up to (but not including) this position and get |
| 4040 | * good data. |
| 4041 | * The READ index is managed by the firmware once the card is enabled. |
| 4042 | * |
| 4043 | * The WRITE index maps to the last position the driver has read from -- the |
| 4044 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4045 | * |
| 4046 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 4047 | * WRITE = READ. |
| 4048 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4049 | * 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] | 4050 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4051 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4052 | * 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] | 4053 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4054 | * process as many packets as possible, moving the WRITE index forward as it |
| 4055 | * resets the Rx queue buffers with new memory. |
| 4056 | * |
| 4057 | * The management in the driver is as follows: |
| 4058 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 4059 | * 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] | 4060 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4061 | * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4062 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 4063 | * 'processed' and 'read' driver indexes as well) |
| 4064 | * + A received packet is processed and handed to the kernel network stack, |
| 4065 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 4066 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 4067 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 4068 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 4069 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4070 | * |
| 4071 | * |
| 4072 | * Driver sequence: |
| 4073 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4074 | * iwl4965_rx_queue_alloc() Allocates rx_free |
| 4075 | * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4076 | * iwl4965_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4077 | * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4078 | * queue, updates firmware pointers, and updates |
| 4079 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4080 | * are available, schedules iwl4965_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4081 | * |
| 4082 | * -- enable interrupts -- |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4083 | * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4084 | * READ INDEX, detaching the SKB from the pool. |
| 4085 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4086 | * Calls iwl4965_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4087 | * slots. |
| 4088 | * ... |
| 4089 | * |
| 4090 | */ |
| 4091 | |
| 4092 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4093 | * iwl4965_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4094 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4095 | static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4096 | { |
| 4097 | int s = q->read - q->write; |
| 4098 | if (s <= 0) |
| 4099 | s += RX_QUEUE_SIZE; |
| 4100 | /* keep some buffer to not confuse full and empty queue */ |
| 4101 | s -= 2; |
| 4102 | if (s < 0) |
| 4103 | s = 0; |
| 4104 | return s; |
| 4105 | } |
| 4106 | |
| 4107 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4108 | * iwl4965_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] | 4109 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4110 | int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv *priv, struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4111 | { |
| 4112 | u32 reg = 0; |
| 4113 | int rc = 0; |
| 4114 | unsigned long flags; |
| 4115 | |
| 4116 | spin_lock_irqsave(&q->lock, flags); |
| 4117 | |
| 4118 | if (q->need_update == 0) |
| 4119 | goto exit_unlock; |
| 4120 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4121 | /* If power-saving is in use, make sure device is awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4122 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4123 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4124 | |
| 4125 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4126 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4127 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4128 | goto exit_unlock; |
| 4129 | } |
| 4130 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4131 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4132 | if (rc) |
| 4133 | goto exit_unlock; |
| 4134 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4135 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4136 | iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4137 | q->write & ~0x7); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4138 | iwl4965_release_nic_access(priv); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4139 | |
| 4140 | /* Else device is assumed to be awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4141 | } else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4142 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4143 | iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4144 | |
| 4145 | |
| 4146 | q->need_update = 0; |
| 4147 | |
| 4148 | exit_unlock: |
| 4149 | spin_unlock_irqrestore(&q->lock, flags); |
| 4150 | return rc; |
| 4151 | } |
| 4152 | |
| 4153 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4154 | * iwl4965_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] | 4155 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4156 | static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4157 | dma_addr_t dma_addr) |
| 4158 | { |
| 4159 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 4160 | } |
| 4161 | |
| 4162 | |
| 4163 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4164 | * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4165 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4166 | * 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] | 4167 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4168 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4169 | * |
| 4170 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4171 | * also updates the memory address in the firmware to reference the new |
| 4172 | * target buffer. |
| 4173 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4174 | static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4175 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4176 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4177 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4178 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4179 | unsigned long flags; |
| 4180 | int write, rc; |
| 4181 | |
| 4182 | spin_lock_irqsave(&rxq->lock, flags); |
| 4183 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4184 | while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4185 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4186 | element = rxq->rx_free.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4187 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4188 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4189 | |
| 4190 | /* Point to Rx buffer via next RBD in circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4191 | rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4192 | rxq->queue[rxq->write] = rxb; |
| 4193 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 4194 | rxq->free_count--; |
| 4195 | } |
| 4196 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4197 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 4198 | * refill it */ |
| 4199 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4200 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4201 | |
| 4202 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4203 | /* If we've added more space for the firmware to place data, tell it. |
| 4204 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4205 | if ((write != (rxq->write & ~0x7)) |
| 4206 | || (abs(rxq->write - rxq->read) > 7)) { |
| 4207 | spin_lock_irqsave(&rxq->lock, flags); |
| 4208 | rxq->need_update = 1; |
| 4209 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4210 | rc = iwl4965_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4211 | if (rc) |
| 4212 | return rc; |
| 4213 | } |
| 4214 | |
| 4215 | return 0; |
| 4216 | } |
| 4217 | |
| 4218 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4219 | * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4220 | * |
| 4221 | * When moving to rx_free an SKB is allocated for the slot. |
| 4222 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4223 | * Also restock the Rx queue via iwl4965_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 4224 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4225 | */ |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4226 | static void iwl4965_rx_allocate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4227 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4228 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4229 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4230 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4231 | unsigned long flags; |
| 4232 | spin_lock_irqsave(&rxq->lock, flags); |
| 4233 | while (!list_empty(&rxq->rx_used)) { |
| 4234 | element = rxq->rx_used.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4235 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4236 | |
| 4237 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4238 | rxb->skb = |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4239 | alloc_skb(priv->hw_setting.rx_buf_size, |
| 4240 | __GFP_NOWARN | GFP_ATOMIC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4241 | if (!rxb->skb) { |
| 4242 | if (net_ratelimit()) |
| 4243 | printk(KERN_CRIT DRV_NAME |
| 4244 | ": Can not allocate SKB buffers\n"); |
| 4245 | /* We don't reschedule replenish work here -- we will |
| 4246 | * call the restock method and if it still needs |
| 4247 | * more buffers it will schedule replenish */ |
| 4248 | break; |
| 4249 | } |
| 4250 | priv->alloc_rxb_skb++; |
| 4251 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4252 | |
| 4253 | /* Get physical address of RB/SKB */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4254 | rxb->dma_addr = |
| 4255 | pci_map_single(priv->pci_dev, rxb->skb->data, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4256 | priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4257 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4258 | rxq->free_count++; |
| 4259 | } |
| 4260 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | /* |
| 4264 | * this should be called while priv->lock is locked |
| 4265 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 4266 | static void __iwl4965_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4267 | { |
| 4268 | struct iwl4965_priv *priv = data; |
| 4269 | |
| 4270 | iwl4965_rx_allocate(priv); |
| 4271 | iwl4965_rx_queue_restock(priv); |
| 4272 | } |
| 4273 | |
| 4274 | |
| 4275 | void iwl4965_rx_replenish(void *data) |
| 4276 | { |
| 4277 | struct iwl4965_priv *priv = data; |
| 4278 | unsigned long flags; |
| 4279 | |
| 4280 | iwl4965_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4281 | |
| 4282 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4283 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4284 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4285 | } |
| 4286 | |
| 4287 | /* 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] | 4288 | * 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] | 4289 | * This free routine walks the list of POOL entries and if SKB is set to |
| 4290 | * non NULL it is unmapped and freed |
| 4291 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4292 | static void iwl4965_rx_queue_free(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4293 | { |
| 4294 | int i; |
| 4295 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4296 | if (rxq->pool[i].skb != NULL) { |
| 4297 | pci_unmap_single(priv->pci_dev, |
| 4298 | rxq->pool[i].dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4299 | priv->hw_setting.rx_buf_size, |
| 4300 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4301 | dev_kfree_skb(rxq->pool[i].skb); |
| 4302 | } |
| 4303 | } |
| 4304 | |
| 4305 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 4306 | rxq->dma_addr); |
| 4307 | rxq->bd = NULL; |
| 4308 | } |
| 4309 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4310 | int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4311 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4312 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4313 | struct pci_dev *dev = priv->pci_dev; |
| 4314 | int i; |
| 4315 | |
| 4316 | spin_lock_init(&rxq->lock); |
| 4317 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4318 | INIT_LIST_HEAD(&rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4319 | |
| 4320 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4321 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 4322 | if (!rxq->bd) |
| 4323 | return -ENOMEM; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4324 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4325 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4326 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 4327 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4328 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4329 | /* Set us so that we have processed and used all buffers, but have |
| 4330 | * not restocked the Rx queue with fresh buffers */ |
| 4331 | rxq->read = rxq->write = 0; |
| 4332 | rxq->free_count = 0; |
| 4333 | rxq->need_update = 0; |
| 4334 | return 0; |
| 4335 | } |
| 4336 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4337 | void iwl4965_rx_queue_reset(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4338 | { |
| 4339 | unsigned long flags; |
| 4340 | int i; |
| 4341 | spin_lock_irqsave(&rxq->lock, flags); |
| 4342 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4343 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4344 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4345 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 4346 | /* In the reset function, these buffers may have been allocated |
| 4347 | * to an SKB, so we need to unmap and free potential storage */ |
| 4348 | if (rxq->pool[i].skb != NULL) { |
| 4349 | pci_unmap_single(priv->pci_dev, |
| 4350 | rxq->pool[i].dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4351 | priv->hw_setting.rx_buf_size, |
| 4352 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4353 | priv->alloc_rxb_skb--; |
| 4354 | dev_kfree_skb(rxq->pool[i].skb); |
| 4355 | rxq->pool[i].skb = NULL; |
| 4356 | } |
| 4357 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4358 | } |
| 4359 | |
| 4360 | /* Set us so that we have processed and used all buffers, but have |
| 4361 | * not restocked the Rx queue with fresh buffers */ |
| 4362 | rxq->read = rxq->write = 0; |
| 4363 | rxq->free_count = 0; |
| 4364 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4365 | } |
| 4366 | |
| 4367 | /* Convert linear signal-to-noise ratio into dB */ |
| 4368 | static u8 ratio2dB[100] = { |
| 4369 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 4370 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 4371 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 4372 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 4373 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 4374 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 4375 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 4376 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 4377 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 4378 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 4379 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 4380 | }; |
| 4381 | |
| 4382 | /* Calculates a relative dB value from a ratio of linear |
| 4383 | * (i.e. not dB) signal levels. |
| 4384 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4385 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4386 | { |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4387 | /* 1000:1 or higher just report as 60 dB */ |
| 4388 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4389 | return 60; |
| 4390 | |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4391 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4392 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4393 | if (sig_ratio >= 100) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4394 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 4395 | |
| 4396 | /* We shouldn't see this */ |
| 4397 | if (sig_ratio < 1) |
| 4398 | return 0; |
| 4399 | |
| 4400 | /* Use table for ratios 1:1 - 99:1 */ |
| 4401 | return (int)ratio2dB[sig_ratio]; |
| 4402 | } |
| 4403 | |
| 4404 | #define PERFECT_RSSI (-20) /* dBm */ |
| 4405 | #define WORST_RSSI (-95) /* dBm */ |
| 4406 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 4407 | |
| 4408 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 4409 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 4410 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4411 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4412 | { |
| 4413 | int sig_qual; |
| 4414 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 4415 | |
| 4416 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 4417 | * as indicator; formula is (signal dbm - noise dbm). |
| 4418 | * SNR at or above 40 is a great signal (100%). |
| 4419 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 4420 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 4421 | if (noise_dbm) { |
| 4422 | if (rssi_dbm - noise_dbm >= 40) |
| 4423 | return 100; |
| 4424 | else if (rssi_dbm < noise_dbm) |
| 4425 | return 0; |
| 4426 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 4427 | |
| 4428 | /* Else use just the signal level. |
| 4429 | * This formula is a least squares fit of data points collected and |
| 4430 | * compared with a reference system that had a percentage (%) display |
| 4431 | * for signal quality. */ |
| 4432 | } else |
| 4433 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 4434 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 4435 | (RSSI_RANGE * RSSI_RANGE); |
| 4436 | |
| 4437 | if (sig_qual > 100) |
| 4438 | sig_qual = 100; |
| 4439 | else if (sig_qual < 1) |
| 4440 | sig_qual = 0; |
| 4441 | |
| 4442 | return sig_qual; |
| 4443 | } |
| 4444 | |
| 4445 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4446 | * iwl4965_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4447 | * |
| 4448 | * Uses the priv->rx_handlers callback function array to invoke |
| 4449 | * the appropriate handlers, including command responses, |
| 4450 | * frame-received notifications, and other notifications. |
| 4451 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4452 | static void iwl4965_rx_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4453 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4454 | struct iwl4965_rx_mem_buffer *rxb; |
| 4455 | struct iwl4965_rx_packet *pkt; |
| 4456 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4457 | u32 r, i; |
| 4458 | int reclaim; |
| 4459 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4460 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 4461 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4462 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4463 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 4464 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4465 | r = iwl4965_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4466 | i = rxq->read; |
| 4467 | |
| 4468 | /* Rx interrupt, but nothing sent from uCode */ |
| 4469 | if (i == r) |
| 4470 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 4471 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4472 | if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
| 4473 | fill_rx = 1; |
| 4474 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4475 | while (i != r) { |
| 4476 | rxb = rxq->queue[i]; |
| 4477 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4478 | /* 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] | 4479 | * then a bug has been introduced in the queue refilling |
| 4480 | * routines -- catch it here */ |
| 4481 | BUG_ON(rxb == NULL); |
| 4482 | |
| 4483 | rxq->queue[i] = NULL; |
| 4484 | |
| 4485 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4486 | priv->hw_setting.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4487 | PCI_DMA_FROMDEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4488 | pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4489 | |
| 4490 | /* Reclaim a command buffer only if this packet is a response |
| 4491 | * to a (driver-originated) command. |
| 4492 | * If the packet (e.g. Rx frame) originated from uCode, |
| 4493 | * there is no command buffer to reclaim. |
| 4494 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 4495 | * but apparently a few don't get set; catch them here. */ |
| 4496 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 4497 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
| 4498 | (pkt->hdr.cmd != REPLY_4965_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 4499 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4500 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 4501 | (pkt->hdr.cmd != REPLY_TX); |
| 4502 | |
| 4503 | /* Based on type of command response or notification, |
| 4504 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4505 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4506 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 4507 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4508 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 4509 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 4510 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 4511 | } else { |
| 4512 | /* No handling needed */ |
| 4513 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4514 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 4515 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 4516 | pkt->hdr.cmd); |
| 4517 | } |
| 4518 | |
| 4519 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4520 | /* Invoke any callbacks, transfer the skb to caller, and |
| 4521 | * fire off the (possibly) blocking iwl4965_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4522 | * as we reclaim the driver command queue */ |
| 4523 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4524 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4525 | else |
| 4526 | IWL_WARNING("Claim null rxb?\n"); |
| 4527 | } |
| 4528 | |
| 4529 | /* For now we just don't re-use anything. We can tweak this |
| 4530 | * later to try and re-use notification packets and SKBs that |
| 4531 | * fail to Rx correctly */ |
| 4532 | if (rxb->skb != NULL) { |
| 4533 | priv->alloc_rxb_skb--; |
| 4534 | dev_kfree_skb_any(rxb->skb); |
| 4535 | rxb->skb = NULL; |
| 4536 | } |
| 4537 | |
| 4538 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4539 | priv->hw_setting.rx_buf_size, |
| 4540 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4541 | spin_lock_irqsave(&rxq->lock, flags); |
| 4542 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 4543 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4544 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4545 | /* If there are a lot of unused frames, |
| 4546 | * restock the Rx queue so ucode wont assert. */ |
| 4547 | if (fill_rx) { |
| 4548 | count++; |
| 4549 | if (count >= 8) { |
| 4550 | priv->rxq.read = i; |
| 4551 | __iwl4965_rx_replenish(priv); |
| 4552 | count = 0; |
| 4553 | } |
| 4554 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4555 | } |
| 4556 | |
| 4557 | /* Backtrack one entry */ |
| 4558 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4559 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4560 | } |
| 4561 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4562 | /** |
| 4563 | * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware |
| 4564 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4565 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 4566 | struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4567 | { |
| 4568 | u32 reg = 0; |
| 4569 | int rc = 0; |
| 4570 | int txq_id = txq->q.id; |
| 4571 | |
| 4572 | if (txq->need_update == 0) |
| 4573 | return rc; |
| 4574 | |
| 4575 | /* if we're trying to save power */ |
| 4576 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 4577 | /* wake up nic if it's powered down ... |
| 4578 | * uCode will wake up, and interrupt us again, so next |
| 4579 | * time we'll skip this part. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4580 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4581 | |
| 4582 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 4583 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4584 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4585 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4586 | return rc; |
| 4587 | } |
| 4588 | |
| 4589 | /* restore this queue's parameters in nic hardware. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4590 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4591 | if (rc) |
| 4592 | return rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4593 | iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4594 | txq->q.write_ptr | (txq_id << 8)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4595 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4596 | |
| 4597 | /* else not in power-save mode, uCode will never sleep when we're |
| 4598 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 4599 | } else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4600 | iwl4965_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4601 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4602 | |
| 4603 | txq->need_update = 0; |
| 4604 | |
| 4605 | return rc; |
| 4606 | } |
| 4607 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4608 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4609 | static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4610 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4611 | DECLARE_MAC_BUF(mac); |
| 4612 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4613 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4614 | iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4615 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 4616 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 4617 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 4618 | le32_to_cpu(rxon->filter_flags)); |
| 4619 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 4620 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 4621 | rxon->ofdm_basic_rates); |
| 4622 | IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4623 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 4624 | print_mac(mac, rxon->node_addr)); |
| 4625 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 4626 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4627 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 4628 | } |
| 4629 | #endif |
| 4630 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4631 | static void iwl4965_enable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4632 | { |
| 4633 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 4634 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4635 | iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4636 | } |
| 4637 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4638 | static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4639 | { |
| 4640 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 4641 | |
| 4642 | /* disable interrupts from uCode/NIC to host */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4643 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4644 | |
| 4645 | /* acknowledge/clear/reset any interrupts still pending |
| 4646 | * from uCode or flow handler (Rx/Tx DMA) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4647 | iwl4965_write32(priv, CSR_INT, 0xffffffff); |
| 4648 | iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4649 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 4650 | } |
| 4651 | |
| 4652 | static const char *desc_lookup(int i) |
| 4653 | { |
| 4654 | switch (i) { |
| 4655 | case 1: |
| 4656 | return "FAIL"; |
| 4657 | case 2: |
| 4658 | return "BAD_PARAM"; |
| 4659 | case 3: |
| 4660 | return "BAD_CHECKSUM"; |
| 4661 | case 4: |
| 4662 | return "NMI_INTERRUPT"; |
| 4663 | case 5: |
| 4664 | return "SYSASSERT"; |
| 4665 | case 6: |
| 4666 | return "FATAL_ERROR"; |
| 4667 | } |
| 4668 | |
| 4669 | return "UNKNOWN"; |
| 4670 | } |
| 4671 | |
| 4672 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4673 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4674 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4675 | static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4676 | { |
| 4677 | u32 data2, line; |
| 4678 | u32 desc, time, count, base, data1; |
| 4679 | u32 blink1, blink2, ilink1, ilink2; |
| 4680 | int rc; |
| 4681 | |
| 4682 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 4683 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4684 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4685 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 4686 | return; |
| 4687 | } |
| 4688 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4689 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4690 | if (rc) { |
| 4691 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4692 | return; |
| 4693 | } |
| 4694 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4695 | count = iwl4965_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4696 | |
| 4697 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 4698 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
Tomas Winkler | 2acae16 | 2008-03-02 01:25:59 +0200 | [diff] [blame] | 4699 | IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4700 | } |
| 4701 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4702 | desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 4703 | blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 4704 | blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 4705 | ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 4706 | ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 4707 | data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 4708 | data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 4709 | line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 4710 | time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4711 | |
| 4712 | IWL_ERROR("Desc Time " |
| 4713 | "data1 data2 line\n"); |
| 4714 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 4715 | desc_lookup(desc), desc, time, data1, data2, line); |
| 4716 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 4717 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 4718 | ilink1, ilink2); |
| 4719 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4720 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 4724 | |
| 4725 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4726 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4727 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4728 | * NOTE: Must be called with iwl4965_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4729 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4730 | static void iwl4965_print_event_log(struct iwl4965_priv *priv, u32 start_idx, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4731 | u32 num_events, u32 mode) |
| 4732 | { |
| 4733 | u32 i; |
| 4734 | u32 base; /* SRAM byte address of event log header */ |
| 4735 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 4736 | u32 ptr; /* SRAM byte address of log data */ |
| 4737 | u32 ev, time, data; /* event log data */ |
| 4738 | |
| 4739 | if (num_events == 0) |
| 4740 | return; |
| 4741 | |
| 4742 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 4743 | |
| 4744 | if (mode == 0) |
| 4745 | event_size = 2 * sizeof(u32); |
| 4746 | else |
| 4747 | event_size = 3 * sizeof(u32); |
| 4748 | |
| 4749 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 4750 | |
| 4751 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 4752 | * place event id # at far right for easier visual parsing. */ |
| 4753 | for (i = 0; i < num_events; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4754 | ev = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4755 | ptr += sizeof(u32); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4756 | time = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4757 | ptr += sizeof(u32); |
| 4758 | if (mode == 0) |
| 4759 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 4760 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4761 | data = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4762 | ptr += sizeof(u32); |
| 4763 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 4764 | } |
| 4765 | } |
| 4766 | } |
| 4767 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4768 | static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4769 | { |
| 4770 | int rc; |
| 4771 | u32 base; /* SRAM byte address of event log header */ |
| 4772 | u32 capacity; /* event log capacity in # entries */ |
| 4773 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 4774 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 4775 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 4776 | u32 size; /* # entries that we'll print */ |
| 4777 | |
| 4778 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4779 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4780 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 4781 | return; |
| 4782 | } |
| 4783 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4784 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4785 | if (rc) { |
| 4786 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4787 | return; |
| 4788 | } |
| 4789 | |
| 4790 | /* event log header */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4791 | capacity = iwl4965_read_targ_mem(priv, base); |
| 4792 | mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 4793 | num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 4794 | next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4795 | |
| 4796 | size = num_wraps ? capacity : next_entry; |
| 4797 | |
| 4798 | /* bail out if nothing in log */ |
| 4799 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4800 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4801 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4802 | return; |
| 4803 | } |
| 4804 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4805 | IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4806 | size, num_wraps); |
| 4807 | |
| 4808 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 4809 | * i.e the next one that uCode would fill. */ |
| 4810 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4811 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4812 | capacity - next_entry, mode); |
| 4813 | |
| 4814 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4815 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4816 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4817 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4818 | } |
| 4819 | |
| 4820 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4821 | * iwl4965_irq_handle_error - called for HW or SW error interrupt from card |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4822 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4823 | static void iwl4965_irq_handle_error(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4824 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4825 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4826 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 4827 | |
| 4828 | /* Cancel currently queued command. */ |
| 4829 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4830 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4831 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4832 | if (iwl4965_debug_level & IWL_DL_FW_ERRORS) { |
| 4833 | iwl4965_dump_nic_error_log(priv); |
| 4834 | iwl4965_dump_nic_event_log(priv); |
| 4835 | iwl4965_print_rx_config_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4836 | } |
| 4837 | #endif |
| 4838 | |
| 4839 | wake_up_interruptible(&priv->wait_command_queue); |
| 4840 | |
| 4841 | /* Keep the restart process from trying to send host |
| 4842 | * commands by clearing the INIT status bit */ |
| 4843 | clear_bit(STATUS_READY, &priv->status); |
| 4844 | |
| 4845 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4846 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 4847 | "Restarting adapter due to uCode error.\n"); |
| 4848 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4849 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4850 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 4851 | sizeof(priv->recovery_rxon)); |
| 4852 | priv->error_recovering = 1; |
| 4853 | } |
| 4854 | queue_work(priv->workqueue, &priv->restart); |
| 4855 | } |
| 4856 | } |
| 4857 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4858 | static void iwl4965_error_recovery(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4859 | { |
| 4860 | unsigned long flags; |
| 4861 | |
| 4862 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 4863 | sizeof(priv->staging_rxon)); |
| 4864 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4865 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4866 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4867 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4868 | |
| 4869 | spin_lock_irqsave(&priv->lock, flags); |
| 4870 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 4871 | priv->error_recovering = 0; |
| 4872 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4873 | } |
| 4874 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4875 | static void iwl4965_irq_tasklet(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4876 | { |
| 4877 | u32 inta, handled = 0; |
| 4878 | u32 inta_fh; |
| 4879 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4880 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4881 | u32 inta_mask; |
| 4882 | #endif |
| 4883 | |
| 4884 | spin_lock_irqsave(&priv->lock, flags); |
| 4885 | |
| 4886 | /* Ack/clear/reset pending uCode interrupts. |
| 4887 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4888 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4889 | inta = iwl4965_read32(priv, CSR_INT); |
| 4890 | iwl4965_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4891 | |
| 4892 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4893 | * Any new interrupts that happen after this, either while we're |
| 4894 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4895 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
| 4896 | iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4897 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4898 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4899 | if (iwl4965_debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4900 | /* just for debug */ |
| 4901 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4902 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4903 | inta, inta_mask, inta_fh); |
| 4904 | } |
| 4905 | #endif |
| 4906 | |
| 4907 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 4908 | * atomic, make sure that inta covers all the interrupts that |
| 4909 | * we've discovered, even if FH interrupt came in just after |
| 4910 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4911 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4912 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4913 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4914 | inta |= CSR_INT_BIT_FH_TX; |
| 4915 | |
| 4916 | /* Now service all interrupt bits discovered above. */ |
| 4917 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 4918 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 4919 | |
| 4920 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4921 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4922 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4923 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4924 | |
| 4925 | handled |= CSR_INT_BIT_HW_ERR; |
| 4926 | |
| 4927 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4928 | |
| 4929 | return; |
| 4930 | } |
| 4931 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4932 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4933 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4934 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4935 | if (inta & CSR_INT_BIT_SCD) |
| 4936 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 4937 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4938 | |
| 4939 | /* Alive notification via Rx interrupt will do the real work */ |
| 4940 | if (inta & CSR_INT_BIT_ALIVE) |
| 4941 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 4942 | } |
| 4943 | #endif |
| 4944 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4945 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4946 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4947 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4948 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 4949 | int hw_rf_kill = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4950 | if (!(iwl4965_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4951 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 4952 | hw_rf_kill = 1; |
| 4953 | |
| 4954 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 4955 | "RF_KILL bit toggled to %s.\n", |
| 4956 | hw_rf_kill ? "disable radio":"enable radio"); |
| 4957 | |
| 4958 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 4959 | * when we loaded driver, and is now set to "enable". |
| 4960 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 4961 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 4962 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 4963 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4964 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 4965 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4966 | |
| 4967 | handled |= CSR_INT_BIT_RF_KILL; |
| 4968 | } |
| 4969 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4970 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4971 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 4972 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 4973 | handled |= CSR_INT_BIT_CT_KILL; |
| 4974 | } |
| 4975 | |
| 4976 | /* Error detected by uCode */ |
| 4977 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 4978 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 4979 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4980 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4981 | handled |= CSR_INT_BIT_SW_ERR; |
| 4982 | } |
| 4983 | |
| 4984 | /* uCode wakes up after power-down sleep */ |
| 4985 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 4986 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4987 | iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq); |
| 4988 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 4989 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 4990 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 4991 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 4992 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 4993 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4994 | |
| 4995 | handled |= CSR_INT_BIT_WAKEUP; |
| 4996 | } |
| 4997 | |
| 4998 | /* All uCode command responses, including Tx command responses, |
| 4999 | * Rx "responses" (frame-received notification), and other |
| 5000 | * notifications from uCode come through here*/ |
| 5001 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5002 | iwl4965_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5003 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 5004 | } |
| 5005 | |
| 5006 | if (inta & CSR_INT_BIT_FH_TX) { |
| 5007 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 5008 | handled |= CSR_INT_BIT_FH_TX; |
| 5009 | } |
| 5010 | |
| 5011 | if (inta & ~handled) |
| 5012 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 5013 | |
| 5014 | if (inta & ~CSR_INI_SET_MASK) { |
| 5015 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 5016 | inta & ~CSR_INI_SET_MASK); |
| 5017 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 5018 | } |
| 5019 | |
| 5020 | /* Re-enable all interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5021 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5022 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5023 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5024 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
| 5025 | inta = iwl4965_read32(priv, CSR_INT); |
| 5026 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
| 5027 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5028 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 5029 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 5030 | } |
| 5031 | #endif |
| 5032 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5033 | } |
| 5034 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5035 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5036 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5037 | struct iwl4965_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5038 | u32 inta, inta_mask; |
| 5039 | u32 inta_fh; |
| 5040 | if (!priv) |
| 5041 | return IRQ_NONE; |
| 5042 | |
| 5043 | spin_lock(&priv->lock); |
| 5044 | |
| 5045 | /* Disable (but don't clear!) interrupts here to avoid |
| 5046 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 5047 | * If we have something to service, the tasklet will re-enable ints. |
| 5048 | * If we *don't* have something, we'll re-enable before leaving here. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5049 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 5050 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5051 | |
| 5052 | /* Discover which interrupts are active/pending */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5053 | inta = iwl4965_read32(priv, CSR_INT); |
| 5054 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5055 | |
| 5056 | /* Ignore interrupt if there's nothing in NIC to service. |
| 5057 | * This may be due to IRQ shared with another device, |
| 5058 | * or due to sporadic interrupts thrown from our NIC. */ |
| 5059 | if (!inta && !inta_fh) { |
| 5060 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 5061 | goto none; |
| 5062 | } |
| 5063 | |
| 5064 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5065 | /* Hardware disappeared. It might have already raised |
| 5066 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5067 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5068 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5072 | inta, inta_mask, inta_fh); |
| 5073 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 5074 | inta &= ~CSR_INT_BIT_SCD; |
| 5075 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5076 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 5077 | if (likely(inta || inta_fh)) |
| 5078 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5079 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5080 | unplugged: |
| 5081 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5082 | return IRQ_HANDLED; |
| 5083 | |
| 5084 | none: |
| 5085 | /* re-enable interrupts here since we don't have anything to service. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5086 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5087 | spin_unlock(&priv->lock); |
| 5088 | return IRQ_NONE; |
| 5089 | } |
| 5090 | |
| 5091 | /************************** EEPROM BANDS **************************** |
| 5092 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5093 | * The iwl4965_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5094 | * EEPROM contents to the specific channel number supported for each |
| 5095 | * band. |
| 5096 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5097 | * For example, iwl4965_priv->eeprom.band_3_channels[4] from the band_3 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5098 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 5099 | * The specific geography and calibration information for that channel |
| 5100 | * is contained in the eeprom map itself. |
| 5101 | * |
| 5102 | * During init, we copy the eeprom information and channel map |
| 5103 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 5104 | * |
| 5105 | * channel_map_24/52 provides the index in the channel_info array for a |
| 5106 | * given channel. We have to have two separate maps as there is channel |
| 5107 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 5108 | * band_2 |
| 5109 | * |
| 5110 | * A value of 0xff stored in the channel_map indicates that the channel |
| 5111 | * is not supported by the hardware at all. |
| 5112 | * |
| 5113 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 5114 | * valid for Tx with the current hardware. This means that |
| 5115 | * while the system can tune and receive on a given channel, it may not |
| 5116 | * be able to associate or transmit any frames on that |
| 5117 | * channel. There is no corresponding channel information for that |
| 5118 | * entry. |
| 5119 | * |
| 5120 | *********************************************************************/ |
| 5121 | |
| 5122 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5123 | static const u8 iwl4965_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5124 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 5125 | }; |
| 5126 | |
| 5127 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5128 | static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5129 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 5130 | }; |
| 5131 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5132 | static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5133 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 5134 | }; |
| 5135 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5136 | static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5137 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 5138 | }; |
| 5139 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5140 | static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5141 | 145, 149, 153, 157, 161, 165 |
| 5142 | }; |
| 5143 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5144 | static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5145 | 1, 2, 3, 4, 5, 6, 7 |
| 5146 | }; |
| 5147 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5148 | static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5149 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 |
| 5150 | }; |
| 5151 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5152 | static void iwl4965_init_band_reference(const struct iwl4965_priv *priv, |
| 5153 | int band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5154 | int *eeprom_ch_count, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5155 | const struct iwl4965_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5156 | **eeprom_ch_info, |
| 5157 | const u8 **eeprom_ch_index) |
| 5158 | { |
| 5159 | switch (band) { |
| 5160 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5161 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5162 | *eeprom_ch_info = priv->eeprom.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5163 | *eeprom_ch_index = iwl4965_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5164 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5165 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5166 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5167 | *eeprom_ch_info = priv->eeprom.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5168 | *eeprom_ch_index = iwl4965_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5169 | break; |
| 5170 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5171 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5172 | *eeprom_ch_info = priv->eeprom.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5173 | *eeprom_ch_index = iwl4965_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5174 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5175 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5176 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5177 | *eeprom_ch_info = priv->eeprom.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5178 | *eeprom_ch_index = iwl4965_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5179 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5180 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5181 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5182 | *eeprom_ch_info = priv->eeprom.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5183 | *eeprom_ch_index = iwl4965_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5184 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5185 | case 6: /* 2.4GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5186 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5187 | *eeprom_ch_info = priv->eeprom.band_24_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5188 | *eeprom_ch_index = iwl4965_eeprom_band_6; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5189 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5190 | case 7: /* 5 GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5191 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5192 | *eeprom_ch_info = priv->eeprom.band_52_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5193 | *eeprom_ch_index = iwl4965_eeprom_band_7; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5194 | break; |
| 5195 | default: |
| 5196 | BUG(); |
| 5197 | return; |
| 5198 | } |
| 5199 | } |
| 5200 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5201 | /** |
| 5202 | * iwl4965_get_channel_info - Find driver's private channel info |
| 5203 | * |
| 5204 | * Based on band and channel number. |
| 5205 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5206 | const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5207 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5208 | { |
| 5209 | int i; |
| 5210 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5211 | switch (band) { |
| 5212 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5213 | for (i = 14; i < priv->channel_count; i++) { |
| 5214 | if (priv->channel_info[i].channel == channel) |
| 5215 | return &priv->channel_info[i]; |
| 5216 | } |
| 5217 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5218 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5219 | if (channel >= 1 && channel <= 14) |
| 5220 | return &priv->channel_info[channel - 1]; |
| 5221 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5222 | default: |
| 5223 | BUG(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5224 | } |
| 5225 | |
| 5226 | return NULL; |
| 5227 | } |
| 5228 | |
| 5229 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 5230 | ? # x " " : "") |
| 5231 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5232 | /** |
| 5233 | * iwl4965_init_channel_map - Set up driver's info for all possible channels |
| 5234 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5235 | static int iwl4965_init_channel_map(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5236 | { |
| 5237 | int eeprom_ch_count = 0; |
| 5238 | const u8 *eeprom_ch_index = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5239 | const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5240 | int band, ch; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5241 | struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5242 | |
| 5243 | if (priv->channel_count) { |
| 5244 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 5245 | return 0; |
| 5246 | } |
| 5247 | |
| 5248 | if (priv->eeprom.version < 0x2f) { |
| 5249 | IWL_WARNING("Unsupported EEPROM version: 0x%04X\n", |
| 5250 | priv->eeprom.version); |
| 5251 | return -EINVAL; |
| 5252 | } |
| 5253 | |
| 5254 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 5255 | |
| 5256 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5257 | ARRAY_SIZE(iwl4965_eeprom_band_1) + |
| 5258 | ARRAY_SIZE(iwl4965_eeprom_band_2) + |
| 5259 | ARRAY_SIZE(iwl4965_eeprom_band_3) + |
| 5260 | ARRAY_SIZE(iwl4965_eeprom_band_4) + |
| 5261 | ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5262 | |
| 5263 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 5264 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5265 | priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5266 | priv->channel_count, GFP_KERNEL); |
| 5267 | if (!priv->channel_info) { |
| 5268 | IWL_ERROR("Could not allocate channel_info\n"); |
| 5269 | priv->channel_count = 0; |
| 5270 | return -ENOMEM; |
| 5271 | } |
| 5272 | |
| 5273 | ch_info = priv->channel_info; |
| 5274 | |
| 5275 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 5276 | * channel map we maintain (that contains additional information than |
| 5277 | * what just in the EEPROM) */ |
| 5278 | for (band = 1; band <= 5; band++) { |
| 5279 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5280 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5281 | &eeprom_ch_info, &eeprom_ch_index); |
| 5282 | |
| 5283 | /* Loop through each band adding each of the channels */ |
| 5284 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5285 | ch_info->channel = eeprom_ch_index[ch]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5286 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 5287 | IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5288 | |
| 5289 | /* permanently store EEPROM's channel regulatory flags |
| 5290 | * and max power in channel info database. */ |
| 5291 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 5292 | |
| 5293 | /* Copy the run-time flags so they are there even on |
| 5294 | * invalid channels */ |
| 5295 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 5296 | |
| 5297 | if (!(is_channel_valid(ch_info))) { |
| 5298 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 5299 | "No traffic\n", |
| 5300 | ch_info->channel, |
| 5301 | ch_info->flags, |
| 5302 | is_channel_a_band(ch_info) ? |
| 5303 | "5.2" : "2.4"); |
| 5304 | ch_info++; |
| 5305 | continue; |
| 5306 | } |
| 5307 | |
| 5308 | /* Initialize regulatory-based run-time data */ |
| 5309 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 5310 | eeprom_ch_info[ch].max_power_avg; |
| 5311 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 5312 | ch_info->min_power = 0; |
| 5313 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5314 | IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5315 | " %ddBm): Ad-Hoc %ssupported\n", |
| 5316 | ch_info->channel, |
| 5317 | is_channel_a_band(ch_info) ? |
| 5318 | "5.2" : "2.4", |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5319 | CHECK_AND_PRINT(VALID), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5320 | CHECK_AND_PRINT(IBSS), |
| 5321 | CHECK_AND_PRINT(ACTIVE), |
| 5322 | CHECK_AND_PRINT(RADAR), |
| 5323 | CHECK_AND_PRINT(WIDE), |
| 5324 | CHECK_AND_PRINT(NARROW), |
| 5325 | CHECK_AND_PRINT(DFS), |
| 5326 | eeprom_ch_info[ch].flags, |
| 5327 | eeprom_ch_info[ch].max_power_avg, |
| 5328 | ((eeprom_ch_info[ch]. |
| 5329 | flags & EEPROM_CHANNEL_IBSS) |
| 5330 | && !(eeprom_ch_info[ch]. |
| 5331 | flags & EEPROM_CHANNEL_RADAR)) |
| 5332 | ? "" : "not "); |
| 5333 | |
| 5334 | /* Set the user_txpower_limit to the highest power |
| 5335 | * supported by any channel */ |
| 5336 | if (eeprom_ch_info[ch].max_power_avg > |
| 5337 | priv->user_txpower_limit) |
| 5338 | priv->user_txpower_limit = |
| 5339 | eeprom_ch_info[ch].max_power_avg; |
| 5340 | |
| 5341 | ch_info++; |
| 5342 | } |
| 5343 | } |
| 5344 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5345 | /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5346 | for (band = 6; band <= 7; band++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5347 | enum ieee80211_band ieeeband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5348 | u8 fat_extension_chan; |
| 5349 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5350 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5351 | &eeprom_ch_info, &eeprom_ch_index); |
| 5352 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5353 | /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5354 | ieeeband = (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5355 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5356 | /* Loop through each band adding each of the channels */ |
| 5357 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5358 | |
| 5359 | if ((band == 6) && |
| 5360 | ((eeprom_ch_index[ch] == 5) || |
| 5361 | (eeprom_ch_index[ch] == 6) || |
| 5362 | (eeprom_ch_index[ch] == 7))) |
| 5363 | fat_extension_chan = HT_IE_EXT_CHANNEL_MAX; |
| 5364 | else |
| 5365 | fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; |
| 5366 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5367 | /* Set up driver's info for lower half */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5368 | iwl4965_set_fat_chan_info(priv, ieeeband, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5369 | eeprom_ch_index[ch], |
| 5370 | &(eeprom_ch_info[ch]), |
| 5371 | fat_extension_chan); |
| 5372 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5373 | /* Set up driver's info for upper half */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5374 | iwl4965_set_fat_chan_info(priv, ieeeband, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5375 | (eeprom_ch_index[ch] + 4), |
| 5376 | &(eeprom_ch_info[ch]), |
| 5377 | HT_IE_EXT_CHANNEL_BELOW); |
| 5378 | } |
| 5379 | } |
| 5380 | |
| 5381 | return 0; |
| 5382 | } |
| 5383 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5384 | /* |
| 5385 | * iwl4965_free_channel_map - undo allocations in iwl4965_init_channel_map |
| 5386 | */ |
| 5387 | static void iwl4965_free_channel_map(struct iwl4965_priv *priv) |
| 5388 | { |
| 5389 | kfree(priv->channel_info); |
| 5390 | priv->channel_count = 0; |
| 5391 | } |
| 5392 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5393 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 5394 | * sending probe req. This should be set long enough to hear probe responses |
| 5395 | * from more than one AP. */ |
| 5396 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5397 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 5398 | |
| 5399 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 5400 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 5401 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 5402 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 5403 | * no other traffic). |
| 5404 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 5405 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 5406 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 5407 | |
| 5408 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 5409 | * Must be set longer than active dwell time. |
| 5410 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 5411 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5412 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 5413 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 5414 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 5415 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5416 | static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv, |
| 5417 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5418 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5419 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5420 | return IWL_ACTIVE_DWELL_TIME_52; |
| 5421 | else |
| 5422 | return IWL_ACTIVE_DWELL_TIME_24; |
| 5423 | } |
| 5424 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5425 | static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, |
| 5426 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5427 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5428 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 5429 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5430 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 5431 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 5432 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5433 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5434 | /* If we're associated, we clamp the maximum passive |
| 5435 | * dwell time to be 98% of the beacon interval (minus |
| 5436 | * 2 * channel tune time) */ |
| 5437 | passive = priv->beacon_int; |
| 5438 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 5439 | passive = IWL_PASSIVE_DWELL_BASE; |
| 5440 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 5441 | } |
| 5442 | |
| 5443 | if (passive <= active) |
| 5444 | passive = active + 1; |
| 5445 | |
| 5446 | return passive; |
| 5447 | } |
| 5448 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5449 | static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, |
| 5450 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5451 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5452 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5453 | { |
| 5454 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5455 | const struct ieee80211_supported_band *sband; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5456 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5457 | u16 passive_dwell = 0; |
| 5458 | u16 active_dwell = 0; |
| 5459 | int added, i; |
| 5460 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5461 | sband = iwl4965_get_hw_mode(priv, band); |
| 5462 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5463 | return 0; |
| 5464 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5465 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5466 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5467 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 5468 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5469 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5470 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
| 5471 | if (ieee80211_frequency_to_channel(channels[i].center_freq) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5472 | le16_to_cpu(priv->active_rxon.channel)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5473 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5474 | IWL_DEBUG_SCAN |
| 5475 | ("Skipping current channel %d\n", |
| 5476 | le16_to_cpu(priv->active_rxon.channel)); |
| 5477 | continue; |
| 5478 | } |
| 5479 | } else if (priv->only_active_channel) |
| 5480 | continue; |
| 5481 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5482 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5483 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5484 | ch_info = iwl4965_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5485 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5486 | if (!is_channel_valid(ch_info)) { |
| 5487 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 5488 | scan_ch->channel); |
| 5489 | continue; |
| 5490 | } |
| 5491 | |
| 5492 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5493 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5494 | scan_ch->type = 0; /* passive */ |
| 5495 | else |
| 5496 | scan_ch->type = 1; /* active */ |
| 5497 | |
| 5498 | if (scan_ch->type & 1) |
| 5499 | scan_ch->type |= (direct_mask << 1); |
| 5500 | |
| 5501 | if (is_channel_narrow(ch_info)) |
| 5502 | scan_ch->type |= (1 << 7); |
| 5503 | |
| 5504 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 5505 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 5506 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5507 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5508 | scan_ch->tpc.dsp_atten = 110; |
| 5509 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 5510 | |
| 5511 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5512 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5513 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 5514 | else { |
| 5515 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 5516 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5517 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 5518 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5519 | */ |
| 5520 | } |
| 5521 | |
| 5522 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 5523 | scan_ch->channel, |
| 5524 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 5525 | (scan_ch->type & 1) ? |
| 5526 | active_dwell : passive_dwell); |
| 5527 | |
| 5528 | scan_ch++; |
| 5529 | added++; |
| 5530 | } |
| 5531 | |
| 5532 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 5533 | return added; |
| 5534 | } |
| 5535 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5536 | static void iwl4965_init_hw_rates(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5537 | struct ieee80211_rate *rates) |
| 5538 | { |
| 5539 | int i; |
| 5540 | |
| 5541 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5542 | rates[i].bitrate = iwl4965_rates[i].ieee * 5; |
| 5543 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 5544 | rates[i].hw_value_short = i; |
| 5545 | rates[i].flags = 0; |
| 5546 | if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5547 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5548 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5549 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5550 | rates[i].flags |= (iwl4965_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5551 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5552 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5553 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5554 | } |
| 5555 | |
| 5556 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5557 | * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5558 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5559 | static int iwl4965_init_geos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5560 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5561 | struct iwl4965_channel_info *ch; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5562 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5563 | struct ieee80211_channel *channels; |
| 5564 | struct ieee80211_channel *geo_ch; |
| 5565 | struct ieee80211_rate *rates; |
| 5566 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5567 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5568 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 5569 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5570 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 5571 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5572 | return 0; |
| 5573 | } |
| 5574 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5575 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 5576 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5577 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5578 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5579 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5580 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5581 | GFP_KERNEL); |
| 5582 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5583 | kfree(channels); |
| 5584 | return -ENOMEM; |
| 5585 | } |
| 5586 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5587 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5588 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 5589 | sband->channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)]; |
| 5590 | /* just OFDM */ |
| 5591 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
| 5592 | sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5593 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5594 | iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_5GHZ); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5595 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5596 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 5597 | sband->channels = channels; |
| 5598 | /* OFDM & CCK */ |
| 5599 | sband->bitrates = rates; |
| 5600 | sband->n_bitrates = IWL_RATE_COUNT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5601 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5602 | iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_2GHZ); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5603 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5604 | priv->ieee_channels = channels; |
| 5605 | priv->ieee_rates = rates; |
| 5606 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5607 | iwl4965_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5608 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5609 | for (i = 0; i < priv->channel_count; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5610 | ch = &priv->channel_info[i]; |
| 5611 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5612 | /* FIXME: might be removed if scan is OK */ |
| 5613 | if (!is_channel_valid(ch)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5614 | continue; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5615 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5616 | if (is_channel_a_band(ch)) |
| 5617 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 5618 | else |
| 5619 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5620 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5621 | geo_ch = &sband->channels[sband->n_channels++]; |
| 5622 | |
| 5623 | geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5624 | geo_ch->max_power = ch->max_power_avg; |
| 5625 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 5626 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5627 | |
| 5628 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5629 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 5630 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5631 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5632 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 5633 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5634 | |
| 5635 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5636 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5637 | |
| 5638 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 5639 | priv->max_channel_txpower_limit = |
| 5640 | ch->max_power_avg; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5641 | } else { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5642 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5643 | } |
| 5644 | |
| 5645 | /* Save flags for reg domain usage */ |
| 5646 | geo_ch->orig_flags = geo_ch->flags; |
| 5647 | |
| 5648 | IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n", |
| 5649 | ch->channel, geo_ch->center_freq, |
| 5650 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 5651 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 5652 | "restricted" : "valid", |
| 5653 | geo_ch->flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5654 | } |
| 5655 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5656 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && |
| 5657 | priv->cfg->sku & IWL_SKU_A) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5658 | printk(KERN_INFO DRV_NAME |
| 5659 | ": Incorrectly detected BG card as ABG. Please send " |
| 5660 | "your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 5661 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5662 | priv->cfg->sku &= ~IWL_SKU_A; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5663 | } |
| 5664 | |
| 5665 | printk(KERN_INFO DRV_NAME |
| 5666 | ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5667 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 5668 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5669 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5670 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 5671 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5672 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5673 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5674 | |
| 5675 | return 0; |
| 5676 | } |
| 5677 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5678 | /* |
| 5679 | * iwl4965_free_geos - undo allocations in iwl4965_init_geos |
| 5680 | */ |
| 5681 | static void iwl4965_free_geos(struct iwl4965_priv *priv) |
| 5682 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5683 | kfree(priv->ieee_channels); |
| 5684 | kfree(priv->ieee_rates); |
| 5685 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5686 | } |
| 5687 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5688 | /****************************************************************************** |
| 5689 | * |
| 5690 | * uCode download functions |
| 5691 | * |
| 5692 | ******************************************************************************/ |
| 5693 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5694 | static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5695 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5696 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 5697 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 5698 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 5699 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 5700 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 5701 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5702 | } |
| 5703 | |
| 5704 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5705 | * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5706 | * looking at all data. |
| 5707 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 5708 | static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 *image, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5709 | u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5710 | { |
| 5711 | u32 val; |
| 5712 | u32 save_len = len; |
| 5713 | int rc = 0; |
| 5714 | u32 errcnt; |
| 5715 | |
| 5716 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5717 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5718 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5719 | if (rc) |
| 5720 | return rc; |
| 5721 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5722 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5723 | |
| 5724 | errcnt = 0; |
| 5725 | for (; len > 0; len -= sizeof(u32), image++) { |
| 5726 | /* read data comes through single port, auto-incr addr */ |
| 5727 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5728 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5729 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5730 | if (val != le32_to_cpu(*image)) { |
| 5731 | IWL_ERROR("uCode INST section is invalid at " |
| 5732 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5733 | save_len - len, val, le32_to_cpu(*image)); |
| 5734 | rc = -EIO; |
| 5735 | errcnt++; |
| 5736 | if (errcnt >= 20) |
| 5737 | break; |
| 5738 | } |
| 5739 | } |
| 5740 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5741 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5742 | |
| 5743 | if (!errcnt) |
| 5744 | IWL_DEBUG_INFO |
| 5745 | ("ucode image in INSTRUCTION memory is good\n"); |
| 5746 | |
| 5747 | return rc; |
| 5748 | } |
| 5749 | |
| 5750 | |
| 5751 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5752 | * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5753 | * using sample data 100 bytes apart. If these sample points are good, |
| 5754 | * it's a pretty good bet that everything between them is good, too. |
| 5755 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5756 | static int iwl4965_verify_inst_sparse(struct iwl4965_priv *priv, __le32 *image, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5757 | { |
| 5758 | u32 val; |
| 5759 | int rc = 0; |
| 5760 | u32 errcnt = 0; |
| 5761 | u32 i; |
| 5762 | |
| 5763 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5764 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5765 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5766 | if (rc) |
| 5767 | return rc; |
| 5768 | |
| 5769 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 5770 | /* read data comes through single port, auto-incr addr */ |
| 5771 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5772 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5773 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5774 | i + RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5775 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5776 | if (val != le32_to_cpu(*image)) { |
| 5777 | #if 0 /* Enable this if you want to see details */ |
| 5778 | IWL_ERROR("uCode INST section is invalid at " |
| 5779 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5780 | i, val, *image); |
| 5781 | #endif |
| 5782 | rc = -EIO; |
| 5783 | errcnt++; |
| 5784 | if (errcnt >= 3) |
| 5785 | break; |
| 5786 | } |
| 5787 | } |
| 5788 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5789 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5790 | |
| 5791 | return rc; |
| 5792 | } |
| 5793 | |
| 5794 | |
| 5795 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5796 | * iwl4965_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5797 | * and verify its contents |
| 5798 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5799 | static int iwl4965_verify_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5800 | { |
| 5801 | __le32 *image; |
| 5802 | u32 len; |
| 5803 | int rc = 0; |
| 5804 | |
| 5805 | /* Try bootstrap */ |
| 5806 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5807 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5808 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5809 | if (rc == 0) { |
| 5810 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 5811 | return 0; |
| 5812 | } |
| 5813 | |
| 5814 | /* Try initialize */ |
| 5815 | image = (__le32 *)priv->ucode_init.v_addr; |
| 5816 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5817 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5818 | if (rc == 0) { |
| 5819 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 5820 | return 0; |
| 5821 | } |
| 5822 | |
| 5823 | /* Try runtime/protocol */ |
| 5824 | image = (__le32 *)priv->ucode_code.v_addr; |
| 5825 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5826 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5827 | if (rc == 0) { |
| 5828 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 5829 | return 0; |
| 5830 | } |
| 5831 | |
| 5832 | IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
| 5833 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5834 | /* Since nothing seems to match, show first several data entries in |
| 5835 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 5836 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5837 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5838 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5839 | rc = iwl4965_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5840 | |
| 5841 | return rc; |
| 5842 | } |
| 5843 | |
| 5844 | |
| 5845 | /* check contents of special bootstrap uCode SRAM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5846 | static int iwl4965_verify_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5847 | { |
| 5848 | __le32 *image = priv->ucode_boot.v_addr; |
| 5849 | u32 len = priv->ucode_boot.len; |
| 5850 | u32 reg; |
| 5851 | u32 val; |
| 5852 | |
| 5853 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 5854 | |
| 5855 | /* verify BSM SRAM contents */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5856 | val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5857 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 5858 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 5859 | reg += sizeof(u32), image ++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5860 | val = iwl4965_read_prph(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5861 | if (val != le32_to_cpu(*image)) { |
| 5862 | IWL_ERROR("BSM uCode verification failed at " |
| 5863 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 5864 | BSM_SRAM_LOWER_BOUND, |
| 5865 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 5866 | val, le32_to_cpu(*image)); |
| 5867 | return -EIO; |
| 5868 | } |
| 5869 | } |
| 5870 | |
| 5871 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 5872 | |
| 5873 | return 0; |
| 5874 | } |
| 5875 | |
| 5876 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5877 | * iwl4965_load_bsm - Load bootstrap instructions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5878 | * |
| 5879 | * BSM operation: |
| 5880 | * |
| 5881 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 5882 | * in special SRAM that does not power down during RFKILL. When powering back |
| 5883 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 5884 | * the bootstrap program into the on-board processor, and starts it. |
| 5885 | * |
| 5886 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 5887 | * program from host DRAM locations indicated by the host driver in the |
| 5888 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 5889 | * automatically. |
| 5890 | * |
| 5891 | * When initializing the NIC, the host driver points the BSM to the |
| 5892 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 5893 | * notifies host via "initialize alive" that it is complete. |
| 5894 | * |
| 5895 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 5896 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 5897 | * (filled initially with starting data values for the on-board processor), |
| 5898 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 5899 | * which begins normal operation. |
| 5900 | * |
| 5901 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 5902 | * the backup data cache in DRAM before SRAM is powered down. |
| 5903 | * |
| 5904 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 5905 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 5906 | * and re-launches the runtime uCode from where it left off. |
| 5907 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5908 | static int iwl4965_load_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5909 | { |
| 5910 | __le32 *image = priv->ucode_boot.v_addr; |
| 5911 | u32 len = priv->ucode_boot.len; |
| 5912 | dma_addr_t pinst; |
| 5913 | dma_addr_t pdata; |
| 5914 | u32 inst_len; |
| 5915 | u32 data_len; |
| 5916 | int rc; |
| 5917 | int i; |
| 5918 | u32 done; |
| 5919 | u32 reg_offset; |
| 5920 | |
| 5921 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 5922 | |
| 5923 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 5924 | if (len > IWL_MAX_BSM_SIZE) |
| 5925 | return -EINVAL; |
| 5926 | |
| 5927 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5928 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5929 | * NOTE: iwl4965_initialize_alive_start() will replace these values, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5930 | * after the "initialize" uCode has run, to point to |
| 5931 | * runtime/protocol instructions and backup data cache. */ |
| 5932 | pinst = priv->ucode_init.p_addr >> 4; |
| 5933 | pdata = priv->ucode_init_data.p_addr >> 4; |
| 5934 | inst_len = priv->ucode_init.len; |
| 5935 | data_len = priv->ucode_init_data.len; |
| 5936 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5937 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5938 | if (rc) |
| 5939 | return rc; |
| 5940 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5941 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 5942 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 5943 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 5944 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5945 | |
| 5946 | /* Fill BSM memory with bootstrap instructions */ |
| 5947 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 5948 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 5949 | reg_offset += sizeof(u32), image++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5950 | _iwl4965_write_prph(priv, reg_offset, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5951 | le32_to_cpu(*image)); |
| 5952 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5953 | rc = iwl4965_verify_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5954 | if (rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5955 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5956 | return rc; |
| 5957 | } |
| 5958 | |
| 5959 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5960 | iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 5961 | iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5962 | RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5963 | iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5964 | |
| 5965 | /* Load bootstrap code into instruction SRAM now, |
| 5966 | * to prepare to load "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5967 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5968 | BSM_WR_CTRL_REG_BIT_START); |
| 5969 | |
| 5970 | /* Wait for load of bootstrap uCode to finish */ |
| 5971 | for (i = 0; i < 100; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5972 | done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5973 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 5974 | break; |
| 5975 | udelay(10); |
| 5976 | } |
| 5977 | if (i < 100) |
| 5978 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 5979 | else { |
| 5980 | IWL_ERROR("BSM write did not complete!\n"); |
| 5981 | return -EIO; |
| 5982 | } |
| 5983 | |
| 5984 | /* Enable future boot loads whenever power management unit triggers it |
| 5985 | * (e.g. when powering back up after power-save shutdown) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5986 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5987 | BSM_WR_CTRL_REG_BIT_START_EN); |
| 5988 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5989 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5990 | |
| 5991 | return 0; |
| 5992 | } |
| 5993 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5994 | static void iwl4965_nic_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5995 | { |
| 5996 | /* Remove all resets to allow NIC to operate */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5997 | iwl4965_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5998 | } |
| 5999 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6000 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6001 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6002 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6003 | * |
| 6004 | * Copy into buffers for card to fetch via bus-mastering |
| 6005 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6006 | static int iwl4965_read_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6007 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6008 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6009 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6010 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 6011 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6012 | u8 *src; |
| 6013 | size_t len; |
| 6014 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 6015 | |
| 6016 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 6017 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6018 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 6019 | if (ret < 0) { |
| 6020 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 6021 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6022 | goto error; |
| 6023 | } |
| 6024 | |
| 6025 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 6026 | name, ucode_raw->size); |
| 6027 | |
| 6028 | /* Make sure that we got at least our header! */ |
| 6029 | if (ucode_raw->size < sizeof(*ucode)) { |
| 6030 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6031 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6032 | goto err_release; |
| 6033 | } |
| 6034 | |
| 6035 | /* Data from ucode file: header followed by uCode images */ |
| 6036 | ucode = (void *)ucode_raw->data; |
| 6037 | |
| 6038 | ver = le32_to_cpu(ucode->ver); |
| 6039 | inst_size = le32_to_cpu(ucode->inst_size); |
| 6040 | data_size = le32_to_cpu(ucode->data_size); |
| 6041 | init_size = le32_to_cpu(ucode->init_size); |
| 6042 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 6043 | boot_size = le32_to_cpu(ucode->boot_size); |
| 6044 | |
| 6045 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 6046 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 6047 | inst_size); |
| 6048 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 6049 | data_size); |
| 6050 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 6051 | init_size); |
| 6052 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 6053 | init_data_size); |
| 6054 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 6055 | boot_size); |
| 6056 | |
| 6057 | /* Verify size of file vs. image size info in file's header */ |
| 6058 | if (ucode_raw->size < sizeof(*ucode) + |
| 6059 | inst_size + data_size + init_size + |
| 6060 | init_data_size + boot_size) { |
| 6061 | |
| 6062 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 6063 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6064 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6065 | goto err_release; |
| 6066 | } |
| 6067 | |
| 6068 | /* Verify that uCode images will fit in card's SRAM */ |
| 6069 | if (inst_size > IWL_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6070 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 6071 | inst_size); |
| 6072 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6073 | goto err_release; |
| 6074 | } |
| 6075 | |
| 6076 | if (data_size > IWL_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6077 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 6078 | data_size); |
| 6079 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6080 | goto err_release; |
| 6081 | } |
| 6082 | if (init_size > IWL_MAX_INST_SIZE) { |
| 6083 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6084 | ("uCode init instr len %d too large to fit in\n", |
| 6085 | init_size); |
| 6086 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6087 | goto err_release; |
| 6088 | } |
| 6089 | if (init_data_size > IWL_MAX_DATA_SIZE) { |
| 6090 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6091 | ("uCode init data len %d too large to fit in\n", |
| 6092 | init_data_size); |
| 6093 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6094 | goto err_release; |
| 6095 | } |
| 6096 | if (boot_size > IWL_MAX_BSM_SIZE) { |
| 6097 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6098 | ("uCode boot instr len %d too large to fit in\n", |
| 6099 | boot_size); |
| 6100 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6101 | goto err_release; |
| 6102 | } |
| 6103 | |
| 6104 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 6105 | |
| 6106 | /* Runtime instructions and 2 copies of data: |
| 6107 | * 1) unmodified from disk |
| 6108 | * 2) backup cache for save/restore during power-downs */ |
| 6109 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6110 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6111 | |
| 6112 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6113 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6114 | |
| 6115 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6116 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6117 | |
| 6118 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6119 | if (init_size && init_data_size) { |
| 6120 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6121 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6122 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6123 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6124 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6125 | |
| 6126 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 6127 | goto err_pci_alloc; |
| 6128 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6129 | |
| 6130 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6131 | if (boot_size) { |
| 6132 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6133 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6134 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6135 | if (!priv->ucode_boot.v_addr) |
| 6136 | goto err_pci_alloc; |
| 6137 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6138 | |
| 6139 | /* Copy images into buffers for card's bus-master reads ... */ |
| 6140 | |
| 6141 | /* Runtime instructions (first block of data in file) */ |
| 6142 | src = &ucode->data[0]; |
| 6143 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6144 | 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] | 6145 | memcpy(priv->ucode_code.v_addr, src, len); |
| 6146 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 6147 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 6148 | |
| 6149 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6150 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6151 | src = &ucode->data[inst_size]; |
| 6152 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6153 | 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] | 6154 | memcpy(priv->ucode_data.v_addr, src, len); |
| 6155 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 6156 | |
| 6157 | /* Initialization instructions (3rd block) */ |
| 6158 | if (init_size) { |
| 6159 | src = &ucode->data[inst_size + data_size]; |
| 6160 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6161 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 6162 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6163 | memcpy(priv->ucode_init.v_addr, src, len); |
| 6164 | } |
| 6165 | |
| 6166 | /* Initialization data (4th block) */ |
| 6167 | if (init_data_size) { |
| 6168 | src = &ucode->data[inst_size + data_size + init_size]; |
| 6169 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6170 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 6171 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6172 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 6173 | } |
| 6174 | |
| 6175 | /* Bootstrap instructions (5th block) */ |
| 6176 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 6177 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6178 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6179 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 6180 | |
| 6181 | /* We have our copies now, allow OS release its copies */ |
| 6182 | release_firmware(ucode_raw); |
| 6183 | return 0; |
| 6184 | |
| 6185 | err_pci_alloc: |
| 6186 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6187 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6188 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6189 | |
| 6190 | err_release: |
| 6191 | release_firmware(ucode_raw); |
| 6192 | |
| 6193 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6194 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6195 | } |
| 6196 | |
| 6197 | |
| 6198 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6199 | * iwl4965_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6200 | * |
| 6201 | * Tell initialization uCode where to find runtime uCode. |
| 6202 | * |
| 6203 | * BSM registers initially contain pointers to initialization uCode. |
| 6204 | * We need to replace them to load runtime uCode inst and data, |
| 6205 | * and to save runtime data when powering down. |
| 6206 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6207 | static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6208 | { |
| 6209 | dma_addr_t pinst; |
| 6210 | dma_addr_t pdata; |
| 6211 | int rc = 0; |
| 6212 | unsigned long flags; |
| 6213 | |
| 6214 | /* bits 35:4 for 4965 */ |
| 6215 | pinst = priv->ucode_code.p_addr >> 4; |
| 6216 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 6217 | |
| 6218 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6219 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6220 | if (rc) { |
| 6221 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6222 | return rc; |
| 6223 | } |
| 6224 | |
| 6225 | /* Tell bootstrap uCode where to find image to load */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6226 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6227 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6228 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6229 | priv->ucode_data.len); |
| 6230 | |
| 6231 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 6232 | * that all new ptr/size info is in place */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6233 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6234 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 6235 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6236 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6237 | |
| 6238 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6239 | |
| 6240 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 6241 | |
| 6242 | return rc; |
| 6243 | } |
| 6244 | |
| 6245 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6246 | * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6247 | * |
| 6248 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 6249 | * |
| 6250 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 6251 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 6252 | * (3945 does not contain this data). |
| 6253 | * |
| 6254 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 6255 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6256 | static void iwl4965_init_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6257 | { |
| 6258 | /* Check alive response for "valid" sign from uCode */ |
| 6259 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 6260 | /* We had an error bringing up the hardware, so take it |
| 6261 | * all the way back down so we can try again */ |
| 6262 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 6263 | goto restart; |
| 6264 | } |
| 6265 | |
| 6266 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 6267 | * This is a paranoid check, because we would not have gotten the |
| 6268 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6269 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6270 | /* Runtime instruction load was bad; |
| 6271 | * take it all the way back down so we can try again */ |
| 6272 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 6273 | goto restart; |
| 6274 | } |
| 6275 | |
| 6276 | /* Calculate temperature */ |
| 6277 | priv->temperature = iwl4965_get_temperature(priv); |
| 6278 | |
| 6279 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 6280 | * load and launch runtime uCode, which will send us another "Alive" |
| 6281 | * notification. */ |
| 6282 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6283 | if (iwl4965_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6284 | /* Runtime instruction load won't happen; |
| 6285 | * take it all the way back down so we can try again */ |
| 6286 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 6287 | goto restart; |
| 6288 | } |
| 6289 | return; |
| 6290 | |
| 6291 | restart: |
| 6292 | queue_work(priv->workqueue, &priv->restart); |
| 6293 | } |
| 6294 | |
| 6295 | |
| 6296 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6297 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6298 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6299 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6300 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6301 | static void iwl4965_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6302 | { |
| 6303 | int rc = 0; |
| 6304 | |
| 6305 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 6306 | |
| 6307 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 6308 | /* We had an error bringing up the hardware, so take it |
| 6309 | * all the way back down so we can try again */ |
| 6310 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 6311 | goto restart; |
| 6312 | } |
| 6313 | |
| 6314 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 6315 | * This is a paranoid check, because we would not have gotten the |
| 6316 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6317 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6318 | /* Runtime instruction load was bad; |
| 6319 | * take it all the way back down so we can try again */ |
| 6320 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 6321 | goto restart; |
| 6322 | } |
| 6323 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6324 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6325 | |
| 6326 | rc = iwl4965_alive_notify(priv); |
| 6327 | if (rc) { |
| 6328 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
| 6329 | rc); |
| 6330 | goto restart; |
| 6331 | } |
| 6332 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6333 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6334 | set_bit(STATUS_ALIVE, &priv->status); |
| 6335 | |
| 6336 | /* Clear out the uCode error bit if it is set */ |
| 6337 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 6338 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6339 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6340 | return; |
| 6341 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6342 | ieee80211_start_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6343 | |
| 6344 | priv->active_rate = priv->rates_mask; |
| 6345 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 6346 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6347 | iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6348 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6349 | if (iwl4965_is_associated(priv)) { |
| 6350 | struct iwl4965_rxon_cmd *active_rxon = |
| 6351 | (struct iwl4965_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6352 | |
| 6353 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 6354 | sizeof(priv->staging_rxon)); |
| 6355 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 6356 | } else { |
| 6357 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6358 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6359 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 6360 | } |
| 6361 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6362 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6363 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6364 | |
| 6365 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6366 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6367 | |
| 6368 | /* At this point, the NIC is initialized and operational */ |
| 6369 | priv->notif_missed_beacons = 0; |
| 6370 | set_bit(STATUS_READY, &priv->status); |
| 6371 | |
| 6372 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6373 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6374 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6375 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6376 | |
| 6377 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6378 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6379 | |
| 6380 | return; |
| 6381 | |
| 6382 | restart: |
| 6383 | queue_work(priv->workqueue, &priv->restart); |
| 6384 | } |
| 6385 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6386 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6387 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6388 | static void __iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6389 | { |
| 6390 | unsigned long flags; |
| 6391 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6392 | struct ieee80211_conf *conf = NULL; |
| 6393 | |
| 6394 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 6395 | |
| 6396 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6397 | |
| 6398 | if (!exit_pending) |
| 6399 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6400 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6401 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6402 | |
| 6403 | /* Unblock any waiting calls */ |
| 6404 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 6405 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6406 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 6407 | * exiting the module */ |
| 6408 | if (!exit_pending) |
| 6409 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6410 | |
| 6411 | /* stop and reset the on-board processor */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6412 | iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6413 | |
| 6414 | /* tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6415 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6416 | |
| 6417 | if (priv->mac80211_registered) |
| 6418 | ieee80211_stop_queues(priv->hw); |
| 6419 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6420 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6421 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6422 | if (!iwl4965_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6423 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6424 | STATUS_RF_KILL_HW | |
| 6425 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6426 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 6427 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 6428 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6429 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6430 | STATUS_IN_SUSPEND; |
| 6431 | goto exit; |
| 6432 | } |
| 6433 | |
| 6434 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 6435 | * SUSPEND bits and continue taking the NIC down. */ |
| 6436 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6437 | STATUS_RF_KILL_HW | |
| 6438 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6439 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 6440 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 6441 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6442 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6443 | STATUS_IN_SUSPEND | |
| 6444 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 6445 | STATUS_FW_ERROR; |
| 6446 | |
| 6447 | spin_lock_irqsave(&priv->lock, flags); |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6448 | iwl4965_clear_bit(priv, CSR_GP_CNTRL, |
| 6449 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6450 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6451 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6452 | iwl4965_hw_txq_ctx_stop(priv); |
| 6453 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6454 | |
| 6455 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6456 | if (!iwl4965_grab_nic_access(priv)) { |
| 6457 | iwl4965_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6458 | APMG_CLK_VAL_DMA_CLK_RQT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6459 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6460 | } |
| 6461 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6462 | |
| 6463 | udelay(5); |
| 6464 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6465 | iwl4965_hw_nic_stop_master(priv); |
| 6466 | iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
| 6467 | iwl4965_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6468 | |
| 6469 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6470 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6471 | |
| 6472 | if (priv->ibss_beacon) |
| 6473 | dev_kfree_skb(priv->ibss_beacon); |
| 6474 | priv->ibss_beacon = NULL; |
| 6475 | |
| 6476 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6477 | iwl4965_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6478 | } |
| 6479 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6480 | static void iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6481 | { |
| 6482 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6483 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6484 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6485 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6486 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6487 | } |
| 6488 | |
| 6489 | #define MAX_HW_RESTARTS 5 |
| 6490 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6491 | static int __iwl4965_up(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6492 | { |
| 6493 | int rc, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6494 | |
| 6495 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6496 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 6497 | return -EIO; |
| 6498 | } |
| 6499 | |
| 6500 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 6501 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 6502 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6503 | return -ENODEV; |
| 6504 | } |
| 6505 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 6506 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 6507 | IWL_ERROR("ucode not available for device bringup\n"); |
| 6508 | return -EIO; |
| 6509 | } |
| 6510 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6511 | /* If platform's RF_KILL switch is NOT set to KILL */ |
| 6512 | if (iwl4965_read32(priv, CSR_GP_CNTRL) & |
| 6513 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 6514 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6515 | else { |
| 6516 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6517 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
| 6518 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 6519 | return -ENODEV; |
| 6520 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6521 | } |
| 6522 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6523 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6524 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6525 | rc = iwl4965_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6526 | if (rc) { |
| 6527 | IWL_ERROR("Unable to int nic\n"); |
| 6528 | return rc; |
| 6529 | } |
| 6530 | |
| 6531 | /* make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6532 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6533 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6534 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 6535 | |
| 6536 | /* clear (again), then enable host interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6537 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 6538 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6539 | |
| 6540 | /* really make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6541 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6542 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6543 | |
| 6544 | /* Copy original ucode data image from disk into backup cache. |
| 6545 | * This will be used to initialize the on-board processor's |
| 6546 | * data SRAM for a clean start when the runtime program first loads. */ |
| 6547 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6548 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6549 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6550 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 6551 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6552 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6553 | |
| 6554 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 6555 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6556 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6557 | |
| 6558 | /* load bootstrap state machine, |
| 6559 | * load bootstrap program into processor's memory, |
| 6560 | * prepare to load the "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6561 | rc = iwl4965_load_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6562 | |
| 6563 | if (rc) { |
| 6564 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); |
| 6565 | continue; |
| 6566 | } |
| 6567 | |
| 6568 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6569 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6570 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6571 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 6572 | |
| 6573 | return 0; |
| 6574 | } |
| 6575 | |
| 6576 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6577 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6578 | |
| 6579 | /* tried to restart and config the device for as long as our |
| 6580 | * patience could withstand */ |
| 6581 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 6582 | return -EIO; |
| 6583 | } |
| 6584 | |
| 6585 | |
| 6586 | /***************************************************************************** |
| 6587 | * |
| 6588 | * Workqueue callbacks |
| 6589 | * |
| 6590 | *****************************************************************************/ |
| 6591 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6592 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6593 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6594 | struct iwl4965_priv *priv = |
| 6595 | container_of(data, struct iwl4965_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6596 | |
| 6597 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6598 | return; |
| 6599 | |
| 6600 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6601 | iwl4965_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6602 | mutex_unlock(&priv->mutex); |
| 6603 | } |
| 6604 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6605 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6606 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6607 | struct iwl4965_priv *priv = |
| 6608 | container_of(data, struct iwl4965_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6609 | |
| 6610 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6611 | return; |
| 6612 | |
| 6613 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6614 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6615 | mutex_unlock(&priv->mutex); |
| 6616 | } |
| 6617 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6618 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6619 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6620 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6621 | |
| 6622 | wake_up_interruptible(&priv->wait_command_queue); |
| 6623 | |
| 6624 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6625 | return; |
| 6626 | |
| 6627 | mutex_lock(&priv->mutex); |
| 6628 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6629 | if (!iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6630 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 6631 | "HW and/or SW RF Kill no longer active, restarting " |
| 6632 | "device\n"); |
| 6633 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6634 | queue_work(priv->workqueue, &priv->restart); |
| 6635 | } else { |
| 6636 | |
| 6637 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 6638 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 6639 | "disabled by SW switch\n"); |
| 6640 | else |
| 6641 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 6642 | "Kill switch must be turned off for " |
| 6643 | "wireless networking to work.\n"); |
| 6644 | } |
| 6645 | mutex_unlock(&priv->mutex); |
| 6646 | } |
| 6647 | |
| 6648 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 6649 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6650 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6651 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6652 | struct iwl4965_priv *priv = |
| 6653 | container_of(data, struct iwl4965_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6654 | |
| 6655 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6656 | return; |
| 6657 | |
| 6658 | mutex_lock(&priv->mutex); |
| 6659 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 6660 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6661 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 6662 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 6663 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6664 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6665 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6666 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6667 | } |
| 6668 | mutex_unlock(&priv->mutex); |
| 6669 | } |
| 6670 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6671 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6672 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6673 | struct iwl4965_priv *priv = |
| 6674 | container_of(data, struct iwl4965_priv, request_scan); |
| 6675 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6676 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6677 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6678 | .meta.flags = CMD_SIZE_HUGE, |
| 6679 | }; |
| 6680 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6681 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6682 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6683 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6684 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6685 | u8 direct_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6686 | |
| 6687 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6688 | |
| 6689 | mutex_lock(&priv->mutex); |
| 6690 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6691 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6692 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 6693 | goto done; |
| 6694 | } |
| 6695 | |
| 6696 | /* Make sure the scan wasn't cancelled before this queued work |
| 6697 | * was given the chance to run... */ |
| 6698 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 6699 | goto done; |
| 6700 | |
| 6701 | /* This should never be called or scheduled if there is currently |
| 6702 | * a scan active in the hardware. */ |
| 6703 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 6704 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 6705 | "Ignoring second request.\n"); |
| 6706 | rc = -EIO; |
| 6707 | goto done; |
| 6708 | } |
| 6709 | |
| 6710 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6711 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 6712 | goto done; |
| 6713 | } |
| 6714 | |
| 6715 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6716 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6717 | goto done; |
| 6718 | } |
| 6719 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6720 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6721 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6722 | goto done; |
| 6723 | } |
| 6724 | |
| 6725 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 6726 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 6727 | goto done; |
| 6728 | } |
| 6729 | |
| 6730 | if (!priv->scan_bands) { |
| 6731 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 6732 | goto done; |
| 6733 | } |
| 6734 | |
| 6735 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6736 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6737 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 6738 | if (!priv->scan) { |
| 6739 | rc = -ENOMEM; |
| 6740 | goto done; |
| 6741 | } |
| 6742 | } |
| 6743 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6744 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6745 | |
| 6746 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 6747 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 6748 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6749 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6750 | u16 interval = 0; |
| 6751 | u32 extra; |
| 6752 | u32 suspend_time = 100; |
| 6753 | u32 scan_suspend_time = 100; |
| 6754 | unsigned long flags; |
| 6755 | |
| 6756 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 6757 | |
| 6758 | spin_lock_irqsave(&priv->lock, flags); |
| 6759 | interval = priv->beacon_int; |
| 6760 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6761 | |
| 6762 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6763 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6764 | if (!interval) |
| 6765 | interval = suspend_time; |
| 6766 | |
| 6767 | extra = (suspend_time / interval) << 22; |
| 6768 | scan_suspend_time = (extra | |
| 6769 | ((suspend_time % interval) * 1024)); |
| 6770 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 6771 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 6772 | scan_suspend_time, interval); |
| 6773 | } |
| 6774 | |
| 6775 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 6776 | if (priv->one_direct_scan) { |
| 6777 | IWL_DEBUG_SCAN |
| 6778 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6779 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6780 | priv->direct_ssid_len)); |
| 6781 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6782 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 6783 | memcpy(scan->direct_scan[0].ssid, |
| 6784 | priv->direct_ssid, priv->direct_ssid_len); |
| 6785 | direct_mask = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6786 | } else if (!iwl4965_is_associated(priv) && priv->essid_len) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6787 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6788 | scan->direct_scan[0].len = priv->essid_len; |
| 6789 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 6790 | direct_mask = 1; |
| 6791 | } else |
| 6792 | direct_mask = 0; |
| 6793 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6794 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 6795 | scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; |
| 6796 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 6797 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6798 | |
| 6799 | switch (priv->scan_bands) { |
| 6800 | case 2: |
| 6801 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 6802 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6803 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6804 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 6805 | |
| 6806 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6807 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6808 | break; |
| 6809 | |
| 6810 | case 1: |
| 6811 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6812 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6813 | RATE_MCS_ANT_B_MSK); |
| 6814 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6815 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6816 | break; |
| 6817 | |
| 6818 | default: |
| 6819 | IWL_WARNING("Invalid scan band count\n"); |
| 6820 | goto done; |
| 6821 | } |
| 6822 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6823 | /* We don't build a direct scan probe request; the uCode will do |
| 6824 | * that based on the direct_mask added to each channel entry */ |
| 6825 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 6826 | (struct ieee80211_mgmt *)scan->data, |
| 6827 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 6828 | |
| 6829 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6830 | /* select Rx chains */ |
| 6831 | |
| 6832 | /* Force use of chains B and C (0x6) for scan Rx. |
| 6833 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 6834 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 6835 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 6836 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 6837 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 6838 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 6839 | |
| 6840 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 6841 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 6842 | |
| 6843 | if (direct_mask) |
| 6844 | IWL_DEBUG_SCAN |
| 6845 | ("Initiating direct scan for %s.\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6846 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6847 | else |
| 6848 | IWL_DEBUG_SCAN("Initiating indirect scan.\n"); |
| 6849 | |
| 6850 | scan->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6851 | iwl4965_get_channels_for_scan( |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6852 | priv, band, 1, /* active */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6853 | direct_mask, |
| 6854 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
| 6855 | |
| 6856 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6857 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6858 | cmd.data = scan; |
| 6859 | scan->len = cpu_to_le16(cmd.len); |
| 6860 | |
| 6861 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6862 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6863 | if (rc) |
| 6864 | goto done; |
| 6865 | |
| 6866 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6867 | IWL_SCAN_CHECK_WATCHDOG); |
| 6868 | |
| 6869 | mutex_unlock(&priv->mutex); |
| 6870 | return; |
| 6871 | |
| 6872 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 6873 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6874 | queue_work(priv->workqueue, &priv->scan_completed); |
| 6875 | mutex_unlock(&priv->mutex); |
| 6876 | } |
| 6877 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6878 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6879 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6880 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6881 | |
| 6882 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6883 | return; |
| 6884 | |
| 6885 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6886 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6887 | mutex_unlock(&priv->mutex); |
| 6888 | } |
| 6889 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6890 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6891 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6892 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6893 | |
| 6894 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6895 | return; |
| 6896 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6897 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6898 | queue_work(priv->workqueue, &priv->up); |
| 6899 | } |
| 6900 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6901 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6902 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6903 | struct iwl4965_priv *priv = |
| 6904 | container_of(data, struct iwl4965_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6905 | |
| 6906 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6907 | return; |
| 6908 | |
| 6909 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6910 | iwl4965_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6911 | mutex_unlock(&priv->mutex); |
| 6912 | } |
| 6913 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6914 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 6915 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6916 | static void iwl4965_bg_post_associate(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6917 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6918 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6919 | post_associate.work); |
| 6920 | |
| 6921 | int rc = 0; |
| 6922 | struct ieee80211_conf *conf = NULL; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6923 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6924 | |
| 6925 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 6926 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 6927 | return; |
| 6928 | } |
| 6929 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6930 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 6931 | priv->assoc_id, |
| 6932 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6933 | |
| 6934 | |
| 6935 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6936 | return; |
| 6937 | |
| 6938 | mutex_lock(&priv->mutex); |
| 6939 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6940 | if (!priv->vif || !priv->is_open) { |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 6941 | mutex_unlock(&priv->mutex); |
| 6942 | return; |
| 6943 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6944 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6945 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6946 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6947 | |
| 6948 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6949 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6950 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6951 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 6952 | iwl4965_setup_rxon_timing(priv); |
| 6953 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6954 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 6955 | if (rc) |
| 6956 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 6957 | "Attempting to continue.\n"); |
| 6958 | |
| 6959 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 6960 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6961 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 6962 | if (priv->current_ht_config.is_ht) |
| 6963 | iwl4965_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6964 | #endif /* CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6965 | iwl4965_set_rxon_chain(priv); |
| 6966 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 6967 | |
| 6968 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 6969 | priv->assoc_id, priv->beacon_int); |
| 6970 | |
| 6971 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 6972 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6973 | else |
| 6974 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6975 | |
| 6976 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 6977 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 6978 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 6979 | else |
| 6980 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 6981 | |
| 6982 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 6983 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 6984 | |
| 6985 | } |
| 6986 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6987 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6988 | |
| 6989 | switch (priv->iw_mode) { |
| 6990 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6991 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6992 | break; |
| 6993 | |
| 6994 | case IEEE80211_IF_TYPE_IBSS: |
| 6995 | |
| 6996 | /* clear out the station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6997 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6998 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6999 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
| 7000 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 7001 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 7002 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7003 | |
| 7004 | break; |
| 7005 | |
| 7006 | default: |
| 7007 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 7008 | __FUNCTION__, priv->iw_mode); |
| 7009 | break; |
| 7010 | } |
| 7011 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7012 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7013 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7014 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7015 | /* Enable Rx differential gain and sensitivity calibrations */ |
| 7016 | iwl4965_chain_noise_reset(priv); |
| 7017 | priv->start_calib = 1; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7018 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7019 | |
| 7020 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7021 | priv->assoc_station_added = 1; |
| 7022 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7023 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 7024 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7025 | /* we have just associated, don't start scan too early */ |
| 7026 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7027 | mutex_unlock(&priv->mutex); |
| 7028 | } |
| 7029 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7030 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7031 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7032 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7033 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7034 | if (!iwl4965_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7035 | return; |
| 7036 | |
| 7037 | mutex_lock(&priv->mutex); |
| 7038 | |
| 7039 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7040 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7041 | |
| 7042 | mutex_unlock(&priv->mutex); |
| 7043 | } |
| 7044 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7045 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 7046 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7047 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7048 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7049 | struct iwl4965_priv *priv = |
| 7050 | container_of(work, struct iwl4965_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7051 | |
| 7052 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 7053 | |
| 7054 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7055 | return; |
| 7056 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7057 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 7058 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7059 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7060 | ieee80211_scan_completed(priv->hw); |
| 7061 | |
| 7062 | /* Since setting the TXPOWER may have been deferred while |
| 7063 | * performing the scan, fire one off */ |
| 7064 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7065 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7066 | mutex_unlock(&priv->mutex); |
| 7067 | } |
| 7068 | |
| 7069 | /***************************************************************************** |
| 7070 | * |
| 7071 | * mac80211 entry point functions |
| 7072 | * |
| 7073 | *****************************************************************************/ |
| 7074 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7075 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 7076 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7077 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7078 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7079 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7080 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7081 | |
| 7082 | IWL_DEBUG_MAC80211("enter\n"); |
| 7083 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7084 | if (pci_enable_device(priv->pci_dev)) { |
| 7085 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 7086 | return -ENODEV; |
| 7087 | } |
| 7088 | pci_restore_state(priv->pci_dev); |
| 7089 | pci_enable_msi(priv->pci_dev); |
| 7090 | |
| 7091 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 7092 | DRV_NAME, priv); |
| 7093 | if (ret) { |
| 7094 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 7095 | goto out_disable_msi; |
| 7096 | } |
| 7097 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7098 | /* we should be verifying the device is ready to be opened */ |
| 7099 | mutex_lock(&priv->mutex); |
| 7100 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7101 | memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd)); |
| 7102 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 7103 | * ucode filename and max sizes are card-specific. */ |
| 7104 | |
| 7105 | if (!priv->ucode_code.len) { |
| 7106 | ret = iwl4965_read_ucode(priv); |
| 7107 | if (ret) { |
| 7108 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 7109 | mutex_unlock(&priv->mutex); |
| 7110 | goto out_release_irq; |
| 7111 | } |
| 7112 | } |
| 7113 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7114 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7115 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7116 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7117 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7118 | if (ret) |
| 7119 | goto out_release_irq; |
| 7120 | |
| 7121 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 7122 | |
| 7123 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 7124 | return 0; |
| 7125 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7126 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 7127 | * mac80211 will not be run successfully. */ |
| 7128 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 7129 | test_bit(STATUS_READY, &priv->status), |
| 7130 | UCODE_READY_TIMEOUT); |
| 7131 | if (!ret) { |
| 7132 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 7133 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 7134 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 7135 | ret = -ETIMEDOUT; |
| 7136 | goto out_release_irq; |
| 7137 | } |
| 7138 | } |
| 7139 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7140 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7141 | IWL_DEBUG_MAC80211("leave\n"); |
| 7142 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7143 | |
| 7144 | out_release_irq: |
| 7145 | free_irq(priv->pci_dev->irq, priv); |
| 7146 | out_disable_msi: |
| 7147 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7148 | pci_disable_device(priv->pci_dev); |
| 7149 | priv->is_open = 0; |
| 7150 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7151 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7152 | } |
| 7153 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7154 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7155 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7156 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7157 | |
| 7158 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7159 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7160 | if (!priv->is_open) { |
| 7161 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 7162 | return; |
| 7163 | } |
| 7164 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7165 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7166 | |
| 7167 | if (iwl4965_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7168 | /* stop mac, cancel any scan request and clear |
| 7169 | * RXON_FILTER_ASSOC_MSK BIT |
| 7170 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7171 | mutex_lock(&priv->mutex); |
| 7172 | iwl4965_scan_cancel_timeout(priv, 100); |
| 7173 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7174 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7175 | } |
| 7176 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7177 | iwl4965_down(priv); |
| 7178 | |
| 7179 | flush_workqueue(priv->workqueue); |
| 7180 | free_irq(priv->pci_dev->irq, priv); |
| 7181 | pci_disable_msi(priv->pci_dev); |
| 7182 | pci_save_state(priv->pci_dev); |
| 7183 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7184 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7185 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7186 | } |
| 7187 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7188 | static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7189 | struct ieee80211_tx_control *ctl) |
| 7190 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7191 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7192 | |
| 7193 | IWL_DEBUG_MAC80211("enter\n"); |
| 7194 | |
| 7195 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 7196 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 7197 | return -1; |
| 7198 | } |
| 7199 | |
| 7200 | IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7201 | ctl->tx_rate->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7202 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7203 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7204 | dev_kfree_skb_any(skb); |
| 7205 | |
| 7206 | IWL_DEBUG_MAC80211("leave\n"); |
| 7207 | return 0; |
| 7208 | } |
| 7209 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7210 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7211 | struct ieee80211_if_init_conf *conf) |
| 7212 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7213 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7214 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7215 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7216 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7217 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7218 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7219 | if (priv->vif) { |
| 7220 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 7221 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7222 | } |
| 7223 | |
| 7224 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7225 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7226 | |
| 7227 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7228 | |
| 7229 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 7230 | |
| 7231 | if (conf->mac_addr) { |
| 7232 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 7233 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 7234 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7235 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7236 | if (iwl4965_is_ready(priv)) |
| 7237 | iwl4965_set_mode(priv, conf->type); |
| 7238 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7239 | mutex_unlock(&priv->mutex); |
| 7240 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7241 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7242 | return 0; |
| 7243 | } |
| 7244 | |
| 7245 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7246 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7247 | * |
| 7248 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 7249 | * be set inappropriately and the driver currently sets the hardware up to |
| 7250 | * use it whenever needed. |
| 7251 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7252 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7253 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7254 | struct iwl4965_priv *priv = hw->priv; |
| 7255 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7256 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7257 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7258 | |
| 7259 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7260 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7261 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 7262 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 7263 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7264 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7265 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7266 | ret = -EIO; |
| 7267 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7268 | } |
| 7269 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7270 | if (unlikely(!iwl4965_param_disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7271 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7272 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7273 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7274 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7275 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7276 | } |
| 7277 | |
| 7278 | spin_lock_irqsave(&priv->lock, flags); |
| 7279 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7280 | ch_info = iwl4965_get_channel_info(priv, conf->channel->band, |
| 7281 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7282 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7283 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 7284 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7285 | ret = -EINVAL; |
| 7286 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7287 | } |
| 7288 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7289 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 7290 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7291 | * from any ht related info since 2.4 does not |
| 7292 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 7293 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7294 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7295 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 7296 | #endif |
| 7297 | ) |
| 7298 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7299 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7300 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7301 | iwl4965_set_rxon_channel(priv, conf->channel->band, |
| 7302 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7303 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7304 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7305 | |
| 7306 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7307 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7308 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7309 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7310 | |
| 7311 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7312 | |
| 7313 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7314 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7315 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7316 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7317 | } |
| 7318 | #endif |
| 7319 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7320 | iwl4965_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7321 | |
| 7322 | if (!conf->radio_enabled) { |
| 7323 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7324 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7325 | } |
| 7326 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7327 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7328 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7329 | ret = -EIO; |
| 7330 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7331 | } |
| 7332 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7333 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7334 | |
| 7335 | if (memcmp(&priv->active_rxon, |
| 7336 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7337 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7338 | else |
| 7339 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 7340 | |
| 7341 | IWL_DEBUG_MAC80211("leave\n"); |
| 7342 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7343 | out: |
| 7344 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7345 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7346 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7347 | } |
| 7348 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7349 | static void iwl4965_config_ap(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7350 | { |
| 7351 | int rc = 0; |
| 7352 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 7353 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7354 | return; |
| 7355 | |
| 7356 | /* The following should be done only at AP bring up */ |
| 7357 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 7358 | |
| 7359 | /* RXON - unassoc (to set timing command) */ |
| 7360 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7361 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7362 | |
| 7363 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7364 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7365 | iwl4965_setup_rxon_timing(priv); |
| 7366 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7367 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7368 | if (rc) |
| 7369 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7370 | "Attempting to continue.\n"); |
| 7371 | |
| 7372 | iwl4965_set_rxon_chain(priv); |
| 7373 | |
| 7374 | /* FIXME: what should be the assoc_id for AP? */ |
| 7375 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7376 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7377 | priv->staging_rxon.flags |= |
| 7378 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7379 | else |
| 7380 | priv->staging_rxon.flags &= |
| 7381 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7382 | |
| 7383 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7384 | if (priv->assoc_capability & |
| 7385 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7386 | priv->staging_rxon.flags |= |
| 7387 | RXON_FLG_SHORT_SLOT_MSK; |
| 7388 | else |
| 7389 | priv->staging_rxon.flags &= |
| 7390 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7391 | |
| 7392 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7393 | priv->staging_rxon.flags &= |
| 7394 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7395 | } |
| 7396 | /* restore RXON assoc */ |
| 7397 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7398 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7399 | iwl4965_activate_qos(priv, 1); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7400 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 7401 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7402 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7403 | |
| 7404 | /* FIXME - we need to add code here to detect a totally new |
| 7405 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 7406 | * clear sta table, add BCAST sta... */ |
| 7407 | } |
| 7408 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7409 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 7410 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7411 | struct ieee80211_if_conf *conf) |
| 7412 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7413 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7414 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7415 | unsigned long flags; |
| 7416 | int rc; |
| 7417 | |
| 7418 | if (conf == NULL) |
| 7419 | return -EIO; |
| 7420 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 7421 | if (priv->vif != vif) { |
| 7422 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
| 7423 | mutex_unlock(&priv->mutex); |
| 7424 | return 0; |
| 7425 | } |
| 7426 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7427 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 7428 | (!conf->beacon || !conf->ssid_len)) { |
| 7429 | IWL_DEBUG_MAC80211 |
| 7430 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 7431 | return 0; |
| 7432 | } |
| 7433 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7434 | if (!iwl4965_is_alive(priv)) |
| 7435 | return -EAGAIN; |
| 7436 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7437 | mutex_lock(&priv->mutex); |
| 7438 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7439 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7440 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 7441 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7442 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7443 | /* |
| 7444 | * very dubious code was here; the probe filtering flag is never set: |
| 7445 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7446 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 7447 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7448 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7449 | |
| 7450 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7451 | if (!conf->bssid) { |
| 7452 | conf->bssid = priv->mac_addr; |
| 7453 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7454 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 7455 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7456 | } |
| 7457 | if (priv->ibss_beacon) |
| 7458 | dev_kfree_skb(priv->ibss_beacon); |
| 7459 | |
| 7460 | priv->ibss_beacon = conf->beacon; |
| 7461 | } |
| 7462 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7463 | if (iwl4965_is_rfkill(priv)) |
| 7464 | goto done; |
| 7465 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7466 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 7467 | !is_multicast_ether_addr(conf->bssid)) { |
| 7468 | /* If there is currently a HW scan going on in the background |
| 7469 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7470 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7471 | IWL_WARNING("Aborted scan still in progress " |
| 7472 | "after 100ms\n"); |
| 7473 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 7474 | mutex_unlock(&priv->mutex); |
| 7475 | return -EAGAIN; |
| 7476 | } |
| 7477 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 7478 | |
| 7479 | /* TODO: Audit driver for usage of these members and see |
| 7480 | * if mac80211 deprecates them (priv->bssid looks like it |
| 7481 | * shouldn't be there, but I haven't scanned the IBSS code |
| 7482 | * to verify) - jpk */ |
| 7483 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 7484 | |
| 7485 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7486 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7487 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7488 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7489 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7490 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7491 | priv, priv->active_rxon.bssid_addr, 1); |
| 7492 | } |
| 7493 | |
| 7494 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7495 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7496 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7497 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7498 | } |
| 7499 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7500 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7501 | spin_lock_irqsave(&priv->lock, flags); |
| 7502 | if (!conf->ssid_len) |
| 7503 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7504 | else |
| 7505 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 7506 | |
| 7507 | priv->essid_len = conf->ssid_len; |
| 7508 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7509 | |
| 7510 | IWL_DEBUG_MAC80211("leave\n"); |
| 7511 | mutex_unlock(&priv->mutex); |
| 7512 | |
| 7513 | return 0; |
| 7514 | } |
| 7515 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7516 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7517 | unsigned int changed_flags, |
| 7518 | unsigned int *total_flags, |
| 7519 | int mc_count, struct dev_addr_list *mc_list) |
| 7520 | { |
| 7521 | /* |
| 7522 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7523 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7524 | */ |
| 7525 | *total_flags = 0; |
| 7526 | } |
| 7527 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7528 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7529 | struct ieee80211_if_init_conf *conf) |
| 7530 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7531 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7532 | |
| 7533 | IWL_DEBUG_MAC80211("enter\n"); |
| 7534 | |
| 7535 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7536 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7537 | if (iwl4965_is_ready_rf(priv)) { |
| 7538 | iwl4965_scan_cancel_timeout(priv, 100); |
| 7539 | cancel_delayed_work(&priv->post_associate); |
| 7540 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 7541 | iwl4965_commit_rxon(priv); |
| 7542 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7543 | if (priv->vif == conf->vif) { |
| 7544 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7545 | memset(priv->bssid, 0, ETH_ALEN); |
| 7546 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7547 | priv->essid_len = 0; |
| 7548 | } |
| 7549 | mutex_unlock(&priv->mutex); |
| 7550 | |
| 7551 | IWL_DEBUG_MAC80211("leave\n"); |
| 7552 | |
| 7553 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7554 | |
| 7555 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 7556 | struct ieee80211_vif *vif, |
| 7557 | struct ieee80211_bss_conf *bss_conf, |
| 7558 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7559 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7560 | struct iwl4965_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7561 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7562 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 7563 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7564 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7565 | else |
| 7566 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7567 | } |
| 7568 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7569 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7570 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7571 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 7572 | else |
| 7573 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 7574 | } |
| 7575 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7576 | if (changes & BSS_CHANGED_ASSOC) { |
| 7577 | /* |
| 7578 | * TODO: |
| 7579 | * do stuff instead of sniffing assoc resp |
| 7580 | */ |
| 7581 | } |
| 7582 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7583 | if (iwl4965_is_associated(priv)) |
| 7584 | iwl4965_send_rxon_assoc(priv); |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7585 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7586 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7587 | static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7588 | { |
| 7589 | int rc = 0; |
| 7590 | unsigned long flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7591 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7592 | |
| 7593 | IWL_DEBUG_MAC80211("enter\n"); |
| 7594 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7595 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7596 | spin_lock_irqsave(&priv->lock, flags); |
| 7597 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7598 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7599 | rc = -EIO; |
| 7600 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 7601 | goto out_unlock; |
| 7602 | } |
| 7603 | |
| 7604 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 7605 | rc = -EIO; |
| 7606 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 7607 | goto out_unlock; |
| 7608 | } |
| 7609 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7610 | /* we don't schedule scan within next_scan_jiffies period */ |
| 7611 | if (priv->next_scan_jiffies && |
| 7612 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 7613 | rc = -EAGAIN; |
| 7614 | goto out_unlock; |
| 7615 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7616 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7617 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 7618 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7619 | rc = -EAGAIN; |
| 7620 | goto out_unlock; |
| 7621 | } |
| 7622 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7623 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7624 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7625 | |
| 7626 | priv->one_direct_scan = 1; |
| 7627 | priv->direct_ssid_len = (u8) |
| 7628 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 7629 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7630 | } else |
| 7631 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7632 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7633 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7634 | |
| 7635 | IWL_DEBUG_MAC80211("leave\n"); |
| 7636 | |
| 7637 | out_unlock: |
| 7638 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7639 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7640 | |
| 7641 | return rc; |
| 7642 | } |
| 7643 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7644 | static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7645 | const u8 *local_addr, const u8 *addr, |
| 7646 | struct ieee80211_key_conf *key) |
| 7647 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7648 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7649 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7650 | int rc = 0; |
| 7651 | u8 sta_id; |
| 7652 | |
| 7653 | IWL_DEBUG_MAC80211("enter\n"); |
| 7654 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7655 | if (!iwl4965_param_hwcrypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7656 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 7657 | return -EOPNOTSUPP; |
| 7658 | } |
| 7659 | |
| 7660 | if (is_zero_ether_addr(addr)) |
| 7661 | /* only support pairwise keys */ |
| 7662 | return -EOPNOTSUPP; |
| 7663 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7664 | sta_id = iwl4965_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7665 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7666 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 7667 | print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7668 | return -EINVAL; |
| 7669 | } |
| 7670 | |
| 7671 | mutex_lock(&priv->mutex); |
| 7672 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7673 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7674 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7675 | switch (cmd) { |
| 7676 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7677 | rc = iwl4965_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7678 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7679 | iwl4965_set_rxon_hwcrypto(priv, 1); |
| 7680 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7681 | key->hw_key_idx = sta_id; |
| 7682 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 7683 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 7684 | } |
| 7685 | break; |
| 7686 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7687 | rc = iwl4965_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7688 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7689 | iwl4965_set_rxon_hwcrypto(priv, 0); |
| 7690 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7691 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 7692 | } |
| 7693 | break; |
| 7694 | default: |
| 7695 | rc = -EINVAL; |
| 7696 | } |
| 7697 | |
| 7698 | IWL_DEBUG_MAC80211("leave\n"); |
| 7699 | mutex_unlock(&priv->mutex); |
| 7700 | |
| 7701 | return rc; |
| 7702 | } |
| 7703 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7704 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7705 | const struct ieee80211_tx_queue_params *params) |
| 7706 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7707 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7708 | unsigned long flags; |
| 7709 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7710 | |
| 7711 | IWL_DEBUG_MAC80211("enter\n"); |
| 7712 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7713 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7714 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7715 | return -EIO; |
| 7716 | } |
| 7717 | |
| 7718 | if (queue >= AC_NUM) { |
| 7719 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 7720 | return 0; |
| 7721 | } |
| 7722 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7723 | if (!priv->qos_data.qos_enable) { |
| 7724 | priv->qos_data.qos_active = 0; |
| 7725 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 7726 | return 0; |
| 7727 | } |
| 7728 | q = AC_NUM - 1 - queue; |
| 7729 | |
| 7730 | spin_lock_irqsave(&priv->lock, flags); |
| 7731 | |
| 7732 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 7733 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 7734 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 7735 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 7736 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7737 | |
| 7738 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 7739 | priv->qos_data.qos_active = 1; |
| 7740 | |
| 7741 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7742 | |
| 7743 | mutex_lock(&priv->mutex); |
| 7744 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7745 | iwl4965_activate_qos(priv, 1); |
| 7746 | else if (priv->assoc_id && iwl4965_is_associated(priv)) |
| 7747 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7748 | |
| 7749 | mutex_unlock(&priv->mutex); |
| 7750 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7751 | IWL_DEBUG_MAC80211("leave\n"); |
| 7752 | return 0; |
| 7753 | } |
| 7754 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7755 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7756 | struct ieee80211_tx_queue_stats *stats) |
| 7757 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7758 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7759 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7760 | struct iwl4965_tx_queue *txq; |
| 7761 | struct iwl4965_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7762 | unsigned long flags; |
| 7763 | |
| 7764 | IWL_DEBUG_MAC80211("enter\n"); |
| 7765 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7766 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7767 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7768 | return -EIO; |
| 7769 | } |
| 7770 | |
| 7771 | spin_lock_irqsave(&priv->lock, flags); |
| 7772 | |
| 7773 | for (i = 0; i < AC_NUM; i++) { |
| 7774 | txq = &priv->txq[i]; |
| 7775 | q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7776 | avail = iwl4965_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7777 | |
| 7778 | stats->data[i].len = q->n_window - avail; |
| 7779 | stats->data[i].limit = q->n_window - q->high_mark; |
| 7780 | stats->data[i].count = q->n_window; |
| 7781 | |
| 7782 | } |
| 7783 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7784 | |
| 7785 | IWL_DEBUG_MAC80211("leave\n"); |
| 7786 | |
| 7787 | return 0; |
| 7788 | } |
| 7789 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7790 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7791 | struct ieee80211_low_level_stats *stats) |
| 7792 | { |
| 7793 | IWL_DEBUG_MAC80211("enter\n"); |
| 7794 | IWL_DEBUG_MAC80211("leave\n"); |
| 7795 | |
| 7796 | return 0; |
| 7797 | } |
| 7798 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7799 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7800 | { |
| 7801 | IWL_DEBUG_MAC80211("enter\n"); |
| 7802 | IWL_DEBUG_MAC80211("leave\n"); |
| 7803 | |
| 7804 | return 0; |
| 7805 | } |
| 7806 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7807 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7808 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7809 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7810 | unsigned long flags; |
| 7811 | |
| 7812 | mutex_lock(&priv->mutex); |
| 7813 | IWL_DEBUG_MAC80211("enter\n"); |
| 7814 | |
| 7815 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7816 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7817 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7818 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7819 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7820 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7821 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7822 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7823 | |
| 7824 | cancel_delayed_work(&priv->post_associate); |
| 7825 | |
| 7826 | spin_lock_irqsave(&priv->lock, flags); |
| 7827 | priv->assoc_id = 0; |
| 7828 | priv->assoc_capability = 0; |
| 7829 | priv->call_post_assoc_from_beacon = 0; |
| 7830 | priv->assoc_station_added = 0; |
| 7831 | |
| 7832 | /* new association get rid of ibss beacon skb */ |
| 7833 | if (priv->ibss_beacon) |
| 7834 | dev_kfree_skb(priv->ibss_beacon); |
| 7835 | |
| 7836 | priv->ibss_beacon = NULL; |
| 7837 | |
| 7838 | priv->beacon_int = priv->hw->conf.beacon_int; |
| 7839 | priv->timestamp1 = 0; |
| 7840 | priv->timestamp0 = 0; |
| 7841 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 7842 | priv->beacon_int = 0; |
| 7843 | |
| 7844 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7845 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7846 | if (!iwl4965_is_ready_rf(priv)) { |
| 7847 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 7848 | mutex_unlock(&priv->mutex); |
| 7849 | return; |
| 7850 | } |
| 7851 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7852 | /* we are restarting association process |
| 7853 | * clear RXON_FILTER_ASSOC_MSK bit |
| 7854 | */ |
| 7855 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7856 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7857 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7858 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7859 | } |
| 7860 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7861 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 7862 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7863 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7864 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 7865 | mutex_unlock(&priv->mutex); |
| 7866 | return; |
| 7867 | } |
| 7868 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7869 | priv->only_active_channel = 0; |
| 7870 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7871 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7872 | |
| 7873 | mutex_unlock(&priv->mutex); |
| 7874 | |
| 7875 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7876 | } |
| 7877 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7878 | static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7879 | struct ieee80211_tx_control *control) |
| 7880 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7881 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7882 | unsigned long flags; |
| 7883 | |
| 7884 | mutex_lock(&priv->mutex); |
| 7885 | IWL_DEBUG_MAC80211("enter\n"); |
| 7886 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7887 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7888 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7889 | mutex_unlock(&priv->mutex); |
| 7890 | return -EIO; |
| 7891 | } |
| 7892 | |
| 7893 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 7894 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 7895 | mutex_unlock(&priv->mutex); |
| 7896 | return -EIO; |
| 7897 | } |
| 7898 | |
| 7899 | spin_lock_irqsave(&priv->lock, flags); |
| 7900 | |
| 7901 | if (priv->ibss_beacon) |
| 7902 | dev_kfree_skb(priv->ibss_beacon); |
| 7903 | |
| 7904 | priv->ibss_beacon = skb; |
| 7905 | |
| 7906 | priv->assoc_id = 0; |
| 7907 | |
| 7908 | IWL_DEBUG_MAC80211("leave\n"); |
| 7909 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7910 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7911 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7912 | |
| 7913 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 7914 | |
| 7915 | mutex_unlock(&priv->mutex); |
| 7916 | |
| 7917 | return 0; |
| 7918 | } |
| 7919 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7920 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7921 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7922 | static void iwl4965_ht_info_fill(struct ieee80211_conf *conf, |
| 7923 | struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7924 | { |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7925 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 7926 | struct ieee80211_ht_info *ht_conf = &conf->ht_conf; |
| 7927 | struct ieee80211_ht_bss_info *ht_bss_conf = &conf->ht_bss_conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7928 | |
| 7929 | IWL_DEBUG_MAC80211("enter: \n"); |
| 7930 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7931 | if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) { |
| 7932 | iwl_conf->is_ht = 0; |
| 7933 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7934 | } |
| 7935 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7936 | iwl_conf->is_ht = 1; |
| 7937 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7938 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7939 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
| 7940 | iwl_conf->sgf |= 0x1; |
| 7941 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
| 7942 | iwl_conf->sgf |= 0x2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7943 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7944 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 7945 | iwl_conf->max_amsdu_size = |
| 7946 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
Guy Cohen | 134eb5d | 2008-03-04 18:09:25 -0800 | [diff] [blame] | 7947 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7948 | iwl_conf->supported_chan_width = |
| 7949 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
Guy Cohen | 134eb5d | 2008-03-04 18:09:25 -0800 | [diff] [blame] | 7950 | iwl_conf->extension_chan_offset = |
| 7951 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 7952 | /* If no above or below channel supplied disable FAT channel */ |
| 7953 | if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE && |
| 7954 | iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW) |
| 7955 | iwl_conf->supported_chan_width = 0; |
| 7956 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7957 | iwl_conf->tx_mimo_ps_mode = |
| 7958 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 7959 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7960 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7961 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7962 | iwl_conf->tx_chan_width = |
| 7963 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 7964 | iwl_conf->ht_protection = |
| 7965 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 7966 | iwl_conf->non_GF_STA_present = |
| 7967 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7968 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7969 | IWL_DEBUG_MAC80211("control channel %d\n", |
| 7970 | iwl_conf->control_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7971 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7972 | } |
| 7973 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7974 | static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw, |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7975 | struct ieee80211_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7976 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7977 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7978 | |
| 7979 | IWL_DEBUG_MAC80211("enter: \n"); |
| 7980 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7981 | iwl4965_ht_info_fill(conf, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7982 | iwl4965_set_rxon_chain(priv); |
| 7983 | |
| 7984 | if (priv && priv->assoc_id && |
| 7985 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
| 7986 | unsigned long flags; |
| 7987 | |
| 7988 | spin_lock_irqsave(&priv->lock, flags); |
| 7989 | if (priv->beacon_int) |
| 7990 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 7991 | else |
| 7992 | priv->call_post_assoc_from_beacon = 1; |
| 7993 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7994 | } |
| 7995 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7996 | IWL_DEBUG_MAC80211("leave:\n"); |
| 7997 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7998 | } |
| 7999 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8000 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8001 | |
| 8002 | /***************************************************************************** |
| 8003 | * |
| 8004 | * sysfs attributes |
| 8005 | * |
| 8006 | *****************************************************************************/ |
| 8007 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8008 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8009 | |
| 8010 | /* |
| 8011 | * The following adds a new attribute to the sysfs representation |
| 8012 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 8013 | * used for controlling the debug level. |
| 8014 | * |
| 8015 | * See the level definitions in iwl for details. |
| 8016 | */ |
| 8017 | |
| 8018 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 8019 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8020 | return sprintf(buf, "0x%08X\n", iwl4965_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8021 | } |
| 8022 | static ssize_t store_debug_level(struct device_driver *d, |
| 8023 | const char *buf, size_t count) |
| 8024 | { |
| 8025 | char *p = (char *)buf; |
| 8026 | u32 val; |
| 8027 | |
| 8028 | val = simple_strtoul(p, &p, 0); |
| 8029 | if (p == buf) |
| 8030 | printk(KERN_INFO DRV_NAME |
| 8031 | ": %s is not in hex or decimal form.\n", buf); |
| 8032 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8033 | iwl4965_debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8034 | |
| 8035 | return strnlen(buf, count); |
| 8036 | } |
| 8037 | |
| 8038 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 8039 | show_debug_level, store_debug_level); |
| 8040 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8041 | #endif /* CONFIG_IWL4965_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8042 | |
| 8043 | static ssize_t show_rf_kill(struct device *d, |
| 8044 | struct device_attribute *attr, char *buf) |
| 8045 | { |
| 8046 | /* |
| 8047 | * 0 - RF kill not enabled |
| 8048 | * 1 - SW based RF kill active (sysfs) |
| 8049 | * 2 - HW based RF kill active |
| 8050 | * 3 - Both HW and SW based RF kill active |
| 8051 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8052 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8053 | int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | |
| 8054 | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); |
| 8055 | |
| 8056 | return sprintf(buf, "%i\n", val); |
| 8057 | } |
| 8058 | |
| 8059 | static ssize_t store_rf_kill(struct device *d, |
| 8060 | struct device_attribute *attr, |
| 8061 | const char *buf, size_t count) |
| 8062 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8063 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8064 | |
| 8065 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8066 | iwl4965_radio_kill_sw(priv, buf[0] == '1'); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8067 | mutex_unlock(&priv->mutex); |
| 8068 | |
| 8069 | return count; |
| 8070 | } |
| 8071 | |
| 8072 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); |
| 8073 | |
| 8074 | static ssize_t show_temperature(struct device *d, |
| 8075 | struct device_attribute *attr, char *buf) |
| 8076 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8077 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8078 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8079 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8080 | return -EAGAIN; |
| 8081 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8082 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8083 | } |
| 8084 | |
| 8085 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 8086 | |
| 8087 | static ssize_t show_rs_window(struct device *d, |
| 8088 | struct device_attribute *attr, |
| 8089 | char *buf) |
| 8090 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8091 | struct iwl4965_priv *priv = d->driver_data; |
| 8092 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8093 | } |
| 8094 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 8095 | |
| 8096 | static ssize_t show_tx_power(struct device *d, |
| 8097 | struct device_attribute *attr, char *buf) |
| 8098 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8099 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8100 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 8101 | } |
| 8102 | |
| 8103 | static ssize_t store_tx_power(struct device *d, |
| 8104 | struct device_attribute *attr, |
| 8105 | const char *buf, size_t count) |
| 8106 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8107 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8108 | char *p = (char *)buf; |
| 8109 | u32 val; |
| 8110 | |
| 8111 | val = simple_strtoul(p, &p, 10); |
| 8112 | if (p == buf) |
| 8113 | printk(KERN_INFO DRV_NAME |
| 8114 | ": %s is not in decimal form.\n", buf); |
| 8115 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8116 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8117 | |
| 8118 | return count; |
| 8119 | } |
| 8120 | |
| 8121 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 8122 | |
| 8123 | static ssize_t show_flags(struct device *d, |
| 8124 | struct device_attribute *attr, char *buf) |
| 8125 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8126 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8127 | |
| 8128 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 8129 | } |
| 8130 | |
| 8131 | static ssize_t store_flags(struct device *d, |
| 8132 | struct device_attribute *attr, |
| 8133 | const char *buf, size_t count) |
| 8134 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8135 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8136 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 8137 | |
| 8138 | mutex_lock(&priv->mutex); |
| 8139 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 8140 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8141 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8142 | IWL_WARNING("Could not cancel scan.\n"); |
| 8143 | else { |
| 8144 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 8145 | flags); |
| 8146 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8147 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8148 | } |
| 8149 | } |
| 8150 | mutex_unlock(&priv->mutex); |
| 8151 | |
| 8152 | return count; |
| 8153 | } |
| 8154 | |
| 8155 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 8156 | |
| 8157 | static ssize_t show_filter_flags(struct device *d, |
| 8158 | struct device_attribute *attr, char *buf) |
| 8159 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8160 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8161 | |
| 8162 | return sprintf(buf, "0x%04X\n", |
| 8163 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 8164 | } |
| 8165 | |
| 8166 | static ssize_t store_filter_flags(struct device *d, |
| 8167 | struct device_attribute *attr, |
| 8168 | const char *buf, size_t count) |
| 8169 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8170 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8171 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 8172 | |
| 8173 | mutex_lock(&priv->mutex); |
| 8174 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 8175 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8176 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8177 | IWL_WARNING("Could not cancel scan.\n"); |
| 8178 | else { |
| 8179 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 8180 | "0x%04X\n", filter_flags); |
| 8181 | priv->staging_rxon.filter_flags = |
| 8182 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8183 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8184 | } |
| 8185 | } |
| 8186 | mutex_unlock(&priv->mutex); |
| 8187 | |
| 8188 | return count; |
| 8189 | } |
| 8190 | |
| 8191 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 8192 | store_filter_flags); |
| 8193 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8194 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8195 | |
| 8196 | static ssize_t show_measurement(struct device *d, |
| 8197 | struct device_attribute *attr, char *buf) |
| 8198 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8199 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8200 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8201 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 8202 | u8 *data = (u8 *) & measure_report; |
| 8203 | unsigned long flags; |
| 8204 | |
| 8205 | spin_lock_irqsave(&priv->lock, flags); |
| 8206 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 8207 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8208 | return 0; |
| 8209 | } |
| 8210 | memcpy(&measure_report, &priv->measure_report, size); |
| 8211 | priv->measurement_status = 0; |
| 8212 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8213 | |
| 8214 | while (size && (PAGE_SIZE - len)) { |
| 8215 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8216 | PAGE_SIZE - len, 1); |
| 8217 | len = strlen(buf); |
| 8218 | if (PAGE_SIZE - len) |
| 8219 | buf[len++] = '\n'; |
| 8220 | |
| 8221 | ofs += 16; |
| 8222 | size -= min(size, 16U); |
| 8223 | } |
| 8224 | |
| 8225 | return len; |
| 8226 | } |
| 8227 | |
| 8228 | static ssize_t store_measurement(struct device *d, |
| 8229 | struct device_attribute *attr, |
| 8230 | const char *buf, size_t count) |
| 8231 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8232 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8233 | struct ieee80211_measurement_params params = { |
| 8234 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 8235 | .start_time = cpu_to_le64(priv->last_tsf), |
| 8236 | .duration = cpu_to_le16(1), |
| 8237 | }; |
| 8238 | u8 type = IWL_MEASURE_BASIC; |
| 8239 | u8 buffer[32]; |
| 8240 | u8 channel; |
| 8241 | |
| 8242 | if (count) { |
| 8243 | char *p = buffer; |
| 8244 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 8245 | channel = simple_strtoul(p, NULL, 0); |
| 8246 | if (channel) |
| 8247 | params.channel = channel; |
| 8248 | |
| 8249 | p = buffer; |
| 8250 | while (*p && *p != ' ') |
| 8251 | p++; |
| 8252 | if (*p) |
| 8253 | type = simple_strtoul(p + 1, NULL, 0); |
| 8254 | } |
| 8255 | |
| 8256 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 8257 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8258 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8259 | |
| 8260 | return count; |
| 8261 | } |
| 8262 | |
| 8263 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 8264 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8265 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8266 | |
| 8267 | static ssize_t store_retry_rate(struct device *d, |
| 8268 | struct device_attribute *attr, |
| 8269 | const char *buf, size_t count) |
| 8270 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8271 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8272 | |
| 8273 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 8274 | if (priv->retry_rate <= 0) |
| 8275 | priv->retry_rate = 1; |
| 8276 | |
| 8277 | return count; |
| 8278 | } |
| 8279 | |
| 8280 | static ssize_t show_retry_rate(struct device *d, |
| 8281 | struct device_attribute *attr, char *buf) |
| 8282 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8283 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8284 | return sprintf(buf, "%d", priv->retry_rate); |
| 8285 | } |
| 8286 | |
| 8287 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 8288 | store_retry_rate); |
| 8289 | |
| 8290 | static ssize_t store_power_level(struct device *d, |
| 8291 | struct device_attribute *attr, |
| 8292 | const char *buf, size_t count) |
| 8293 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8294 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8295 | int rc; |
| 8296 | int mode; |
| 8297 | |
| 8298 | mode = simple_strtoul(buf, NULL, 0); |
| 8299 | mutex_lock(&priv->mutex); |
| 8300 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8301 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8302 | rc = -EAGAIN; |
| 8303 | goto out; |
| 8304 | } |
| 8305 | |
| 8306 | if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC)) |
| 8307 | mode = IWL_POWER_AC; |
| 8308 | else |
| 8309 | mode |= IWL_POWER_ENABLED; |
| 8310 | |
| 8311 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8312 | rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8313 | if (rc) { |
| 8314 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 8315 | goto out; |
| 8316 | } |
| 8317 | priv->power_mode = mode; |
| 8318 | } |
| 8319 | |
| 8320 | rc = count; |
| 8321 | |
| 8322 | out: |
| 8323 | mutex_unlock(&priv->mutex); |
| 8324 | return rc; |
| 8325 | } |
| 8326 | |
| 8327 | #define MAX_WX_STRING 80 |
| 8328 | |
| 8329 | /* Values are in microsecond */ |
| 8330 | static const s32 timeout_duration[] = { |
| 8331 | 350000, |
| 8332 | 250000, |
| 8333 | 75000, |
| 8334 | 37000, |
| 8335 | 25000, |
| 8336 | }; |
| 8337 | static const s32 period_duration[] = { |
| 8338 | 400000, |
| 8339 | 700000, |
| 8340 | 1000000, |
| 8341 | 1000000, |
| 8342 | 1000000 |
| 8343 | }; |
| 8344 | |
| 8345 | static ssize_t show_power_level(struct device *d, |
| 8346 | struct device_attribute *attr, char *buf) |
| 8347 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8348 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8349 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 8350 | char *p = buf; |
| 8351 | |
| 8352 | p += sprintf(p, "%d ", level); |
| 8353 | switch (level) { |
| 8354 | case IWL_POWER_MODE_CAM: |
| 8355 | case IWL_POWER_AC: |
| 8356 | p += sprintf(p, "(AC)"); |
| 8357 | break; |
| 8358 | case IWL_POWER_BATTERY: |
| 8359 | p += sprintf(p, "(BATTERY)"); |
| 8360 | break; |
| 8361 | default: |
| 8362 | p += sprintf(p, |
| 8363 | "(Timeout %dms, Period %dms)", |
| 8364 | timeout_duration[level - 1] / 1000, |
| 8365 | period_duration[level - 1] / 1000); |
| 8366 | } |
| 8367 | |
| 8368 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 8369 | p += sprintf(p, " OFF\n"); |
| 8370 | else |
| 8371 | p += sprintf(p, " \n"); |
| 8372 | |
| 8373 | return (p - buf + 1); |
| 8374 | |
| 8375 | } |
| 8376 | |
| 8377 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 8378 | store_power_level); |
| 8379 | |
| 8380 | static ssize_t show_channels(struct device *d, |
| 8381 | struct device_attribute *attr, char *buf) |
| 8382 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8383 | /* all this shit doesn't belong into sysfs anyway */ |
| 8384 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8385 | } |
| 8386 | |
| 8387 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 8388 | |
| 8389 | static ssize_t show_statistics(struct device *d, |
| 8390 | struct device_attribute *attr, char *buf) |
| 8391 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8392 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8393 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8394 | u32 len = 0, ofs = 0; |
| 8395 | u8 *data = (u8 *) & priv->statistics; |
| 8396 | int rc = 0; |
| 8397 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8398 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8399 | return -EAGAIN; |
| 8400 | |
| 8401 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8402 | rc = iwl4965_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8403 | mutex_unlock(&priv->mutex); |
| 8404 | |
| 8405 | if (rc) { |
| 8406 | len = sprintf(buf, |
| 8407 | "Error sending statistics request: 0x%08X\n", rc); |
| 8408 | return len; |
| 8409 | } |
| 8410 | |
| 8411 | while (size && (PAGE_SIZE - len)) { |
| 8412 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8413 | PAGE_SIZE - len, 1); |
| 8414 | len = strlen(buf); |
| 8415 | if (PAGE_SIZE - len) |
| 8416 | buf[len++] = '\n'; |
| 8417 | |
| 8418 | ofs += 16; |
| 8419 | size -= min(size, 16U); |
| 8420 | } |
| 8421 | |
| 8422 | return len; |
| 8423 | } |
| 8424 | |
| 8425 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 8426 | |
| 8427 | static ssize_t show_antenna(struct device *d, |
| 8428 | struct device_attribute *attr, char *buf) |
| 8429 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8430 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8431 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8432 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8433 | return -EAGAIN; |
| 8434 | |
| 8435 | return sprintf(buf, "%d\n", priv->antenna); |
| 8436 | } |
| 8437 | |
| 8438 | static ssize_t store_antenna(struct device *d, |
| 8439 | struct device_attribute *attr, |
| 8440 | const char *buf, size_t count) |
| 8441 | { |
| 8442 | int ant; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8443 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8444 | |
| 8445 | if (count == 0) |
| 8446 | return 0; |
| 8447 | |
| 8448 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 8449 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 8450 | return count; |
| 8451 | } |
| 8452 | |
| 8453 | if ((ant >= 0) && (ant <= 2)) { |
| 8454 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8455 | priv->antenna = (enum iwl4965_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8456 | } else |
| 8457 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 8458 | |
| 8459 | |
| 8460 | return count; |
| 8461 | } |
| 8462 | |
| 8463 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 8464 | |
| 8465 | static ssize_t show_status(struct device *d, |
| 8466 | struct device_attribute *attr, char *buf) |
| 8467 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8468 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
| 8469 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8470 | return -EAGAIN; |
| 8471 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 8472 | } |
| 8473 | |
| 8474 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 8475 | |
| 8476 | static ssize_t dump_error_log(struct device *d, |
| 8477 | struct device_attribute *attr, |
| 8478 | const char *buf, size_t count) |
| 8479 | { |
| 8480 | char *p = (char *)buf; |
| 8481 | |
| 8482 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8483 | iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8484 | |
| 8485 | return strnlen(buf, count); |
| 8486 | } |
| 8487 | |
| 8488 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 8489 | |
| 8490 | static ssize_t dump_event_log(struct device *d, |
| 8491 | struct device_attribute *attr, |
| 8492 | const char *buf, size_t count) |
| 8493 | { |
| 8494 | char *p = (char *)buf; |
| 8495 | |
| 8496 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8497 | iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8498 | |
| 8499 | return strnlen(buf, count); |
| 8500 | } |
| 8501 | |
| 8502 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 8503 | |
| 8504 | /***************************************************************************** |
| 8505 | * |
| 8506 | * driver setup and teardown |
| 8507 | * |
| 8508 | *****************************************************************************/ |
| 8509 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8510 | static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8511 | { |
| 8512 | priv->workqueue = create_workqueue(DRV_NAME); |
| 8513 | |
| 8514 | init_waitqueue_head(&priv->wait_command_queue); |
| 8515 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8516 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 8517 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 8518 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 8519 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 8520 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 8521 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 8522 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 8523 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
| 8524 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 8525 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 8526 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 8527 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8528 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8529 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8530 | |
| 8531 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8532 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8533 | } |
| 8534 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8535 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8536 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8537 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8538 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 8539 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8540 | cancel_delayed_work(&priv->scan_check); |
| 8541 | cancel_delayed_work(&priv->alive_start); |
| 8542 | cancel_delayed_work(&priv->post_associate); |
| 8543 | cancel_work_sync(&priv->beacon_update); |
| 8544 | } |
| 8545 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8546 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8547 | &dev_attr_antenna.attr, |
| 8548 | &dev_attr_channels.attr, |
| 8549 | &dev_attr_dump_errors.attr, |
| 8550 | &dev_attr_dump_events.attr, |
| 8551 | &dev_attr_flags.attr, |
| 8552 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8553 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8554 | &dev_attr_measurement.attr, |
| 8555 | #endif |
| 8556 | &dev_attr_power_level.attr, |
| 8557 | &dev_attr_retry_rate.attr, |
| 8558 | &dev_attr_rf_kill.attr, |
| 8559 | &dev_attr_rs_window.attr, |
| 8560 | &dev_attr_statistics.attr, |
| 8561 | &dev_attr_status.attr, |
| 8562 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8563 | &dev_attr_tx_power.attr, |
| 8564 | |
| 8565 | NULL |
| 8566 | }; |
| 8567 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8568 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8569 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8570 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8571 | }; |
| 8572 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8573 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 8574 | .tx = iwl4965_mac_tx, |
| 8575 | .start = iwl4965_mac_start, |
| 8576 | .stop = iwl4965_mac_stop, |
| 8577 | .add_interface = iwl4965_mac_add_interface, |
| 8578 | .remove_interface = iwl4965_mac_remove_interface, |
| 8579 | .config = iwl4965_mac_config, |
| 8580 | .config_interface = iwl4965_mac_config_interface, |
| 8581 | .configure_filter = iwl4965_configure_filter, |
| 8582 | .set_key = iwl4965_mac_set_key, |
| 8583 | .get_stats = iwl4965_mac_get_stats, |
| 8584 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 8585 | .conf_tx = iwl4965_mac_conf_tx, |
| 8586 | .get_tsf = iwl4965_mac_get_tsf, |
| 8587 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 8588 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 8589 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8590 | #ifdef CONFIG_IWL4965_HT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8591 | .conf_ht = iwl4965_mac_conf_ht, |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 8592 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8593 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8594 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8595 | }; |
| 8596 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8597 | static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8598 | { |
| 8599 | int err = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8600 | struct iwl4965_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8601 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 8602 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8603 | int i; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8604 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8605 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8606 | /* Disabling hardware scan means that mac80211 will perform scans |
| 8607 | * "the hard way", rather than using device's scan. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8608 | if (iwl4965_param_disable_hw_scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8609 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8610 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8611 | } |
| 8612 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8613 | if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) || |
| 8614 | (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8615 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
| 8616 | IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); |
| 8617 | err = -EINVAL; |
| 8618 | goto out; |
| 8619 | } |
| 8620 | |
| 8621 | /* mac80211 allocates memory for this device instance, including |
| 8622 | * space for this driver's private structure */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8623 | hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8624 | if (hw == NULL) { |
| 8625 | IWL_ERROR("Can not allocate network device\n"); |
| 8626 | err = -ENOMEM; |
| 8627 | goto out; |
| 8628 | } |
| 8629 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 8630 | |
Johannes Berg | f51359a | 2007-10-28 14:53:36 +0100 | [diff] [blame] | 8631 | hw->rate_control_algorithm = "iwl-4965-rs"; |
| 8632 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8633 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 8634 | priv = hw->priv; |
| 8635 | priv->hw = hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 8636 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8637 | |
| 8638 | priv->pci_dev = pdev; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8639 | priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8640 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8641 | iwl4965_debug_level = iwl4965_param_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8642 | atomic_set(&priv->restrict_refcnt, 0); |
| 8643 | #endif |
| 8644 | priv->retry_rate = 1; |
| 8645 | |
| 8646 | priv->ibss_beacon = NULL; |
| 8647 | |
| 8648 | /* Tell mac80211 and its clients (e.g. Wireless Extensions) |
| 8649 | * the range of signal quality values that we'll provide. |
| 8650 | * Negative values for level/noise indicate that we'll provide dBm. |
| 8651 | * For WE, at least, non-0 values here *enable* display of values |
| 8652 | * in app (iwconfig). */ |
| 8653 | hw->max_rssi = -20; /* signal level, negative indicates dBm */ |
| 8654 | hw->max_noise = -20; /* noise level, negative indicates dBm */ |
| 8655 | hw->max_signal = 100; /* link quality indication (%) */ |
| 8656 | |
| 8657 | /* Tell mac80211 our Tx characteristics */ |
| 8658 | hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; |
| 8659 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8660 | /* Default value; 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8661 | hw->queues = 4; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8662 | #ifdef CONFIG_IWL4965_HT |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8663 | /* Enhanced value; more queues, to support 11n aggregation */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8664 | hw->queues = 16; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8665 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8666 | |
| 8667 | spin_lock_init(&priv->lock); |
| 8668 | spin_lock_init(&priv->power_data.lock); |
| 8669 | spin_lock_init(&priv->sta_lock); |
| 8670 | spin_lock_init(&priv->hcmd_lock); |
| 8671 | spin_lock_init(&priv->lq_mngr.lock); |
| 8672 | |
| 8673 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) |
| 8674 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
| 8675 | |
| 8676 | INIT_LIST_HEAD(&priv->free_frames); |
| 8677 | |
| 8678 | mutex_init(&priv->mutex); |
| 8679 | if (pci_enable_device(pdev)) { |
| 8680 | err = -ENODEV; |
| 8681 | goto out_ieee80211_free_hw; |
| 8682 | } |
| 8683 | |
| 8684 | pci_set_master(pdev); |
| 8685 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8686 | /* Clear the driver's (not device's) station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8687 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8688 | |
| 8689 | priv->data_retry_limit = -1; |
| 8690 | priv->ieee_channels = NULL; |
| 8691 | priv->ieee_rates = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8692 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8693 | |
| 8694 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 8695 | if (!err) |
| 8696 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 8697 | if (err) { |
| 8698 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 8699 | goto out_pci_disable_device; |
| 8700 | } |
| 8701 | |
| 8702 | pci_set_drvdata(pdev, priv); |
| 8703 | err = pci_request_regions(pdev, DRV_NAME); |
| 8704 | if (err) |
| 8705 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8706 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8707 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 8708 | * PCI Tx retries from interfering with C3 CPU state */ |
| 8709 | pci_write_config_byte(pdev, 0x41, 0x00); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8710 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8711 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 8712 | if (!priv->hw_base) { |
| 8713 | err = -ENODEV; |
| 8714 | goto out_pci_release_regions; |
| 8715 | } |
| 8716 | |
| 8717 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 8718 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 8719 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 8720 | |
| 8721 | /* Initialize module parameter values here */ |
| 8722 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8723 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8724 | if (iwl4965_param_disable) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8725 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 8726 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 8727 | } |
| 8728 | |
| 8729 | priv->iw_mode = IEEE80211_IF_TYPE_STA; |
| 8730 | |
| 8731 | priv->ps_mode = 0; |
| 8732 | priv->use_ant_b_for_management_frame = 1; /* start with ant B */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8733 | priv->valid_antenna = 0x7; /* assume all 3 connected */ |
| 8734 | priv->ps_mode = IWL_MIMO_PS_NONE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8735 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8736 | /* Choose which receivers/antennas to use */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8737 | iwl4965_set_rxon_chain(priv); |
| 8738 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 8739 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8740 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 8741 | ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8742 | |
| 8743 | /* Device-specific setup */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8744 | if (iwl4965_hw_set_hw_setting(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8745 | IWL_ERROR("failed to set hw settings\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8746 | goto out_iounmap; |
| 8747 | } |
| 8748 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8749 | if (iwl4965_param_qos_enable) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8750 | priv->qos_data.qos_enable = 1; |
| 8751 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8752 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8753 | |
| 8754 | priv->qos_data.qos_active = 0; |
| 8755 | priv->qos_data.qos_cap.val = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8756 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8757 | iwl4965_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8758 | iwl4965_setup_deferred_work(priv); |
| 8759 | iwl4965_setup_rx_handlers(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8760 | |
| 8761 | priv->rates_mask = IWL_RATES_MASK; |
| 8762 | /* If power management is turned on, default to AC mode */ |
| 8763 | priv->power_mode = IWL_POWER_AC; |
| 8764 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 8765 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8766 | iwl4965_disable_interrupts(priv); |
Jes Sorensen | 49df2b3 | 2007-10-26 16:10:39 +0200 | [diff] [blame] | 8767 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8768 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8769 | if (err) { |
| 8770 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8771 | goto out_release_irq; |
| 8772 | } |
| 8773 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8774 | /* nic init */ |
| 8775 | iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
| 8776 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
| 8777 | |
| 8778 | iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 8779 | err = iwl4965_poll_bit(priv, CSR_GP_CNTRL, |
| 8780 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 8781 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
| 8782 | if (err < 0) { |
| 8783 | IWL_DEBUG_INFO("Failed to init the card\n"); |
| 8784 | goto out_remove_sysfs; |
| 8785 | } |
| 8786 | /* Read the EEPROM */ |
| 8787 | err = iwl4965_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8788 | if (err) { |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8789 | IWL_ERROR("Unable to init EEPROM\n"); |
| 8790 | goto out_remove_sysfs; |
| 8791 | } |
| 8792 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 8793 | get_eeprom_mac(priv, priv->mac_addr); |
| 8794 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 8795 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 8796 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8797 | err = iwl4965_init_channel_map(priv); |
| 8798 | if (err) { |
| 8799 | IWL_ERROR("initializing regulatory failed: %d\n", err); |
| 8800 | goto out_remove_sysfs; |
| 8801 | } |
| 8802 | |
| 8803 | err = iwl4965_init_geos(priv); |
| 8804 | if (err) { |
| 8805 | IWL_ERROR("initializing geos failed: %d\n", err); |
| 8806 | goto out_free_channel_map; |
| 8807 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8808 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8809 | iwl4965_rate_control_register(priv->hw); |
| 8810 | err = ieee80211_register_hw(priv->hw); |
| 8811 | if (err) { |
| 8812 | IWL_ERROR("Failed to register network device (error %d)\n", err); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8813 | goto out_free_geos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8814 | } |
| 8815 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8816 | priv->hw->conf.beacon_int = 100; |
| 8817 | priv->mac80211_registered = 1; |
| 8818 | pci_save_state(pdev); |
| 8819 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8820 | |
| 8821 | return 0; |
| 8822 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8823 | out_free_geos: |
| 8824 | iwl4965_free_geos(priv); |
| 8825 | out_free_channel_map: |
| 8826 | iwl4965_free_channel_map(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8827 | out_remove_sysfs: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8828 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8829 | |
| 8830 | out_release_irq: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8831 | destroy_workqueue(priv->workqueue); |
| 8832 | priv->workqueue = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8833 | iwl4965_unset_hw_setting(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8834 | |
| 8835 | out_iounmap: |
| 8836 | pci_iounmap(pdev, priv->hw_base); |
| 8837 | out_pci_release_regions: |
| 8838 | pci_release_regions(pdev); |
| 8839 | out_pci_disable_device: |
| 8840 | pci_disable_device(pdev); |
| 8841 | pci_set_drvdata(pdev, NULL); |
| 8842 | out_ieee80211_free_hw: |
| 8843 | ieee80211_free_hw(priv->hw); |
| 8844 | out: |
| 8845 | return err; |
| 8846 | } |
| 8847 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8848 | static void iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8849 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8850 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8851 | struct list_head *p, *q; |
| 8852 | int i; |
| 8853 | |
| 8854 | if (!priv) |
| 8855 | return; |
| 8856 | |
| 8857 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 8858 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8859 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 8860 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8861 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8862 | |
| 8863 | /* Free MAC hash list for ADHOC */ |
| 8864 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 8865 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 8866 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8867 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8868 | } |
| 8869 | } |
| 8870 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8871 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8872 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8873 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8874 | |
| 8875 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8876 | iwl4965_rx_queue_free(priv, &priv->rxq); |
| 8877 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8878 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8879 | iwl4965_unset_hw_setting(priv); |
| 8880 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8881 | |
| 8882 | if (priv->mac80211_registered) { |
| 8883 | ieee80211_unregister_hw(priv->hw); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8884 | iwl4965_rate_control_unregister(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8885 | } |
| 8886 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 8887 | /*netif_stop_queue(dev); */ |
| 8888 | flush_workqueue(priv->workqueue); |
| 8889 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8890 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8891 | * priv->workqueue... so we can't take down the workqueue |
| 8892 | * until now... */ |
| 8893 | destroy_workqueue(priv->workqueue); |
| 8894 | priv->workqueue = NULL; |
| 8895 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8896 | pci_iounmap(pdev, priv->hw_base); |
| 8897 | pci_release_regions(pdev); |
| 8898 | pci_disable_device(pdev); |
| 8899 | pci_set_drvdata(pdev, NULL); |
| 8900 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8901 | iwl4965_free_channel_map(priv); |
| 8902 | iwl4965_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8903 | |
| 8904 | if (priv->ibss_beacon) |
| 8905 | dev_kfree_skb(priv->ibss_beacon); |
| 8906 | |
| 8907 | ieee80211_free_hw(priv->hw); |
| 8908 | } |
| 8909 | |
| 8910 | #ifdef CONFIG_PM |
| 8911 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8912 | static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8913 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8914 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8915 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8916 | if (priv->is_open) { |
| 8917 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 8918 | iwl4965_mac_stop(priv->hw); |
| 8919 | priv->is_open = 1; |
| 8920 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8921 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8922 | pci_set_power_state(pdev, PCI_D3hot); |
| 8923 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8924 | return 0; |
| 8925 | } |
| 8926 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8927 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8928 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8929 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8930 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8931 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8932 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8933 | if (priv->is_open) |
| 8934 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8935 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8936 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8937 | return 0; |
| 8938 | } |
| 8939 | |
| 8940 | #endif /* CONFIG_PM */ |
| 8941 | |
| 8942 | /***************************************************************************** |
| 8943 | * |
| 8944 | * driver and module entry point |
| 8945 | * |
| 8946 | *****************************************************************************/ |
| 8947 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8948 | static struct pci_driver iwl4965_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8949 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8950 | .id_table = iwl4965_hw_card_ids, |
| 8951 | .probe = iwl4965_pci_probe, |
| 8952 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8953 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8954 | .suspend = iwl4965_pci_suspend, |
| 8955 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8956 | #endif |
| 8957 | }; |
| 8958 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8959 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8960 | { |
| 8961 | |
| 8962 | int ret; |
| 8963 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 8964 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8965 | ret = pci_register_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8966 | if (ret) { |
| 8967 | IWL_ERROR("Unable to initialize PCI module\n"); |
| 8968 | return ret; |
| 8969 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8970 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8971 | ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8972 | if (ret) { |
| 8973 | IWL_ERROR("Unable to create driver sysfs file\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8974 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8975 | return ret; |
| 8976 | } |
| 8977 | #endif |
| 8978 | |
| 8979 | return ret; |
| 8980 | } |
| 8981 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8982 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8983 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8984 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8985 | driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8986 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8987 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8988 | } |
| 8989 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8990 | module_param_named(antenna, iwl4965_param_antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8991 | 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] | 8992 | module_param_named(disable, iwl4965_param_disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8993 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8994 | module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8995 | MODULE_PARM_DESC(hwcrypto, |
| 8996 | "using hardware crypto engine (default 0 [software])\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8997 | module_param_named(debug, iwl4965_param_debug, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8998 | MODULE_PARM_DESC(debug, "debug output mask"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8999 | module_param_named(disable_hw_scan, iwl4965_param_disable_hw_scan, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9000 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 9001 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9002 | module_param_named(queues_num, iwl4965_param_queues_num, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9003 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 9004 | |
| 9005 | /* QoS */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9006 | module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9007 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 9008 | module_param_named(amsdu_size_8K, iwl4965_param_amsdu_size_8K, int, 0444); |
| 9009 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9010 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9011 | module_exit(iwl4965_exit); |
| 9012 | module_init(iwl4965_init); |