Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. |
| 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/version.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/skbuff.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/wireless.h> |
| 40 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 41 | #include <linux/etherdevice.h> |
| 42 | #include <linux/if_arp.h> |
| 43 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 44 | #include <net/mac80211.h> |
| 45 | |
| 46 | #include <asm/div64.h> |
| 47 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 48 | #include "iwl-4965.h" |
| 49 | #include "iwl-helpers.h" |
| 50 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 51 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 52 | u32 iwl4965_debug_level; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 53 | #endif |
| 54 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 55 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 56 | struct iwl4965_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 57 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 58 | /****************************************************************************** |
| 59 | * |
| 60 | * module boiler plate |
| 61 | * |
| 62 | ******************************************************************************/ |
| 63 | |
| 64 | /* module parameters */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 65 | static int iwl4965_param_disable_hw_scan; /* def: 0 = use 4965's h/w scan */ |
| 66 | static int iwl4965_param_debug; /* def: 0 = minimal debug log messages */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 67 | static int iwl4965_param_disable; /* def: enable radio */ |
| 68 | static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */ |
| 69 | int iwl4965_param_hwcrypto; /* def: using software encryption */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 70 | static int iwl4965_param_qos_enable = 1; /* def: 1 = use quality of service */ |
| 71 | int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 16 Tx queues */ |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 72 | int iwl4965_param_amsdu_size_8K; /* def: enable 8K amsdu size */ |
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 | 7197266 | 2008-01-14 17:46:23 -0800 | [diff] [blame] | 93 | #define IWLWIFI_VERSION "1.2.23k" 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 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 186 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 187 | * of buffer descriptors, each of which points to one or more data buffers for |
| 188 | * the device to read from or fill. Driver and device exchange status of each |
| 189 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 190 | * entries in each circular buffer, to protect against confusing empty and full |
| 191 | * queue states. |
| 192 | * |
| 193 | * The device reads or writes the data in the queues via the device's several |
| 194 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 195 | * |
| 196 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 197 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 198 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 199 | * Tx queue resumed. |
| 200 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 201 | * The 4965 operates with up to 17 queues: One receive queue, one transmit |
| 202 | * queue (#4) for sending commands to the device firmware, and 15 other |
| 203 | * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels. |
Ben Cahill | e385144 | 2007-11-29 11:10:07 +0800 | [diff] [blame] | 204 | * |
| 205 | * See more detailed info in iwl-4965-hw.h. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 206 | ***************************************************/ |
| 207 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 208 | static int iwl4965_queue_space(const struct iwl4965_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 209 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 210 | int s = q->read_ptr - q->write_ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 211 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 212 | if (q->read_ptr > q->write_ptr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 213 | s -= q->n_bd; |
| 214 | |
| 215 | if (s <= 0) |
| 216 | s += q->n_window; |
| 217 | /* keep some reserve to not confuse empty and full situations */ |
| 218 | s -= 2; |
| 219 | if (s < 0) |
| 220 | s = 0; |
| 221 | return s; |
| 222 | } |
| 223 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 224 | /** |
| 225 | * iwl4965_queue_inc_wrap - increment queue index, wrap back to beginning |
| 226 | * @index -- current index |
| 227 | * @n_bd -- total number of entries in queue (must be power of 2) |
| 228 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 229 | static inline int iwl4965_queue_inc_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 230 | { |
| 231 | return ++index & (n_bd - 1); |
| 232 | } |
| 233 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 234 | /** |
| 235 | * iwl4965_queue_dec_wrap - decrement queue index, wrap back to end |
| 236 | * @index -- current index |
| 237 | * @n_bd -- total number of entries in queue (must be power of 2) |
| 238 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 239 | static inline int iwl4965_queue_dec_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 240 | { |
| 241 | return --index & (n_bd - 1); |
| 242 | } |
| 243 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 244 | 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] | 245 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 246 | return q->write_ptr > q->read_ptr ? |
| 247 | (i >= q->read_ptr && i < q->write_ptr) : |
| 248 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 251 | 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] | 252 | { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 253 | /* This is for scan command, the big buffer at end of command array */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 254 | if (is_huge) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 255 | return q->n_window; /* must be power of 2 */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 256 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 257 | /* Otherwise, use normal size buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 258 | return index & (q->n_window - 1); |
| 259 | } |
| 260 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 261 | /** |
| 262 | * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes |
| 263 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 264 | 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] | 265 | int count, int slots_num, u32 id) |
| 266 | { |
| 267 | q->n_bd = count; |
| 268 | q->n_window = slots_num; |
| 269 | q->id = id; |
| 270 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 271 | /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap |
| 272 | * and iwl4965_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 273 | BUG_ON(!is_power_of_2(count)); |
| 274 | |
| 275 | /* slots_num must be power-of-two size, otherwise |
| 276 | * get_cmd_index is broken. */ |
| 277 | BUG_ON(!is_power_of_2(slots_num)); |
| 278 | |
| 279 | q->low_mark = q->n_window / 4; |
| 280 | if (q->low_mark < 4) |
| 281 | q->low_mark = 4; |
| 282 | |
| 283 | q->high_mark = q->n_window / 8; |
| 284 | if (q->high_mark < 2) |
| 285 | q->high_mark = 2; |
| 286 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 287 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 292 | /** |
| 293 | * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 294 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 295 | static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv, |
| 296 | struct iwl4965_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 297 | { |
| 298 | struct pci_dev *dev = priv->pci_dev; |
| 299 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 300 | /* Driver private data, only for Tx (not command) queues, |
| 301 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 302 | if (id != IWL_CMD_QUEUE_NUM) { |
| 303 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 304 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 305 | if (!txq->txb) { |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 306 | IWL_ERROR("kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 307 | "structures failed\n"); |
| 308 | goto error; |
| 309 | } |
| 310 | } else |
| 311 | txq->txb = NULL; |
| 312 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 313 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 314 | * shared with device */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 315 | txq->bd = pci_alloc_consistent(dev, |
| 316 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 317 | &txq->q.dma_addr); |
| 318 | |
| 319 | if (!txq->bd) { |
| 320 | IWL_ERROR("pci_alloc_consistent(%zd) failed\n", |
| 321 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 322 | goto error; |
| 323 | } |
| 324 | txq->q.id = id; |
| 325 | |
| 326 | return 0; |
| 327 | |
| 328 | error: |
| 329 | if (txq->txb) { |
| 330 | kfree(txq->txb); |
| 331 | txq->txb = NULL; |
| 332 | } |
| 333 | |
| 334 | return -ENOMEM; |
| 335 | } |
| 336 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 337 | /** |
| 338 | * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 339 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 340 | int iwl4965_tx_queue_init(struct iwl4965_priv *priv, |
| 341 | struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 342 | { |
| 343 | struct pci_dev *dev = priv->pci_dev; |
| 344 | int len; |
| 345 | int rc = 0; |
| 346 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 347 | /* |
| 348 | * Alloc buffer array for commands (Tx or other types of commands). |
| 349 | * For the command queue (#4), allocate command space + one big |
| 350 | * command for scan, since scan command is very huge; the system will |
| 351 | * not have two scans at the same time, so only one is needed. |
Tomas Winkler | bb54244 | 2007-12-05 20:59:59 +0200 | [diff] [blame] | 352 | * For normal Tx queues (all other queues), no super-size command |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 353 | * space is needed. |
| 354 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 355 | len = sizeof(struct iwl4965_cmd) * slots_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 356 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 357 | len += IWL_MAX_SCAN_SIZE; |
| 358 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 359 | if (!txq->cmd) |
| 360 | return -ENOMEM; |
| 361 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 362 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 363 | rc = iwl4965_tx_queue_alloc(priv, txq, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 364 | if (rc) { |
| 365 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 366 | |
| 367 | return -ENOMEM; |
| 368 | } |
| 369 | txq->need_update = 0; |
| 370 | |
| 371 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 372 | * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 373 | BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 374 | |
| 375 | /* Initialize queue's high/low-water marks, and head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 376 | 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] | 377 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 378 | /* Tell device where to find queue */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 379 | iwl4965_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 385 | * iwl4965_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 386 | * @txq: Transmit queue to deallocate. |
| 387 | * |
| 388 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 389 | * Free all buffers. |
| 390 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 391 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 392 | 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] | 393 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 394 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 395 | struct pci_dev *dev = priv->pci_dev; |
| 396 | int len; |
| 397 | |
| 398 | if (q->n_bd == 0) |
| 399 | return; |
| 400 | |
| 401 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 402 | for (; q->write_ptr != q->read_ptr; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 403 | q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) |
| 404 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 405 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 406 | len = sizeof(struct iwl4965_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 407 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 408 | len += IWL_MAX_SCAN_SIZE; |
| 409 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 410 | /* De-alloc array of command/tx buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 411 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 412 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 413 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 414 | if (txq->q.n_bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 415 | pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 416 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 417 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 418 | /* De-alloc array of per-TFD driver data */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 419 | if (txq->txb) { |
| 420 | kfree(txq->txb); |
| 421 | txq->txb = NULL; |
| 422 | } |
| 423 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 424 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 425 | memset(txq, 0, sizeof(*txq)); |
| 426 | } |
| 427 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 428 | 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] | 429 | |
| 430 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 431 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 432 | * the functionality provided here |
| 433 | */ |
| 434 | |
| 435 | /**************************************************************/ |
| 436 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 437 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 438 | /** |
| 439 | * iwl4965_remove_station - Remove driver's knowledge of station. |
| 440 | * |
| 441 | * NOTE: This does not remove station from device's station table. |
| 442 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 443 | 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] | 444 | { |
| 445 | int index = IWL_INVALID_STATION; |
| 446 | int i; |
| 447 | unsigned long flags; |
| 448 | |
| 449 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 450 | |
| 451 | if (is_ap) |
| 452 | index = IWL_AP_ID; |
| 453 | else if (is_broadcast_ether_addr(addr)) |
| 454 | index = priv->hw_setting.bcast_sta_id; |
| 455 | else |
| 456 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) |
| 457 | if (priv->stations[i].used && |
| 458 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 459 | addr)) { |
| 460 | index = i; |
| 461 | break; |
| 462 | } |
| 463 | |
| 464 | if (unlikely(index == IWL_INVALID_STATION)) |
| 465 | goto out; |
| 466 | |
| 467 | if (priv->stations[index].used) { |
| 468 | priv->stations[index].used = 0; |
| 469 | priv->num_stations--; |
| 470 | } |
| 471 | |
| 472 | BUG_ON(priv->num_stations < 0); |
| 473 | |
| 474 | out: |
| 475 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 476 | return 0; |
| 477 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 478 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 479 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 480 | /** |
| 481 | * iwl4965_clear_stations_table - Clear the driver's station table |
| 482 | * |
| 483 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 484 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 485 | static void iwl4965_clear_stations_table(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 486 | { |
| 487 | unsigned long flags; |
| 488 | |
| 489 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 490 | |
| 491 | priv->num_stations = 0; |
| 492 | memset(priv->stations, 0, sizeof(priv->stations)); |
| 493 | |
| 494 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 495 | } |
| 496 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 497 | /** |
| 498 | * iwl4965_add_station_flags - Add station to tables in driver and device |
| 499 | */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 500 | u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr, |
| 501 | int is_ap, u8 flags, void *ht_data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 502 | { |
| 503 | int i; |
| 504 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 505 | struct iwl4965_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 506 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 507 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 508 | |
| 509 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 510 | if (is_ap) |
| 511 | index = IWL_AP_ID; |
| 512 | else if (is_broadcast_ether_addr(addr)) |
| 513 | index = priv->hw_setting.bcast_sta_id; |
| 514 | else |
| 515 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) { |
| 516 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 517 | addr)) { |
| 518 | index = i; |
| 519 | break; |
| 520 | } |
| 521 | |
| 522 | if (!priv->stations[i].used && |
| 523 | index == IWL_INVALID_STATION) |
| 524 | index = i; |
| 525 | } |
| 526 | |
| 527 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 528 | /* These two conditions have the same outcome, but keep them separate |
| 529 | since they have different meanings */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 530 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 531 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 532 | return index; |
| 533 | } |
| 534 | |
| 535 | if (priv->stations[index].used && |
| 536 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 537 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 538 | return index; |
| 539 | } |
| 540 | |
| 541 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 542 | 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] | 543 | station = &priv->stations[index]; |
| 544 | station->used = 1; |
| 545 | priv->num_stations++; |
| 546 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 547 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 548 | memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 549 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 550 | station->sta.mode = 0; |
| 551 | station->sta.sta.sta_id = index; |
| 552 | station->sta.station_flags = 0; |
| 553 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 554 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 555 | /* BCAST station and IBSS stations do not work in HT mode */ |
| 556 | if (index != priv->hw_setting.bcast_sta_id && |
| 557 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 558 | iwl4965_set_ht_add_station(priv, index, |
| 559 | (struct ieee80211_ht_info *) ht_data); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 560 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 561 | |
| 562 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 563 | |
| 564 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 565 | iwl4965_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 566 | return index; |
| 567 | |
| 568 | } |
| 569 | |
| 570 | /*************** DRIVER STATUS FUNCTIONS *****/ |
| 571 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 572 | static inline int iwl4965_is_ready(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 573 | { |
| 574 | /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are |
| 575 | * set but EXIT_PENDING is not */ |
| 576 | return test_bit(STATUS_READY, &priv->status) && |
| 577 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) && |
| 578 | !test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 579 | } |
| 580 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 581 | static inline int iwl4965_is_alive(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 582 | { |
| 583 | return test_bit(STATUS_ALIVE, &priv->status); |
| 584 | } |
| 585 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 586 | static inline int iwl4965_is_init(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 587 | { |
| 588 | return test_bit(STATUS_INIT, &priv->status); |
| 589 | } |
| 590 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 591 | static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 592 | { |
| 593 | return test_bit(STATUS_RF_KILL_HW, &priv->status) || |
| 594 | test_bit(STATUS_RF_KILL_SW, &priv->status); |
| 595 | } |
| 596 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 597 | static inline int iwl4965_is_ready_rf(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 598 | { |
| 599 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 600 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 601 | return 0; |
| 602 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 603 | return iwl4965_is_ready(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 607 | |
| 608 | #define IWL_CMD(x) case x : return #x |
| 609 | |
| 610 | static const char *get_cmd_string(u8 cmd) |
| 611 | { |
| 612 | switch (cmd) { |
| 613 | IWL_CMD(REPLY_ALIVE); |
| 614 | IWL_CMD(REPLY_ERROR); |
| 615 | IWL_CMD(REPLY_RXON); |
| 616 | IWL_CMD(REPLY_RXON_ASSOC); |
| 617 | IWL_CMD(REPLY_QOS_PARAM); |
| 618 | IWL_CMD(REPLY_RXON_TIMING); |
| 619 | IWL_CMD(REPLY_ADD_STA); |
| 620 | IWL_CMD(REPLY_REMOVE_STA); |
| 621 | IWL_CMD(REPLY_REMOVE_ALL_STA); |
| 622 | IWL_CMD(REPLY_TX); |
| 623 | IWL_CMD(REPLY_RATE_SCALE); |
| 624 | IWL_CMD(REPLY_LEDS_CMD); |
| 625 | IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); |
| 626 | IWL_CMD(RADAR_NOTIFICATION); |
| 627 | IWL_CMD(REPLY_QUIET_CMD); |
| 628 | IWL_CMD(REPLY_CHANNEL_SWITCH); |
| 629 | IWL_CMD(CHANNEL_SWITCH_NOTIFICATION); |
| 630 | IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD); |
| 631 | IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION); |
| 632 | IWL_CMD(POWER_TABLE_CMD); |
| 633 | IWL_CMD(PM_SLEEP_NOTIFICATION); |
| 634 | IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC); |
| 635 | IWL_CMD(REPLY_SCAN_CMD); |
| 636 | IWL_CMD(REPLY_SCAN_ABORT_CMD); |
| 637 | IWL_CMD(SCAN_START_NOTIFICATION); |
| 638 | IWL_CMD(SCAN_RESULTS_NOTIFICATION); |
| 639 | IWL_CMD(SCAN_COMPLETE_NOTIFICATION); |
| 640 | IWL_CMD(BEACON_NOTIFICATION); |
| 641 | IWL_CMD(REPLY_TX_BEACON); |
| 642 | IWL_CMD(WHO_IS_AWAKE_NOTIFICATION); |
| 643 | IWL_CMD(QUIET_NOTIFICATION); |
| 644 | IWL_CMD(REPLY_TX_PWR_TABLE_CMD); |
| 645 | IWL_CMD(MEASURE_ABORT_NOTIFICATION); |
| 646 | IWL_CMD(REPLY_BT_CONFIG); |
| 647 | IWL_CMD(REPLY_STATISTICS_CMD); |
| 648 | IWL_CMD(STATISTICS_NOTIFICATION); |
| 649 | IWL_CMD(REPLY_CARD_STATE_CMD); |
| 650 | IWL_CMD(CARD_STATE_NOTIFICATION); |
| 651 | IWL_CMD(MISSED_BEACONS_NOTIFICATION); |
| 652 | IWL_CMD(REPLY_CT_KILL_CONFIG_CMD); |
| 653 | IWL_CMD(SENSITIVITY_CMD); |
| 654 | IWL_CMD(REPLY_PHY_CALIBRATION_CMD); |
| 655 | IWL_CMD(REPLY_RX_PHY_CMD); |
| 656 | IWL_CMD(REPLY_RX_MPDU_CMD); |
| 657 | IWL_CMD(REPLY_4965_RX); |
| 658 | IWL_CMD(REPLY_COMPRESSED_BA); |
| 659 | default: |
| 660 | return "UNKNOWN"; |
| 661 | |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 666 | |
| 667 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 668 | * iwl4965_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 669 | * @priv: device private data point |
| 670 | * @cmd: a point to the ucode command structure |
| 671 | * |
| 672 | * The function returns < 0 values to indicate the operation is |
| 673 | * failed. On success, it turns the index (> 0) of command in the |
| 674 | * command queue. |
| 675 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 676 | 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] | 677 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 678 | struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 679 | struct iwl4965_queue *q = &txq->q; |
| 680 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 681 | u32 *control_flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 682 | struct iwl4965_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 683 | u32 idx; |
| 684 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 685 | dma_addr_t phys_addr; |
| 686 | int ret; |
| 687 | unsigned long flags; |
| 688 | |
| 689 | /* If any of the command structures end up being larger than |
| 690 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 691 | * we will need to increase the size of the TFD entries */ |
| 692 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 693 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 694 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 695 | if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 696 | IWL_ERROR("No space for Tx\n"); |
| 697 | return -ENOSPC; |
| 698 | } |
| 699 | |
| 700 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 701 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 702 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 703 | memset(tfd, 0, sizeof(*tfd)); |
| 704 | |
| 705 | control_flags = (u32 *) tfd; |
| 706 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 707 | 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] | 708 | out_cmd = &txq->cmd[idx]; |
| 709 | |
| 710 | out_cmd->hdr.cmd = cmd->id; |
| 711 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 712 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 713 | |
| 714 | /* At this point, the out_cmd now has all of the incoming cmd |
| 715 | * information */ |
| 716 | |
| 717 | out_cmd->hdr.flags = 0; |
| 718 | 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] | 719 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 720 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 721 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 722 | |
| 723 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 724 | offsetof(struct iwl4965_cmd, hdr); |
| 725 | 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] | 726 | |
| 727 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 728 | "%d bytes at %d[%d]:%d\n", |
| 729 | get_cmd_string(out_cmd->hdr.cmd), |
| 730 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 731 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 732 | |
| 733 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 734 | |
| 735 | /* Set up entry in queue's byte count circular buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 736 | ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 737 | |
| 738 | /* Increment and update queue's write index */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 739 | q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 740 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 741 | |
| 742 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 743 | return ret ? ret : idx; |
| 744 | } |
| 745 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 746 | 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] | 747 | { |
| 748 | int ret; |
| 749 | |
| 750 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 751 | |
| 752 | /* An asynchronous command can not expect an SKB to be set. */ |
| 753 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 754 | |
| 755 | /* An asynchronous command MUST have a callback. */ |
| 756 | BUG_ON(!cmd->meta.u.callback); |
| 757 | |
| 758 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 759 | return -EBUSY; |
| 760 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 761 | ret = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 762 | if (ret < 0) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 763 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 764 | get_cmd_string(cmd->id), ret); |
| 765 | return ret; |
| 766 | } |
| 767 | return 0; |
| 768 | } |
| 769 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 770 | 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] | 771 | { |
| 772 | int cmd_idx; |
| 773 | int ret; |
| 774 | static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */ |
| 775 | |
| 776 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 777 | |
| 778 | /* A synchronous command can not have a callback set. */ |
| 779 | BUG_ON(cmd->meta.u.callback != NULL); |
| 780 | |
| 781 | if (atomic_xchg(&entry, 1)) { |
| 782 | IWL_ERROR("Error sending %s: Already sending a host command\n", |
| 783 | get_cmd_string(cmd->id)); |
| 784 | return -EBUSY; |
| 785 | } |
| 786 | |
| 787 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 788 | |
| 789 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 790 | cmd->meta.source = &cmd->meta; |
| 791 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 792 | cmd_idx = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 793 | if (cmd_idx < 0) { |
| 794 | ret = cmd_idx; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 795 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 796 | get_cmd_string(cmd->id), ret); |
| 797 | goto out; |
| 798 | } |
| 799 | |
| 800 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 801 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 802 | HOST_COMPLETE_TIMEOUT); |
| 803 | if (!ret) { |
| 804 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
| 805 | IWL_ERROR("Error sending %s: time out after %dms.\n", |
| 806 | get_cmd_string(cmd->id), |
| 807 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 808 | |
| 809 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 810 | ret = -ETIMEDOUT; |
| 811 | goto cancel; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 816 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 817 | get_cmd_string(cmd->id)); |
| 818 | ret = -ECANCELED; |
| 819 | goto fail; |
| 820 | } |
| 821 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 822 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 823 | get_cmd_string(cmd->id)); |
| 824 | ret = -EIO; |
| 825 | goto fail; |
| 826 | } |
| 827 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
| 828 | IWL_ERROR("Error: Response NULL in '%s'\n", |
| 829 | get_cmd_string(cmd->id)); |
| 830 | ret = -EIO; |
| 831 | goto out; |
| 832 | } |
| 833 | |
| 834 | ret = 0; |
| 835 | goto out; |
| 836 | |
| 837 | cancel: |
| 838 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 839 | struct iwl4965_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 840 | |
| 841 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 842 | * TX cmd queue. Otherwise in case the cmd comes |
| 843 | * in later, it will possibly set an invalid |
| 844 | * address (cmd->meta.source). */ |
| 845 | qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
| 846 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 847 | } |
| 848 | fail: |
| 849 | if (cmd->meta.u.skb) { |
| 850 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 851 | cmd->meta.u.skb = NULL; |
| 852 | } |
| 853 | out: |
| 854 | atomic_set(&entry, 0); |
| 855 | return ret; |
| 856 | } |
| 857 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 858 | 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] | 859 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 860 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 861 | return iwl4965_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 862 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 863 | return iwl4965_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 866 | int iwl4965_send_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] | 867 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 868 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 869 | .id = id, |
| 870 | .len = len, |
| 871 | .data = data, |
| 872 | }; |
| 873 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 874 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 877 | 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] | 878 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 879 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 880 | .id = id, |
| 881 | .len = sizeof(val), |
| 882 | .data = &val, |
| 883 | }; |
| 884 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 885 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 888 | int iwl4965_send_statistics_request(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 889 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 890 | return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 894 | * iwl4965_rxon_add_station - add station into station table. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 895 | * |
| 896 | * there is only one AP station with id= IWL_AP_ID |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 897 | * NOTE: mutex must be held before calling this fnction |
| 898 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 899 | static int iwl4965_rxon_add_station(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 900 | const u8 *addr, int is_ap) |
| 901 | { |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 902 | u8 sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 903 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 904 | /* Add station to device's station table */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 905 | #ifdef CONFIG_IWL4965_HT |
| 906 | struct ieee80211_conf *conf = &priv->hw->conf; |
| 907 | struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf; |
| 908 | |
| 909 | if ((is_ap) && |
| 910 | (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && |
| 911 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 912 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 913 | 0, cur_ht_config); |
| 914 | else |
| 915 | #endif /* CONFIG_IWL4965_HT */ |
| 916 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 917 | 0, NULL); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 918 | |
| 919 | /* Set up default rate scaling table in device's station table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 920 | iwl4965_add_station(priv, addr, is_ap); |
| 921 | |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 922 | return sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 926 | * 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] | 927 | * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz |
| 928 | * @channel: Any channel valid for the requested phymode |
| 929 | |
| 930 | * In addition to setting the staging RXON, priv->phymode is also set. |
| 931 | * |
| 932 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
| 933 | * in the staging RXON flag structure based on the phymode |
| 934 | */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 935 | static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, u8 phymode, |
| 936 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 937 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 938 | if (!iwl4965_get_channel_info(priv, phymode, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 939 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
| 940 | channel, phymode); |
| 941 | return -EINVAL; |
| 942 | } |
| 943 | |
| 944 | if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && |
| 945 | (priv->phymode == phymode)) |
| 946 | return 0; |
| 947 | |
| 948 | priv->staging_rxon.channel = cpu_to_le16(channel); |
| 949 | if (phymode == MODE_IEEE80211A) |
| 950 | priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
| 951 | else |
| 952 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 953 | |
| 954 | priv->phymode = phymode; |
| 955 | |
| 956 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode); |
| 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 962 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 963 | * |
| 964 | * NOTE: This is really only useful during development and can eventually |
| 965 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 966 | * making changes |
| 967 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 968 | static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 969 | { |
| 970 | int error = 0; |
| 971 | int counter = 1; |
| 972 | |
| 973 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 974 | error |= le32_to_cpu(rxon->flags & |
| 975 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 976 | RXON_FLG_RADAR_DETECT_MSK)); |
| 977 | if (error) |
| 978 | IWL_WARNING("check 24G fields %d | %d\n", |
| 979 | counter++, error); |
| 980 | } else { |
| 981 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 982 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 983 | if (error) |
| 984 | IWL_WARNING("check 52 fields %d | %d\n", |
| 985 | counter++, error); |
| 986 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 987 | if (error) |
| 988 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 989 | counter++, error); |
| 990 | } |
| 991 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 992 | if (error) |
| 993 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 994 | |
| 995 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 996 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 997 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 998 | if (error) |
| 999 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 1000 | |
| 1001 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 1002 | if (error) |
| 1003 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 1004 | |
| 1005 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 1006 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 1007 | if (error) |
| 1008 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 1009 | counter++, error); |
| 1010 | |
| 1011 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 1012 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 1013 | if (error) |
| 1014 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 1015 | counter++, error); |
| 1016 | |
| 1017 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 1018 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 1019 | if (error) |
| 1020 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 1021 | counter++, error); |
| 1022 | |
| 1023 | if (error) |
| 1024 | IWL_WARNING("Tuning to channel %d\n", |
| 1025 | le16_to_cpu(rxon->channel)); |
| 1026 | |
| 1027 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1028 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1029 | return -1; |
| 1030 | } |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1035 | * 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] | 1036 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1037 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1038 | * If the RXON structure is changing enough to require a new tune, |
| 1039 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 1040 | * 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] | 1041 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1042 | static int iwl4965_full_rxon_required(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1043 | { |
| 1044 | |
| 1045 | /* These items are only settable from the full RXON command */ |
| 1046 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 1047 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 1048 | priv->active_rxon.bssid_addr) || |
| 1049 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 1050 | priv->active_rxon.node_addr) || |
| 1051 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 1052 | priv->active_rxon.wlap_bssid_addr) || |
| 1053 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 1054 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 1055 | (priv->staging_rxon.air_propagation != |
| 1056 | priv->active_rxon.air_propagation) || |
| 1057 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 1058 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 1059 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 1060 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 1061 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 1062 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 1063 | return 1; |
| 1064 | |
| 1065 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 1066 | * be updated with the RXON_ASSOC command -- however only some |
| 1067 | * flag transitions are allowed using RXON_ASSOC */ |
| 1068 | |
| 1069 | /* Check if we are not switching bands */ |
| 1070 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 1071 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 1072 | return 1; |
| 1073 | |
| 1074 | /* Check if we are switching association toggle */ |
| 1075 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 1076 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 1077 | return 1; |
| 1078 | |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1082 | static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1083 | { |
| 1084 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1085 | struct iwl4965_rx_packet *res = NULL; |
| 1086 | struct iwl4965_rxon_assoc_cmd rxon_assoc; |
| 1087 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1088 | .id = REPLY_RXON_ASSOC, |
| 1089 | .len = sizeof(rxon_assoc), |
| 1090 | .meta.flags = CMD_WANT_SKB, |
| 1091 | .data = &rxon_assoc, |
| 1092 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1093 | const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 1094 | const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1095 | |
| 1096 | if ((rxon1->flags == rxon2->flags) && |
| 1097 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 1098 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 1099 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 1100 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 1101 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 1102 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 1103 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 1104 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 1105 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 1106 | return 0; |
| 1107 | } |
| 1108 | |
| 1109 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 1110 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 1111 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 1112 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
| 1113 | rxon_assoc.reserved = 0; |
| 1114 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 1115 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates; |
| 1116 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 1117 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; |
| 1118 | rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; |
| 1119 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1120 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | if (rc) |
| 1122 | return rc; |
| 1123 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1124 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1125 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1126 | IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n"); |
| 1127 | rc = -EIO; |
| 1128 | } |
| 1129 | |
| 1130 | priv->alloc_rxb_skb--; |
| 1131 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1132 | |
| 1133 | return rc; |
| 1134 | } |
| 1135 | |
| 1136 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1137 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1138 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1139 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1140 | * the active_rxon structure is updated with the new data. This |
| 1141 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 1142 | * a HW tune is required based on the RXON structure changes. |
| 1143 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1144 | static int iwl4965_commit_rxon(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1145 | { |
| 1146 | /* cast away the const for active_rxon in this function */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1147 | struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1148 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1149 | int rc = 0; |
| 1150 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1151 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1152 | return -1; |
| 1153 | |
| 1154 | /* always get timestamp with Rx frame */ |
| 1155 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 1156 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1157 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1158 | if (rc) { |
| 1159 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 1160 | return -EINVAL; |
| 1161 | } |
| 1162 | |
| 1163 | /* 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] | 1164 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1165 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1166 | if (!iwl4965_full_rxon_required(priv)) { |
| 1167 | rc = iwl4965_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1168 | if (rc) { |
| 1169 | IWL_ERROR("Error setting RXON_ASSOC " |
| 1170 | "configuration (%d).\n", rc); |
| 1171 | return rc; |
| 1172 | } |
| 1173 | |
| 1174 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1175 | |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | /* station table will be cleared */ |
| 1180 | priv->assoc_station_added = 0; |
| 1181 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1182 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1183 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1184 | if (!priv->error_recovering) |
| 1185 | priv->start_calib = 0; |
| 1186 | |
| 1187 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1188 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1189 | |
| 1190 | /* If we are currently associated and the new config requires |
| 1191 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 1192 | * we must clear the associated from the active configuration |
| 1193 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1194 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1195 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 1196 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 1197 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1198 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1199 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1200 | sizeof(struct iwl4965_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1201 | &priv->active_rxon); |
| 1202 | |
| 1203 | /* If the mask clearing failed then we set |
| 1204 | * active_rxon back to what it was previously */ |
| 1205 | if (rc) { |
| 1206 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1207 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 1208 | "configuration (%d).\n", rc); |
| 1209 | return rc; |
| 1210 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | IWL_DEBUG_INFO("Sending RXON\n" |
| 1214 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 1215 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1216 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1217 | ((priv->staging_rxon.filter_flags & |
| 1218 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 1219 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1220 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1221 | |
| 1222 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1223 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1224 | sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1225 | if (rc) { |
| 1226 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 1227 | return rc; |
| 1228 | } |
| 1229 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1230 | iwl4965_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 1231 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1232 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1233 | if (!priv->error_recovering) |
| 1234 | priv->start_calib = 0; |
| 1235 | |
| 1236 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1237 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1238 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1239 | |
| 1240 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1241 | |
| 1242 | /* If we issue a new RXON command which required a tune then we must |
| 1243 | * 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] | 1244 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1245 | if (rc) { |
| 1246 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 1247 | return rc; |
| 1248 | } |
| 1249 | |
| 1250 | /* Add the broadcast address so we can send broadcast frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1251 | if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1252 | IWL_INVALID_STATION) { |
| 1253 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 1254 | return -EIO; |
| 1255 | } |
| 1256 | |
| 1257 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 1258 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1259 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1260 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1261 | if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1262 | == IWL_INVALID_STATION) { |
| 1263 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 1264 | return -EIO; |
| 1265 | } |
| 1266 | priv->assoc_station_added = 1; |
| 1267 | } |
| 1268 | |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1272 | static int iwl4965_send_bt_config(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1273 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1274 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1275 | .flags = 3, |
| 1276 | .lead_time = 0xAA, |
| 1277 | .max_kill = 1, |
| 1278 | .kill_ack_mask = 0, |
| 1279 | .kill_cts_mask = 0, |
| 1280 | }; |
| 1281 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1282 | return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
| 1283 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1286 | static int iwl4965_send_scan_abort(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1287 | { |
| 1288 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1289 | struct iwl4965_rx_packet *res; |
| 1290 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1291 | .id = REPLY_SCAN_ABORT_CMD, |
| 1292 | .meta.flags = CMD_WANT_SKB, |
| 1293 | }; |
| 1294 | |
| 1295 | /* If there isn't a scan actively going on in the hardware |
| 1296 | * then we are in between scan bands and not actually |
| 1297 | * actively scanning, so don't send the abort command */ |
| 1298 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1299 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1303 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1304 | if (rc) { |
| 1305 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1306 | return rc; |
| 1307 | } |
| 1308 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1309 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1310 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1311 | /* The scan abort will return 1 for success or |
| 1312 | * 2 for "failure". A failure condition can be |
| 1313 | * due to simply not being in an active scan which |
| 1314 | * can occur if we send the scan abort before we |
| 1315 | * the microcode has notified us that a scan is |
| 1316 | * completed. */ |
| 1317 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1318 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1319 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1320 | } |
| 1321 | |
| 1322 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1323 | |
| 1324 | return rc; |
| 1325 | } |
| 1326 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1327 | static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv, |
| 1328 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1329 | struct sk_buff *skb) |
| 1330 | { |
| 1331 | return 1; |
| 1332 | } |
| 1333 | |
| 1334 | /* |
| 1335 | * CARD_STATE_CMD |
| 1336 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1337 | * 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] | 1338 | * |
| 1339 | * When in the 'enable' state the card operates as normal. |
| 1340 | * When in the 'disable' state, the card enters into a low power mode. |
| 1341 | * When in the 'halt' state, the card is shut down and must be fully |
| 1342 | * restarted to come back on. |
| 1343 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1344 | 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] | 1345 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1346 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1347 | .id = REPLY_CARD_STATE_CMD, |
| 1348 | .len = sizeof(u32), |
| 1349 | .data = &flags, |
| 1350 | .meta.flags = meta_flag, |
| 1351 | }; |
| 1352 | |
| 1353 | if (meta_flag & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1354 | cmd.meta.u.callback = iwl4965_card_state_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1355 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1356 | return iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1359 | static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv, |
| 1360 | struct iwl4965_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1361 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1362 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1363 | |
| 1364 | if (!skb) { |
| 1365 | IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); |
| 1366 | return 1; |
| 1367 | } |
| 1368 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1369 | res = (struct iwl4965_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1370 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1371 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1372 | res->hdr.flags); |
| 1373 | return 1; |
| 1374 | } |
| 1375 | |
| 1376 | switch (res->u.add_sta.status) { |
| 1377 | case ADD_STA_SUCCESS_MSK: |
| 1378 | break; |
| 1379 | default: |
| 1380 | break; |
| 1381 | } |
| 1382 | |
| 1383 | /* We didn't cache the SKB; let the caller free it */ |
| 1384 | return 1; |
| 1385 | } |
| 1386 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1387 | int iwl4965_send_add_station(struct iwl4965_priv *priv, |
| 1388 | struct iwl4965_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1389 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1390 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1391 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1392 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1393 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1394 | .len = sizeof(struct iwl4965_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1395 | .meta.flags = flags, |
| 1396 | .data = sta, |
| 1397 | }; |
| 1398 | |
| 1399 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1400 | cmd.meta.u.callback = iwl4965_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1401 | else |
| 1402 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1403 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1404 | rc = iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1405 | |
| 1406 | if (rc || (flags & CMD_ASYNC)) |
| 1407 | return rc; |
| 1408 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1409 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1410 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1411 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1412 | res->hdr.flags); |
| 1413 | rc = -EIO; |
| 1414 | } |
| 1415 | |
| 1416 | if (rc == 0) { |
| 1417 | switch (res->u.add_sta.status) { |
| 1418 | case ADD_STA_SUCCESS_MSK: |
| 1419 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1420 | break; |
| 1421 | default: |
| 1422 | rc = -EIO; |
| 1423 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 1424 | break; |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | priv->alloc_rxb_skb--; |
| 1429 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1430 | |
| 1431 | return rc; |
| 1432 | } |
| 1433 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1434 | static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1435 | struct ieee80211_key_conf *keyconf, |
| 1436 | u8 sta_id) |
| 1437 | { |
| 1438 | unsigned long flags; |
| 1439 | __le16 key_flags = 0; |
| 1440 | |
| 1441 | switch (keyconf->alg) { |
| 1442 | case ALG_CCMP: |
| 1443 | key_flags |= STA_KEY_FLG_CCMP; |
| 1444 | key_flags |= cpu_to_le16( |
| 1445 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1446 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1447 | break; |
| 1448 | case ALG_TKIP: |
| 1449 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1450 | default: |
| 1451 | return -EINVAL; |
| 1452 | } |
| 1453 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1454 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 1455 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1456 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 1457 | keyconf->keylen); |
| 1458 | |
| 1459 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 1460 | keyconf->keylen); |
| 1461 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 1462 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1463 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1464 | |
| 1465 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1466 | |
| 1467 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1468 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1469 | return 0; |
| 1470 | } |
| 1471 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1472 | 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] | 1473 | { |
| 1474 | unsigned long flags; |
| 1475 | |
| 1476 | spin_lock_irqsave(&priv->sta_lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1477 | memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key)); |
| 1478 | memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1479 | priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1480 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1481 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1482 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1483 | |
| 1484 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1485 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1486 | return 0; |
| 1487 | } |
| 1488 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1489 | static void iwl4965_clear_free_frames(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1490 | { |
| 1491 | struct list_head *element; |
| 1492 | |
| 1493 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1494 | priv->frames_count); |
| 1495 | |
| 1496 | while (!list_empty(&priv->free_frames)) { |
| 1497 | element = priv->free_frames.next; |
| 1498 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1499 | kfree(list_entry(element, struct iwl4965_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1500 | priv->frames_count--; |
| 1501 | } |
| 1502 | |
| 1503 | if (priv->frames_count) { |
| 1504 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 1505 | priv->frames_count); |
| 1506 | priv->frames_count = 0; |
| 1507 | } |
| 1508 | } |
| 1509 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1510 | static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1511 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1512 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1513 | struct list_head *element; |
| 1514 | if (list_empty(&priv->free_frames)) { |
| 1515 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1516 | if (!frame) { |
| 1517 | IWL_ERROR("Could not allocate frame!\n"); |
| 1518 | return NULL; |
| 1519 | } |
| 1520 | |
| 1521 | priv->frames_count++; |
| 1522 | return frame; |
| 1523 | } |
| 1524 | |
| 1525 | element = priv->free_frames.next; |
| 1526 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1527 | return list_entry(element, struct iwl4965_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1530 | 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] | 1531 | { |
| 1532 | memset(frame, 0, sizeof(*frame)); |
| 1533 | list_add(&frame->list, &priv->free_frames); |
| 1534 | } |
| 1535 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1536 | unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1537 | struct ieee80211_hdr *hdr, |
| 1538 | const u8 *dest, int left) |
| 1539 | { |
| 1540 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1541 | if (!iwl4965_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1542 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 1543 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 1544 | return 0; |
| 1545 | |
| 1546 | if (priv->ibss_beacon->len > left) |
| 1547 | return 0; |
| 1548 | |
| 1549 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1550 | |
| 1551 | return priv->ibss_beacon->len; |
| 1552 | } |
| 1553 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1554 | int iwl4965_rate_index_from_plcp(int plcp) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1555 | { |
| 1556 | int i = 0; |
| 1557 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1558 | /* 4965 HT rate format */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1559 | if (plcp & RATE_MCS_HT_MSK) { |
| 1560 | i = (plcp & 0xff); |
| 1561 | |
| 1562 | if (i >= IWL_RATE_MIMO_6M_PLCP) |
| 1563 | i = i - IWL_RATE_MIMO_6M_PLCP; |
| 1564 | |
| 1565 | i += IWL_FIRST_OFDM_RATE; |
| 1566 | /* skip 9M not supported in ht*/ |
| 1567 | if (i >= IWL_RATE_9M_INDEX) |
| 1568 | i += 1; |
| 1569 | if ((i >= IWL_FIRST_OFDM_RATE) && |
| 1570 | (i <= IWL_LAST_OFDM_RATE)) |
| 1571 | return i; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1572 | |
| 1573 | /* 4965 legacy rate format, search for match in table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1574 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1575 | for (i = 0; i < ARRAY_SIZE(iwl4965_rates); i++) |
| 1576 | if (iwl4965_rates[i].plcp == (plcp &0xFF)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | return i; |
| 1578 | } |
| 1579 | return -1; |
| 1580 | } |
| 1581 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1582 | static u8 iwl4965_rate_get_lowest_plcp(int rate_mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1583 | { |
| 1584 | u8 i; |
| 1585 | |
| 1586 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1587 | i = iwl4965_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1588 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1589 | return iwl4965_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | return IWL_RATE_INVALID; |
| 1593 | } |
| 1594 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1595 | static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1596 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1597 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1598 | unsigned int frame_size; |
| 1599 | int rc; |
| 1600 | u8 rate; |
| 1601 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1602 | frame = iwl4965_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1603 | |
| 1604 | if (!frame) { |
| 1605 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 1606 | "command.\n"); |
| 1607 | return -ENOMEM; |
| 1608 | } |
| 1609 | |
| 1610 | if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1611 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1612 | 0xFF0); |
| 1613 | if (rate == IWL_INVALID_RATE) |
| 1614 | rate = IWL_RATE_6M_PLCP; |
| 1615 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1616 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1617 | if (rate == IWL_INVALID_RATE) |
| 1618 | rate = IWL_RATE_1M_PLCP; |
| 1619 | } |
| 1620 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1621 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1622 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1623 | rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1624 | &frame->u.cmd[0]); |
| 1625 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1626 | iwl4965_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1627 | |
| 1628 | return rc; |
| 1629 | } |
| 1630 | |
| 1631 | /****************************************************************************** |
| 1632 | * |
| 1633 | * EEPROM related functions |
| 1634 | * |
| 1635 | ******************************************************************************/ |
| 1636 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1637 | static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1638 | { |
| 1639 | memcpy(mac, priv->eeprom.mac_address, 6); |
| 1640 | } |
| 1641 | |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1642 | static inline void iwl4965_eeprom_release_semaphore(struct iwl4965_priv *priv) |
| 1643 | { |
| 1644 | iwl4965_clear_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 1645 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); |
| 1646 | } |
| 1647 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1648 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1649 | * iwl4965_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1650 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1651 | * Load the EEPROM contents from adapter into priv->eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1652 | * |
| 1653 | * NOTE: This routine uses the non-debug IO access functions. |
| 1654 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1655 | int iwl4965_eeprom_init(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1656 | { |
Al Viro | 0e5ce1f | 2007-12-22 13:45:50 -0500 | [diff] [blame] | 1657 | __le16 *e = (__le16 *)&priv->eeprom; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1658 | u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1659 | u32 r; |
| 1660 | int sz = sizeof(priv->eeprom); |
| 1661 | int rc; |
| 1662 | int i; |
| 1663 | u16 addr; |
| 1664 | |
| 1665 | /* The EEPROM structure has several padding buffers within it |
| 1666 | * and when adding new EEPROM maps is subject to programmer errors |
| 1667 | * which may be very difficult to identify without explicitly |
| 1668 | * checking the resulting size of the eeprom map. */ |
| 1669 | BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); |
| 1670 | |
| 1671 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
| 1672 | IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); |
| 1673 | return -ENOENT; |
| 1674 | } |
| 1675 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1676 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1677 | rc = iwl4965_eeprom_acquire_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1678 | if (rc < 0) { |
Ian Schram | 91e1747 | 2007-10-25 17:15:23 +0800 | [diff] [blame] | 1679 | IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1680 | return -ENOENT; |
| 1681 | } |
| 1682 | |
| 1683 | /* eeprom is an array of 16bit values */ |
| 1684 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1685 | _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1); |
| 1686 | _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1687 | |
| 1688 | for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; |
| 1689 | i += IWL_EEPROM_ACCESS_DELAY) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1690 | r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1691 | if (r & CSR_EEPROM_REG_READ_VALID_MSK) |
| 1692 | break; |
| 1693 | udelay(IWL_EEPROM_ACCESS_DELAY); |
| 1694 | } |
| 1695 | |
| 1696 | if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { |
| 1697 | IWL_ERROR("Time out reading EEPROM[%d]", addr); |
| 1698 | rc = -ETIMEDOUT; |
| 1699 | goto done; |
| 1700 | } |
Al Viro | 0e5ce1f | 2007-12-22 13:45:50 -0500 | [diff] [blame] | 1701 | e[addr / 2] = cpu_to_le16(r >> 16); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1702 | } |
| 1703 | rc = 0; |
| 1704 | |
| 1705 | done: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1706 | iwl4965_eeprom_release_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1707 | return rc; |
| 1708 | } |
| 1709 | |
| 1710 | /****************************************************************************** |
| 1711 | * |
| 1712 | * Misc. internal state and helper functions |
| 1713 | * |
| 1714 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1715 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1716 | |
| 1717 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1718 | * iwl4965_report_frame - dump frame to syslog during debug sessions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1719 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1720 | * You may hack this function to show different aspects of received frames, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1721 | * including selective frame dumps. |
| 1722 | * group100 parameter selects whether to show 1 out of 100 good frames. |
| 1723 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1724 | * TODO: This was originally written for 3945, need to audit for |
| 1725 | * proper operation with 4965. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1726 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1727 | void iwl4965_report_frame(struct iwl4965_priv *priv, |
| 1728 | struct iwl4965_rx_packet *pkt, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1729 | struct ieee80211_hdr *header, int group100) |
| 1730 | { |
| 1731 | u32 to_us; |
| 1732 | u32 print_summary = 0; |
| 1733 | u32 print_dump = 0; /* set to 1 to dump all frames' contents */ |
| 1734 | u32 hundred = 0; |
| 1735 | u32 dataframe = 0; |
| 1736 | u16 fc; |
| 1737 | u16 seq_ctl; |
| 1738 | u16 channel; |
| 1739 | u16 phy_flags; |
| 1740 | int rate_sym; |
| 1741 | u16 length; |
| 1742 | u16 status; |
| 1743 | u16 bcn_tmr; |
| 1744 | u32 tsf_low; |
| 1745 | u64 tsf; |
| 1746 | u8 rssi; |
| 1747 | u8 agc; |
| 1748 | u16 sig_avg; |
| 1749 | u16 noise_diff; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1750 | struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); |
| 1751 | struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); |
| 1752 | struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1753 | u8 *data = IWL_RX_DATA(pkt); |
| 1754 | |
| 1755 | /* MAC header */ |
| 1756 | fc = le16_to_cpu(header->frame_control); |
| 1757 | seq_ctl = le16_to_cpu(header->seq_ctrl); |
| 1758 | |
| 1759 | /* metadata */ |
| 1760 | channel = le16_to_cpu(rx_hdr->channel); |
| 1761 | phy_flags = le16_to_cpu(rx_hdr->phy_flags); |
| 1762 | rate_sym = rx_hdr->rate; |
| 1763 | length = le16_to_cpu(rx_hdr->len); |
| 1764 | |
| 1765 | /* end-of-frame status and timestamp */ |
| 1766 | status = le32_to_cpu(rx_end->status); |
| 1767 | bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp); |
| 1768 | tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff; |
| 1769 | tsf = le64_to_cpu(rx_end->timestamp); |
| 1770 | |
| 1771 | /* signal statistics */ |
| 1772 | rssi = rx_stats->rssi; |
| 1773 | agc = rx_stats->agc; |
| 1774 | sig_avg = le16_to_cpu(rx_stats->sig_avg); |
| 1775 | noise_diff = le16_to_cpu(rx_stats->noise_diff); |
| 1776 | |
| 1777 | to_us = !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1778 | |
| 1779 | /* if data frame is to us and all is good, |
| 1780 | * (optionally) print summary for only 1 out of every 100 */ |
| 1781 | if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) == |
| 1782 | (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) { |
| 1783 | dataframe = 1; |
| 1784 | if (!group100) |
| 1785 | print_summary = 1; /* print each frame */ |
| 1786 | else if (priv->framecnt_to_us < 100) { |
| 1787 | priv->framecnt_to_us++; |
| 1788 | print_summary = 0; |
| 1789 | } else { |
| 1790 | priv->framecnt_to_us = 0; |
| 1791 | print_summary = 1; |
| 1792 | hundred = 1; |
| 1793 | } |
| 1794 | } else { |
| 1795 | /* print summary for all other frames */ |
| 1796 | print_summary = 1; |
| 1797 | } |
| 1798 | |
| 1799 | if (print_summary) { |
| 1800 | char *title; |
| 1801 | u32 rate; |
| 1802 | |
| 1803 | if (hundred) |
| 1804 | title = "100Frames"; |
| 1805 | else if (fc & IEEE80211_FCTL_RETRY) |
| 1806 | title = "Retry"; |
| 1807 | else if (ieee80211_is_assoc_response(fc)) |
| 1808 | title = "AscRsp"; |
| 1809 | else if (ieee80211_is_reassoc_response(fc)) |
| 1810 | title = "RasRsp"; |
| 1811 | else if (ieee80211_is_probe_response(fc)) { |
| 1812 | title = "PrbRsp"; |
| 1813 | print_dump = 1; /* dump frame contents */ |
| 1814 | } else if (ieee80211_is_beacon(fc)) { |
| 1815 | title = "Beacon"; |
| 1816 | print_dump = 1; /* dump frame contents */ |
| 1817 | } else if (ieee80211_is_atim(fc)) |
| 1818 | title = "ATIM"; |
| 1819 | else if (ieee80211_is_auth(fc)) |
| 1820 | title = "Auth"; |
| 1821 | else if (ieee80211_is_deauth(fc)) |
| 1822 | title = "DeAuth"; |
| 1823 | else if (ieee80211_is_disassoc(fc)) |
| 1824 | title = "DisAssoc"; |
| 1825 | else |
| 1826 | title = "Frame"; |
| 1827 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1828 | rate = iwl4965_rate_index_from_plcp(rate_sym); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1829 | if (rate == -1) |
| 1830 | rate = 0; |
| 1831 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1832 | rate = iwl4965_rates[rate].ieee / 2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1833 | |
| 1834 | /* print frame summary. |
| 1835 | * MAC addresses show just the last byte (for brevity), |
| 1836 | * but you can hack it to show more, if you'd like to. */ |
| 1837 | if (dataframe) |
| 1838 | IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, " |
| 1839 | "len=%u, rssi=%d, chnl=%d, rate=%u, \n", |
| 1840 | title, fc, header->addr1[5], |
| 1841 | length, rssi, channel, rate); |
| 1842 | else { |
| 1843 | /* src/dst addresses assume managed mode */ |
| 1844 | IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, " |
| 1845 | "src=0x%02x, rssi=%u, tim=%lu usec, " |
| 1846 | "phy=0x%02x, chnl=%d\n", |
| 1847 | title, fc, header->addr1[5], |
| 1848 | header->addr3[5], rssi, |
| 1849 | tsf_low - priv->scan_start_tsf, |
| 1850 | phy_flags, channel); |
| 1851 | } |
| 1852 | } |
| 1853 | if (print_dump) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1854 | iwl4965_print_hex_dump(IWL_DL_RX, data, length); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1855 | } |
| 1856 | #endif |
| 1857 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1858 | static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1859 | { |
| 1860 | if (priv->hw_setting.shared_virt) |
| 1861 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1862 | sizeof(struct iwl4965_shared), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1863 | priv->hw_setting.shared_virt, |
| 1864 | priv->hw_setting.shared_phys); |
| 1865 | } |
| 1866 | |
| 1867 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1868 | * 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] | 1869 | * |
| 1870 | * return : set the bit for each supported rate insert in ie |
| 1871 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1872 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1873 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1874 | { |
| 1875 | u16 ret_rates = 0, bit; |
| 1876 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1877 | u8 *cnt = ie; |
| 1878 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1879 | |
| 1880 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1881 | if (bit & supported_rate) { |
| 1882 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1883 | rates[*cnt] = iwl4965_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1884 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1885 | (*cnt)++; |
| 1886 | (*left)--; |
| 1887 | if ((*left <= 0) || |
| 1888 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1889 | break; |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | return ret_rates; |
| 1894 | } |
| 1895 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1896 | #ifdef CONFIG_IWL4965_HT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1897 | void static iwl4965_set_ht_capab(struct ieee80211_hw *hw, |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1898 | struct ieee80211_ht_cap *ht_cap, |
| 1899 | u8 use_current_config); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1900 | #endif |
| 1901 | |
| 1902 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1903 | * 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] | 1904 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1905 | static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1906 | struct ieee80211_mgmt *frame, |
| 1907 | int left, int is_direct) |
| 1908 | { |
| 1909 | int len = 0; |
| 1910 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1911 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1912 | #ifdef CONFIG_IWL4965_HT |
| 1913 | struct ieee80211_hw_mode *mode; |
| 1914 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1915 | |
| 1916 | /* Make sure there is enough space for the probe request, |
| 1917 | * two mandatory IEs and the data */ |
| 1918 | left -= 24; |
| 1919 | if (left < 0) |
| 1920 | return 0; |
| 1921 | len += 24; |
| 1922 | |
| 1923 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1924 | memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1925 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1926 | memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1927 | frame->seq_ctrl = 0; |
| 1928 | |
| 1929 | /* fill in our indirect SSID IE */ |
| 1930 | /* ...next IE... */ |
| 1931 | |
| 1932 | left -= 2; |
| 1933 | if (left < 0) |
| 1934 | return 0; |
| 1935 | len += 2; |
| 1936 | pos = &(frame->u.probe_req.variable[0]); |
| 1937 | *pos++ = WLAN_EID_SSID; |
| 1938 | *pos++ = 0; |
| 1939 | |
| 1940 | /* fill in our direct SSID IE... */ |
| 1941 | if (is_direct) { |
| 1942 | /* ...next IE... */ |
| 1943 | left -= 2 + priv->essid_len; |
| 1944 | if (left < 0) |
| 1945 | return 0; |
| 1946 | /* ... fill it in... */ |
| 1947 | *pos++ = WLAN_EID_SSID; |
| 1948 | *pos++ = priv->essid_len; |
| 1949 | memcpy(pos, priv->essid, priv->essid_len); |
| 1950 | pos += priv->essid_len; |
| 1951 | len += 2 + priv->essid_len; |
| 1952 | } |
| 1953 | |
| 1954 | /* fill in supported rate */ |
| 1955 | /* ...next IE... */ |
| 1956 | left -= 2; |
| 1957 | if (left < 0) |
| 1958 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1959 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1960 | /* ... fill it in... */ |
| 1961 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1962 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1963 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1964 | /* exclude 60M rate */ |
| 1965 | active_rates = priv->rates_mask; |
| 1966 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1967 | |
| 1968 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1969 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1970 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1971 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1972 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1973 | active_rates &= ~ret_rates; |
| 1974 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1975 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1976 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1977 | active_rates &= ~ret_rates; |
| 1978 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1979 | len += 2 + *pos; |
| 1980 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1981 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1982 | goto fill_end; |
| 1983 | |
| 1984 | /* fill in supported extended rate */ |
| 1985 | /* ...next IE... */ |
| 1986 | left -= 2; |
| 1987 | if (left < 0) |
| 1988 | return 0; |
| 1989 | /* ... fill it in... */ |
| 1990 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1991 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1992 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1993 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1994 | if (*pos > 0) |
| 1995 | len += 2 + *pos; |
| 1996 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1997 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1998 | mode = priv->hw->conf.mode; |
| 1999 | if (mode->ht_info.ht_supported) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2000 | pos += (*pos) + 1; |
| 2001 | *pos++ = WLAN_EID_HT_CAPABILITY; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 2002 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 2003 | iwl4965_set_ht_capab(priv->hw, |
| 2004 | (struct ieee80211_ht_cap *)pos, 0); |
| 2005 | len += 2 + sizeof(struct ieee80211_ht_cap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2006 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2007 | #endif /*CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2008 | |
| 2009 | fill_end: |
| 2010 | return (u16)len; |
| 2011 | } |
| 2012 | |
| 2013 | /* |
| 2014 | * QoS support |
| 2015 | */ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2016 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2017 | static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv, |
| 2018 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2019 | { |
| 2020 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2021 | return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
| 2022 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2025 | static void iwl4965_reset_qos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2026 | { |
| 2027 | u16 cw_min = 15; |
| 2028 | u16 cw_max = 1023; |
| 2029 | u8 aifs = 2; |
| 2030 | u8 is_legacy = 0; |
| 2031 | unsigned long flags; |
| 2032 | int i; |
| 2033 | |
| 2034 | spin_lock_irqsave(&priv->lock, flags); |
| 2035 | priv->qos_data.qos_active = 0; |
| 2036 | |
| 2037 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { |
| 2038 | if (priv->qos_data.qos_enable) |
| 2039 | priv->qos_data.qos_active = 1; |
| 2040 | if (!(priv->active_rate & 0xfff0)) { |
| 2041 | cw_min = 31; |
| 2042 | is_legacy = 1; |
| 2043 | } |
| 2044 | } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2045 | if (priv->qos_data.qos_enable) |
| 2046 | priv->qos_data.qos_active = 1; |
| 2047 | } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 2048 | cw_min = 31; |
| 2049 | is_legacy = 1; |
| 2050 | } |
| 2051 | |
| 2052 | if (priv->qos_data.qos_active) |
| 2053 | aifs = 3; |
| 2054 | |
| 2055 | priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); |
| 2056 | priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); |
| 2057 | priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; |
| 2058 | priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; |
| 2059 | priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; |
| 2060 | |
| 2061 | if (priv->qos_data.qos_active) { |
| 2062 | i = 1; |
| 2063 | priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); |
| 2064 | priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); |
| 2065 | priv->qos_data.def_qos_parm.ac[i].aifsn = 7; |
| 2066 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 2067 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2068 | |
| 2069 | i = 2; |
| 2070 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2071 | cpu_to_le16((cw_min + 1) / 2 - 1); |
| 2072 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2073 | cpu_to_le16(cw_max); |
| 2074 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 2075 | if (is_legacy) |
| 2076 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2077 | cpu_to_le16(6016); |
| 2078 | else |
| 2079 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2080 | cpu_to_le16(3008); |
| 2081 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2082 | |
| 2083 | i = 3; |
| 2084 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2085 | cpu_to_le16((cw_min + 1) / 4 - 1); |
| 2086 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2087 | cpu_to_le16((cw_max + 1) / 2 - 1); |
| 2088 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 2089 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2090 | if (is_legacy) |
| 2091 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2092 | cpu_to_le16(3264); |
| 2093 | else |
| 2094 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2095 | cpu_to_le16(1504); |
| 2096 | } else { |
| 2097 | for (i = 1; i < 4; i++) { |
| 2098 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2099 | cpu_to_le16(cw_min); |
| 2100 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2101 | cpu_to_le16(cw_max); |
| 2102 | priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; |
| 2103 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 2104 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2105 | } |
| 2106 | } |
| 2107 | IWL_DEBUG_QOS("set QoS to default \n"); |
| 2108 | |
| 2109 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2110 | } |
| 2111 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2112 | static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2113 | { |
| 2114 | unsigned long flags; |
| 2115 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2116 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2117 | return; |
| 2118 | |
| 2119 | if (!priv->qos_data.qos_enable) |
| 2120 | return; |
| 2121 | |
| 2122 | spin_lock_irqsave(&priv->lock, flags); |
| 2123 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 2124 | |
| 2125 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 2126 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 2127 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2128 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2129 | if (priv->qos_data.qos_active) |
| 2130 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2131 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 2132 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2133 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 2134 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2135 | 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] | 2136 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2137 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2138 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2139 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2140 | if (force || iwl4965_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2141 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 2142 | priv->qos_data.qos_active, |
| 2143 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2144 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2145 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2146 | &(priv->qos_data.def_qos_parm)); |
| 2147 | } |
| 2148 | } |
| 2149 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2150 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2151 | /* |
| 2152 | * Power management (not Tx power!) functions |
| 2153 | */ |
| 2154 | #define MSEC_TO_USEC 1024 |
| 2155 | |
| 2156 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 2157 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
| 2158 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 2159 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 2160 | __constant_cpu_to_le32(X1), \ |
| 2161 | __constant_cpu_to_le32(X2), \ |
| 2162 | __constant_cpu_to_le32(X3), \ |
| 2163 | __constant_cpu_to_le32(X4)} |
| 2164 | |
| 2165 | |
| 2166 | /* default power management (not Tx power) table values */ |
| 2167 | /* for tim 0-10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2168 | static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2169 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2170 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 2171 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 2172 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 2173 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 2174 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 2175 | }; |
| 2176 | |
| 2177 | /* for tim > 10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2178 | static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2179 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2180 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 2181 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 2182 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 2183 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 2184 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 2185 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 2186 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 2187 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 2188 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 2189 | }; |
| 2190 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2191 | int iwl4965_power_init_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2192 | { |
| 2193 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2194 | struct iwl4965_power_mgr *pow_data; |
| 2195 | int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2196 | u16 pci_pm; |
| 2197 | |
| 2198 | IWL_DEBUG_POWER("Initialize power \n"); |
| 2199 | |
| 2200 | pow_data = &(priv->power_data); |
| 2201 | |
| 2202 | memset(pow_data, 0, sizeof(*pow_data)); |
| 2203 | |
| 2204 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 2205 | pow_data->dtim_val = 0xffff; |
| 2206 | |
| 2207 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 2208 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 2209 | |
| 2210 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 2211 | if (rc != 0) |
| 2212 | return 0; |
| 2213 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2214 | struct iwl4965_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2215 | |
| 2216 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 2217 | |
| 2218 | for (i = 0; i < IWL_POWER_AC; i++) { |
| 2219 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 2220 | |
| 2221 | if (pci_pm & 0x1) |
| 2222 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 2223 | else |
| 2224 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 2225 | } |
| 2226 | } |
| 2227 | return rc; |
| 2228 | } |
| 2229 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2230 | static int iwl4965_update_power_cmd(struct iwl4965_priv *priv, |
| 2231 | struct iwl4965_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2232 | { |
| 2233 | int rc = 0, i; |
| 2234 | u8 skip; |
| 2235 | u32 max_sleep = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2236 | struct iwl4965_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2237 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2238 | struct iwl4965_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2239 | |
| 2240 | if (mode > IWL_POWER_INDEX_5) { |
| 2241 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 2242 | return -1; |
| 2243 | } |
| 2244 | pow_data = &(priv->power_data); |
| 2245 | |
| 2246 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 2247 | range = &pow_data->pwr_range_0[0]; |
| 2248 | else |
| 2249 | range = &pow_data->pwr_range_1[1]; |
| 2250 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2251 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2252 | |
| 2253 | #ifdef IWL_MAC80211_DISABLE |
| 2254 | if (priv->assoc_network != NULL) { |
| 2255 | unsigned long flags; |
| 2256 | |
| 2257 | period = priv->assoc_network->tim.tim_period; |
| 2258 | } |
| 2259 | #endif /*IWL_MAC80211_DISABLE */ |
| 2260 | skip = range[mode].no_dtim; |
| 2261 | |
| 2262 | if (period == 0) { |
| 2263 | period = 1; |
| 2264 | skip = 0; |
| 2265 | } |
| 2266 | |
| 2267 | if (skip == 0) { |
| 2268 | max_sleep = period; |
| 2269 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2270 | } else { |
| 2271 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 2272 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 2273 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2274 | } |
| 2275 | |
| 2276 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 2277 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 2278 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 2279 | } |
| 2280 | |
| 2281 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 2282 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 2283 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 2284 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 2285 | le32_to_cpu(cmd->sleep_interval[0]), |
| 2286 | le32_to_cpu(cmd->sleep_interval[1]), |
| 2287 | le32_to_cpu(cmd->sleep_interval[2]), |
| 2288 | le32_to_cpu(cmd->sleep_interval[3]), |
| 2289 | le32_to_cpu(cmd->sleep_interval[4])); |
| 2290 | |
| 2291 | return rc; |
| 2292 | } |
| 2293 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2294 | static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2295 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 2296 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2297 | int rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2298 | struct iwl4965_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2299 | |
| 2300 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2301 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2302 | * else user level */ |
| 2303 | switch (mode) { |
| 2304 | case IWL_POWER_BATTERY: |
| 2305 | final_mode = IWL_POWER_INDEX_3; |
| 2306 | break; |
| 2307 | case IWL_POWER_AC: |
| 2308 | final_mode = IWL_POWER_MODE_CAM; |
| 2309 | break; |
| 2310 | default: |
| 2311 | final_mode = mode; |
| 2312 | break; |
| 2313 | } |
| 2314 | |
| 2315 | cmd.keep_alive_beacons = 0; |
| 2316 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2317 | iwl4965_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2318 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2319 | rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2320 | |
| 2321 | if (final_mode == IWL_POWER_MODE_CAM) |
| 2322 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 2323 | else |
| 2324 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 2325 | |
| 2326 | return rc; |
| 2327 | } |
| 2328 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2329 | 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] | 2330 | { |
| 2331 | /* Filter incoming packets to determine if they are targeted toward |
| 2332 | * this network, discarding packets coming from ourselves */ |
| 2333 | switch (priv->iw_mode) { |
| 2334 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 2335 | /* packets from our adapter are dropped (echo) */ |
| 2336 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 2337 | return 0; |
| 2338 | /* {broad,multi}cast packets to our IBSS go through */ |
| 2339 | if (is_multicast_ether_addr(header->addr1)) |
| 2340 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 2341 | /* packets to our adapter go through */ |
| 2342 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2343 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 2344 | /* packets from our adapter are dropped (echo) */ |
| 2345 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 2346 | return 0; |
| 2347 | /* {broad,multi}cast packets to our BSS go through */ |
| 2348 | if (is_multicast_ether_addr(header->addr1)) |
| 2349 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 2350 | /* packets to our adapter go through */ |
| 2351 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2352 | } |
| 2353 | |
| 2354 | return 1; |
| 2355 | } |
| 2356 | |
| 2357 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2358 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2359 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2360 | { |
| 2361 | switch (status & TX_STATUS_MSK) { |
| 2362 | case TX_STATUS_SUCCESS: |
| 2363 | return "SUCCESS"; |
| 2364 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 2365 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 2366 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 2367 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 2368 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 2369 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 2370 | TX_STATUS_ENTRY(DEST_PS); |
| 2371 | TX_STATUS_ENTRY(ABORTED); |
| 2372 | TX_STATUS_ENTRY(BT_RETRY); |
| 2373 | TX_STATUS_ENTRY(STA_INVALID); |
| 2374 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 2375 | TX_STATUS_ENTRY(TID_DISABLE); |
| 2376 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 2377 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 2378 | TX_STATUS_ENTRY(TX_LOCKED); |
| 2379 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 2380 | } |
| 2381 | |
| 2382 | return "UNKNOWN"; |
| 2383 | } |
| 2384 | |
| 2385 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2386 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2387 | * |
| 2388 | * NOTE: priv->mutex is not required before calling this function |
| 2389 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2390 | static int iwl4965_scan_cancel(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2391 | { |
| 2392 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 2393 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2394 | return 0; |
| 2395 | } |
| 2396 | |
| 2397 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2398 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2399 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 2400 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2401 | queue_work(priv->workqueue, &priv->abort_scan); |
| 2402 | |
| 2403 | } else |
| 2404 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 2405 | |
| 2406 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2407 | } |
| 2408 | |
| 2409 | return 0; |
| 2410 | } |
| 2411 | |
| 2412 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2413 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2414 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 2415 | * |
| 2416 | * NOTE: priv->mutex must be held before calling this function |
| 2417 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2418 | 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] | 2419 | { |
| 2420 | unsigned long now = jiffies; |
| 2421 | int ret; |
| 2422 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2423 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2424 | if (ret && ms) { |
| 2425 | mutex_unlock(&priv->mutex); |
| 2426 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 2427 | test_bit(STATUS_SCANNING, &priv->status)) |
| 2428 | msleep(1); |
| 2429 | mutex_lock(&priv->mutex); |
| 2430 | |
| 2431 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2432 | } |
| 2433 | |
| 2434 | return ret; |
| 2435 | } |
| 2436 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2437 | static void iwl4965_sequence_reset(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2438 | { |
| 2439 | /* Reset ieee stats */ |
| 2440 | |
| 2441 | /* We don't reset the net_device_stats (ieee->stats) on |
| 2442 | * re-association */ |
| 2443 | |
| 2444 | priv->last_seq_num = -1; |
| 2445 | priv->last_frag_num = -1; |
| 2446 | priv->last_packet_time = 0; |
| 2447 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2448 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 2452 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 2453 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2454 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2455 | { |
| 2456 | u16 new_val = 0; |
| 2457 | u16 beacon_factor = 0; |
| 2458 | |
| 2459 | beacon_factor = |
| 2460 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 2461 | / MAX_UCODE_BEACON_INTERVAL; |
| 2462 | new_val = beacon_val / beacon_factor; |
| 2463 | |
| 2464 | return cpu_to_le16(new_val); |
| 2465 | } |
| 2466 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2467 | static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2468 | { |
| 2469 | u64 interval_tm_unit; |
| 2470 | u64 tsf, result; |
| 2471 | unsigned long flags; |
| 2472 | struct ieee80211_conf *conf = NULL; |
| 2473 | u16 beacon_int = 0; |
| 2474 | |
| 2475 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2476 | |
| 2477 | spin_lock_irqsave(&priv->lock, flags); |
| 2478 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1); |
| 2479 | priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0); |
| 2480 | |
| 2481 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 2482 | |
| 2483 | tsf = priv->timestamp1; |
| 2484 | tsf = ((tsf << 32) | priv->timestamp0); |
| 2485 | |
| 2486 | beacon_int = priv->beacon_int; |
| 2487 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2488 | |
| 2489 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 2490 | if (beacon_int == 0) { |
| 2491 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 2492 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 2493 | } else { |
| 2494 | priv->rxon_timing.beacon_interval = |
| 2495 | cpu_to_le16(beacon_int); |
| 2496 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2497 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2498 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2499 | } |
| 2500 | |
| 2501 | priv->rxon_timing.atim_window = 0; |
| 2502 | } else { |
| 2503 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2504 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2505 | /* TODO: we need to get atim_window from upper stack |
| 2506 | * for now we set to 0 */ |
| 2507 | priv->rxon_timing.atim_window = 0; |
| 2508 | } |
| 2509 | |
| 2510 | interval_tm_unit = |
| 2511 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 2512 | result = do_div(tsf, interval_tm_unit); |
| 2513 | priv->rxon_timing.beacon_init_val = |
| 2514 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 2515 | |
| 2516 | IWL_DEBUG_ASSOC |
| 2517 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 2518 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 2519 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 2520 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 2521 | } |
| 2522 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2523 | static int iwl4965_scan_initiate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2524 | { |
| 2525 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2526 | IWL_ERROR("APs don't scan.\n"); |
| 2527 | return 0; |
| 2528 | } |
| 2529 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2530 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2531 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 2532 | return -EIO; |
| 2533 | } |
| 2534 | |
| 2535 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2536 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 2537 | return -EAGAIN; |
| 2538 | } |
| 2539 | |
| 2540 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2541 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 2542 | "Queuing.\n"); |
| 2543 | return -EAGAIN; |
| 2544 | } |
| 2545 | |
| 2546 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 2547 | priv->scan_bands = 2; |
| 2548 | set_bit(STATUS_SCANNING, &priv->status); |
| 2549 | priv->scan_start = jiffies; |
| 2550 | priv->scan_pass_start = priv->scan_start; |
| 2551 | |
| 2552 | queue_work(priv->workqueue, &priv->request_scan); |
| 2553 | |
| 2554 | return 0; |
| 2555 | } |
| 2556 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2557 | 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] | 2558 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2559 | struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2560 | |
| 2561 | if (hw_decrypt) |
| 2562 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 2563 | else |
| 2564 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 2565 | |
| 2566 | return 0; |
| 2567 | } |
| 2568 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2569 | 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] | 2570 | { |
| 2571 | if (phymode == MODE_IEEE80211A) { |
| 2572 | priv->staging_rxon.flags &= |
| 2573 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 2574 | | RXON_FLG_CCK_MSK); |
| 2575 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2576 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2577 | /* Copied from iwl4965_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2578 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2579 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2580 | else |
| 2581 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2582 | |
| 2583 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2584 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2585 | |
| 2586 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 2587 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 2588 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2593 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2594 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2595 | static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2596 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2597 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2598 | |
| 2599 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 2600 | |
| 2601 | switch (priv->iw_mode) { |
| 2602 | case IEEE80211_IF_TYPE_AP: |
| 2603 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 2604 | break; |
| 2605 | |
| 2606 | case IEEE80211_IF_TYPE_STA: |
| 2607 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 2608 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 2609 | break; |
| 2610 | |
| 2611 | case IEEE80211_IF_TYPE_IBSS: |
| 2612 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 2613 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2614 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 2615 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2616 | break; |
| 2617 | |
| 2618 | case IEEE80211_IF_TYPE_MNTR: |
| 2619 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 2620 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 2621 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2622 | break; |
| 2623 | } |
| 2624 | |
| 2625 | #if 0 |
| 2626 | /* TODO: Figure out when short_preamble would be set and cache from |
| 2627 | * that */ |
| 2628 | if (!hw_to_local(priv->hw)->short_preamble) |
| 2629 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2630 | else |
| 2631 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2632 | #endif |
| 2633 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2634 | ch_info = iwl4965_get_channel_info(priv, priv->phymode, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2635 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2636 | |
| 2637 | if (!ch_info) |
| 2638 | ch_info = &priv->channel_info[0]; |
| 2639 | |
| 2640 | /* |
| 2641 | * in some case A channels are all non IBSS |
| 2642 | * in this case force B/G channel |
| 2643 | */ |
| 2644 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 2645 | !(is_channel_ibss(ch_info))) |
| 2646 | ch_info = &priv->channel_info[0]; |
| 2647 | |
| 2648 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
| 2649 | if (is_channel_a_band(ch_info)) |
| 2650 | priv->phymode = MODE_IEEE80211A; |
| 2651 | else |
| 2652 | priv->phymode = MODE_IEEE80211G; |
| 2653 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2654 | iwl4965_set_flags_for_phymode(priv, priv->phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2655 | |
| 2656 | priv->staging_rxon.ofdm_basic_rates = |
| 2657 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2658 | priv->staging_rxon.cck_basic_rates = |
| 2659 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2660 | |
| 2661 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 2662 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 2663 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2664 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 2665 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 2666 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 2667 | iwl4965_set_rxon_chain(priv); |
| 2668 | } |
| 2669 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2670 | static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2671 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2672 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2673 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2674 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2675 | ch_info = iwl4965_get_channel_info(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2676 | priv->phymode, |
| 2677 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2678 | |
| 2679 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 2680 | IWL_ERROR("channel %d not IBSS channel\n", |
| 2681 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2682 | return -EINVAL; |
| 2683 | } |
| 2684 | } |
| 2685 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2686 | priv->iw_mode = mode; |
| 2687 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2688 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2689 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2690 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2691 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2692 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2693 | /* dont commit rxon if rf-kill is on*/ |
| 2694 | if (!iwl4965_is_ready_rf(priv)) |
| 2695 | return -EAGAIN; |
| 2696 | |
| 2697 | cancel_delayed_work(&priv->scan_check); |
| 2698 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 2699 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 2700 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2701 | return -EAGAIN; |
| 2702 | } |
| 2703 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2704 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2705 | |
| 2706 | return 0; |
| 2707 | } |
| 2708 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2709 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2710 | struct ieee80211_tx_control *ctl, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2711 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2712 | struct sk_buff *skb_frag, |
| 2713 | int last_frag) |
| 2714 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2715 | struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2716 | |
| 2717 | switch (keyinfo->alg) { |
| 2718 | case ALG_CCMP: |
| 2719 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2720 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
| 2721 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 2722 | break; |
| 2723 | |
| 2724 | case ALG_TKIP: |
| 2725 | #if 0 |
| 2726 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2727 | |
| 2728 | if (last_frag) |
| 2729 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2730 | 8); |
| 2731 | else |
| 2732 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2733 | #endif |
| 2734 | break; |
| 2735 | |
| 2736 | case ALG_WEP: |
| 2737 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
| 2738 | (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
| 2739 | |
| 2740 | if (keyinfo->keylen == 13) |
| 2741 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2742 | |
| 2743 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2744 | |
| 2745 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
| 2746 | "with key %d\n", ctl->key_idx); |
| 2747 | break; |
| 2748 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2749 | default: |
| 2750 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 2751 | break; |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | /* |
| 2756 | * handle build REPLY_TX command notification. |
| 2757 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2758 | static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv, |
| 2759 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2760 | struct ieee80211_tx_control *ctrl, |
| 2761 | struct ieee80211_hdr *hdr, |
| 2762 | int is_unicast, u8 std_id) |
| 2763 | { |
| 2764 | __le16 *qc; |
| 2765 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2766 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 2767 | |
| 2768 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2769 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 2770 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 2771 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 2772 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2773 | if (ieee80211_is_probe_response(fc) && |
| 2774 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2775 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2776 | } else { |
| 2777 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2778 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2779 | } |
| 2780 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2781 | if (ieee80211_is_back_request(fc)) |
| 2782 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 2783 | |
| 2784 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2785 | cmd->cmd.tx.sta_id = std_id; |
| 2786 | if (ieee80211_get_morefrag(hdr)) |
| 2787 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2788 | |
| 2789 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2790 | if (qc) { |
| 2791 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 2792 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 2793 | } else |
| 2794 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2795 | |
| 2796 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 2797 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2798 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 2799 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 2800 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2801 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2802 | } |
| 2803 | |
| 2804 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2805 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2806 | |
| 2807 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 2808 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 2809 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 2810 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2811 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2812 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2813 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2814 | } else |
| 2815 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
| 2816 | |
| 2817 | cmd->cmd.tx.driver_txop = 0; |
| 2818 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2819 | cmd->cmd.tx.next_frame_len = 0; |
| 2820 | } |
| 2821 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2822 | /** |
| 2823 | * iwl4965_get_sta_id - Find station's index within station table |
| 2824 | * |
| 2825 | * If new IBSS station, create new entry in station table |
| 2826 | */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2827 | static int iwl4965_get_sta_id(struct iwl4965_priv *priv, |
| 2828 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2829 | { |
| 2830 | int sta_id; |
| 2831 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2832 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2833 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2834 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2835 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2836 | is_multicast_ether_addr(hdr->addr1)) |
| 2837 | return priv->hw_setting.bcast_sta_id; |
| 2838 | |
| 2839 | switch (priv->iw_mode) { |
| 2840 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2841 | /* If we are a client station in a BSS network, use the special |
| 2842 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2843 | case IEEE80211_IF_TYPE_STA: |
| 2844 | return IWL_AP_ID; |
| 2845 | |
| 2846 | /* If we are an AP, then find the station, or use BCAST */ |
| 2847 | case IEEE80211_IF_TYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2848 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2849 | if (sta_id != IWL_INVALID_STATION) |
| 2850 | return sta_id; |
| 2851 | return priv->hw_setting.bcast_sta_id; |
| 2852 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2853 | /* If this frame is going out to an IBSS network, find the station, |
| 2854 | * or create a new station table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2855 | case IEEE80211_IF_TYPE_IBSS: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2856 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2857 | if (sta_id != IWL_INVALID_STATION) |
| 2858 | return sta_id; |
| 2859 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2860 | /* Create new station table entry */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 2861 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, |
| 2862 | 0, CMD_ASYNC, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2863 | |
| 2864 | if (sta_id != IWL_INVALID_STATION) |
| 2865 | return sta_id; |
| 2866 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2867 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2868 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2869 | print_mac(mac, hdr->addr1)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2870 | iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2871 | return priv->hw_setting.bcast_sta_id; |
| 2872 | |
| 2873 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2874 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2875 | return priv->hw_setting.bcast_sta_id; |
| 2876 | } |
| 2877 | } |
| 2878 | |
| 2879 | /* |
| 2880 | * start REPLY_TX command process |
| 2881 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2882 | static int iwl4965_tx_skb(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2883 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 2884 | { |
| 2885 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2886 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2887 | u32 *control_flags; |
| 2888 | int txq_id = ctl->queue; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2889 | struct iwl4965_tx_queue *txq = NULL; |
| 2890 | struct iwl4965_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2891 | dma_addr_t phys_addr; |
| 2892 | dma_addr_t txcmd_phys; |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2893 | dma_addr_t scratch_phys; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2894 | struct iwl4965_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2895 | u16 len, idx, len_org; |
| 2896 | u8 id, hdr_len, unicast; |
| 2897 | u8 sta_id; |
| 2898 | u16 seq_number = 0; |
| 2899 | u16 fc; |
| 2900 | __le16 *qc; |
| 2901 | u8 wait_write_ptr = 0; |
| 2902 | unsigned long flags; |
| 2903 | int rc; |
| 2904 | |
| 2905 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2906 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2907 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2908 | goto drop_unlock; |
| 2909 | } |
| 2910 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2911 | if (!priv->vif) { |
| 2912 | IWL_DEBUG_DROP("Dropping - !priv->vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2913 | goto drop_unlock; |
| 2914 | } |
| 2915 | |
| 2916 | if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) { |
| 2917 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 2918 | goto drop_unlock; |
| 2919 | } |
| 2920 | |
| 2921 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2922 | id = 0; |
| 2923 | |
| 2924 | fc = le16_to_cpu(hdr->frame_control); |
| 2925 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2926 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2927 | if (ieee80211_is_auth(fc)) |
| 2928 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 2929 | else if (ieee80211_is_assoc_request(fc)) |
| 2930 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 2931 | else if (ieee80211_is_reassoc_request(fc)) |
| 2932 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2933 | #endif |
| 2934 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2935 | /* drop all data frame if we are not associated */ |
| 2936 | if (!iwl4965_is_associated(priv) && !priv->assoc_id && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2937 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2938 | IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2939 | goto drop_unlock; |
| 2940 | } |
| 2941 | |
| 2942 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2943 | |
| 2944 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2945 | |
| 2946 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2947 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2948 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2949 | DECLARE_MAC_BUF(mac); |
| 2950 | |
| 2951 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 2952 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2953 | goto drop; |
| 2954 | } |
| 2955 | |
| 2956 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2957 | |
| 2958 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2959 | if (qc) { |
| 2960 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2961 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 2962 | IEEE80211_SCTL_SEQ; |
| 2963 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2964 | (hdr->seq_ctrl & |
| 2965 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2966 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2967 | #ifdef CONFIG_IWL4965_HT |
| 2968 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2969 | /* aggregation is on for this <sta,tid> */ |
| 2970 | if (ctl->flags & IEEE80211_TXCTL_HT_MPDU_AGG) |
| 2971 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2972 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 2973 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2974 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2975 | |
| 2976 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2977 | txq = &priv->txq[txq_id]; |
| 2978 | q = &txq->q; |
| 2979 | |
| 2980 | spin_lock_irqsave(&priv->lock, flags); |
| 2981 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2982 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2983 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2984 | memset(tfd, 0, sizeof(*tfd)); |
| 2985 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2986 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2987 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2988 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2989 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2990 | txq->txb[q->write_ptr].skb[0] = skb; |
| 2991 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2992 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2993 | |
| 2994 | /* Set up first empty entry in queue's array of Tx/cmd buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2995 | out_cmd = &txq->cmd[idx]; |
| 2996 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2997 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2998 | |
| 2999 | /* |
| 3000 | * Set up the Tx-command (not MAC!) header. |
| 3001 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 3002 | * after Tx, uCode's Tx response will return this value so driver can |
| 3003 | * locate the frame within the tx queue and do post-tx processing. |
| 3004 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3005 | out_cmd->hdr.cmd = REPLY_TX; |
| 3006 | 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] | 3007 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3008 | |
| 3009 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 3011 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3012 | /* |
| 3013 | * Use the first empty entry in this queue's command buffer array |
| 3014 | * to contain the Tx command and MAC header concatenated together |
| 3015 | * (payload data will be in another buffer). |
| 3016 | * Size of this varies, due to varying MAC header length. |
| 3017 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 3018 | * of the MAC header (device reads on dword boundaries). |
| 3019 | * We'll tell device about this padding later. |
| 3020 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3021 | len = priv->hw_setting.tx_cmd_len + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3022 | sizeof(struct iwl4965_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3023 | |
| 3024 | len_org = len; |
| 3025 | len = (len + 3) & ~3; |
| 3026 | |
| 3027 | if (len_org != len) |
| 3028 | len_org = 1; |
| 3029 | else |
| 3030 | len_org = 0; |
| 3031 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3032 | /* Physical address of this Tx command's header (not MAC header!), |
| 3033 | * within command buffer array. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3034 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx + |
| 3035 | offsetof(struct iwl4965_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3036 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3037 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 3038 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3039 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3040 | |
| 3041 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3042 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3043 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3044 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 3045 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3046 | len = skb->len - hdr_len; |
| 3047 | if (len) { |
| 3048 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 3049 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3050 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3051 | } |
| 3052 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3053 | /* Tell 4965 about any 2-byte padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3054 | if (len_org) |
| 3055 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 3056 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3057 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3058 | len = (u16)skb->len; |
| 3059 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 3060 | |
| 3061 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3062 | 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] | 3063 | |
| 3064 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3065 | 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] | 3066 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 3067 | scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) + |
| 3068 | offsetof(struct iwl4965_tx_cmd, scratch); |
| 3069 | out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 3070 | out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys); |
| 3071 | |
| 3072 | #ifdef CONFIG_IWL4965_HT_AGG |
| 3073 | #ifdef CONFIG_IWL4965_HT |
| 3074 | /* TODO: move this functionality to rate scaling */ |
| 3075 | iwl4965_tl_get_stats(priv, hdr); |
| 3076 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 3077 | #endif /*CONFIG_IWL4965_HT */ |
| 3078 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3079 | |
| 3080 | if (!ieee80211_get_morefrag(hdr)) { |
| 3081 | txq->need_update = 1; |
| 3082 | if (qc) { |
| 3083 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 3084 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 3085 | } |
| 3086 | } else { |
| 3087 | wait_write_ptr = 1; |
| 3088 | txq->need_update = 0; |
| 3089 | } |
| 3090 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3091 | iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3092 | sizeof(out_cmd->cmd.tx)); |
| 3093 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3094 | 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] | 3095 | ieee80211_get_hdrlen(fc)); |
| 3096 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3097 | /* Set up entry for this TFD in Tx byte-count array */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3098 | iwl4965_tx_queue_update_wr_ptr(priv, txq, len); |
| 3099 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3100 | /* Tell device the write index *just past* this latest filled TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3101 | q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 3102 | rc = iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3103 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3104 | |
| 3105 | if (rc) |
| 3106 | return rc; |
| 3107 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3108 | if ((iwl4965_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3109 | && priv->mac80211_registered) { |
| 3110 | if (wait_write_ptr) { |
| 3111 | spin_lock_irqsave(&priv->lock, flags); |
| 3112 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3113 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3114 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3115 | } |
| 3116 | |
| 3117 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 3118 | } |
| 3119 | |
| 3120 | return 0; |
| 3121 | |
| 3122 | drop_unlock: |
| 3123 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3124 | drop: |
| 3125 | return -1; |
| 3126 | } |
| 3127 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3128 | static void iwl4965_set_rate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3129 | { |
| 3130 | const struct ieee80211_hw_mode *hw = NULL; |
| 3131 | struct ieee80211_rate *rate; |
| 3132 | int i; |
| 3133 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3134 | hw = iwl4965_get_hw_mode(priv, priv->phymode); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 3135 | if (!hw) { |
| 3136 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 3137 | return; |
| 3138 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3139 | |
| 3140 | priv->active_rate = 0; |
| 3141 | priv->active_rate_basic = 0; |
| 3142 | |
| 3143 | IWL_DEBUG_RATE("Setting rates for 802.11%c\n", |
| 3144 | hw->mode == MODE_IEEE80211A ? |
| 3145 | 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g')); |
| 3146 | |
| 3147 | for (i = 0; i < hw->num_rates; i++) { |
| 3148 | rate = &(hw->rates[i]); |
| 3149 | if ((rate->val < IWL_RATE_COUNT) && |
| 3150 | (rate->flags & IEEE80211_RATE_SUPPORTED)) { |
| 3151 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3152 | rate->val, iwl4965_rates[rate->val].plcp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3153 | (rate->flags & IEEE80211_RATE_BASIC) ? |
| 3154 | "*" : ""); |
| 3155 | priv->active_rate |= (1 << rate->val); |
| 3156 | if (rate->flags & IEEE80211_RATE_BASIC) |
| 3157 | priv->active_rate_basic |= (1 << rate->val); |
| 3158 | } else |
| 3159 | IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3160 | rate->val, iwl4965_rates[rate->val].plcp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 3164 | priv->active_rate, priv->active_rate_basic); |
| 3165 | |
| 3166 | /* |
| 3167 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 3168 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 3169 | * OFDM |
| 3170 | */ |
| 3171 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 3172 | priv->staging_rxon.cck_basic_rates = |
| 3173 | ((priv->active_rate_basic & |
| 3174 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3175 | else |
| 3176 | priv->staging_rxon.cck_basic_rates = |
| 3177 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3178 | |
| 3179 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 3180 | priv->staging_rxon.ofdm_basic_rates = |
| 3181 | ((priv->active_rate_basic & |
| 3182 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 3183 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3184 | else |
| 3185 | priv->staging_rxon.ofdm_basic_rates = |
| 3186 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3187 | } |
| 3188 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3189 | 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] | 3190 | { |
| 3191 | unsigned long flags; |
| 3192 | |
| 3193 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 3194 | return; |
| 3195 | |
| 3196 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 3197 | disable_radio ? "OFF" : "ON"); |
| 3198 | |
| 3199 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3200 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3201 | /* FIXME: This is a workaround for AP */ |
| 3202 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 3203 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3204 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3205 | CSR_UCODE_SW_BIT_RFKILL); |
| 3206 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3207 | iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3208 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3209 | } |
| 3210 | return; |
| 3211 | } |
| 3212 | |
| 3213 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3214 | 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] | 3215 | |
| 3216 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3217 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3218 | |
| 3219 | /* wake up ucode */ |
| 3220 | msleep(10); |
| 3221 | |
| 3222 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3223 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 3224 | if (!iwl4965_grab_nic_access(priv)) |
| 3225 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3226 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3227 | |
| 3228 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 3229 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3230 | "disabled by HW switch\n"); |
| 3231 | return; |
| 3232 | } |
| 3233 | |
| 3234 | queue_work(priv->workqueue, &priv->restart); |
| 3235 | return; |
| 3236 | } |
| 3237 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3238 | 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] | 3239 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 3240 | { |
| 3241 | u16 fc = |
| 3242 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 3243 | |
| 3244 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 3245 | return; |
| 3246 | |
| 3247 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 3248 | return; |
| 3249 | |
| 3250 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 3251 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 3252 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 3253 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3254 | RX_RES_STATUS_BAD_ICV_MIC) |
| 3255 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 3256 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 3257 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 3258 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3259 | RX_RES_STATUS_DECRYPT_OK) { |
| 3260 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 3261 | stats->flag |= RX_FLAG_DECRYPTED; |
| 3262 | } |
| 3263 | break; |
| 3264 | |
| 3265 | default: |
| 3266 | break; |
| 3267 | } |
| 3268 | } |
| 3269 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3270 | |
| 3271 | #define IWL_PACKET_RETRY_TIME HZ |
| 3272 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3273 | 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] | 3274 | { |
| 3275 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 3276 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 3277 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 3278 | u16 *last_seq, *last_frag; |
| 3279 | unsigned long *last_time; |
| 3280 | |
| 3281 | switch (priv->iw_mode) { |
| 3282 | case IEEE80211_IF_TYPE_IBSS:{ |
| 3283 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3284 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3285 | u8 *mac = header->addr2; |
| 3286 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 3287 | |
| 3288 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3289 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3290 | if (!compare_ether_addr(entry->mac, mac)) |
| 3291 | break; |
| 3292 | } |
| 3293 | if (p == &priv->ibss_mac_hash[index]) { |
| 3294 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 3295 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3296 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | return 0; |
| 3298 | } |
| 3299 | memcpy(entry->mac, mac, ETH_ALEN); |
| 3300 | entry->seq_num = seq; |
| 3301 | entry->frag_num = frag; |
| 3302 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3303 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3304 | return 0; |
| 3305 | } |
| 3306 | last_seq = &entry->seq_num; |
| 3307 | last_frag = &entry->frag_num; |
| 3308 | last_time = &entry->packet_time; |
| 3309 | break; |
| 3310 | } |
| 3311 | case IEEE80211_IF_TYPE_STA: |
| 3312 | last_seq = &priv->last_seq_num; |
| 3313 | last_frag = &priv->last_frag_num; |
| 3314 | last_time = &priv->last_packet_time; |
| 3315 | break; |
| 3316 | default: |
| 3317 | return 0; |
| 3318 | } |
| 3319 | if ((*last_seq == seq) && |
| 3320 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 3321 | if (*last_frag == frag) |
| 3322 | goto drop; |
| 3323 | if (*last_frag + 1 != frag) |
| 3324 | /* out-of-order fragment */ |
| 3325 | goto drop; |
| 3326 | } else |
| 3327 | *last_seq = seq; |
| 3328 | |
| 3329 | *last_frag = frag; |
| 3330 | *last_time = jiffies; |
| 3331 | return 0; |
| 3332 | |
| 3333 | drop: |
| 3334 | return 1; |
| 3335 | } |
| 3336 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3337 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3338 | |
| 3339 | #include "iwl-spectrum.h" |
| 3340 | |
| 3341 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 3342 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 3343 | #define TIME_UNIT 1024 |
| 3344 | |
| 3345 | /* |
| 3346 | * extended beacon time format |
| 3347 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 3348 | * the high 1 byte is the beacon counts |
| 3349 | * the lower 3 bytes is the time in usec within one beacon interval |
| 3350 | */ |
| 3351 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3352 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3353 | { |
| 3354 | u32 quot; |
| 3355 | u32 rem; |
| 3356 | u32 interval = beacon_interval * 1024; |
| 3357 | |
| 3358 | if (!interval || !usec) |
| 3359 | return 0; |
| 3360 | |
| 3361 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 3362 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 3363 | |
| 3364 | return (quot << 24) + rem; |
| 3365 | } |
| 3366 | |
| 3367 | /* base is usually what we get from ucode with each received frame, |
| 3368 | * the same as HW timer counter counting down |
| 3369 | */ |
| 3370 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3371 | 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] | 3372 | { |
| 3373 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 3374 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 3375 | u32 interval = beacon_interval * TIME_UNIT; |
| 3376 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 3377 | (addon & BEACON_TIME_MASK_HIGH); |
| 3378 | |
| 3379 | if (base_low > addon_low) |
| 3380 | res += base_low - addon_low; |
| 3381 | else if (base_low < addon_low) { |
| 3382 | res += interval + base_low - addon_low; |
| 3383 | res += (1 << 24); |
| 3384 | } else |
| 3385 | res += (1 << 24); |
| 3386 | |
| 3387 | return cpu_to_le32(res); |
| 3388 | } |
| 3389 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3390 | static int iwl4965_get_measurement(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3391 | struct ieee80211_measurement_params *params, |
| 3392 | u8 type) |
| 3393 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3394 | struct iwl4965_spectrum_cmd spectrum; |
| 3395 | struct iwl4965_rx_packet *res; |
| 3396 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3397 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 3398 | .data = (void *)&spectrum, |
| 3399 | .meta.flags = CMD_WANT_SKB, |
| 3400 | }; |
| 3401 | u32 add_time = le64_to_cpu(params->start_time); |
| 3402 | int rc; |
| 3403 | int spectrum_resp_status; |
| 3404 | int duration = le16_to_cpu(params->duration); |
| 3405 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3406 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3407 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3408 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3409 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 3410 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3411 | |
| 3412 | memset(&spectrum, 0, sizeof(spectrum)); |
| 3413 | |
| 3414 | spectrum.channel_count = cpu_to_le16(1); |
| 3415 | spectrum.flags = |
| 3416 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 3417 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 3418 | cmd.len = sizeof(spectrum); |
| 3419 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 3420 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3421 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3422 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3423 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3424 | add_time, |
| 3425 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3426 | else |
| 3427 | spectrum.start_time = 0; |
| 3428 | |
| 3429 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 3430 | spectrum.channels[0].channel = params->channel; |
| 3431 | spectrum.channels[0].type = type; |
| 3432 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 3433 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 3434 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 3435 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3436 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3437 | if (rc) |
| 3438 | return rc; |
| 3439 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3440 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3441 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 3442 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 3443 | rc = -EIO; |
| 3444 | } |
| 3445 | |
| 3446 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 3447 | switch (spectrum_resp_status) { |
| 3448 | case 0: /* Command will be handled */ |
| 3449 | if (res->u.spectrum.id != 0xff) { |
| 3450 | IWL_DEBUG_INFO |
| 3451 | ("Replaced existing measurement: %d\n", |
| 3452 | res->u.spectrum.id); |
| 3453 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 3454 | } |
| 3455 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 3456 | rc = 0; |
| 3457 | break; |
| 3458 | |
| 3459 | case 1: /* Command will not be handled */ |
| 3460 | rc = -EAGAIN; |
| 3461 | break; |
| 3462 | } |
| 3463 | |
| 3464 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 3465 | |
| 3466 | return rc; |
| 3467 | } |
| 3468 | #endif |
| 3469 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3470 | static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv, |
| 3471 | struct iwl4965_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3472 | { |
| 3473 | |
| 3474 | tx_sta->status.ack_signal = 0; |
| 3475 | tx_sta->status.excessive_retries = 0; |
| 3476 | tx_sta->status.queue_length = 0; |
| 3477 | tx_sta->status.queue_number = 0; |
| 3478 | |
| 3479 | if (in_interrupt()) |
| 3480 | ieee80211_tx_status_irqsafe(priv->hw, |
| 3481 | tx_sta->skb[0], &(tx_sta->status)); |
| 3482 | else |
| 3483 | ieee80211_tx_status(priv->hw, |
| 3484 | tx_sta->skb[0], &(tx_sta->status)); |
| 3485 | |
| 3486 | tx_sta->skb[0] = NULL; |
| 3487 | } |
| 3488 | |
| 3489 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3490 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3491 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3492 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3493 | * need to be reclaimed. As result, some free space forms. If there is |
| 3494 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3495 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3496 | 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] | 3497 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3498 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
| 3499 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3500 | int nfreed = 0; |
| 3501 | |
| 3502 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 3503 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 3504 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3505 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3506 | return 0; |
| 3507 | } |
| 3508 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3509 | for (index = iwl4965_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3510 | q->read_ptr != index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3511 | 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] | 3512 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3513 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3514 | &(txq->txb[txq->q.read_ptr])); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3515 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3516 | } else if (nfreed > 1) { |
| 3517 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3518 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3519 | queue_work(priv->workqueue, &priv->restart); |
| 3520 | } |
| 3521 | nfreed++; |
| 3522 | } |
| 3523 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3524 | if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3525 | (txq_id != IWL_CMD_QUEUE_NUM) && |
| 3526 | priv->mac80211_registered) |
| 3527 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3528 | |
| 3529 | |
| 3530 | return nfreed; |
| 3531 | } |
| 3532 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3533 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3534 | { |
| 3535 | status &= TX_STATUS_MSK; |
| 3536 | return (status == TX_STATUS_SUCCESS) |
| 3537 | || (status == TX_STATUS_DIRECT_DONE); |
| 3538 | } |
| 3539 | |
| 3540 | /****************************************************************************** |
| 3541 | * |
| 3542 | * Generic RX handler implementations |
| 3543 | * |
| 3544 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3545 | #ifdef CONFIG_IWL4965_HT |
| 3546 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3547 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3548 | static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3549 | struct ieee80211_hdr *hdr) |
| 3550 | { |
| 3551 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 3552 | return IWL_AP_ID; |
| 3553 | else { |
| 3554 | u8 *da = ieee80211_get_DA(hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3555 | return iwl4965_hw_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3556 | } |
| 3557 | } |
| 3558 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3559 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
| 3560 | struct iwl4965_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3561 | { |
| 3562 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 3563 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 3564 | txb[idx].skb[0]->data; |
| 3565 | return NULL; |
| 3566 | } |
| 3567 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3568 | 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] | 3569 | { |
| 3570 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 3571 | tx_resp->frame_count); |
| 3572 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 3573 | |
| 3574 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3575 | |
| 3576 | /** |
| 3577 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 3578 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3579 | static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv, |
| 3580 | struct iwl4965_ht_agg *agg, |
| 3581 | struct iwl4965_tx_resp *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3582 | u16 start_idx) |
| 3583 | { |
| 3584 | u32 status; |
| 3585 | __le32 *frame_status = &tx_resp->status; |
| 3586 | struct ieee80211_tx_status *tx_status = NULL; |
| 3587 | struct ieee80211_hdr *hdr = NULL; |
| 3588 | int i, sh; |
| 3589 | int txq_id, idx; |
| 3590 | u16 seq; |
| 3591 | |
| 3592 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3593 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3594 | |
| 3595 | agg->frame_count = tx_resp->frame_count; |
| 3596 | agg->start_idx = start_idx; |
| 3597 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3598 | agg->bitmap0 = agg->bitmap1 = 0; |
| 3599 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3600 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3601 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3602 | /* Only one frame was attempted; no block-ack will arrive */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3603 | struct iwl4965_tx_queue *txq ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3604 | status = le32_to_cpu(frame_status[0]); |
| 3605 | |
| 3606 | txq_id = agg->txq_id; |
| 3607 | txq = &priv->txq[txq_id]; |
| 3608 | /* FIXME: code repetition */ |
| 3609 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d \n", |
| 3610 | agg->frame_count, agg->start_idx); |
| 3611 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3612 | tx_status = &(priv->txq[txq_id].txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3613 | tx_status->retry_count = tx_resp->failure_frame; |
| 3614 | tx_status->queue_number = status & 0xff; |
| 3615 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3616 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3617 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3618 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3619 | IEEE80211_TX_STATUS_ACK : 0; |
| 3620 | tx_status->control.tx_rate = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3621 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3622 | /* FIXME: code repetition end */ |
| 3623 | |
| 3624 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 3625 | status & 0xff, tx_resp->failure_frame); |
| 3626 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3627 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3628 | |
| 3629 | agg->wait_for_ba = 0; |
| 3630 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3631 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3632 | u64 bitmap = 0; |
| 3633 | int start = agg->start_idx; |
| 3634 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3635 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3636 | for (i = 0; i < agg->frame_count; i++) { |
| 3637 | u16 sc; |
| 3638 | status = le32_to_cpu(frame_status[i]); |
| 3639 | seq = status >> 16; |
| 3640 | idx = SEQ_TO_INDEX(seq); |
| 3641 | txq_id = SEQ_TO_QUEUE(seq); |
| 3642 | |
| 3643 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 3644 | AGG_TX_STATE_ABORT_MSK)) |
| 3645 | continue; |
| 3646 | |
| 3647 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 3648 | agg->frame_count, txq_id, idx); |
| 3649 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3650 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3651 | |
| 3652 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 3653 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 3654 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 3655 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 3656 | idx, SEQ_TO_SN(sc), |
| 3657 | hdr->seq_ctrl); |
| 3658 | return -1; |
| 3659 | } |
| 3660 | |
| 3661 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 3662 | i, idx, SEQ_TO_SN(sc)); |
| 3663 | |
| 3664 | sh = idx - start; |
| 3665 | if (sh > 64) { |
| 3666 | sh = (start - idx) + 0xff; |
| 3667 | bitmap = bitmap << sh; |
| 3668 | sh = 0; |
| 3669 | start = idx; |
| 3670 | } else if (sh < -64) |
| 3671 | sh = 0xff - (start - idx); |
| 3672 | else if (sh < 0) { |
| 3673 | sh = start - idx; |
| 3674 | start = idx; |
| 3675 | bitmap = bitmap << sh; |
| 3676 | sh = 0; |
| 3677 | } |
| 3678 | bitmap |= (1 << sh); |
| 3679 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 3680 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 3681 | } |
| 3682 | |
| 3683 | agg->bitmap0 = bitmap & 0xFFFFFFFF; |
| 3684 | agg->bitmap1 = bitmap >> 32; |
| 3685 | agg->start_idx = start; |
| 3686 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3687 | IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%x\n", |
| 3688 | agg->frame_count, agg->start_idx, |
| 3689 | agg->bitmap0); |
| 3690 | |
| 3691 | if (bitmap) |
| 3692 | agg->wait_for_ba = 1; |
| 3693 | } |
| 3694 | return 0; |
| 3695 | } |
| 3696 | #endif |
| 3697 | #endif |
| 3698 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3699 | /** |
| 3700 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 3701 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3702 | static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv, |
| 3703 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3704 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3705 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3706 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3707 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3708 | int index = SEQ_TO_INDEX(sequence); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3709 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3710 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3711 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3712 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3713 | #ifdef CONFIG_IWL4965_HT |
| 3714 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3715 | int tid, sta_id; |
| 3716 | #endif |
| 3717 | #endif |
| 3718 | |
| 3719 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 3720 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 3721 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3722 | index, txq->q.n_bd, txq->q.write_ptr, |
| 3723 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3724 | return; |
| 3725 | } |
| 3726 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3727 | #ifdef CONFIG_IWL4965_HT |
| 3728 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3729 | if (txq->sched_retry) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3730 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3731 | struct ieee80211_hdr *hdr = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3732 | iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 3733 | struct iwl4965_ht_agg *agg = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3734 | __le16 *qc = ieee80211_get_qos_ctrl(hdr); |
| 3735 | |
| 3736 | if (qc == NULL) { |
| 3737 | IWL_ERROR("BUG_ON qc is null!!!!\n"); |
| 3738 | return; |
| 3739 | } |
| 3740 | |
| 3741 | tid = le16_to_cpu(*qc) & 0xf; |
| 3742 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3743 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3744 | if (unlikely(sta_id == IWL_INVALID_STATION)) { |
| 3745 | IWL_ERROR("Station not known for\n"); |
| 3746 | return; |
| 3747 | } |
| 3748 | |
| 3749 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 3750 | |
| 3751 | iwl4965_tx_status_reply_tx(priv, agg, tx_resp, index); |
| 3752 | |
| 3753 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3754 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3755 | /* TODO: send BAR */ |
| 3756 | } |
| 3757 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3758 | if ((txq->q.read_ptr != (scd_ssn & 0xff))) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3759 | index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3760 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 3761 | "%d index %d\n", scd_ssn , index); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3762 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3763 | } |
| 3764 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3765 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 3766 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3767 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3768 | |
| 3769 | tx_status->retry_count = tx_resp->failure_frame; |
| 3770 | tx_status->queue_number = status; |
| 3771 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3772 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3773 | |
| 3774 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3775 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3776 | |
| 3777 | tx_status->control.tx_rate = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3778 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3779 | |
| 3780 | 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] | 3781 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3782 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 3783 | tx_resp->failure_frame); |
| 3784 | |
| 3785 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
| 3786 | if (index != -1) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3787 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3788 | #ifdef CONFIG_IWL4965_HT |
| 3789 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3790 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3791 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 3792 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3793 | |
| 3794 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 3795 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 3796 | } |
| 3797 | |
| 3798 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3799 | static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv, |
| 3800 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3801 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3802 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3803 | struct iwl4965_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3804 | struct delayed_work *pwork; |
| 3805 | |
| 3806 | palive = &pkt->u.alive_frame; |
| 3807 | |
| 3808 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 3809 | "0x%01X 0x%01X\n", |
| 3810 | palive->is_valid, palive->ver_type, |
| 3811 | palive->ver_subtype); |
| 3812 | |
| 3813 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 3814 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 3815 | memcpy(&priv->card_alive_init, |
| 3816 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3817 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3818 | pwork = &priv->init_alive_start; |
| 3819 | } else { |
| 3820 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3821 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3822 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3823 | pwork = &priv->alive_start; |
| 3824 | } |
| 3825 | |
| 3826 | /* We delay the ALIVE response by 5ms to |
| 3827 | * give the HW RF Kill time to activate... */ |
| 3828 | if (palive->is_valid == UCODE_VALID_OK) |
| 3829 | queue_delayed_work(priv->workqueue, pwork, |
| 3830 | msecs_to_jiffies(5)); |
| 3831 | else |
| 3832 | IWL_WARNING("uCode did not respond OK.\n"); |
| 3833 | } |
| 3834 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3835 | static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv, |
| 3836 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3837 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3838 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3839 | |
| 3840 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 3841 | return; |
| 3842 | } |
| 3843 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3844 | static void iwl4965_rx_reply_error(struct iwl4965_priv *priv, |
| 3845 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3846 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3847 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3848 | |
| 3849 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 3850 | "seq 0x%04X ser 0x%08X\n", |
| 3851 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 3852 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 3853 | pkt->u.err_resp.cmd_id, |
| 3854 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 3855 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 3856 | } |
| 3857 | |
| 3858 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 3859 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3860 | 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] | 3861 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3862 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3863 | struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 3864 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3865 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 3866 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 3867 | rxon->channel = csa->channel; |
| 3868 | priv->staging_rxon.channel = csa->channel; |
| 3869 | } |
| 3870 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3871 | static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv, |
| 3872 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3873 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3874 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3875 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3876 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3877 | |
| 3878 | if (!report->state) { |
| 3879 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 3880 | "Spectrum Measure Notification: Start\n"); |
| 3881 | return; |
| 3882 | } |
| 3883 | |
| 3884 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 3885 | priv->measurement_status |= MEASUREMENT_READY; |
| 3886 | #endif |
| 3887 | } |
| 3888 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3889 | static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv, |
| 3890 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3891 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3892 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3893 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3894 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3895 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 3896 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 3897 | #endif |
| 3898 | } |
| 3899 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3900 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv, |
| 3901 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3902 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3903 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3904 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 3905 | "notification for %s:\n", |
| 3906 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3907 | 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] | 3908 | } |
| 3909 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3910 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3911 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3912 | struct iwl4965_priv *priv = |
| 3913 | container_of(work, struct iwl4965_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3914 | struct sk_buff *beacon; |
| 3915 | |
| 3916 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3917 | beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3918 | |
| 3919 | if (!beacon) { |
| 3920 | IWL_ERROR("update beacon failed\n"); |
| 3921 | return; |
| 3922 | } |
| 3923 | |
| 3924 | mutex_lock(&priv->mutex); |
| 3925 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 3926 | if (priv->ibss_beacon) |
| 3927 | dev_kfree_skb(priv->ibss_beacon); |
| 3928 | |
| 3929 | priv->ibss_beacon = beacon; |
| 3930 | mutex_unlock(&priv->mutex); |
| 3931 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3932 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3933 | } |
| 3934 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3935 | static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv, |
| 3936 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3937 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3938 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3939 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3940 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 3941 | 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] | 3942 | |
| 3943 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 3944 | "tsf %d %d rate %d\n", |
| 3945 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 3946 | beacon->beacon_notify_hdr.failure_frame, |
| 3947 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3948 | le32_to_cpu(beacon->high_tsf), |
| 3949 | le32_to_cpu(beacon->low_tsf), rate); |
| 3950 | #endif |
| 3951 | |
| 3952 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3953 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 3954 | queue_work(priv->workqueue, &priv->beacon_update); |
| 3955 | } |
| 3956 | |
| 3957 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3958 | static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv, |
| 3959 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3960 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3961 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3962 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3963 | struct iwl4965_scanreq_notification *notif = |
| 3964 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3965 | |
| 3966 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 3967 | #endif |
| 3968 | } |
| 3969 | |
| 3970 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3971 | static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv, |
| 3972 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3973 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3974 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3975 | struct iwl4965_scanstart_notification *notif = |
| 3976 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3977 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 3978 | IWL_DEBUG_SCAN("Scan start: " |
| 3979 | "%d [802.11%s] " |
| 3980 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 3981 | notif->channel, |
| 3982 | notif->band ? "bg" : "a", |
| 3983 | notif->tsf_high, |
| 3984 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 3985 | } |
| 3986 | |
| 3987 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3988 | static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv, |
| 3989 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3990 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3991 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3992 | struct iwl4965_scanresults_notification *notif = |
| 3993 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3994 | |
| 3995 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 3996 | "%d [802.11%s] " |
| 3997 | "(TSF: 0x%08X:%08X) - %d " |
| 3998 | "elapsed=%lu usec (%dms since last)\n", |
| 3999 | notif->channel, |
| 4000 | notif->band ? "bg" : "a", |
| 4001 | le32_to_cpu(notif->tsf_high), |
| 4002 | le32_to_cpu(notif->tsf_low), |
| 4003 | le32_to_cpu(notif->statistics[0]), |
| 4004 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 4005 | jiffies_to_msecs(elapsed_jiffies |
| 4006 | (priv->last_scan_jiffies, jiffies))); |
| 4007 | |
| 4008 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4009 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4013 | static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv, |
| 4014 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4015 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4016 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 4017 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4018 | |
| 4019 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 4020 | scan_notif->scanned_channels, |
| 4021 | scan_notif->tsf_low, |
| 4022 | scan_notif->tsf_high, scan_notif->status); |
| 4023 | |
| 4024 | /* The HW is no longer scanning */ |
| 4025 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 4026 | |
| 4027 | /* The scan completion notification came in, so kill that timer... */ |
| 4028 | cancel_delayed_work(&priv->scan_check); |
| 4029 | |
| 4030 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 4031 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 4032 | jiffies_to_msecs(elapsed_jiffies |
| 4033 | (priv->scan_pass_start, jiffies))); |
| 4034 | |
| 4035 | /* Remove this scanned band from the list |
| 4036 | * of pending bands to scan */ |
| 4037 | priv->scan_bands--; |
| 4038 | |
| 4039 | /* If a request to abort was given, or the scan did not succeed |
| 4040 | * then we reset the scan state machine and terminate, |
| 4041 | * re-queuing another scan if one has been requested */ |
| 4042 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 4043 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 4044 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 4045 | } else { |
| 4046 | /* If there are more bands on this scan pass reschedule */ |
| 4047 | if (priv->scan_bands > 0) |
| 4048 | goto reschedule; |
| 4049 | } |
| 4050 | |
| 4051 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4052 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4053 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 4054 | |
| 4055 | clear_bit(STATUS_SCANNING, &priv->status); |
| 4056 | |
| 4057 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 4058 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 4059 | |
| 4060 | queue_work(priv->workqueue, &priv->scan_completed); |
| 4061 | |
| 4062 | return; |
| 4063 | |
| 4064 | reschedule: |
| 4065 | priv->scan_pass_start = jiffies; |
| 4066 | queue_work(priv->workqueue, &priv->request_scan); |
| 4067 | } |
| 4068 | |
| 4069 | /* Handle notification from uCode that card's power state is changing |
| 4070 | * due to software, hardware, or critical temperature RFKILL */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4071 | static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv, |
| 4072 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4073 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4074 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4075 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 4076 | unsigned long status = priv->status; |
| 4077 | |
| 4078 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 4079 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 4080 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 4081 | |
| 4082 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 4083 | RF_CARD_DISABLED)) { |
| 4084 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4085 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4086 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 4087 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4088 | if (!iwl4965_grab_nic_access(priv)) { |
| 4089 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4090 | priv, HBUS_TARG_MBX_C, |
| 4091 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4092 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4093 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | if (!(flags & RXON_CARD_DISABLED)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4097 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4098 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4099 | if (!iwl4965_grab_nic_access(priv)) { |
| 4100 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4101 | priv, HBUS_TARG_MBX_C, |
| 4102 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4103 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4104 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | if (flags & RF_CARD_DISABLED) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4109 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4110 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4111 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 4112 | if (!iwl4965_grab_nic_access(priv)) |
| 4113 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4114 | } |
| 4115 | } |
| 4116 | |
| 4117 | if (flags & HW_CARD_DISABLED) |
| 4118 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4119 | else |
| 4120 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4121 | |
| 4122 | |
| 4123 | if (flags & SW_CARD_DISABLED) |
| 4124 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4125 | else |
| 4126 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4127 | |
| 4128 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4129 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4130 | |
| 4131 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 4132 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 4133 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 4134 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 4135 | queue_work(priv->workqueue, &priv->rf_kill); |
| 4136 | else |
| 4137 | wake_up_interruptible(&priv->wait_command_queue); |
| 4138 | } |
| 4139 | |
| 4140 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4141 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4142 | * |
| 4143 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 4144 | * to the host. |
| 4145 | * |
| 4146 | * This function chains into the hardware specific files for them to setup |
| 4147 | * any hardware specific handlers as well. |
| 4148 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4149 | static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4150 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4151 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 4152 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 4153 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 4154 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4155 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4156 | iwl4965_rx_spectrum_measure_notif; |
| 4157 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4158 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4159 | iwl4965_rx_pm_debug_statistics_notif; |
| 4160 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4161 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4162 | /* |
| 4163 | * The same handler is used for both the REPLY to a discrete |
| 4164 | * statistics request from the host as well as for the periodic |
| 4165 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4166 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4167 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 4168 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4169 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4170 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 4171 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4172 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4173 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4174 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4175 | iwl4965_rx_scan_complete_notif; |
| 4176 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 4177 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4178 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4179 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4180 | iwl4965_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4184 | * 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] | 4185 | * @rxb: Rx buffer to reclaim |
| 4186 | * |
| 4187 | * If an Rx buffer has an async callback associated with it the callback |
| 4188 | * will be executed. The attached skb (if present) will only be freed |
| 4189 | * if the callback returns 1 |
| 4190 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4191 | static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv, |
| 4192 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4193 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4194 | struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4195 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 4196 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 4197 | int index = SEQ_TO_INDEX(sequence); |
| 4198 | int huge = sequence & SEQ_HUGE_FRAME; |
| 4199 | int cmd_index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4200 | struct iwl4965_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4201 | |
| 4202 | /* If a Tx command is being handled and it isn't in the actual |
| 4203 | * command queue then there a command routing bug has been introduced |
| 4204 | * in the queue management code. */ |
| 4205 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 4206 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 4207 | txq_id, pkt->hdr.cmd); |
| 4208 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 4209 | |
| 4210 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 4211 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 4212 | |
| 4213 | /* Input error checking is done when commands are added to queue. */ |
| 4214 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 4215 | cmd->meta.source->u.skb = rxb->skb; |
| 4216 | rxb->skb = NULL; |
| 4217 | } else if (cmd->meta.u.callback && |
| 4218 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 4219 | rxb->skb = NULL; |
| 4220 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4221 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4222 | |
| 4223 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 4224 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4225 | wake_up_interruptible(&priv->wait_command_queue); |
| 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | /************************** RX-FUNCTIONS ****************************/ |
| 4230 | /* |
| 4231 | * Rx theory of operation |
| 4232 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4233 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), |
| 4234 | * each of which point to Receive Buffers to be filled by 4965. These get |
| 4235 | * used not only for Rx frames, but for any command response or notification |
| 4236 | * from the 4965. The driver and 4965 manage the Rx buffers by means |
| 4237 | * of indexes into the circular buffer. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4238 | * |
| 4239 | * Rx Queue Indexes |
| 4240 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4241 | * |
| 4242 | * The READ index maps to the first position that the firmware may be writing |
| 4243 | * to -- the driver can read up to (but not including) this position and get |
| 4244 | * good data. |
| 4245 | * The READ index is managed by the firmware once the card is enabled. |
| 4246 | * |
| 4247 | * The WRITE index maps to the last position the driver has read from -- the |
| 4248 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4249 | * |
| 4250 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 4251 | * WRITE = READ. |
| 4252 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4253 | * 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] | 4254 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4255 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4256 | * 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] | 4257 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4258 | * process as many packets as possible, moving the WRITE index forward as it |
| 4259 | * resets the Rx queue buffers with new memory. |
| 4260 | * |
| 4261 | * The management in the driver is as follows: |
| 4262 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 4263 | * 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] | 4264 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4265 | * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4266 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 4267 | * 'processed' and 'read' driver indexes as well) |
| 4268 | * + A received packet is processed and handed to the kernel network stack, |
| 4269 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 4270 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 4271 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 4272 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 4273 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4274 | * |
| 4275 | * |
| 4276 | * Driver sequence: |
| 4277 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4278 | * iwl4965_rx_queue_alloc() Allocates rx_free |
| 4279 | * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4280 | * iwl4965_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4281 | * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4282 | * queue, updates firmware pointers, and updates |
| 4283 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4284 | * are available, schedules iwl4965_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4285 | * |
| 4286 | * -- enable interrupts -- |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4287 | * 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] | 4288 | * READ INDEX, detaching the SKB from the pool. |
| 4289 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4290 | * Calls iwl4965_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4291 | * slots. |
| 4292 | * ... |
| 4293 | * |
| 4294 | */ |
| 4295 | |
| 4296 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4297 | * iwl4965_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4298 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4299 | static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4300 | { |
| 4301 | int s = q->read - q->write; |
| 4302 | if (s <= 0) |
| 4303 | s += RX_QUEUE_SIZE; |
| 4304 | /* keep some buffer to not confuse full and empty queue */ |
| 4305 | s -= 2; |
| 4306 | if (s < 0) |
| 4307 | s = 0; |
| 4308 | return s; |
| 4309 | } |
| 4310 | |
| 4311 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4312 | * 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] | 4313 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4314 | 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] | 4315 | { |
| 4316 | u32 reg = 0; |
| 4317 | int rc = 0; |
| 4318 | unsigned long flags; |
| 4319 | |
| 4320 | spin_lock_irqsave(&q->lock, flags); |
| 4321 | |
| 4322 | if (q->need_update == 0) |
| 4323 | goto exit_unlock; |
| 4324 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4325 | /* If power-saving is in use, make sure device is awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4326 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4327 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4328 | |
| 4329 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4330 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4331 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4332 | goto exit_unlock; |
| 4333 | } |
| 4334 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4335 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4336 | if (rc) |
| 4337 | goto exit_unlock; |
| 4338 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4339 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4340 | iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4341 | q->write & ~0x7); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4342 | iwl4965_release_nic_access(priv); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4343 | |
| 4344 | /* Else device is assumed to be awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4345 | } else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4346 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4347 | iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4348 | |
| 4349 | |
| 4350 | q->need_update = 0; |
| 4351 | |
| 4352 | exit_unlock: |
| 4353 | spin_unlock_irqrestore(&q->lock, flags); |
| 4354 | return rc; |
| 4355 | } |
| 4356 | |
| 4357 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4358 | * 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] | 4359 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4360 | static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4361 | dma_addr_t dma_addr) |
| 4362 | { |
| 4363 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 4364 | } |
| 4365 | |
| 4366 | |
| 4367 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4368 | * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4369 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4370 | * 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] | 4371 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4372 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4373 | * |
| 4374 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4375 | * also updates the memory address in the firmware to reference the new |
| 4376 | * target buffer. |
| 4377 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4378 | static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4379 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4380 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4381 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4382 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4383 | unsigned long flags; |
| 4384 | int write, rc; |
| 4385 | |
| 4386 | spin_lock_irqsave(&rxq->lock, flags); |
| 4387 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4388 | while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4389 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4390 | element = rxq->rx_free.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4391 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4392 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4393 | |
| 4394 | /* Point to Rx buffer via next RBD in circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4395 | rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4396 | rxq->queue[rxq->write] = rxb; |
| 4397 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 4398 | rxq->free_count--; |
| 4399 | } |
| 4400 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4401 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 4402 | * refill it */ |
| 4403 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4404 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4405 | |
| 4406 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4407 | /* If we've added more space for the firmware to place data, tell it. |
| 4408 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4409 | if ((write != (rxq->write & ~0x7)) |
| 4410 | || (abs(rxq->write - rxq->read) > 7)) { |
| 4411 | spin_lock_irqsave(&rxq->lock, flags); |
| 4412 | rxq->need_update = 1; |
| 4413 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4414 | rc = iwl4965_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4415 | if (rc) |
| 4416 | return rc; |
| 4417 | } |
| 4418 | |
| 4419 | return 0; |
| 4420 | } |
| 4421 | |
| 4422 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4423 | * 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] | 4424 | * |
| 4425 | * When moving to rx_free an SKB is allocated for the slot. |
| 4426 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4427 | * Also restock the Rx queue via iwl4965_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 4428 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4429 | */ |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4430 | static void iwl4965_rx_allocate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4431 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4432 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4433 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4434 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4435 | unsigned long flags; |
| 4436 | spin_lock_irqsave(&rxq->lock, flags); |
| 4437 | while (!list_empty(&rxq->rx_used)) { |
| 4438 | element = rxq->rx_used.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4439 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4440 | |
| 4441 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4442 | rxb->skb = |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4443 | alloc_skb(priv->hw_setting.rx_buf_size, |
| 4444 | __GFP_NOWARN | GFP_ATOMIC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4445 | if (!rxb->skb) { |
| 4446 | if (net_ratelimit()) |
| 4447 | printk(KERN_CRIT DRV_NAME |
| 4448 | ": Can not allocate SKB buffers\n"); |
| 4449 | /* We don't reschedule replenish work here -- we will |
| 4450 | * call the restock method and if it still needs |
| 4451 | * more buffers it will schedule replenish */ |
| 4452 | break; |
| 4453 | } |
| 4454 | priv->alloc_rxb_skb++; |
| 4455 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4456 | |
| 4457 | /* Get physical address of RB/SKB */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4458 | rxb->dma_addr = |
| 4459 | pci_map_single(priv->pci_dev, rxb->skb->data, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4460 | priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4461 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4462 | rxq->free_count++; |
| 4463 | } |
| 4464 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | /* |
| 4468 | * this should be called while priv->lock is locked |
| 4469 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 4470 | static void __iwl4965_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4471 | { |
| 4472 | struct iwl4965_priv *priv = data; |
| 4473 | |
| 4474 | iwl4965_rx_allocate(priv); |
| 4475 | iwl4965_rx_queue_restock(priv); |
| 4476 | } |
| 4477 | |
| 4478 | |
| 4479 | void iwl4965_rx_replenish(void *data) |
| 4480 | { |
| 4481 | struct iwl4965_priv *priv = data; |
| 4482 | unsigned long flags; |
| 4483 | |
| 4484 | iwl4965_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4485 | |
| 4486 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4487 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4488 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4489 | } |
| 4490 | |
| 4491 | /* 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] | 4492 | * 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] | 4493 | * This free routine walks the list of POOL entries and if SKB is set to |
| 4494 | * non NULL it is unmapped and freed |
| 4495 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4496 | 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] | 4497 | { |
| 4498 | int i; |
| 4499 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4500 | if (rxq->pool[i].skb != NULL) { |
| 4501 | pci_unmap_single(priv->pci_dev, |
| 4502 | rxq->pool[i].dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4503 | priv->hw_setting.rx_buf_size, |
| 4504 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4505 | dev_kfree_skb(rxq->pool[i].skb); |
| 4506 | } |
| 4507 | } |
| 4508 | |
| 4509 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 4510 | rxq->dma_addr); |
| 4511 | rxq->bd = NULL; |
| 4512 | } |
| 4513 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4514 | int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4515 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4516 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4517 | struct pci_dev *dev = priv->pci_dev; |
| 4518 | int i; |
| 4519 | |
| 4520 | spin_lock_init(&rxq->lock); |
| 4521 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4522 | INIT_LIST_HEAD(&rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4523 | |
| 4524 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4525 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 4526 | if (!rxq->bd) |
| 4527 | return -ENOMEM; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4528 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4529 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4530 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 4531 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4532 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4533 | /* Set us so that we have processed and used all buffers, but have |
| 4534 | * not restocked the Rx queue with fresh buffers */ |
| 4535 | rxq->read = rxq->write = 0; |
| 4536 | rxq->free_count = 0; |
| 4537 | rxq->need_update = 0; |
| 4538 | return 0; |
| 4539 | } |
| 4540 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4541 | 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] | 4542 | { |
| 4543 | unsigned long flags; |
| 4544 | int i; |
| 4545 | spin_lock_irqsave(&rxq->lock, flags); |
| 4546 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4547 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4548 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4549 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 4550 | /* In the reset function, these buffers may have been allocated |
| 4551 | * to an SKB, so we need to unmap and free potential storage */ |
| 4552 | if (rxq->pool[i].skb != NULL) { |
| 4553 | pci_unmap_single(priv->pci_dev, |
| 4554 | rxq->pool[i].dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4555 | priv->hw_setting.rx_buf_size, |
| 4556 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4557 | priv->alloc_rxb_skb--; |
| 4558 | dev_kfree_skb(rxq->pool[i].skb); |
| 4559 | rxq->pool[i].skb = NULL; |
| 4560 | } |
| 4561 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4562 | } |
| 4563 | |
| 4564 | /* Set us so that we have processed and used all buffers, but have |
| 4565 | * not restocked the Rx queue with fresh buffers */ |
| 4566 | rxq->read = rxq->write = 0; |
| 4567 | rxq->free_count = 0; |
| 4568 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4569 | } |
| 4570 | |
| 4571 | /* Convert linear signal-to-noise ratio into dB */ |
| 4572 | static u8 ratio2dB[100] = { |
| 4573 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 4574 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 4575 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 4576 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 4577 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 4578 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 4579 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 4580 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 4581 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 4582 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 4583 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 4584 | }; |
| 4585 | |
| 4586 | /* Calculates a relative dB value from a ratio of linear |
| 4587 | * (i.e. not dB) signal levels. |
| 4588 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4589 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4590 | { |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4591 | /* 1000:1 or higher just report as 60 dB */ |
| 4592 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4593 | return 60; |
| 4594 | |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4595 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4596 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4597 | if (sig_ratio >= 100) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4598 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 4599 | |
| 4600 | /* We shouldn't see this */ |
| 4601 | if (sig_ratio < 1) |
| 4602 | return 0; |
| 4603 | |
| 4604 | /* Use table for ratios 1:1 - 99:1 */ |
| 4605 | return (int)ratio2dB[sig_ratio]; |
| 4606 | } |
| 4607 | |
| 4608 | #define PERFECT_RSSI (-20) /* dBm */ |
| 4609 | #define WORST_RSSI (-95) /* dBm */ |
| 4610 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 4611 | |
| 4612 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 4613 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 4614 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4615 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4616 | { |
| 4617 | int sig_qual; |
| 4618 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 4619 | |
| 4620 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 4621 | * as indicator; formula is (signal dbm - noise dbm). |
| 4622 | * SNR at or above 40 is a great signal (100%). |
| 4623 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 4624 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 4625 | if (noise_dbm) { |
| 4626 | if (rssi_dbm - noise_dbm >= 40) |
| 4627 | return 100; |
| 4628 | else if (rssi_dbm < noise_dbm) |
| 4629 | return 0; |
| 4630 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 4631 | |
| 4632 | /* Else use just the signal level. |
| 4633 | * This formula is a least squares fit of data points collected and |
| 4634 | * compared with a reference system that had a percentage (%) display |
| 4635 | * for signal quality. */ |
| 4636 | } else |
| 4637 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 4638 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 4639 | (RSSI_RANGE * RSSI_RANGE); |
| 4640 | |
| 4641 | if (sig_qual > 100) |
| 4642 | sig_qual = 100; |
| 4643 | else if (sig_qual < 1) |
| 4644 | sig_qual = 0; |
| 4645 | |
| 4646 | return sig_qual; |
| 4647 | } |
| 4648 | |
| 4649 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4650 | * iwl4965_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4651 | * |
| 4652 | * Uses the priv->rx_handlers callback function array to invoke |
| 4653 | * the appropriate handlers, including command responses, |
| 4654 | * frame-received notifications, and other notifications. |
| 4655 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4656 | static void iwl4965_rx_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4657 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4658 | struct iwl4965_rx_mem_buffer *rxb; |
| 4659 | struct iwl4965_rx_packet *pkt; |
| 4660 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4661 | u32 r, i; |
| 4662 | int reclaim; |
| 4663 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4664 | u8 fill_rx = 0; |
| 4665 | u32 count = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4666 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4667 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 4668 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4669 | r = iwl4965_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4670 | i = rxq->read; |
| 4671 | |
| 4672 | /* Rx interrupt, but nothing sent from uCode */ |
| 4673 | if (i == r) |
| 4674 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 4675 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4676 | if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
| 4677 | fill_rx = 1; |
| 4678 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4679 | while (i != r) { |
| 4680 | rxb = rxq->queue[i]; |
| 4681 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4682 | /* 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] | 4683 | * then a bug has been introduced in the queue refilling |
| 4684 | * routines -- catch it here */ |
| 4685 | BUG_ON(rxb == NULL); |
| 4686 | |
| 4687 | rxq->queue[i] = NULL; |
| 4688 | |
| 4689 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4690 | priv->hw_setting.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4691 | PCI_DMA_FROMDEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4692 | pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4693 | |
| 4694 | /* Reclaim a command buffer only if this packet is a response |
| 4695 | * to a (driver-originated) command. |
| 4696 | * If the packet (e.g. Rx frame) originated from uCode, |
| 4697 | * there is no command buffer to reclaim. |
| 4698 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 4699 | * but apparently a few don't get set; catch them here. */ |
| 4700 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 4701 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
| 4702 | (pkt->hdr.cmd != REPLY_4965_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 4703 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4704 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 4705 | (pkt->hdr.cmd != REPLY_TX); |
| 4706 | |
| 4707 | /* Based on type of command response or notification, |
| 4708 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4709 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4710 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 4711 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4712 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 4713 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 4714 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 4715 | } else { |
| 4716 | /* No handling needed */ |
| 4717 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4718 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 4719 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 4720 | pkt->hdr.cmd); |
| 4721 | } |
| 4722 | |
| 4723 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4724 | /* Invoke any callbacks, transfer the skb to caller, and |
| 4725 | * fire off the (possibly) blocking iwl4965_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4726 | * as we reclaim the driver command queue */ |
| 4727 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4728 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4729 | else |
| 4730 | IWL_WARNING("Claim null rxb?\n"); |
| 4731 | } |
| 4732 | |
| 4733 | /* For now we just don't re-use anything. We can tweak this |
| 4734 | * later to try and re-use notification packets and SKBs that |
| 4735 | * fail to Rx correctly */ |
| 4736 | if (rxb->skb != NULL) { |
| 4737 | priv->alloc_rxb_skb--; |
| 4738 | dev_kfree_skb_any(rxb->skb); |
| 4739 | rxb->skb = NULL; |
| 4740 | } |
| 4741 | |
| 4742 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4743 | priv->hw_setting.rx_buf_size, |
| 4744 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4745 | spin_lock_irqsave(&rxq->lock, flags); |
| 4746 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 4747 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4748 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4749 | /* If there are a lot of unused frames, |
| 4750 | * restock the Rx queue so ucode wont assert. */ |
| 4751 | if (fill_rx) { |
| 4752 | count++; |
| 4753 | if (count >= 8) { |
| 4754 | priv->rxq.read = i; |
| 4755 | __iwl4965_rx_replenish(priv); |
| 4756 | count = 0; |
| 4757 | } |
| 4758 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | /* Backtrack one entry */ |
| 4762 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4763 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4764 | } |
| 4765 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4766 | /** |
| 4767 | * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware |
| 4768 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4769 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 4770 | struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4771 | { |
| 4772 | u32 reg = 0; |
| 4773 | int rc = 0; |
| 4774 | int txq_id = txq->q.id; |
| 4775 | |
| 4776 | if (txq->need_update == 0) |
| 4777 | return rc; |
| 4778 | |
| 4779 | /* if we're trying to save power */ |
| 4780 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 4781 | /* wake up nic if it's powered down ... |
| 4782 | * uCode will wake up, and interrupt us again, so next |
| 4783 | * time we'll skip this part. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4784 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4785 | |
| 4786 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 4787 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4788 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4789 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4790 | return rc; |
| 4791 | } |
| 4792 | |
| 4793 | /* restore this queue's parameters in nic hardware. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4794 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4795 | if (rc) |
| 4796 | return rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4797 | iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4798 | txq->q.write_ptr | (txq_id << 8)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4799 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4800 | |
| 4801 | /* else not in power-save mode, uCode will never sleep when we're |
| 4802 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 4803 | } else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4804 | iwl4965_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4805 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4806 | |
| 4807 | txq->need_update = 0; |
| 4808 | |
| 4809 | return rc; |
| 4810 | } |
| 4811 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4812 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4813 | static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4814 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4815 | DECLARE_MAC_BUF(mac); |
| 4816 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4817 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4818 | iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4819 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 4820 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 4821 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 4822 | le32_to_cpu(rxon->filter_flags)); |
| 4823 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 4824 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 4825 | rxon->ofdm_basic_rates); |
| 4826 | 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] | 4827 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 4828 | print_mac(mac, rxon->node_addr)); |
| 4829 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 4830 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4831 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 4832 | } |
| 4833 | #endif |
| 4834 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4835 | static void iwl4965_enable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4836 | { |
| 4837 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 4838 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4839 | iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4842 | static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4843 | { |
| 4844 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 4845 | |
| 4846 | /* disable interrupts from uCode/NIC to host */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4847 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4848 | |
| 4849 | /* acknowledge/clear/reset any interrupts still pending |
| 4850 | * from uCode or flow handler (Rx/Tx DMA) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4851 | iwl4965_write32(priv, CSR_INT, 0xffffffff); |
| 4852 | iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4853 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 4854 | } |
| 4855 | |
| 4856 | static const char *desc_lookup(int i) |
| 4857 | { |
| 4858 | switch (i) { |
| 4859 | case 1: |
| 4860 | return "FAIL"; |
| 4861 | case 2: |
| 4862 | return "BAD_PARAM"; |
| 4863 | case 3: |
| 4864 | return "BAD_CHECKSUM"; |
| 4865 | case 4: |
| 4866 | return "NMI_INTERRUPT"; |
| 4867 | case 5: |
| 4868 | return "SYSASSERT"; |
| 4869 | case 6: |
| 4870 | return "FATAL_ERROR"; |
| 4871 | } |
| 4872 | |
| 4873 | return "UNKNOWN"; |
| 4874 | } |
| 4875 | |
| 4876 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4877 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4878 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4879 | static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4880 | { |
| 4881 | u32 data2, line; |
| 4882 | u32 desc, time, count, base, data1; |
| 4883 | u32 blink1, blink2, ilink1, ilink2; |
| 4884 | int rc; |
| 4885 | |
| 4886 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 4887 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4888 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4889 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 4890 | return; |
| 4891 | } |
| 4892 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4893 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4894 | if (rc) { |
| 4895 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4896 | return; |
| 4897 | } |
| 4898 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4899 | count = iwl4965_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4900 | |
| 4901 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 4902 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
| 4903 | IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n", |
| 4904 | priv->status, priv->config, count); |
| 4905 | } |
| 4906 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4907 | desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 4908 | blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 4909 | blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 4910 | ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 4911 | ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 4912 | data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 4913 | data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 4914 | line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 4915 | time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4916 | |
| 4917 | IWL_ERROR("Desc Time " |
| 4918 | "data1 data2 line\n"); |
| 4919 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 4920 | desc_lookup(desc), desc, time, data1, data2, line); |
| 4921 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 4922 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 4923 | ilink1, ilink2); |
| 4924 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4925 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 4929 | |
| 4930 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4931 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4932 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4933 | * NOTE: Must be called with iwl4965_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4934 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4935 | 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] | 4936 | u32 num_events, u32 mode) |
| 4937 | { |
| 4938 | u32 i; |
| 4939 | u32 base; /* SRAM byte address of event log header */ |
| 4940 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 4941 | u32 ptr; /* SRAM byte address of log data */ |
| 4942 | u32 ev, time, data; /* event log data */ |
| 4943 | |
| 4944 | if (num_events == 0) |
| 4945 | return; |
| 4946 | |
| 4947 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 4948 | |
| 4949 | if (mode == 0) |
| 4950 | event_size = 2 * sizeof(u32); |
| 4951 | else |
| 4952 | event_size = 3 * sizeof(u32); |
| 4953 | |
| 4954 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 4955 | |
| 4956 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 4957 | * place event id # at far right for easier visual parsing. */ |
| 4958 | for (i = 0; i < num_events; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4959 | ev = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4960 | ptr += sizeof(u32); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4961 | time = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4962 | ptr += sizeof(u32); |
| 4963 | if (mode == 0) |
| 4964 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 4965 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4966 | data = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4967 | ptr += sizeof(u32); |
| 4968 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 4969 | } |
| 4970 | } |
| 4971 | } |
| 4972 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4973 | static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4974 | { |
| 4975 | int rc; |
| 4976 | u32 base; /* SRAM byte address of event log header */ |
| 4977 | u32 capacity; /* event log capacity in # entries */ |
| 4978 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 4979 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 4980 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 4981 | u32 size; /* # entries that we'll print */ |
| 4982 | |
| 4983 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4984 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4985 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 4986 | return; |
| 4987 | } |
| 4988 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4989 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4990 | if (rc) { |
| 4991 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4992 | return; |
| 4993 | } |
| 4994 | |
| 4995 | /* event log header */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4996 | capacity = iwl4965_read_targ_mem(priv, base); |
| 4997 | mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 4998 | num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 4999 | next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5000 | |
| 5001 | size = num_wraps ? capacity : next_entry; |
| 5002 | |
| 5003 | /* bail out if nothing in log */ |
| 5004 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 5005 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5006 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5007 | return; |
| 5008 | } |
| 5009 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 5010 | 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] | 5011 | size, num_wraps); |
| 5012 | |
| 5013 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 5014 | * i.e the next one that uCode would fill. */ |
| 5015 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5016 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5017 | capacity - next_entry, mode); |
| 5018 | |
| 5019 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5020 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5021 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5022 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5023 | } |
| 5024 | |
| 5025 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5026 | * 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] | 5027 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5028 | static void iwl4965_irq_handle_error(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5029 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5030 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5031 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 5032 | |
| 5033 | /* Cancel currently queued command. */ |
| 5034 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 5035 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5036 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5037 | if (iwl4965_debug_level & IWL_DL_FW_ERRORS) { |
| 5038 | iwl4965_dump_nic_error_log(priv); |
| 5039 | iwl4965_dump_nic_event_log(priv); |
| 5040 | iwl4965_print_rx_config_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5041 | } |
| 5042 | #endif |
| 5043 | |
| 5044 | wake_up_interruptible(&priv->wait_command_queue); |
| 5045 | |
| 5046 | /* Keep the restart process from trying to send host |
| 5047 | * commands by clearing the INIT status bit */ |
| 5048 | clear_bit(STATUS_READY, &priv->status); |
| 5049 | |
| 5050 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 5051 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 5052 | "Restarting adapter due to uCode error.\n"); |
| 5053 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5054 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5055 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 5056 | sizeof(priv->recovery_rxon)); |
| 5057 | priv->error_recovering = 1; |
| 5058 | } |
| 5059 | queue_work(priv->workqueue, &priv->restart); |
| 5060 | } |
| 5061 | } |
| 5062 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5063 | static void iwl4965_error_recovery(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5064 | { |
| 5065 | unsigned long flags; |
| 5066 | |
| 5067 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 5068 | sizeof(priv->staging_rxon)); |
| 5069 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5070 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5071 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5072 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5073 | |
| 5074 | spin_lock_irqsave(&priv->lock, flags); |
| 5075 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 5076 | priv->error_recovering = 0; |
| 5077 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5078 | } |
| 5079 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5080 | static void iwl4965_irq_tasklet(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5081 | { |
| 5082 | u32 inta, handled = 0; |
| 5083 | u32 inta_fh; |
| 5084 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5085 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5086 | u32 inta_mask; |
| 5087 | #endif |
| 5088 | |
| 5089 | spin_lock_irqsave(&priv->lock, flags); |
| 5090 | |
| 5091 | /* Ack/clear/reset pending uCode interrupts. |
| 5092 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 5093 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5094 | inta = iwl4965_read32(priv, CSR_INT); |
| 5095 | iwl4965_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5096 | |
| 5097 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 5098 | * Any new interrupts that happen after this, either while we're |
| 5099 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5100 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
| 5101 | iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5102 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5103 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5104 | if (iwl4965_debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5105 | /* just for debug */ |
| 5106 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5107 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5108 | inta, inta_mask, inta_fh); |
| 5109 | } |
| 5110 | #endif |
| 5111 | |
| 5112 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 5113 | * atomic, make sure that inta covers all the interrupts that |
| 5114 | * we've discovered, even if FH interrupt came in just after |
| 5115 | * reading CSR_INT. */ |
| 5116 | if (inta_fh & CSR_FH_INT_RX_MASK) |
| 5117 | inta |= CSR_INT_BIT_FH_RX; |
| 5118 | if (inta_fh & CSR_FH_INT_TX_MASK) |
| 5119 | inta |= CSR_INT_BIT_FH_TX; |
| 5120 | |
| 5121 | /* Now service all interrupt bits discovered above. */ |
| 5122 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 5123 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 5124 | |
| 5125 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5126 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5127 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5128 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5129 | |
| 5130 | handled |= CSR_INT_BIT_HW_ERR; |
| 5131 | |
| 5132 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5133 | |
| 5134 | return; |
| 5135 | } |
| 5136 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5137 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5138 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5139 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame^] | 5140 | if (inta & CSR_INT_BIT_SCD) |
| 5141 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 5142 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5143 | |
| 5144 | /* Alive notification via Rx interrupt will do the real work */ |
| 5145 | if (inta & CSR_INT_BIT_ALIVE) |
| 5146 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 5147 | } |
| 5148 | #endif |
| 5149 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame^] | 5150 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5151 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5152 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5153 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 5154 | int hw_rf_kill = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5155 | if (!(iwl4965_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5156 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 5157 | hw_rf_kill = 1; |
| 5158 | |
| 5159 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 5160 | "RF_KILL bit toggled to %s.\n", |
| 5161 | hw_rf_kill ? "disable radio":"enable radio"); |
| 5162 | |
| 5163 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 5164 | * when we loaded driver, and is now set to "enable". |
| 5165 | * After we're Alive, RF_KILL gets handled by |
| 5166 | * iwl_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 5167 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 5168 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5169 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 5170 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5171 | |
| 5172 | handled |= CSR_INT_BIT_RF_KILL; |
| 5173 | } |
| 5174 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5175 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5176 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 5177 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 5178 | handled |= CSR_INT_BIT_CT_KILL; |
| 5179 | } |
| 5180 | |
| 5181 | /* Error detected by uCode */ |
| 5182 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 5183 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 5184 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5185 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5186 | handled |= CSR_INT_BIT_SW_ERR; |
| 5187 | } |
| 5188 | |
| 5189 | /* uCode wakes up after power-down sleep */ |
| 5190 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 5191 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5192 | iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq); |
| 5193 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 5194 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 5195 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 5196 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 5197 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 5198 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5199 | |
| 5200 | handled |= CSR_INT_BIT_WAKEUP; |
| 5201 | } |
| 5202 | |
| 5203 | /* All uCode command responses, including Tx command responses, |
| 5204 | * Rx "responses" (frame-received notification), and other |
| 5205 | * notifications from uCode come through here*/ |
| 5206 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5207 | iwl4965_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5208 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 5209 | } |
| 5210 | |
| 5211 | if (inta & CSR_INT_BIT_FH_TX) { |
| 5212 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 5213 | handled |= CSR_INT_BIT_FH_TX; |
| 5214 | } |
| 5215 | |
| 5216 | if (inta & ~handled) |
| 5217 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 5218 | |
| 5219 | if (inta & ~CSR_INI_SET_MASK) { |
| 5220 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 5221 | inta & ~CSR_INI_SET_MASK); |
| 5222 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 5223 | } |
| 5224 | |
| 5225 | /* Re-enable all interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5226 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5227 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5228 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5229 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
| 5230 | inta = iwl4965_read32(priv, CSR_INT); |
| 5231 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
| 5232 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5233 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 5234 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 5235 | } |
| 5236 | #endif |
| 5237 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5238 | } |
| 5239 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5240 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5241 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5242 | struct iwl4965_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5243 | u32 inta, inta_mask; |
| 5244 | u32 inta_fh; |
| 5245 | if (!priv) |
| 5246 | return IRQ_NONE; |
| 5247 | |
| 5248 | spin_lock(&priv->lock); |
| 5249 | |
| 5250 | /* Disable (but don't clear!) interrupts here to avoid |
| 5251 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 5252 | * If we have something to service, the tasklet will re-enable ints. |
| 5253 | * 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] | 5254 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 5255 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5256 | |
| 5257 | /* Discover which interrupts are active/pending */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5258 | inta = iwl4965_read32(priv, CSR_INT); |
| 5259 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5260 | |
| 5261 | /* Ignore interrupt if there's nothing in NIC to service. |
| 5262 | * This may be due to IRQ shared with another device, |
| 5263 | * or due to sporadic interrupts thrown from our NIC. */ |
| 5264 | if (!inta && !inta_fh) { |
| 5265 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 5266 | goto none; |
| 5267 | } |
| 5268 | |
| 5269 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5270 | /* Hardware disappeared. It might have already raised |
| 5271 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5272 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5273 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5277 | inta, inta_mask, inta_fh); |
| 5278 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame^] | 5279 | inta &= ~CSR_INT_BIT_SCD; |
| 5280 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5281 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame^] | 5282 | if (likely(inta || inta_fh)) |
| 5283 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5284 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5285 | unplugged: |
| 5286 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5287 | return IRQ_HANDLED; |
| 5288 | |
| 5289 | none: |
| 5290 | /* re-enable interrupts here since we don't have anything to service. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5291 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5292 | spin_unlock(&priv->lock); |
| 5293 | return IRQ_NONE; |
| 5294 | } |
| 5295 | |
| 5296 | /************************** EEPROM BANDS **************************** |
| 5297 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5298 | * The iwl4965_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5299 | * EEPROM contents to the specific channel number supported for each |
| 5300 | * band. |
| 5301 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5302 | * 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] | 5303 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 5304 | * The specific geography and calibration information for that channel |
| 5305 | * is contained in the eeprom map itself. |
| 5306 | * |
| 5307 | * During init, we copy the eeprom information and channel map |
| 5308 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 5309 | * |
| 5310 | * channel_map_24/52 provides the index in the channel_info array for a |
| 5311 | * given channel. We have to have two separate maps as there is channel |
| 5312 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 5313 | * band_2 |
| 5314 | * |
| 5315 | * A value of 0xff stored in the channel_map indicates that the channel |
| 5316 | * is not supported by the hardware at all. |
| 5317 | * |
| 5318 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 5319 | * valid for Tx with the current hardware. This means that |
| 5320 | * while the system can tune and receive on a given channel, it may not |
| 5321 | * be able to associate or transmit any frames on that |
| 5322 | * channel. There is no corresponding channel information for that |
| 5323 | * entry. |
| 5324 | * |
| 5325 | *********************************************************************/ |
| 5326 | |
| 5327 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5328 | static const u8 iwl4965_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5329 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 5330 | }; |
| 5331 | |
| 5332 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5333 | static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5334 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 5335 | }; |
| 5336 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5337 | static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5338 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 5339 | }; |
| 5340 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5341 | static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5342 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 5343 | }; |
| 5344 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5345 | static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5346 | 145, 149, 153, 157, 161, 165 |
| 5347 | }; |
| 5348 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5349 | static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5350 | 1, 2, 3, 4, 5, 6, 7 |
| 5351 | }; |
| 5352 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5353 | static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5354 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 |
| 5355 | }; |
| 5356 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5357 | static void iwl4965_init_band_reference(const struct iwl4965_priv *priv, |
| 5358 | int band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5359 | int *eeprom_ch_count, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5360 | const struct iwl4965_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5361 | **eeprom_ch_info, |
| 5362 | const u8 **eeprom_ch_index) |
| 5363 | { |
| 5364 | switch (band) { |
| 5365 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5366 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5367 | *eeprom_ch_info = priv->eeprom.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5368 | *eeprom_ch_index = iwl4965_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5369 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5370 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5371 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5372 | *eeprom_ch_info = priv->eeprom.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5373 | *eeprom_ch_index = iwl4965_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5374 | break; |
| 5375 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5376 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5377 | *eeprom_ch_info = priv->eeprom.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5378 | *eeprom_ch_index = iwl4965_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5379 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5380 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5381 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5382 | *eeprom_ch_info = priv->eeprom.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5383 | *eeprom_ch_index = iwl4965_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5384 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5385 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5386 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5387 | *eeprom_ch_info = priv->eeprom.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5388 | *eeprom_ch_index = iwl4965_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5389 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5390 | case 6: /* 2.4GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5391 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5392 | *eeprom_ch_info = priv->eeprom.band_24_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5393 | *eeprom_ch_index = iwl4965_eeprom_band_6; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5394 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5395 | case 7: /* 5 GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5396 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5397 | *eeprom_ch_info = priv->eeprom.band_52_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5398 | *eeprom_ch_index = iwl4965_eeprom_band_7; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5399 | break; |
| 5400 | default: |
| 5401 | BUG(); |
| 5402 | return; |
| 5403 | } |
| 5404 | } |
| 5405 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5406 | /** |
| 5407 | * iwl4965_get_channel_info - Find driver's private channel info |
| 5408 | * |
| 5409 | * Based on band and channel number. |
| 5410 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5411 | 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] | 5412 | int phymode, u16 channel) |
| 5413 | { |
| 5414 | int i; |
| 5415 | |
| 5416 | switch (phymode) { |
| 5417 | case MODE_IEEE80211A: |
| 5418 | for (i = 14; i < priv->channel_count; i++) { |
| 5419 | if (priv->channel_info[i].channel == channel) |
| 5420 | return &priv->channel_info[i]; |
| 5421 | } |
| 5422 | break; |
| 5423 | |
| 5424 | case MODE_IEEE80211B: |
| 5425 | case MODE_IEEE80211G: |
| 5426 | if (channel >= 1 && channel <= 14) |
| 5427 | return &priv->channel_info[channel - 1]; |
| 5428 | break; |
| 5429 | |
| 5430 | } |
| 5431 | |
| 5432 | return NULL; |
| 5433 | } |
| 5434 | |
| 5435 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 5436 | ? # x " " : "") |
| 5437 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5438 | /** |
| 5439 | * iwl4965_init_channel_map - Set up driver's info for all possible channels |
| 5440 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5441 | static int iwl4965_init_channel_map(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5442 | { |
| 5443 | int eeprom_ch_count = 0; |
| 5444 | const u8 *eeprom_ch_index = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5445 | const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5446 | int band, ch; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5447 | struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5448 | |
| 5449 | if (priv->channel_count) { |
| 5450 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 5451 | return 0; |
| 5452 | } |
| 5453 | |
| 5454 | if (priv->eeprom.version < 0x2f) { |
| 5455 | IWL_WARNING("Unsupported EEPROM version: 0x%04X\n", |
| 5456 | priv->eeprom.version); |
| 5457 | return -EINVAL; |
| 5458 | } |
| 5459 | |
| 5460 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 5461 | |
| 5462 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5463 | ARRAY_SIZE(iwl4965_eeprom_band_1) + |
| 5464 | ARRAY_SIZE(iwl4965_eeprom_band_2) + |
| 5465 | ARRAY_SIZE(iwl4965_eeprom_band_3) + |
| 5466 | ARRAY_SIZE(iwl4965_eeprom_band_4) + |
| 5467 | ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5468 | |
| 5469 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 5470 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5471 | priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5472 | priv->channel_count, GFP_KERNEL); |
| 5473 | if (!priv->channel_info) { |
| 5474 | IWL_ERROR("Could not allocate channel_info\n"); |
| 5475 | priv->channel_count = 0; |
| 5476 | return -ENOMEM; |
| 5477 | } |
| 5478 | |
| 5479 | ch_info = priv->channel_info; |
| 5480 | |
| 5481 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 5482 | * channel map we maintain (that contains additional information than |
| 5483 | * what just in the EEPROM) */ |
| 5484 | for (band = 1; band <= 5; band++) { |
| 5485 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5486 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5487 | &eeprom_ch_info, &eeprom_ch_index); |
| 5488 | |
| 5489 | /* Loop through each band adding each of the channels */ |
| 5490 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5491 | ch_info->channel = eeprom_ch_index[ch]; |
| 5492 | ch_info->phymode = (band == 1) ? MODE_IEEE80211B : |
| 5493 | MODE_IEEE80211A; |
| 5494 | |
| 5495 | /* permanently store EEPROM's channel regulatory flags |
| 5496 | * and max power in channel info database. */ |
| 5497 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 5498 | |
| 5499 | /* Copy the run-time flags so they are there even on |
| 5500 | * invalid channels */ |
| 5501 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 5502 | |
| 5503 | if (!(is_channel_valid(ch_info))) { |
| 5504 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 5505 | "No traffic\n", |
| 5506 | ch_info->channel, |
| 5507 | ch_info->flags, |
| 5508 | is_channel_a_band(ch_info) ? |
| 5509 | "5.2" : "2.4"); |
| 5510 | ch_info++; |
| 5511 | continue; |
| 5512 | } |
| 5513 | |
| 5514 | /* Initialize regulatory-based run-time data */ |
| 5515 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 5516 | eeprom_ch_info[ch].max_power_avg; |
| 5517 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 5518 | ch_info->min_power = 0; |
| 5519 | |
| 5520 | IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x" |
| 5521 | " %ddBm): Ad-Hoc %ssupported\n", |
| 5522 | ch_info->channel, |
| 5523 | is_channel_a_band(ch_info) ? |
| 5524 | "5.2" : "2.4", |
| 5525 | CHECK_AND_PRINT(IBSS), |
| 5526 | CHECK_AND_PRINT(ACTIVE), |
| 5527 | CHECK_AND_PRINT(RADAR), |
| 5528 | CHECK_AND_PRINT(WIDE), |
| 5529 | CHECK_AND_PRINT(NARROW), |
| 5530 | CHECK_AND_PRINT(DFS), |
| 5531 | eeprom_ch_info[ch].flags, |
| 5532 | eeprom_ch_info[ch].max_power_avg, |
| 5533 | ((eeprom_ch_info[ch]. |
| 5534 | flags & EEPROM_CHANNEL_IBSS) |
| 5535 | && !(eeprom_ch_info[ch]. |
| 5536 | flags & EEPROM_CHANNEL_RADAR)) |
| 5537 | ? "" : "not "); |
| 5538 | |
| 5539 | /* Set the user_txpower_limit to the highest power |
| 5540 | * supported by any channel */ |
| 5541 | if (eeprom_ch_info[ch].max_power_avg > |
| 5542 | priv->user_txpower_limit) |
| 5543 | priv->user_txpower_limit = |
| 5544 | eeprom_ch_info[ch].max_power_avg; |
| 5545 | |
| 5546 | ch_info++; |
| 5547 | } |
| 5548 | } |
| 5549 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5550 | /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5551 | for (band = 6; band <= 7; band++) { |
| 5552 | int phymode; |
| 5553 | u8 fat_extension_chan; |
| 5554 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5555 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5556 | &eeprom_ch_info, &eeprom_ch_index); |
| 5557 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5558 | /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5559 | phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5560 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5561 | /* Loop through each band adding each of the channels */ |
| 5562 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5563 | |
| 5564 | if ((band == 6) && |
| 5565 | ((eeprom_ch_index[ch] == 5) || |
| 5566 | (eeprom_ch_index[ch] == 6) || |
| 5567 | (eeprom_ch_index[ch] == 7))) |
| 5568 | fat_extension_chan = HT_IE_EXT_CHANNEL_MAX; |
| 5569 | else |
| 5570 | fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; |
| 5571 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5572 | /* Set up driver's info for lower half */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5573 | iwl4965_set_fat_chan_info(priv, phymode, |
| 5574 | eeprom_ch_index[ch], |
| 5575 | &(eeprom_ch_info[ch]), |
| 5576 | fat_extension_chan); |
| 5577 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5578 | /* Set up driver's info for upper half */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5579 | iwl4965_set_fat_chan_info(priv, phymode, |
| 5580 | (eeprom_ch_index[ch] + 4), |
| 5581 | &(eeprom_ch_info[ch]), |
| 5582 | HT_IE_EXT_CHANNEL_BELOW); |
| 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | return 0; |
| 5587 | } |
| 5588 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5589 | /* |
| 5590 | * iwl4965_free_channel_map - undo allocations in iwl4965_init_channel_map |
| 5591 | */ |
| 5592 | static void iwl4965_free_channel_map(struct iwl4965_priv *priv) |
| 5593 | { |
| 5594 | kfree(priv->channel_info); |
| 5595 | priv->channel_count = 0; |
| 5596 | } |
| 5597 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5598 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 5599 | * sending probe req. This should be set long enough to hear probe responses |
| 5600 | * from more than one AP. */ |
| 5601 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5602 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 5603 | |
| 5604 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 5605 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 5606 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 5607 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 5608 | * no other traffic). |
| 5609 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 5610 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 5611 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 5612 | |
| 5613 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 5614 | * Must be set longer than active dwell time. |
| 5615 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 5616 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5617 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 5618 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 5619 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 5620 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5621 | 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] | 5622 | { |
| 5623 | if (phymode == MODE_IEEE80211A) |
| 5624 | return IWL_ACTIVE_DWELL_TIME_52; |
| 5625 | else |
| 5626 | return IWL_ACTIVE_DWELL_TIME_24; |
| 5627 | } |
| 5628 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5629 | 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] | 5630 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5631 | u16 active = iwl4965_get_active_dwell_time(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5632 | u16 passive = (phymode != MODE_IEEE80211A) ? |
| 5633 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 5634 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 5635 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5636 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5637 | /* If we're associated, we clamp the maximum passive |
| 5638 | * dwell time to be 98% of the beacon interval (minus |
| 5639 | * 2 * channel tune time) */ |
| 5640 | passive = priv->beacon_int; |
| 5641 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 5642 | passive = IWL_PASSIVE_DWELL_BASE; |
| 5643 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 5644 | } |
| 5645 | |
| 5646 | if (passive <= active) |
| 5647 | passive = active + 1; |
| 5648 | |
| 5649 | return passive; |
| 5650 | } |
| 5651 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5652 | 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] | 5653 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5654 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5655 | { |
| 5656 | const struct ieee80211_channel *channels = NULL; |
| 5657 | const struct ieee80211_hw_mode *hw_mode; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5658 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5659 | u16 passive_dwell = 0; |
| 5660 | u16 active_dwell = 0; |
| 5661 | int added, i; |
| 5662 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5663 | hw_mode = iwl4965_get_hw_mode(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5664 | if (!hw_mode) |
| 5665 | return 0; |
| 5666 | |
| 5667 | channels = hw_mode->channels; |
| 5668 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5669 | active_dwell = iwl4965_get_active_dwell_time(priv, phymode); |
| 5670 | passive_dwell = iwl4965_get_passive_dwell_time(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5671 | |
| 5672 | for (i = 0, added = 0; i < hw_mode->num_channels; i++) { |
| 5673 | if (channels[i].chan == |
| 5674 | le16_to_cpu(priv->active_rxon.channel)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5675 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5676 | IWL_DEBUG_SCAN |
| 5677 | ("Skipping current channel %d\n", |
| 5678 | le16_to_cpu(priv->active_rxon.channel)); |
| 5679 | continue; |
| 5680 | } |
| 5681 | } else if (priv->only_active_channel) |
| 5682 | continue; |
| 5683 | |
| 5684 | scan_ch->channel = channels[i].chan; |
| 5685 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5686 | ch_info = iwl4965_get_channel_info(priv, phymode, |
| 5687 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5688 | if (!is_channel_valid(ch_info)) { |
| 5689 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 5690 | scan_ch->channel); |
| 5691 | continue; |
| 5692 | } |
| 5693 | |
| 5694 | if (!is_active || is_channel_passive(ch_info) || |
| 5695 | !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN)) |
| 5696 | scan_ch->type = 0; /* passive */ |
| 5697 | else |
| 5698 | scan_ch->type = 1; /* active */ |
| 5699 | |
| 5700 | if (scan_ch->type & 1) |
| 5701 | scan_ch->type |= (direct_mask << 1); |
| 5702 | |
| 5703 | if (is_channel_narrow(ch_info)) |
| 5704 | scan_ch->type |= (1 << 7); |
| 5705 | |
| 5706 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 5707 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 5708 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5709 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5710 | scan_ch->tpc.dsp_atten = 110; |
| 5711 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 5712 | |
| 5713 | /*scan_pwr_info->tpc.tx_gain; */ |
| 5714 | if (phymode == MODE_IEEE80211A) |
| 5715 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 5716 | else { |
| 5717 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 5718 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5719 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 5720 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5721 | */ |
| 5722 | } |
| 5723 | |
| 5724 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 5725 | scan_ch->channel, |
| 5726 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 5727 | (scan_ch->type & 1) ? |
| 5728 | active_dwell : passive_dwell); |
| 5729 | |
| 5730 | scan_ch++; |
| 5731 | added++; |
| 5732 | } |
| 5733 | |
| 5734 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 5735 | return added; |
| 5736 | } |
| 5737 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5738 | static void iwl4965_reset_channel_flag(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5739 | { |
| 5740 | int i, j; |
| 5741 | for (i = 0; i < 3; i++) { |
| 5742 | struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i]; |
| 5743 | for (j = 0; j < hw_mode->num_channels; j++) |
| 5744 | hw_mode->channels[j].flag = hw_mode->channels[j].val; |
| 5745 | } |
| 5746 | } |
| 5747 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5748 | static void iwl4965_init_hw_rates(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5749 | struct ieee80211_rate *rates) |
| 5750 | { |
| 5751 | int i; |
| 5752 | |
| 5753 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5754 | rates[i].rate = iwl4965_rates[i].ieee * 5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5755 | rates[i].val = i; /* Rate scaling will work on indexes */ |
| 5756 | rates[i].val2 = i; |
| 5757 | rates[i].flags = IEEE80211_RATE_SUPPORTED; |
| 5758 | /* Only OFDM have the bits-per-symbol set */ |
| 5759 | if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE)) |
| 5760 | rates[i].flags |= IEEE80211_RATE_OFDM; |
| 5761 | else { |
| 5762 | /* |
| 5763 | * If CCK 1M then set rate flag to CCK else CCK_2 |
| 5764 | * which is CCK | PREAMBLE2 |
| 5765 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5766 | rates[i].flags |= (iwl4965_rates[i].plcp == 10) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5767 | IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2; |
| 5768 | } |
| 5769 | |
| 5770 | /* Set up which ones are basic rates... */ |
| 5771 | if (IWL_BASIC_RATES_MASK & (1 << i)) |
| 5772 | rates[i].flags |= IEEE80211_RATE_BASIC; |
| 5773 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5777 | * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5778 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5779 | static int iwl4965_init_geos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5780 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5781 | struct iwl4965_channel_info *ch; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5782 | struct ieee80211_hw_mode *modes; |
| 5783 | struct ieee80211_channel *channels; |
| 5784 | struct ieee80211_channel *geo_ch; |
| 5785 | struct ieee80211_rate *rates; |
| 5786 | int i = 0; |
| 5787 | enum { |
| 5788 | A = 0, |
| 5789 | B = 1, |
| 5790 | G = 2, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5791 | }; |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 5792 | int mode_count = 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5793 | |
| 5794 | if (priv->modes) { |
| 5795 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 5796 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5797 | return 0; |
| 5798 | } |
| 5799 | |
| 5800 | modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count, |
| 5801 | GFP_KERNEL); |
| 5802 | if (!modes) |
| 5803 | return -ENOMEM; |
| 5804 | |
| 5805 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 5806 | priv->channel_count, GFP_KERNEL); |
| 5807 | if (!channels) { |
| 5808 | kfree(modes); |
| 5809 | return -ENOMEM; |
| 5810 | } |
| 5811 | |
| 5812 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)), |
| 5813 | GFP_KERNEL); |
| 5814 | if (!rates) { |
| 5815 | kfree(modes); |
| 5816 | kfree(channels); |
| 5817 | return -ENOMEM; |
| 5818 | } |
| 5819 | |
| 5820 | /* 0 = 802.11a |
| 5821 | * 1 = 802.11b |
| 5822 | * 2 = 802.11g |
| 5823 | */ |
| 5824 | |
| 5825 | /* 5.2GHz channels start after the 2.4GHz channels */ |
| 5826 | modes[A].mode = MODE_IEEE80211A; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5827 | modes[A].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5828 | modes[A].rates = rates; |
| 5829 | modes[A].num_rates = 8; /* just OFDM */ |
| 5830 | modes[A].rates = &rates[4]; |
| 5831 | modes[A].num_channels = 0; |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 5832 | #ifdef CONFIG_IWL4965_HT |
| 5833 | iwl4965_init_ht_hw_capab(&modes[A].ht_info, MODE_IEEE80211A); |
| 5834 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5835 | |
| 5836 | modes[B].mode = MODE_IEEE80211B; |
| 5837 | modes[B].channels = channels; |
| 5838 | modes[B].rates = rates; |
| 5839 | modes[B].num_rates = 4; /* just CCK */ |
| 5840 | modes[B].num_channels = 0; |
| 5841 | |
| 5842 | modes[G].mode = MODE_IEEE80211G; |
| 5843 | modes[G].channels = channels; |
| 5844 | modes[G].rates = rates; |
| 5845 | modes[G].num_rates = 12; /* OFDM & CCK */ |
| 5846 | modes[G].num_channels = 0; |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 5847 | #ifdef CONFIG_IWL4965_HT |
| 5848 | iwl4965_init_ht_hw_capab(&modes[G].ht_info, MODE_IEEE80211G); |
| 5849 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5850 | |
| 5851 | priv->ieee_channels = channels; |
| 5852 | priv->ieee_rates = rates; |
| 5853 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5854 | iwl4965_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5855 | |
| 5856 | for (i = 0, geo_ch = channels; i < priv->channel_count; i++) { |
| 5857 | ch = &priv->channel_info[i]; |
| 5858 | |
| 5859 | if (!is_channel_valid(ch)) { |
| 5860 | IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- " |
| 5861 | "skipping.\n", |
| 5862 | ch->channel, is_channel_a_band(ch) ? |
| 5863 | "5.2" : "2.4"); |
| 5864 | continue; |
| 5865 | } |
| 5866 | |
| 5867 | if (is_channel_a_band(ch)) { |
| 5868 | geo_ch = &modes[A].channels[modes[A].num_channels++]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5869 | } else { |
| 5870 | geo_ch = &modes[B].channels[modes[B].num_channels++]; |
| 5871 | modes[G].num_channels++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | geo_ch->freq = ieee80211chan2mhz(ch->channel); |
| 5875 | geo_ch->chan = ch->channel; |
| 5876 | geo_ch->power_level = ch->max_power_avg; |
| 5877 | geo_ch->antenna_max = 0xff; |
| 5878 | |
| 5879 | if (is_channel_valid(ch)) { |
| 5880 | geo_ch->flag = IEEE80211_CHAN_W_SCAN; |
| 5881 | if (ch->flags & EEPROM_CHANNEL_IBSS) |
| 5882 | geo_ch->flag |= IEEE80211_CHAN_W_IBSS; |
| 5883 | |
| 5884 | if (ch->flags & EEPROM_CHANNEL_ACTIVE) |
| 5885 | geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN; |
| 5886 | |
| 5887 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
| 5888 | geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT; |
| 5889 | |
| 5890 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 5891 | priv->max_channel_txpower_limit = |
| 5892 | ch->max_power_avg; |
| 5893 | } |
| 5894 | |
| 5895 | geo_ch->val = geo_ch->flag; |
| 5896 | } |
| 5897 | |
| 5898 | if ((modes[A].num_channels == 0) && priv->is_abg) { |
| 5899 | printk(KERN_INFO DRV_NAME |
| 5900 | ": Incorrectly detected BG card as ABG. Please send " |
| 5901 | "your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 5902 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
| 5903 | priv->is_abg = 0; |
| 5904 | } |
| 5905 | |
| 5906 | printk(KERN_INFO DRV_NAME |
| 5907 | ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
| 5908 | modes[G].num_channels, modes[A].num_channels); |
| 5909 | |
| 5910 | /* |
| 5911 | * NOTE: We register these in preference of order -- the |
| 5912 | * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick |
| 5913 | * a phymode based on rates or AP capabilities but seems to |
| 5914 | * configure it purely on if the channel being configured |
| 5915 | * is supported by a mode -- and the first match is taken |
| 5916 | */ |
| 5917 | |
| 5918 | if (modes[G].num_channels) |
| 5919 | ieee80211_register_hwmode(priv->hw, &modes[G]); |
| 5920 | if (modes[B].num_channels) |
| 5921 | ieee80211_register_hwmode(priv->hw, &modes[B]); |
| 5922 | if (modes[A].num_channels) |
| 5923 | ieee80211_register_hwmode(priv->hw, &modes[A]); |
| 5924 | |
| 5925 | priv->modes = modes; |
| 5926 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5927 | |
| 5928 | return 0; |
| 5929 | } |
| 5930 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5931 | /* |
| 5932 | * iwl4965_free_geos - undo allocations in iwl4965_init_geos |
| 5933 | */ |
| 5934 | static void iwl4965_free_geos(struct iwl4965_priv *priv) |
| 5935 | { |
| 5936 | kfree(priv->modes); |
| 5937 | kfree(priv->ieee_channels); |
| 5938 | kfree(priv->ieee_rates); |
| 5939 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5940 | } |
| 5941 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5942 | /****************************************************************************** |
| 5943 | * |
| 5944 | * uCode download functions |
| 5945 | * |
| 5946 | ******************************************************************************/ |
| 5947 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5948 | static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5949 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5950 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 5951 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 5952 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 5953 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 5954 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 5955 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5956 | } |
| 5957 | |
| 5958 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5959 | * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5960 | * looking at all data. |
| 5961 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 5962 | static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 *image, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5963 | u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5964 | { |
| 5965 | u32 val; |
| 5966 | u32 save_len = len; |
| 5967 | int rc = 0; |
| 5968 | u32 errcnt; |
| 5969 | |
| 5970 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5971 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5972 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5973 | if (rc) |
| 5974 | return rc; |
| 5975 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5976 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5977 | |
| 5978 | errcnt = 0; |
| 5979 | for (; len > 0; len -= sizeof(u32), image++) { |
| 5980 | /* read data comes through single port, auto-incr addr */ |
| 5981 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5982 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5983 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5984 | if (val != le32_to_cpu(*image)) { |
| 5985 | IWL_ERROR("uCode INST section is invalid at " |
| 5986 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5987 | save_len - len, val, le32_to_cpu(*image)); |
| 5988 | rc = -EIO; |
| 5989 | errcnt++; |
| 5990 | if (errcnt >= 20) |
| 5991 | break; |
| 5992 | } |
| 5993 | } |
| 5994 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5995 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5996 | |
| 5997 | if (!errcnt) |
| 5998 | IWL_DEBUG_INFO |
| 5999 | ("ucode image in INSTRUCTION memory is good\n"); |
| 6000 | |
| 6001 | return rc; |
| 6002 | } |
| 6003 | |
| 6004 | |
| 6005 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6006 | * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6007 | * using sample data 100 bytes apart. If these sample points are good, |
| 6008 | * it's a pretty good bet that everything between them is good, too. |
| 6009 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6010 | 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] | 6011 | { |
| 6012 | u32 val; |
| 6013 | int rc = 0; |
| 6014 | u32 errcnt = 0; |
| 6015 | u32 i; |
| 6016 | |
| 6017 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 6018 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6019 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6020 | if (rc) |
| 6021 | return rc; |
| 6022 | |
| 6023 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 6024 | /* read data comes through single port, auto-incr addr */ |
| 6025 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 6026 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6027 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6028 | i + RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6029 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6030 | if (val != le32_to_cpu(*image)) { |
| 6031 | #if 0 /* Enable this if you want to see details */ |
| 6032 | IWL_ERROR("uCode INST section is invalid at " |
| 6033 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 6034 | i, val, *image); |
| 6035 | #endif |
| 6036 | rc = -EIO; |
| 6037 | errcnt++; |
| 6038 | if (errcnt >= 3) |
| 6039 | break; |
| 6040 | } |
| 6041 | } |
| 6042 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6043 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6044 | |
| 6045 | return rc; |
| 6046 | } |
| 6047 | |
| 6048 | |
| 6049 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6050 | * iwl4965_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6051 | * and verify its contents |
| 6052 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6053 | static int iwl4965_verify_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6054 | { |
| 6055 | __le32 *image; |
| 6056 | u32 len; |
| 6057 | int rc = 0; |
| 6058 | |
| 6059 | /* Try bootstrap */ |
| 6060 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 6061 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6062 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6063 | if (rc == 0) { |
| 6064 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 6065 | return 0; |
| 6066 | } |
| 6067 | |
| 6068 | /* Try initialize */ |
| 6069 | image = (__le32 *)priv->ucode_init.v_addr; |
| 6070 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6071 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6072 | if (rc == 0) { |
| 6073 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 6074 | return 0; |
| 6075 | } |
| 6076 | |
| 6077 | /* Try runtime/protocol */ |
| 6078 | image = (__le32 *)priv->ucode_code.v_addr; |
| 6079 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6080 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6081 | if (rc == 0) { |
| 6082 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 6083 | return 0; |
| 6084 | } |
| 6085 | |
| 6086 | IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
| 6087 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6088 | /* Since nothing seems to match, show first several data entries in |
| 6089 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 6090 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6091 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 6092 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6093 | rc = iwl4965_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6094 | |
| 6095 | return rc; |
| 6096 | } |
| 6097 | |
| 6098 | |
| 6099 | /* check contents of special bootstrap uCode SRAM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6100 | static int iwl4965_verify_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6101 | { |
| 6102 | __le32 *image = priv->ucode_boot.v_addr; |
| 6103 | u32 len = priv->ucode_boot.len; |
| 6104 | u32 reg; |
| 6105 | u32 val; |
| 6106 | |
| 6107 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 6108 | |
| 6109 | /* verify BSM SRAM contents */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6110 | val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6111 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 6112 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 6113 | reg += sizeof(u32), image ++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6114 | val = iwl4965_read_prph(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6115 | if (val != le32_to_cpu(*image)) { |
| 6116 | IWL_ERROR("BSM uCode verification failed at " |
| 6117 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 6118 | BSM_SRAM_LOWER_BOUND, |
| 6119 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 6120 | val, le32_to_cpu(*image)); |
| 6121 | return -EIO; |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 6126 | |
| 6127 | return 0; |
| 6128 | } |
| 6129 | |
| 6130 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6131 | * iwl4965_load_bsm - Load bootstrap instructions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6132 | * |
| 6133 | * BSM operation: |
| 6134 | * |
| 6135 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 6136 | * in special SRAM that does not power down during RFKILL. When powering back |
| 6137 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 6138 | * the bootstrap program into the on-board processor, and starts it. |
| 6139 | * |
| 6140 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 6141 | * program from host DRAM locations indicated by the host driver in the |
| 6142 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 6143 | * automatically. |
| 6144 | * |
| 6145 | * When initializing the NIC, the host driver points the BSM to the |
| 6146 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 6147 | * notifies host via "initialize alive" that it is complete. |
| 6148 | * |
| 6149 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 6150 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 6151 | * (filled initially with starting data values for the on-board processor), |
| 6152 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 6153 | * which begins normal operation. |
| 6154 | * |
| 6155 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 6156 | * the backup data cache in DRAM before SRAM is powered down. |
| 6157 | * |
| 6158 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 6159 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 6160 | * and re-launches the runtime uCode from where it left off. |
| 6161 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6162 | static int iwl4965_load_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6163 | { |
| 6164 | __le32 *image = priv->ucode_boot.v_addr; |
| 6165 | u32 len = priv->ucode_boot.len; |
| 6166 | dma_addr_t pinst; |
| 6167 | dma_addr_t pdata; |
| 6168 | u32 inst_len; |
| 6169 | u32 data_len; |
| 6170 | int rc; |
| 6171 | int i; |
| 6172 | u32 done; |
| 6173 | u32 reg_offset; |
| 6174 | |
| 6175 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 6176 | |
| 6177 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 6178 | if (len > IWL_MAX_BSM_SIZE) |
| 6179 | return -EINVAL; |
| 6180 | |
| 6181 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6182 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6183 | * NOTE: iwl4965_initialize_alive_start() will replace these values, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6184 | * after the "initialize" uCode has run, to point to |
| 6185 | * runtime/protocol instructions and backup data cache. */ |
| 6186 | pinst = priv->ucode_init.p_addr >> 4; |
| 6187 | pdata = priv->ucode_init_data.p_addr >> 4; |
| 6188 | inst_len = priv->ucode_init.len; |
| 6189 | data_len = priv->ucode_init_data.len; |
| 6190 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6191 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6192 | if (rc) |
| 6193 | return rc; |
| 6194 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6195 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6196 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6197 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 6198 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6199 | |
| 6200 | /* Fill BSM memory with bootstrap instructions */ |
| 6201 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 6202 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 6203 | reg_offset += sizeof(u32), image++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6204 | _iwl4965_write_prph(priv, reg_offset, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6205 | le32_to_cpu(*image)); |
| 6206 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6207 | rc = iwl4965_verify_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6208 | if (rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6209 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6210 | return rc; |
| 6211 | } |
| 6212 | |
| 6213 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6214 | iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 6215 | iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6216 | RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6217 | iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6218 | |
| 6219 | /* Load bootstrap code into instruction SRAM now, |
| 6220 | * to prepare to load "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6221 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6222 | BSM_WR_CTRL_REG_BIT_START); |
| 6223 | |
| 6224 | /* Wait for load of bootstrap uCode to finish */ |
| 6225 | for (i = 0; i < 100; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6226 | done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6227 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 6228 | break; |
| 6229 | udelay(10); |
| 6230 | } |
| 6231 | if (i < 100) |
| 6232 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 6233 | else { |
| 6234 | IWL_ERROR("BSM write did not complete!\n"); |
| 6235 | return -EIO; |
| 6236 | } |
| 6237 | |
| 6238 | /* Enable future boot loads whenever power management unit triggers it |
| 6239 | * (e.g. when powering back up after power-save shutdown) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6240 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6241 | BSM_WR_CTRL_REG_BIT_START_EN); |
| 6242 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6243 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6244 | |
| 6245 | return 0; |
| 6246 | } |
| 6247 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6248 | static void iwl4965_nic_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6249 | { |
| 6250 | /* Remove all resets to allow NIC to operate */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6251 | iwl4965_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6252 | } |
| 6253 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6254 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6255 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6256 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6257 | * |
| 6258 | * Copy into buffers for card to fetch via bus-mastering |
| 6259 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6260 | static int iwl4965_read_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6261 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6262 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6263 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6264 | const struct firmware *ucode_raw; |
| 6265 | const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode"; |
| 6266 | u8 *src; |
| 6267 | size_t len; |
| 6268 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 6269 | |
| 6270 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 6271 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6272 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 6273 | if (ret < 0) { |
| 6274 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 6275 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6276 | goto error; |
| 6277 | } |
| 6278 | |
| 6279 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 6280 | name, ucode_raw->size); |
| 6281 | |
| 6282 | /* Make sure that we got at least our header! */ |
| 6283 | if (ucode_raw->size < sizeof(*ucode)) { |
| 6284 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6285 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6286 | goto err_release; |
| 6287 | } |
| 6288 | |
| 6289 | /* Data from ucode file: header followed by uCode images */ |
| 6290 | ucode = (void *)ucode_raw->data; |
| 6291 | |
| 6292 | ver = le32_to_cpu(ucode->ver); |
| 6293 | inst_size = le32_to_cpu(ucode->inst_size); |
| 6294 | data_size = le32_to_cpu(ucode->data_size); |
| 6295 | init_size = le32_to_cpu(ucode->init_size); |
| 6296 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 6297 | boot_size = le32_to_cpu(ucode->boot_size); |
| 6298 | |
| 6299 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 6300 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 6301 | inst_size); |
| 6302 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 6303 | data_size); |
| 6304 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 6305 | init_size); |
| 6306 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 6307 | init_data_size); |
| 6308 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 6309 | boot_size); |
| 6310 | |
| 6311 | /* Verify size of file vs. image size info in file's header */ |
| 6312 | if (ucode_raw->size < sizeof(*ucode) + |
| 6313 | inst_size + data_size + init_size + |
| 6314 | init_data_size + boot_size) { |
| 6315 | |
| 6316 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 6317 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6318 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6319 | goto err_release; |
| 6320 | } |
| 6321 | |
| 6322 | /* Verify that uCode images will fit in card's SRAM */ |
| 6323 | if (inst_size > IWL_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6324 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 6325 | inst_size); |
| 6326 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6327 | goto err_release; |
| 6328 | } |
| 6329 | |
| 6330 | if (data_size > IWL_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6331 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 6332 | data_size); |
| 6333 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6334 | goto err_release; |
| 6335 | } |
| 6336 | if (init_size > IWL_MAX_INST_SIZE) { |
| 6337 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6338 | ("uCode init instr len %d too large to fit in\n", |
| 6339 | init_size); |
| 6340 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6341 | goto err_release; |
| 6342 | } |
| 6343 | if (init_data_size > IWL_MAX_DATA_SIZE) { |
| 6344 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6345 | ("uCode init data len %d too large to fit in\n", |
| 6346 | init_data_size); |
| 6347 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6348 | goto err_release; |
| 6349 | } |
| 6350 | if (boot_size > IWL_MAX_BSM_SIZE) { |
| 6351 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6352 | ("uCode boot instr len %d too large to fit in\n", |
| 6353 | boot_size); |
| 6354 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6355 | goto err_release; |
| 6356 | } |
| 6357 | |
| 6358 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 6359 | |
| 6360 | /* Runtime instructions and 2 copies of data: |
| 6361 | * 1) unmodified from disk |
| 6362 | * 2) backup cache for save/restore during power-downs */ |
| 6363 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6364 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6365 | |
| 6366 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6367 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6368 | |
| 6369 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6370 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6371 | |
| 6372 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6373 | if (init_size && init_data_size) { |
| 6374 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6375 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6376 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6377 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6378 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6379 | |
| 6380 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 6381 | goto err_pci_alloc; |
| 6382 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6383 | |
| 6384 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6385 | if (boot_size) { |
| 6386 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6387 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6388 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6389 | if (!priv->ucode_boot.v_addr) |
| 6390 | goto err_pci_alloc; |
| 6391 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6392 | |
| 6393 | /* Copy images into buffers for card's bus-master reads ... */ |
| 6394 | |
| 6395 | /* Runtime instructions (first block of data in file) */ |
| 6396 | src = &ucode->data[0]; |
| 6397 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6398 | 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] | 6399 | memcpy(priv->ucode_code.v_addr, src, len); |
| 6400 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 6401 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 6402 | |
| 6403 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6404 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6405 | src = &ucode->data[inst_size]; |
| 6406 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6407 | 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] | 6408 | memcpy(priv->ucode_data.v_addr, src, len); |
| 6409 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 6410 | |
| 6411 | /* Initialization instructions (3rd block) */ |
| 6412 | if (init_size) { |
| 6413 | src = &ucode->data[inst_size + data_size]; |
| 6414 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6415 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 6416 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6417 | memcpy(priv->ucode_init.v_addr, src, len); |
| 6418 | } |
| 6419 | |
| 6420 | /* Initialization data (4th block) */ |
| 6421 | if (init_data_size) { |
| 6422 | src = &ucode->data[inst_size + data_size + init_size]; |
| 6423 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6424 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 6425 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6426 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 6427 | } |
| 6428 | |
| 6429 | /* Bootstrap instructions (5th block) */ |
| 6430 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 6431 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6432 | 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] | 6433 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 6434 | |
| 6435 | /* We have our copies now, allow OS release its copies */ |
| 6436 | release_firmware(ucode_raw); |
| 6437 | return 0; |
| 6438 | |
| 6439 | err_pci_alloc: |
| 6440 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6441 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6442 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6443 | |
| 6444 | err_release: |
| 6445 | release_firmware(ucode_raw); |
| 6446 | |
| 6447 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6448 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6449 | } |
| 6450 | |
| 6451 | |
| 6452 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6453 | * iwl4965_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6454 | * |
| 6455 | * Tell initialization uCode where to find runtime uCode. |
| 6456 | * |
| 6457 | * BSM registers initially contain pointers to initialization uCode. |
| 6458 | * We need to replace them to load runtime uCode inst and data, |
| 6459 | * and to save runtime data when powering down. |
| 6460 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6461 | static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6462 | { |
| 6463 | dma_addr_t pinst; |
| 6464 | dma_addr_t pdata; |
| 6465 | int rc = 0; |
| 6466 | unsigned long flags; |
| 6467 | |
| 6468 | /* bits 35:4 for 4965 */ |
| 6469 | pinst = priv->ucode_code.p_addr >> 4; |
| 6470 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 6471 | |
| 6472 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6473 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6474 | if (rc) { |
| 6475 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6476 | return rc; |
| 6477 | } |
| 6478 | |
| 6479 | /* Tell bootstrap uCode where to find image to load */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6480 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6481 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6482 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6483 | priv->ucode_data.len); |
| 6484 | |
| 6485 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 6486 | * that all new ptr/size info is in place */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6487 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6488 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 6489 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6490 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6491 | |
| 6492 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6493 | |
| 6494 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 6495 | |
| 6496 | return rc; |
| 6497 | } |
| 6498 | |
| 6499 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6500 | * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6501 | * |
| 6502 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 6503 | * |
| 6504 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 6505 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 6506 | * (3945 does not contain this data). |
| 6507 | * |
| 6508 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 6509 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6510 | static void iwl4965_init_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6511 | { |
| 6512 | /* Check alive response for "valid" sign from uCode */ |
| 6513 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 6514 | /* We had an error bringing up the hardware, so take it |
| 6515 | * all the way back down so we can try again */ |
| 6516 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 6517 | goto restart; |
| 6518 | } |
| 6519 | |
| 6520 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 6521 | * This is a paranoid check, because we would not have gotten the |
| 6522 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6523 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6524 | /* Runtime instruction load was bad; |
| 6525 | * take it all the way back down so we can try again */ |
| 6526 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 6527 | goto restart; |
| 6528 | } |
| 6529 | |
| 6530 | /* Calculate temperature */ |
| 6531 | priv->temperature = iwl4965_get_temperature(priv); |
| 6532 | |
| 6533 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 6534 | * load and launch runtime uCode, which will send us another "Alive" |
| 6535 | * notification. */ |
| 6536 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6537 | if (iwl4965_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6538 | /* Runtime instruction load won't happen; |
| 6539 | * take it all the way back down so we can try again */ |
| 6540 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 6541 | goto restart; |
| 6542 | } |
| 6543 | return; |
| 6544 | |
| 6545 | restart: |
| 6546 | queue_work(priv->workqueue, &priv->restart); |
| 6547 | } |
| 6548 | |
| 6549 | |
| 6550 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6551 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6552 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6553 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6554 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6555 | static void iwl4965_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6556 | { |
| 6557 | int rc = 0; |
| 6558 | |
| 6559 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 6560 | |
| 6561 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 6562 | /* We had an error bringing up the hardware, so take it |
| 6563 | * all the way back down so we can try again */ |
| 6564 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 6565 | goto restart; |
| 6566 | } |
| 6567 | |
| 6568 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 6569 | * This is a paranoid check, because we would not have gotten the |
| 6570 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6571 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6572 | /* Runtime instruction load was bad; |
| 6573 | * take it all the way back down so we can try again */ |
| 6574 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 6575 | goto restart; |
| 6576 | } |
| 6577 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6578 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6579 | |
| 6580 | rc = iwl4965_alive_notify(priv); |
| 6581 | if (rc) { |
| 6582 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
| 6583 | rc); |
| 6584 | goto restart; |
| 6585 | } |
| 6586 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6587 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6588 | set_bit(STATUS_ALIVE, &priv->status); |
| 6589 | |
| 6590 | /* Clear out the uCode error bit if it is set */ |
| 6591 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 6592 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6593 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6594 | return; |
| 6595 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6596 | ieee80211_start_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6597 | |
| 6598 | priv->active_rate = priv->rates_mask; |
| 6599 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 6600 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6601 | iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6602 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6603 | if (iwl4965_is_associated(priv)) { |
| 6604 | struct iwl4965_rxon_cmd *active_rxon = |
| 6605 | (struct iwl4965_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6606 | |
| 6607 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 6608 | sizeof(priv->staging_rxon)); |
| 6609 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 6610 | } else { |
| 6611 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6612 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6613 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 6614 | } |
| 6615 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6616 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6617 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6618 | |
| 6619 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6620 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6621 | |
| 6622 | /* At this point, the NIC is initialized and operational */ |
| 6623 | priv->notif_missed_beacons = 0; |
| 6624 | set_bit(STATUS_READY, &priv->status); |
| 6625 | |
| 6626 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6627 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6628 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6629 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6630 | |
| 6631 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6632 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6633 | |
| 6634 | return; |
| 6635 | |
| 6636 | restart: |
| 6637 | queue_work(priv->workqueue, &priv->restart); |
| 6638 | } |
| 6639 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6640 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6641 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6642 | static void __iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6643 | { |
| 6644 | unsigned long flags; |
| 6645 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6646 | struct ieee80211_conf *conf = NULL; |
| 6647 | |
| 6648 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 6649 | |
| 6650 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6651 | |
| 6652 | if (!exit_pending) |
| 6653 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6654 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6655 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6656 | |
| 6657 | /* Unblock any waiting calls */ |
| 6658 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 6659 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6660 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 6661 | * exiting the module */ |
| 6662 | if (!exit_pending) |
| 6663 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6664 | |
| 6665 | /* stop and reset the on-board processor */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6666 | iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6667 | |
| 6668 | /* tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6669 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6670 | |
| 6671 | if (priv->mac80211_registered) |
| 6672 | ieee80211_stop_queues(priv->hw); |
| 6673 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6674 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6675 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6676 | if (!iwl4965_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6677 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6678 | STATUS_RF_KILL_HW | |
| 6679 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6680 | STATUS_RF_KILL_SW | |
| 6681 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6682 | STATUS_IN_SUSPEND; |
| 6683 | goto exit; |
| 6684 | } |
| 6685 | |
| 6686 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 6687 | * SUSPEND bits and continue taking the NIC down. */ |
| 6688 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6689 | STATUS_RF_KILL_HW | |
| 6690 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6691 | STATUS_RF_KILL_SW | |
| 6692 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6693 | STATUS_IN_SUSPEND | |
| 6694 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 6695 | STATUS_FW_ERROR; |
| 6696 | |
| 6697 | spin_lock_irqsave(&priv->lock, flags); |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6698 | iwl4965_clear_bit(priv, CSR_GP_CNTRL, |
| 6699 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6700 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6701 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6702 | iwl4965_hw_txq_ctx_stop(priv); |
| 6703 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6704 | |
| 6705 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6706 | if (!iwl4965_grab_nic_access(priv)) { |
| 6707 | iwl4965_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6708 | APMG_CLK_VAL_DMA_CLK_RQT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6709 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6710 | } |
| 6711 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6712 | |
| 6713 | udelay(5); |
| 6714 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6715 | iwl4965_hw_nic_stop_master(priv); |
| 6716 | iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
| 6717 | iwl4965_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6718 | |
| 6719 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6720 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6721 | |
| 6722 | if (priv->ibss_beacon) |
| 6723 | dev_kfree_skb(priv->ibss_beacon); |
| 6724 | priv->ibss_beacon = NULL; |
| 6725 | |
| 6726 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6727 | iwl4965_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6728 | } |
| 6729 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6730 | static void iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6731 | { |
| 6732 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6733 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6734 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6735 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6736 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6737 | } |
| 6738 | |
| 6739 | #define MAX_HW_RESTARTS 5 |
| 6740 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6741 | static int __iwl4965_up(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6742 | { |
| 6743 | int rc, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6744 | |
| 6745 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6746 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 6747 | return -EIO; |
| 6748 | } |
| 6749 | |
| 6750 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 6751 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 6752 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6753 | return -ENODEV; |
| 6754 | } |
| 6755 | |
| 6756 | /* If platform's RF_KILL switch is NOT set to KILL */ |
| 6757 | if (iwl4965_read32(priv, CSR_GP_CNTRL) & |
| 6758 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 6759 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6760 | else { |
| 6761 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6762 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
| 6763 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 6764 | return -ENODEV; |
| 6765 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
Reinette Chatre | a781cf9 | 2008-01-21 10:08:31 -0800 | [diff] [blame] | 6768 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 6769 | IWL_ERROR("ucode not available for device bringup\n"); |
| 6770 | return -EIO; |
| 6771 | } |
| 6772 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6773 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6774 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6775 | rc = iwl4965_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6776 | if (rc) { |
| 6777 | IWL_ERROR("Unable to int nic\n"); |
| 6778 | return rc; |
| 6779 | } |
| 6780 | |
| 6781 | /* make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6782 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6783 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6784 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 6785 | |
| 6786 | /* clear (again), then enable host interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6787 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 6788 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6789 | |
| 6790 | /* really make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6791 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6792 | 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] | 6793 | |
| 6794 | /* Copy original ucode data image from disk into backup cache. |
| 6795 | * This will be used to initialize the on-board processor's |
| 6796 | * data SRAM for a clean start when the runtime program first loads. */ |
| 6797 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6798 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6799 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6800 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 6801 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6802 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6803 | |
| 6804 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 6805 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6806 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6807 | |
| 6808 | /* load bootstrap state machine, |
| 6809 | * load bootstrap program into processor's memory, |
| 6810 | * prepare to load the "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6811 | rc = iwl4965_load_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6812 | |
| 6813 | if (rc) { |
| 6814 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); |
| 6815 | continue; |
| 6816 | } |
| 6817 | |
| 6818 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6819 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6820 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6821 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 6822 | |
| 6823 | return 0; |
| 6824 | } |
| 6825 | |
| 6826 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6827 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6828 | |
| 6829 | /* tried to restart and config the device for as long as our |
| 6830 | * patience could withstand */ |
| 6831 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 6832 | return -EIO; |
| 6833 | } |
| 6834 | |
| 6835 | |
| 6836 | /***************************************************************************** |
| 6837 | * |
| 6838 | * Workqueue callbacks |
| 6839 | * |
| 6840 | *****************************************************************************/ |
| 6841 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6842 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6843 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6844 | struct iwl4965_priv *priv = |
| 6845 | container_of(data, struct iwl4965_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6846 | |
| 6847 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6848 | return; |
| 6849 | |
| 6850 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6851 | iwl4965_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6852 | mutex_unlock(&priv->mutex); |
| 6853 | } |
| 6854 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6855 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6856 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6857 | struct iwl4965_priv *priv = |
| 6858 | container_of(data, struct iwl4965_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6859 | |
| 6860 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6861 | return; |
| 6862 | |
| 6863 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6864 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6865 | mutex_unlock(&priv->mutex); |
| 6866 | } |
| 6867 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6868 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6869 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6870 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6871 | |
| 6872 | wake_up_interruptible(&priv->wait_command_queue); |
| 6873 | |
| 6874 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6875 | return; |
| 6876 | |
| 6877 | mutex_lock(&priv->mutex); |
| 6878 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6879 | if (!iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6880 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 6881 | "HW and/or SW RF Kill no longer active, restarting " |
| 6882 | "device\n"); |
| 6883 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6884 | queue_work(priv->workqueue, &priv->restart); |
| 6885 | } else { |
| 6886 | |
| 6887 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 6888 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 6889 | "disabled by SW switch\n"); |
| 6890 | else |
| 6891 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 6892 | "Kill switch must be turned off for " |
| 6893 | "wireless networking to work.\n"); |
| 6894 | } |
| 6895 | mutex_unlock(&priv->mutex); |
| 6896 | } |
| 6897 | |
| 6898 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 6899 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6900 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6901 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6902 | struct iwl4965_priv *priv = |
| 6903 | container_of(data, struct iwl4965_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6904 | |
| 6905 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6906 | return; |
| 6907 | |
| 6908 | mutex_lock(&priv->mutex); |
| 6909 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 6910 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6911 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 6912 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 6913 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6914 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6915 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6916 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6917 | } |
| 6918 | mutex_unlock(&priv->mutex); |
| 6919 | } |
| 6920 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6921 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6922 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6923 | struct iwl4965_priv *priv = |
| 6924 | container_of(data, struct iwl4965_priv, request_scan); |
| 6925 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6926 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6927 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6928 | .meta.flags = CMD_SIZE_HUGE, |
| 6929 | }; |
| 6930 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6931 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6932 | struct ieee80211_conf *conf = NULL; |
| 6933 | u8 direct_mask; |
| 6934 | int phymode; |
| 6935 | |
| 6936 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6937 | |
| 6938 | mutex_lock(&priv->mutex); |
| 6939 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6940 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6941 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 6942 | goto done; |
| 6943 | } |
| 6944 | |
| 6945 | /* Make sure the scan wasn't cancelled before this queued work |
| 6946 | * was given the chance to run... */ |
| 6947 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 6948 | goto done; |
| 6949 | |
| 6950 | /* This should never be called or scheduled if there is currently |
| 6951 | * a scan active in the hardware. */ |
| 6952 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 6953 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 6954 | "Ignoring second request.\n"); |
| 6955 | rc = -EIO; |
| 6956 | goto done; |
| 6957 | } |
| 6958 | |
| 6959 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6960 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 6961 | goto done; |
| 6962 | } |
| 6963 | |
| 6964 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6965 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6966 | goto done; |
| 6967 | } |
| 6968 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6969 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6970 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6971 | goto done; |
| 6972 | } |
| 6973 | |
| 6974 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 6975 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 6976 | goto done; |
| 6977 | } |
| 6978 | |
| 6979 | if (!priv->scan_bands) { |
| 6980 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 6981 | goto done; |
| 6982 | } |
| 6983 | |
| 6984 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6985 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6986 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 6987 | if (!priv->scan) { |
| 6988 | rc = -ENOMEM; |
| 6989 | goto done; |
| 6990 | } |
| 6991 | } |
| 6992 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6993 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6994 | |
| 6995 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 6996 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 6997 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6998 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6999 | u16 interval = 0; |
| 7000 | u32 extra; |
| 7001 | u32 suspend_time = 100; |
| 7002 | u32 scan_suspend_time = 100; |
| 7003 | unsigned long flags; |
| 7004 | |
| 7005 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 7006 | |
| 7007 | spin_lock_irqsave(&priv->lock, flags); |
| 7008 | interval = priv->beacon_int; |
| 7009 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7010 | |
| 7011 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7012 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7013 | if (!interval) |
| 7014 | interval = suspend_time; |
| 7015 | |
| 7016 | extra = (suspend_time / interval) << 22; |
| 7017 | scan_suspend_time = (extra | |
| 7018 | ((suspend_time % interval) * 1024)); |
| 7019 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 7020 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 7021 | scan_suspend_time, interval); |
| 7022 | } |
| 7023 | |
| 7024 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 7025 | if (priv->one_direct_scan) { |
| 7026 | IWL_DEBUG_SCAN |
| 7027 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7028 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7029 | priv->direct_ssid_len)); |
| 7030 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 7031 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 7032 | memcpy(scan->direct_scan[0].ssid, |
| 7033 | priv->direct_ssid, priv->direct_ssid_len); |
| 7034 | direct_mask = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7035 | } else if (!iwl4965_is_associated(priv) && priv->essid_len) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7036 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 7037 | scan->direct_scan[0].len = priv->essid_len; |
| 7038 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 7039 | direct_mask = 1; |
| 7040 | } else |
| 7041 | direct_mask = 0; |
| 7042 | |
| 7043 | /* We don't build a direct scan probe request; the uCode will do |
| 7044 | * that based on the direct_mask added to each channel entry */ |
| 7045 | scan->tx_cmd.len = cpu_to_le16( |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7046 | iwl4965_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7047 | IWL_MAX_SCAN_SIZE - sizeof(scan), 0)); |
| 7048 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 7049 | scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; |
| 7050 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 7051 | |
| 7052 | /* flags + rate selection */ |
| 7053 | |
| 7054 | scan->tx_cmd.tx_flags |= cpu_to_le32(0x200); |
| 7055 | |
| 7056 | switch (priv->scan_bands) { |
| 7057 | case 2: |
| 7058 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 7059 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7060 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7061 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 7062 | |
| 7063 | scan->good_CRC_th = 0; |
| 7064 | phymode = MODE_IEEE80211G; |
| 7065 | break; |
| 7066 | |
| 7067 | case 1: |
| 7068 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7069 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7070 | RATE_MCS_ANT_B_MSK); |
| 7071 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
| 7072 | phymode = MODE_IEEE80211A; |
| 7073 | break; |
| 7074 | |
| 7075 | default: |
| 7076 | IWL_WARNING("Invalid scan band count\n"); |
| 7077 | goto done; |
| 7078 | } |
| 7079 | |
| 7080 | /* select Rx chains */ |
| 7081 | |
| 7082 | /* Force use of chains B and C (0x6) for scan Rx. |
| 7083 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 7084 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 7085 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 7086 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 7087 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 7088 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 7089 | |
| 7090 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 7091 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 7092 | |
| 7093 | if (direct_mask) |
| 7094 | IWL_DEBUG_SCAN |
| 7095 | ("Initiating direct scan for %s.\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7096 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7097 | else |
| 7098 | IWL_DEBUG_SCAN("Initiating indirect scan.\n"); |
| 7099 | |
| 7100 | scan->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7101 | iwl4965_get_channels_for_scan( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7102 | priv, phymode, 1, /* active */ |
| 7103 | direct_mask, |
| 7104 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
| 7105 | |
| 7106 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7107 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7108 | cmd.data = scan; |
| 7109 | scan->len = cpu_to_le16(cmd.len); |
| 7110 | |
| 7111 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7112 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7113 | if (rc) |
| 7114 | goto done; |
| 7115 | |
| 7116 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 7117 | IWL_SCAN_CHECK_WATCHDOG); |
| 7118 | |
| 7119 | mutex_unlock(&priv->mutex); |
| 7120 | return; |
| 7121 | |
| 7122 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 7123 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7124 | queue_work(priv->workqueue, &priv->scan_completed); |
| 7125 | mutex_unlock(&priv->mutex); |
| 7126 | } |
| 7127 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7128 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7129 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7130 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7131 | |
| 7132 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7133 | return; |
| 7134 | |
| 7135 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7136 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7137 | mutex_unlock(&priv->mutex); |
| 7138 | } |
| 7139 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7140 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7141 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7142 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7143 | |
| 7144 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7145 | return; |
| 7146 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7147 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7148 | queue_work(priv->workqueue, &priv->up); |
| 7149 | } |
| 7150 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7151 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7152 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7153 | struct iwl4965_priv *priv = |
| 7154 | container_of(data, struct iwl4965_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7155 | |
| 7156 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7157 | return; |
| 7158 | |
| 7159 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7160 | iwl4965_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7161 | mutex_unlock(&priv->mutex); |
| 7162 | } |
| 7163 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7164 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 7165 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7166 | static void iwl4965_bg_post_associate(struct work_struct *data) |
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 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7169 | post_associate.work); |
| 7170 | |
| 7171 | int rc = 0; |
| 7172 | struct ieee80211_conf *conf = NULL; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7173 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7174 | |
| 7175 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7176 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 7177 | return; |
| 7178 | } |
| 7179 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7180 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 7181 | priv->assoc_id, |
| 7182 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7183 | |
| 7184 | |
| 7185 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7186 | return; |
| 7187 | |
| 7188 | mutex_lock(&priv->mutex); |
| 7189 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7190 | if (!priv->vif || !priv->is_open) { |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7191 | mutex_unlock(&priv->mutex); |
| 7192 | return; |
| 7193 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7194 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7195 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7196 | conf = ieee80211_get_hw_conf(priv->hw); |
| 7197 | |
| 7198 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7199 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7200 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7201 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7202 | iwl4965_setup_rxon_timing(priv); |
| 7203 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7204 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7205 | if (rc) |
| 7206 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7207 | "Attempting to continue.\n"); |
| 7208 | |
| 7209 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 7210 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7211 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7212 | if (priv->current_ht_config.is_ht) |
| 7213 | iwl4965_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7214 | #endif /* CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7215 | iwl4965_set_rxon_chain(priv); |
| 7216 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7217 | |
| 7218 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 7219 | priv->assoc_id, priv->beacon_int); |
| 7220 | |
| 7221 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7222 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7223 | else |
| 7224 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7225 | |
| 7226 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7227 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7228 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 7229 | else |
| 7230 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7231 | |
| 7232 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7233 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7234 | |
| 7235 | } |
| 7236 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7237 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7238 | |
| 7239 | switch (priv->iw_mode) { |
| 7240 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7241 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7242 | break; |
| 7243 | |
| 7244 | case IEEE80211_IF_TYPE_IBSS: |
| 7245 | |
| 7246 | /* clear out the station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7247 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7248 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7249 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
| 7250 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 7251 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 7252 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7253 | |
| 7254 | break; |
| 7255 | |
| 7256 | default: |
| 7257 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 7258 | __FUNCTION__, priv->iw_mode); |
| 7259 | break; |
| 7260 | } |
| 7261 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7262 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7263 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7264 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7265 | /* Enable Rx differential gain and sensitivity calibrations */ |
| 7266 | iwl4965_chain_noise_reset(priv); |
| 7267 | priv->start_calib = 1; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7268 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7269 | |
| 7270 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7271 | priv->assoc_station_added = 1; |
| 7272 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7273 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7274 | iwl4965_activate_qos(priv, 0); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7275 | #endif /* CONFIG_IWL4965_QOS */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7276 | /* we have just associated, don't start scan too early */ |
| 7277 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7278 | mutex_unlock(&priv->mutex); |
| 7279 | } |
| 7280 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7281 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7282 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7283 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7284 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7285 | if (!iwl4965_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7286 | return; |
| 7287 | |
| 7288 | mutex_lock(&priv->mutex); |
| 7289 | |
| 7290 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7291 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7292 | |
| 7293 | mutex_unlock(&priv->mutex); |
| 7294 | } |
| 7295 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7296 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 7297 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7298 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7299 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7300 | struct iwl4965_priv *priv = |
| 7301 | container_of(work, struct iwl4965_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7302 | |
| 7303 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 7304 | |
| 7305 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7306 | return; |
| 7307 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7308 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 7309 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7310 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7311 | ieee80211_scan_completed(priv->hw); |
| 7312 | |
| 7313 | /* Since setting the TXPOWER may have been deferred while |
| 7314 | * performing the scan, fire one off */ |
| 7315 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7316 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7317 | mutex_unlock(&priv->mutex); |
| 7318 | } |
| 7319 | |
| 7320 | /***************************************************************************** |
| 7321 | * |
| 7322 | * mac80211 entry point functions |
| 7323 | * |
| 7324 | *****************************************************************************/ |
| 7325 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7326 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 7327 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7328 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7329 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7330 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7331 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7332 | |
| 7333 | IWL_DEBUG_MAC80211("enter\n"); |
| 7334 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7335 | if (pci_enable_device(priv->pci_dev)) { |
| 7336 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 7337 | return -ENODEV; |
| 7338 | } |
| 7339 | pci_restore_state(priv->pci_dev); |
| 7340 | pci_enable_msi(priv->pci_dev); |
| 7341 | |
| 7342 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 7343 | DRV_NAME, priv); |
| 7344 | if (ret) { |
| 7345 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 7346 | goto out_disable_msi; |
| 7347 | } |
| 7348 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7349 | /* we should be verifying the device is ready to be opened */ |
| 7350 | mutex_lock(&priv->mutex); |
| 7351 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7352 | memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd)); |
| 7353 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 7354 | * ucode filename and max sizes are card-specific. */ |
| 7355 | |
| 7356 | if (!priv->ucode_code.len) { |
| 7357 | ret = iwl4965_read_ucode(priv); |
| 7358 | if (ret) { |
| 7359 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 7360 | mutex_unlock(&priv->mutex); |
| 7361 | goto out_release_irq; |
| 7362 | } |
| 7363 | } |
| 7364 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7365 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7366 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7367 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7368 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7369 | if (ret) |
| 7370 | goto out_release_irq; |
| 7371 | |
| 7372 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 7373 | |
| 7374 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 7375 | return 0; |
| 7376 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7377 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 7378 | * mac80211 will not be run successfully. */ |
| 7379 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 7380 | test_bit(STATUS_READY, &priv->status), |
| 7381 | UCODE_READY_TIMEOUT); |
| 7382 | if (!ret) { |
| 7383 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 7384 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 7385 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 7386 | ret = -ETIMEDOUT; |
| 7387 | goto out_release_irq; |
| 7388 | } |
| 7389 | } |
| 7390 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7391 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7392 | IWL_DEBUG_MAC80211("leave\n"); |
| 7393 | return 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7394 | |
| 7395 | out_release_irq: |
| 7396 | free_irq(priv->pci_dev->irq, priv); |
| 7397 | out_disable_msi: |
| 7398 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7399 | pci_disable_device(priv->pci_dev); |
| 7400 | priv->is_open = 0; |
| 7401 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7402 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7403 | } |
| 7404 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7405 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7406 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7407 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7408 | |
| 7409 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7410 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7411 | if (!priv->is_open) { |
| 7412 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 7413 | return; |
| 7414 | } |
| 7415 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7416 | priv->is_open = 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7417 | |
| 7418 | if (iwl4965_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7419 | /* stop mac, cancel any scan request and clear |
| 7420 | * RXON_FILTER_ASSOC_MSK BIT |
| 7421 | */ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7422 | mutex_lock(&priv->mutex); |
| 7423 | iwl4965_scan_cancel_timeout(priv, 100); |
| 7424 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7425 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7426 | } |
| 7427 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7428 | iwl4965_down(priv); |
| 7429 | |
| 7430 | flush_workqueue(priv->workqueue); |
| 7431 | free_irq(priv->pci_dev->irq, priv); |
| 7432 | pci_disable_msi(priv->pci_dev); |
| 7433 | pci_save_state(priv->pci_dev); |
| 7434 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7435 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7436 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7437 | } |
| 7438 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7439 | 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] | 7440 | struct ieee80211_tx_control *ctl) |
| 7441 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7442 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7443 | |
| 7444 | IWL_DEBUG_MAC80211("enter\n"); |
| 7445 | |
| 7446 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 7447 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 7448 | return -1; |
| 7449 | } |
| 7450 | |
| 7451 | IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
| 7452 | ctl->tx_rate); |
| 7453 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7454 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7455 | dev_kfree_skb_any(skb); |
| 7456 | |
| 7457 | IWL_DEBUG_MAC80211("leave\n"); |
| 7458 | return 0; |
| 7459 | } |
| 7460 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7461 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7462 | struct ieee80211_if_init_conf *conf) |
| 7463 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7464 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7465 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7466 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7467 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7468 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7469 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7470 | if (priv->vif) { |
| 7471 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 7472 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7473 | } |
| 7474 | |
| 7475 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7476 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7477 | |
| 7478 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7479 | |
| 7480 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 7481 | |
| 7482 | if (conf->mac_addr) { |
| 7483 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 7484 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 7485 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7486 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7487 | if (iwl4965_is_ready(priv)) |
| 7488 | iwl4965_set_mode(priv, conf->type); |
| 7489 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7490 | mutex_unlock(&priv->mutex); |
| 7491 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7492 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7493 | return 0; |
| 7494 | } |
| 7495 | |
| 7496 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7497 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7498 | * |
| 7499 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 7500 | * be set inappropriately and the driver currently sets the hardware up to |
| 7501 | * use it whenever needed. |
| 7502 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7503 | 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] | 7504 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7505 | struct iwl4965_priv *priv = hw->priv; |
| 7506 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7507 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7508 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7509 | |
| 7510 | mutex_lock(&priv->mutex); |
| 7511 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel); |
| 7512 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 7513 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 7514 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7515 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7516 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7517 | ret = -EIO; |
| 7518 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7519 | } |
| 7520 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7521 | if (unlikely(!iwl4965_param_disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7522 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7523 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7524 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7525 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7526 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7527 | } |
| 7528 | |
| 7529 | spin_lock_irqsave(&priv->lock, flags); |
| 7530 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7531 | ch_info = iwl4965_get_channel_info(priv, conf->phymode, conf->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7532 | if (!is_channel_valid(ch_info)) { |
| 7533 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n", |
| 7534 | conf->channel, conf->phymode); |
| 7535 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 7536 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7537 | ret = -EINVAL; |
| 7538 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7539 | } |
| 7540 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7541 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7542 | /* if we are switching fron ht to 2.4 clear flags |
| 7543 | * from any ht related info since 2.4 does not |
| 7544 | * support ht */ |
| 7545 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel) |
| 7546 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7547 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 7548 | #endif |
| 7549 | ) |
| 7550 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7551 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7552 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7553 | iwl4965_set_rxon_channel(priv, conf->phymode, conf->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7554 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7555 | iwl4965_set_flags_for_phymode(priv, conf->phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7556 | |
| 7557 | /* The list of supported rates and rate mask can be different |
| 7558 | * for each phymode; since the phymode may have changed, reset |
| 7559 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7560 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7561 | |
| 7562 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7563 | |
| 7564 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7565 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7566 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7567 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7568 | } |
| 7569 | #endif |
| 7570 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7571 | iwl4965_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7572 | |
| 7573 | if (!conf->radio_enabled) { |
| 7574 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7575 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7576 | } |
| 7577 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7578 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7579 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7580 | ret = -EIO; |
| 7581 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7582 | } |
| 7583 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7584 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7585 | |
| 7586 | if (memcmp(&priv->active_rxon, |
| 7587 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7588 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7589 | else |
| 7590 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 7591 | |
| 7592 | IWL_DEBUG_MAC80211("leave\n"); |
| 7593 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7594 | out: |
| 7595 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7596 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7597 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7598 | } |
| 7599 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7600 | static void iwl4965_config_ap(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7601 | { |
| 7602 | int rc = 0; |
| 7603 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 7604 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7605 | return; |
| 7606 | |
| 7607 | /* The following should be done only at AP bring up */ |
| 7608 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 7609 | |
| 7610 | /* RXON - unassoc (to set timing command) */ |
| 7611 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7612 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7613 | |
| 7614 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7615 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7616 | iwl4965_setup_rxon_timing(priv); |
| 7617 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7618 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7619 | if (rc) |
| 7620 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7621 | "Attempting to continue.\n"); |
| 7622 | |
| 7623 | iwl4965_set_rxon_chain(priv); |
| 7624 | |
| 7625 | /* FIXME: what should be the assoc_id for AP? */ |
| 7626 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7627 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7628 | priv->staging_rxon.flags |= |
| 7629 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7630 | else |
| 7631 | priv->staging_rxon.flags &= |
| 7632 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7633 | |
| 7634 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7635 | if (priv->assoc_capability & |
| 7636 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7637 | priv->staging_rxon.flags |= |
| 7638 | RXON_FLG_SHORT_SLOT_MSK; |
| 7639 | else |
| 7640 | priv->staging_rxon.flags &= |
| 7641 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7642 | |
| 7643 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7644 | priv->staging_rxon.flags &= |
| 7645 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7646 | } |
| 7647 | /* restore RXON assoc */ |
| 7648 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7649 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7650 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7651 | iwl4965_activate_qos(priv, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7652 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7653 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 7654 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7655 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7656 | |
| 7657 | /* FIXME - we need to add code here to detect a totally new |
| 7658 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 7659 | * clear sta table, add BCAST sta... */ |
| 7660 | } |
| 7661 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7662 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 7663 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7664 | struct ieee80211_if_conf *conf) |
| 7665 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7666 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7667 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7668 | unsigned long flags; |
| 7669 | int rc; |
| 7670 | |
| 7671 | if (conf == NULL) |
| 7672 | return -EIO; |
| 7673 | |
| 7674 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 7675 | (!conf->beacon || !conf->ssid_len)) { |
| 7676 | IWL_DEBUG_MAC80211 |
| 7677 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 7678 | return 0; |
| 7679 | } |
| 7680 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7681 | if (!iwl4965_is_alive(priv)) |
| 7682 | return -EAGAIN; |
| 7683 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7684 | mutex_lock(&priv->mutex); |
| 7685 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7686 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7687 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 7688 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7689 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7690 | /* |
| 7691 | * very dubious code was here; the probe filtering flag is never set: |
| 7692 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7693 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 7694 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7695 | */ |
| 7696 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7697 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7698 | mutex_unlock(&priv->mutex); |
| 7699 | return 0; |
| 7700 | } |
| 7701 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7702 | if (priv->vif != vif) { |
| 7703 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7704 | mutex_unlock(&priv->mutex); |
| 7705 | return 0; |
| 7706 | } |
| 7707 | |
| 7708 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7709 | if (!conf->bssid) { |
| 7710 | conf->bssid = priv->mac_addr; |
| 7711 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7712 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 7713 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7714 | } |
| 7715 | if (priv->ibss_beacon) |
| 7716 | dev_kfree_skb(priv->ibss_beacon); |
| 7717 | |
| 7718 | priv->ibss_beacon = conf->beacon; |
| 7719 | } |
| 7720 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7721 | if (iwl4965_is_rfkill(priv)) |
| 7722 | goto done; |
| 7723 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7724 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 7725 | !is_multicast_ether_addr(conf->bssid)) { |
| 7726 | /* If there is currently a HW scan going on in the background |
| 7727 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7728 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7729 | IWL_WARNING("Aborted scan still in progress " |
| 7730 | "after 100ms\n"); |
| 7731 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 7732 | mutex_unlock(&priv->mutex); |
| 7733 | return -EAGAIN; |
| 7734 | } |
| 7735 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 7736 | |
| 7737 | /* TODO: Audit driver for usage of these members and see |
| 7738 | * if mac80211 deprecates them (priv->bssid looks like it |
| 7739 | * shouldn't be there, but I haven't scanned the IBSS code |
| 7740 | * to verify) - jpk */ |
| 7741 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 7742 | |
| 7743 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7744 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7745 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7746 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7747 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7748 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7749 | priv, priv->active_rxon.bssid_addr, 1); |
| 7750 | } |
| 7751 | |
| 7752 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7753 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7754 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7755 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7756 | } |
| 7757 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7758 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7759 | spin_lock_irqsave(&priv->lock, flags); |
| 7760 | if (!conf->ssid_len) |
| 7761 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7762 | else |
| 7763 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 7764 | |
| 7765 | priv->essid_len = conf->ssid_len; |
| 7766 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7767 | |
| 7768 | IWL_DEBUG_MAC80211("leave\n"); |
| 7769 | mutex_unlock(&priv->mutex); |
| 7770 | |
| 7771 | return 0; |
| 7772 | } |
| 7773 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7774 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7775 | unsigned int changed_flags, |
| 7776 | unsigned int *total_flags, |
| 7777 | int mc_count, struct dev_addr_list *mc_list) |
| 7778 | { |
| 7779 | /* |
| 7780 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7781 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7782 | */ |
| 7783 | *total_flags = 0; |
| 7784 | } |
| 7785 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7786 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7787 | struct ieee80211_if_init_conf *conf) |
| 7788 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7789 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7790 | |
| 7791 | IWL_DEBUG_MAC80211("enter\n"); |
| 7792 | |
| 7793 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7794 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7795 | if (iwl4965_is_ready_rf(priv)) { |
| 7796 | iwl4965_scan_cancel_timeout(priv, 100); |
| 7797 | cancel_delayed_work(&priv->post_associate); |
| 7798 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 7799 | iwl4965_commit_rxon(priv); |
| 7800 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7801 | if (priv->vif == conf->vif) { |
| 7802 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7803 | memset(priv->bssid, 0, ETH_ALEN); |
| 7804 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7805 | priv->essid_len = 0; |
| 7806 | } |
| 7807 | mutex_unlock(&priv->mutex); |
| 7808 | |
| 7809 | IWL_DEBUG_MAC80211("leave\n"); |
| 7810 | |
| 7811 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7812 | |
| 7813 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 7814 | struct ieee80211_vif *vif, |
| 7815 | struct ieee80211_bss_conf *bss_conf, |
| 7816 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7817 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7818 | struct iwl4965_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7819 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7820 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 7821 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7822 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7823 | else |
| 7824 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7825 | } |
| 7826 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7827 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
| 7828 | if (bss_conf->use_cts_prot && (priv->phymode != MODE_IEEE80211A)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7829 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 7830 | else |
| 7831 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 7832 | } |
| 7833 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7834 | if (changes & BSS_CHANGED_ASSOC) { |
| 7835 | /* |
| 7836 | * TODO: |
| 7837 | * do stuff instead of sniffing assoc resp |
| 7838 | */ |
| 7839 | } |
| 7840 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7841 | if (iwl4965_is_associated(priv)) |
| 7842 | iwl4965_send_rxon_assoc(priv); |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7843 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7844 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7845 | 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] | 7846 | { |
| 7847 | int rc = 0; |
| 7848 | unsigned long flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7849 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7850 | |
| 7851 | IWL_DEBUG_MAC80211("enter\n"); |
| 7852 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7853 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7854 | spin_lock_irqsave(&priv->lock, flags); |
| 7855 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7856 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7857 | rc = -EIO; |
| 7858 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 7859 | goto out_unlock; |
| 7860 | } |
| 7861 | |
| 7862 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 7863 | rc = -EIO; |
| 7864 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 7865 | goto out_unlock; |
| 7866 | } |
| 7867 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7868 | /* we don't schedule scan within next_scan_jiffies period */ |
| 7869 | if (priv->next_scan_jiffies && |
| 7870 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 7871 | rc = -EAGAIN; |
| 7872 | goto out_unlock; |
| 7873 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7874 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7875 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 7876 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7877 | rc = -EAGAIN; |
| 7878 | goto out_unlock; |
| 7879 | } |
| 7880 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7881 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7882 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7883 | |
| 7884 | priv->one_direct_scan = 1; |
| 7885 | priv->direct_ssid_len = (u8) |
| 7886 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 7887 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7888 | } else |
| 7889 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7890 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7891 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7892 | |
| 7893 | IWL_DEBUG_MAC80211("leave\n"); |
| 7894 | |
| 7895 | out_unlock: |
| 7896 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7897 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7898 | |
| 7899 | return rc; |
| 7900 | } |
| 7901 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7902 | 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] | 7903 | const u8 *local_addr, const u8 *addr, |
| 7904 | struct ieee80211_key_conf *key) |
| 7905 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7906 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7907 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7908 | int rc = 0; |
| 7909 | u8 sta_id; |
| 7910 | |
| 7911 | IWL_DEBUG_MAC80211("enter\n"); |
| 7912 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7913 | if (!iwl4965_param_hwcrypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7914 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 7915 | return -EOPNOTSUPP; |
| 7916 | } |
| 7917 | |
| 7918 | if (is_zero_ether_addr(addr)) |
| 7919 | /* only support pairwise keys */ |
| 7920 | return -EOPNOTSUPP; |
| 7921 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7922 | sta_id = iwl4965_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7923 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7924 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 7925 | print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7926 | return -EINVAL; |
| 7927 | } |
| 7928 | |
| 7929 | mutex_lock(&priv->mutex); |
| 7930 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7931 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7932 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7933 | switch (cmd) { |
| 7934 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7935 | rc = iwl4965_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7936 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7937 | iwl4965_set_rxon_hwcrypto(priv, 1); |
| 7938 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7939 | key->hw_key_idx = sta_id; |
| 7940 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 7941 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 7942 | } |
| 7943 | break; |
| 7944 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7945 | rc = iwl4965_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7946 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7947 | iwl4965_set_rxon_hwcrypto(priv, 0); |
| 7948 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7949 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 7950 | } |
| 7951 | break; |
| 7952 | default: |
| 7953 | rc = -EINVAL; |
| 7954 | } |
| 7955 | |
| 7956 | IWL_DEBUG_MAC80211("leave\n"); |
| 7957 | mutex_unlock(&priv->mutex); |
| 7958 | |
| 7959 | return rc; |
| 7960 | } |
| 7961 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7962 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7963 | const struct ieee80211_tx_queue_params *params) |
| 7964 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7965 | struct iwl4965_priv *priv = hw->priv; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7966 | #ifdef CONFIG_IWL4965_QOS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7967 | unsigned long flags; |
| 7968 | int q; |
Reinette Chatre | 0054b34 | 2007-11-29 11:09:42 +0800 | [diff] [blame] | 7969 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7970 | |
| 7971 | IWL_DEBUG_MAC80211("enter\n"); |
| 7972 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7973 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7974 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7975 | return -EIO; |
| 7976 | } |
| 7977 | |
| 7978 | if (queue >= AC_NUM) { |
| 7979 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 7980 | return 0; |
| 7981 | } |
| 7982 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7983 | #ifdef CONFIG_IWL4965_QOS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7984 | if (!priv->qos_data.qos_enable) { |
| 7985 | priv->qos_data.qos_active = 0; |
| 7986 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 7987 | return 0; |
| 7988 | } |
| 7989 | q = AC_NUM - 1 - queue; |
| 7990 | |
| 7991 | spin_lock_irqsave(&priv->lock, flags); |
| 7992 | |
| 7993 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 7994 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 7995 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 7996 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
| 7997 | cpu_to_le16((params->burst_time * 100)); |
| 7998 | |
| 7999 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 8000 | priv->qos_data.qos_active = 1; |
| 8001 | |
| 8002 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8003 | |
| 8004 | mutex_lock(&priv->mutex); |
| 8005 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8006 | iwl4965_activate_qos(priv, 1); |
| 8007 | else if (priv->assoc_id && iwl4965_is_associated(priv)) |
| 8008 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8009 | |
| 8010 | mutex_unlock(&priv->mutex); |
| 8011 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8012 | #endif /*CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8013 | |
| 8014 | IWL_DEBUG_MAC80211("leave\n"); |
| 8015 | return 0; |
| 8016 | } |
| 8017 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8018 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8019 | struct ieee80211_tx_queue_stats *stats) |
| 8020 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8021 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8022 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8023 | struct iwl4965_tx_queue *txq; |
| 8024 | struct iwl4965_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8025 | unsigned long flags; |
| 8026 | |
| 8027 | IWL_DEBUG_MAC80211("enter\n"); |
| 8028 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8029 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8030 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 8031 | return -EIO; |
| 8032 | } |
| 8033 | |
| 8034 | spin_lock_irqsave(&priv->lock, flags); |
| 8035 | |
| 8036 | for (i = 0; i < AC_NUM; i++) { |
| 8037 | txq = &priv->txq[i]; |
| 8038 | q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8039 | avail = iwl4965_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8040 | |
| 8041 | stats->data[i].len = q->n_window - avail; |
| 8042 | stats->data[i].limit = q->n_window - q->high_mark; |
| 8043 | stats->data[i].count = q->n_window; |
| 8044 | |
| 8045 | } |
| 8046 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8047 | |
| 8048 | IWL_DEBUG_MAC80211("leave\n"); |
| 8049 | |
| 8050 | return 0; |
| 8051 | } |
| 8052 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8053 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8054 | struct ieee80211_low_level_stats *stats) |
| 8055 | { |
| 8056 | IWL_DEBUG_MAC80211("enter\n"); |
| 8057 | IWL_DEBUG_MAC80211("leave\n"); |
| 8058 | |
| 8059 | return 0; |
| 8060 | } |
| 8061 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8062 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8063 | { |
| 8064 | IWL_DEBUG_MAC80211("enter\n"); |
| 8065 | IWL_DEBUG_MAC80211("leave\n"); |
| 8066 | |
| 8067 | return 0; |
| 8068 | } |
| 8069 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8070 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8071 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8072 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8073 | unsigned long flags; |
| 8074 | |
| 8075 | mutex_lock(&priv->mutex); |
| 8076 | IWL_DEBUG_MAC80211("enter\n"); |
| 8077 | |
| 8078 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8079 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8080 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8081 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8082 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8083 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8084 | /* if (priv->lq_mngr.agg_ctrl.granted_ba) |
| 8085 | iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);*/ |
| 8086 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8087 | memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl4965_agg_control)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8088 | priv->lq_mngr.agg_ctrl.tid_traffic_load_threshold = 10; |
| 8089 | priv->lq_mngr.agg_ctrl.ba_timeout = 5000; |
| 8090 | priv->lq_mngr.agg_ctrl.auto_agg = 1; |
| 8091 | |
| 8092 | if (priv->lq_mngr.agg_ctrl.auto_agg) |
| 8093 | priv->lq_mngr.agg_ctrl.requested_ba = TID_ALL_ENABLED; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8094 | #endif /*CONFIG_IWL4965_HT_AGG */ |
| 8095 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8096 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8097 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8098 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8099 | #endif |
| 8100 | |
| 8101 | cancel_delayed_work(&priv->post_associate); |
| 8102 | |
| 8103 | spin_lock_irqsave(&priv->lock, flags); |
| 8104 | priv->assoc_id = 0; |
| 8105 | priv->assoc_capability = 0; |
| 8106 | priv->call_post_assoc_from_beacon = 0; |
| 8107 | priv->assoc_station_added = 0; |
| 8108 | |
| 8109 | /* new association get rid of ibss beacon skb */ |
| 8110 | if (priv->ibss_beacon) |
| 8111 | dev_kfree_skb(priv->ibss_beacon); |
| 8112 | |
| 8113 | priv->ibss_beacon = NULL; |
| 8114 | |
| 8115 | priv->beacon_int = priv->hw->conf.beacon_int; |
| 8116 | priv->timestamp1 = 0; |
| 8117 | priv->timestamp0 = 0; |
| 8118 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 8119 | priv->beacon_int = 0; |
| 8120 | |
| 8121 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8122 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 8123 | if (!iwl4965_is_ready_rf(priv)) { |
| 8124 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 8125 | mutex_unlock(&priv->mutex); |
| 8126 | return; |
| 8127 | } |
| 8128 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8129 | /* we are restarting association process |
| 8130 | * clear RXON_FILTER_ASSOC_MSK bit |
| 8131 | */ |
| 8132 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8133 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8134 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8135 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8136 | } |
| 8137 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8138 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 8139 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8140 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8141 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 8142 | mutex_unlock(&priv->mutex); |
| 8143 | return; |
| 8144 | } |
| 8145 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8146 | priv->only_active_channel = 0; |
| 8147 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8148 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8149 | |
| 8150 | mutex_unlock(&priv->mutex); |
| 8151 | |
| 8152 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8153 | } |
| 8154 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8155 | 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] | 8156 | struct ieee80211_tx_control *control) |
| 8157 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8158 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8159 | unsigned long flags; |
| 8160 | |
| 8161 | mutex_lock(&priv->mutex); |
| 8162 | IWL_DEBUG_MAC80211("enter\n"); |
| 8163 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8164 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8165 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 8166 | mutex_unlock(&priv->mutex); |
| 8167 | return -EIO; |
| 8168 | } |
| 8169 | |
| 8170 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 8171 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 8172 | mutex_unlock(&priv->mutex); |
| 8173 | return -EIO; |
| 8174 | } |
| 8175 | |
| 8176 | spin_lock_irqsave(&priv->lock, flags); |
| 8177 | |
| 8178 | if (priv->ibss_beacon) |
| 8179 | dev_kfree_skb(priv->ibss_beacon); |
| 8180 | |
| 8181 | priv->ibss_beacon = skb; |
| 8182 | |
| 8183 | priv->assoc_id = 0; |
| 8184 | |
| 8185 | IWL_DEBUG_MAC80211("leave\n"); |
| 8186 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8187 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8188 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8189 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8190 | #endif |
| 8191 | |
| 8192 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 8193 | |
| 8194 | mutex_unlock(&priv->mutex); |
| 8195 | |
| 8196 | return 0; |
| 8197 | } |
| 8198 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8199 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8200 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8201 | static void iwl4965_ht_info_fill(struct ieee80211_conf *conf, |
| 8202 | struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8203 | { |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8204 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 8205 | struct ieee80211_ht_info *ht_conf = &conf->ht_conf; |
| 8206 | struct ieee80211_ht_bss_info *ht_bss_conf = &conf->ht_bss_conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8207 | |
| 8208 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8209 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8210 | if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) { |
| 8211 | iwl_conf->is_ht = 0; |
| 8212 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8213 | } |
| 8214 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8215 | iwl_conf->is_ht = 1; |
| 8216 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8217 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8218 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
| 8219 | iwl_conf->sgf |= 0x1; |
| 8220 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
| 8221 | iwl_conf->sgf |= 0x2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8222 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8223 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 8224 | iwl_conf->max_amsdu_size = |
| 8225 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 8226 | iwl_conf->supported_chan_width = |
| 8227 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 8228 | iwl_conf->tx_mimo_ps_mode = |
| 8229 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 8230 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8231 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8232 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 8233 | iwl_conf->extension_chan_offset = |
| 8234 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 8235 | iwl_conf->tx_chan_width = |
| 8236 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 8237 | iwl_conf->ht_protection = |
| 8238 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 8239 | iwl_conf->non_GF_STA_present = |
| 8240 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8241 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8242 | IWL_DEBUG_MAC80211("control channel %d\n", |
| 8243 | iwl_conf->control_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8244 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8245 | } |
| 8246 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8247 | static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw, |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8248 | struct ieee80211_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8249 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8250 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8251 | |
| 8252 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8253 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8254 | iwl4965_ht_info_fill(conf, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8255 | iwl4965_set_rxon_chain(priv); |
| 8256 | |
| 8257 | if (priv && priv->assoc_id && |
| 8258 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
| 8259 | unsigned long flags; |
| 8260 | |
| 8261 | spin_lock_irqsave(&priv->lock, flags); |
| 8262 | if (priv->beacon_int) |
| 8263 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 8264 | else |
| 8265 | priv->call_post_assoc_from_beacon = 1; |
| 8266 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8267 | } |
| 8268 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8269 | IWL_DEBUG_MAC80211("leave:\n"); |
| 8270 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8271 | } |
| 8272 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8273 | static void iwl4965_set_ht_capab(struct ieee80211_hw *hw, |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 8274 | struct ieee80211_ht_cap *ht_cap, |
| 8275 | u8 use_current_config) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8276 | { |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 8277 | struct ieee80211_conf *conf = &hw->conf; |
| 8278 | struct ieee80211_hw_mode *mode = conf->mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8279 | |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 8280 | if (use_current_config) { |
| 8281 | ht_cap->cap_info = cpu_to_le16(conf->ht_conf.cap); |
| 8282 | memcpy(ht_cap->supp_mcs_set, |
| 8283 | conf->ht_conf.supp_mcs_set, 16); |
| 8284 | } else { |
| 8285 | ht_cap->cap_info = cpu_to_le16(mode->ht_info.cap); |
| 8286 | memcpy(ht_cap->supp_mcs_set, |
| 8287 | mode->ht_info.supp_mcs_set, 16); |
| 8288 | } |
| 8289 | ht_cap->ampdu_params_info = |
| 8290 | (mode->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 8291 | ((mode->ht_info.ampdu_density << 2) & |
| 8292 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8293 | } |
| 8294 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8295 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8296 | |
| 8297 | /***************************************************************************** |
| 8298 | * |
| 8299 | * sysfs attributes |
| 8300 | * |
| 8301 | *****************************************************************************/ |
| 8302 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8303 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8304 | |
| 8305 | /* |
| 8306 | * The following adds a new attribute to the sysfs representation |
| 8307 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 8308 | * used for controlling the debug level. |
| 8309 | * |
| 8310 | * See the level definitions in iwl for details. |
| 8311 | */ |
| 8312 | |
| 8313 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 8314 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8315 | return sprintf(buf, "0x%08X\n", iwl4965_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8316 | } |
| 8317 | static ssize_t store_debug_level(struct device_driver *d, |
| 8318 | const char *buf, size_t count) |
| 8319 | { |
| 8320 | char *p = (char *)buf; |
| 8321 | u32 val; |
| 8322 | |
| 8323 | val = simple_strtoul(p, &p, 0); |
| 8324 | if (p == buf) |
| 8325 | printk(KERN_INFO DRV_NAME |
| 8326 | ": %s is not in hex or decimal form.\n", buf); |
| 8327 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8328 | iwl4965_debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8329 | |
| 8330 | return strnlen(buf, count); |
| 8331 | } |
| 8332 | |
| 8333 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 8334 | show_debug_level, store_debug_level); |
| 8335 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8336 | #endif /* CONFIG_IWL4965_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8337 | |
| 8338 | static ssize_t show_rf_kill(struct device *d, |
| 8339 | struct device_attribute *attr, char *buf) |
| 8340 | { |
| 8341 | /* |
| 8342 | * 0 - RF kill not enabled |
| 8343 | * 1 - SW based RF kill active (sysfs) |
| 8344 | * 2 - HW based RF kill active |
| 8345 | * 3 - Both HW and SW based RF kill active |
| 8346 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8347 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8348 | int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | |
| 8349 | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); |
| 8350 | |
| 8351 | return sprintf(buf, "%i\n", val); |
| 8352 | } |
| 8353 | |
| 8354 | static ssize_t store_rf_kill(struct device *d, |
| 8355 | struct device_attribute *attr, |
| 8356 | const char *buf, size_t count) |
| 8357 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8358 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8359 | |
| 8360 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8361 | iwl4965_radio_kill_sw(priv, buf[0] == '1'); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8362 | mutex_unlock(&priv->mutex); |
| 8363 | |
| 8364 | return count; |
| 8365 | } |
| 8366 | |
| 8367 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); |
| 8368 | |
| 8369 | static ssize_t show_temperature(struct device *d, |
| 8370 | struct device_attribute *attr, char *buf) |
| 8371 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8372 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8373 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8374 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8375 | return -EAGAIN; |
| 8376 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8377 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8378 | } |
| 8379 | |
| 8380 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 8381 | |
| 8382 | static ssize_t show_rs_window(struct device *d, |
| 8383 | struct device_attribute *attr, |
| 8384 | char *buf) |
| 8385 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8386 | struct iwl4965_priv *priv = d->driver_data; |
| 8387 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8388 | } |
| 8389 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 8390 | |
| 8391 | static ssize_t show_tx_power(struct device *d, |
| 8392 | struct device_attribute *attr, char *buf) |
| 8393 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8394 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8395 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 8396 | } |
| 8397 | |
| 8398 | static ssize_t store_tx_power(struct device *d, |
| 8399 | struct device_attribute *attr, |
| 8400 | const char *buf, size_t count) |
| 8401 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8402 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8403 | char *p = (char *)buf; |
| 8404 | u32 val; |
| 8405 | |
| 8406 | val = simple_strtoul(p, &p, 10); |
| 8407 | if (p == buf) |
| 8408 | printk(KERN_INFO DRV_NAME |
| 8409 | ": %s is not in decimal form.\n", buf); |
| 8410 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8411 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8412 | |
| 8413 | return count; |
| 8414 | } |
| 8415 | |
| 8416 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 8417 | |
| 8418 | static ssize_t show_flags(struct device *d, |
| 8419 | struct device_attribute *attr, char *buf) |
| 8420 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8421 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8422 | |
| 8423 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 8424 | } |
| 8425 | |
| 8426 | static ssize_t store_flags(struct device *d, |
| 8427 | struct device_attribute *attr, |
| 8428 | const char *buf, size_t count) |
| 8429 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8430 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8431 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 8432 | |
| 8433 | mutex_lock(&priv->mutex); |
| 8434 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 8435 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8436 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8437 | IWL_WARNING("Could not cancel scan.\n"); |
| 8438 | else { |
| 8439 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 8440 | flags); |
| 8441 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8442 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8443 | } |
| 8444 | } |
| 8445 | mutex_unlock(&priv->mutex); |
| 8446 | |
| 8447 | return count; |
| 8448 | } |
| 8449 | |
| 8450 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 8451 | |
| 8452 | static ssize_t show_filter_flags(struct device *d, |
| 8453 | struct device_attribute *attr, char *buf) |
| 8454 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8455 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8456 | |
| 8457 | return sprintf(buf, "0x%04X\n", |
| 8458 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 8459 | } |
| 8460 | |
| 8461 | static ssize_t store_filter_flags(struct device *d, |
| 8462 | struct device_attribute *attr, |
| 8463 | const char *buf, size_t count) |
| 8464 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8465 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8466 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 8467 | |
| 8468 | mutex_lock(&priv->mutex); |
| 8469 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 8470 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8471 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8472 | IWL_WARNING("Could not cancel scan.\n"); |
| 8473 | else { |
| 8474 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 8475 | "0x%04X\n", filter_flags); |
| 8476 | priv->staging_rxon.filter_flags = |
| 8477 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8478 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8479 | } |
| 8480 | } |
| 8481 | mutex_unlock(&priv->mutex); |
| 8482 | |
| 8483 | return count; |
| 8484 | } |
| 8485 | |
| 8486 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 8487 | store_filter_flags); |
| 8488 | |
| 8489 | static ssize_t show_tune(struct device *d, |
| 8490 | struct device_attribute *attr, char *buf) |
| 8491 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8492 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8493 | |
| 8494 | return sprintf(buf, "0x%04X\n", |
| 8495 | (priv->phymode << 8) | |
| 8496 | le16_to_cpu(priv->active_rxon.channel)); |
| 8497 | } |
| 8498 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8499 | 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] | 8500 | |
| 8501 | static ssize_t store_tune(struct device *d, |
| 8502 | struct device_attribute *attr, |
| 8503 | const char *buf, size_t count) |
| 8504 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8505 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8506 | char *p = (char *)buf; |
| 8507 | u16 tune = simple_strtoul(p, &p, 0); |
| 8508 | u8 phymode = (tune >> 8) & 0xff; |
| 8509 | u16 channel = tune & 0xff; |
| 8510 | |
| 8511 | IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel); |
| 8512 | |
| 8513 | mutex_lock(&priv->mutex); |
| 8514 | if ((le16_to_cpu(priv->staging_rxon.channel) != channel) || |
| 8515 | (priv->phymode != phymode)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8516 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8517 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8518 | ch_info = iwl4965_get_channel_info(priv, phymode, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8519 | if (!ch_info) { |
| 8520 | IWL_WARNING("Requested invalid phymode/channel " |
| 8521 | "combination: %d %d\n", phymode, channel); |
| 8522 | mutex_unlock(&priv->mutex); |
| 8523 | return -EINVAL; |
| 8524 | } |
| 8525 | |
| 8526 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8527 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8528 | IWL_WARNING("Could not cancel scan.\n"); |
| 8529 | else { |
| 8530 | IWL_DEBUG_INFO("Committing phymode and " |
| 8531 | "rxon.channel = %d %d\n", |
| 8532 | phymode, channel); |
| 8533 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8534 | iwl4965_set_rxon_channel(priv, phymode, channel); |
| 8535 | iwl4965_set_flags_for_phymode(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8536 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8537 | iwl4965_set_rate(priv); |
| 8538 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8539 | } |
| 8540 | } |
| 8541 | mutex_unlock(&priv->mutex); |
| 8542 | |
| 8543 | return count; |
| 8544 | } |
| 8545 | |
| 8546 | static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune); |
| 8547 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8548 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8549 | |
| 8550 | static ssize_t show_measurement(struct device *d, |
| 8551 | struct device_attribute *attr, char *buf) |
| 8552 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8553 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8554 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8555 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 8556 | u8 *data = (u8 *) & measure_report; |
| 8557 | unsigned long flags; |
| 8558 | |
| 8559 | spin_lock_irqsave(&priv->lock, flags); |
| 8560 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 8561 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8562 | return 0; |
| 8563 | } |
| 8564 | memcpy(&measure_report, &priv->measure_report, size); |
| 8565 | priv->measurement_status = 0; |
| 8566 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8567 | |
| 8568 | while (size && (PAGE_SIZE - len)) { |
| 8569 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8570 | PAGE_SIZE - len, 1); |
| 8571 | len = strlen(buf); |
| 8572 | if (PAGE_SIZE - len) |
| 8573 | buf[len++] = '\n'; |
| 8574 | |
| 8575 | ofs += 16; |
| 8576 | size -= min(size, 16U); |
| 8577 | } |
| 8578 | |
| 8579 | return len; |
| 8580 | } |
| 8581 | |
| 8582 | static ssize_t store_measurement(struct device *d, |
| 8583 | struct device_attribute *attr, |
| 8584 | const char *buf, size_t count) |
| 8585 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8586 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8587 | struct ieee80211_measurement_params params = { |
| 8588 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 8589 | .start_time = cpu_to_le64(priv->last_tsf), |
| 8590 | .duration = cpu_to_le16(1), |
| 8591 | }; |
| 8592 | u8 type = IWL_MEASURE_BASIC; |
| 8593 | u8 buffer[32]; |
| 8594 | u8 channel; |
| 8595 | |
| 8596 | if (count) { |
| 8597 | char *p = buffer; |
| 8598 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 8599 | channel = simple_strtoul(p, NULL, 0); |
| 8600 | if (channel) |
| 8601 | params.channel = channel; |
| 8602 | |
| 8603 | p = buffer; |
| 8604 | while (*p && *p != ' ') |
| 8605 | p++; |
| 8606 | if (*p) |
| 8607 | type = simple_strtoul(p + 1, NULL, 0); |
| 8608 | } |
| 8609 | |
| 8610 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 8611 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8612 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8613 | |
| 8614 | return count; |
| 8615 | } |
| 8616 | |
| 8617 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 8618 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8619 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8620 | |
| 8621 | static ssize_t store_retry_rate(struct device *d, |
| 8622 | struct device_attribute *attr, |
| 8623 | const char *buf, size_t count) |
| 8624 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8625 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8626 | |
| 8627 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 8628 | if (priv->retry_rate <= 0) |
| 8629 | priv->retry_rate = 1; |
| 8630 | |
| 8631 | return count; |
| 8632 | } |
| 8633 | |
| 8634 | static ssize_t show_retry_rate(struct device *d, |
| 8635 | struct device_attribute *attr, char *buf) |
| 8636 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8637 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8638 | return sprintf(buf, "%d", priv->retry_rate); |
| 8639 | } |
| 8640 | |
| 8641 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 8642 | store_retry_rate); |
| 8643 | |
| 8644 | static ssize_t store_power_level(struct device *d, |
| 8645 | struct device_attribute *attr, |
| 8646 | const char *buf, size_t count) |
| 8647 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8648 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8649 | int rc; |
| 8650 | int mode; |
| 8651 | |
| 8652 | mode = simple_strtoul(buf, NULL, 0); |
| 8653 | mutex_lock(&priv->mutex); |
| 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 | rc = -EAGAIN; |
| 8657 | goto out; |
| 8658 | } |
| 8659 | |
| 8660 | if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC)) |
| 8661 | mode = IWL_POWER_AC; |
| 8662 | else |
| 8663 | mode |= IWL_POWER_ENABLED; |
| 8664 | |
| 8665 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8666 | rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8667 | if (rc) { |
| 8668 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 8669 | goto out; |
| 8670 | } |
| 8671 | priv->power_mode = mode; |
| 8672 | } |
| 8673 | |
| 8674 | rc = count; |
| 8675 | |
| 8676 | out: |
| 8677 | mutex_unlock(&priv->mutex); |
| 8678 | return rc; |
| 8679 | } |
| 8680 | |
| 8681 | #define MAX_WX_STRING 80 |
| 8682 | |
| 8683 | /* Values are in microsecond */ |
| 8684 | static const s32 timeout_duration[] = { |
| 8685 | 350000, |
| 8686 | 250000, |
| 8687 | 75000, |
| 8688 | 37000, |
| 8689 | 25000, |
| 8690 | }; |
| 8691 | static const s32 period_duration[] = { |
| 8692 | 400000, |
| 8693 | 700000, |
| 8694 | 1000000, |
| 8695 | 1000000, |
| 8696 | 1000000 |
| 8697 | }; |
| 8698 | |
| 8699 | static ssize_t show_power_level(struct device *d, |
| 8700 | struct device_attribute *attr, char *buf) |
| 8701 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8702 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8703 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 8704 | char *p = buf; |
| 8705 | |
| 8706 | p += sprintf(p, "%d ", level); |
| 8707 | switch (level) { |
| 8708 | case IWL_POWER_MODE_CAM: |
| 8709 | case IWL_POWER_AC: |
| 8710 | p += sprintf(p, "(AC)"); |
| 8711 | break; |
| 8712 | case IWL_POWER_BATTERY: |
| 8713 | p += sprintf(p, "(BATTERY)"); |
| 8714 | break; |
| 8715 | default: |
| 8716 | p += sprintf(p, |
| 8717 | "(Timeout %dms, Period %dms)", |
| 8718 | timeout_duration[level - 1] / 1000, |
| 8719 | period_duration[level - 1] / 1000); |
| 8720 | } |
| 8721 | |
| 8722 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 8723 | p += sprintf(p, " OFF\n"); |
| 8724 | else |
| 8725 | p += sprintf(p, " \n"); |
| 8726 | |
| 8727 | return (p - buf + 1); |
| 8728 | |
| 8729 | } |
| 8730 | |
| 8731 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 8732 | store_power_level); |
| 8733 | |
| 8734 | static ssize_t show_channels(struct device *d, |
| 8735 | struct device_attribute *attr, char *buf) |
| 8736 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8737 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8738 | int len = 0, i; |
| 8739 | struct ieee80211_channel *channels = NULL; |
| 8740 | const struct ieee80211_hw_mode *hw_mode = NULL; |
| 8741 | int count = 0; |
| 8742 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8743 | if (!iwl4965_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8744 | return -EAGAIN; |
| 8745 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8746 | hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211G); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8747 | if (!hw_mode) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8748 | hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211B); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8749 | if (hw_mode) { |
| 8750 | channels = hw_mode->channels; |
| 8751 | count = hw_mode->num_channels; |
| 8752 | } |
| 8753 | |
| 8754 | len += |
| 8755 | sprintf(&buf[len], |
| 8756 | "Displaying %d channels in 2.4GHz band " |
| 8757 | "(802.11bg):\n", count); |
| 8758 | |
| 8759 | for (i = 0; i < count; i++) |
| 8760 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 8761 | channels[i].chan, |
| 8762 | channels[i].power_level, |
| 8763 | channels[i]. |
| 8764 | flag & IEEE80211_CHAN_W_RADAR_DETECT ? |
| 8765 | " (IEEE 802.11h required)" : "", |
| 8766 | (!(channels[i].flag & IEEE80211_CHAN_W_IBSS) |
| 8767 | || (channels[i]. |
| 8768 | flag & |
| 8769 | IEEE80211_CHAN_W_RADAR_DETECT)) ? "" : |
| 8770 | ", IBSS", |
| 8771 | channels[i]. |
| 8772 | flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? |
| 8773 | "active/passive" : "passive only"); |
| 8774 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8775 | hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211A); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8776 | if (hw_mode) { |
| 8777 | channels = hw_mode->channels; |
| 8778 | count = hw_mode->num_channels; |
| 8779 | } else { |
| 8780 | channels = NULL; |
| 8781 | count = 0; |
| 8782 | } |
| 8783 | |
| 8784 | len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band " |
| 8785 | "(802.11a):\n", count); |
| 8786 | |
| 8787 | for (i = 0; i < count; i++) |
| 8788 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 8789 | channels[i].chan, |
| 8790 | channels[i].power_level, |
| 8791 | channels[i]. |
| 8792 | flag & IEEE80211_CHAN_W_RADAR_DETECT ? |
| 8793 | " (IEEE 802.11h required)" : "", |
| 8794 | (!(channels[i].flag & IEEE80211_CHAN_W_IBSS) |
| 8795 | || (channels[i]. |
| 8796 | flag & |
| 8797 | IEEE80211_CHAN_W_RADAR_DETECT)) ? "" : |
| 8798 | ", IBSS", |
| 8799 | channels[i]. |
| 8800 | flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? |
| 8801 | "active/passive" : "passive only"); |
| 8802 | |
| 8803 | return len; |
| 8804 | } |
| 8805 | |
| 8806 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 8807 | |
| 8808 | static ssize_t show_statistics(struct device *d, |
| 8809 | struct device_attribute *attr, char *buf) |
| 8810 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8811 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8812 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8813 | u32 len = 0, ofs = 0; |
| 8814 | u8 *data = (u8 *) & priv->statistics; |
| 8815 | int rc = 0; |
| 8816 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8817 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8818 | return -EAGAIN; |
| 8819 | |
| 8820 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8821 | rc = iwl4965_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8822 | mutex_unlock(&priv->mutex); |
| 8823 | |
| 8824 | if (rc) { |
| 8825 | len = sprintf(buf, |
| 8826 | "Error sending statistics request: 0x%08X\n", rc); |
| 8827 | return len; |
| 8828 | } |
| 8829 | |
| 8830 | while (size && (PAGE_SIZE - len)) { |
| 8831 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8832 | PAGE_SIZE - len, 1); |
| 8833 | len = strlen(buf); |
| 8834 | if (PAGE_SIZE - len) |
| 8835 | buf[len++] = '\n'; |
| 8836 | |
| 8837 | ofs += 16; |
| 8838 | size -= min(size, 16U); |
| 8839 | } |
| 8840 | |
| 8841 | return len; |
| 8842 | } |
| 8843 | |
| 8844 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 8845 | |
| 8846 | static ssize_t show_antenna(struct device *d, |
| 8847 | struct device_attribute *attr, char *buf) |
| 8848 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8849 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8850 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8851 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8852 | return -EAGAIN; |
| 8853 | |
| 8854 | return sprintf(buf, "%d\n", priv->antenna); |
| 8855 | } |
| 8856 | |
| 8857 | static ssize_t store_antenna(struct device *d, |
| 8858 | struct device_attribute *attr, |
| 8859 | const char *buf, size_t count) |
| 8860 | { |
| 8861 | int ant; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8862 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8863 | |
| 8864 | if (count == 0) |
| 8865 | return 0; |
| 8866 | |
| 8867 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 8868 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 8869 | return count; |
| 8870 | } |
| 8871 | |
| 8872 | if ((ant >= 0) && (ant <= 2)) { |
| 8873 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8874 | priv->antenna = (enum iwl4965_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8875 | } else |
| 8876 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 8877 | |
| 8878 | |
| 8879 | return count; |
| 8880 | } |
| 8881 | |
| 8882 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 8883 | |
| 8884 | static ssize_t show_status(struct device *d, |
| 8885 | struct device_attribute *attr, char *buf) |
| 8886 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8887 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
| 8888 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8889 | return -EAGAIN; |
| 8890 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 8891 | } |
| 8892 | |
| 8893 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 8894 | |
| 8895 | static ssize_t dump_error_log(struct device *d, |
| 8896 | struct device_attribute *attr, |
| 8897 | const char *buf, size_t count) |
| 8898 | { |
| 8899 | char *p = (char *)buf; |
| 8900 | |
| 8901 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8902 | iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8903 | |
| 8904 | return strnlen(buf, count); |
| 8905 | } |
| 8906 | |
| 8907 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 8908 | |
| 8909 | static ssize_t dump_event_log(struct device *d, |
| 8910 | struct device_attribute *attr, |
| 8911 | const char *buf, size_t count) |
| 8912 | { |
| 8913 | char *p = (char *)buf; |
| 8914 | |
| 8915 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8916 | iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8917 | |
| 8918 | return strnlen(buf, count); |
| 8919 | } |
| 8920 | |
| 8921 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 8922 | |
| 8923 | /***************************************************************************** |
| 8924 | * |
| 8925 | * driver setup and teardown |
| 8926 | * |
| 8927 | *****************************************************************************/ |
| 8928 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8929 | static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8930 | { |
| 8931 | priv->workqueue = create_workqueue(DRV_NAME); |
| 8932 | |
| 8933 | init_waitqueue_head(&priv->wait_command_queue); |
| 8934 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8935 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 8936 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 8937 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 8938 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 8939 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 8940 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 8941 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 8942 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
| 8943 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 8944 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 8945 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 8946 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8947 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8948 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8949 | |
| 8950 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8951 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8952 | } |
| 8953 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8954 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8955 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8956 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8957 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 8958 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8959 | cancel_delayed_work(&priv->scan_check); |
| 8960 | cancel_delayed_work(&priv->alive_start); |
| 8961 | cancel_delayed_work(&priv->post_associate); |
| 8962 | cancel_work_sync(&priv->beacon_update); |
| 8963 | } |
| 8964 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8965 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8966 | &dev_attr_antenna.attr, |
| 8967 | &dev_attr_channels.attr, |
| 8968 | &dev_attr_dump_errors.attr, |
| 8969 | &dev_attr_dump_events.attr, |
| 8970 | &dev_attr_flags.attr, |
| 8971 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8972 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8973 | &dev_attr_measurement.attr, |
| 8974 | #endif |
| 8975 | &dev_attr_power_level.attr, |
| 8976 | &dev_attr_retry_rate.attr, |
| 8977 | &dev_attr_rf_kill.attr, |
| 8978 | &dev_attr_rs_window.attr, |
| 8979 | &dev_attr_statistics.attr, |
| 8980 | &dev_attr_status.attr, |
| 8981 | &dev_attr_temperature.attr, |
| 8982 | &dev_attr_tune.attr, |
| 8983 | &dev_attr_tx_power.attr, |
| 8984 | |
| 8985 | NULL |
| 8986 | }; |
| 8987 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8988 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8989 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8990 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8991 | }; |
| 8992 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8993 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 8994 | .tx = iwl4965_mac_tx, |
| 8995 | .start = iwl4965_mac_start, |
| 8996 | .stop = iwl4965_mac_stop, |
| 8997 | .add_interface = iwl4965_mac_add_interface, |
| 8998 | .remove_interface = iwl4965_mac_remove_interface, |
| 8999 | .config = iwl4965_mac_config, |
| 9000 | .config_interface = iwl4965_mac_config_interface, |
| 9001 | .configure_filter = iwl4965_configure_filter, |
| 9002 | .set_key = iwl4965_mac_set_key, |
| 9003 | .get_stats = iwl4965_mac_get_stats, |
| 9004 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 9005 | .conf_tx = iwl4965_mac_conf_tx, |
| 9006 | .get_tsf = iwl4965_mac_get_tsf, |
| 9007 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 9008 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 9009 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9010 | #ifdef CONFIG_IWL4965_HT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9011 | .conf_ht = iwl4965_mac_conf_ht, |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 9012 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9013 | #ifdef CONFIG_IWL4965_HT_AGG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9014 | .ht_tx_agg_start = iwl4965_mac_ht_tx_agg_start, |
| 9015 | .ht_tx_agg_stop = iwl4965_mac_ht_tx_agg_stop, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9016 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 9017 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9018 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9019 | }; |
| 9020 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9021 | 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] | 9022 | { |
| 9023 | int err = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9024 | struct iwl4965_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9025 | struct ieee80211_hw *hw; |
| 9026 | int i; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 9027 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9028 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9029 | /* Disabling hardware scan means that mac80211 will perform scans |
| 9030 | * "the hard way", rather than using device's scan. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9031 | if (iwl4965_param_disable_hw_scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9032 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9033 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9034 | } |
| 9035 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9036 | if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) || |
| 9037 | (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9038 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
| 9039 | IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); |
| 9040 | err = -EINVAL; |
| 9041 | goto out; |
| 9042 | } |
| 9043 | |
| 9044 | /* mac80211 allocates memory for this device instance, including |
| 9045 | * space for this driver's private structure */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9046 | hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9047 | if (hw == NULL) { |
| 9048 | IWL_ERROR("Can not allocate network device\n"); |
| 9049 | err = -ENOMEM; |
| 9050 | goto out; |
| 9051 | } |
| 9052 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 9053 | |
Johannes Berg | f51359a | 2007-10-28 14:53:36 +0100 | [diff] [blame] | 9054 | hw->rate_control_algorithm = "iwl-4965-rs"; |
| 9055 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9056 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 9057 | priv = hw->priv; |
| 9058 | priv->hw = hw; |
| 9059 | |
| 9060 | priv->pci_dev = pdev; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9061 | priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9062 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9063 | iwl4965_debug_level = iwl4965_param_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9064 | atomic_set(&priv->restrict_refcnt, 0); |
| 9065 | #endif |
| 9066 | priv->retry_rate = 1; |
| 9067 | |
| 9068 | priv->ibss_beacon = NULL; |
| 9069 | |
| 9070 | /* Tell mac80211 and its clients (e.g. Wireless Extensions) |
| 9071 | * the range of signal quality values that we'll provide. |
| 9072 | * Negative values for level/noise indicate that we'll provide dBm. |
| 9073 | * For WE, at least, non-0 values here *enable* display of values |
| 9074 | * in app (iwconfig). */ |
| 9075 | hw->max_rssi = -20; /* signal level, negative indicates dBm */ |
| 9076 | hw->max_noise = -20; /* noise level, negative indicates dBm */ |
| 9077 | hw->max_signal = 100; /* link quality indication (%) */ |
| 9078 | |
| 9079 | /* Tell mac80211 our Tx characteristics */ |
| 9080 | hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; |
| 9081 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9082 | /* Default value; 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9083 | hw->queues = 4; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9084 | #ifdef CONFIG_IWL4965_HT |
| 9085 | #ifdef CONFIG_IWL4965_HT_AGG |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9086 | /* Enhanced value; more queues, to support 11n aggregation */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9087 | hw->queues = 16; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9088 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 9089 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9090 | |
| 9091 | spin_lock_init(&priv->lock); |
| 9092 | spin_lock_init(&priv->power_data.lock); |
| 9093 | spin_lock_init(&priv->sta_lock); |
| 9094 | spin_lock_init(&priv->hcmd_lock); |
| 9095 | spin_lock_init(&priv->lq_mngr.lock); |
| 9096 | |
| 9097 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) |
| 9098 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
| 9099 | |
| 9100 | INIT_LIST_HEAD(&priv->free_frames); |
| 9101 | |
| 9102 | mutex_init(&priv->mutex); |
| 9103 | if (pci_enable_device(pdev)) { |
| 9104 | err = -ENODEV; |
| 9105 | goto out_ieee80211_free_hw; |
| 9106 | } |
| 9107 | |
| 9108 | pci_set_master(pdev); |
| 9109 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9110 | /* Clear the driver's (not device's) station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9111 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9112 | |
| 9113 | priv->data_retry_limit = -1; |
| 9114 | priv->ieee_channels = NULL; |
| 9115 | priv->ieee_rates = NULL; |
| 9116 | priv->phymode = -1; |
| 9117 | |
| 9118 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 9119 | if (!err) |
| 9120 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 9121 | if (err) { |
| 9122 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 9123 | goto out_pci_disable_device; |
| 9124 | } |
| 9125 | |
| 9126 | pci_set_drvdata(pdev, priv); |
| 9127 | err = pci_request_regions(pdev, DRV_NAME); |
| 9128 | if (err) |
| 9129 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9130 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9131 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 9132 | * PCI Tx retries from interfering with C3 CPU state */ |
| 9133 | pci_write_config_byte(pdev, 0x41, 0x00); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9134 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9135 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 9136 | if (!priv->hw_base) { |
| 9137 | err = -ENODEV; |
| 9138 | goto out_pci_release_regions; |
| 9139 | } |
| 9140 | |
| 9141 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 9142 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 9143 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 9144 | |
| 9145 | /* Initialize module parameter values here */ |
| 9146 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9147 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9148 | if (iwl4965_param_disable) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9149 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 9150 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 9151 | } |
| 9152 | |
| 9153 | priv->iw_mode = IEEE80211_IF_TYPE_STA; |
| 9154 | |
| 9155 | priv->ps_mode = 0; |
| 9156 | priv->use_ant_b_for_management_frame = 1; /* start with ant B */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9157 | priv->valid_antenna = 0x7; /* assume all 3 connected */ |
| 9158 | priv->ps_mode = IWL_MIMO_PS_NONE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9159 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9160 | /* Choose which receivers/antennas to use */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9161 | iwl4965_set_rxon_chain(priv); |
| 9162 | |
| 9163 | printk(KERN_INFO DRV_NAME |
| 9164 | ": Detected Intel Wireless WiFi Link 4965AGN\n"); |
| 9165 | |
| 9166 | /* Device-specific setup */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9167 | if (iwl4965_hw_set_hw_setting(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9168 | IWL_ERROR("failed to set hw settings\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9169 | goto out_iounmap; |
| 9170 | } |
| 9171 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9172 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9173 | if (iwl4965_param_qos_enable) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9174 | priv->qos_data.qos_enable = 1; |
| 9175 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9176 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9177 | |
| 9178 | priv->qos_data.qos_active = 0; |
| 9179 | priv->qos_data.qos_cap.val = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9180 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9181 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9182 | iwl4965_set_rxon_channel(priv, MODE_IEEE80211G, 6); |
| 9183 | iwl4965_setup_deferred_work(priv); |
| 9184 | iwl4965_setup_rx_handlers(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9185 | |
| 9186 | priv->rates_mask = IWL_RATES_MASK; |
| 9187 | /* If power management is turned on, default to AC mode */ |
| 9188 | priv->power_mode = IWL_POWER_AC; |
| 9189 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 9190 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9191 | iwl4965_disable_interrupts(priv); |
Jes Sorensen | 49df2b3 | 2007-10-26 16:10:39 +0200 | [diff] [blame] | 9192 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9193 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9194 | if (err) { |
| 9195 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9196 | goto out_release_irq; |
| 9197 | } |
| 9198 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 9199 | /* nic init */ |
| 9200 | iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
| 9201 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
| 9202 | |
| 9203 | iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 9204 | err = iwl4965_poll_bit(priv, CSR_GP_CNTRL, |
| 9205 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 9206 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
| 9207 | if (err < 0) { |
| 9208 | IWL_DEBUG_INFO("Failed to init the card\n"); |
| 9209 | goto out_remove_sysfs; |
| 9210 | } |
| 9211 | /* Read the EEPROM */ |
| 9212 | err = iwl4965_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9213 | if (err) { |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 9214 | IWL_ERROR("Unable to init EEPROM\n"); |
| 9215 | goto out_remove_sysfs; |
| 9216 | } |
| 9217 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 9218 | get_eeprom_mac(priv, priv->mac_addr); |
| 9219 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 9220 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 9221 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 9222 | err = iwl4965_init_channel_map(priv); |
| 9223 | if (err) { |
| 9224 | IWL_ERROR("initializing regulatory failed: %d\n", err); |
| 9225 | goto out_remove_sysfs; |
| 9226 | } |
| 9227 | |
| 9228 | err = iwl4965_init_geos(priv); |
| 9229 | if (err) { |
| 9230 | IWL_ERROR("initializing geos failed: %d\n", err); |
| 9231 | goto out_free_channel_map; |
| 9232 | } |
| 9233 | iwl4965_reset_channel_flag(priv); |
| 9234 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 9235 | iwl4965_rate_control_register(priv->hw); |
| 9236 | err = ieee80211_register_hw(priv->hw); |
| 9237 | if (err) { |
| 9238 | IWL_ERROR("Failed to register network device (error %d)\n", err); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 9239 | goto out_free_geos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9240 | } |
| 9241 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 9242 | priv->hw->conf.beacon_int = 100; |
| 9243 | priv->mac80211_registered = 1; |
| 9244 | pci_save_state(pdev); |
| 9245 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9246 | |
| 9247 | return 0; |
| 9248 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 9249 | out_free_geos: |
| 9250 | iwl4965_free_geos(priv); |
| 9251 | out_free_channel_map: |
| 9252 | iwl4965_free_channel_map(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 9253 | out_remove_sysfs: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9254 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9255 | |
| 9256 | out_release_irq: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9257 | destroy_workqueue(priv->workqueue); |
| 9258 | priv->workqueue = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9259 | iwl4965_unset_hw_setting(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9260 | |
| 9261 | out_iounmap: |
| 9262 | pci_iounmap(pdev, priv->hw_base); |
| 9263 | out_pci_release_regions: |
| 9264 | pci_release_regions(pdev); |
| 9265 | out_pci_disable_device: |
| 9266 | pci_disable_device(pdev); |
| 9267 | pci_set_drvdata(pdev, NULL); |
| 9268 | out_ieee80211_free_hw: |
| 9269 | ieee80211_free_hw(priv->hw); |
| 9270 | out: |
| 9271 | return err; |
| 9272 | } |
| 9273 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9274 | static void iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9275 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9276 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9277 | struct list_head *p, *q; |
| 9278 | int i; |
| 9279 | |
| 9280 | if (!priv) |
| 9281 | return; |
| 9282 | |
| 9283 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 9284 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9285 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 9286 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9287 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9288 | |
| 9289 | /* Free MAC hash list for ADHOC */ |
| 9290 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 9291 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 9292 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9293 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9294 | } |
| 9295 | } |
| 9296 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9297 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9298 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9299 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9300 | |
| 9301 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9302 | iwl4965_rx_queue_free(priv, &priv->rxq); |
| 9303 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9304 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9305 | iwl4965_unset_hw_setting(priv); |
| 9306 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9307 | |
| 9308 | if (priv->mac80211_registered) { |
| 9309 | ieee80211_unregister_hw(priv->hw); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9310 | iwl4965_rate_control_unregister(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9311 | } |
| 9312 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 9313 | /*netif_stop_queue(dev); */ |
| 9314 | flush_workqueue(priv->workqueue); |
| 9315 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9316 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9317 | * priv->workqueue... so we can't take down the workqueue |
| 9318 | * until now... */ |
| 9319 | destroy_workqueue(priv->workqueue); |
| 9320 | priv->workqueue = NULL; |
| 9321 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9322 | pci_iounmap(pdev, priv->hw_base); |
| 9323 | pci_release_regions(pdev); |
| 9324 | pci_disable_device(pdev); |
| 9325 | pci_set_drvdata(pdev, NULL); |
| 9326 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 9327 | iwl4965_free_channel_map(priv); |
| 9328 | iwl4965_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9329 | |
| 9330 | if (priv->ibss_beacon) |
| 9331 | dev_kfree_skb(priv->ibss_beacon); |
| 9332 | |
| 9333 | ieee80211_free_hw(priv->hw); |
| 9334 | } |
| 9335 | |
| 9336 | #ifdef CONFIG_PM |
| 9337 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9338 | 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] | 9339 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9340 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9341 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 9342 | if (priv->is_open) { |
| 9343 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 9344 | iwl4965_mac_stop(priv->hw); |
| 9345 | priv->is_open = 1; |
| 9346 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9347 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9348 | pci_set_power_state(pdev, PCI_D3hot); |
| 9349 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9350 | return 0; |
| 9351 | } |
| 9352 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9353 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9354 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9355 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9356 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9357 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9358 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 9359 | if (priv->is_open) |
| 9360 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9361 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 9362 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9363 | return 0; |
| 9364 | } |
| 9365 | |
| 9366 | #endif /* CONFIG_PM */ |
| 9367 | |
| 9368 | /***************************************************************************** |
| 9369 | * |
| 9370 | * driver and module entry point |
| 9371 | * |
| 9372 | *****************************************************************************/ |
| 9373 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9374 | static struct pci_driver iwl4965_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9375 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9376 | .id_table = iwl4965_hw_card_ids, |
| 9377 | .probe = iwl4965_pci_probe, |
| 9378 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9379 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9380 | .suspend = iwl4965_pci_suspend, |
| 9381 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9382 | #endif |
| 9383 | }; |
| 9384 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9385 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9386 | { |
| 9387 | |
| 9388 | int ret; |
| 9389 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 9390 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9391 | ret = pci_register_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9392 | if (ret) { |
| 9393 | IWL_ERROR("Unable to initialize PCI module\n"); |
| 9394 | return ret; |
| 9395 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9396 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9397 | ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9398 | if (ret) { |
| 9399 | IWL_ERROR("Unable to create driver sysfs file\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9400 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9401 | return ret; |
| 9402 | } |
| 9403 | #endif |
| 9404 | |
| 9405 | return ret; |
| 9406 | } |
| 9407 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9408 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9409 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9410 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9411 | driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9412 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9413 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9414 | } |
| 9415 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9416 | module_param_named(antenna, iwl4965_param_antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9417 | 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] | 9418 | module_param_named(disable, iwl4965_param_disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9419 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9420 | module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9421 | MODULE_PARM_DESC(hwcrypto, |
| 9422 | "using hardware crypto engine (default 0 [software])\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9423 | module_param_named(debug, iwl4965_param_debug, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9424 | MODULE_PARM_DESC(debug, "debug output mask"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9425 | 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] | 9426 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 9427 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9428 | module_param_named(queues_num, iwl4965_param_queues_num, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9429 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 9430 | |
| 9431 | /* QoS */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9432 | module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9433 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 9434 | module_param_named(amsdu_size_8K, iwl4965_param_amsdu_size_8K, int, 0444); |
| 9435 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9436 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9437 | module_exit(iwl4965_exit); |
| 9438 | module_init(iwl4965_init); |