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 | |
| 44 | #include <net/ieee80211_radiotap.h> |
| 45 | #include <net/mac80211.h> |
| 46 | |
| 47 | #include <asm/div64.h> |
| 48 | |
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 | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 52 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 53 | u32 iwl4965_debug_level; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 54 | #endif |
| 55 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 56 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 57 | struct iwl4965_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 58 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 59 | /****************************************************************************** |
| 60 | * |
| 61 | * module boiler plate |
| 62 | * |
| 63 | ******************************************************************************/ |
| 64 | |
| 65 | /* module parameters */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 66 | static int iwl4965_param_disable_hw_scan; |
| 67 | static int iwl4965_param_debug; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 68 | static int iwl4965_param_disable; /* def: enable radio */ |
| 69 | static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */ |
| 70 | int iwl4965_param_hwcrypto; /* def: using software encryption */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 71 | static int iwl4965_param_qos_enable = 1; |
| 72 | int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * module name, copyright, version, etc. |
| 76 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 77 | */ |
| 78 | |
| 79 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" |
| 80 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 81 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 82 | #define VD "d" |
| 83 | #else |
| 84 | #define VD |
| 85 | #endif |
| 86 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 87 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 88 | #define VS "s" |
| 89 | #else |
| 90 | #define VS |
| 91 | #endif |
| 92 | |
Zhu Yi | 80f3e02 | 2007-10-25 17:15:48 +0800 | [diff] [blame] | 93 | #define IWLWIFI_VERSION "1.1.19k" VD VS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 94 | #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation" |
| 95 | #define DRV_VERSION IWLWIFI_VERSION |
| 96 | |
| 97 | /* Change firmware file name, using "-" and incrementing number, |
| 98 | * *only* when uCode interface or architecture changes so that it |
| 99 | * is not compatible with earlier drivers. |
| 100 | * This number will also appear in << 8 position of 1st dword of uCode file */ |
| 101 | #define IWL4965_UCODE_API "-1" |
| 102 | |
| 103 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 104 | MODULE_VERSION(DRV_VERSION); |
| 105 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 106 | MODULE_LICENSE("GPL"); |
| 107 | |
| 108 | __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) |
| 109 | { |
| 110 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 111 | int hdr_len = ieee80211_get_hdrlen(fc); |
| 112 | |
| 113 | if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA)) |
| 114 | return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN); |
| 115 | return NULL; |
| 116 | } |
| 117 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 118 | static const struct ieee80211_hw_mode *iwl4965_get_hw_mode( |
| 119 | struct iwl4965_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 120 | { |
| 121 | int i; |
| 122 | |
| 123 | for (i = 0; i < 3; i++) |
| 124 | if (priv->modes[i].mode == mode) |
| 125 | return &priv->modes[i]; |
| 126 | |
| 127 | return NULL; |
| 128 | } |
| 129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 130 | static int iwl4965_is_empty_essid(const char *essid, int essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 131 | { |
| 132 | /* Single white space is for Linksys APs */ |
| 133 | if (essid_len == 1 && essid[0] == ' ') |
| 134 | return 1; |
| 135 | |
| 136 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 137 | while (essid_len) { |
| 138 | essid_len--; |
| 139 | if (essid[essid_len] != '\0') |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | return 1; |
| 144 | } |
| 145 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 146 | static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 147 | { |
| 148 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 149 | const char *s = essid; |
| 150 | char *d = escaped; |
| 151 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 152 | if (iwl4965_is_empty_essid(essid, essid_len)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 153 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 154 | return escaped; |
| 155 | } |
| 156 | |
| 157 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 158 | while (essid_len--) { |
| 159 | if (*s == '\0') { |
| 160 | *d++ = '\\'; |
| 161 | *d++ = '0'; |
| 162 | s++; |
| 163 | } else |
| 164 | *d++ = *s++; |
| 165 | } |
| 166 | *d = '\0'; |
| 167 | return escaped; |
| 168 | } |
| 169 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 170 | static void iwl4965_print_hex_dump(int level, void *p, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 171 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 172 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 173 | if (!(iwl4965_debug_level & level)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 174 | return; |
| 175 | |
| 176 | print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1, |
| 177 | p, len, 1); |
| 178 | #endif |
| 179 | } |
| 180 | |
| 181 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 182 | * DMA services |
| 183 | * |
| 184 | * Theory of operation |
| 185 | * |
| 186 | * A queue is a circular buffers with 'Read' and 'Write' pointers. |
| 187 | * 2 empty entries always kept in the buffer to protect from overflow. |
| 188 | * |
| 189 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 190 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 191 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 192 | * Tx queue resumed. |
| 193 | * |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 194 | * The IWL operates with six queues, one receive queue in the device's |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 195 | * sram, one transmit queue for sending commands to the device firmware, |
| 196 | * and four transmit queues for data. |
| 197 | ***************************************************/ |
| 198 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 199 | static int iwl4965_queue_space(const struct iwl4965_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 200 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 201 | int s = q->read_ptr - q->write_ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 202 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 203 | if (q->read_ptr > q->write_ptr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 204 | s -= q->n_bd; |
| 205 | |
| 206 | if (s <= 0) |
| 207 | s += q->n_window; |
| 208 | /* keep some reserve to not confuse empty and full situations */ |
| 209 | s -= 2; |
| 210 | if (s < 0) |
| 211 | s = 0; |
| 212 | return s; |
| 213 | } |
| 214 | |
| 215 | /* XXX: n_bd must be power-of-two size */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 216 | static inline int iwl4965_queue_inc_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 217 | { |
| 218 | return ++index & (n_bd - 1); |
| 219 | } |
| 220 | |
| 221 | /* XXX: n_bd must be power-of-two size */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 222 | static inline int iwl4965_queue_dec_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 223 | { |
| 224 | return --index & (n_bd - 1); |
| 225 | } |
| 226 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 227 | 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] | 228 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 229 | return q->write_ptr > q->read_ptr ? |
| 230 | (i >= q->read_ptr && i < q->write_ptr) : |
| 231 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 234 | 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] | 235 | { |
| 236 | if (is_huge) |
| 237 | return q->n_window; |
| 238 | |
| 239 | return index & (q->n_window - 1); |
| 240 | } |
| 241 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 242 | 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] | 243 | int count, int slots_num, u32 id) |
| 244 | { |
| 245 | q->n_bd = count; |
| 246 | q->n_window = slots_num; |
| 247 | q->id = id; |
| 248 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 249 | /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap |
| 250 | * and iwl4965_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 251 | BUG_ON(!is_power_of_2(count)); |
| 252 | |
| 253 | /* slots_num must be power-of-two size, otherwise |
| 254 | * get_cmd_index is broken. */ |
| 255 | BUG_ON(!is_power_of_2(slots_num)); |
| 256 | |
| 257 | q->low_mark = q->n_window / 4; |
| 258 | if (q->low_mark < 4) |
| 259 | q->low_mark = 4; |
| 260 | |
| 261 | q->high_mark = q->n_window / 8; |
| 262 | if (q->high_mark < 2) |
| 263 | q->high_mark = 2; |
| 264 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 265 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 270 | static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv, |
| 271 | struct iwl4965_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 272 | { |
| 273 | struct pci_dev *dev = priv->pci_dev; |
| 274 | |
| 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 | |
| 286 | txq->bd = pci_alloc_consistent(dev, |
| 287 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 288 | &txq->q.dma_addr); |
| 289 | |
| 290 | if (!txq->bd) { |
| 291 | IWL_ERROR("pci_alloc_consistent(%zd) failed\n", |
| 292 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 293 | goto error; |
| 294 | } |
| 295 | txq->q.id = id; |
| 296 | |
| 297 | return 0; |
| 298 | |
| 299 | error: |
| 300 | if (txq->txb) { |
| 301 | kfree(txq->txb); |
| 302 | txq->txb = NULL; |
| 303 | } |
| 304 | |
| 305 | return -ENOMEM; |
| 306 | } |
| 307 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 308 | int iwl4965_tx_queue_init(struct iwl4965_priv *priv, |
| 309 | struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 310 | { |
| 311 | struct pci_dev *dev = priv->pci_dev; |
| 312 | int len; |
| 313 | int rc = 0; |
| 314 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 315 | /* allocate command space + one big command for scan since scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 316 | * command is very huge the system will not have two scan at the |
| 317 | * same time */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 318 | len = sizeof(struct iwl4965_cmd) * slots_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 319 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 320 | len += IWL_MAX_SCAN_SIZE; |
| 321 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 322 | if (!txq->cmd) |
| 323 | return -ENOMEM; |
| 324 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 325 | rc = iwl4965_tx_queue_alloc(priv, txq, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 326 | if (rc) { |
| 327 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 328 | |
| 329 | return -ENOMEM; |
| 330 | } |
| 331 | txq->need_update = 0; |
| 332 | |
| 333 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 334 | * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 335 | BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 336 | 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] | 337 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 338 | iwl4965_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 344 | * iwl4965_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 345 | * @txq: Transmit queue to deallocate. |
| 346 | * |
| 347 | * Empty queue by removing and destroying all BD's. |
| 348 | * Free all buffers. txq itself is not freed. |
| 349 | * |
| 350 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 351 | 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] | 352 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 353 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 354 | struct pci_dev *dev = priv->pci_dev; |
| 355 | int len; |
| 356 | |
| 357 | if (q->n_bd == 0) |
| 358 | return; |
| 359 | |
| 360 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 361 | for (; q->write_ptr != q->read_ptr; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 362 | q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) |
| 363 | iwl4965_hw_txq_free_tfd(priv, txq); |
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 | len = sizeof(struct iwl4965_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 366 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 367 | len += IWL_MAX_SCAN_SIZE; |
| 368 | |
| 369 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 370 | |
| 371 | /* free buffers belonging to queue itself */ |
| 372 | if (txq->q.n_bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 373 | pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 374 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 375 | |
| 376 | if (txq->txb) { |
| 377 | kfree(txq->txb); |
| 378 | txq->txb = NULL; |
| 379 | } |
| 380 | |
| 381 | /* 0 fill whole structure */ |
| 382 | memset(txq, 0, sizeof(*txq)); |
| 383 | } |
| 384 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 385 | 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] | 386 | |
| 387 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 388 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 389 | * the functionality provided here |
| 390 | */ |
| 391 | |
| 392 | /**************************************************************/ |
| 393 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 394 | #if 0 /* temporary disable till we add real remove station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 395 | 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] | 396 | { |
| 397 | int index = IWL_INVALID_STATION; |
| 398 | int i; |
| 399 | unsigned long flags; |
| 400 | |
| 401 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 402 | |
| 403 | if (is_ap) |
| 404 | index = IWL_AP_ID; |
| 405 | else if (is_broadcast_ether_addr(addr)) |
| 406 | index = priv->hw_setting.bcast_sta_id; |
| 407 | else |
| 408 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) |
| 409 | if (priv->stations[i].used && |
| 410 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 411 | addr)) { |
| 412 | index = i; |
| 413 | break; |
| 414 | } |
| 415 | |
| 416 | if (unlikely(index == IWL_INVALID_STATION)) |
| 417 | goto out; |
| 418 | |
| 419 | if (priv->stations[index].used) { |
| 420 | priv->stations[index].used = 0; |
| 421 | priv->num_stations--; |
| 422 | } |
| 423 | |
| 424 | BUG_ON(priv->num_stations < 0); |
| 425 | |
| 426 | out: |
| 427 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 428 | return 0; |
| 429 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 430 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 431 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 432 | static void iwl4965_clear_stations_table(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 433 | { |
| 434 | unsigned long flags; |
| 435 | |
| 436 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 437 | |
| 438 | priv->num_stations = 0; |
| 439 | memset(priv->stations, 0, sizeof(priv->stations)); |
| 440 | |
| 441 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 442 | } |
| 443 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 444 | u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr, int is_ap, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 445 | { |
| 446 | int i; |
| 447 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 448 | struct iwl4965_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 449 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 450 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 451 | |
| 452 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 453 | if (is_ap) |
| 454 | index = IWL_AP_ID; |
| 455 | else if (is_broadcast_ether_addr(addr)) |
| 456 | index = priv->hw_setting.bcast_sta_id; |
| 457 | else |
| 458 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) { |
| 459 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 460 | addr)) { |
| 461 | index = i; |
| 462 | break; |
| 463 | } |
| 464 | |
| 465 | if (!priv->stations[i].used && |
| 466 | index == IWL_INVALID_STATION) |
| 467 | index = i; |
| 468 | } |
| 469 | |
| 470 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 471 | /* These two conditions have the same outcome, but keep them separate |
| 472 | since they have different meanings */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 473 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 474 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 475 | return index; |
| 476 | } |
| 477 | |
| 478 | if (priv->stations[index].used && |
| 479 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 480 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 481 | return index; |
| 482 | } |
| 483 | |
| 484 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 485 | 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] | 486 | station = &priv->stations[index]; |
| 487 | station->used = 1; |
| 488 | priv->num_stations++; |
| 489 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 490 | memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 491 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 492 | station->sta.mode = 0; |
| 493 | station->sta.sta.sta_id = index; |
| 494 | station->sta.station_flags = 0; |
| 495 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 496 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 497 | /* BCAST station and IBSS stations do not work in HT mode */ |
| 498 | if (index != priv->hw_setting.bcast_sta_id && |
| 499 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
| 500 | iwl4965_set_ht_add_station(priv, index); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 501 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 502 | |
| 503 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 504 | iwl4965_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 505 | return index; |
| 506 | |
| 507 | } |
| 508 | |
| 509 | /*************** DRIVER STATUS FUNCTIONS *****/ |
| 510 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 511 | static inline int iwl4965_is_ready(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 512 | { |
| 513 | /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are |
| 514 | * set but EXIT_PENDING is not */ |
| 515 | return test_bit(STATUS_READY, &priv->status) && |
| 516 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) && |
| 517 | !test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 518 | } |
| 519 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 520 | static inline int iwl4965_is_alive(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 521 | { |
| 522 | return test_bit(STATUS_ALIVE, &priv->status); |
| 523 | } |
| 524 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 525 | static inline int iwl4965_is_init(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 526 | { |
| 527 | return test_bit(STATUS_INIT, &priv->status); |
| 528 | } |
| 529 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 530 | static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 531 | { |
| 532 | return test_bit(STATUS_RF_KILL_HW, &priv->status) || |
| 533 | test_bit(STATUS_RF_KILL_SW, &priv->status); |
| 534 | } |
| 535 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 536 | static inline int iwl4965_is_ready_rf(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 537 | { |
| 538 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 539 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 540 | return 0; |
| 541 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 542 | return iwl4965_is_ready(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 546 | |
| 547 | #define IWL_CMD(x) case x : return #x |
| 548 | |
| 549 | static const char *get_cmd_string(u8 cmd) |
| 550 | { |
| 551 | switch (cmd) { |
| 552 | IWL_CMD(REPLY_ALIVE); |
| 553 | IWL_CMD(REPLY_ERROR); |
| 554 | IWL_CMD(REPLY_RXON); |
| 555 | IWL_CMD(REPLY_RXON_ASSOC); |
| 556 | IWL_CMD(REPLY_QOS_PARAM); |
| 557 | IWL_CMD(REPLY_RXON_TIMING); |
| 558 | IWL_CMD(REPLY_ADD_STA); |
| 559 | IWL_CMD(REPLY_REMOVE_STA); |
| 560 | IWL_CMD(REPLY_REMOVE_ALL_STA); |
| 561 | IWL_CMD(REPLY_TX); |
| 562 | IWL_CMD(REPLY_RATE_SCALE); |
| 563 | IWL_CMD(REPLY_LEDS_CMD); |
| 564 | IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); |
| 565 | IWL_CMD(RADAR_NOTIFICATION); |
| 566 | IWL_CMD(REPLY_QUIET_CMD); |
| 567 | IWL_CMD(REPLY_CHANNEL_SWITCH); |
| 568 | IWL_CMD(CHANNEL_SWITCH_NOTIFICATION); |
| 569 | IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD); |
| 570 | IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION); |
| 571 | IWL_CMD(POWER_TABLE_CMD); |
| 572 | IWL_CMD(PM_SLEEP_NOTIFICATION); |
| 573 | IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC); |
| 574 | IWL_CMD(REPLY_SCAN_CMD); |
| 575 | IWL_CMD(REPLY_SCAN_ABORT_CMD); |
| 576 | IWL_CMD(SCAN_START_NOTIFICATION); |
| 577 | IWL_CMD(SCAN_RESULTS_NOTIFICATION); |
| 578 | IWL_CMD(SCAN_COMPLETE_NOTIFICATION); |
| 579 | IWL_CMD(BEACON_NOTIFICATION); |
| 580 | IWL_CMD(REPLY_TX_BEACON); |
| 581 | IWL_CMD(WHO_IS_AWAKE_NOTIFICATION); |
| 582 | IWL_CMD(QUIET_NOTIFICATION); |
| 583 | IWL_CMD(REPLY_TX_PWR_TABLE_CMD); |
| 584 | IWL_CMD(MEASURE_ABORT_NOTIFICATION); |
| 585 | IWL_CMD(REPLY_BT_CONFIG); |
| 586 | IWL_CMD(REPLY_STATISTICS_CMD); |
| 587 | IWL_CMD(STATISTICS_NOTIFICATION); |
| 588 | IWL_CMD(REPLY_CARD_STATE_CMD); |
| 589 | IWL_CMD(CARD_STATE_NOTIFICATION); |
| 590 | IWL_CMD(MISSED_BEACONS_NOTIFICATION); |
| 591 | IWL_CMD(REPLY_CT_KILL_CONFIG_CMD); |
| 592 | IWL_CMD(SENSITIVITY_CMD); |
| 593 | IWL_CMD(REPLY_PHY_CALIBRATION_CMD); |
| 594 | IWL_CMD(REPLY_RX_PHY_CMD); |
| 595 | IWL_CMD(REPLY_RX_MPDU_CMD); |
| 596 | IWL_CMD(REPLY_4965_RX); |
| 597 | IWL_CMD(REPLY_COMPRESSED_BA); |
| 598 | default: |
| 599 | return "UNKNOWN"; |
| 600 | |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 605 | |
| 606 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 607 | * iwl4965_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 608 | * @priv: device private data point |
| 609 | * @cmd: a point to the ucode command structure |
| 610 | * |
| 611 | * The function returns < 0 values to indicate the operation is |
| 612 | * failed. On success, it turns the index (> 0) of command in the |
| 613 | * command queue. |
| 614 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 615 | 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] | 616 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 617 | struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 618 | struct iwl4965_queue *q = &txq->q; |
| 619 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 620 | u32 *control_flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 621 | struct iwl4965_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 622 | u32 idx; |
| 623 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 624 | dma_addr_t phys_addr; |
| 625 | int ret; |
| 626 | unsigned long flags; |
| 627 | |
| 628 | /* If any of the command structures end up being larger than |
| 629 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 630 | * we will need to increase the size of the TFD entries */ |
| 631 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 632 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 633 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 634 | if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 635 | IWL_ERROR("No space for Tx\n"); |
| 636 | return -ENOSPC; |
| 637 | } |
| 638 | |
| 639 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 640 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 641 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 642 | memset(tfd, 0, sizeof(*tfd)); |
| 643 | |
| 644 | control_flags = (u32 *) tfd; |
| 645 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 646 | 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] | 647 | out_cmd = &txq->cmd[idx]; |
| 648 | |
| 649 | out_cmd->hdr.cmd = cmd->id; |
| 650 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 651 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 652 | |
| 653 | /* At this point, the out_cmd now has all of the incoming cmd |
| 654 | * information */ |
| 655 | |
| 656 | out_cmd->hdr.flags = 0; |
| 657 | 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] | 658 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 659 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 660 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 661 | |
| 662 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 663 | offsetof(struct iwl4965_cmd, hdr); |
| 664 | 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] | 665 | |
| 666 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 667 | "%d bytes at %d[%d]:%d\n", |
| 668 | get_cmd_string(out_cmd->hdr.cmd), |
| 669 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 670 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 671 | |
| 672 | txq->need_update = 1; |
| 673 | ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 674 | q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 675 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 676 | |
| 677 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 678 | return ret ? ret : idx; |
| 679 | } |
| 680 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 681 | 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] | 682 | { |
| 683 | int ret; |
| 684 | |
| 685 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 686 | |
| 687 | /* An asynchronous command can not expect an SKB to be set. */ |
| 688 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 689 | |
| 690 | /* An asynchronous command MUST have a callback. */ |
| 691 | BUG_ON(!cmd->meta.u.callback); |
| 692 | |
| 693 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 694 | return -EBUSY; |
| 695 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 696 | ret = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 697 | if (ret < 0) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 698 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 699 | get_cmd_string(cmd->id), ret); |
| 700 | return ret; |
| 701 | } |
| 702 | return 0; |
| 703 | } |
| 704 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 705 | 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] | 706 | { |
| 707 | int cmd_idx; |
| 708 | int ret; |
| 709 | static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */ |
| 710 | |
| 711 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 712 | |
| 713 | /* A synchronous command can not have a callback set. */ |
| 714 | BUG_ON(cmd->meta.u.callback != NULL); |
| 715 | |
| 716 | if (atomic_xchg(&entry, 1)) { |
| 717 | IWL_ERROR("Error sending %s: Already sending a host command\n", |
| 718 | get_cmd_string(cmd->id)); |
| 719 | return -EBUSY; |
| 720 | } |
| 721 | |
| 722 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 723 | |
| 724 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 725 | cmd->meta.source = &cmd->meta; |
| 726 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 727 | cmd_idx = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 728 | if (cmd_idx < 0) { |
| 729 | ret = cmd_idx; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 730 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 731 | get_cmd_string(cmd->id), ret); |
| 732 | goto out; |
| 733 | } |
| 734 | |
| 735 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 736 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 737 | HOST_COMPLETE_TIMEOUT); |
| 738 | if (!ret) { |
| 739 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
| 740 | IWL_ERROR("Error sending %s: time out after %dms.\n", |
| 741 | get_cmd_string(cmd->id), |
| 742 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 743 | |
| 744 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 745 | ret = -ETIMEDOUT; |
| 746 | goto cancel; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 751 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 752 | get_cmd_string(cmd->id)); |
| 753 | ret = -ECANCELED; |
| 754 | goto fail; |
| 755 | } |
| 756 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 757 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 758 | get_cmd_string(cmd->id)); |
| 759 | ret = -EIO; |
| 760 | goto fail; |
| 761 | } |
| 762 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
| 763 | IWL_ERROR("Error: Response NULL in '%s'\n", |
| 764 | get_cmd_string(cmd->id)); |
| 765 | ret = -EIO; |
| 766 | goto out; |
| 767 | } |
| 768 | |
| 769 | ret = 0; |
| 770 | goto out; |
| 771 | |
| 772 | cancel: |
| 773 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 774 | struct iwl4965_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 775 | |
| 776 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 777 | * TX cmd queue. Otherwise in case the cmd comes |
| 778 | * in later, it will possibly set an invalid |
| 779 | * address (cmd->meta.source). */ |
| 780 | qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
| 781 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 782 | } |
| 783 | fail: |
| 784 | if (cmd->meta.u.skb) { |
| 785 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 786 | cmd->meta.u.skb = NULL; |
| 787 | } |
| 788 | out: |
| 789 | atomic_set(&entry, 0); |
| 790 | return ret; |
| 791 | } |
| 792 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 793 | 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] | 794 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 795 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 796 | return iwl4965_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 797 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 798 | return iwl4965_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 801 | 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] | 802 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 803 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 804 | .id = id, |
| 805 | .len = len, |
| 806 | .data = data, |
| 807 | }; |
| 808 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 809 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 812 | 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] | 813 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 814 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 815 | .id = id, |
| 816 | .len = sizeof(val), |
| 817 | .data = &val, |
| 818 | }; |
| 819 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 820 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 823 | int iwl4965_send_statistics_request(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 824 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 825 | return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 829 | * iwl4965_rxon_add_station - add station into station table. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 830 | * |
| 831 | * there is only one AP station with id= IWL_AP_ID |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 832 | * NOTE: mutex must be held before calling this fnction |
| 833 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 834 | static int iwl4965_rxon_add_station(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 835 | const u8 *addr, int is_ap) |
| 836 | { |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 837 | u8 sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 838 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 839 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 840 | iwl4965_add_station(priv, addr, is_ap); |
| 841 | |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 842 | return sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 846 | * 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] | 847 | * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz |
| 848 | * @channel: Any channel valid for the requested phymode |
| 849 | |
| 850 | * In addition to setting the staging RXON, priv->phymode is also set. |
| 851 | * |
| 852 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
| 853 | * in the staging RXON flag structure based on the phymode |
| 854 | */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 855 | static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, u8 phymode, |
| 856 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 857 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 858 | if (!iwl4965_get_channel_info(priv, phymode, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 859 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
| 860 | channel, phymode); |
| 861 | return -EINVAL; |
| 862 | } |
| 863 | |
| 864 | if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && |
| 865 | (priv->phymode == phymode)) |
| 866 | return 0; |
| 867 | |
| 868 | priv->staging_rxon.channel = cpu_to_le16(channel); |
| 869 | if (phymode == MODE_IEEE80211A) |
| 870 | priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
| 871 | else |
| 872 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 873 | |
| 874 | priv->phymode = phymode; |
| 875 | |
| 876 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode); |
| 877 | |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 882 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 883 | * |
| 884 | * NOTE: This is really only useful during development and can eventually |
| 885 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 886 | * making changes |
| 887 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 888 | static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 889 | { |
| 890 | int error = 0; |
| 891 | int counter = 1; |
| 892 | |
| 893 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 894 | error |= le32_to_cpu(rxon->flags & |
| 895 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 896 | RXON_FLG_RADAR_DETECT_MSK)); |
| 897 | if (error) |
| 898 | IWL_WARNING("check 24G fields %d | %d\n", |
| 899 | counter++, error); |
| 900 | } else { |
| 901 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 902 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 903 | if (error) |
| 904 | IWL_WARNING("check 52 fields %d | %d\n", |
| 905 | counter++, error); |
| 906 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 907 | if (error) |
| 908 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 909 | counter++, error); |
| 910 | } |
| 911 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 912 | if (error) |
| 913 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 914 | |
| 915 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 916 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 917 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 918 | if (error) |
| 919 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 920 | |
| 921 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 922 | if (error) |
| 923 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 924 | |
| 925 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 926 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 927 | if (error) |
| 928 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 929 | counter++, error); |
| 930 | |
| 931 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 932 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 933 | if (error) |
| 934 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 935 | counter++, error); |
| 936 | |
| 937 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 938 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 939 | if (error) |
| 940 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 941 | counter++, error); |
| 942 | |
| 943 | if (error) |
| 944 | IWL_WARNING("Tuning to channel %d\n", |
| 945 | le16_to_cpu(rxon->channel)); |
| 946 | |
| 947 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 948 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 949 | return -1; |
| 950 | } |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 955 | * 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] | 956 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 957 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 958 | * If the RXON structure is changing enough to require a new tune, |
| 959 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 960 | * 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] | 961 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 962 | static int iwl4965_full_rxon_required(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 963 | { |
| 964 | |
| 965 | /* These items are only settable from the full RXON command */ |
| 966 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 967 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 968 | priv->active_rxon.bssid_addr) || |
| 969 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 970 | priv->active_rxon.node_addr) || |
| 971 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 972 | priv->active_rxon.wlap_bssid_addr) || |
| 973 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 974 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 975 | (priv->staging_rxon.air_propagation != |
| 976 | priv->active_rxon.air_propagation) || |
| 977 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 978 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 979 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 980 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 981 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 982 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 983 | return 1; |
| 984 | |
| 985 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 986 | * be updated with the RXON_ASSOC command -- however only some |
| 987 | * flag transitions are allowed using RXON_ASSOC */ |
| 988 | |
| 989 | /* Check if we are not switching bands */ |
| 990 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 991 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 992 | return 1; |
| 993 | |
| 994 | /* Check if we are switching association toggle */ |
| 995 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 996 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 997 | return 1; |
| 998 | |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1002 | static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1003 | { |
| 1004 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1005 | struct iwl4965_rx_packet *res = NULL; |
| 1006 | struct iwl4965_rxon_assoc_cmd rxon_assoc; |
| 1007 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1008 | .id = REPLY_RXON_ASSOC, |
| 1009 | .len = sizeof(rxon_assoc), |
| 1010 | .meta.flags = CMD_WANT_SKB, |
| 1011 | .data = &rxon_assoc, |
| 1012 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1013 | const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 1014 | const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1015 | |
| 1016 | if ((rxon1->flags == rxon2->flags) && |
| 1017 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 1018 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 1019 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 1020 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 1021 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 1022 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 1023 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 1024 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 1025 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 1030 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 1031 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 1032 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
| 1033 | rxon_assoc.reserved = 0; |
| 1034 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 1035 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates; |
| 1036 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 1037 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; |
| 1038 | rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; |
| 1039 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1040 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1041 | if (rc) |
| 1042 | return rc; |
| 1043 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1044 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1045 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1046 | IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n"); |
| 1047 | rc = -EIO; |
| 1048 | } |
| 1049 | |
| 1050 | priv->alloc_rxb_skb--; |
| 1051 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1052 | |
| 1053 | return rc; |
| 1054 | } |
| 1055 | |
| 1056 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1057 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1058 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1059 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1060 | * the active_rxon structure is updated with the new data. This |
| 1061 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 1062 | * a HW tune is required based on the RXON structure changes. |
| 1063 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1064 | static int iwl4965_commit_rxon(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1065 | { |
| 1066 | /* cast away the const for active_rxon in this function */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1067 | struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1068 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1069 | int rc = 0; |
| 1070 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1071 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1072 | return -1; |
| 1073 | |
| 1074 | /* always get timestamp with Rx frame */ |
| 1075 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 1076 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1077 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1078 | if (rc) { |
| 1079 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 1080 | return -EINVAL; |
| 1081 | } |
| 1082 | |
| 1083 | /* 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] | 1084 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1085 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1086 | if (!iwl4965_full_rxon_required(priv)) { |
| 1087 | rc = iwl4965_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1088 | if (rc) { |
| 1089 | IWL_ERROR("Error setting RXON_ASSOC " |
| 1090 | "configuration (%d).\n", rc); |
| 1091 | return rc; |
| 1092 | } |
| 1093 | |
| 1094 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1095 | |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | /* station table will be cleared */ |
| 1100 | priv->assoc_station_added = 0; |
| 1101 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1102 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1103 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1104 | if (!priv->error_recovering) |
| 1105 | priv->start_calib = 0; |
| 1106 | |
| 1107 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1108 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1109 | |
| 1110 | /* If we are currently associated and the new config requires |
| 1111 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 1112 | * we must clear the associated from the active configuration |
| 1113 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1114 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1115 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 1116 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 1117 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1118 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1119 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1120 | sizeof(struct iwl4965_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | &priv->active_rxon); |
| 1122 | |
| 1123 | /* If the mask clearing failed then we set |
| 1124 | * active_rxon back to what it was previously */ |
| 1125 | if (rc) { |
| 1126 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1127 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 1128 | "configuration (%d).\n", rc); |
| 1129 | return rc; |
| 1130 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | IWL_DEBUG_INFO("Sending RXON\n" |
| 1134 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 1135 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1136 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1137 | ((priv->staging_rxon.filter_flags & |
| 1138 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 1139 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1140 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1141 | |
| 1142 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1143 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1144 | sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1145 | if (rc) { |
| 1146 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 1147 | return rc; |
| 1148 | } |
| 1149 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1150 | iwl4965_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 1151 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1152 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1153 | if (!priv->error_recovering) |
| 1154 | priv->start_calib = 0; |
| 1155 | |
| 1156 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1157 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1158 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1159 | |
| 1160 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1161 | |
| 1162 | /* If we issue a new RXON command which required a tune then we must |
| 1163 | * 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] | 1164 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1165 | if (rc) { |
| 1166 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 1167 | return rc; |
| 1168 | } |
| 1169 | |
| 1170 | /* Add the broadcast address so we can send broadcast frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1171 | if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1172 | IWL_INVALID_STATION) { |
| 1173 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 1174 | return -EIO; |
| 1175 | } |
| 1176 | |
| 1177 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 1178 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1179 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1180 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1181 | if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1182 | == IWL_INVALID_STATION) { |
| 1183 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 1184 | return -EIO; |
| 1185 | } |
| 1186 | priv->assoc_station_added = 1; |
| 1187 | } |
| 1188 | |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1192 | static int iwl4965_send_bt_config(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1193 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1194 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1195 | .flags = 3, |
| 1196 | .lead_time = 0xAA, |
| 1197 | .max_kill = 1, |
| 1198 | .kill_ack_mask = 0, |
| 1199 | .kill_cts_mask = 0, |
| 1200 | }; |
| 1201 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1202 | return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
| 1203 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1206 | static int iwl4965_send_scan_abort(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1207 | { |
| 1208 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1209 | struct iwl4965_rx_packet *res; |
| 1210 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1211 | .id = REPLY_SCAN_ABORT_CMD, |
| 1212 | .meta.flags = CMD_WANT_SKB, |
| 1213 | }; |
| 1214 | |
| 1215 | /* If there isn't a scan actively going on in the hardware |
| 1216 | * then we are in between scan bands and not actually |
| 1217 | * actively scanning, so don't send the abort command */ |
| 1218 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1219 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1223 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1224 | if (rc) { |
| 1225 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1226 | return rc; |
| 1227 | } |
| 1228 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1229 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1230 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1231 | /* The scan abort will return 1 for success or |
| 1232 | * 2 for "failure". A failure condition can be |
| 1233 | * due to simply not being in an active scan which |
| 1234 | * can occur if we send the scan abort before we |
| 1235 | * the microcode has notified us that a scan is |
| 1236 | * completed. */ |
| 1237 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1238 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1239 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1240 | } |
| 1241 | |
| 1242 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1243 | |
| 1244 | return rc; |
| 1245 | } |
| 1246 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1247 | static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv, |
| 1248 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1249 | struct sk_buff *skb) |
| 1250 | { |
| 1251 | return 1; |
| 1252 | } |
| 1253 | |
| 1254 | /* |
| 1255 | * CARD_STATE_CMD |
| 1256 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1257 | * 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] | 1258 | * |
| 1259 | * When in the 'enable' state the card operates as normal. |
| 1260 | * When in the 'disable' state, the card enters into a low power mode. |
| 1261 | * When in the 'halt' state, the card is shut down and must be fully |
| 1262 | * restarted to come back on. |
| 1263 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1264 | 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] | 1265 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1266 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1267 | .id = REPLY_CARD_STATE_CMD, |
| 1268 | .len = sizeof(u32), |
| 1269 | .data = &flags, |
| 1270 | .meta.flags = meta_flag, |
| 1271 | }; |
| 1272 | |
| 1273 | if (meta_flag & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1274 | cmd.meta.u.callback = iwl4965_card_state_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1275 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1276 | return iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1279 | static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv, |
| 1280 | struct iwl4965_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1281 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1282 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1283 | |
| 1284 | if (!skb) { |
| 1285 | IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); |
| 1286 | return 1; |
| 1287 | } |
| 1288 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1289 | res = (struct iwl4965_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1290 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1291 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1292 | res->hdr.flags); |
| 1293 | return 1; |
| 1294 | } |
| 1295 | |
| 1296 | switch (res->u.add_sta.status) { |
| 1297 | case ADD_STA_SUCCESS_MSK: |
| 1298 | break; |
| 1299 | default: |
| 1300 | break; |
| 1301 | } |
| 1302 | |
| 1303 | /* We didn't cache the SKB; let the caller free it */ |
| 1304 | return 1; |
| 1305 | } |
| 1306 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1307 | int iwl4965_send_add_station(struct iwl4965_priv *priv, |
| 1308 | struct iwl4965_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1309 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1310 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1311 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1312 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1313 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1314 | .len = sizeof(struct iwl4965_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1315 | .meta.flags = flags, |
| 1316 | .data = sta, |
| 1317 | }; |
| 1318 | |
| 1319 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1320 | cmd.meta.u.callback = iwl4965_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1321 | else |
| 1322 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1323 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1324 | rc = iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1325 | |
| 1326 | if (rc || (flags & CMD_ASYNC)) |
| 1327 | return rc; |
| 1328 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1329 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1330 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1331 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1332 | res->hdr.flags); |
| 1333 | rc = -EIO; |
| 1334 | } |
| 1335 | |
| 1336 | if (rc == 0) { |
| 1337 | switch (res->u.add_sta.status) { |
| 1338 | case ADD_STA_SUCCESS_MSK: |
| 1339 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1340 | break; |
| 1341 | default: |
| 1342 | rc = -EIO; |
| 1343 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 1344 | break; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | priv->alloc_rxb_skb--; |
| 1349 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1350 | |
| 1351 | return rc; |
| 1352 | } |
| 1353 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1354 | static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1355 | struct ieee80211_key_conf *keyconf, |
| 1356 | u8 sta_id) |
| 1357 | { |
| 1358 | unsigned long flags; |
| 1359 | __le16 key_flags = 0; |
| 1360 | |
| 1361 | switch (keyconf->alg) { |
| 1362 | case ALG_CCMP: |
| 1363 | key_flags |= STA_KEY_FLG_CCMP; |
| 1364 | key_flags |= cpu_to_le16( |
| 1365 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1366 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1367 | break; |
| 1368 | case ALG_TKIP: |
| 1369 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1370 | default: |
| 1371 | return -EINVAL; |
| 1372 | } |
| 1373 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1374 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 1375 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1376 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 1377 | keyconf->keylen); |
| 1378 | |
| 1379 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 1380 | keyconf->keylen); |
| 1381 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 1382 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1383 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1384 | |
| 1385 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1386 | |
| 1387 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1388 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1389 | return 0; |
| 1390 | } |
| 1391 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1392 | 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] | 1393 | { |
| 1394 | unsigned long flags; |
| 1395 | |
| 1396 | spin_lock_irqsave(&priv->sta_lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1397 | memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key)); |
| 1398 | memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1399 | priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1400 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1401 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1402 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1403 | |
| 1404 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1405 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1406 | return 0; |
| 1407 | } |
| 1408 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1409 | static void iwl4965_clear_free_frames(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1410 | { |
| 1411 | struct list_head *element; |
| 1412 | |
| 1413 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1414 | priv->frames_count); |
| 1415 | |
| 1416 | while (!list_empty(&priv->free_frames)) { |
| 1417 | element = priv->free_frames.next; |
| 1418 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1419 | kfree(list_entry(element, struct iwl4965_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1420 | priv->frames_count--; |
| 1421 | } |
| 1422 | |
| 1423 | if (priv->frames_count) { |
| 1424 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 1425 | priv->frames_count); |
| 1426 | priv->frames_count = 0; |
| 1427 | } |
| 1428 | } |
| 1429 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1430 | static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1431 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1432 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1433 | struct list_head *element; |
| 1434 | if (list_empty(&priv->free_frames)) { |
| 1435 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1436 | if (!frame) { |
| 1437 | IWL_ERROR("Could not allocate frame!\n"); |
| 1438 | return NULL; |
| 1439 | } |
| 1440 | |
| 1441 | priv->frames_count++; |
| 1442 | return frame; |
| 1443 | } |
| 1444 | |
| 1445 | element = priv->free_frames.next; |
| 1446 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1447 | return list_entry(element, struct iwl4965_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1450 | 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] | 1451 | { |
| 1452 | memset(frame, 0, sizeof(*frame)); |
| 1453 | list_add(&frame->list, &priv->free_frames); |
| 1454 | } |
| 1455 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1456 | unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1457 | struct ieee80211_hdr *hdr, |
| 1458 | const u8 *dest, int left) |
| 1459 | { |
| 1460 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1461 | if (!iwl4965_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1462 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 1463 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 1464 | return 0; |
| 1465 | |
| 1466 | if (priv->ibss_beacon->len > left) |
| 1467 | return 0; |
| 1468 | |
| 1469 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1470 | |
| 1471 | return priv->ibss_beacon->len; |
| 1472 | } |
| 1473 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1474 | int iwl4965_rate_index_from_plcp(int plcp) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1475 | { |
| 1476 | int i = 0; |
| 1477 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1478 | /* 4965 HT rate format */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1479 | if (plcp & RATE_MCS_HT_MSK) { |
| 1480 | i = (plcp & 0xff); |
| 1481 | |
| 1482 | if (i >= IWL_RATE_MIMO_6M_PLCP) |
| 1483 | i = i - IWL_RATE_MIMO_6M_PLCP; |
| 1484 | |
| 1485 | i += IWL_FIRST_OFDM_RATE; |
| 1486 | /* skip 9M not supported in ht*/ |
| 1487 | if (i >= IWL_RATE_9M_INDEX) |
| 1488 | i += 1; |
| 1489 | if ((i >= IWL_FIRST_OFDM_RATE) && |
| 1490 | (i <= IWL_LAST_OFDM_RATE)) |
| 1491 | return i; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1492 | |
| 1493 | /* 4965 legacy rate format, search for match in table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1494 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1495 | for (i = 0; i < ARRAY_SIZE(iwl4965_rates); i++) |
| 1496 | if (iwl4965_rates[i].plcp == (plcp &0xFF)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1497 | return i; |
| 1498 | } |
| 1499 | return -1; |
| 1500 | } |
| 1501 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1502 | static u8 iwl4965_rate_get_lowest_plcp(int rate_mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1503 | { |
| 1504 | u8 i; |
| 1505 | |
| 1506 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1507 | i = iwl4965_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1508 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1509 | return iwl4965_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | return IWL_RATE_INVALID; |
| 1513 | } |
| 1514 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1515 | static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1516 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1517 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1518 | unsigned int frame_size; |
| 1519 | int rc; |
| 1520 | u8 rate; |
| 1521 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1522 | frame = iwl4965_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1523 | |
| 1524 | if (!frame) { |
| 1525 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 1526 | "command.\n"); |
| 1527 | return -ENOMEM; |
| 1528 | } |
| 1529 | |
| 1530 | if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1531 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1532 | 0xFF0); |
| 1533 | if (rate == IWL_INVALID_RATE) |
| 1534 | rate = IWL_RATE_6M_PLCP; |
| 1535 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1536 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1537 | if (rate == IWL_INVALID_RATE) |
| 1538 | rate = IWL_RATE_1M_PLCP; |
| 1539 | } |
| 1540 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1541 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1542 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1543 | rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1544 | &frame->u.cmd[0]); |
| 1545 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1546 | iwl4965_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1547 | |
| 1548 | return rc; |
| 1549 | } |
| 1550 | |
| 1551 | /****************************************************************************** |
| 1552 | * |
| 1553 | * EEPROM related functions |
| 1554 | * |
| 1555 | ******************************************************************************/ |
| 1556 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1557 | static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1558 | { |
| 1559 | memcpy(mac, priv->eeprom.mac_address, 6); |
| 1560 | } |
| 1561 | |
| 1562 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1563 | * iwl4965_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1564 | * |
| 1565 | * Load the EEPROM from adapter into priv->eeprom |
| 1566 | * |
| 1567 | * NOTE: This routine uses the non-debug IO access functions. |
| 1568 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1569 | int iwl4965_eeprom_init(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1570 | { |
| 1571 | u16 *e = (u16 *)&priv->eeprom; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1572 | u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1573 | u32 r; |
| 1574 | int sz = sizeof(priv->eeprom); |
| 1575 | int rc; |
| 1576 | int i; |
| 1577 | u16 addr; |
| 1578 | |
| 1579 | /* The EEPROM structure has several padding buffers within it |
| 1580 | * and when adding new EEPROM maps is subject to programmer errors |
| 1581 | * which may be very difficult to identify without explicitly |
| 1582 | * checking the resulting size of the eeprom map. */ |
| 1583 | BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); |
| 1584 | |
| 1585 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
| 1586 | IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); |
| 1587 | return -ENOENT; |
| 1588 | } |
| 1589 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1590 | rc = iwl4965_eeprom_acquire_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1591 | if (rc < 0) { |
Ian Schram | 91e1747 | 2007-10-25 17:15:23 +0800 | [diff] [blame] | 1592 | IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1593 | return -ENOENT; |
| 1594 | } |
| 1595 | |
| 1596 | /* eeprom is an array of 16bit values */ |
| 1597 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1598 | _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1); |
| 1599 | _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1600 | |
| 1601 | for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; |
| 1602 | i += IWL_EEPROM_ACCESS_DELAY) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1603 | r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1604 | if (r & CSR_EEPROM_REG_READ_VALID_MSK) |
| 1605 | break; |
| 1606 | udelay(IWL_EEPROM_ACCESS_DELAY); |
| 1607 | } |
| 1608 | |
| 1609 | if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { |
| 1610 | IWL_ERROR("Time out reading EEPROM[%d]", addr); |
| 1611 | rc = -ETIMEDOUT; |
| 1612 | goto done; |
| 1613 | } |
| 1614 | e[addr / 2] = le16_to_cpu(r >> 16); |
| 1615 | } |
| 1616 | rc = 0; |
| 1617 | |
| 1618 | done: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1619 | iwl4965_eeprom_release_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1620 | return rc; |
| 1621 | } |
| 1622 | |
| 1623 | /****************************************************************************** |
| 1624 | * |
| 1625 | * Misc. internal state and helper functions |
| 1626 | * |
| 1627 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1628 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1629 | |
| 1630 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1631 | * iwl4965_report_frame - dump frame to syslog during debug sessions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1632 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1633 | * You may hack this function to show different aspects of received frames, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1634 | * including selective frame dumps. |
| 1635 | * group100 parameter selects whether to show 1 out of 100 good frames. |
| 1636 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1637 | * TODO: This was originally written for 3945, need to audit for |
| 1638 | * proper operation with 4965. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1639 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1640 | void iwl4965_report_frame(struct iwl4965_priv *priv, |
| 1641 | struct iwl4965_rx_packet *pkt, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1642 | struct ieee80211_hdr *header, int group100) |
| 1643 | { |
| 1644 | u32 to_us; |
| 1645 | u32 print_summary = 0; |
| 1646 | u32 print_dump = 0; /* set to 1 to dump all frames' contents */ |
| 1647 | u32 hundred = 0; |
| 1648 | u32 dataframe = 0; |
| 1649 | u16 fc; |
| 1650 | u16 seq_ctl; |
| 1651 | u16 channel; |
| 1652 | u16 phy_flags; |
| 1653 | int rate_sym; |
| 1654 | u16 length; |
| 1655 | u16 status; |
| 1656 | u16 bcn_tmr; |
| 1657 | u32 tsf_low; |
| 1658 | u64 tsf; |
| 1659 | u8 rssi; |
| 1660 | u8 agc; |
| 1661 | u16 sig_avg; |
| 1662 | u16 noise_diff; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1663 | struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); |
| 1664 | struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); |
| 1665 | struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1666 | u8 *data = IWL_RX_DATA(pkt); |
| 1667 | |
| 1668 | /* MAC header */ |
| 1669 | fc = le16_to_cpu(header->frame_control); |
| 1670 | seq_ctl = le16_to_cpu(header->seq_ctrl); |
| 1671 | |
| 1672 | /* metadata */ |
| 1673 | channel = le16_to_cpu(rx_hdr->channel); |
| 1674 | phy_flags = le16_to_cpu(rx_hdr->phy_flags); |
| 1675 | rate_sym = rx_hdr->rate; |
| 1676 | length = le16_to_cpu(rx_hdr->len); |
| 1677 | |
| 1678 | /* end-of-frame status and timestamp */ |
| 1679 | status = le32_to_cpu(rx_end->status); |
| 1680 | bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp); |
| 1681 | tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff; |
| 1682 | tsf = le64_to_cpu(rx_end->timestamp); |
| 1683 | |
| 1684 | /* signal statistics */ |
| 1685 | rssi = rx_stats->rssi; |
| 1686 | agc = rx_stats->agc; |
| 1687 | sig_avg = le16_to_cpu(rx_stats->sig_avg); |
| 1688 | noise_diff = le16_to_cpu(rx_stats->noise_diff); |
| 1689 | |
| 1690 | to_us = !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1691 | |
| 1692 | /* if data frame is to us and all is good, |
| 1693 | * (optionally) print summary for only 1 out of every 100 */ |
| 1694 | if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) == |
| 1695 | (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) { |
| 1696 | dataframe = 1; |
| 1697 | if (!group100) |
| 1698 | print_summary = 1; /* print each frame */ |
| 1699 | else if (priv->framecnt_to_us < 100) { |
| 1700 | priv->framecnt_to_us++; |
| 1701 | print_summary = 0; |
| 1702 | } else { |
| 1703 | priv->framecnt_to_us = 0; |
| 1704 | print_summary = 1; |
| 1705 | hundred = 1; |
| 1706 | } |
| 1707 | } else { |
| 1708 | /* print summary for all other frames */ |
| 1709 | print_summary = 1; |
| 1710 | } |
| 1711 | |
| 1712 | if (print_summary) { |
| 1713 | char *title; |
| 1714 | u32 rate; |
| 1715 | |
| 1716 | if (hundred) |
| 1717 | title = "100Frames"; |
| 1718 | else if (fc & IEEE80211_FCTL_RETRY) |
| 1719 | title = "Retry"; |
| 1720 | else if (ieee80211_is_assoc_response(fc)) |
| 1721 | title = "AscRsp"; |
| 1722 | else if (ieee80211_is_reassoc_response(fc)) |
| 1723 | title = "RasRsp"; |
| 1724 | else if (ieee80211_is_probe_response(fc)) { |
| 1725 | title = "PrbRsp"; |
| 1726 | print_dump = 1; /* dump frame contents */ |
| 1727 | } else if (ieee80211_is_beacon(fc)) { |
| 1728 | title = "Beacon"; |
| 1729 | print_dump = 1; /* dump frame contents */ |
| 1730 | } else if (ieee80211_is_atim(fc)) |
| 1731 | title = "ATIM"; |
| 1732 | else if (ieee80211_is_auth(fc)) |
| 1733 | title = "Auth"; |
| 1734 | else if (ieee80211_is_deauth(fc)) |
| 1735 | title = "DeAuth"; |
| 1736 | else if (ieee80211_is_disassoc(fc)) |
| 1737 | title = "DisAssoc"; |
| 1738 | else |
| 1739 | title = "Frame"; |
| 1740 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1741 | rate = iwl4965_rate_index_from_plcp(rate_sym); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1742 | if (rate == -1) |
| 1743 | rate = 0; |
| 1744 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1745 | rate = iwl4965_rates[rate].ieee / 2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1746 | |
| 1747 | /* print frame summary. |
| 1748 | * MAC addresses show just the last byte (for brevity), |
| 1749 | * but you can hack it to show more, if you'd like to. */ |
| 1750 | if (dataframe) |
| 1751 | IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, " |
| 1752 | "len=%u, rssi=%d, chnl=%d, rate=%u, \n", |
| 1753 | title, fc, header->addr1[5], |
| 1754 | length, rssi, channel, rate); |
| 1755 | else { |
| 1756 | /* src/dst addresses assume managed mode */ |
| 1757 | IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, " |
| 1758 | "src=0x%02x, rssi=%u, tim=%lu usec, " |
| 1759 | "phy=0x%02x, chnl=%d\n", |
| 1760 | title, fc, header->addr1[5], |
| 1761 | header->addr3[5], rssi, |
| 1762 | tsf_low - priv->scan_start_tsf, |
| 1763 | phy_flags, channel); |
| 1764 | } |
| 1765 | } |
| 1766 | if (print_dump) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1767 | iwl4965_print_hex_dump(IWL_DL_RX, data, length); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1768 | } |
| 1769 | #endif |
| 1770 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1771 | static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1772 | { |
| 1773 | if (priv->hw_setting.shared_virt) |
| 1774 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1775 | sizeof(struct iwl4965_shared), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1776 | priv->hw_setting.shared_virt, |
| 1777 | priv->hw_setting.shared_phys); |
| 1778 | } |
| 1779 | |
| 1780 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1781 | * 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] | 1782 | * |
| 1783 | * return : set the bit for each supported rate insert in ie |
| 1784 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1785 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1786 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1787 | { |
| 1788 | u16 ret_rates = 0, bit; |
| 1789 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1790 | u8 *cnt = ie; |
| 1791 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1792 | |
| 1793 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1794 | if (bit & supported_rate) { |
| 1795 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1796 | rates[*cnt] = iwl4965_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1797 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1798 | (*cnt)++; |
| 1799 | (*left)--; |
| 1800 | if ((*left <= 0) || |
| 1801 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1802 | break; |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | return ret_rates; |
| 1807 | } |
| 1808 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1809 | #ifdef CONFIG_IWL4965_HT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1810 | void static iwl4965_set_ht_capab(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1811 | struct ieee80211_ht_capability *ht_cap, |
| 1812 | u8 use_wide_chan); |
| 1813 | #endif |
| 1814 | |
| 1815 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1816 | * 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] | 1817 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1818 | static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1819 | struct ieee80211_mgmt *frame, |
| 1820 | int left, int is_direct) |
| 1821 | { |
| 1822 | int len = 0; |
| 1823 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1824 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1825 | |
| 1826 | /* Make sure there is enough space for the probe request, |
| 1827 | * two mandatory IEs and the data */ |
| 1828 | left -= 24; |
| 1829 | if (left < 0) |
| 1830 | return 0; |
| 1831 | len += 24; |
| 1832 | |
| 1833 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1834 | memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1835 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1836 | memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1837 | frame->seq_ctrl = 0; |
| 1838 | |
| 1839 | /* fill in our indirect SSID IE */ |
| 1840 | /* ...next IE... */ |
| 1841 | |
| 1842 | left -= 2; |
| 1843 | if (left < 0) |
| 1844 | return 0; |
| 1845 | len += 2; |
| 1846 | pos = &(frame->u.probe_req.variable[0]); |
| 1847 | *pos++ = WLAN_EID_SSID; |
| 1848 | *pos++ = 0; |
| 1849 | |
| 1850 | /* fill in our direct SSID IE... */ |
| 1851 | if (is_direct) { |
| 1852 | /* ...next IE... */ |
| 1853 | left -= 2 + priv->essid_len; |
| 1854 | if (left < 0) |
| 1855 | return 0; |
| 1856 | /* ... fill it in... */ |
| 1857 | *pos++ = WLAN_EID_SSID; |
| 1858 | *pos++ = priv->essid_len; |
| 1859 | memcpy(pos, priv->essid, priv->essid_len); |
| 1860 | pos += priv->essid_len; |
| 1861 | len += 2 + priv->essid_len; |
| 1862 | } |
| 1863 | |
| 1864 | /* fill in supported rate */ |
| 1865 | /* ...next IE... */ |
| 1866 | left -= 2; |
| 1867 | if (left < 0) |
| 1868 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1869 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1870 | /* ... fill it in... */ |
| 1871 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1872 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1873 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1874 | /* exclude 60M rate */ |
| 1875 | active_rates = priv->rates_mask; |
| 1876 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1877 | |
| 1878 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1879 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1880 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1881 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1882 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1883 | active_rates &= ~ret_rates; |
| 1884 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1885 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1886 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1887 | active_rates &= ~ret_rates; |
| 1888 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1889 | len += 2 + *pos; |
| 1890 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1891 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1892 | goto fill_end; |
| 1893 | |
| 1894 | /* fill in supported extended rate */ |
| 1895 | /* ...next IE... */ |
| 1896 | left -= 2; |
| 1897 | if (left < 0) |
| 1898 | return 0; |
| 1899 | /* ... fill it in... */ |
| 1900 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1901 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1902 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1903 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1904 | if (*pos > 0) |
| 1905 | len += 2 + *pos; |
| 1906 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1907 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1908 | if (is_direct && priv->is_ht_enabled) { |
| 1909 | u8 use_wide_chan = 1; |
| 1910 | |
| 1911 | if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ) |
| 1912 | use_wide_chan = 0; |
| 1913 | pos += (*pos) + 1; |
| 1914 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 1915 | *pos++ = sizeof(struct ieee80211_ht_capability); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1916 | iwl4965_set_ht_capab(NULL, (struct ieee80211_ht_capability *)pos, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1917 | use_wide_chan); |
| 1918 | len += 2 + sizeof(struct ieee80211_ht_capability); |
| 1919 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1920 | #endif /*CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1921 | |
| 1922 | fill_end: |
| 1923 | return (u16)len; |
| 1924 | } |
| 1925 | |
| 1926 | /* |
| 1927 | * QoS support |
| 1928 | */ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1929 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1930 | static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv, |
| 1931 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1932 | { |
| 1933 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1934 | return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
| 1935 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1938 | static void iwl4965_reset_qos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1939 | { |
| 1940 | u16 cw_min = 15; |
| 1941 | u16 cw_max = 1023; |
| 1942 | u8 aifs = 2; |
| 1943 | u8 is_legacy = 0; |
| 1944 | unsigned long flags; |
| 1945 | int i; |
| 1946 | |
| 1947 | spin_lock_irqsave(&priv->lock, flags); |
| 1948 | priv->qos_data.qos_active = 0; |
| 1949 | |
| 1950 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { |
| 1951 | if (priv->qos_data.qos_enable) |
| 1952 | priv->qos_data.qos_active = 1; |
| 1953 | if (!(priv->active_rate & 0xfff0)) { |
| 1954 | cw_min = 31; |
| 1955 | is_legacy = 1; |
| 1956 | } |
| 1957 | } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1958 | if (priv->qos_data.qos_enable) |
| 1959 | priv->qos_data.qos_active = 1; |
| 1960 | } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 1961 | cw_min = 31; |
| 1962 | is_legacy = 1; |
| 1963 | } |
| 1964 | |
| 1965 | if (priv->qos_data.qos_active) |
| 1966 | aifs = 3; |
| 1967 | |
| 1968 | priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); |
| 1969 | priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); |
| 1970 | priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; |
| 1971 | priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; |
| 1972 | priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; |
| 1973 | |
| 1974 | if (priv->qos_data.qos_active) { |
| 1975 | i = 1; |
| 1976 | priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); |
| 1977 | priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); |
| 1978 | priv->qos_data.def_qos_parm.ac[i].aifsn = 7; |
| 1979 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 1980 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1981 | |
| 1982 | i = 2; |
| 1983 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1984 | cpu_to_le16((cw_min + 1) / 2 - 1); |
| 1985 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1986 | cpu_to_le16(cw_max); |
| 1987 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 1988 | if (is_legacy) |
| 1989 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1990 | cpu_to_le16(6016); |
| 1991 | else |
| 1992 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1993 | cpu_to_le16(3008); |
| 1994 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1995 | |
| 1996 | i = 3; |
| 1997 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1998 | cpu_to_le16((cw_min + 1) / 4 - 1); |
| 1999 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2000 | cpu_to_le16((cw_max + 1) / 2 - 1); |
| 2001 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 2002 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2003 | if (is_legacy) |
| 2004 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2005 | cpu_to_le16(3264); |
| 2006 | else |
| 2007 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2008 | cpu_to_le16(1504); |
| 2009 | } else { |
| 2010 | for (i = 1; i < 4; i++) { |
| 2011 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2012 | cpu_to_le16(cw_min); |
| 2013 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2014 | cpu_to_le16(cw_max); |
| 2015 | priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; |
| 2016 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 2017 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2018 | } |
| 2019 | } |
| 2020 | IWL_DEBUG_QOS("set QoS to default \n"); |
| 2021 | |
| 2022 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2023 | } |
| 2024 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2025 | static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2026 | { |
| 2027 | unsigned long flags; |
| 2028 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2029 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2030 | return; |
| 2031 | |
| 2032 | if (!priv->qos_data.qos_enable) |
| 2033 | return; |
| 2034 | |
| 2035 | spin_lock_irqsave(&priv->lock, flags); |
| 2036 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 2037 | |
| 2038 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 2039 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 2040 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2041 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2042 | if (priv->qos_data.qos_active) |
| 2043 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2044 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 2045 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2046 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2047 | if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht) |
| 2048 | 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] | 2049 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2050 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2051 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2052 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2053 | if (force || iwl4965_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2054 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 2055 | priv->qos_data.qos_active, |
| 2056 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2057 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2058 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2059 | &(priv->qos_data.def_qos_parm)); |
| 2060 | } |
| 2061 | } |
| 2062 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2063 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2064 | /* |
| 2065 | * Power management (not Tx power!) functions |
| 2066 | */ |
| 2067 | #define MSEC_TO_USEC 1024 |
| 2068 | |
| 2069 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 2070 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
| 2071 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 2072 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 2073 | __constant_cpu_to_le32(X1), \ |
| 2074 | __constant_cpu_to_le32(X2), \ |
| 2075 | __constant_cpu_to_le32(X3), \ |
| 2076 | __constant_cpu_to_le32(X4)} |
| 2077 | |
| 2078 | |
| 2079 | /* default power management (not Tx power) table values */ |
| 2080 | /* for tim 0-10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2081 | static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2082 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2083 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 2084 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 2085 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 2086 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 2087 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 2088 | }; |
| 2089 | |
| 2090 | /* for tim > 10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2091 | static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2092 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2093 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 2094 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 2095 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 2096 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 2097 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 2098 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 2099 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 2100 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 2101 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 2102 | }; |
| 2103 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2104 | int iwl4965_power_init_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2105 | { |
| 2106 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2107 | struct iwl4965_power_mgr *pow_data; |
| 2108 | int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2109 | u16 pci_pm; |
| 2110 | |
| 2111 | IWL_DEBUG_POWER("Initialize power \n"); |
| 2112 | |
| 2113 | pow_data = &(priv->power_data); |
| 2114 | |
| 2115 | memset(pow_data, 0, sizeof(*pow_data)); |
| 2116 | |
| 2117 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 2118 | pow_data->dtim_val = 0xffff; |
| 2119 | |
| 2120 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 2121 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 2122 | |
| 2123 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 2124 | if (rc != 0) |
| 2125 | return 0; |
| 2126 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2127 | struct iwl4965_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2128 | |
| 2129 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 2130 | |
| 2131 | for (i = 0; i < IWL_POWER_AC; i++) { |
| 2132 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 2133 | |
| 2134 | if (pci_pm & 0x1) |
| 2135 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 2136 | else |
| 2137 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 2138 | } |
| 2139 | } |
| 2140 | return rc; |
| 2141 | } |
| 2142 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2143 | static int iwl4965_update_power_cmd(struct iwl4965_priv *priv, |
| 2144 | struct iwl4965_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2145 | { |
| 2146 | int rc = 0, i; |
| 2147 | u8 skip; |
| 2148 | u32 max_sleep = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2149 | struct iwl4965_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2150 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2151 | struct iwl4965_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2152 | |
| 2153 | if (mode > IWL_POWER_INDEX_5) { |
| 2154 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 2155 | return -1; |
| 2156 | } |
| 2157 | pow_data = &(priv->power_data); |
| 2158 | |
| 2159 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 2160 | range = &pow_data->pwr_range_0[0]; |
| 2161 | else |
| 2162 | range = &pow_data->pwr_range_1[1]; |
| 2163 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2164 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2165 | |
| 2166 | #ifdef IWL_MAC80211_DISABLE |
| 2167 | if (priv->assoc_network != NULL) { |
| 2168 | unsigned long flags; |
| 2169 | |
| 2170 | period = priv->assoc_network->tim.tim_period; |
| 2171 | } |
| 2172 | #endif /*IWL_MAC80211_DISABLE */ |
| 2173 | skip = range[mode].no_dtim; |
| 2174 | |
| 2175 | if (period == 0) { |
| 2176 | period = 1; |
| 2177 | skip = 0; |
| 2178 | } |
| 2179 | |
| 2180 | if (skip == 0) { |
| 2181 | max_sleep = period; |
| 2182 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2183 | } else { |
| 2184 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 2185 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 2186 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2187 | } |
| 2188 | |
| 2189 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 2190 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 2191 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 2192 | } |
| 2193 | |
| 2194 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 2195 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 2196 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 2197 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 2198 | le32_to_cpu(cmd->sleep_interval[0]), |
| 2199 | le32_to_cpu(cmd->sleep_interval[1]), |
| 2200 | le32_to_cpu(cmd->sleep_interval[2]), |
| 2201 | le32_to_cpu(cmd->sleep_interval[3]), |
| 2202 | le32_to_cpu(cmd->sleep_interval[4])); |
| 2203 | |
| 2204 | return rc; |
| 2205 | } |
| 2206 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2207 | static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2208 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 2209 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2210 | int rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2211 | struct iwl4965_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2212 | |
| 2213 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2214 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2215 | * else user level */ |
| 2216 | switch (mode) { |
| 2217 | case IWL_POWER_BATTERY: |
| 2218 | final_mode = IWL_POWER_INDEX_3; |
| 2219 | break; |
| 2220 | case IWL_POWER_AC: |
| 2221 | final_mode = IWL_POWER_MODE_CAM; |
| 2222 | break; |
| 2223 | default: |
| 2224 | final_mode = mode; |
| 2225 | break; |
| 2226 | } |
| 2227 | |
| 2228 | cmd.keep_alive_beacons = 0; |
| 2229 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2230 | iwl4965_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2231 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2232 | rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2233 | |
| 2234 | if (final_mode == IWL_POWER_MODE_CAM) |
| 2235 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 2236 | else |
| 2237 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 2238 | |
| 2239 | return rc; |
| 2240 | } |
| 2241 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2242 | 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] | 2243 | { |
| 2244 | /* Filter incoming packets to determine if they are targeted toward |
| 2245 | * this network, discarding packets coming from ourselves */ |
| 2246 | switch (priv->iw_mode) { |
| 2247 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 2248 | /* packets from our adapter are dropped (echo) */ |
| 2249 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 2250 | return 0; |
| 2251 | /* {broad,multi}cast packets to our IBSS go through */ |
| 2252 | if (is_multicast_ether_addr(header->addr1)) |
| 2253 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 2254 | /* packets to our adapter go through */ |
| 2255 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2256 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 2257 | /* packets from our adapter are dropped (echo) */ |
| 2258 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 2259 | return 0; |
| 2260 | /* {broad,multi}cast packets to our BSS go through */ |
| 2261 | if (is_multicast_ether_addr(header->addr1)) |
| 2262 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 2263 | /* packets to our adapter go through */ |
| 2264 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2265 | } |
| 2266 | |
| 2267 | return 1; |
| 2268 | } |
| 2269 | |
| 2270 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2271 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2272 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2273 | { |
| 2274 | switch (status & TX_STATUS_MSK) { |
| 2275 | case TX_STATUS_SUCCESS: |
| 2276 | return "SUCCESS"; |
| 2277 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 2278 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 2279 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 2280 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 2281 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 2282 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 2283 | TX_STATUS_ENTRY(DEST_PS); |
| 2284 | TX_STATUS_ENTRY(ABORTED); |
| 2285 | TX_STATUS_ENTRY(BT_RETRY); |
| 2286 | TX_STATUS_ENTRY(STA_INVALID); |
| 2287 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 2288 | TX_STATUS_ENTRY(TID_DISABLE); |
| 2289 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 2290 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 2291 | TX_STATUS_ENTRY(TX_LOCKED); |
| 2292 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 2293 | } |
| 2294 | |
| 2295 | return "UNKNOWN"; |
| 2296 | } |
| 2297 | |
| 2298 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2299 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2300 | * |
| 2301 | * NOTE: priv->mutex is not required before calling this function |
| 2302 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2303 | static int iwl4965_scan_cancel(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2304 | { |
| 2305 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 2306 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2307 | return 0; |
| 2308 | } |
| 2309 | |
| 2310 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2311 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2312 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 2313 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2314 | queue_work(priv->workqueue, &priv->abort_scan); |
| 2315 | |
| 2316 | } else |
| 2317 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 2318 | |
| 2319 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2320 | } |
| 2321 | |
| 2322 | return 0; |
| 2323 | } |
| 2324 | |
| 2325 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2326 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2327 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 2328 | * |
| 2329 | * NOTE: priv->mutex must be held before calling this function |
| 2330 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2331 | 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] | 2332 | { |
| 2333 | unsigned long now = jiffies; |
| 2334 | int ret; |
| 2335 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2336 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2337 | if (ret && ms) { |
| 2338 | mutex_unlock(&priv->mutex); |
| 2339 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 2340 | test_bit(STATUS_SCANNING, &priv->status)) |
| 2341 | msleep(1); |
| 2342 | mutex_lock(&priv->mutex); |
| 2343 | |
| 2344 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2345 | } |
| 2346 | |
| 2347 | return ret; |
| 2348 | } |
| 2349 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2350 | static void iwl4965_sequence_reset(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2351 | { |
| 2352 | /* Reset ieee stats */ |
| 2353 | |
| 2354 | /* We don't reset the net_device_stats (ieee->stats) on |
| 2355 | * re-association */ |
| 2356 | |
| 2357 | priv->last_seq_num = -1; |
| 2358 | priv->last_frag_num = -1; |
| 2359 | priv->last_packet_time = 0; |
| 2360 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2361 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 2365 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 2366 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2367 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2368 | { |
| 2369 | u16 new_val = 0; |
| 2370 | u16 beacon_factor = 0; |
| 2371 | |
| 2372 | beacon_factor = |
| 2373 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 2374 | / MAX_UCODE_BEACON_INTERVAL; |
| 2375 | new_val = beacon_val / beacon_factor; |
| 2376 | |
| 2377 | return cpu_to_le16(new_val); |
| 2378 | } |
| 2379 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2380 | static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2381 | { |
| 2382 | u64 interval_tm_unit; |
| 2383 | u64 tsf, result; |
| 2384 | unsigned long flags; |
| 2385 | struct ieee80211_conf *conf = NULL; |
| 2386 | u16 beacon_int = 0; |
| 2387 | |
| 2388 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2389 | |
| 2390 | spin_lock_irqsave(&priv->lock, flags); |
| 2391 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1); |
| 2392 | priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0); |
| 2393 | |
| 2394 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 2395 | |
| 2396 | tsf = priv->timestamp1; |
| 2397 | tsf = ((tsf << 32) | priv->timestamp0); |
| 2398 | |
| 2399 | beacon_int = priv->beacon_int; |
| 2400 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2401 | |
| 2402 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 2403 | if (beacon_int == 0) { |
| 2404 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 2405 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 2406 | } else { |
| 2407 | priv->rxon_timing.beacon_interval = |
| 2408 | cpu_to_le16(beacon_int); |
| 2409 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2410 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2411 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2412 | } |
| 2413 | |
| 2414 | priv->rxon_timing.atim_window = 0; |
| 2415 | } else { |
| 2416 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2417 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2418 | /* TODO: we need to get atim_window from upper stack |
| 2419 | * for now we set to 0 */ |
| 2420 | priv->rxon_timing.atim_window = 0; |
| 2421 | } |
| 2422 | |
| 2423 | interval_tm_unit = |
| 2424 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 2425 | result = do_div(tsf, interval_tm_unit); |
| 2426 | priv->rxon_timing.beacon_init_val = |
| 2427 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 2428 | |
| 2429 | IWL_DEBUG_ASSOC |
| 2430 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 2431 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 2432 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 2433 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 2434 | } |
| 2435 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2436 | static int iwl4965_scan_initiate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2437 | { |
| 2438 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2439 | IWL_ERROR("APs don't scan.\n"); |
| 2440 | return 0; |
| 2441 | } |
| 2442 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2443 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2444 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 2445 | return -EIO; |
| 2446 | } |
| 2447 | |
| 2448 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2449 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 2450 | return -EAGAIN; |
| 2451 | } |
| 2452 | |
| 2453 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2454 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 2455 | "Queuing.\n"); |
| 2456 | return -EAGAIN; |
| 2457 | } |
| 2458 | |
| 2459 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 2460 | priv->scan_bands = 2; |
| 2461 | set_bit(STATUS_SCANNING, &priv->status); |
| 2462 | priv->scan_start = jiffies; |
| 2463 | priv->scan_pass_start = priv->scan_start; |
| 2464 | |
| 2465 | queue_work(priv->workqueue, &priv->request_scan); |
| 2466 | |
| 2467 | return 0; |
| 2468 | } |
| 2469 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2470 | 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] | 2471 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2472 | struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2473 | |
| 2474 | if (hw_decrypt) |
| 2475 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 2476 | else |
| 2477 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 2478 | |
| 2479 | return 0; |
| 2480 | } |
| 2481 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2482 | static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2483 | { |
| 2484 | if (phymode == MODE_IEEE80211A) { |
| 2485 | priv->staging_rxon.flags &= |
| 2486 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 2487 | | RXON_FLG_CCK_MSK); |
| 2488 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2489 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2490 | /* Copied from iwl4965_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2491 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2492 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2493 | else |
| 2494 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2495 | |
| 2496 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2497 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2498 | |
| 2499 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 2500 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 2501 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2506 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2507 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2508 | static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2509 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2510 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2511 | |
| 2512 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 2513 | |
| 2514 | switch (priv->iw_mode) { |
| 2515 | case IEEE80211_IF_TYPE_AP: |
| 2516 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 2517 | break; |
| 2518 | |
| 2519 | case IEEE80211_IF_TYPE_STA: |
| 2520 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 2521 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 2522 | break; |
| 2523 | |
| 2524 | case IEEE80211_IF_TYPE_IBSS: |
| 2525 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 2526 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2527 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 2528 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2529 | break; |
| 2530 | |
| 2531 | case IEEE80211_IF_TYPE_MNTR: |
| 2532 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 2533 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 2534 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2535 | break; |
| 2536 | } |
| 2537 | |
| 2538 | #if 0 |
| 2539 | /* TODO: Figure out when short_preamble would be set and cache from |
| 2540 | * that */ |
| 2541 | if (!hw_to_local(priv->hw)->short_preamble) |
| 2542 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2543 | else |
| 2544 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2545 | #endif |
| 2546 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2547 | ch_info = iwl4965_get_channel_info(priv, priv->phymode, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2548 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2549 | |
| 2550 | if (!ch_info) |
| 2551 | ch_info = &priv->channel_info[0]; |
| 2552 | |
| 2553 | /* |
| 2554 | * in some case A channels are all non IBSS |
| 2555 | * in this case force B/G channel |
| 2556 | */ |
| 2557 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 2558 | !(is_channel_ibss(ch_info))) |
| 2559 | ch_info = &priv->channel_info[0]; |
| 2560 | |
| 2561 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
| 2562 | if (is_channel_a_band(ch_info)) |
| 2563 | priv->phymode = MODE_IEEE80211A; |
| 2564 | else |
| 2565 | priv->phymode = MODE_IEEE80211G; |
| 2566 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2567 | iwl4965_set_flags_for_phymode(priv, priv->phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2568 | |
| 2569 | priv->staging_rxon.ofdm_basic_rates = |
| 2570 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2571 | priv->staging_rxon.cck_basic_rates = |
| 2572 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2573 | |
| 2574 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 2575 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 2576 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2577 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 2578 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 2579 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 2580 | iwl4965_set_rxon_chain(priv); |
| 2581 | } |
| 2582 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2583 | static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2584 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2585 | if (!iwl4965_is_ready_rf(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2586 | return -EAGAIN; |
| 2587 | |
| 2588 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2589 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2590 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2591 | ch_info = iwl4965_get_channel_info(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2592 | priv->phymode, |
| 2593 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2594 | |
| 2595 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 2596 | IWL_ERROR("channel %d not IBSS channel\n", |
| 2597 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2598 | return -EINVAL; |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | cancel_delayed_work(&priv->scan_check); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2603 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2604 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 2605 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2606 | return -EAGAIN; |
| 2607 | } |
| 2608 | |
| 2609 | priv->iw_mode = mode; |
| 2610 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2611 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2612 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2613 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2614 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2615 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2616 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2617 | |
| 2618 | return 0; |
| 2619 | } |
| 2620 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2621 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2622 | struct ieee80211_tx_control *ctl, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2623 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2624 | struct sk_buff *skb_frag, |
| 2625 | int last_frag) |
| 2626 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2627 | struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2628 | |
| 2629 | switch (keyinfo->alg) { |
| 2630 | case ALG_CCMP: |
| 2631 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2632 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
| 2633 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 2634 | break; |
| 2635 | |
| 2636 | case ALG_TKIP: |
| 2637 | #if 0 |
| 2638 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2639 | |
| 2640 | if (last_frag) |
| 2641 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2642 | 8); |
| 2643 | else |
| 2644 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2645 | #endif |
| 2646 | break; |
| 2647 | |
| 2648 | case ALG_WEP: |
| 2649 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
| 2650 | (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
| 2651 | |
| 2652 | if (keyinfo->keylen == 13) |
| 2653 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2654 | |
| 2655 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2656 | |
| 2657 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
| 2658 | "with key %d\n", ctl->key_idx); |
| 2659 | break; |
| 2660 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2661 | default: |
| 2662 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 2663 | break; |
| 2664 | } |
| 2665 | } |
| 2666 | |
| 2667 | /* |
| 2668 | * handle build REPLY_TX command notification. |
| 2669 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2670 | static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv, |
| 2671 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2672 | struct ieee80211_tx_control *ctrl, |
| 2673 | struct ieee80211_hdr *hdr, |
| 2674 | int is_unicast, u8 std_id) |
| 2675 | { |
| 2676 | __le16 *qc; |
| 2677 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2678 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 2679 | |
| 2680 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2681 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 2682 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 2683 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 2684 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2685 | if (ieee80211_is_probe_response(fc) && |
| 2686 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2687 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2688 | } else { |
| 2689 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2690 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2691 | } |
| 2692 | |
| 2693 | cmd->cmd.tx.sta_id = std_id; |
| 2694 | if (ieee80211_get_morefrag(hdr)) |
| 2695 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2696 | |
| 2697 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2698 | if (qc) { |
| 2699 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 2700 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 2701 | } else |
| 2702 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2703 | |
| 2704 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 2705 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2706 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 2707 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 2708 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2709 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2710 | } |
| 2711 | |
| 2712 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2713 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2714 | |
| 2715 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 2716 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 2717 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 2718 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2719 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2720 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2721 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2722 | } else |
| 2723 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
| 2724 | |
| 2725 | cmd->cmd.tx.driver_txop = 0; |
| 2726 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2727 | cmd->cmd.tx.next_frame_len = 0; |
| 2728 | } |
| 2729 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2730 | static int iwl4965_get_sta_id(struct iwl4965_priv *priv, |
| 2731 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2732 | { |
| 2733 | int sta_id; |
| 2734 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2735 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2736 | |
| 2737 | /* If this frame is broadcast or not data then use the broadcast |
| 2738 | * station id */ |
| 2739 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2740 | is_multicast_ether_addr(hdr->addr1)) |
| 2741 | return priv->hw_setting.bcast_sta_id; |
| 2742 | |
| 2743 | switch (priv->iw_mode) { |
| 2744 | |
| 2745 | /* If this frame is part of a BSS network (we're a station), then |
| 2746 | * we use the AP's station id */ |
| 2747 | case IEEE80211_IF_TYPE_STA: |
| 2748 | return IWL_AP_ID; |
| 2749 | |
| 2750 | /* If we are an AP, then find the station, or use BCAST */ |
| 2751 | case IEEE80211_IF_TYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2752 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2753 | if (sta_id != IWL_INVALID_STATION) |
| 2754 | return sta_id; |
| 2755 | return priv->hw_setting.bcast_sta_id; |
| 2756 | |
| 2757 | /* If this frame is part of a IBSS network, then we use the |
| 2758 | * target specific station id */ |
| 2759 | case IEEE80211_IF_TYPE_IBSS: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2760 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2761 | if (sta_id != IWL_INVALID_STATION) |
| 2762 | return sta_id; |
| 2763 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2764 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, 0, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2765 | |
| 2766 | if (sta_id != IWL_INVALID_STATION) |
| 2767 | return sta_id; |
| 2768 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2769 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2770 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2771 | print_mac(mac, hdr->addr1)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2772 | iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2773 | return priv->hw_setting.bcast_sta_id; |
| 2774 | |
| 2775 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2776 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2777 | return priv->hw_setting.bcast_sta_id; |
| 2778 | } |
| 2779 | } |
| 2780 | |
| 2781 | /* |
| 2782 | * start REPLY_TX command process |
| 2783 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2784 | static int iwl4965_tx_skb(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2785 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 2786 | { |
| 2787 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2788 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2789 | u32 *control_flags; |
| 2790 | int txq_id = ctl->queue; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2791 | struct iwl4965_tx_queue *txq = NULL; |
| 2792 | struct iwl4965_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2793 | dma_addr_t phys_addr; |
| 2794 | dma_addr_t txcmd_phys; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2795 | struct iwl4965_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2796 | u16 len, idx, len_org; |
| 2797 | u8 id, hdr_len, unicast; |
| 2798 | u8 sta_id; |
| 2799 | u16 seq_number = 0; |
| 2800 | u16 fc; |
| 2801 | __le16 *qc; |
| 2802 | u8 wait_write_ptr = 0; |
| 2803 | unsigned long flags; |
| 2804 | int rc; |
| 2805 | |
| 2806 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2807 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2808 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2809 | goto drop_unlock; |
| 2810 | } |
| 2811 | |
| 2812 | if (!priv->interface_id) { |
| 2813 | IWL_DEBUG_DROP("Dropping - !priv->interface_id\n"); |
| 2814 | goto drop_unlock; |
| 2815 | } |
| 2816 | |
| 2817 | if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) { |
| 2818 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 2819 | goto drop_unlock; |
| 2820 | } |
| 2821 | |
| 2822 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2823 | id = 0; |
| 2824 | |
| 2825 | fc = le16_to_cpu(hdr->frame_control); |
| 2826 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2827 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2828 | if (ieee80211_is_auth(fc)) |
| 2829 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 2830 | else if (ieee80211_is_assoc_request(fc)) |
| 2831 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 2832 | else if (ieee80211_is_reassoc_request(fc)) |
| 2833 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2834 | #endif |
| 2835 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2836 | if (!iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2837 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2838 | IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2839 | goto drop_unlock; |
| 2840 | } |
| 2841 | |
| 2842 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2843 | |
| 2844 | hdr_len = ieee80211_get_hdrlen(fc); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2845 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2846 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2847 | DECLARE_MAC_BUF(mac); |
| 2848 | |
| 2849 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 2850 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2851 | goto drop; |
| 2852 | } |
| 2853 | |
| 2854 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2855 | |
| 2856 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2857 | if (qc) { |
| 2858 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2859 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 2860 | IEEE80211_SCTL_SEQ; |
| 2861 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2862 | (hdr->seq_ctrl & |
| 2863 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2864 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2865 | #ifdef CONFIG_IWL4965_HT |
| 2866 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2867 | /* aggregation is on for this <sta,tid> */ |
| 2868 | if (ctl->flags & IEEE80211_TXCTL_HT_MPDU_AGG) |
| 2869 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2870 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 2871 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2872 | } |
| 2873 | txq = &priv->txq[txq_id]; |
| 2874 | q = &txq->q; |
| 2875 | |
| 2876 | spin_lock_irqsave(&priv->lock, flags); |
| 2877 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2878 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2879 | memset(tfd, 0, sizeof(*tfd)); |
| 2880 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2881 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2882 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2883 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2884 | txq->txb[q->write_ptr].skb[0] = skb; |
| 2885 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2886 | ctl, sizeof(struct ieee80211_tx_control)); |
| 2887 | out_cmd = &txq->cmd[idx]; |
| 2888 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2889 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
| 2890 | out_cmd->hdr.cmd = REPLY_TX; |
| 2891 | 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] | 2892 | INDEX_TO_SEQ(q->write_ptr))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2893 | /* copy frags header */ |
| 2894 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 2895 | |
| 2896 | /* hdr = (struct ieee80211_hdr *)out_cmd->cmd.tx.hdr; */ |
| 2897 | len = priv->hw_setting.tx_cmd_len + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2898 | sizeof(struct iwl4965_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2899 | |
| 2900 | len_org = len; |
| 2901 | len = (len + 3) & ~3; |
| 2902 | |
| 2903 | if (len_org != len) |
| 2904 | len_org = 1; |
| 2905 | else |
| 2906 | len_org = 0; |
| 2907 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2908 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx + |
| 2909 | offsetof(struct iwl4965_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2910 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2911 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2912 | |
| 2913 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2914 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2915 | |
| 2916 | /* 802.11 null functions have no payload... */ |
| 2917 | len = skb->len - hdr_len; |
| 2918 | if (len) { |
| 2919 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2920 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2921 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | if (len_org) |
| 2925 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 2926 | |
| 2927 | len = (u16)skb->len; |
| 2928 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 2929 | |
| 2930 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2931 | 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] | 2932 | |
| 2933 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2934 | 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] | 2935 | |
| 2936 | iwl4965_tx_cmd(priv, out_cmd, sta_id, txcmd_phys, |
| 2937 | hdr, hdr_len, ctl, NULL); |
| 2938 | |
| 2939 | if (!ieee80211_get_morefrag(hdr)) { |
| 2940 | txq->need_update = 1; |
| 2941 | if (qc) { |
| 2942 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2943 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 2944 | } |
| 2945 | } else { |
| 2946 | wait_write_ptr = 1; |
| 2947 | txq->need_update = 0; |
| 2948 | } |
| 2949 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2950 | iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2951 | sizeof(out_cmd->cmd.tx)); |
| 2952 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2953 | 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] | 2954 | ieee80211_get_hdrlen(fc)); |
| 2955 | |
| 2956 | iwl4965_tx_queue_update_wr_ptr(priv, txq, len); |
| 2957 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2958 | q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 2959 | rc = iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2960 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2961 | |
| 2962 | if (rc) |
| 2963 | return rc; |
| 2964 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2965 | if ((iwl4965_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2966 | && priv->mac80211_registered) { |
| 2967 | if (wait_write_ptr) { |
| 2968 | spin_lock_irqsave(&priv->lock, flags); |
| 2969 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2970 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2971 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2972 | } |
| 2973 | |
| 2974 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 2975 | } |
| 2976 | |
| 2977 | return 0; |
| 2978 | |
| 2979 | drop_unlock: |
| 2980 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2981 | drop: |
| 2982 | return -1; |
| 2983 | } |
| 2984 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2985 | static void iwl4965_set_rate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2986 | { |
| 2987 | const struct ieee80211_hw_mode *hw = NULL; |
| 2988 | struct ieee80211_rate *rate; |
| 2989 | int i; |
| 2990 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2991 | hw = iwl4965_get_hw_mode(priv, priv->phymode); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 2992 | if (!hw) { |
| 2993 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 2994 | return; |
| 2995 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2996 | |
| 2997 | priv->active_rate = 0; |
| 2998 | priv->active_rate_basic = 0; |
| 2999 | |
| 3000 | IWL_DEBUG_RATE("Setting rates for 802.11%c\n", |
| 3001 | hw->mode == MODE_IEEE80211A ? |
| 3002 | 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g')); |
| 3003 | |
| 3004 | for (i = 0; i < hw->num_rates; i++) { |
| 3005 | rate = &(hw->rates[i]); |
| 3006 | if ((rate->val < IWL_RATE_COUNT) && |
| 3007 | (rate->flags & IEEE80211_RATE_SUPPORTED)) { |
| 3008 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3009 | rate->val, iwl4965_rates[rate->val].plcp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | (rate->flags & IEEE80211_RATE_BASIC) ? |
| 3011 | "*" : ""); |
| 3012 | priv->active_rate |= (1 << rate->val); |
| 3013 | if (rate->flags & IEEE80211_RATE_BASIC) |
| 3014 | priv->active_rate_basic |= (1 << rate->val); |
| 3015 | } else |
| 3016 | IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3017 | rate->val, iwl4965_rates[rate->val].plcp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 3021 | priv->active_rate, priv->active_rate_basic); |
| 3022 | |
| 3023 | /* |
| 3024 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 3025 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 3026 | * OFDM |
| 3027 | */ |
| 3028 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 3029 | priv->staging_rxon.cck_basic_rates = |
| 3030 | ((priv->active_rate_basic & |
| 3031 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3032 | else |
| 3033 | priv->staging_rxon.cck_basic_rates = |
| 3034 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3035 | |
| 3036 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 3037 | priv->staging_rxon.ofdm_basic_rates = |
| 3038 | ((priv->active_rate_basic & |
| 3039 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 3040 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3041 | else |
| 3042 | priv->staging_rxon.ofdm_basic_rates = |
| 3043 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3044 | } |
| 3045 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3046 | 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] | 3047 | { |
| 3048 | unsigned long flags; |
| 3049 | |
| 3050 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 3051 | return; |
| 3052 | |
| 3053 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 3054 | disable_radio ? "OFF" : "ON"); |
| 3055 | |
| 3056 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3057 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3058 | /* FIXME: This is a workaround for AP */ |
| 3059 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 3060 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3061 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3062 | CSR_UCODE_SW_BIT_RFKILL); |
| 3063 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3064 | iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3065 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3066 | } |
| 3067 | return; |
| 3068 | } |
| 3069 | |
| 3070 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3071 | 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] | 3072 | |
| 3073 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3074 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3075 | |
| 3076 | /* wake up ucode */ |
| 3077 | msleep(10); |
| 3078 | |
| 3079 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3080 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 3081 | if (!iwl4965_grab_nic_access(priv)) |
| 3082 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3083 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3084 | |
| 3085 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 3086 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3087 | "disabled by HW switch\n"); |
| 3088 | return; |
| 3089 | } |
| 3090 | |
| 3091 | queue_work(priv->workqueue, &priv->restart); |
| 3092 | return; |
| 3093 | } |
| 3094 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3095 | 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] | 3096 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 3097 | { |
| 3098 | u16 fc = |
| 3099 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 3100 | |
| 3101 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 3102 | return; |
| 3103 | |
| 3104 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 3105 | return; |
| 3106 | |
| 3107 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 3108 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 3109 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 3110 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3111 | RX_RES_STATUS_BAD_ICV_MIC) |
| 3112 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 3113 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 3114 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 3115 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3116 | RX_RES_STATUS_DECRYPT_OK) { |
| 3117 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 3118 | stats->flag |= RX_FLAG_DECRYPTED; |
| 3119 | } |
| 3120 | break; |
| 3121 | |
| 3122 | default: |
| 3123 | break; |
| 3124 | } |
| 3125 | } |
| 3126 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3127 | void iwl4965_handle_data_packet_monitor(struct iwl4965_priv *priv, |
| 3128 | struct iwl4965_rx_mem_buffer *rxb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3129 | void *data, short len, |
| 3130 | struct ieee80211_rx_status *stats, |
| 3131 | u16 phy_flags) |
| 3132 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3133 | struct iwl4965_rt_rx_hdr *iwl4965_rt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3134 | |
| 3135 | /* First cache any information we need before we overwrite |
| 3136 | * the information provided in the skb from the hardware */ |
| 3137 | s8 signal = stats->ssi; |
| 3138 | s8 noise = 0; |
| 3139 | int rate = stats->rate; |
| 3140 | u64 tsf = stats->mactime; |
| 3141 | __le16 phy_flags_hw = cpu_to_le16(phy_flags); |
| 3142 | |
| 3143 | /* We received data from the HW, so stop the watchdog */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3144 | if (len > IWL_RX_BUF_SIZE - sizeof(*iwl4965_rt)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3145 | IWL_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 3146 | return; |
| 3147 | } |
| 3148 | |
| 3149 | /* copy the frame data to write after where the radiotap header goes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3150 | iwl4965_rt = (void *)rxb->skb->data; |
| 3151 | memmove(iwl4965_rt->payload, data, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3152 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3153 | iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 3154 | iwl4965_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3155 | |
| 3156 | /* total header + data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3157 | iwl4965_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl4965_rt)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3158 | |
| 3159 | /* Set the size of the skb to the size of the frame */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3160 | skb_put(rxb->skb, sizeof(*iwl4965_rt) + len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3161 | |
| 3162 | /* Big bitfield of all the fields we provide in radiotap */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3163 | iwl4965_rt->rt_hdr.it_present = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3164 | cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) | |
| 3165 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
| 3166 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 3167 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 3168 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 3169 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 3170 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 3171 | |
| 3172 | /* Zero the flags, we'll add to them as we go */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3173 | iwl4965_rt->rt_flags = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3174 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3175 | iwl4965_rt->rt_tsf = cpu_to_le64(tsf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3176 | |
| 3177 | /* Convert to dBm */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3178 | iwl4965_rt->rt_dbmsignal = signal; |
| 3179 | iwl4965_rt->rt_dbmnoise = noise; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3180 | |
| 3181 | /* Convert the channel frequency and set the flags */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3182 | iwl4965_rt->rt_channelMHz = cpu_to_le16(stats->freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3183 | if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3184 | iwl4965_rt->rt_chbitmask = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3185 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 3186 | else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3187 | iwl4965_rt->rt_chbitmask = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3188 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 3189 | else /* 802.11g */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3190 | iwl4965_rt->rt_chbitmask = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3191 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ)); |
| 3192 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3193 | rate = iwl4965_rate_index_from_plcp(rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3194 | if (rate == -1) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3195 | iwl4965_rt->rt_rate = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3196 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3197 | iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3198 | |
| 3199 | /* antenna number */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3200 | iwl4965_rt->rt_antenna = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3201 | le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4; |
| 3202 | |
| 3203 | /* set the preamble flag if we have it */ |
| 3204 | if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3205 | iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3206 | |
| 3207 | IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 3208 | |
| 3209 | stats->flag |= RX_FLAG_RADIOTAP; |
| 3210 | ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); |
| 3211 | rxb->skb = NULL; |
| 3212 | } |
| 3213 | |
| 3214 | |
| 3215 | #define IWL_PACKET_RETRY_TIME HZ |
| 3216 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3217 | 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] | 3218 | { |
| 3219 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 3220 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 3221 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 3222 | u16 *last_seq, *last_frag; |
| 3223 | unsigned long *last_time; |
| 3224 | |
| 3225 | switch (priv->iw_mode) { |
| 3226 | case IEEE80211_IF_TYPE_IBSS:{ |
| 3227 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3228 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3229 | u8 *mac = header->addr2; |
| 3230 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 3231 | |
| 3232 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3233 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3234 | if (!compare_ether_addr(entry->mac, mac)) |
| 3235 | break; |
| 3236 | } |
| 3237 | if (p == &priv->ibss_mac_hash[index]) { |
| 3238 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 3239 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3240 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3241 | return 0; |
| 3242 | } |
| 3243 | memcpy(entry->mac, mac, ETH_ALEN); |
| 3244 | entry->seq_num = seq; |
| 3245 | entry->frag_num = frag; |
| 3246 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3247 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3248 | return 0; |
| 3249 | } |
| 3250 | last_seq = &entry->seq_num; |
| 3251 | last_frag = &entry->frag_num; |
| 3252 | last_time = &entry->packet_time; |
| 3253 | break; |
| 3254 | } |
| 3255 | case IEEE80211_IF_TYPE_STA: |
| 3256 | last_seq = &priv->last_seq_num; |
| 3257 | last_frag = &priv->last_frag_num; |
| 3258 | last_time = &priv->last_packet_time; |
| 3259 | break; |
| 3260 | default: |
| 3261 | return 0; |
| 3262 | } |
| 3263 | if ((*last_seq == seq) && |
| 3264 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 3265 | if (*last_frag == frag) |
| 3266 | goto drop; |
| 3267 | if (*last_frag + 1 != frag) |
| 3268 | /* out-of-order fragment */ |
| 3269 | goto drop; |
| 3270 | } else |
| 3271 | *last_seq = seq; |
| 3272 | |
| 3273 | *last_frag = frag; |
| 3274 | *last_time = jiffies; |
| 3275 | return 0; |
| 3276 | |
| 3277 | drop: |
| 3278 | return 1; |
| 3279 | } |
| 3280 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3281 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3282 | |
| 3283 | #include "iwl-spectrum.h" |
| 3284 | |
| 3285 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 3286 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 3287 | #define TIME_UNIT 1024 |
| 3288 | |
| 3289 | /* |
| 3290 | * extended beacon time format |
| 3291 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 3292 | * the high 1 byte is the beacon counts |
| 3293 | * the lower 3 bytes is the time in usec within one beacon interval |
| 3294 | */ |
| 3295 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3296 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | { |
| 3298 | u32 quot; |
| 3299 | u32 rem; |
| 3300 | u32 interval = beacon_interval * 1024; |
| 3301 | |
| 3302 | if (!interval || !usec) |
| 3303 | return 0; |
| 3304 | |
| 3305 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 3306 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 3307 | |
| 3308 | return (quot << 24) + rem; |
| 3309 | } |
| 3310 | |
| 3311 | /* base is usually what we get from ucode with each received frame, |
| 3312 | * the same as HW timer counter counting down |
| 3313 | */ |
| 3314 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3315 | 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] | 3316 | { |
| 3317 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 3318 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 3319 | u32 interval = beacon_interval * TIME_UNIT; |
| 3320 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 3321 | (addon & BEACON_TIME_MASK_HIGH); |
| 3322 | |
| 3323 | if (base_low > addon_low) |
| 3324 | res += base_low - addon_low; |
| 3325 | else if (base_low < addon_low) { |
| 3326 | res += interval + base_low - addon_low; |
| 3327 | res += (1 << 24); |
| 3328 | } else |
| 3329 | res += (1 << 24); |
| 3330 | |
| 3331 | return cpu_to_le32(res); |
| 3332 | } |
| 3333 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3334 | static int iwl4965_get_measurement(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3335 | struct ieee80211_measurement_params *params, |
| 3336 | u8 type) |
| 3337 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3338 | struct iwl4965_spectrum_cmd spectrum; |
| 3339 | struct iwl4965_rx_packet *res; |
| 3340 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3341 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 3342 | .data = (void *)&spectrum, |
| 3343 | .meta.flags = CMD_WANT_SKB, |
| 3344 | }; |
| 3345 | u32 add_time = le64_to_cpu(params->start_time); |
| 3346 | int rc; |
| 3347 | int spectrum_resp_status; |
| 3348 | int duration = le16_to_cpu(params->duration); |
| 3349 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3350 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3351 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3352 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3353 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 3354 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3355 | |
| 3356 | memset(&spectrum, 0, sizeof(spectrum)); |
| 3357 | |
| 3358 | spectrum.channel_count = cpu_to_le16(1); |
| 3359 | spectrum.flags = |
| 3360 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 3361 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 3362 | cmd.len = sizeof(spectrum); |
| 3363 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 3364 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3365 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3366 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3367 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3368 | add_time, |
| 3369 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3370 | else |
| 3371 | spectrum.start_time = 0; |
| 3372 | |
| 3373 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 3374 | spectrum.channels[0].channel = params->channel; |
| 3375 | spectrum.channels[0].type = type; |
| 3376 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 3377 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 3378 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 3379 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3380 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3381 | if (rc) |
| 3382 | return rc; |
| 3383 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3384 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3385 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 3386 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 3387 | rc = -EIO; |
| 3388 | } |
| 3389 | |
| 3390 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 3391 | switch (spectrum_resp_status) { |
| 3392 | case 0: /* Command will be handled */ |
| 3393 | if (res->u.spectrum.id != 0xff) { |
| 3394 | IWL_DEBUG_INFO |
| 3395 | ("Replaced existing measurement: %d\n", |
| 3396 | res->u.spectrum.id); |
| 3397 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 3398 | } |
| 3399 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 3400 | rc = 0; |
| 3401 | break; |
| 3402 | |
| 3403 | case 1: /* Command will not be handled */ |
| 3404 | rc = -EAGAIN; |
| 3405 | break; |
| 3406 | } |
| 3407 | |
| 3408 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 3409 | |
| 3410 | return rc; |
| 3411 | } |
| 3412 | #endif |
| 3413 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3414 | static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv, |
| 3415 | struct iwl4965_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3416 | { |
| 3417 | |
| 3418 | tx_sta->status.ack_signal = 0; |
| 3419 | tx_sta->status.excessive_retries = 0; |
| 3420 | tx_sta->status.queue_length = 0; |
| 3421 | tx_sta->status.queue_number = 0; |
| 3422 | |
| 3423 | if (in_interrupt()) |
| 3424 | ieee80211_tx_status_irqsafe(priv->hw, |
| 3425 | tx_sta->skb[0], &(tx_sta->status)); |
| 3426 | else |
| 3427 | ieee80211_tx_status(priv->hw, |
| 3428 | tx_sta->skb[0], &(tx_sta->status)); |
| 3429 | |
| 3430 | tx_sta->skb[0] = NULL; |
| 3431 | } |
| 3432 | |
| 3433 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3434 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries no more used by NIC. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3435 | * |
| 3436 | * When FW advances 'R' index, all entries between old and |
| 3437 | * new 'R' index need to be reclaimed. As result, some free space |
| 3438 | * forms. If there is enough free space (> low mark), wake Tx queue. |
| 3439 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3440 | 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] | 3441 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3442 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
| 3443 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3444 | int nfreed = 0; |
| 3445 | |
| 3446 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 3447 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 3448 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3449 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3450 | return 0; |
| 3451 | } |
| 3452 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3453 | for (index = iwl4965_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3454 | q->read_ptr != index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3455 | 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] | 3456 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3457 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3458 | &(txq->txb[txq->q.read_ptr])); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3459 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3460 | } else if (nfreed > 1) { |
| 3461 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3462 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3463 | queue_work(priv->workqueue, &priv->restart); |
| 3464 | } |
| 3465 | nfreed++; |
| 3466 | } |
| 3467 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3468 | if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3469 | (txq_id != IWL_CMD_QUEUE_NUM) && |
| 3470 | priv->mac80211_registered) |
| 3471 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3472 | |
| 3473 | |
| 3474 | return nfreed; |
| 3475 | } |
| 3476 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3477 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3478 | { |
| 3479 | status &= TX_STATUS_MSK; |
| 3480 | return (status == TX_STATUS_SUCCESS) |
| 3481 | || (status == TX_STATUS_DIRECT_DONE); |
| 3482 | } |
| 3483 | |
| 3484 | /****************************************************************************** |
| 3485 | * |
| 3486 | * Generic RX handler implementations |
| 3487 | * |
| 3488 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3489 | #ifdef CONFIG_IWL4965_HT |
| 3490 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3491 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3492 | static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3493 | struct ieee80211_hdr *hdr) |
| 3494 | { |
| 3495 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 3496 | return IWL_AP_ID; |
| 3497 | else { |
| 3498 | u8 *da = ieee80211_get_DA(hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3499 | return iwl4965_hw_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3500 | } |
| 3501 | } |
| 3502 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3503 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
| 3504 | struct iwl4965_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3505 | { |
| 3506 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 3507 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 3508 | txb[idx].skb[0]->data; |
| 3509 | return NULL; |
| 3510 | } |
| 3511 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3512 | 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] | 3513 | { |
| 3514 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 3515 | tx_resp->frame_count); |
| 3516 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 3517 | |
| 3518 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3519 | static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv, |
| 3520 | struct iwl4965_ht_agg *agg, |
| 3521 | struct iwl4965_tx_resp *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3522 | u16 start_idx) |
| 3523 | { |
| 3524 | u32 status; |
| 3525 | __le32 *frame_status = &tx_resp->status; |
| 3526 | struct ieee80211_tx_status *tx_status = NULL; |
| 3527 | struct ieee80211_hdr *hdr = NULL; |
| 3528 | int i, sh; |
| 3529 | int txq_id, idx; |
| 3530 | u16 seq; |
| 3531 | |
| 3532 | if (agg->wait_for_ba) |
| 3533 | IWL_DEBUG_TX_REPLY("got tx repsons w/o back\n"); |
| 3534 | |
| 3535 | agg->frame_count = tx_resp->frame_count; |
| 3536 | agg->start_idx = start_idx; |
| 3537 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3538 | agg->bitmap0 = agg->bitmap1 = 0; |
| 3539 | |
| 3540 | if (agg->frame_count == 1) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3541 | struct iwl4965_tx_queue *txq ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3542 | status = le32_to_cpu(frame_status[0]); |
| 3543 | |
| 3544 | txq_id = agg->txq_id; |
| 3545 | txq = &priv->txq[txq_id]; |
| 3546 | /* FIXME: code repetition */ |
| 3547 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d \n", |
| 3548 | agg->frame_count, agg->start_idx); |
| 3549 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3550 | tx_status = &(priv->txq[txq_id].txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3551 | tx_status->retry_count = tx_resp->failure_frame; |
| 3552 | tx_status->queue_number = status & 0xff; |
| 3553 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3554 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3555 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3556 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3557 | IEEE80211_TX_STATUS_ACK : 0; |
| 3558 | tx_status->control.tx_rate = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3559 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3560 | /* FIXME: code repetition end */ |
| 3561 | |
| 3562 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 3563 | status & 0xff, tx_resp->failure_frame); |
| 3564 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3565 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3566 | |
| 3567 | agg->wait_for_ba = 0; |
| 3568 | } else { |
| 3569 | u64 bitmap = 0; |
| 3570 | int start = agg->start_idx; |
| 3571 | |
| 3572 | for (i = 0; i < agg->frame_count; i++) { |
| 3573 | u16 sc; |
| 3574 | status = le32_to_cpu(frame_status[i]); |
| 3575 | seq = status >> 16; |
| 3576 | idx = SEQ_TO_INDEX(seq); |
| 3577 | txq_id = SEQ_TO_QUEUE(seq); |
| 3578 | |
| 3579 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 3580 | AGG_TX_STATE_ABORT_MSK)) |
| 3581 | continue; |
| 3582 | |
| 3583 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 3584 | agg->frame_count, txq_id, idx); |
| 3585 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3586 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3587 | |
| 3588 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 3589 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 3590 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 3591 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 3592 | idx, SEQ_TO_SN(sc), |
| 3593 | hdr->seq_ctrl); |
| 3594 | return -1; |
| 3595 | } |
| 3596 | |
| 3597 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 3598 | i, idx, SEQ_TO_SN(sc)); |
| 3599 | |
| 3600 | sh = idx - start; |
| 3601 | if (sh > 64) { |
| 3602 | sh = (start - idx) + 0xff; |
| 3603 | bitmap = bitmap << sh; |
| 3604 | sh = 0; |
| 3605 | start = idx; |
| 3606 | } else if (sh < -64) |
| 3607 | sh = 0xff - (start - idx); |
| 3608 | else if (sh < 0) { |
| 3609 | sh = start - idx; |
| 3610 | start = idx; |
| 3611 | bitmap = bitmap << sh; |
| 3612 | sh = 0; |
| 3613 | } |
| 3614 | bitmap |= (1 << sh); |
| 3615 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 3616 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 3617 | } |
| 3618 | |
| 3619 | agg->bitmap0 = bitmap & 0xFFFFFFFF; |
| 3620 | agg->bitmap1 = bitmap >> 32; |
| 3621 | agg->start_idx = start; |
| 3622 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3623 | IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%x\n", |
| 3624 | agg->frame_count, agg->start_idx, |
| 3625 | agg->bitmap0); |
| 3626 | |
| 3627 | if (bitmap) |
| 3628 | agg->wait_for_ba = 1; |
| 3629 | } |
| 3630 | return 0; |
| 3631 | } |
| 3632 | #endif |
| 3633 | #endif |
| 3634 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3635 | static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv, |
| 3636 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3637 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3638 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3639 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3640 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3641 | int index = SEQ_TO_INDEX(sequence); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3642 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3643 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3644 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3645 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3646 | #ifdef CONFIG_IWL4965_HT |
| 3647 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3648 | int tid, sta_id; |
| 3649 | #endif |
| 3650 | #endif |
| 3651 | |
| 3652 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 3653 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 3654 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3655 | index, txq->q.n_bd, txq->q.write_ptr, |
| 3656 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3657 | return; |
| 3658 | } |
| 3659 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3660 | #ifdef CONFIG_IWL4965_HT |
| 3661 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3662 | if (txq->sched_retry) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3663 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3664 | struct ieee80211_hdr *hdr = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3665 | iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 3666 | struct iwl4965_ht_agg *agg = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3667 | __le16 *qc = ieee80211_get_qos_ctrl(hdr); |
| 3668 | |
| 3669 | if (qc == NULL) { |
| 3670 | IWL_ERROR("BUG_ON qc is null!!!!\n"); |
| 3671 | return; |
| 3672 | } |
| 3673 | |
| 3674 | tid = le16_to_cpu(*qc) & 0xf; |
| 3675 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3676 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3677 | if (unlikely(sta_id == IWL_INVALID_STATION)) { |
| 3678 | IWL_ERROR("Station not known for\n"); |
| 3679 | return; |
| 3680 | } |
| 3681 | |
| 3682 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 3683 | |
| 3684 | iwl4965_tx_status_reply_tx(priv, agg, tx_resp, index); |
| 3685 | |
| 3686 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3687 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3688 | /* TODO: send BAR */ |
| 3689 | } |
| 3690 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3691 | if ((txq->q.read_ptr != (scd_ssn & 0xff))) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3692 | index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3693 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 3694 | "%d index %d\n", scd_ssn , index); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3695 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3696 | } |
| 3697 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3698 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 3699 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3700 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3701 | |
| 3702 | tx_status->retry_count = tx_resp->failure_frame; |
| 3703 | tx_status->queue_number = status; |
| 3704 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3705 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3706 | |
| 3707 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3708 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3709 | |
| 3710 | tx_status->control.tx_rate = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3711 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3712 | |
| 3713 | 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] | 3714 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3715 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 3716 | tx_resp->failure_frame); |
| 3717 | |
| 3718 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
| 3719 | if (index != -1) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3720 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3721 | #ifdef CONFIG_IWL4965_HT |
| 3722 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3723 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3724 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 3725 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3726 | |
| 3727 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 3728 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 3729 | } |
| 3730 | |
| 3731 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3732 | static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv, |
| 3733 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3734 | { |
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_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3737 | struct delayed_work *pwork; |
| 3738 | |
| 3739 | palive = &pkt->u.alive_frame; |
| 3740 | |
| 3741 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 3742 | "0x%01X 0x%01X\n", |
| 3743 | palive->is_valid, palive->ver_type, |
| 3744 | palive->ver_subtype); |
| 3745 | |
| 3746 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 3747 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 3748 | memcpy(&priv->card_alive_init, |
| 3749 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3750 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3751 | pwork = &priv->init_alive_start; |
| 3752 | } else { |
| 3753 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3754 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3755 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3756 | pwork = &priv->alive_start; |
| 3757 | } |
| 3758 | |
| 3759 | /* We delay the ALIVE response by 5ms to |
| 3760 | * give the HW RF Kill time to activate... */ |
| 3761 | if (palive->is_valid == UCODE_VALID_OK) |
| 3762 | queue_delayed_work(priv->workqueue, pwork, |
| 3763 | msecs_to_jiffies(5)); |
| 3764 | else |
| 3765 | IWL_WARNING("uCode did not respond OK.\n"); |
| 3766 | } |
| 3767 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3768 | static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv, |
| 3769 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3770 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3771 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3772 | |
| 3773 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 3774 | return; |
| 3775 | } |
| 3776 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3777 | static void iwl4965_rx_reply_error(struct iwl4965_priv *priv, |
| 3778 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3779 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3780 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3781 | |
| 3782 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 3783 | "seq 0x%04X ser 0x%08X\n", |
| 3784 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 3785 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 3786 | pkt->u.err_resp.cmd_id, |
| 3787 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 3788 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 3789 | } |
| 3790 | |
| 3791 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 3792 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3793 | 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] | 3794 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3795 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3796 | struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 3797 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3798 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 3799 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 3800 | rxon->channel = csa->channel; |
| 3801 | priv->staging_rxon.channel = csa->channel; |
| 3802 | } |
| 3803 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3804 | static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv, |
| 3805 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3806 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3807 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3808 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3809 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3810 | |
| 3811 | if (!report->state) { |
| 3812 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 3813 | "Spectrum Measure Notification: Start\n"); |
| 3814 | return; |
| 3815 | } |
| 3816 | |
| 3817 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 3818 | priv->measurement_status |= MEASUREMENT_READY; |
| 3819 | #endif |
| 3820 | } |
| 3821 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3822 | static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv, |
| 3823 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3824 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3825 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3826 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3827 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3828 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 3829 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 3830 | #endif |
| 3831 | } |
| 3832 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3833 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv, |
| 3834 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3835 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3836 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3837 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 3838 | "notification for %s:\n", |
| 3839 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3840 | 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] | 3841 | } |
| 3842 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3843 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3844 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3845 | struct iwl4965_priv *priv = |
| 3846 | container_of(work, struct iwl4965_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3847 | struct sk_buff *beacon; |
| 3848 | |
| 3849 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ |
| 3850 | beacon = ieee80211_beacon_get(priv->hw, priv->interface_id, NULL); |
| 3851 | |
| 3852 | if (!beacon) { |
| 3853 | IWL_ERROR("update beacon failed\n"); |
| 3854 | return; |
| 3855 | } |
| 3856 | |
| 3857 | mutex_lock(&priv->mutex); |
| 3858 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 3859 | if (priv->ibss_beacon) |
| 3860 | dev_kfree_skb(priv->ibss_beacon); |
| 3861 | |
| 3862 | priv->ibss_beacon = beacon; |
| 3863 | mutex_unlock(&priv->mutex); |
| 3864 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3865 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3866 | } |
| 3867 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3868 | static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv, |
| 3869 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3870 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3871 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3872 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3873 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 3874 | 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] | 3875 | |
| 3876 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 3877 | "tsf %d %d rate %d\n", |
| 3878 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 3879 | beacon->beacon_notify_hdr.failure_frame, |
| 3880 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3881 | le32_to_cpu(beacon->high_tsf), |
| 3882 | le32_to_cpu(beacon->low_tsf), rate); |
| 3883 | #endif |
| 3884 | |
| 3885 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3886 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 3887 | queue_work(priv->workqueue, &priv->beacon_update); |
| 3888 | } |
| 3889 | |
| 3890 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3891 | static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv, |
| 3892 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3893 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3894 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3895 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3896 | struct iwl4965_scanreq_notification *notif = |
| 3897 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3898 | |
| 3899 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 3900 | #endif |
| 3901 | } |
| 3902 | |
| 3903 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3904 | static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv, |
| 3905 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3906 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3907 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3908 | struct iwl4965_scanstart_notification *notif = |
| 3909 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3910 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 3911 | IWL_DEBUG_SCAN("Scan start: " |
| 3912 | "%d [802.11%s] " |
| 3913 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 3914 | notif->channel, |
| 3915 | notif->band ? "bg" : "a", |
| 3916 | notif->tsf_high, |
| 3917 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 3918 | } |
| 3919 | |
| 3920 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3921 | static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv, |
| 3922 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3923 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3924 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3925 | struct iwl4965_scanresults_notification *notif = |
| 3926 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3927 | |
| 3928 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 3929 | "%d [802.11%s] " |
| 3930 | "(TSF: 0x%08X:%08X) - %d " |
| 3931 | "elapsed=%lu usec (%dms since last)\n", |
| 3932 | notif->channel, |
| 3933 | notif->band ? "bg" : "a", |
| 3934 | le32_to_cpu(notif->tsf_high), |
| 3935 | le32_to_cpu(notif->tsf_low), |
| 3936 | le32_to_cpu(notif->statistics[0]), |
| 3937 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 3938 | jiffies_to_msecs(elapsed_jiffies |
| 3939 | (priv->last_scan_jiffies, jiffies))); |
| 3940 | |
| 3941 | priv->last_scan_jiffies = jiffies; |
| 3942 | } |
| 3943 | |
| 3944 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3945 | static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv, |
| 3946 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3947 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3948 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3949 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3950 | |
| 3951 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 3952 | scan_notif->scanned_channels, |
| 3953 | scan_notif->tsf_low, |
| 3954 | scan_notif->tsf_high, scan_notif->status); |
| 3955 | |
| 3956 | /* The HW is no longer scanning */ |
| 3957 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3958 | |
| 3959 | /* The scan completion notification came in, so kill that timer... */ |
| 3960 | cancel_delayed_work(&priv->scan_check); |
| 3961 | |
| 3962 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 3963 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 3964 | jiffies_to_msecs(elapsed_jiffies |
| 3965 | (priv->scan_pass_start, jiffies))); |
| 3966 | |
| 3967 | /* Remove this scanned band from the list |
| 3968 | * of pending bands to scan */ |
| 3969 | priv->scan_bands--; |
| 3970 | |
| 3971 | /* If a request to abort was given, or the scan did not succeed |
| 3972 | * then we reset the scan state machine and terminate, |
| 3973 | * re-queuing another scan if one has been requested */ |
| 3974 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3975 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 3976 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 3977 | } else { |
| 3978 | /* If there are more bands on this scan pass reschedule */ |
| 3979 | if (priv->scan_bands > 0) |
| 3980 | goto reschedule; |
| 3981 | } |
| 3982 | |
| 3983 | priv->last_scan_jiffies = jiffies; |
| 3984 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 3985 | |
| 3986 | clear_bit(STATUS_SCANNING, &priv->status); |
| 3987 | |
| 3988 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 3989 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 3990 | |
| 3991 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3992 | |
| 3993 | return; |
| 3994 | |
| 3995 | reschedule: |
| 3996 | priv->scan_pass_start = jiffies; |
| 3997 | queue_work(priv->workqueue, &priv->request_scan); |
| 3998 | } |
| 3999 | |
| 4000 | /* Handle notification from uCode that card's power state is changing |
| 4001 | * due to software, hardware, or critical temperature RFKILL */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4002 | static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv, |
| 4003 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4004 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4005 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4006 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 4007 | unsigned long status = priv->status; |
| 4008 | |
| 4009 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 4010 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 4011 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 4012 | |
| 4013 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 4014 | RF_CARD_DISABLED)) { |
| 4015 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4016 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4017 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 4018 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4019 | if (!iwl4965_grab_nic_access(priv)) { |
| 4020 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4021 | priv, HBUS_TARG_MBX_C, |
| 4022 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4023 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4024 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4025 | } |
| 4026 | |
| 4027 | if (!(flags & RXON_CARD_DISABLED)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4028 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4029 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4030 | if (!iwl4965_grab_nic_access(priv)) { |
| 4031 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4032 | priv, HBUS_TARG_MBX_C, |
| 4033 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4034 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4035 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4036 | } |
| 4037 | } |
| 4038 | |
| 4039 | if (flags & RF_CARD_DISABLED) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4040 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4041 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4042 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 4043 | if (!iwl4965_grab_nic_access(priv)) |
| 4044 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4045 | } |
| 4046 | } |
| 4047 | |
| 4048 | if (flags & HW_CARD_DISABLED) |
| 4049 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4050 | else |
| 4051 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4052 | |
| 4053 | |
| 4054 | if (flags & SW_CARD_DISABLED) |
| 4055 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4056 | else |
| 4057 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4058 | |
| 4059 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4060 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4061 | |
| 4062 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 4063 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 4064 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 4065 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 4066 | queue_work(priv->workqueue, &priv->rf_kill); |
| 4067 | else |
| 4068 | wake_up_interruptible(&priv->wait_command_queue); |
| 4069 | } |
| 4070 | |
| 4071 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4072 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4073 | * |
| 4074 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 4075 | * to the host. |
| 4076 | * |
| 4077 | * This function chains into the hardware specific files for them to setup |
| 4078 | * any hardware specific handlers as well. |
| 4079 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4080 | static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4081 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4082 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 4083 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 4084 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 4085 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4086 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4087 | iwl4965_rx_spectrum_measure_notif; |
| 4088 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4089 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4090 | iwl4965_rx_pm_debug_statistics_notif; |
| 4091 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4092 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4093 | /* |
| 4094 | * The same handler is used for both the REPLY to a discrete |
| 4095 | * statistics request from the host as well as for the periodic |
| 4096 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4097 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4098 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 4099 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4100 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4101 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 4102 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4103 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4104 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4105 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4106 | iwl4965_rx_scan_complete_notif; |
| 4107 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 4108 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4109 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4110 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4111 | iwl4965_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4112 | } |
| 4113 | |
| 4114 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4115 | * 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] | 4116 | * @rxb: Rx buffer to reclaim |
| 4117 | * |
| 4118 | * If an Rx buffer has an async callback associated with it the callback |
| 4119 | * will be executed. The attached skb (if present) will only be freed |
| 4120 | * if the callback returns 1 |
| 4121 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4122 | static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv, |
| 4123 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4124 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4125 | struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4126 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 4127 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 4128 | int index = SEQ_TO_INDEX(sequence); |
| 4129 | int huge = sequence & SEQ_HUGE_FRAME; |
| 4130 | int cmd_index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4131 | struct iwl4965_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4132 | |
| 4133 | /* If a Tx command is being handled and it isn't in the actual |
| 4134 | * command queue then there a command routing bug has been introduced |
| 4135 | * in the queue management code. */ |
| 4136 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 4137 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 4138 | txq_id, pkt->hdr.cmd); |
| 4139 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 4140 | |
| 4141 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 4142 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 4143 | |
| 4144 | /* Input error checking is done when commands are added to queue. */ |
| 4145 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 4146 | cmd->meta.source->u.skb = rxb->skb; |
| 4147 | rxb->skb = NULL; |
| 4148 | } else if (cmd->meta.u.callback && |
| 4149 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 4150 | rxb->skb = NULL; |
| 4151 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4152 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4153 | |
| 4154 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 4155 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4156 | wake_up_interruptible(&priv->wait_command_queue); |
| 4157 | } |
| 4158 | } |
| 4159 | |
| 4160 | /************************** RX-FUNCTIONS ****************************/ |
| 4161 | /* |
| 4162 | * Rx theory of operation |
| 4163 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4164 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), |
| 4165 | * each of which point to Receive Buffers to be filled by 4965. These get |
| 4166 | * used not only for Rx frames, but for any command response or notification |
| 4167 | * from the 4965. The driver and 4965 manage the Rx buffers by means |
| 4168 | * of indexes into the circular buffer. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4169 | * |
| 4170 | * Rx Queue Indexes |
| 4171 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4172 | * |
| 4173 | * The READ index maps to the first position that the firmware may be writing |
| 4174 | * to -- the driver can read up to (but not including) this position and get |
| 4175 | * good data. |
| 4176 | * The READ index is managed by the firmware once the card is enabled. |
| 4177 | * |
| 4178 | * The WRITE index maps to the last position the driver has read from -- the |
| 4179 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4180 | * |
| 4181 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 4182 | * WRITE = READ. |
| 4183 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4184 | * 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] | 4185 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4186 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4187 | * 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] | 4188 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4189 | * process as many packets as possible, moving the WRITE index forward as it |
| 4190 | * resets the Rx queue buffers with new memory. |
| 4191 | * |
| 4192 | * The management in the driver is as follows: |
| 4193 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 4194 | * 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] | 4195 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4196 | * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4197 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 4198 | * 'processed' and 'read' driver indexes as well) |
| 4199 | * + A received packet is processed and handed to the kernel network stack, |
| 4200 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 4201 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 4202 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 4203 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 4204 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4205 | * |
| 4206 | * |
| 4207 | * Driver sequence: |
| 4208 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4209 | * iwl4965_rx_queue_alloc() Allocates rx_free |
| 4210 | * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4211 | * iwl4965_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4212 | * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4213 | * queue, updates firmware pointers, and updates |
| 4214 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4215 | * are available, schedules iwl4965_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4216 | * |
| 4217 | * -- enable interrupts -- |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4218 | * 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] | 4219 | * READ INDEX, detaching the SKB from the pool. |
| 4220 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4221 | * Calls iwl4965_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4222 | * slots. |
| 4223 | * ... |
| 4224 | * |
| 4225 | */ |
| 4226 | |
| 4227 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4228 | * iwl4965_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4229 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4230 | static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4231 | { |
| 4232 | int s = q->read - q->write; |
| 4233 | if (s <= 0) |
| 4234 | s += RX_QUEUE_SIZE; |
| 4235 | /* keep some buffer to not confuse full and empty queue */ |
| 4236 | s -= 2; |
| 4237 | if (s < 0) |
| 4238 | s = 0; |
| 4239 | return s; |
| 4240 | } |
| 4241 | |
| 4242 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4243 | * 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] | 4244 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4245 | 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] | 4246 | { |
| 4247 | u32 reg = 0; |
| 4248 | int rc = 0; |
| 4249 | unsigned long flags; |
| 4250 | |
| 4251 | spin_lock_irqsave(&q->lock, flags); |
| 4252 | |
| 4253 | if (q->need_update == 0) |
| 4254 | goto exit_unlock; |
| 4255 | |
| 4256 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4257 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4258 | |
| 4259 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4260 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4261 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4262 | goto exit_unlock; |
| 4263 | } |
| 4264 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4265 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4266 | if (rc) |
| 4267 | goto exit_unlock; |
| 4268 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4269 | iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4270 | q->write & ~0x7); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4271 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4272 | } else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4273 | iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4274 | |
| 4275 | |
| 4276 | q->need_update = 0; |
| 4277 | |
| 4278 | exit_unlock: |
| 4279 | spin_unlock_irqrestore(&q->lock, flags); |
| 4280 | return rc; |
| 4281 | } |
| 4282 | |
| 4283 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4284 | * 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] | 4285 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4286 | static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4287 | dma_addr_t dma_addr) |
| 4288 | { |
| 4289 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 4290 | } |
| 4291 | |
| 4292 | |
| 4293 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4294 | * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4295 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4296 | * 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] | 4297 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4298 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4299 | * |
| 4300 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4301 | * also updates the memory address in the firmware to reference the new |
| 4302 | * target buffer. |
| 4303 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4304 | static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4305 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4306 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4307 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4308 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4309 | unsigned long flags; |
| 4310 | int write, rc; |
| 4311 | |
| 4312 | spin_lock_irqsave(&rxq->lock, flags); |
| 4313 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4314 | while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4315 | element = rxq->rx_free.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4316 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4317 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4318 | rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4319 | rxq->queue[rxq->write] = rxb; |
| 4320 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 4321 | rxq->free_count--; |
| 4322 | } |
| 4323 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4324 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 4325 | * refill it */ |
| 4326 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4327 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4328 | |
| 4329 | |
| 4330 | /* If we've added more space for the firmware to place data, tell it */ |
| 4331 | if ((write != (rxq->write & ~0x7)) |
| 4332 | || (abs(rxq->write - rxq->read) > 7)) { |
| 4333 | spin_lock_irqsave(&rxq->lock, flags); |
| 4334 | rxq->need_update = 1; |
| 4335 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4336 | rc = iwl4965_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4337 | if (rc) |
| 4338 | return rc; |
| 4339 | } |
| 4340 | |
| 4341 | return 0; |
| 4342 | } |
| 4343 | |
| 4344 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4345 | * 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] | 4346 | * |
| 4347 | * When moving to rx_free an SKB is allocated for the slot. |
| 4348 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4349 | * Also restock the Rx queue via iwl4965_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 4350 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4351 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4352 | void iwl4965_rx_replenish(void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4353 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4354 | struct iwl4965_priv *priv = data; |
| 4355 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4356 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4357 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4358 | unsigned long flags; |
| 4359 | spin_lock_irqsave(&rxq->lock, flags); |
| 4360 | while (!list_empty(&rxq->rx_used)) { |
| 4361 | element = rxq->rx_used.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4362 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4363 | rxb->skb = |
| 4364 | alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC); |
| 4365 | if (!rxb->skb) { |
| 4366 | if (net_ratelimit()) |
| 4367 | printk(KERN_CRIT DRV_NAME |
| 4368 | ": Can not allocate SKB buffers\n"); |
| 4369 | /* We don't reschedule replenish work here -- we will |
| 4370 | * call the restock method and if it still needs |
| 4371 | * more buffers it will schedule replenish */ |
| 4372 | break; |
| 4373 | } |
| 4374 | priv->alloc_rxb_skb++; |
| 4375 | list_del(element); |
| 4376 | rxb->dma_addr = |
| 4377 | pci_map_single(priv->pci_dev, rxb->skb->data, |
| 4378 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4379 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4380 | rxq->free_count++; |
| 4381 | } |
| 4382 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4383 | |
| 4384 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4385 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4386 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4387 | } |
| 4388 | |
| 4389 | /* 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] | 4390 | * 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] | 4391 | * This free routine walks the list of POOL entries and if SKB is set to |
| 4392 | * non NULL it is unmapped and freed |
| 4393 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4394 | 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] | 4395 | { |
| 4396 | int i; |
| 4397 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4398 | if (rxq->pool[i].skb != NULL) { |
| 4399 | pci_unmap_single(priv->pci_dev, |
| 4400 | rxq->pool[i].dma_addr, |
| 4401 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4402 | dev_kfree_skb(rxq->pool[i].skb); |
| 4403 | } |
| 4404 | } |
| 4405 | |
| 4406 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 4407 | rxq->dma_addr); |
| 4408 | rxq->bd = NULL; |
| 4409 | } |
| 4410 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4411 | int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4412 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4413 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4414 | struct pci_dev *dev = priv->pci_dev; |
| 4415 | int i; |
| 4416 | |
| 4417 | spin_lock_init(&rxq->lock); |
| 4418 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4419 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4420 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 4421 | if (!rxq->bd) |
| 4422 | return -ENOMEM; |
| 4423 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4424 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 4425 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4426 | /* Set us so that we have processed and used all buffers, but have |
| 4427 | * not restocked the Rx queue with fresh buffers */ |
| 4428 | rxq->read = rxq->write = 0; |
| 4429 | rxq->free_count = 0; |
| 4430 | rxq->need_update = 0; |
| 4431 | return 0; |
| 4432 | } |
| 4433 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4434 | 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] | 4435 | { |
| 4436 | unsigned long flags; |
| 4437 | int i; |
| 4438 | spin_lock_irqsave(&rxq->lock, flags); |
| 4439 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4440 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4441 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4442 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 4443 | /* In the reset function, these buffers may have been allocated |
| 4444 | * to an SKB, so we need to unmap and free potential storage */ |
| 4445 | if (rxq->pool[i].skb != NULL) { |
| 4446 | pci_unmap_single(priv->pci_dev, |
| 4447 | rxq->pool[i].dma_addr, |
| 4448 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4449 | priv->alloc_rxb_skb--; |
| 4450 | dev_kfree_skb(rxq->pool[i].skb); |
| 4451 | rxq->pool[i].skb = NULL; |
| 4452 | } |
| 4453 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4454 | } |
| 4455 | |
| 4456 | /* Set us so that we have processed and used all buffers, but have |
| 4457 | * not restocked the Rx queue with fresh buffers */ |
| 4458 | rxq->read = rxq->write = 0; |
| 4459 | rxq->free_count = 0; |
| 4460 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4461 | } |
| 4462 | |
| 4463 | /* Convert linear signal-to-noise ratio into dB */ |
| 4464 | static u8 ratio2dB[100] = { |
| 4465 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 4466 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 4467 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 4468 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 4469 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 4470 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 4471 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 4472 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 4473 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 4474 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 4475 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 4476 | }; |
| 4477 | |
| 4478 | /* Calculates a relative dB value from a ratio of linear |
| 4479 | * (i.e. not dB) signal levels. |
| 4480 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4481 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4482 | { |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4483 | /* 1000:1 or higher just report as 60 dB */ |
| 4484 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4485 | return 60; |
| 4486 | |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4487 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4488 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4489 | if (sig_ratio >= 100) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4490 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 4491 | |
| 4492 | /* We shouldn't see this */ |
| 4493 | if (sig_ratio < 1) |
| 4494 | return 0; |
| 4495 | |
| 4496 | /* Use table for ratios 1:1 - 99:1 */ |
| 4497 | return (int)ratio2dB[sig_ratio]; |
| 4498 | } |
| 4499 | |
| 4500 | #define PERFECT_RSSI (-20) /* dBm */ |
| 4501 | #define WORST_RSSI (-95) /* dBm */ |
| 4502 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 4503 | |
| 4504 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 4505 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 4506 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4507 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4508 | { |
| 4509 | int sig_qual; |
| 4510 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 4511 | |
| 4512 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 4513 | * as indicator; formula is (signal dbm - noise dbm). |
| 4514 | * SNR at or above 40 is a great signal (100%). |
| 4515 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 4516 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 4517 | if (noise_dbm) { |
| 4518 | if (rssi_dbm - noise_dbm >= 40) |
| 4519 | return 100; |
| 4520 | else if (rssi_dbm < noise_dbm) |
| 4521 | return 0; |
| 4522 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 4523 | |
| 4524 | /* Else use just the signal level. |
| 4525 | * This formula is a least squares fit of data points collected and |
| 4526 | * compared with a reference system that had a percentage (%) display |
| 4527 | * for signal quality. */ |
| 4528 | } else |
| 4529 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 4530 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 4531 | (RSSI_RANGE * RSSI_RANGE); |
| 4532 | |
| 4533 | if (sig_qual > 100) |
| 4534 | sig_qual = 100; |
| 4535 | else if (sig_qual < 1) |
| 4536 | sig_qual = 0; |
| 4537 | |
| 4538 | return sig_qual; |
| 4539 | } |
| 4540 | |
| 4541 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4542 | * iwl4965_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4543 | * |
| 4544 | * Uses the priv->rx_handlers callback function array to invoke |
| 4545 | * the appropriate handlers, including command responses, |
| 4546 | * frame-received notifications, and other notifications. |
| 4547 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4548 | static void iwl4965_rx_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4549 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4550 | struct iwl4965_rx_mem_buffer *rxb; |
| 4551 | struct iwl4965_rx_packet *pkt; |
| 4552 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4553 | u32 r, i; |
| 4554 | int reclaim; |
| 4555 | unsigned long flags; |
| 4556 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4557 | r = iwl4965_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4558 | i = rxq->read; |
| 4559 | |
| 4560 | /* Rx interrupt, but nothing sent from uCode */ |
| 4561 | if (i == r) |
| 4562 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 4563 | |
| 4564 | while (i != r) { |
| 4565 | rxb = rxq->queue[i]; |
| 4566 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4567 | /* 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] | 4568 | * then a bug has been introduced in the queue refilling |
| 4569 | * routines -- catch it here */ |
| 4570 | BUG_ON(rxb == NULL); |
| 4571 | |
| 4572 | rxq->queue[i] = NULL; |
| 4573 | |
| 4574 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
| 4575 | IWL_RX_BUF_SIZE, |
| 4576 | PCI_DMA_FROMDEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4577 | pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4578 | |
| 4579 | /* Reclaim a command buffer only if this packet is a response |
| 4580 | * to a (driver-originated) command. |
| 4581 | * If the packet (e.g. Rx frame) originated from uCode, |
| 4582 | * there is no command buffer to reclaim. |
| 4583 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 4584 | * but apparently a few don't get set; catch them here. */ |
| 4585 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 4586 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
| 4587 | (pkt->hdr.cmd != REPLY_4965_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 4588 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4589 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 4590 | (pkt->hdr.cmd != REPLY_TX); |
| 4591 | |
| 4592 | /* Based on type of command response or notification, |
| 4593 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4594 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4595 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 4596 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4597 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 4598 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 4599 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 4600 | } else { |
| 4601 | /* No handling needed */ |
| 4602 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4603 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 4604 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 4605 | pkt->hdr.cmd); |
| 4606 | } |
| 4607 | |
| 4608 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4609 | /* Invoke any callbacks, transfer the skb to caller, and |
| 4610 | * fire off the (possibly) blocking iwl4965_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4611 | * as we reclaim the driver command queue */ |
| 4612 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4613 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4614 | else |
| 4615 | IWL_WARNING("Claim null rxb?\n"); |
| 4616 | } |
| 4617 | |
| 4618 | /* For now we just don't re-use anything. We can tweak this |
| 4619 | * later to try and re-use notification packets and SKBs that |
| 4620 | * fail to Rx correctly */ |
| 4621 | if (rxb->skb != NULL) { |
| 4622 | priv->alloc_rxb_skb--; |
| 4623 | dev_kfree_skb_any(rxb->skb); |
| 4624 | rxb->skb = NULL; |
| 4625 | } |
| 4626 | |
| 4627 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
| 4628 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4629 | spin_lock_irqsave(&rxq->lock, flags); |
| 4630 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 4631 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4632 | i = (i + 1) & RX_QUEUE_MASK; |
| 4633 | } |
| 4634 | |
| 4635 | /* Backtrack one entry */ |
| 4636 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4637 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4638 | } |
| 4639 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4640 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 4641 | struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4642 | { |
| 4643 | u32 reg = 0; |
| 4644 | int rc = 0; |
| 4645 | int txq_id = txq->q.id; |
| 4646 | |
| 4647 | if (txq->need_update == 0) |
| 4648 | return rc; |
| 4649 | |
| 4650 | /* if we're trying to save power */ |
| 4651 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 4652 | /* wake up nic if it's powered down ... |
| 4653 | * uCode will wake up, and interrupt us again, so next |
| 4654 | * time we'll skip this part. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4655 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4656 | |
| 4657 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 4658 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4659 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4660 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4661 | return rc; |
| 4662 | } |
| 4663 | |
| 4664 | /* restore this queue's parameters in nic hardware. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4665 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4666 | if (rc) |
| 4667 | return rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4668 | iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4669 | txq->q.write_ptr | (txq_id << 8)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4670 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4671 | |
| 4672 | /* else not in power-save mode, uCode will never sleep when we're |
| 4673 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 4674 | } else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4675 | iwl4965_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4676 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4677 | |
| 4678 | txq->need_update = 0; |
| 4679 | |
| 4680 | return rc; |
| 4681 | } |
| 4682 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4683 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4684 | static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4685 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4686 | DECLARE_MAC_BUF(mac); |
| 4687 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4688 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4689 | iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4690 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 4691 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 4692 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 4693 | le32_to_cpu(rxon->filter_flags)); |
| 4694 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 4695 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 4696 | rxon->ofdm_basic_rates); |
| 4697 | 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] | 4698 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 4699 | print_mac(mac, rxon->node_addr)); |
| 4700 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 4701 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4702 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 4703 | } |
| 4704 | #endif |
| 4705 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4706 | static void iwl4965_enable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4707 | { |
| 4708 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 4709 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4710 | iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4713 | static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4714 | { |
| 4715 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 4716 | |
| 4717 | /* disable interrupts from uCode/NIC to host */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4718 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4719 | |
| 4720 | /* acknowledge/clear/reset any interrupts still pending |
| 4721 | * from uCode or flow handler (Rx/Tx DMA) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4722 | iwl4965_write32(priv, CSR_INT, 0xffffffff); |
| 4723 | iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4724 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 4725 | } |
| 4726 | |
| 4727 | static const char *desc_lookup(int i) |
| 4728 | { |
| 4729 | switch (i) { |
| 4730 | case 1: |
| 4731 | return "FAIL"; |
| 4732 | case 2: |
| 4733 | return "BAD_PARAM"; |
| 4734 | case 3: |
| 4735 | return "BAD_CHECKSUM"; |
| 4736 | case 4: |
| 4737 | return "NMI_INTERRUPT"; |
| 4738 | case 5: |
| 4739 | return "SYSASSERT"; |
| 4740 | case 6: |
| 4741 | return "FATAL_ERROR"; |
| 4742 | } |
| 4743 | |
| 4744 | return "UNKNOWN"; |
| 4745 | } |
| 4746 | |
| 4747 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4748 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4749 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4750 | static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4751 | { |
| 4752 | u32 data2, line; |
| 4753 | u32 desc, time, count, base, data1; |
| 4754 | u32 blink1, blink2, ilink1, ilink2; |
| 4755 | int rc; |
| 4756 | |
| 4757 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 4758 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4759 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4760 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 4761 | return; |
| 4762 | } |
| 4763 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4764 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4765 | if (rc) { |
| 4766 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4767 | return; |
| 4768 | } |
| 4769 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4770 | count = iwl4965_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4771 | |
| 4772 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 4773 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
| 4774 | IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n", |
| 4775 | priv->status, priv->config, count); |
| 4776 | } |
| 4777 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4778 | desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 4779 | blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 4780 | blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 4781 | ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 4782 | ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 4783 | data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 4784 | data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 4785 | line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 4786 | time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4787 | |
| 4788 | IWL_ERROR("Desc Time " |
| 4789 | "data1 data2 line\n"); |
| 4790 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 4791 | desc_lookup(desc), desc, time, data1, data2, line); |
| 4792 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 4793 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 4794 | ilink1, ilink2); |
| 4795 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4796 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4797 | } |
| 4798 | |
| 4799 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 4800 | |
| 4801 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4802 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4803 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4804 | * NOTE: Must be called with iwl4965_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4805 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4806 | 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] | 4807 | u32 num_events, u32 mode) |
| 4808 | { |
| 4809 | u32 i; |
| 4810 | u32 base; /* SRAM byte address of event log header */ |
| 4811 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 4812 | u32 ptr; /* SRAM byte address of log data */ |
| 4813 | u32 ev, time, data; /* event log data */ |
| 4814 | |
| 4815 | if (num_events == 0) |
| 4816 | return; |
| 4817 | |
| 4818 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 4819 | |
| 4820 | if (mode == 0) |
| 4821 | event_size = 2 * sizeof(u32); |
| 4822 | else |
| 4823 | event_size = 3 * sizeof(u32); |
| 4824 | |
| 4825 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 4826 | |
| 4827 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 4828 | * place event id # at far right for easier visual parsing. */ |
| 4829 | for (i = 0; i < num_events; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4830 | ev = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4831 | ptr += sizeof(u32); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4832 | time = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4833 | ptr += sizeof(u32); |
| 4834 | if (mode == 0) |
| 4835 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 4836 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4837 | data = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4838 | ptr += sizeof(u32); |
| 4839 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 4840 | } |
| 4841 | } |
| 4842 | } |
| 4843 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4844 | static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4845 | { |
| 4846 | int rc; |
| 4847 | u32 base; /* SRAM byte address of event log header */ |
| 4848 | u32 capacity; /* event log capacity in # entries */ |
| 4849 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 4850 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 4851 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 4852 | u32 size; /* # entries that we'll print */ |
| 4853 | |
| 4854 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4855 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4856 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 4857 | return; |
| 4858 | } |
| 4859 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4860 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4861 | if (rc) { |
| 4862 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4863 | return; |
| 4864 | } |
| 4865 | |
| 4866 | /* event log header */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4867 | capacity = iwl4965_read_targ_mem(priv, base); |
| 4868 | mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 4869 | num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 4870 | next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4871 | |
| 4872 | size = num_wraps ? capacity : next_entry; |
| 4873 | |
| 4874 | /* bail out if nothing in log */ |
| 4875 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4876 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4877 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4878 | return; |
| 4879 | } |
| 4880 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4881 | 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] | 4882 | size, num_wraps); |
| 4883 | |
| 4884 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 4885 | * i.e the next one that uCode would fill. */ |
| 4886 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4887 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4888 | capacity - next_entry, mode); |
| 4889 | |
| 4890 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4891 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4892 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4893 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4894 | } |
| 4895 | |
| 4896 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4897 | * 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] | 4898 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4899 | static void iwl4965_irq_handle_error(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4900 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4901 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4902 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 4903 | |
| 4904 | /* Cancel currently queued command. */ |
| 4905 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4906 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4907 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4908 | if (iwl4965_debug_level & IWL_DL_FW_ERRORS) { |
| 4909 | iwl4965_dump_nic_error_log(priv); |
| 4910 | iwl4965_dump_nic_event_log(priv); |
| 4911 | iwl4965_print_rx_config_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4912 | } |
| 4913 | #endif |
| 4914 | |
| 4915 | wake_up_interruptible(&priv->wait_command_queue); |
| 4916 | |
| 4917 | /* Keep the restart process from trying to send host |
| 4918 | * commands by clearing the INIT status bit */ |
| 4919 | clear_bit(STATUS_READY, &priv->status); |
| 4920 | |
| 4921 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4922 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 4923 | "Restarting adapter due to uCode error.\n"); |
| 4924 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4925 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4926 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 4927 | sizeof(priv->recovery_rxon)); |
| 4928 | priv->error_recovering = 1; |
| 4929 | } |
| 4930 | queue_work(priv->workqueue, &priv->restart); |
| 4931 | } |
| 4932 | } |
| 4933 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4934 | static void iwl4965_error_recovery(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4935 | { |
| 4936 | unsigned long flags; |
| 4937 | |
| 4938 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 4939 | sizeof(priv->staging_rxon)); |
| 4940 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4941 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4942 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4943 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4944 | |
| 4945 | spin_lock_irqsave(&priv->lock, flags); |
| 4946 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 4947 | priv->error_recovering = 0; |
| 4948 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4949 | } |
| 4950 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4951 | static void iwl4965_irq_tasklet(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4952 | { |
| 4953 | u32 inta, handled = 0; |
| 4954 | u32 inta_fh; |
| 4955 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4956 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4957 | u32 inta_mask; |
| 4958 | #endif |
| 4959 | |
| 4960 | spin_lock_irqsave(&priv->lock, flags); |
| 4961 | |
| 4962 | /* Ack/clear/reset pending uCode interrupts. |
| 4963 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4964 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4965 | inta = iwl4965_read32(priv, CSR_INT); |
| 4966 | iwl4965_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4967 | |
| 4968 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4969 | * Any new interrupts that happen after this, either while we're |
| 4970 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4971 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
| 4972 | iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4973 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4974 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4975 | if (iwl4965_debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4976 | /* just for debug */ |
| 4977 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4978 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4979 | inta, inta_mask, inta_fh); |
| 4980 | } |
| 4981 | #endif |
| 4982 | |
| 4983 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 4984 | * atomic, make sure that inta covers all the interrupts that |
| 4985 | * we've discovered, even if FH interrupt came in just after |
| 4986 | * reading CSR_INT. */ |
| 4987 | if (inta_fh & CSR_FH_INT_RX_MASK) |
| 4988 | inta |= CSR_INT_BIT_FH_RX; |
| 4989 | if (inta_fh & CSR_FH_INT_TX_MASK) |
| 4990 | inta |= CSR_INT_BIT_FH_TX; |
| 4991 | |
| 4992 | /* Now service all interrupt bits discovered above. */ |
| 4993 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 4994 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 4995 | |
| 4996 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4997 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4998 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4999 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5000 | |
| 5001 | handled |= CSR_INT_BIT_HW_ERR; |
| 5002 | |
| 5003 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5004 | |
| 5005 | return; |
| 5006 | } |
| 5007 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5008 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5009 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5010 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
| 5011 | if (inta & CSR_INT_BIT_MAC_CLK_ACTV) |
| 5012 | IWL_DEBUG_ISR("Microcode started or stopped.\n"); |
| 5013 | |
| 5014 | /* Alive notification via Rx interrupt will do the real work */ |
| 5015 | if (inta & CSR_INT_BIT_ALIVE) |
| 5016 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 5017 | } |
| 5018 | #endif |
| 5019 | /* Safely ignore these bits for debug checks below */ |
| 5020 | inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE); |
| 5021 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5022 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5023 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 5024 | int hw_rf_kill = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5025 | if (!(iwl4965_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5026 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 5027 | hw_rf_kill = 1; |
| 5028 | |
| 5029 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 5030 | "RF_KILL bit toggled to %s.\n", |
| 5031 | hw_rf_kill ? "disable radio":"enable radio"); |
| 5032 | |
| 5033 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 5034 | * when we loaded driver, and is now set to "enable". |
| 5035 | * After we're Alive, RF_KILL gets handled by |
| 5036 | * iwl_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 5037 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 5038 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5039 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 5040 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5041 | |
| 5042 | handled |= CSR_INT_BIT_RF_KILL; |
| 5043 | } |
| 5044 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5045 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5046 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 5047 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 5048 | handled |= CSR_INT_BIT_CT_KILL; |
| 5049 | } |
| 5050 | |
| 5051 | /* Error detected by uCode */ |
| 5052 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 5053 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 5054 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5055 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5056 | handled |= CSR_INT_BIT_SW_ERR; |
| 5057 | } |
| 5058 | |
| 5059 | /* uCode wakes up after power-down sleep */ |
| 5060 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 5061 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5062 | iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq); |
| 5063 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 5064 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 5065 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 5066 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 5067 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 5068 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5069 | |
| 5070 | handled |= CSR_INT_BIT_WAKEUP; |
| 5071 | } |
| 5072 | |
| 5073 | /* All uCode command responses, including Tx command responses, |
| 5074 | * Rx "responses" (frame-received notification), and other |
| 5075 | * notifications from uCode come through here*/ |
| 5076 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5077 | iwl4965_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5078 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 5079 | } |
| 5080 | |
| 5081 | if (inta & CSR_INT_BIT_FH_TX) { |
| 5082 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 5083 | handled |= CSR_INT_BIT_FH_TX; |
| 5084 | } |
| 5085 | |
| 5086 | if (inta & ~handled) |
| 5087 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 5088 | |
| 5089 | if (inta & ~CSR_INI_SET_MASK) { |
| 5090 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 5091 | inta & ~CSR_INI_SET_MASK); |
| 5092 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 5093 | } |
| 5094 | |
| 5095 | /* Re-enable all interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5096 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5097 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5098 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5099 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
| 5100 | inta = iwl4965_read32(priv, CSR_INT); |
| 5101 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
| 5102 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5103 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 5104 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 5105 | } |
| 5106 | #endif |
| 5107 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5108 | } |
| 5109 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5110 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5111 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5112 | struct iwl4965_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5113 | u32 inta, inta_mask; |
| 5114 | u32 inta_fh; |
| 5115 | if (!priv) |
| 5116 | return IRQ_NONE; |
| 5117 | |
| 5118 | spin_lock(&priv->lock); |
| 5119 | |
| 5120 | /* Disable (but don't clear!) interrupts here to avoid |
| 5121 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 5122 | * If we have something to service, the tasklet will re-enable ints. |
| 5123 | * 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] | 5124 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 5125 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5126 | |
| 5127 | /* Discover which interrupts are active/pending */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5128 | inta = iwl4965_read32(priv, CSR_INT); |
| 5129 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5130 | |
| 5131 | /* Ignore interrupt if there's nothing in NIC to service. |
| 5132 | * This may be due to IRQ shared with another device, |
| 5133 | * or due to sporadic interrupts thrown from our NIC. */ |
| 5134 | if (!inta && !inta_fh) { |
| 5135 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 5136 | goto none; |
| 5137 | } |
| 5138 | |
| 5139 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5140 | /* Hardware disappeared. It might have already raised |
| 5141 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5142 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5143 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5147 | inta, inta_mask, inta_fh); |
| 5148 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5149 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5150 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5151 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5152 | unplugged: |
| 5153 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5154 | return IRQ_HANDLED; |
| 5155 | |
| 5156 | none: |
| 5157 | /* re-enable interrupts here since we don't have anything to service. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5158 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5159 | spin_unlock(&priv->lock); |
| 5160 | return IRQ_NONE; |
| 5161 | } |
| 5162 | |
| 5163 | /************************** EEPROM BANDS **************************** |
| 5164 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5165 | * The iwl4965_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5166 | * EEPROM contents to the specific channel number supported for each |
| 5167 | * band. |
| 5168 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5169 | * 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] | 5170 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 5171 | * The specific geography and calibration information for that channel |
| 5172 | * is contained in the eeprom map itself. |
| 5173 | * |
| 5174 | * During init, we copy the eeprom information and channel map |
| 5175 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 5176 | * |
| 5177 | * channel_map_24/52 provides the index in the channel_info array for a |
| 5178 | * given channel. We have to have two separate maps as there is channel |
| 5179 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 5180 | * band_2 |
| 5181 | * |
| 5182 | * A value of 0xff stored in the channel_map indicates that the channel |
| 5183 | * is not supported by the hardware at all. |
| 5184 | * |
| 5185 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 5186 | * valid for Tx with the current hardware. This means that |
| 5187 | * while the system can tune and receive on a given channel, it may not |
| 5188 | * be able to associate or transmit any frames on that |
| 5189 | * channel. There is no corresponding channel information for that |
| 5190 | * entry. |
| 5191 | * |
| 5192 | *********************************************************************/ |
| 5193 | |
| 5194 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5195 | static const u8 iwl4965_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5196 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 5197 | }; |
| 5198 | |
| 5199 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5200 | static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5201 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 5202 | }; |
| 5203 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5204 | static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5205 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 5206 | }; |
| 5207 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5208 | static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5209 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 5210 | }; |
| 5211 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5212 | static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5213 | 145, 149, 153, 157, 161, 165 |
| 5214 | }; |
| 5215 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5216 | static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5217 | 1, 2, 3, 4, 5, 6, 7 |
| 5218 | }; |
| 5219 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5220 | static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5221 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 |
| 5222 | }; |
| 5223 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5224 | static void iwl4965_init_band_reference(const struct iwl4965_priv *priv, |
| 5225 | int band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5226 | int *eeprom_ch_count, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5227 | const struct iwl4965_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5228 | **eeprom_ch_info, |
| 5229 | const u8 **eeprom_ch_index) |
| 5230 | { |
| 5231 | switch (band) { |
| 5232 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5233 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5234 | *eeprom_ch_info = priv->eeprom.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5235 | *eeprom_ch_index = iwl4965_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5236 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5237 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5238 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5239 | *eeprom_ch_info = priv->eeprom.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5240 | *eeprom_ch_index = iwl4965_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5241 | break; |
| 5242 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5243 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5244 | *eeprom_ch_info = priv->eeprom.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5245 | *eeprom_ch_index = iwl4965_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5246 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5247 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5248 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5249 | *eeprom_ch_info = priv->eeprom.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5250 | *eeprom_ch_index = iwl4965_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5251 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5252 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5253 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5254 | *eeprom_ch_info = priv->eeprom.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5255 | *eeprom_ch_index = iwl4965_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5256 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5257 | case 6: /* 2.4GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5258 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5259 | *eeprom_ch_info = priv->eeprom.band_24_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5260 | *eeprom_ch_index = iwl4965_eeprom_band_6; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5261 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5262 | case 7: /* 5 GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5263 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5264 | *eeprom_ch_info = priv->eeprom.band_52_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5265 | *eeprom_ch_index = iwl4965_eeprom_band_7; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5266 | break; |
| 5267 | default: |
| 5268 | BUG(); |
| 5269 | return; |
| 5270 | } |
| 5271 | } |
| 5272 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5273 | const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5274 | int phymode, u16 channel) |
| 5275 | { |
| 5276 | int i; |
| 5277 | |
| 5278 | switch (phymode) { |
| 5279 | case MODE_IEEE80211A: |
| 5280 | for (i = 14; i < priv->channel_count; i++) { |
| 5281 | if (priv->channel_info[i].channel == channel) |
| 5282 | return &priv->channel_info[i]; |
| 5283 | } |
| 5284 | break; |
| 5285 | |
| 5286 | case MODE_IEEE80211B: |
| 5287 | case MODE_IEEE80211G: |
| 5288 | if (channel >= 1 && channel <= 14) |
| 5289 | return &priv->channel_info[channel - 1]; |
| 5290 | break; |
| 5291 | |
| 5292 | } |
| 5293 | |
| 5294 | return NULL; |
| 5295 | } |
| 5296 | |
| 5297 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 5298 | ? # x " " : "") |
| 5299 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5300 | static int iwl4965_init_channel_map(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5301 | { |
| 5302 | int eeprom_ch_count = 0; |
| 5303 | const u8 *eeprom_ch_index = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5304 | const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5305 | int band, ch; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5306 | struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5307 | |
| 5308 | if (priv->channel_count) { |
| 5309 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 5310 | return 0; |
| 5311 | } |
| 5312 | |
| 5313 | if (priv->eeprom.version < 0x2f) { |
| 5314 | IWL_WARNING("Unsupported EEPROM version: 0x%04X\n", |
| 5315 | priv->eeprom.version); |
| 5316 | return -EINVAL; |
| 5317 | } |
| 5318 | |
| 5319 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 5320 | |
| 5321 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5322 | ARRAY_SIZE(iwl4965_eeprom_band_1) + |
| 5323 | ARRAY_SIZE(iwl4965_eeprom_band_2) + |
| 5324 | ARRAY_SIZE(iwl4965_eeprom_band_3) + |
| 5325 | ARRAY_SIZE(iwl4965_eeprom_band_4) + |
| 5326 | ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5327 | |
| 5328 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 5329 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5330 | priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5331 | priv->channel_count, GFP_KERNEL); |
| 5332 | if (!priv->channel_info) { |
| 5333 | IWL_ERROR("Could not allocate channel_info\n"); |
| 5334 | priv->channel_count = 0; |
| 5335 | return -ENOMEM; |
| 5336 | } |
| 5337 | |
| 5338 | ch_info = priv->channel_info; |
| 5339 | |
| 5340 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 5341 | * channel map we maintain (that contains additional information than |
| 5342 | * what just in the EEPROM) */ |
| 5343 | for (band = 1; band <= 5; band++) { |
| 5344 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5345 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5346 | &eeprom_ch_info, &eeprom_ch_index); |
| 5347 | |
| 5348 | /* Loop through each band adding each of the channels */ |
| 5349 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5350 | ch_info->channel = eeprom_ch_index[ch]; |
| 5351 | ch_info->phymode = (band == 1) ? MODE_IEEE80211B : |
| 5352 | MODE_IEEE80211A; |
| 5353 | |
| 5354 | /* permanently store EEPROM's channel regulatory flags |
| 5355 | * and max power in channel info database. */ |
| 5356 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 5357 | |
| 5358 | /* Copy the run-time flags so they are there even on |
| 5359 | * invalid channels */ |
| 5360 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 5361 | |
| 5362 | if (!(is_channel_valid(ch_info))) { |
| 5363 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 5364 | "No traffic\n", |
| 5365 | ch_info->channel, |
| 5366 | ch_info->flags, |
| 5367 | is_channel_a_band(ch_info) ? |
| 5368 | "5.2" : "2.4"); |
| 5369 | ch_info++; |
| 5370 | continue; |
| 5371 | } |
| 5372 | |
| 5373 | /* Initialize regulatory-based run-time data */ |
| 5374 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 5375 | eeprom_ch_info[ch].max_power_avg; |
| 5376 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 5377 | ch_info->min_power = 0; |
| 5378 | |
| 5379 | IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x" |
| 5380 | " %ddBm): Ad-Hoc %ssupported\n", |
| 5381 | ch_info->channel, |
| 5382 | is_channel_a_band(ch_info) ? |
| 5383 | "5.2" : "2.4", |
| 5384 | CHECK_AND_PRINT(IBSS), |
| 5385 | CHECK_AND_PRINT(ACTIVE), |
| 5386 | CHECK_AND_PRINT(RADAR), |
| 5387 | CHECK_AND_PRINT(WIDE), |
| 5388 | CHECK_AND_PRINT(NARROW), |
| 5389 | CHECK_AND_PRINT(DFS), |
| 5390 | eeprom_ch_info[ch].flags, |
| 5391 | eeprom_ch_info[ch].max_power_avg, |
| 5392 | ((eeprom_ch_info[ch]. |
| 5393 | flags & EEPROM_CHANNEL_IBSS) |
| 5394 | && !(eeprom_ch_info[ch]. |
| 5395 | flags & EEPROM_CHANNEL_RADAR)) |
| 5396 | ? "" : "not "); |
| 5397 | |
| 5398 | /* Set the user_txpower_limit to the highest power |
| 5399 | * supported by any channel */ |
| 5400 | if (eeprom_ch_info[ch].max_power_avg > |
| 5401 | priv->user_txpower_limit) |
| 5402 | priv->user_txpower_limit = |
| 5403 | eeprom_ch_info[ch].max_power_avg; |
| 5404 | |
| 5405 | ch_info++; |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | for (band = 6; band <= 7; band++) { |
| 5410 | int phymode; |
| 5411 | u8 fat_extension_chan; |
| 5412 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5413 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5414 | &eeprom_ch_info, &eeprom_ch_index); |
| 5415 | |
| 5416 | phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A; |
| 5417 | /* Loop through each band adding each of the channels */ |
| 5418 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5419 | |
| 5420 | if ((band == 6) && |
| 5421 | ((eeprom_ch_index[ch] == 5) || |
| 5422 | (eeprom_ch_index[ch] == 6) || |
| 5423 | (eeprom_ch_index[ch] == 7))) |
| 5424 | fat_extension_chan = HT_IE_EXT_CHANNEL_MAX; |
| 5425 | else |
| 5426 | fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; |
| 5427 | |
| 5428 | iwl4965_set_fat_chan_info(priv, phymode, |
| 5429 | eeprom_ch_index[ch], |
| 5430 | &(eeprom_ch_info[ch]), |
| 5431 | fat_extension_chan); |
| 5432 | |
| 5433 | iwl4965_set_fat_chan_info(priv, phymode, |
| 5434 | (eeprom_ch_index[ch] + 4), |
| 5435 | &(eeprom_ch_info[ch]), |
| 5436 | HT_IE_EXT_CHANNEL_BELOW); |
| 5437 | } |
| 5438 | } |
| 5439 | |
| 5440 | return 0; |
| 5441 | } |
| 5442 | |
| 5443 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 5444 | * sending probe req. This should be set long enough to hear probe responses |
| 5445 | * from more than one AP. */ |
| 5446 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5447 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 5448 | |
| 5449 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 5450 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 5451 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 5452 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 5453 | * no other traffic). |
| 5454 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 5455 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 5456 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 5457 | |
| 5458 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 5459 | * Must be set longer than active dwell time. |
| 5460 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 5461 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5462 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 5463 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 5464 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 5465 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5466 | static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv, int phymode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5467 | { |
| 5468 | if (phymode == MODE_IEEE80211A) |
| 5469 | return IWL_ACTIVE_DWELL_TIME_52; |
| 5470 | else |
| 5471 | return IWL_ACTIVE_DWELL_TIME_24; |
| 5472 | } |
| 5473 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5474 | static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, int phymode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5475 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5476 | u16 active = iwl4965_get_active_dwell_time(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5477 | u16 passive = (phymode != MODE_IEEE80211A) ? |
| 5478 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 5479 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 5480 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5481 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5482 | /* If we're associated, we clamp the maximum passive |
| 5483 | * dwell time to be 98% of the beacon interval (minus |
| 5484 | * 2 * channel tune time) */ |
| 5485 | passive = priv->beacon_int; |
| 5486 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 5487 | passive = IWL_PASSIVE_DWELL_BASE; |
| 5488 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 5489 | } |
| 5490 | |
| 5491 | if (passive <= active) |
| 5492 | passive = active + 1; |
| 5493 | |
| 5494 | return passive; |
| 5495 | } |
| 5496 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5497 | static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5498 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5499 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5500 | { |
| 5501 | const struct ieee80211_channel *channels = NULL; |
| 5502 | const struct ieee80211_hw_mode *hw_mode; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5503 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5504 | u16 passive_dwell = 0; |
| 5505 | u16 active_dwell = 0; |
| 5506 | int added, i; |
| 5507 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5508 | hw_mode = iwl4965_get_hw_mode(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5509 | if (!hw_mode) |
| 5510 | return 0; |
| 5511 | |
| 5512 | channels = hw_mode->channels; |
| 5513 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5514 | active_dwell = iwl4965_get_active_dwell_time(priv, phymode); |
| 5515 | passive_dwell = iwl4965_get_passive_dwell_time(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5516 | |
| 5517 | for (i = 0, added = 0; i < hw_mode->num_channels; i++) { |
| 5518 | if (channels[i].chan == |
| 5519 | le16_to_cpu(priv->active_rxon.channel)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5520 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5521 | IWL_DEBUG_SCAN |
| 5522 | ("Skipping current channel %d\n", |
| 5523 | le16_to_cpu(priv->active_rxon.channel)); |
| 5524 | continue; |
| 5525 | } |
| 5526 | } else if (priv->only_active_channel) |
| 5527 | continue; |
| 5528 | |
| 5529 | scan_ch->channel = channels[i].chan; |
| 5530 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5531 | ch_info = iwl4965_get_channel_info(priv, phymode, |
| 5532 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5533 | if (!is_channel_valid(ch_info)) { |
| 5534 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 5535 | scan_ch->channel); |
| 5536 | continue; |
| 5537 | } |
| 5538 | |
| 5539 | if (!is_active || is_channel_passive(ch_info) || |
| 5540 | !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN)) |
| 5541 | scan_ch->type = 0; /* passive */ |
| 5542 | else |
| 5543 | scan_ch->type = 1; /* active */ |
| 5544 | |
| 5545 | if (scan_ch->type & 1) |
| 5546 | scan_ch->type |= (direct_mask << 1); |
| 5547 | |
| 5548 | if (is_channel_narrow(ch_info)) |
| 5549 | scan_ch->type |= (1 << 7); |
| 5550 | |
| 5551 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 5552 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 5553 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5554 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5555 | scan_ch->tpc.dsp_atten = 110; |
| 5556 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 5557 | |
| 5558 | /*scan_pwr_info->tpc.tx_gain; */ |
| 5559 | if (phymode == MODE_IEEE80211A) |
| 5560 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 5561 | else { |
| 5562 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 5563 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5564 | * power level: |
| 5565 | * scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5566 | */ |
| 5567 | } |
| 5568 | |
| 5569 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 5570 | scan_ch->channel, |
| 5571 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 5572 | (scan_ch->type & 1) ? |
| 5573 | active_dwell : passive_dwell); |
| 5574 | |
| 5575 | scan_ch++; |
| 5576 | added++; |
| 5577 | } |
| 5578 | |
| 5579 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 5580 | return added; |
| 5581 | } |
| 5582 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5583 | static void iwl4965_reset_channel_flag(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5584 | { |
| 5585 | int i, j; |
| 5586 | for (i = 0; i < 3; i++) { |
| 5587 | struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i]; |
| 5588 | for (j = 0; j < hw_mode->num_channels; j++) |
| 5589 | hw_mode->channels[j].flag = hw_mode->channels[j].val; |
| 5590 | } |
| 5591 | } |
| 5592 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5593 | static void iwl4965_init_hw_rates(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5594 | struct ieee80211_rate *rates) |
| 5595 | { |
| 5596 | int i; |
| 5597 | |
| 5598 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5599 | rates[i].rate = iwl4965_rates[i].ieee * 5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5600 | rates[i].val = i; /* Rate scaling will work on indexes */ |
| 5601 | rates[i].val2 = i; |
| 5602 | rates[i].flags = IEEE80211_RATE_SUPPORTED; |
| 5603 | /* Only OFDM have the bits-per-symbol set */ |
| 5604 | if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE)) |
| 5605 | rates[i].flags |= IEEE80211_RATE_OFDM; |
| 5606 | else { |
| 5607 | /* |
| 5608 | * If CCK 1M then set rate flag to CCK else CCK_2 |
| 5609 | * which is CCK | PREAMBLE2 |
| 5610 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5611 | rates[i].flags |= (iwl4965_rates[i].plcp == 10) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5612 | IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2; |
| 5613 | } |
| 5614 | |
| 5615 | /* Set up which ones are basic rates... */ |
| 5616 | if (IWL_BASIC_RATES_MASK & (1 << i)) |
| 5617 | rates[i].flags |= IEEE80211_RATE_BASIC; |
| 5618 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5622 | * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5623 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5624 | static int iwl4965_init_geos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5625 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5626 | struct iwl4965_channel_info *ch; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5627 | struct ieee80211_hw_mode *modes; |
| 5628 | struct ieee80211_channel *channels; |
| 5629 | struct ieee80211_channel *geo_ch; |
| 5630 | struct ieee80211_rate *rates; |
| 5631 | int i = 0; |
| 5632 | enum { |
| 5633 | A = 0, |
| 5634 | B = 1, |
| 5635 | G = 2, |
| 5636 | A_11N = 3, |
| 5637 | G_11N = 4, |
| 5638 | }; |
| 5639 | int mode_count = 5; |
| 5640 | |
| 5641 | if (priv->modes) { |
| 5642 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 5643 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5644 | return 0; |
| 5645 | } |
| 5646 | |
| 5647 | modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count, |
| 5648 | GFP_KERNEL); |
| 5649 | if (!modes) |
| 5650 | return -ENOMEM; |
| 5651 | |
| 5652 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 5653 | priv->channel_count, GFP_KERNEL); |
| 5654 | if (!channels) { |
| 5655 | kfree(modes); |
| 5656 | return -ENOMEM; |
| 5657 | } |
| 5658 | |
| 5659 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)), |
| 5660 | GFP_KERNEL); |
| 5661 | if (!rates) { |
| 5662 | kfree(modes); |
| 5663 | kfree(channels); |
| 5664 | return -ENOMEM; |
| 5665 | } |
| 5666 | |
| 5667 | /* 0 = 802.11a |
| 5668 | * 1 = 802.11b |
| 5669 | * 2 = 802.11g |
| 5670 | */ |
| 5671 | |
| 5672 | /* 5.2GHz channels start after the 2.4GHz channels */ |
| 5673 | modes[A].mode = MODE_IEEE80211A; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5674 | modes[A].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5675 | modes[A].rates = rates; |
| 5676 | modes[A].num_rates = 8; /* just OFDM */ |
| 5677 | modes[A].rates = &rates[4]; |
| 5678 | modes[A].num_channels = 0; |
| 5679 | |
| 5680 | modes[B].mode = MODE_IEEE80211B; |
| 5681 | modes[B].channels = channels; |
| 5682 | modes[B].rates = rates; |
| 5683 | modes[B].num_rates = 4; /* just CCK */ |
| 5684 | modes[B].num_channels = 0; |
| 5685 | |
| 5686 | modes[G].mode = MODE_IEEE80211G; |
| 5687 | modes[G].channels = channels; |
| 5688 | modes[G].rates = rates; |
| 5689 | modes[G].num_rates = 12; /* OFDM & CCK */ |
| 5690 | modes[G].num_channels = 0; |
| 5691 | |
| 5692 | modes[G_11N].mode = MODE_IEEE80211G; |
| 5693 | modes[G_11N].channels = channels; |
| 5694 | modes[G_11N].num_rates = 13; /* OFDM & CCK */ |
| 5695 | modes[G_11N].rates = rates; |
| 5696 | modes[G_11N].num_channels = 0; |
| 5697 | |
| 5698 | modes[A_11N].mode = MODE_IEEE80211A; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5699 | modes[A_11N].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5700 | modes[A_11N].rates = &rates[4]; |
| 5701 | modes[A_11N].num_rates = 9; /* just OFDM */ |
| 5702 | modes[A_11N].num_channels = 0; |
| 5703 | |
| 5704 | priv->ieee_channels = channels; |
| 5705 | priv->ieee_rates = rates; |
| 5706 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5707 | iwl4965_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5708 | |
| 5709 | for (i = 0, geo_ch = channels; i < priv->channel_count; i++) { |
| 5710 | ch = &priv->channel_info[i]; |
| 5711 | |
| 5712 | if (!is_channel_valid(ch)) { |
| 5713 | IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- " |
| 5714 | "skipping.\n", |
| 5715 | ch->channel, is_channel_a_band(ch) ? |
| 5716 | "5.2" : "2.4"); |
| 5717 | continue; |
| 5718 | } |
| 5719 | |
| 5720 | if (is_channel_a_band(ch)) { |
| 5721 | geo_ch = &modes[A].channels[modes[A].num_channels++]; |
| 5722 | modes[A_11N].num_channels++; |
| 5723 | } else { |
| 5724 | geo_ch = &modes[B].channels[modes[B].num_channels++]; |
| 5725 | modes[G].num_channels++; |
| 5726 | modes[G_11N].num_channels++; |
| 5727 | } |
| 5728 | |
| 5729 | geo_ch->freq = ieee80211chan2mhz(ch->channel); |
| 5730 | geo_ch->chan = ch->channel; |
| 5731 | geo_ch->power_level = ch->max_power_avg; |
| 5732 | geo_ch->antenna_max = 0xff; |
| 5733 | |
| 5734 | if (is_channel_valid(ch)) { |
| 5735 | geo_ch->flag = IEEE80211_CHAN_W_SCAN; |
| 5736 | if (ch->flags & EEPROM_CHANNEL_IBSS) |
| 5737 | geo_ch->flag |= IEEE80211_CHAN_W_IBSS; |
| 5738 | |
| 5739 | if (ch->flags & EEPROM_CHANNEL_ACTIVE) |
| 5740 | geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN; |
| 5741 | |
| 5742 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
| 5743 | geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT; |
| 5744 | |
| 5745 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 5746 | priv->max_channel_txpower_limit = |
| 5747 | ch->max_power_avg; |
| 5748 | } |
| 5749 | |
| 5750 | geo_ch->val = geo_ch->flag; |
| 5751 | } |
| 5752 | |
| 5753 | if ((modes[A].num_channels == 0) && priv->is_abg) { |
| 5754 | printk(KERN_INFO DRV_NAME |
| 5755 | ": Incorrectly detected BG card as ABG. Please send " |
| 5756 | "your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 5757 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
| 5758 | priv->is_abg = 0; |
| 5759 | } |
| 5760 | |
| 5761 | printk(KERN_INFO DRV_NAME |
| 5762 | ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
| 5763 | modes[G].num_channels, modes[A].num_channels); |
| 5764 | |
| 5765 | /* |
| 5766 | * NOTE: We register these in preference of order -- the |
| 5767 | * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick |
| 5768 | * a phymode based on rates or AP capabilities but seems to |
| 5769 | * configure it purely on if the channel being configured |
| 5770 | * is supported by a mode -- and the first match is taken |
| 5771 | */ |
| 5772 | |
| 5773 | if (modes[G].num_channels) |
| 5774 | ieee80211_register_hwmode(priv->hw, &modes[G]); |
| 5775 | if (modes[B].num_channels) |
| 5776 | ieee80211_register_hwmode(priv->hw, &modes[B]); |
| 5777 | if (modes[A].num_channels) |
| 5778 | ieee80211_register_hwmode(priv->hw, &modes[A]); |
| 5779 | |
| 5780 | priv->modes = modes; |
| 5781 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5782 | |
| 5783 | return 0; |
| 5784 | } |
| 5785 | |
| 5786 | /****************************************************************************** |
| 5787 | * |
| 5788 | * uCode download functions |
| 5789 | * |
| 5790 | ******************************************************************************/ |
| 5791 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5792 | static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5793 | { |
| 5794 | if (priv->ucode_code.v_addr != NULL) { |
| 5795 | pci_free_consistent(priv->pci_dev, |
| 5796 | priv->ucode_code.len, |
| 5797 | priv->ucode_code.v_addr, |
| 5798 | priv->ucode_code.p_addr); |
| 5799 | priv->ucode_code.v_addr = NULL; |
| 5800 | } |
| 5801 | if (priv->ucode_data.v_addr != NULL) { |
| 5802 | pci_free_consistent(priv->pci_dev, |
| 5803 | priv->ucode_data.len, |
| 5804 | priv->ucode_data.v_addr, |
| 5805 | priv->ucode_data.p_addr); |
| 5806 | priv->ucode_data.v_addr = NULL; |
| 5807 | } |
| 5808 | if (priv->ucode_data_backup.v_addr != NULL) { |
| 5809 | pci_free_consistent(priv->pci_dev, |
| 5810 | priv->ucode_data_backup.len, |
| 5811 | priv->ucode_data_backup.v_addr, |
| 5812 | priv->ucode_data_backup.p_addr); |
| 5813 | priv->ucode_data_backup.v_addr = NULL; |
| 5814 | } |
| 5815 | if (priv->ucode_init.v_addr != NULL) { |
| 5816 | pci_free_consistent(priv->pci_dev, |
| 5817 | priv->ucode_init.len, |
| 5818 | priv->ucode_init.v_addr, |
| 5819 | priv->ucode_init.p_addr); |
| 5820 | priv->ucode_init.v_addr = NULL; |
| 5821 | } |
| 5822 | if (priv->ucode_init_data.v_addr != NULL) { |
| 5823 | pci_free_consistent(priv->pci_dev, |
| 5824 | priv->ucode_init_data.len, |
| 5825 | priv->ucode_init_data.v_addr, |
| 5826 | priv->ucode_init_data.p_addr); |
| 5827 | priv->ucode_init_data.v_addr = NULL; |
| 5828 | } |
| 5829 | if (priv->ucode_boot.v_addr != NULL) { |
| 5830 | pci_free_consistent(priv->pci_dev, |
| 5831 | priv->ucode_boot.len, |
| 5832 | priv->ucode_boot.v_addr, |
| 5833 | priv->ucode_boot.p_addr); |
| 5834 | priv->ucode_boot.v_addr = NULL; |
| 5835 | } |
| 5836 | } |
| 5837 | |
| 5838 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5839 | * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5840 | * looking at all data. |
| 5841 | */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5842 | static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 * image, |
| 5843 | u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5844 | { |
| 5845 | u32 val; |
| 5846 | u32 save_len = len; |
| 5847 | int rc = 0; |
| 5848 | u32 errcnt; |
| 5849 | |
| 5850 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5851 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5852 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5853 | if (rc) |
| 5854 | return rc; |
| 5855 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5856 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5857 | |
| 5858 | errcnt = 0; |
| 5859 | for (; len > 0; len -= sizeof(u32), image++) { |
| 5860 | /* read data comes through single port, auto-incr addr */ |
| 5861 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5862 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5863 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5864 | if (val != le32_to_cpu(*image)) { |
| 5865 | IWL_ERROR("uCode INST section is invalid at " |
| 5866 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5867 | save_len - len, val, le32_to_cpu(*image)); |
| 5868 | rc = -EIO; |
| 5869 | errcnt++; |
| 5870 | if (errcnt >= 20) |
| 5871 | break; |
| 5872 | } |
| 5873 | } |
| 5874 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5875 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5876 | |
| 5877 | if (!errcnt) |
| 5878 | IWL_DEBUG_INFO |
| 5879 | ("ucode image in INSTRUCTION memory is good\n"); |
| 5880 | |
| 5881 | return rc; |
| 5882 | } |
| 5883 | |
| 5884 | |
| 5885 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5886 | * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5887 | * using sample data 100 bytes apart. If these sample points are good, |
| 5888 | * it's a pretty good bet that everything between them is good, too. |
| 5889 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5890 | 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] | 5891 | { |
| 5892 | u32 val; |
| 5893 | int rc = 0; |
| 5894 | u32 errcnt = 0; |
| 5895 | u32 i; |
| 5896 | |
| 5897 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5898 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5899 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5900 | if (rc) |
| 5901 | return rc; |
| 5902 | |
| 5903 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 5904 | /* read data comes through single port, auto-incr addr */ |
| 5905 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5906 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5907 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5908 | i + RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5909 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5910 | if (val != le32_to_cpu(*image)) { |
| 5911 | #if 0 /* Enable this if you want to see details */ |
| 5912 | IWL_ERROR("uCode INST section is invalid at " |
| 5913 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5914 | i, val, *image); |
| 5915 | #endif |
| 5916 | rc = -EIO; |
| 5917 | errcnt++; |
| 5918 | if (errcnt >= 3) |
| 5919 | break; |
| 5920 | } |
| 5921 | } |
| 5922 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5923 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5924 | |
| 5925 | return rc; |
| 5926 | } |
| 5927 | |
| 5928 | |
| 5929 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5930 | * iwl4965_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5931 | * and verify its contents |
| 5932 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5933 | static int iwl4965_verify_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5934 | { |
| 5935 | __le32 *image; |
| 5936 | u32 len; |
| 5937 | int rc = 0; |
| 5938 | |
| 5939 | /* Try bootstrap */ |
| 5940 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5941 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5942 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5943 | if (rc == 0) { |
| 5944 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 5945 | return 0; |
| 5946 | } |
| 5947 | |
| 5948 | /* Try initialize */ |
| 5949 | image = (__le32 *)priv->ucode_init.v_addr; |
| 5950 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5951 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5952 | if (rc == 0) { |
| 5953 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 5954 | return 0; |
| 5955 | } |
| 5956 | |
| 5957 | /* Try runtime/protocol */ |
| 5958 | image = (__le32 *)priv->ucode_code.v_addr; |
| 5959 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5960 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5961 | if (rc == 0) { |
| 5962 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 5963 | return 0; |
| 5964 | } |
| 5965 | |
| 5966 | IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
| 5967 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5968 | /* Since nothing seems to match, show first several data entries in |
| 5969 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 5970 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5971 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5972 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5973 | rc = iwl4965_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5974 | |
| 5975 | return rc; |
| 5976 | } |
| 5977 | |
| 5978 | |
| 5979 | /* check contents of special bootstrap uCode SRAM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5980 | static int iwl4965_verify_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5981 | { |
| 5982 | __le32 *image = priv->ucode_boot.v_addr; |
| 5983 | u32 len = priv->ucode_boot.len; |
| 5984 | u32 reg; |
| 5985 | u32 val; |
| 5986 | |
| 5987 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 5988 | |
| 5989 | /* verify BSM SRAM contents */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5990 | val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5991 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 5992 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 5993 | reg += sizeof(u32), image ++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5994 | val = iwl4965_read_prph(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5995 | if (val != le32_to_cpu(*image)) { |
| 5996 | IWL_ERROR("BSM uCode verification failed at " |
| 5997 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 5998 | BSM_SRAM_LOWER_BOUND, |
| 5999 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 6000 | val, le32_to_cpu(*image)); |
| 6001 | return -EIO; |
| 6002 | } |
| 6003 | } |
| 6004 | |
| 6005 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 6006 | |
| 6007 | return 0; |
| 6008 | } |
| 6009 | |
| 6010 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6011 | * iwl4965_load_bsm - Load bootstrap instructions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6012 | * |
| 6013 | * BSM operation: |
| 6014 | * |
| 6015 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 6016 | * in special SRAM that does not power down during RFKILL. When powering back |
| 6017 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 6018 | * the bootstrap program into the on-board processor, and starts it. |
| 6019 | * |
| 6020 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 6021 | * program from host DRAM locations indicated by the host driver in the |
| 6022 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 6023 | * automatically. |
| 6024 | * |
| 6025 | * When initializing the NIC, the host driver points the BSM to the |
| 6026 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 6027 | * notifies host via "initialize alive" that it is complete. |
| 6028 | * |
| 6029 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 6030 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 6031 | * (filled initially with starting data values for the on-board processor), |
| 6032 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 6033 | * which begins normal operation. |
| 6034 | * |
| 6035 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 6036 | * the backup data cache in DRAM before SRAM is powered down. |
| 6037 | * |
| 6038 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 6039 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 6040 | * and re-launches the runtime uCode from where it left off. |
| 6041 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6042 | static int iwl4965_load_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6043 | { |
| 6044 | __le32 *image = priv->ucode_boot.v_addr; |
| 6045 | u32 len = priv->ucode_boot.len; |
| 6046 | dma_addr_t pinst; |
| 6047 | dma_addr_t pdata; |
| 6048 | u32 inst_len; |
| 6049 | u32 data_len; |
| 6050 | int rc; |
| 6051 | int i; |
| 6052 | u32 done; |
| 6053 | u32 reg_offset; |
| 6054 | |
| 6055 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 6056 | |
| 6057 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 6058 | if (len > IWL_MAX_BSM_SIZE) |
| 6059 | return -EINVAL; |
| 6060 | |
| 6061 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6062 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6063 | * NOTE: iwl4965_initialize_alive_start() will replace these values, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6064 | * after the "initialize" uCode has run, to point to |
| 6065 | * runtime/protocol instructions and backup data cache. */ |
| 6066 | pinst = priv->ucode_init.p_addr >> 4; |
| 6067 | pdata = priv->ucode_init_data.p_addr >> 4; |
| 6068 | inst_len = priv->ucode_init.len; |
| 6069 | data_len = priv->ucode_init_data.len; |
| 6070 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6071 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6072 | if (rc) |
| 6073 | return rc; |
| 6074 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6075 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6076 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6077 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 6078 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6079 | |
| 6080 | /* Fill BSM memory with bootstrap instructions */ |
| 6081 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 6082 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 6083 | reg_offset += sizeof(u32), image++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6084 | _iwl4965_write_prph(priv, reg_offset, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6085 | le32_to_cpu(*image)); |
| 6086 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6087 | rc = iwl4965_verify_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6088 | if (rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6089 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6090 | return rc; |
| 6091 | } |
| 6092 | |
| 6093 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6094 | iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 6095 | iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6096 | RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6097 | iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6098 | |
| 6099 | /* Load bootstrap code into instruction SRAM now, |
| 6100 | * to prepare to load "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6101 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6102 | BSM_WR_CTRL_REG_BIT_START); |
| 6103 | |
| 6104 | /* Wait for load of bootstrap uCode to finish */ |
| 6105 | for (i = 0; i < 100; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6106 | done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6107 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 6108 | break; |
| 6109 | udelay(10); |
| 6110 | } |
| 6111 | if (i < 100) |
| 6112 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 6113 | else { |
| 6114 | IWL_ERROR("BSM write did not complete!\n"); |
| 6115 | return -EIO; |
| 6116 | } |
| 6117 | |
| 6118 | /* Enable future boot loads whenever power management unit triggers it |
| 6119 | * (e.g. when powering back up after power-save shutdown) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6120 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6121 | BSM_WR_CTRL_REG_BIT_START_EN); |
| 6122 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6123 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6124 | |
| 6125 | return 0; |
| 6126 | } |
| 6127 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6128 | static void iwl4965_nic_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6129 | { |
| 6130 | /* Remove all resets to allow NIC to operate */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6131 | iwl4965_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6132 | } |
| 6133 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6134 | static int iwl4965_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc) |
| 6135 | { |
| 6136 | desc->v_addr = pci_alloc_consistent(pci_dev, desc->len, &desc->p_addr); |
| 6137 | return (desc->v_addr != NULL) ? 0 : -ENOMEM; |
| 6138 | } |
| 6139 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6140 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6141 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6142 | * |
| 6143 | * Copy into buffers for card to fetch via bus-mastering |
| 6144 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6145 | static int iwl4965_read_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6146 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6147 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6148 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6149 | const struct firmware *ucode_raw; |
| 6150 | const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode"; |
| 6151 | u8 *src; |
| 6152 | size_t len; |
| 6153 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 6154 | |
| 6155 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 6156 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6157 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 6158 | if (ret < 0) { |
| 6159 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 6160 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6161 | goto error; |
| 6162 | } |
| 6163 | |
| 6164 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 6165 | name, ucode_raw->size); |
| 6166 | |
| 6167 | /* Make sure that we got at least our header! */ |
| 6168 | if (ucode_raw->size < sizeof(*ucode)) { |
| 6169 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6170 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6171 | goto err_release; |
| 6172 | } |
| 6173 | |
| 6174 | /* Data from ucode file: header followed by uCode images */ |
| 6175 | ucode = (void *)ucode_raw->data; |
| 6176 | |
| 6177 | ver = le32_to_cpu(ucode->ver); |
| 6178 | inst_size = le32_to_cpu(ucode->inst_size); |
| 6179 | data_size = le32_to_cpu(ucode->data_size); |
| 6180 | init_size = le32_to_cpu(ucode->init_size); |
| 6181 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 6182 | boot_size = le32_to_cpu(ucode->boot_size); |
| 6183 | |
| 6184 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 6185 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 6186 | inst_size); |
| 6187 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 6188 | data_size); |
| 6189 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 6190 | init_size); |
| 6191 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 6192 | init_data_size); |
| 6193 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 6194 | boot_size); |
| 6195 | |
| 6196 | /* Verify size of file vs. image size info in file's header */ |
| 6197 | if (ucode_raw->size < sizeof(*ucode) + |
| 6198 | inst_size + data_size + init_size + |
| 6199 | init_data_size + boot_size) { |
| 6200 | |
| 6201 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 6202 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6203 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6204 | goto err_release; |
| 6205 | } |
| 6206 | |
| 6207 | /* Verify that uCode images will fit in card's SRAM */ |
| 6208 | if (inst_size > IWL_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6209 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 6210 | inst_size); |
| 6211 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6212 | goto err_release; |
| 6213 | } |
| 6214 | |
| 6215 | if (data_size > IWL_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6216 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 6217 | data_size); |
| 6218 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6219 | goto err_release; |
| 6220 | } |
| 6221 | if (init_size > IWL_MAX_INST_SIZE) { |
| 6222 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6223 | ("uCode init instr len %d too large to fit in\n", |
| 6224 | init_size); |
| 6225 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6226 | goto err_release; |
| 6227 | } |
| 6228 | if (init_data_size > IWL_MAX_DATA_SIZE) { |
| 6229 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6230 | ("uCode init data len %d too large to fit in\n", |
| 6231 | init_data_size); |
| 6232 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6233 | goto err_release; |
| 6234 | } |
| 6235 | if (boot_size > IWL_MAX_BSM_SIZE) { |
| 6236 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6237 | ("uCode boot instr len %d too large to fit in\n", |
| 6238 | boot_size); |
| 6239 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6240 | goto err_release; |
| 6241 | } |
| 6242 | |
| 6243 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 6244 | |
| 6245 | /* Runtime instructions and 2 copies of data: |
| 6246 | * 1) unmodified from disk |
| 6247 | * 2) backup cache for save/restore during power-downs */ |
| 6248 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6249 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6250 | |
| 6251 | priv->ucode_data.len = data_size; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6252 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6253 | |
| 6254 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6255 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6256 | |
| 6257 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6258 | if (init_size && init_data_size) { |
| 6259 | priv->ucode_init.len = init_size; |
| 6260 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6261 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6262 | priv->ucode_init_data.len = init_data_size; |
| 6263 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 6264 | |
| 6265 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 6266 | goto err_pci_alloc; |
| 6267 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6268 | |
| 6269 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6270 | if (boot_size) { |
| 6271 | priv->ucode_boot.len = boot_size; |
| 6272 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6273 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6274 | if (!priv->ucode_boot.v_addr) |
| 6275 | goto err_pci_alloc; |
| 6276 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6277 | |
| 6278 | /* Copy images into buffers for card's bus-master reads ... */ |
| 6279 | |
| 6280 | /* Runtime instructions (first block of data in file) */ |
| 6281 | src = &ucode->data[0]; |
| 6282 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6283 | 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] | 6284 | memcpy(priv->ucode_code.v_addr, src, len); |
| 6285 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 6286 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 6287 | |
| 6288 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6289 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6290 | src = &ucode->data[inst_size]; |
| 6291 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6292 | 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] | 6293 | memcpy(priv->ucode_data.v_addr, src, len); |
| 6294 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 6295 | |
| 6296 | /* Initialization instructions (3rd block) */ |
| 6297 | if (init_size) { |
| 6298 | src = &ucode->data[inst_size + data_size]; |
| 6299 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6300 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 6301 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6302 | memcpy(priv->ucode_init.v_addr, src, len); |
| 6303 | } |
| 6304 | |
| 6305 | /* Initialization data (4th block) */ |
| 6306 | if (init_data_size) { |
| 6307 | src = &ucode->data[inst_size + data_size + init_size]; |
| 6308 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6309 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 6310 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6311 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 6312 | } |
| 6313 | |
| 6314 | /* Bootstrap instructions (5th block) */ |
| 6315 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 6316 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6317 | 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] | 6318 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 6319 | |
| 6320 | /* We have our copies now, allow OS release its copies */ |
| 6321 | release_firmware(ucode_raw); |
| 6322 | return 0; |
| 6323 | |
| 6324 | err_pci_alloc: |
| 6325 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6326 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6327 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6328 | |
| 6329 | err_release: |
| 6330 | release_firmware(ucode_raw); |
| 6331 | |
| 6332 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6333 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6334 | } |
| 6335 | |
| 6336 | |
| 6337 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6338 | * iwl4965_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6339 | * |
| 6340 | * Tell initialization uCode where to find runtime uCode. |
| 6341 | * |
| 6342 | * BSM registers initially contain pointers to initialization uCode. |
| 6343 | * We need to replace them to load runtime uCode inst and data, |
| 6344 | * and to save runtime data when powering down. |
| 6345 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6346 | static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6347 | { |
| 6348 | dma_addr_t pinst; |
| 6349 | dma_addr_t pdata; |
| 6350 | int rc = 0; |
| 6351 | unsigned long flags; |
| 6352 | |
| 6353 | /* bits 35:4 for 4965 */ |
| 6354 | pinst = priv->ucode_code.p_addr >> 4; |
| 6355 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 6356 | |
| 6357 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6358 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6359 | if (rc) { |
| 6360 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6361 | return rc; |
| 6362 | } |
| 6363 | |
| 6364 | /* Tell bootstrap uCode where to find image to load */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6365 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6366 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6367 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6368 | priv->ucode_data.len); |
| 6369 | |
| 6370 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 6371 | * that all new ptr/size info is in place */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6372 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6373 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 6374 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6375 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6376 | |
| 6377 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6378 | |
| 6379 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 6380 | |
| 6381 | return rc; |
| 6382 | } |
| 6383 | |
| 6384 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6385 | * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6386 | * |
| 6387 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 6388 | * |
| 6389 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 6390 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 6391 | * (3945 does not contain this data). |
| 6392 | * |
| 6393 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 6394 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6395 | static void iwl4965_init_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6396 | { |
| 6397 | /* Check alive response for "valid" sign from uCode */ |
| 6398 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 6399 | /* We had an error bringing up the hardware, so take it |
| 6400 | * all the way back down so we can try again */ |
| 6401 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 6402 | goto restart; |
| 6403 | } |
| 6404 | |
| 6405 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 6406 | * This is a paranoid check, because we would not have gotten the |
| 6407 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6408 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6409 | /* Runtime instruction load was bad; |
| 6410 | * take it all the way back down so we can try again */ |
| 6411 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 6412 | goto restart; |
| 6413 | } |
| 6414 | |
| 6415 | /* Calculate temperature */ |
| 6416 | priv->temperature = iwl4965_get_temperature(priv); |
| 6417 | |
| 6418 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 6419 | * load and launch runtime uCode, which will send us another "Alive" |
| 6420 | * notification. */ |
| 6421 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6422 | if (iwl4965_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6423 | /* Runtime instruction load won't happen; |
| 6424 | * take it all the way back down so we can try again */ |
| 6425 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 6426 | goto restart; |
| 6427 | } |
| 6428 | return; |
| 6429 | |
| 6430 | restart: |
| 6431 | queue_work(priv->workqueue, &priv->restart); |
| 6432 | } |
| 6433 | |
| 6434 | |
| 6435 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6436 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6437 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6438 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6439 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6440 | static void iwl4965_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6441 | { |
| 6442 | int rc = 0; |
| 6443 | |
| 6444 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 6445 | |
| 6446 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 6447 | /* We had an error bringing up the hardware, so take it |
| 6448 | * all the way back down so we can try again */ |
| 6449 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 6450 | goto restart; |
| 6451 | } |
| 6452 | |
| 6453 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 6454 | * This is a paranoid check, because we would not have gotten the |
| 6455 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6456 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6457 | /* Runtime instruction load was bad; |
| 6458 | * take it all the way back down so we can try again */ |
| 6459 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 6460 | goto restart; |
| 6461 | } |
| 6462 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6463 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6464 | |
| 6465 | rc = iwl4965_alive_notify(priv); |
| 6466 | if (rc) { |
| 6467 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
| 6468 | rc); |
| 6469 | goto restart; |
| 6470 | } |
| 6471 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6472 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6473 | set_bit(STATUS_ALIVE, &priv->status); |
| 6474 | |
| 6475 | /* Clear out the uCode error bit if it is set */ |
| 6476 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 6477 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6478 | rc = iwl4965_init_channel_map(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6479 | if (rc) { |
| 6480 | IWL_ERROR("initializing regulatory failed: %d\n", rc); |
| 6481 | return; |
| 6482 | } |
| 6483 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6484 | iwl4965_init_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6485 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6486 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6487 | return; |
| 6488 | |
| 6489 | if (!priv->mac80211_registered) { |
| 6490 | /* Unlock so any user space entry points can call back into |
| 6491 | * the driver without a deadlock... */ |
| 6492 | mutex_unlock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6493 | iwl4965_rate_control_register(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6494 | rc = ieee80211_register_hw(priv->hw); |
| 6495 | priv->hw->conf.beacon_int = 100; |
| 6496 | mutex_lock(&priv->mutex); |
| 6497 | |
| 6498 | if (rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6499 | iwl4965_rate_control_unregister(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6500 | IWL_ERROR("Failed to register network " |
| 6501 | "device (error %d)\n", rc); |
| 6502 | return; |
| 6503 | } |
| 6504 | |
| 6505 | priv->mac80211_registered = 1; |
| 6506 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6507 | iwl4965_reset_channel_flag(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6508 | } else |
| 6509 | ieee80211_start_queues(priv->hw); |
| 6510 | |
| 6511 | priv->active_rate = priv->rates_mask; |
| 6512 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 6513 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6514 | iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6515 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6516 | if (iwl4965_is_associated(priv)) { |
| 6517 | struct iwl4965_rxon_cmd *active_rxon = |
| 6518 | (struct iwl4965_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6519 | |
| 6520 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 6521 | sizeof(priv->staging_rxon)); |
| 6522 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 6523 | } else { |
| 6524 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6525 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6526 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 6527 | } |
| 6528 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6529 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6530 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6531 | |
| 6532 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6533 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6534 | |
| 6535 | /* At this point, the NIC is initialized and operational */ |
| 6536 | priv->notif_missed_beacons = 0; |
| 6537 | set_bit(STATUS_READY, &priv->status); |
| 6538 | |
| 6539 | iwl4965_rf_kill_ct_config(priv); |
| 6540 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
| 6541 | |
| 6542 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6543 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6544 | |
| 6545 | return; |
| 6546 | |
| 6547 | restart: |
| 6548 | queue_work(priv->workqueue, &priv->restart); |
| 6549 | } |
| 6550 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6551 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6552 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6553 | static void __iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6554 | { |
| 6555 | unsigned long flags; |
| 6556 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6557 | struct ieee80211_conf *conf = NULL; |
| 6558 | |
| 6559 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 6560 | |
| 6561 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6562 | |
| 6563 | if (!exit_pending) |
| 6564 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6565 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6566 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6567 | |
| 6568 | /* Unblock any waiting calls */ |
| 6569 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 6570 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6571 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 6572 | * exiting the module */ |
| 6573 | if (!exit_pending) |
| 6574 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6575 | |
| 6576 | /* stop and reset the on-board processor */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6577 | iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6578 | |
| 6579 | /* tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6580 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6581 | |
| 6582 | if (priv->mac80211_registered) |
| 6583 | ieee80211_stop_queues(priv->hw); |
| 6584 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6585 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6586 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6587 | if (!iwl4965_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6588 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6589 | STATUS_RF_KILL_HW | |
| 6590 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6591 | STATUS_RF_KILL_SW | |
| 6592 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6593 | STATUS_IN_SUSPEND; |
| 6594 | goto exit; |
| 6595 | } |
| 6596 | |
| 6597 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 6598 | * SUSPEND bits and continue taking the NIC down. */ |
| 6599 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6600 | STATUS_RF_KILL_HW | |
| 6601 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6602 | STATUS_RF_KILL_SW | |
| 6603 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6604 | STATUS_IN_SUSPEND | |
| 6605 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 6606 | STATUS_FW_ERROR; |
| 6607 | |
| 6608 | spin_lock_irqsave(&priv->lock, flags); |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6609 | iwl4965_clear_bit(priv, CSR_GP_CNTRL, |
| 6610 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6611 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6612 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6613 | iwl4965_hw_txq_ctx_stop(priv); |
| 6614 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6615 | |
| 6616 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6617 | if (!iwl4965_grab_nic_access(priv)) { |
| 6618 | iwl4965_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6619 | APMG_CLK_VAL_DMA_CLK_RQT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6620 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6621 | } |
| 6622 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6623 | |
| 6624 | udelay(5); |
| 6625 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6626 | iwl4965_hw_nic_stop_master(priv); |
| 6627 | iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
| 6628 | iwl4965_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6629 | |
| 6630 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6631 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6632 | |
| 6633 | if (priv->ibss_beacon) |
| 6634 | dev_kfree_skb(priv->ibss_beacon); |
| 6635 | priv->ibss_beacon = NULL; |
| 6636 | |
| 6637 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6638 | iwl4965_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6639 | } |
| 6640 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6641 | static void iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6642 | { |
| 6643 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6644 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6645 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6646 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6647 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6648 | } |
| 6649 | |
| 6650 | #define MAX_HW_RESTARTS 5 |
| 6651 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6652 | static int __iwl4965_up(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6653 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6654 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6655 | int rc, i; |
| 6656 | u32 hw_rf_kill = 0; |
| 6657 | |
| 6658 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6659 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 6660 | return -EIO; |
| 6661 | } |
| 6662 | |
| 6663 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 6664 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 6665 | "parameter)\n"); |
| 6666 | return 0; |
| 6667 | } |
| 6668 | |
Reinette Chatre | a781cf9 | 2008-01-21 10:08:31 -0800 | [diff] [blame] | 6669 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 6670 | IWL_ERROR("ucode not available for device bringup\n"); |
| 6671 | return -EIO; |
| 6672 | } |
| 6673 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6674 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6675 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6676 | rc = iwl4965_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6677 | if (rc) { |
| 6678 | IWL_ERROR("Unable to int nic\n"); |
| 6679 | return rc; |
| 6680 | } |
| 6681 | |
| 6682 | /* make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6683 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6684 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6685 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 6686 | |
| 6687 | /* clear (again), then enable host interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6688 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 6689 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6690 | |
| 6691 | /* really make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6692 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6693 | 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] | 6694 | |
| 6695 | /* Copy original ucode data image from disk into backup cache. |
| 6696 | * This will be used to initialize the on-board processor's |
| 6697 | * data SRAM for a clean start when the runtime program first loads. */ |
| 6698 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
| 6699 | priv->ucode_data.len); |
| 6700 | |
| 6701 | /* If platform's RF_KILL switch is set to KILL, |
| 6702 | * wait for BIT_INT_RF_KILL interrupt before loading uCode |
| 6703 | * and getting things started */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6704 | if (!(iwl4965_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6705 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 6706 | hw_rf_kill = 1; |
| 6707 | |
| 6708 | if (test_bit(STATUS_RF_KILL_HW, &priv->status) || hw_rf_kill) { |
| 6709 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 6710 | return 0; |
| 6711 | } |
| 6712 | |
| 6713 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 6714 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6715 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6716 | |
| 6717 | /* load bootstrap state machine, |
| 6718 | * load bootstrap program into processor's memory, |
| 6719 | * prepare to load the "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6720 | rc = iwl4965_load_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6721 | |
| 6722 | if (rc) { |
| 6723 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); |
| 6724 | continue; |
| 6725 | } |
| 6726 | |
| 6727 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6728 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6729 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6730 | /* MAC Address location in EEPROM is same for 3945/4965 */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6731 | get_eeprom_mac(priv, priv->mac_addr); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6732 | IWL_DEBUG_INFO("MAC address: %s\n", |
| 6733 | print_mac(mac, priv->mac_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6734 | |
| 6735 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 6736 | |
| 6737 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 6738 | |
| 6739 | return 0; |
| 6740 | } |
| 6741 | |
| 6742 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6743 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6744 | |
| 6745 | /* tried to restart and config the device for as long as our |
| 6746 | * patience could withstand */ |
| 6747 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 6748 | return -EIO; |
| 6749 | } |
| 6750 | |
| 6751 | |
| 6752 | /***************************************************************************** |
| 6753 | * |
| 6754 | * Workqueue callbacks |
| 6755 | * |
| 6756 | *****************************************************************************/ |
| 6757 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6758 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6759 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6760 | struct iwl4965_priv *priv = |
| 6761 | container_of(data, struct iwl4965_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6762 | |
| 6763 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6764 | return; |
| 6765 | |
| 6766 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6767 | iwl4965_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6768 | mutex_unlock(&priv->mutex); |
| 6769 | } |
| 6770 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6771 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6772 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6773 | struct iwl4965_priv *priv = |
| 6774 | container_of(data, struct iwl4965_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6775 | |
| 6776 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6777 | return; |
| 6778 | |
| 6779 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6780 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6781 | mutex_unlock(&priv->mutex); |
| 6782 | } |
| 6783 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6784 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6785 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6786 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6787 | |
| 6788 | wake_up_interruptible(&priv->wait_command_queue); |
| 6789 | |
| 6790 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6791 | return; |
| 6792 | |
| 6793 | mutex_lock(&priv->mutex); |
| 6794 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6795 | if (!iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6796 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 6797 | "HW and/or SW RF Kill no longer active, restarting " |
| 6798 | "device\n"); |
| 6799 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6800 | queue_work(priv->workqueue, &priv->restart); |
| 6801 | } else { |
| 6802 | |
| 6803 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 6804 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 6805 | "disabled by SW switch\n"); |
| 6806 | else |
| 6807 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 6808 | "Kill switch must be turned off for " |
| 6809 | "wireless networking to work.\n"); |
| 6810 | } |
| 6811 | mutex_unlock(&priv->mutex); |
| 6812 | } |
| 6813 | |
| 6814 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 6815 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6816 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6817 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6818 | struct iwl4965_priv *priv = |
| 6819 | container_of(data, struct iwl4965_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6820 | |
| 6821 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6822 | return; |
| 6823 | |
| 6824 | mutex_lock(&priv->mutex); |
| 6825 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 6826 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6827 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 6828 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 6829 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6830 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6831 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6832 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6833 | } |
| 6834 | mutex_unlock(&priv->mutex); |
| 6835 | } |
| 6836 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6837 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6838 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6839 | struct iwl4965_priv *priv = |
| 6840 | container_of(data, struct iwl4965_priv, request_scan); |
| 6841 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6842 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6843 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6844 | .meta.flags = CMD_SIZE_HUGE, |
| 6845 | }; |
| 6846 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6847 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6848 | struct ieee80211_conf *conf = NULL; |
| 6849 | u8 direct_mask; |
| 6850 | int phymode; |
| 6851 | |
| 6852 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6853 | |
| 6854 | mutex_lock(&priv->mutex); |
| 6855 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6856 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6857 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 6858 | goto done; |
| 6859 | } |
| 6860 | |
| 6861 | /* Make sure the scan wasn't cancelled before this queued work |
| 6862 | * was given the chance to run... */ |
| 6863 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 6864 | goto done; |
| 6865 | |
| 6866 | /* This should never be called or scheduled if there is currently |
| 6867 | * a scan active in the hardware. */ |
| 6868 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 6869 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 6870 | "Ignoring second request.\n"); |
| 6871 | rc = -EIO; |
| 6872 | goto done; |
| 6873 | } |
| 6874 | |
| 6875 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6876 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 6877 | goto done; |
| 6878 | } |
| 6879 | |
| 6880 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6881 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6882 | goto done; |
| 6883 | } |
| 6884 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6885 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6886 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6887 | goto done; |
| 6888 | } |
| 6889 | |
| 6890 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 6891 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 6892 | goto done; |
| 6893 | } |
| 6894 | |
| 6895 | if (!priv->scan_bands) { |
| 6896 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 6897 | goto done; |
| 6898 | } |
| 6899 | |
| 6900 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6901 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6902 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 6903 | if (!priv->scan) { |
| 6904 | rc = -ENOMEM; |
| 6905 | goto done; |
| 6906 | } |
| 6907 | } |
| 6908 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6909 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6910 | |
| 6911 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 6912 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 6913 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6914 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6915 | u16 interval = 0; |
| 6916 | u32 extra; |
| 6917 | u32 suspend_time = 100; |
| 6918 | u32 scan_suspend_time = 100; |
| 6919 | unsigned long flags; |
| 6920 | |
| 6921 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 6922 | |
| 6923 | spin_lock_irqsave(&priv->lock, flags); |
| 6924 | interval = priv->beacon_int; |
| 6925 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6926 | |
| 6927 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6928 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6929 | if (!interval) |
| 6930 | interval = suspend_time; |
| 6931 | |
| 6932 | extra = (suspend_time / interval) << 22; |
| 6933 | scan_suspend_time = (extra | |
| 6934 | ((suspend_time % interval) * 1024)); |
| 6935 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 6936 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 6937 | scan_suspend_time, interval); |
| 6938 | } |
| 6939 | |
| 6940 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 6941 | if (priv->one_direct_scan) { |
| 6942 | IWL_DEBUG_SCAN |
| 6943 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6944 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6945 | priv->direct_ssid_len)); |
| 6946 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6947 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 6948 | memcpy(scan->direct_scan[0].ssid, |
| 6949 | priv->direct_ssid, priv->direct_ssid_len); |
| 6950 | direct_mask = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6951 | } else if (!iwl4965_is_associated(priv) && priv->essid_len) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6952 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6953 | scan->direct_scan[0].len = priv->essid_len; |
| 6954 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 6955 | direct_mask = 1; |
| 6956 | } else |
| 6957 | direct_mask = 0; |
| 6958 | |
| 6959 | /* We don't build a direct scan probe request; the uCode will do |
| 6960 | * that based on the direct_mask added to each channel entry */ |
| 6961 | scan->tx_cmd.len = cpu_to_le16( |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6962 | iwl4965_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6963 | IWL_MAX_SCAN_SIZE - sizeof(scan), 0)); |
| 6964 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 6965 | scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; |
| 6966 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 6967 | |
| 6968 | /* flags + rate selection */ |
| 6969 | |
| 6970 | scan->tx_cmd.tx_flags |= cpu_to_le32(0x200); |
| 6971 | |
| 6972 | switch (priv->scan_bands) { |
| 6973 | case 2: |
| 6974 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 6975 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6976 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6977 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 6978 | |
| 6979 | scan->good_CRC_th = 0; |
| 6980 | phymode = MODE_IEEE80211G; |
| 6981 | break; |
| 6982 | |
| 6983 | case 1: |
| 6984 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6985 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6986 | RATE_MCS_ANT_B_MSK); |
| 6987 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
| 6988 | phymode = MODE_IEEE80211A; |
| 6989 | break; |
| 6990 | |
| 6991 | default: |
| 6992 | IWL_WARNING("Invalid scan band count\n"); |
| 6993 | goto done; |
| 6994 | } |
| 6995 | |
| 6996 | /* select Rx chains */ |
| 6997 | |
| 6998 | /* Force use of chains B and C (0x6) for scan Rx. |
| 6999 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 7000 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 7001 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 7002 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 7003 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 7004 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 7005 | |
| 7006 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 7007 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 7008 | |
| 7009 | if (direct_mask) |
| 7010 | IWL_DEBUG_SCAN |
| 7011 | ("Initiating direct scan for %s.\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7012 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7013 | else |
| 7014 | IWL_DEBUG_SCAN("Initiating indirect scan.\n"); |
| 7015 | |
| 7016 | scan->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7017 | iwl4965_get_channels_for_scan( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7018 | priv, phymode, 1, /* active */ |
| 7019 | direct_mask, |
| 7020 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
| 7021 | |
| 7022 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7023 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7024 | cmd.data = scan; |
| 7025 | scan->len = cpu_to_le16(cmd.len); |
| 7026 | |
| 7027 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7028 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7029 | if (rc) |
| 7030 | goto done; |
| 7031 | |
| 7032 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 7033 | IWL_SCAN_CHECK_WATCHDOG); |
| 7034 | |
| 7035 | mutex_unlock(&priv->mutex); |
| 7036 | return; |
| 7037 | |
| 7038 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 7039 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7040 | queue_work(priv->workqueue, &priv->scan_completed); |
| 7041 | mutex_unlock(&priv->mutex); |
| 7042 | } |
| 7043 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7044 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7045 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7046 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7047 | |
| 7048 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7049 | return; |
| 7050 | |
| 7051 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7052 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7053 | mutex_unlock(&priv->mutex); |
| 7054 | } |
| 7055 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7056 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7057 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7058 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7059 | |
| 7060 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7061 | return; |
| 7062 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7063 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7064 | queue_work(priv->workqueue, &priv->up); |
| 7065 | } |
| 7066 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7067 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7068 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7069 | struct iwl4965_priv *priv = |
| 7070 | container_of(data, struct iwl4965_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7071 | |
| 7072 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7073 | return; |
| 7074 | |
| 7075 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7076 | iwl4965_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7077 | mutex_unlock(&priv->mutex); |
| 7078 | } |
| 7079 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7080 | static void iwl4965_bg_post_associate(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7081 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7082 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7083 | post_associate.work); |
| 7084 | |
| 7085 | int rc = 0; |
| 7086 | struct ieee80211_conf *conf = NULL; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7087 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7088 | |
| 7089 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7090 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 7091 | return; |
| 7092 | } |
| 7093 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7094 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 7095 | priv->assoc_id, |
| 7096 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7097 | |
| 7098 | |
| 7099 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7100 | return; |
| 7101 | |
| 7102 | mutex_lock(&priv->mutex); |
| 7103 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7104 | if (!priv->interface_id || !priv->is_open) { |
| 7105 | mutex_unlock(&priv->mutex); |
| 7106 | return; |
| 7107 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7108 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7109 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7110 | conf = ieee80211_get_hw_conf(priv->hw); |
| 7111 | |
| 7112 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7113 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7114 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7115 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7116 | iwl4965_setup_rxon_timing(priv); |
| 7117 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7118 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7119 | if (rc) |
| 7120 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7121 | "Attempting to continue.\n"); |
| 7122 | |
| 7123 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 7124 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7125 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7126 | if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht) |
| 7127 | iwl4965_set_rxon_ht(priv, &priv->current_assoc_ht); |
| 7128 | else { |
| 7129 | priv->active_rate_ht[0] = 0; |
| 7130 | priv->active_rate_ht[1] = 0; |
| 7131 | priv->current_channel_width = IWL_CHANNEL_WIDTH_20MHZ; |
| 7132 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7133 | #endif /* CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7134 | iwl4965_set_rxon_chain(priv); |
| 7135 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7136 | |
| 7137 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 7138 | priv->assoc_id, priv->beacon_int); |
| 7139 | |
| 7140 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7141 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7142 | else |
| 7143 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7144 | |
| 7145 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7146 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7147 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 7148 | else |
| 7149 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7150 | |
| 7151 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7152 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7153 | |
| 7154 | } |
| 7155 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7156 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7157 | |
| 7158 | switch (priv->iw_mode) { |
| 7159 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7160 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7161 | break; |
| 7162 | |
| 7163 | case IEEE80211_IF_TYPE_IBSS: |
| 7164 | |
| 7165 | /* clear out the station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7166 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7167 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7168 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
| 7169 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 7170 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 7171 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7172 | |
| 7173 | break; |
| 7174 | |
| 7175 | default: |
| 7176 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 7177 | __FUNCTION__, priv->iw_mode); |
| 7178 | break; |
| 7179 | } |
| 7180 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7181 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7182 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7183 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7184 | /* Enable Rx differential gain and sensitivity calibrations */ |
| 7185 | iwl4965_chain_noise_reset(priv); |
| 7186 | priv->start_calib = 1; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7187 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7188 | |
| 7189 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7190 | priv->assoc_station_added = 1; |
| 7191 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7192 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7193 | iwl4965_activate_qos(priv, 0); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7194 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7195 | mutex_unlock(&priv->mutex); |
| 7196 | } |
| 7197 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7198 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7199 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7200 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7201 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7202 | if (!iwl4965_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7203 | return; |
| 7204 | |
| 7205 | mutex_lock(&priv->mutex); |
| 7206 | |
| 7207 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7208 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7209 | |
| 7210 | mutex_unlock(&priv->mutex); |
| 7211 | } |
| 7212 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7213 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7214 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7215 | struct iwl4965_priv *priv = |
| 7216 | container_of(work, struct iwl4965_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7217 | |
| 7218 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 7219 | |
| 7220 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7221 | return; |
| 7222 | |
| 7223 | ieee80211_scan_completed(priv->hw); |
| 7224 | |
| 7225 | /* Since setting the TXPOWER may have been deferred while |
| 7226 | * performing the scan, fire one off */ |
| 7227 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7228 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7229 | mutex_unlock(&priv->mutex); |
| 7230 | } |
| 7231 | |
| 7232 | /***************************************************************************** |
| 7233 | * |
| 7234 | * mac80211 entry point functions |
| 7235 | * |
| 7236 | *****************************************************************************/ |
| 7237 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7238 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7239 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7240 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7241 | |
| 7242 | IWL_DEBUG_MAC80211("enter\n"); |
| 7243 | |
| 7244 | /* we should be verifying the device is ready to be opened */ |
| 7245 | mutex_lock(&priv->mutex); |
| 7246 | |
| 7247 | priv->is_open = 1; |
| 7248 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7249 | if (!iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7250 | ieee80211_start_queues(priv->hw); |
| 7251 | |
| 7252 | mutex_unlock(&priv->mutex); |
| 7253 | IWL_DEBUG_MAC80211("leave\n"); |
| 7254 | return 0; |
| 7255 | } |
| 7256 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7257 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7258 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7259 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7260 | |
| 7261 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7262 | |
| 7263 | |
| 7264 | mutex_lock(&priv->mutex); |
| 7265 | /* stop mac, cancel any scan request and clear |
| 7266 | * RXON_FILTER_ASSOC_MSK BIT |
| 7267 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7268 | priv->is_open = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7269 | iwl4965_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7270 | cancel_delayed_work(&priv->post_associate); |
| 7271 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7272 | iwl4965_commit_rxon(priv); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7273 | mutex_unlock(&priv->mutex); |
| 7274 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7275 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7276 | } |
| 7277 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7278 | 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] | 7279 | struct ieee80211_tx_control *ctl) |
| 7280 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7281 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7282 | |
| 7283 | IWL_DEBUG_MAC80211("enter\n"); |
| 7284 | |
| 7285 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 7286 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 7287 | return -1; |
| 7288 | } |
| 7289 | |
| 7290 | IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
| 7291 | ctl->tx_rate); |
| 7292 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7293 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7294 | dev_kfree_skb_any(skb); |
| 7295 | |
| 7296 | IWL_DEBUG_MAC80211("leave\n"); |
| 7297 | return 0; |
| 7298 | } |
| 7299 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7300 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7301 | struct ieee80211_if_init_conf *conf) |
| 7302 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7303 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7304 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7305 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7306 | |
| 7307 | IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7308 | |
| 7309 | if (priv->interface_id) { |
| 7310 | IWL_DEBUG_MAC80211("leave - interface_id != 0\n"); |
| 7311 | return 0; |
| 7312 | } |
| 7313 | |
| 7314 | spin_lock_irqsave(&priv->lock, flags); |
| 7315 | priv->interface_id = conf->if_id; |
| 7316 | |
| 7317 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7318 | |
| 7319 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 7320 | |
| 7321 | if (conf->mac_addr) { |
| 7322 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 7323 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 7324 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7325 | iwl4965_set_mode(priv, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7326 | |
| 7327 | IWL_DEBUG_MAC80211("leave\n"); |
| 7328 | mutex_unlock(&priv->mutex); |
| 7329 | |
| 7330 | return 0; |
| 7331 | } |
| 7332 | |
| 7333 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7334 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7335 | * |
| 7336 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 7337 | * be set inappropriately and the driver currently sets the hardware up to |
| 7338 | * use it whenever needed. |
| 7339 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7340 | 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] | 7341 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7342 | struct iwl4965_priv *priv = hw->priv; |
| 7343 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7344 | unsigned long flags; |
| 7345 | |
| 7346 | mutex_lock(&priv->mutex); |
| 7347 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel); |
| 7348 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7349 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7350 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 7351 | mutex_unlock(&priv->mutex); |
| 7352 | return -EIO; |
| 7353 | } |
| 7354 | |
| 7355 | /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 7356 | * what is exposed through include/ declarations */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7357 | if (unlikely(!iwl4965_param_disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7358 | test_bit(STATUS_SCANNING, &priv->status))) { |
| 7359 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7360 | mutex_unlock(&priv->mutex); |
| 7361 | return 0; |
| 7362 | } |
| 7363 | |
| 7364 | spin_lock_irqsave(&priv->lock, flags); |
| 7365 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7366 | ch_info = iwl4965_get_channel_info(priv, conf->phymode, conf->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7367 | if (!is_channel_valid(ch_info)) { |
| 7368 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n", |
| 7369 | conf->channel, conf->phymode); |
| 7370 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 7371 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7372 | mutex_unlock(&priv->mutex); |
| 7373 | return -EINVAL; |
| 7374 | } |
| 7375 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7376 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7377 | /* if we are switching fron ht to 2.4 clear flags |
| 7378 | * from any ht related info since 2.4 does not |
| 7379 | * support ht */ |
| 7380 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel) |
| 7381 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7382 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 7383 | #endif |
| 7384 | ) |
| 7385 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7386 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7387 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7388 | iwl4965_set_rxon_channel(priv, conf->phymode, conf->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7389 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7390 | iwl4965_set_flags_for_phymode(priv, conf->phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7391 | |
| 7392 | /* The list of supported rates and rate mask can be different |
| 7393 | * for each phymode; since the phymode may have changed, reset |
| 7394 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7395 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7396 | |
| 7397 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7398 | |
| 7399 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7400 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7401 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7402 | mutex_unlock(&priv->mutex); |
| 7403 | return 0; |
| 7404 | } |
| 7405 | #endif |
| 7406 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7407 | iwl4965_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7408 | |
| 7409 | if (!conf->radio_enabled) { |
| 7410 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
| 7411 | mutex_unlock(&priv->mutex); |
| 7412 | return 0; |
| 7413 | } |
| 7414 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7415 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7416 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
| 7417 | mutex_unlock(&priv->mutex); |
| 7418 | return -EIO; |
| 7419 | } |
| 7420 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7421 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7422 | |
| 7423 | if (memcmp(&priv->active_rxon, |
| 7424 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7425 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7426 | else |
| 7427 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 7428 | |
| 7429 | IWL_DEBUG_MAC80211("leave\n"); |
| 7430 | |
| 7431 | mutex_unlock(&priv->mutex); |
| 7432 | |
| 7433 | return 0; |
| 7434 | } |
| 7435 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7436 | static void iwl4965_config_ap(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7437 | { |
| 7438 | int rc = 0; |
| 7439 | |
| 7440 | if (priv->status & STATUS_EXIT_PENDING) |
| 7441 | return; |
| 7442 | |
| 7443 | /* The following should be done only at AP bring up */ |
| 7444 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 7445 | |
| 7446 | /* RXON - unassoc (to set timing command) */ |
| 7447 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7448 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7449 | |
| 7450 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7451 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7452 | iwl4965_setup_rxon_timing(priv); |
| 7453 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7454 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7455 | if (rc) |
| 7456 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7457 | "Attempting to continue.\n"); |
| 7458 | |
| 7459 | iwl4965_set_rxon_chain(priv); |
| 7460 | |
| 7461 | /* FIXME: what should be the assoc_id for AP? */ |
| 7462 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7463 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7464 | priv->staging_rxon.flags |= |
| 7465 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7466 | else |
| 7467 | priv->staging_rxon.flags &= |
| 7468 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7469 | |
| 7470 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7471 | if (priv->assoc_capability & |
| 7472 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7473 | priv->staging_rxon.flags |= |
| 7474 | RXON_FLG_SHORT_SLOT_MSK; |
| 7475 | else |
| 7476 | priv->staging_rxon.flags &= |
| 7477 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7478 | |
| 7479 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7480 | priv->staging_rxon.flags &= |
| 7481 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7482 | } |
| 7483 | /* restore RXON assoc */ |
| 7484 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7485 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7486 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7487 | iwl4965_activate_qos(priv, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7488 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7489 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 7490 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7491 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7492 | |
| 7493 | /* FIXME - we need to add code here to detect a totally new |
| 7494 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 7495 | * clear sta table, add BCAST sta... */ |
| 7496 | } |
| 7497 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7498 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, int if_id, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7499 | struct ieee80211_if_conf *conf) |
| 7500 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7501 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7502 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7503 | unsigned long flags; |
| 7504 | int rc; |
| 7505 | |
| 7506 | if (conf == NULL) |
| 7507 | return -EIO; |
| 7508 | |
| 7509 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 7510 | (!conf->beacon || !conf->ssid_len)) { |
| 7511 | IWL_DEBUG_MAC80211 |
| 7512 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 7513 | return 0; |
| 7514 | } |
| 7515 | |
| 7516 | mutex_lock(&priv->mutex); |
| 7517 | |
| 7518 | IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id); |
| 7519 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7520 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 7521 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7522 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7523 | /* |
| 7524 | * very dubious code was here; the probe filtering flag is never set: |
| 7525 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7526 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 7527 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7528 | */ |
| 7529 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7530 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7531 | mutex_unlock(&priv->mutex); |
| 7532 | return 0; |
| 7533 | } |
| 7534 | |
| 7535 | if (priv->interface_id != if_id) { |
| 7536 | IWL_DEBUG_MAC80211("leave - interface_id != if_id\n"); |
| 7537 | mutex_unlock(&priv->mutex); |
| 7538 | return 0; |
| 7539 | } |
| 7540 | |
| 7541 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7542 | if (!conf->bssid) { |
| 7543 | conf->bssid = priv->mac_addr; |
| 7544 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7545 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 7546 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7547 | } |
| 7548 | if (priv->ibss_beacon) |
| 7549 | dev_kfree_skb(priv->ibss_beacon); |
| 7550 | |
| 7551 | priv->ibss_beacon = conf->beacon; |
| 7552 | } |
| 7553 | |
| 7554 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 7555 | !is_multicast_ether_addr(conf->bssid)) { |
| 7556 | /* If there is currently a HW scan going on in the background |
| 7557 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7558 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7559 | IWL_WARNING("Aborted scan still in progress " |
| 7560 | "after 100ms\n"); |
| 7561 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 7562 | mutex_unlock(&priv->mutex); |
| 7563 | return -EAGAIN; |
| 7564 | } |
| 7565 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 7566 | |
| 7567 | /* TODO: Audit driver for usage of these members and see |
| 7568 | * if mac80211 deprecates them (priv->bssid looks like it |
| 7569 | * shouldn't be there, but I haven't scanned the IBSS code |
| 7570 | * to verify) - jpk */ |
| 7571 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 7572 | |
| 7573 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7574 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7575 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7576 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7577 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7578 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7579 | priv, priv->active_rxon.bssid_addr, 1); |
| 7580 | } |
| 7581 | |
| 7582 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7583 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7584 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7585 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7586 | } |
| 7587 | |
| 7588 | spin_lock_irqsave(&priv->lock, flags); |
| 7589 | if (!conf->ssid_len) |
| 7590 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7591 | else |
| 7592 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 7593 | |
| 7594 | priv->essid_len = conf->ssid_len; |
| 7595 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7596 | |
| 7597 | IWL_DEBUG_MAC80211("leave\n"); |
| 7598 | mutex_unlock(&priv->mutex); |
| 7599 | |
| 7600 | return 0; |
| 7601 | } |
| 7602 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7603 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7604 | unsigned int changed_flags, |
| 7605 | unsigned int *total_flags, |
| 7606 | int mc_count, struct dev_addr_list *mc_list) |
| 7607 | { |
| 7608 | /* |
| 7609 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7610 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7611 | */ |
| 7612 | *total_flags = 0; |
| 7613 | } |
| 7614 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7615 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7616 | struct ieee80211_if_init_conf *conf) |
| 7617 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7618 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7619 | |
| 7620 | IWL_DEBUG_MAC80211("enter\n"); |
| 7621 | |
| 7622 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7623 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7624 | iwl4965_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7625 | cancel_delayed_work(&priv->post_associate); |
| 7626 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7627 | iwl4965_commit_rxon(priv); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7628 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7629 | if (priv->interface_id == conf->if_id) { |
| 7630 | priv->interface_id = 0; |
| 7631 | memset(priv->bssid, 0, ETH_ALEN); |
| 7632 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7633 | priv->essid_len = 0; |
| 7634 | } |
| 7635 | mutex_unlock(&priv->mutex); |
| 7636 | |
| 7637 | IWL_DEBUG_MAC80211("leave\n"); |
| 7638 | |
| 7639 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7640 | static void iwl4965_mac_erp_ie_changed(struct ieee80211_hw *hw, |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7641 | u8 changes, int cts_protection, int preamble) |
| 7642 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7643 | struct iwl4965_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7644 | |
| 7645 | if (changes & IEEE80211_ERP_CHANGE_PREAMBLE) { |
| 7646 | if (preamble == WLAN_ERP_PREAMBLE_SHORT) |
| 7647 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7648 | else |
| 7649 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7650 | } |
| 7651 | |
| 7652 | if (changes & IEEE80211_ERP_CHANGE_PROTECTION) { |
Zhu Yi | 797a54c | 2007-11-12 11:37:43 +0800 | [diff] [blame] | 7653 | if (cts_protection && (priv->phymode != MODE_IEEE80211A)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7654 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 7655 | else |
| 7656 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 7657 | } |
| 7658 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7659 | if (iwl4965_is_associated(priv)) |
| 7660 | iwl4965_send_rxon_assoc(priv); |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7661 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7662 | |
| 7663 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7664 | 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] | 7665 | { |
| 7666 | int rc = 0; |
| 7667 | unsigned long flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7668 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7669 | |
| 7670 | IWL_DEBUG_MAC80211("enter\n"); |
| 7671 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7672 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7673 | spin_lock_irqsave(&priv->lock, flags); |
| 7674 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7675 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7676 | rc = -EIO; |
| 7677 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 7678 | goto out_unlock; |
| 7679 | } |
| 7680 | |
| 7681 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 7682 | rc = -EIO; |
| 7683 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 7684 | goto out_unlock; |
| 7685 | } |
| 7686 | |
| 7687 | /* if we just finished scan ask for delay */ |
| 7688 | if (priv->last_scan_jiffies && |
| 7689 | time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, |
| 7690 | jiffies)) { |
| 7691 | rc = -EAGAIN; |
| 7692 | goto out_unlock; |
| 7693 | } |
| 7694 | if (len) { |
| 7695 | IWL_DEBUG_SCAN("direct scan for " |
| 7696 | "%s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7697 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7698 | |
| 7699 | priv->one_direct_scan = 1; |
| 7700 | priv->direct_ssid_len = (u8) |
| 7701 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 7702 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7703 | } else |
| 7704 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7705 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7706 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7707 | |
| 7708 | IWL_DEBUG_MAC80211("leave\n"); |
| 7709 | |
| 7710 | out_unlock: |
| 7711 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7712 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7713 | |
| 7714 | return rc; |
| 7715 | } |
| 7716 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7717 | 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] | 7718 | const u8 *local_addr, const u8 *addr, |
| 7719 | struct ieee80211_key_conf *key) |
| 7720 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7721 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7722 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7723 | int rc = 0; |
| 7724 | u8 sta_id; |
| 7725 | |
| 7726 | IWL_DEBUG_MAC80211("enter\n"); |
| 7727 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7728 | if (!iwl4965_param_hwcrypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7729 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 7730 | return -EOPNOTSUPP; |
| 7731 | } |
| 7732 | |
| 7733 | if (is_zero_ether_addr(addr)) |
| 7734 | /* only support pairwise keys */ |
| 7735 | return -EOPNOTSUPP; |
| 7736 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7737 | sta_id = iwl4965_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7738 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7739 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 7740 | print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7741 | return -EINVAL; |
| 7742 | } |
| 7743 | |
| 7744 | mutex_lock(&priv->mutex); |
| 7745 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7746 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7747 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7748 | switch (cmd) { |
| 7749 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7750 | rc = iwl4965_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7751 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7752 | iwl4965_set_rxon_hwcrypto(priv, 1); |
| 7753 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7754 | key->hw_key_idx = sta_id; |
| 7755 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 7756 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 7757 | } |
| 7758 | break; |
| 7759 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7760 | rc = iwl4965_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7761 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7762 | iwl4965_set_rxon_hwcrypto(priv, 0); |
| 7763 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7764 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 7765 | } |
| 7766 | break; |
| 7767 | default: |
| 7768 | rc = -EINVAL; |
| 7769 | } |
| 7770 | |
| 7771 | IWL_DEBUG_MAC80211("leave\n"); |
| 7772 | mutex_unlock(&priv->mutex); |
| 7773 | |
| 7774 | return rc; |
| 7775 | } |
| 7776 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7777 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7778 | const struct ieee80211_tx_queue_params *params) |
| 7779 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7780 | struct iwl4965_priv *priv = hw->priv; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7781 | #ifdef CONFIG_IWL4965_QOS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7782 | unsigned long flags; |
| 7783 | int q; |
Reinette Chatre | 0054b34 | 2007-11-29 11:09:42 +0800 | [diff] [blame] | 7784 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7785 | |
| 7786 | IWL_DEBUG_MAC80211("enter\n"); |
| 7787 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7788 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7789 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7790 | return -EIO; |
| 7791 | } |
| 7792 | |
| 7793 | if (queue >= AC_NUM) { |
| 7794 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 7795 | return 0; |
| 7796 | } |
| 7797 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7798 | #ifdef CONFIG_IWL4965_QOS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7799 | if (!priv->qos_data.qos_enable) { |
| 7800 | priv->qos_data.qos_active = 0; |
| 7801 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 7802 | return 0; |
| 7803 | } |
| 7804 | q = AC_NUM - 1 - queue; |
| 7805 | |
| 7806 | spin_lock_irqsave(&priv->lock, flags); |
| 7807 | |
| 7808 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 7809 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 7810 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 7811 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
| 7812 | cpu_to_le16((params->burst_time * 100)); |
| 7813 | |
| 7814 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 7815 | priv->qos_data.qos_active = 1; |
| 7816 | |
| 7817 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7818 | |
| 7819 | mutex_lock(&priv->mutex); |
| 7820 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7821 | iwl4965_activate_qos(priv, 1); |
| 7822 | else if (priv->assoc_id && iwl4965_is_associated(priv)) |
| 7823 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7824 | |
| 7825 | mutex_unlock(&priv->mutex); |
| 7826 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7827 | #endif /*CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7828 | |
| 7829 | IWL_DEBUG_MAC80211("leave\n"); |
| 7830 | return 0; |
| 7831 | } |
| 7832 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7833 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7834 | struct ieee80211_tx_queue_stats *stats) |
| 7835 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7836 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7837 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7838 | struct iwl4965_tx_queue *txq; |
| 7839 | struct iwl4965_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7840 | unsigned long flags; |
| 7841 | |
| 7842 | IWL_DEBUG_MAC80211("enter\n"); |
| 7843 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7844 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7845 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7846 | return -EIO; |
| 7847 | } |
| 7848 | |
| 7849 | spin_lock_irqsave(&priv->lock, flags); |
| 7850 | |
| 7851 | for (i = 0; i < AC_NUM; i++) { |
| 7852 | txq = &priv->txq[i]; |
| 7853 | q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7854 | avail = iwl4965_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7855 | |
| 7856 | stats->data[i].len = q->n_window - avail; |
| 7857 | stats->data[i].limit = q->n_window - q->high_mark; |
| 7858 | stats->data[i].count = q->n_window; |
| 7859 | |
| 7860 | } |
| 7861 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7862 | |
| 7863 | IWL_DEBUG_MAC80211("leave\n"); |
| 7864 | |
| 7865 | return 0; |
| 7866 | } |
| 7867 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7868 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7869 | struct ieee80211_low_level_stats *stats) |
| 7870 | { |
| 7871 | IWL_DEBUG_MAC80211("enter\n"); |
| 7872 | IWL_DEBUG_MAC80211("leave\n"); |
| 7873 | |
| 7874 | return 0; |
| 7875 | } |
| 7876 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7877 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7878 | { |
| 7879 | IWL_DEBUG_MAC80211("enter\n"); |
| 7880 | IWL_DEBUG_MAC80211("leave\n"); |
| 7881 | |
| 7882 | return 0; |
| 7883 | } |
| 7884 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7885 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7886 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7887 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7888 | unsigned long flags; |
| 7889 | |
| 7890 | mutex_lock(&priv->mutex); |
| 7891 | IWL_DEBUG_MAC80211("enter\n"); |
| 7892 | |
| 7893 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7894 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7895 | spin_lock_irqsave(&priv->lock, flags); |
| 7896 | memset(&priv->current_assoc_ht, 0, sizeof(struct sta_ht_info)); |
| 7897 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7898 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7899 | /* if (priv->lq_mngr.agg_ctrl.granted_ba) |
| 7900 | iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);*/ |
| 7901 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7902 | memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl4965_agg_control)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7903 | priv->lq_mngr.agg_ctrl.tid_traffic_load_threshold = 10; |
| 7904 | priv->lq_mngr.agg_ctrl.ba_timeout = 5000; |
| 7905 | priv->lq_mngr.agg_ctrl.auto_agg = 1; |
| 7906 | |
| 7907 | if (priv->lq_mngr.agg_ctrl.auto_agg) |
| 7908 | priv->lq_mngr.agg_ctrl.requested_ba = TID_ALL_ENABLED; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7909 | #endif /*CONFIG_IWL4965_HT_AGG */ |
| 7910 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7911 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7912 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7913 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7914 | #endif |
| 7915 | |
| 7916 | cancel_delayed_work(&priv->post_associate); |
| 7917 | |
| 7918 | spin_lock_irqsave(&priv->lock, flags); |
| 7919 | priv->assoc_id = 0; |
| 7920 | priv->assoc_capability = 0; |
| 7921 | priv->call_post_assoc_from_beacon = 0; |
| 7922 | priv->assoc_station_added = 0; |
| 7923 | |
| 7924 | /* new association get rid of ibss beacon skb */ |
| 7925 | if (priv->ibss_beacon) |
| 7926 | dev_kfree_skb(priv->ibss_beacon); |
| 7927 | |
| 7928 | priv->ibss_beacon = NULL; |
| 7929 | |
| 7930 | priv->beacon_int = priv->hw->conf.beacon_int; |
| 7931 | priv->timestamp1 = 0; |
| 7932 | priv->timestamp0 = 0; |
| 7933 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 7934 | priv->beacon_int = 0; |
| 7935 | |
| 7936 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7937 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7938 | /* we are restarting association process |
| 7939 | * clear RXON_FILTER_ASSOC_MSK bit |
| 7940 | */ |
| 7941 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7942 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7943 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7944 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7945 | } |
| 7946 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7947 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 7948 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7949 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7950 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 7951 | mutex_unlock(&priv->mutex); |
| 7952 | return; |
| 7953 | } |
| 7954 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7955 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7956 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 7957 | mutex_unlock(&priv->mutex); |
| 7958 | return; |
| 7959 | } |
| 7960 | |
| 7961 | priv->only_active_channel = 0; |
| 7962 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7963 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7964 | |
| 7965 | mutex_unlock(&priv->mutex); |
| 7966 | |
| 7967 | IWL_DEBUG_MAC80211("leave\n"); |
| 7968 | |
| 7969 | } |
| 7970 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7971 | 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] | 7972 | struct ieee80211_tx_control *control) |
| 7973 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7974 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7975 | unsigned long flags; |
| 7976 | |
| 7977 | mutex_lock(&priv->mutex); |
| 7978 | IWL_DEBUG_MAC80211("enter\n"); |
| 7979 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7980 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7981 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7982 | mutex_unlock(&priv->mutex); |
| 7983 | return -EIO; |
| 7984 | } |
| 7985 | |
| 7986 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 7987 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 7988 | mutex_unlock(&priv->mutex); |
| 7989 | return -EIO; |
| 7990 | } |
| 7991 | |
| 7992 | spin_lock_irqsave(&priv->lock, flags); |
| 7993 | |
| 7994 | if (priv->ibss_beacon) |
| 7995 | dev_kfree_skb(priv->ibss_beacon); |
| 7996 | |
| 7997 | priv->ibss_beacon = skb; |
| 7998 | |
| 7999 | priv->assoc_id = 0; |
| 8000 | |
| 8001 | IWL_DEBUG_MAC80211("leave\n"); |
| 8002 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8003 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8004 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8005 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8006 | #endif |
| 8007 | |
| 8008 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 8009 | |
| 8010 | mutex_unlock(&priv->mutex); |
| 8011 | |
| 8012 | return 0; |
| 8013 | } |
| 8014 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8015 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8016 | union ht_cap_info { |
| 8017 | struct { |
| 8018 | u16 advanced_coding_cap :1; |
| 8019 | u16 supported_chan_width_set :1; |
| 8020 | u16 mimo_power_save_mode :2; |
| 8021 | u16 green_field :1; |
| 8022 | u16 short_GI20 :1; |
| 8023 | u16 short_GI40 :1; |
| 8024 | u16 tx_stbc :1; |
| 8025 | u16 rx_stbc :1; |
| 8026 | u16 beam_forming :1; |
| 8027 | u16 delayed_ba :1; |
| 8028 | u16 maximal_amsdu_size :1; |
| 8029 | u16 cck_mode_at_40MHz :1; |
| 8030 | u16 psmp_support :1; |
| 8031 | u16 stbc_ctrl_frame_support :1; |
| 8032 | u16 sig_txop_protection_support :1; |
| 8033 | }; |
| 8034 | u16 val; |
| 8035 | } __attribute__ ((packed)); |
| 8036 | |
| 8037 | union ht_param_info{ |
| 8038 | struct { |
| 8039 | u8 max_rx_ampdu_factor :2; |
| 8040 | u8 mpdu_density :3; |
| 8041 | u8 reserved :3; |
| 8042 | }; |
| 8043 | u8 val; |
| 8044 | } __attribute__ ((packed)); |
| 8045 | |
| 8046 | union ht_exra_param_info { |
| 8047 | struct { |
| 8048 | u8 ext_chan_offset :2; |
| 8049 | u8 tx_chan_width :1; |
| 8050 | u8 rifs_mode :1; |
| 8051 | u8 controlled_access_only :1; |
| 8052 | u8 service_interval_granularity :3; |
| 8053 | }; |
| 8054 | u8 val; |
| 8055 | } __attribute__ ((packed)); |
| 8056 | |
| 8057 | union ht_operation_mode{ |
| 8058 | struct { |
| 8059 | u16 op_mode :2; |
| 8060 | u16 non_GF :1; |
| 8061 | u16 reserved :13; |
| 8062 | }; |
| 8063 | u16 val; |
| 8064 | } __attribute__ ((packed)); |
| 8065 | |
| 8066 | |
| 8067 | static int sta_ht_info_init(struct ieee80211_ht_capability *ht_cap, |
| 8068 | struct ieee80211_ht_additional_info *ht_extra, |
| 8069 | struct sta_ht_info *ht_info_ap, |
| 8070 | struct sta_ht_info *ht_info) |
| 8071 | { |
| 8072 | union ht_cap_info cap; |
| 8073 | union ht_operation_mode op_mode; |
| 8074 | union ht_param_info param_info; |
| 8075 | union ht_exra_param_info extra_param_info; |
| 8076 | |
| 8077 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8078 | |
| 8079 | if (!ht_info) { |
| 8080 | IWL_DEBUG_MAC80211("leave: ht_info is NULL\n"); |
| 8081 | return -1; |
| 8082 | } |
| 8083 | |
| 8084 | if (ht_cap) { |
| 8085 | cap.val = (u16) le16_to_cpu(ht_cap->capabilities_info); |
| 8086 | param_info.val = ht_cap->mac_ht_params_info; |
| 8087 | ht_info->is_ht = 1; |
| 8088 | if (cap.short_GI20) |
| 8089 | ht_info->sgf |= 0x1; |
| 8090 | if (cap.short_GI40) |
| 8091 | ht_info->sgf |= 0x2; |
| 8092 | ht_info->is_green_field = cap.green_field; |
| 8093 | ht_info->max_amsdu_size = cap.maximal_amsdu_size; |
| 8094 | ht_info->supported_chan_width = cap.supported_chan_width_set; |
| 8095 | ht_info->tx_mimo_ps_mode = cap.mimo_power_save_mode; |
| 8096 | memcpy(ht_info->supp_rates, ht_cap->supported_mcs_set, 16); |
| 8097 | |
| 8098 | ht_info->ampdu_factor = param_info.max_rx_ampdu_factor; |
| 8099 | ht_info->mpdu_density = param_info.mpdu_density; |
| 8100 | |
| 8101 | IWL_DEBUG_MAC80211("SISO mask 0x%X MIMO mask 0x%X \n", |
| 8102 | ht_cap->supported_mcs_set[0], |
| 8103 | ht_cap->supported_mcs_set[1]); |
| 8104 | |
| 8105 | if (ht_info_ap) { |
| 8106 | ht_info->control_channel = ht_info_ap->control_channel; |
| 8107 | ht_info->extension_chan_offset = |
| 8108 | ht_info_ap->extension_chan_offset; |
| 8109 | ht_info->tx_chan_width = ht_info_ap->tx_chan_width; |
| 8110 | ht_info->operating_mode = ht_info_ap->operating_mode; |
| 8111 | } |
| 8112 | |
| 8113 | if (ht_extra) { |
| 8114 | extra_param_info.val = ht_extra->ht_param; |
| 8115 | ht_info->control_channel = ht_extra->control_chan; |
| 8116 | ht_info->extension_chan_offset = |
| 8117 | extra_param_info.ext_chan_offset; |
| 8118 | ht_info->tx_chan_width = extra_param_info.tx_chan_width; |
| 8119 | op_mode.val = (u16) |
| 8120 | le16_to_cpu(ht_extra->operation_mode); |
| 8121 | ht_info->operating_mode = op_mode.op_mode; |
| 8122 | IWL_DEBUG_MAC80211("control channel %d\n", |
| 8123 | ht_extra->control_chan); |
| 8124 | } |
| 8125 | } else |
| 8126 | ht_info->is_ht = 0; |
| 8127 | |
| 8128 | IWL_DEBUG_MAC80211("leave\n"); |
| 8129 | return 0; |
| 8130 | } |
| 8131 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8132 | static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8133 | struct ieee80211_ht_capability *ht_cap, |
| 8134 | struct ieee80211_ht_additional_info *ht_extra) |
| 8135 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8136 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8137 | int rs; |
| 8138 | |
| 8139 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8140 | |
| 8141 | rs = sta_ht_info_init(ht_cap, ht_extra, NULL, &priv->current_assoc_ht); |
| 8142 | iwl4965_set_rxon_chain(priv); |
| 8143 | |
| 8144 | if (priv && priv->assoc_id && |
| 8145 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
| 8146 | unsigned long flags; |
| 8147 | |
| 8148 | spin_lock_irqsave(&priv->lock, flags); |
| 8149 | if (priv->beacon_int) |
| 8150 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 8151 | else |
| 8152 | priv->call_post_assoc_from_beacon = 1; |
| 8153 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8154 | } |
| 8155 | |
| 8156 | IWL_DEBUG_MAC80211("leave: control channel %d\n", |
| 8157 | ht_extra->control_chan); |
| 8158 | return rs; |
| 8159 | |
| 8160 | } |
| 8161 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8162 | static void iwl4965_set_ht_capab(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8163 | struct ieee80211_ht_capability *ht_cap, |
| 8164 | u8 use_wide_chan) |
| 8165 | { |
| 8166 | union ht_cap_info cap; |
| 8167 | union ht_param_info param_info; |
| 8168 | |
| 8169 | memset(&cap, 0, sizeof(union ht_cap_info)); |
| 8170 | memset(¶m_info, 0, sizeof(union ht_param_info)); |
| 8171 | |
| 8172 | cap.maximal_amsdu_size = HT_IE_MAX_AMSDU_SIZE_4K; |
| 8173 | cap.green_field = 1; |
| 8174 | cap.short_GI20 = 1; |
| 8175 | cap.short_GI40 = 1; |
| 8176 | cap.supported_chan_width_set = use_wide_chan; |
| 8177 | cap.mimo_power_save_mode = 0x3; |
| 8178 | |
| 8179 | param_info.max_rx_ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF; |
| 8180 | param_info.mpdu_density = CFG_HT_MPDU_DENSITY_DEF; |
| 8181 | ht_cap->capabilities_info = (__le16) cpu_to_le16(cap.val); |
| 8182 | ht_cap->mac_ht_params_info = (u8) param_info.val; |
| 8183 | |
| 8184 | ht_cap->supported_mcs_set[0] = 0xff; |
| 8185 | ht_cap->supported_mcs_set[1] = 0xff; |
| 8186 | ht_cap->supported_mcs_set[4] = |
| 8187 | (cap.supported_chan_width_set) ? 0x1: 0x0; |
| 8188 | } |
| 8189 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8190 | static void iwl4965_mac_get_ht_capab(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8191 | struct ieee80211_ht_capability *ht_cap) |
| 8192 | { |
| 8193 | u8 use_wide_channel = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8194 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8195 | |
| 8196 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8197 | if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ) |
| 8198 | use_wide_channel = 0; |
| 8199 | |
| 8200 | /* no fat tx allowed on 2.4GHZ */ |
| 8201 | if (priv->phymode != MODE_IEEE80211A) |
| 8202 | use_wide_channel = 0; |
| 8203 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8204 | iwl4965_set_ht_capab(hw, ht_cap, use_wide_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8205 | IWL_DEBUG_MAC80211("leave: \n"); |
| 8206 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8207 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8208 | |
| 8209 | /***************************************************************************** |
| 8210 | * |
| 8211 | * sysfs attributes |
| 8212 | * |
| 8213 | *****************************************************************************/ |
| 8214 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8215 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8216 | |
| 8217 | /* |
| 8218 | * The following adds a new attribute to the sysfs representation |
| 8219 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 8220 | * used for controlling the debug level. |
| 8221 | * |
| 8222 | * See the level definitions in iwl for details. |
| 8223 | */ |
| 8224 | |
| 8225 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 8226 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8227 | return sprintf(buf, "0x%08X\n", iwl4965_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8228 | } |
| 8229 | static ssize_t store_debug_level(struct device_driver *d, |
| 8230 | const char *buf, size_t count) |
| 8231 | { |
| 8232 | char *p = (char *)buf; |
| 8233 | u32 val; |
| 8234 | |
| 8235 | val = simple_strtoul(p, &p, 0); |
| 8236 | if (p == buf) |
| 8237 | printk(KERN_INFO DRV_NAME |
| 8238 | ": %s is not in hex or decimal form.\n", buf); |
| 8239 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8240 | iwl4965_debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8241 | |
| 8242 | return strnlen(buf, count); |
| 8243 | } |
| 8244 | |
| 8245 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 8246 | show_debug_level, store_debug_level); |
| 8247 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8248 | #endif /* CONFIG_IWL4965_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8249 | |
| 8250 | static ssize_t show_rf_kill(struct device *d, |
| 8251 | struct device_attribute *attr, char *buf) |
| 8252 | { |
| 8253 | /* |
| 8254 | * 0 - RF kill not enabled |
| 8255 | * 1 - SW based RF kill active (sysfs) |
| 8256 | * 2 - HW based RF kill active |
| 8257 | * 3 - Both HW and SW based RF kill active |
| 8258 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8259 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8260 | int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | |
| 8261 | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); |
| 8262 | |
| 8263 | return sprintf(buf, "%i\n", val); |
| 8264 | } |
| 8265 | |
| 8266 | static ssize_t store_rf_kill(struct device *d, |
| 8267 | struct device_attribute *attr, |
| 8268 | const char *buf, size_t count) |
| 8269 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8270 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8271 | |
| 8272 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8273 | iwl4965_radio_kill_sw(priv, buf[0] == '1'); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8274 | mutex_unlock(&priv->mutex); |
| 8275 | |
| 8276 | return count; |
| 8277 | } |
| 8278 | |
| 8279 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); |
| 8280 | |
| 8281 | static ssize_t show_temperature(struct device *d, |
| 8282 | struct device_attribute *attr, char *buf) |
| 8283 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8284 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8285 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8286 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8287 | return -EAGAIN; |
| 8288 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8289 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8290 | } |
| 8291 | |
| 8292 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 8293 | |
| 8294 | static ssize_t show_rs_window(struct device *d, |
| 8295 | struct device_attribute *attr, |
| 8296 | char *buf) |
| 8297 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8298 | struct iwl4965_priv *priv = d->driver_data; |
| 8299 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8300 | } |
| 8301 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 8302 | |
| 8303 | static ssize_t show_tx_power(struct device *d, |
| 8304 | struct device_attribute *attr, char *buf) |
| 8305 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8306 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8307 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 8308 | } |
| 8309 | |
| 8310 | static ssize_t store_tx_power(struct device *d, |
| 8311 | struct device_attribute *attr, |
| 8312 | const char *buf, size_t count) |
| 8313 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8314 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8315 | char *p = (char *)buf; |
| 8316 | u32 val; |
| 8317 | |
| 8318 | val = simple_strtoul(p, &p, 10); |
| 8319 | if (p == buf) |
| 8320 | printk(KERN_INFO DRV_NAME |
| 8321 | ": %s is not in decimal form.\n", buf); |
| 8322 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8323 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8324 | |
| 8325 | return count; |
| 8326 | } |
| 8327 | |
| 8328 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 8329 | |
| 8330 | static ssize_t show_flags(struct device *d, |
| 8331 | struct device_attribute *attr, char *buf) |
| 8332 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8333 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8334 | |
| 8335 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 8336 | } |
| 8337 | |
| 8338 | static ssize_t store_flags(struct device *d, |
| 8339 | struct device_attribute *attr, |
| 8340 | const char *buf, size_t count) |
| 8341 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8342 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8343 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 8344 | |
| 8345 | mutex_lock(&priv->mutex); |
| 8346 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 8347 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8348 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8349 | IWL_WARNING("Could not cancel scan.\n"); |
| 8350 | else { |
| 8351 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 8352 | flags); |
| 8353 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8354 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8355 | } |
| 8356 | } |
| 8357 | mutex_unlock(&priv->mutex); |
| 8358 | |
| 8359 | return count; |
| 8360 | } |
| 8361 | |
| 8362 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 8363 | |
| 8364 | static ssize_t show_filter_flags(struct device *d, |
| 8365 | struct device_attribute *attr, char *buf) |
| 8366 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8367 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8368 | |
| 8369 | return sprintf(buf, "0x%04X\n", |
| 8370 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 8371 | } |
| 8372 | |
| 8373 | static ssize_t store_filter_flags(struct device *d, |
| 8374 | struct device_attribute *attr, |
| 8375 | const char *buf, size_t count) |
| 8376 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8377 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8378 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 8379 | |
| 8380 | mutex_lock(&priv->mutex); |
| 8381 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 8382 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8383 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8384 | IWL_WARNING("Could not cancel scan.\n"); |
| 8385 | else { |
| 8386 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 8387 | "0x%04X\n", filter_flags); |
| 8388 | priv->staging_rxon.filter_flags = |
| 8389 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8390 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8391 | } |
| 8392 | } |
| 8393 | mutex_unlock(&priv->mutex); |
| 8394 | |
| 8395 | return count; |
| 8396 | } |
| 8397 | |
| 8398 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 8399 | store_filter_flags); |
| 8400 | |
| 8401 | static ssize_t show_tune(struct device *d, |
| 8402 | struct device_attribute *attr, char *buf) |
| 8403 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8404 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8405 | |
| 8406 | return sprintf(buf, "0x%04X\n", |
| 8407 | (priv->phymode << 8) | |
| 8408 | le16_to_cpu(priv->active_rxon.channel)); |
| 8409 | } |
| 8410 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8411 | static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8412 | |
| 8413 | static ssize_t store_tune(struct device *d, |
| 8414 | struct device_attribute *attr, |
| 8415 | const char *buf, size_t count) |
| 8416 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8417 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8418 | char *p = (char *)buf; |
| 8419 | u16 tune = simple_strtoul(p, &p, 0); |
| 8420 | u8 phymode = (tune >> 8) & 0xff; |
| 8421 | u16 channel = tune & 0xff; |
| 8422 | |
| 8423 | IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel); |
| 8424 | |
| 8425 | mutex_lock(&priv->mutex); |
| 8426 | if ((le16_to_cpu(priv->staging_rxon.channel) != channel) || |
| 8427 | (priv->phymode != phymode)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8428 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8429 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8430 | ch_info = iwl4965_get_channel_info(priv, phymode, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8431 | if (!ch_info) { |
| 8432 | IWL_WARNING("Requested invalid phymode/channel " |
| 8433 | "combination: %d %d\n", phymode, channel); |
| 8434 | mutex_unlock(&priv->mutex); |
| 8435 | return -EINVAL; |
| 8436 | } |
| 8437 | |
| 8438 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8439 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8440 | IWL_WARNING("Could not cancel scan.\n"); |
| 8441 | else { |
| 8442 | IWL_DEBUG_INFO("Committing phymode and " |
| 8443 | "rxon.channel = %d %d\n", |
| 8444 | phymode, channel); |
| 8445 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8446 | iwl4965_set_rxon_channel(priv, phymode, channel); |
| 8447 | iwl4965_set_flags_for_phymode(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8448 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8449 | iwl4965_set_rate(priv); |
| 8450 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8451 | } |
| 8452 | } |
| 8453 | mutex_unlock(&priv->mutex); |
| 8454 | |
| 8455 | return count; |
| 8456 | } |
| 8457 | |
| 8458 | static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune); |
| 8459 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8460 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8461 | |
| 8462 | static ssize_t show_measurement(struct device *d, |
| 8463 | struct device_attribute *attr, char *buf) |
| 8464 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8465 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8466 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8467 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 8468 | u8 *data = (u8 *) & measure_report; |
| 8469 | unsigned long flags; |
| 8470 | |
| 8471 | spin_lock_irqsave(&priv->lock, flags); |
| 8472 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 8473 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8474 | return 0; |
| 8475 | } |
| 8476 | memcpy(&measure_report, &priv->measure_report, size); |
| 8477 | priv->measurement_status = 0; |
| 8478 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8479 | |
| 8480 | while (size && (PAGE_SIZE - len)) { |
| 8481 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8482 | PAGE_SIZE - len, 1); |
| 8483 | len = strlen(buf); |
| 8484 | if (PAGE_SIZE - len) |
| 8485 | buf[len++] = '\n'; |
| 8486 | |
| 8487 | ofs += 16; |
| 8488 | size -= min(size, 16U); |
| 8489 | } |
| 8490 | |
| 8491 | return len; |
| 8492 | } |
| 8493 | |
| 8494 | static ssize_t store_measurement(struct device *d, |
| 8495 | struct device_attribute *attr, |
| 8496 | const char *buf, size_t count) |
| 8497 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8498 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8499 | struct ieee80211_measurement_params params = { |
| 8500 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 8501 | .start_time = cpu_to_le64(priv->last_tsf), |
| 8502 | .duration = cpu_to_le16(1), |
| 8503 | }; |
| 8504 | u8 type = IWL_MEASURE_BASIC; |
| 8505 | u8 buffer[32]; |
| 8506 | u8 channel; |
| 8507 | |
| 8508 | if (count) { |
| 8509 | char *p = buffer; |
| 8510 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 8511 | channel = simple_strtoul(p, NULL, 0); |
| 8512 | if (channel) |
| 8513 | params.channel = channel; |
| 8514 | |
| 8515 | p = buffer; |
| 8516 | while (*p && *p != ' ') |
| 8517 | p++; |
| 8518 | if (*p) |
| 8519 | type = simple_strtoul(p + 1, NULL, 0); |
| 8520 | } |
| 8521 | |
| 8522 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 8523 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8524 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8525 | |
| 8526 | return count; |
| 8527 | } |
| 8528 | |
| 8529 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 8530 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8531 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8532 | |
| 8533 | static ssize_t store_retry_rate(struct device *d, |
| 8534 | struct device_attribute *attr, |
| 8535 | const char *buf, size_t count) |
| 8536 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8537 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8538 | |
| 8539 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 8540 | if (priv->retry_rate <= 0) |
| 8541 | priv->retry_rate = 1; |
| 8542 | |
| 8543 | return count; |
| 8544 | } |
| 8545 | |
| 8546 | static ssize_t show_retry_rate(struct device *d, |
| 8547 | struct device_attribute *attr, char *buf) |
| 8548 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8549 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8550 | return sprintf(buf, "%d", priv->retry_rate); |
| 8551 | } |
| 8552 | |
| 8553 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 8554 | store_retry_rate); |
| 8555 | |
| 8556 | static ssize_t store_power_level(struct device *d, |
| 8557 | struct device_attribute *attr, |
| 8558 | const char *buf, size_t count) |
| 8559 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8560 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8561 | int rc; |
| 8562 | int mode; |
| 8563 | |
| 8564 | mode = simple_strtoul(buf, NULL, 0); |
| 8565 | mutex_lock(&priv->mutex); |
| 8566 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8567 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8568 | rc = -EAGAIN; |
| 8569 | goto out; |
| 8570 | } |
| 8571 | |
| 8572 | if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC)) |
| 8573 | mode = IWL_POWER_AC; |
| 8574 | else |
| 8575 | mode |= IWL_POWER_ENABLED; |
| 8576 | |
| 8577 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8578 | rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8579 | if (rc) { |
| 8580 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 8581 | goto out; |
| 8582 | } |
| 8583 | priv->power_mode = mode; |
| 8584 | } |
| 8585 | |
| 8586 | rc = count; |
| 8587 | |
| 8588 | out: |
| 8589 | mutex_unlock(&priv->mutex); |
| 8590 | return rc; |
| 8591 | } |
| 8592 | |
| 8593 | #define MAX_WX_STRING 80 |
| 8594 | |
| 8595 | /* Values are in microsecond */ |
| 8596 | static const s32 timeout_duration[] = { |
| 8597 | 350000, |
| 8598 | 250000, |
| 8599 | 75000, |
| 8600 | 37000, |
| 8601 | 25000, |
| 8602 | }; |
| 8603 | static const s32 period_duration[] = { |
| 8604 | 400000, |
| 8605 | 700000, |
| 8606 | 1000000, |
| 8607 | 1000000, |
| 8608 | 1000000 |
| 8609 | }; |
| 8610 | |
| 8611 | static ssize_t show_power_level(struct device *d, |
| 8612 | struct device_attribute *attr, char *buf) |
| 8613 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8614 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8615 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 8616 | char *p = buf; |
| 8617 | |
| 8618 | p += sprintf(p, "%d ", level); |
| 8619 | switch (level) { |
| 8620 | case IWL_POWER_MODE_CAM: |
| 8621 | case IWL_POWER_AC: |
| 8622 | p += sprintf(p, "(AC)"); |
| 8623 | break; |
| 8624 | case IWL_POWER_BATTERY: |
| 8625 | p += sprintf(p, "(BATTERY)"); |
| 8626 | break; |
| 8627 | default: |
| 8628 | p += sprintf(p, |
| 8629 | "(Timeout %dms, Period %dms)", |
| 8630 | timeout_duration[level - 1] / 1000, |
| 8631 | period_duration[level - 1] / 1000); |
| 8632 | } |
| 8633 | |
| 8634 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 8635 | p += sprintf(p, " OFF\n"); |
| 8636 | else |
| 8637 | p += sprintf(p, " \n"); |
| 8638 | |
| 8639 | return (p - buf + 1); |
| 8640 | |
| 8641 | } |
| 8642 | |
| 8643 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 8644 | store_power_level); |
| 8645 | |
| 8646 | static ssize_t show_channels(struct device *d, |
| 8647 | struct device_attribute *attr, char *buf) |
| 8648 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8649 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8650 | int len = 0, i; |
| 8651 | struct ieee80211_channel *channels = NULL; |
| 8652 | const struct ieee80211_hw_mode *hw_mode = NULL; |
| 8653 | int count = 0; |
| 8654 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8655 | if (!iwl4965_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8656 | return -EAGAIN; |
| 8657 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8658 | hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211G); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8659 | if (!hw_mode) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8660 | hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211B); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8661 | if (hw_mode) { |
| 8662 | channels = hw_mode->channels; |
| 8663 | count = hw_mode->num_channels; |
| 8664 | } |
| 8665 | |
| 8666 | len += |
| 8667 | sprintf(&buf[len], |
| 8668 | "Displaying %d channels in 2.4GHz band " |
| 8669 | "(802.11bg):\n", count); |
| 8670 | |
| 8671 | for (i = 0; i < count; i++) |
| 8672 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 8673 | channels[i].chan, |
| 8674 | channels[i].power_level, |
| 8675 | channels[i]. |
| 8676 | flag & IEEE80211_CHAN_W_RADAR_DETECT ? |
| 8677 | " (IEEE 802.11h required)" : "", |
| 8678 | (!(channels[i].flag & IEEE80211_CHAN_W_IBSS) |
| 8679 | || (channels[i]. |
| 8680 | flag & |
| 8681 | IEEE80211_CHAN_W_RADAR_DETECT)) ? "" : |
| 8682 | ", IBSS", |
| 8683 | channels[i]. |
| 8684 | flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? |
| 8685 | "active/passive" : "passive only"); |
| 8686 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8687 | hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211A); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8688 | if (hw_mode) { |
| 8689 | channels = hw_mode->channels; |
| 8690 | count = hw_mode->num_channels; |
| 8691 | } else { |
| 8692 | channels = NULL; |
| 8693 | count = 0; |
| 8694 | } |
| 8695 | |
| 8696 | len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band " |
| 8697 | "(802.11a):\n", count); |
| 8698 | |
| 8699 | for (i = 0; i < count; i++) |
| 8700 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 8701 | channels[i].chan, |
| 8702 | channels[i].power_level, |
| 8703 | channels[i]. |
| 8704 | flag & IEEE80211_CHAN_W_RADAR_DETECT ? |
| 8705 | " (IEEE 802.11h required)" : "", |
| 8706 | (!(channels[i].flag & IEEE80211_CHAN_W_IBSS) |
| 8707 | || (channels[i]. |
| 8708 | flag & |
| 8709 | IEEE80211_CHAN_W_RADAR_DETECT)) ? "" : |
| 8710 | ", IBSS", |
| 8711 | channels[i]. |
| 8712 | flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? |
| 8713 | "active/passive" : "passive only"); |
| 8714 | |
| 8715 | return len; |
| 8716 | } |
| 8717 | |
| 8718 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 8719 | |
| 8720 | static ssize_t show_statistics(struct device *d, |
| 8721 | struct device_attribute *attr, char *buf) |
| 8722 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8723 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8724 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8725 | u32 len = 0, ofs = 0; |
| 8726 | u8 *data = (u8 *) & priv->statistics; |
| 8727 | int rc = 0; |
| 8728 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8729 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8730 | return -EAGAIN; |
| 8731 | |
| 8732 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8733 | rc = iwl4965_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8734 | mutex_unlock(&priv->mutex); |
| 8735 | |
| 8736 | if (rc) { |
| 8737 | len = sprintf(buf, |
| 8738 | "Error sending statistics request: 0x%08X\n", rc); |
| 8739 | return len; |
| 8740 | } |
| 8741 | |
| 8742 | while (size && (PAGE_SIZE - len)) { |
| 8743 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8744 | PAGE_SIZE - len, 1); |
| 8745 | len = strlen(buf); |
| 8746 | if (PAGE_SIZE - len) |
| 8747 | buf[len++] = '\n'; |
| 8748 | |
| 8749 | ofs += 16; |
| 8750 | size -= min(size, 16U); |
| 8751 | } |
| 8752 | |
| 8753 | return len; |
| 8754 | } |
| 8755 | |
| 8756 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 8757 | |
| 8758 | static ssize_t show_antenna(struct device *d, |
| 8759 | struct device_attribute *attr, char *buf) |
| 8760 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8761 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8762 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8763 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8764 | return -EAGAIN; |
| 8765 | |
| 8766 | return sprintf(buf, "%d\n", priv->antenna); |
| 8767 | } |
| 8768 | |
| 8769 | static ssize_t store_antenna(struct device *d, |
| 8770 | struct device_attribute *attr, |
| 8771 | const char *buf, size_t count) |
| 8772 | { |
| 8773 | int ant; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8774 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8775 | |
| 8776 | if (count == 0) |
| 8777 | return 0; |
| 8778 | |
| 8779 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 8780 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 8781 | return count; |
| 8782 | } |
| 8783 | |
| 8784 | if ((ant >= 0) && (ant <= 2)) { |
| 8785 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8786 | priv->antenna = (enum iwl4965_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8787 | } else |
| 8788 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 8789 | |
| 8790 | |
| 8791 | return count; |
| 8792 | } |
| 8793 | |
| 8794 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 8795 | |
| 8796 | static ssize_t show_status(struct device *d, |
| 8797 | struct device_attribute *attr, char *buf) |
| 8798 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8799 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
| 8800 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8801 | return -EAGAIN; |
| 8802 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 8803 | } |
| 8804 | |
| 8805 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 8806 | |
| 8807 | static ssize_t dump_error_log(struct device *d, |
| 8808 | struct device_attribute *attr, |
| 8809 | const char *buf, size_t count) |
| 8810 | { |
| 8811 | char *p = (char *)buf; |
| 8812 | |
| 8813 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8814 | iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8815 | |
| 8816 | return strnlen(buf, count); |
| 8817 | } |
| 8818 | |
| 8819 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 8820 | |
| 8821 | static ssize_t dump_event_log(struct device *d, |
| 8822 | struct device_attribute *attr, |
| 8823 | const char *buf, size_t count) |
| 8824 | { |
| 8825 | char *p = (char *)buf; |
| 8826 | |
| 8827 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8828 | iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8829 | |
| 8830 | return strnlen(buf, count); |
| 8831 | } |
| 8832 | |
| 8833 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 8834 | |
| 8835 | /***************************************************************************** |
| 8836 | * |
| 8837 | * driver setup and teardown |
| 8838 | * |
| 8839 | *****************************************************************************/ |
| 8840 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8841 | static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8842 | { |
| 8843 | priv->workqueue = create_workqueue(DRV_NAME); |
| 8844 | |
| 8845 | init_waitqueue_head(&priv->wait_command_queue); |
| 8846 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8847 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 8848 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 8849 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 8850 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 8851 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 8852 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 8853 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 8854 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
| 8855 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 8856 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 8857 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 8858 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8859 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8860 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8861 | |
| 8862 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8863 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8864 | } |
| 8865 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8866 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8867 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8868 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8869 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 8870 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8871 | cancel_delayed_work(&priv->scan_check); |
| 8872 | cancel_delayed_work(&priv->alive_start); |
| 8873 | cancel_delayed_work(&priv->post_associate); |
| 8874 | cancel_work_sync(&priv->beacon_update); |
| 8875 | } |
| 8876 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8877 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8878 | &dev_attr_antenna.attr, |
| 8879 | &dev_attr_channels.attr, |
| 8880 | &dev_attr_dump_errors.attr, |
| 8881 | &dev_attr_dump_events.attr, |
| 8882 | &dev_attr_flags.attr, |
| 8883 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8884 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8885 | &dev_attr_measurement.attr, |
| 8886 | #endif |
| 8887 | &dev_attr_power_level.attr, |
| 8888 | &dev_attr_retry_rate.attr, |
| 8889 | &dev_attr_rf_kill.attr, |
| 8890 | &dev_attr_rs_window.attr, |
| 8891 | &dev_attr_statistics.attr, |
| 8892 | &dev_attr_status.attr, |
| 8893 | &dev_attr_temperature.attr, |
| 8894 | &dev_attr_tune.attr, |
| 8895 | &dev_attr_tx_power.attr, |
| 8896 | |
| 8897 | NULL |
| 8898 | }; |
| 8899 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8900 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8901 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8902 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8903 | }; |
| 8904 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8905 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 8906 | .tx = iwl4965_mac_tx, |
| 8907 | .start = iwl4965_mac_start, |
| 8908 | .stop = iwl4965_mac_stop, |
| 8909 | .add_interface = iwl4965_mac_add_interface, |
| 8910 | .remove_interface = iwl4965_mac_remove_interface, |
| 8911 | .config = iwl4965_mac_config, |
| 8912 | .config_interface = iwl4965_mac_config_interface, |
| 8913 | .configure_filter = iwl4965_configure_filter, |
| 8914 | .set_key = iwl4965_mac_set_key, |
| 8915 | .get_stats = iwl4965_mac_get_stats, |
| 8916 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 8917 | .conf_tx = iwl4965_mac_conf_tx, |
| 8918 | .get_tsf = iwl4965_mac_get_tsf, |
| 8919 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 8920 | .beacon_update = iwl4965_mac_beacon_update, |
| 8921 | .erp_ie_changed = iwl4965_mac_erp_ie_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8922 | #ifdef CONFIG_IWL4965_HT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8923 | .conf_ht = iwl4965_mac_conf_ht, |
| 8924 | .get_ht_capab = iwl4965_mac_get_ht_capab, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8925 | #ifdef CONFIG_IWL4965_HT_AGG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8926 | .ht_tx_agg_start = iwl4965_mac_ht_tx_agg_start, |
| 8927 | .ht_tx_agg_stop = iwl4965_mac_ht_tx_agg_stop, |
| 8928 | .ht_rx_agg_start = iwl4965_mac_ht_rx_agg_start, |
| 8929 | .ht_rx_agg_stop = iwl4965_mac_ht_rx_agg_stop, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8930 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 8931 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8932 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8933 | }; |
| 8934 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8935 | 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] | 8936 | { |
| 8937 | int err = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8938 | struct iwl4965_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8939 | struct ieee80211_hw *hw; |
| 8940 | int i; |
| 8941 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8942 | if (iwl4965_param_disable_hw_scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8943 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8944 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8945 | } |
| 8946 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8947 | if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) || |
| 8948 | (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8949 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
| 8950 | IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); |
| 8951 | err = -EINVAL; |
| 8952 | goto out; |
| 8953 | } |
| 8954 | |
| 8955 | /* mac80211 allocates memory for this device instance, including |
| 8956 | * space for this driver's private structure */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8957 | hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8958 | if (hw == NULL) { |
| 8959 | IWL_ERROR("Can not allocate network device\n"); |
| 8960 | err = -ENOMEM; |
| 8961 | goto out; |
| 8962 | } |
| 8963 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 8964 | |
Johannes Berg | f51359a | 2007-10-28 14:53:36 +0100 | [diff] [blame] | 8965 | hw->rate_control_algorithm = "iwl-4965-rs"; |
| 8966 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8967 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 8968 | priv = hw->priv; |
| 8969 | priv->hw = hw; |
| 8970 | |
| 8971 | priv->pci_dev = pdev; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8972 | priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8973 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8974 | iwl4965_debug_level = iwl4965_param_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8975 | atomic_set(&priv->restrict_refcnt, 0); |
| 8976 | #endif |
| 8977 | priv->retry_rate = 1; |
| 8978 | |
| 8979 | priv->ibss_beacon = NULL; |
| 8980 | |
| 8981 | /* Tell mac80211 and its clients (e.g. Wireless Extensions) |
| 8982 | * the range of signal quality values that we'll provide. |
| 8983 | * Negative values for level/noise indicate that we'll provide dBm. |
| 8984 | * For WE, at least, non-0 values here *enable* display of values |
| 8985 | * in app (iwconfig). */ |
| 8986 | hw->max_rssi = -20; /* signal level, negative indicates dBm */ |
| 8987 | hw->max_noise = -20; /* noise level, negative indicates dBm */ |
| 8988 | hw->max_signal = 100; /* link quality indication (%) */ |
| 8989 | |
| 8990 | /* Tell mac80211 our Tx characteristics */ |
| 8991 | hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; |
| 8992 | |
| 8993 | hw->queues = 4; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8994 | #ifdef CONFIG_IWL4965_HT |
| 8995 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8996 | hw->queues = 16; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8997 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 8998 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8999 | |
| 9000 | spin_lock_init(&priv->lock); |
| 9001 | spin_lock_init(&priv->power_data.lock); |
| 9002 | spin_lock_init(&priv->sta_lock); |
| 9003 | spin_lock_init(&priv->hcmd_lock); |
| 9004 | spin_lock_init(&priv->lq_mngr.lock); |
| 9005 | |
| 9006 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) |
| 9007 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
| 9008 | |
| 9009 | INIT_LIST_HEAD(&priv->free_frames); |
| 9010 | |
| 9011 | mutex_init(&priv->mutex); |
| 9012 | if (pci_enable_device(pdev)) { |
| 9013 | err = -ENODEV; |
| 9014 | goto out_ieee80211_free_hw; |
| 9015 | } |
| 9016 | |
| 9017 | pci_set_master(pdev); |
| 9018 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9019 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9020 | |
| 9021 | priv->data_retry_limit = -1; |
| 9022 | priv->ieee_channels = NULL; |
| 9023 | priv->ieee_rates = NULL; |
| 9024 | priv->phymode = -1; |
| 9025 | |
| 9026 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 9027 | if (!err) |
| 9028 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 9029 | if (err) { |
| 9030 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 9031 | goto out_pci_disable_device; |
| 9032 | } |
| 9033 | |
| 9034 | pci_set_drvdata(pdev, priv); |
| 9035 | err = pci_request_regions(pdev, DRV_NAME); |
| 9036 | if (err) |
| 9037 | goto out_pci_disable_device; |
| 9038 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 9039 | * PCI Tx retries from interfering with C3 CPU state */ |
| 9040 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 9041 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 9042 | if (!priv->hw_base) { |
| 9043 | err = -ENODEV; |
| 9044 | goto out_pci_release_regions; |
| 9045 | } |
| 9046 | |
| 9047 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 9048 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 9049 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 9050 | |
| 9051 | /* Initialize module parameter values here */ |
| 9052 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9053 | if (iwl4965_param_disable) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9054 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 9055 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 9056 | } |
| 9057 | |
| 9058 | priv->iw_mode = IEEE80211_IF_TYPE_STA; |
| 9059 | |
| 9060 | priv->ps_mode = 0; |
| 9061 | priv->use_ant_b_for_management_frame = 1; /* start with ant B */ |
| 9062 | priv->is_ht_enabled = 1; |
| 9063 | priv->channel_width = IWL_CHANNEL_WIDTH_40MHZ; |
| 9064 | priv->valid_antenna = 0x7; /* assume all 3 connected */ |
| 9065 | priv->ps_mode = IWL_MIMO_PS_NONE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9066 | |
| 9067 | iwl4965_set_rxon_chain(priv); |
| 9068 | |
| 9069 | printk(KERN_INFO DRV_NAME |
| 9070 | ": Detected Intel Wireless WiFi Link 4965AGN\n"); |
| 9071 | |
| 9072 | /* Device-specific setup */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9073 | if (iwl4965_hw_set_hw_setting(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9074 | IWL_ERROR("failed to set hw settings\n"); |
| 9075 | mutex_unlock(&priv->mutex); |
| 9076 | goto out_iounmap; |
| 9077 | } |
| 9078 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9079 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9080 | if (iwl4965_param_qos_enable) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9081 | priv->qos_data.qos_enable = 1; |
| 9082 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9083 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9084 | |
| 9085 | priv->qos_data.qos_active = 0; |
| 9086 | priv->qos_data.qos_cap.val = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9087 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9088 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9089 | iwl4965_set_rxon_channel(priv, MODE_IEEE80211G, 6); |
| 9090 | iwl4965_setup_deferred_work(priv); |
| 9091 | iwl4965_setup_rx_handlers(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9092 | |
| 9093 | priv->rates_mask = IWL_RATES_MASK; |
| 9094 | /* If power management is turned on, default to AC mode */ |
| 9095 | priv->power_mode = IWL_POWER_AC; |
| 9096 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 9097 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9098 | iwl4965_disable_interrupts(priv); |
Jes Sorensen | 49df2b3 | 2007-10-26 16:10:39 +0200 | [diff] [blame] | 9099 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9100 | pci_enable_msi(pdev); |
| 9101 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9102 | err = request_irq(pdev->irq, iwl4965_isr, IRQF_SHARED, DRV_NAME, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9103 | if (err) { |
| 9104 | IWL_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 9105 | goto out_disable_msi; |
| 9106 | } |
| 9107 | |
| 9108 | mutex_lock(&priv->mutex); |
| 9109 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9110 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9111 | if (err) { |
| 9112 | IWL_ERROR("failed to create sysfs device attributes\n"); |
| 9113 | mutex_unlock(&priv->mutex); |
| 9114 | goto out_release_irq; |
| 9115 | } |
| 9116 | |
| 9117 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 9118 | * ucode filename and max sizes are card-specific. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9119 | err = iwl4965_read_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9120 | if (err) { |
| 9121 | IWL_ERROR("Could not read microcode: %d\n", err); |
| 9122 | mutex_unlock(&priv->mutex); |
| 9123 | goto out_pci_alloc; |
| 9124 | } |
| 9125 | |
| 9126 | mutex_unlock(&priv->mutex); |
| 9127 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 9128 | IWL_DEBUG_INFO("Queueing UP work.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9129 | |
| 9130 | queue_work(priv->workqueue, &priv->up); |
| 9131 | |
| 9132 | return 0; |
| 9133 | |
| 9134 | out_pci_alloc: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9135 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9136 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9137 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9138 | |
| 9139 | out_release_irq: |
| 9140 | free_irq(pdev->irq, priv); |
| 9141 | |
| 9142 | out_disable_msi: |
| 9143 | pci_disable_msi(pdev); |
| 9144 | destroy_workqueue(priv->workqueue); |
| 9145 | priv->workqueue = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9146 | iwl4965_unset_hw_setting(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9147 | |
| 9148 | out_iounmap: |
| 9149 | pci_iounmap(pdev, priv->hw_base); |
| 9150 | out_pci_release_regions: |
| 9151 | pci_release_regions(pdev); |
| 9152 | out_pci_disable_device: |
| 9153 | pci_disable_device(pdev); |
| 9154 | pci_set_drvdata(pdev, NULL); |
| 9155 | out_ieee80211_free_hw: |
| 9156 | ieee80211_free_hw(priv->hw); |
| 9157 | out: |
| 9158 | return err; |
| 9159 | } |
| 9160 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9161 | static void iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9162 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9163 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9164 | struct list_head *p, *q; |
| 9165 | int i; |
| 9166 | |
| 9167 | if (!priv) |
| 9168 | return; |
| 9169 | |
| 9170 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 9171 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9172 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 9173 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9174 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9175 | |
| 9176 | /* Free MAC hash list for ADHOC */ |
| 9177 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 9178 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 9179 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9180 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9181 | } |
| 9182 | } |
| 9183 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9184 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9185 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9186 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9187 | |
| 9188 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9189 | iwl4965_rx_queue_free(priv, &priv->rxq); |
| 9190 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9191 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9192 | iwl4965_unset_hw_setting(priv); |
| 9193 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9194 | |
| 9195 | if (priv->mac80211_registered) { |
| 9196 | ieee80211_unregister_hw(priv->hw); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9197 | iwl4965_rate_control_unregister(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9198 | } |
| 9199 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 9200 | /*netif_stop_queue(dev); */ |
| 9201 | flush_workqueue(priv->workqueue); |
| 9202 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9203 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9204 | * priv->workqueue... so we can't take down the workqueue |
| 9205 | * until now... */ |
| 9206 | destroy_workqueue(priv->workqueue); |
| 9207 | priv->workqueue = NULL; |
| 9208 | |
| 9209 | free_irq(pdev->irq, priv); |
| 9210 | pci_disable_msi(pdev); |
| 9211 | pci_iounmap(pdev, priv->hw_base); |
| 9212 | pci_release_regions(pdev); |
| 9213 | pci_disable_device(pdev); |
| 9214 | pci_set_drvdata(pdev, NULL); |
| 9215 | |
| 9216 | kfree(priv->channel_info); |
| 9217 | |
| 9218 | kfree(priv->ieee_channels); |
| 9219 | kfree(priv->ieee_rates); |
| 9220 | |
| 9221 | if (priv->ibss_beacon) |
| 9222 | dev_kfree_skb(priv->ibss_beacon); |
| 9223 | |
| 9224 | ieee80211_free_hw(priv->hw); |
| 9225 | } |
| 9226 | |
| 9227 | #ifdef CONFIG_PM |
| 9228 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9229 | 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] | 9230 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9231 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9232 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9233 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 9234 | |
| 9235 | /* Take down the device; powers it off, etc. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9236 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9237 | |
| 9238 | if (priv->mac80211_registered) |
| 9239 | ieee80211_stop_queues(priv->hw); |
| 9240 | |
| 9241 | pci_save_state(pdev); |
| 9242 | pci_disable_device(pdev); |
| 9243 | pci_set_power_state(pdev, PCI_D3hot); |
| 9244 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9245 | return 0; |
| 9246 | } |
| 9247 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9248 | static void iwl4965_resume(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9249 | { |
| 9250 | unsigned long flags; |
| 9251 | |
| 9252 | /* The following it a temporary work around due to the |
| 9253 | * suspend / resume not fully initializing the NIC correctly. |
| 9254 | * Without all of the following, resume will not attempt to take |
| 9255 | * down the NIC (it shouldn't really need to) and will just try |
| 9256 | * and bring the NIC back up. However that fails during the |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9257 | * ucode verification process. This then causes iwl4965_down to be |
| 9258 | * called *after* iwl4965_hw_nic_init() has succeeded -- which |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9259 | * then lets the next init sequence succeed. So, we've |
| 9260 | * replicated all of that NIC init code here... */ |
| 9261 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9262 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9263 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9264 | iwl4965_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9265 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9266 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 9267 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9268 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9269 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 9270 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 9271 | 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] | 9272 | |
| 9273 | /* tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9274 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9275 | |
| 9276 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9277 | iwl4965_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9278 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9279 | if (!iwl4965_grab_nic_access(priv)) { |
| 9280 | iwl4965_write_prph(priv, APMG_CLK_DIS_REG, |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 9281 | APMG_CLK_VAL_DMA_CLK_RQT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9282 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9283 | } |
| 9284 | spin_unlock_irqrestore(&priv->lock, flags); |
| 9285 | |
| 9286 | udelay(5); |
| 9287 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9288 | iwl4965_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9289 | |
| 9290 | /* Bring the device back up */ |
| 9291 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
| 9292 | queue_work(priv->workqueue, &priv->up); |
| 9293 | } |
| 9294 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9295 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9296 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9297 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9298 | int err; |
| 9299 | |
| 9300 | printk(KERN_INFO "Coming out of suspend...\n"); |
| 9301 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9302 | pci_set_power_state(pdev, PCI_D0); |
| 9303 | err = pci_enable_device(pdev); |
| 9304 | pci_restore_state(pdev); |
| 9305 | |
| 9306 | /* |
| 9307 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 9308 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 9309 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 9310 | * here since it only restores the first 64 bytes pci config header. |
| 9311 | */ |
| 9312 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 9313 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9314 | iwl4965_resume(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9315 | |
| 9316 | return 0; |
| 9317 | } |
| 9318 | |
| 9319 | #endif /* CONFIG_PM */ |
| 9320 | |
| 9321 | /***************************************************************************** |
| 9322 | * |
| 9323 | * driver and module entry point |
| 9324 | * |
| 9325 | *****************************************************************************/ |
| 9326 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9327 | static struct pci_driver iwl4965_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9328 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9329 | .id_table = iwl4965_hw_card_ids, |
| 9330 | .probe = iwl4965_pci_probe, |
| 9331 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9332 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9333 | .suspend = iwl4965_pci_suspend, |
| 9334 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9335 | #endif |
| 9336 | }; |
| 9337 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9338 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9339 | { |
| 9340 | |
| 9341 | int ret; |
| 9342 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 9343 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9344 | ret = pci_register_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9345 | if (ret) { |
| 9346 | IWL_ERROR("Unable to initialize PCI module\n"); |
| 9347 | return ret; |
| 9348 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9349 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9350 | ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9351 | if (ret) { |
| 9352 | IWL_ERROR("Unable to create driver sysfs file\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9353 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9354 | return ret; |
| 9355 | } |
| 9356 | #endif |
| 9357 | |
| 9358 | return ret; |
| 9359 | } |
| 9360 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9361 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9362 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9363 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9364 | driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9365 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9366 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9367 | } |
| 9368 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9369 | module_param_named(antenna, iwl4965_param_antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9370 | 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] | 9371 | module_param_named(disable, iwl4965_param_disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9372 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9373 | module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9374 | MODULE_PARM_DESC(hwcrypto, |
| 9375 | "using hardware crypto engine (default 0 [software])\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9376 | module_param_named(debug, iwl4965_param_debug, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9377 | MODULE_PARM_DESC(debug, "debug output mask"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9378 | 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] | 9379 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 9380 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9381 | module_param_named(queues_num, iwl4965_param_queues_num, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9382 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 9383 | |
| 9384 | /* QoS */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9385 | module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9386 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
| 9387 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9388 | module_exit(iwl4965_exit); |
| 9389 | module_init(iwl4965_init); |