Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. |
| 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/version.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/skbuff.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/wireless.h> |
| 40 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 41 | #include <linux/etherdevice.h> |
| 42 | #include <linux/if_arp.h> |
| 43 | |
| 44 | #include <net/ieee80211_radiotap.h> |
| 45 | #include <net/mac80211.h> |
| 46 | |
| 47 | #include <asm/div64.h> |
| 48 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 49 | #include "iwl-4965.h" |
| 50 | #include "iwl-helpers.h" |
| 51 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 52 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 53 | u32 iwl4965_debug_level; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 54 | #endif |
| 55 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 56 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 57 | struct iwl4965_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 58 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 59 | /****************************************************************************** |
| 60 | * |
| 61 | * module boiler plate |
| 62 | * |
| 63 | ******************************************************************************/ |
| 64 | |
| 65 | /* module parameters */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 66 | static int iwl4965_param_disable_hw_scan; /* def: 0 = use 4965's h/w scan */ |
| 67 | static int iwl4965_param_debug; /* def: 0 = minimal debug log messages */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 68 | static int iwl4965_param_disable; /* def: enable radio */ |
| 69 | static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */ |
| 70 | int iwl4965_param_hwcrypto; /* def: using software encryption */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 71 | static int iwl4965_param_qos_enable = 1; /* def: 1 = use quality of service */ |
| 72 | int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 16 Tx queues */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * module name, copyright, version, etc. |
| 76 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 77 | */ |
| 78 | |
| 79 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" |
| 80 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 81 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 82 | #define VD "d" |
| 83 | #else |
| 84 | #define VD |
| 85 | #endif |
| 86 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 87 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 88 | #define VS "s" |
| 89 | #else |
| 90 | #define VS |
| 91 | #endif |
| 92 | |
Zhu Yi | d128394 | 2007-11-29 11:10:16 +0800 | [diff] [blame] | 93 | #define IWLWIFI_VERSION "1.2.22k" 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. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 352 | * For data 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 | |
| 1642 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1643 | * iwl4965_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1644 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1645 | * Load the EEPROM contents from adapter into priv->eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1646 | * |
| 1647 | * NOTE: This routine uses the non-debug IO access functions. |
| 1648 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1649 | int iwl4965_eeprom_init(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1650 | { |
| 1651 | u16 *e = (u16 *)&priv->eeprom; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1652 | u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1653 | u32 r; |
| 1654 | int sz = sizeof(priv->eeprom); |
| 1655 | int rc; |
| 1656 | int i; |
| 1657 | u16 addr; |
| 1658 | |
| 1659 | /* The EEPROM structure has several padding buffers within it |
| 1660 | * and when adding new EEPROM maps is subject to programmer errors |
| 1661 | * which may be very difficult to identify without explicitly |
| 1662 | * checking the resulting size of the eeprom map. */ |
| 1663 | BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); |
| 1664 | |
| 1665 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
| 1666 | IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); |
| 1667 | return -ENOENT; |
| 1668 | } |
| 1669 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1670 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1671 | rc = iwl4965_eeprom_acquire_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1672 | if (rc < 0) { |
Ian Schram | 91e1747 | 2007-10-25 17:15:23 +0800 | [diff] [blame] | 1673 | IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1674 | return -ENOENT; |
| 1675 | } |
| 1676 | |
| 1677 | /* eeprom is an array of 16bit values */ |
| 1678 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1679 | _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1); |
| 1680 | _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1681 | |
| 1682 | for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; |
| 1683 | i += IWL_EEPROM_ACCESS_DELAY) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1684 | r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1685 | if (r & CSR_EEPROM_REG_READ_VALID_MSK) |
| 1686 | break; |
| 1687 | udelay(IWL_EEPROM_ACCESS_DELAY); |
| 1688 | } |
| 1689 | |
| 1690 | if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { |
| 1691 | IWL_ERROR("Time out reading EEPROM[%d]", addr); |
| 1692 | rc = -ETIMEDOUT; |
| 1693 | goto done; |
| 1694 | } |
| 1695 | e[addr / 2] = le16_to_cpu(r >> 16); |
| 1696 | } |
| 1697 | rc = 0; |
| 1698 | |
| 1699 | done: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1700 | iwl4965_eeprom_release_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1701 | return rc; |
| 1702 | } |
| 1703 | |
| 1704 | /****************************************************************************** |
| 1705 | * |
| 1706 | * Misc. internal state and helper functions |
| 1707 | * |
| 1708 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1709 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1710 | |
| 1711 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1712 | * iwl4965_report_frame - dump frame to syslog during debug sessions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1713 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1714 | * You may hack this function to show different aspects of received frames, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1715 | * including selective frame dumps. |
| 1716 | * group100 parameter selects whether to show 1 out of 100 good frames. |
| 1717 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1718 | * TODO: This was originally written for 3945, need to audit for |
| 1719 | * proper operation with 4965. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1720 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1721 | void iwl4965_report_frame(struct iwl4965_priv *priv, |
| 1722 | struct iwl4965_rx_packet *pkt, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1723 | struct ieee80211_hdr *header, int group100) |
| 1724 | { |
| 1725 | u32 to_us; |
| 1726 | u32 print_summary = 0; |
| 1727 | u32 print_dump = 0; /* set to 1 to dump all frames' contents */ |
| 1728 | u32 hundred = 0; |
| 1729 | u32 dataframe = 0; |
| 1730 | u16 fc; |
| 1731 | u16 seq_ctl; |
| 1732 | u16 channel; |
| 1733 | u16 phy_flags; |
| 1734 | int rate_sym; |
| 1735 | u16 length; |
| 1736 | u16 status; |
| 1737 | u16 bcn_tmr; |
| 1738 | u32 tsf_low; |
| 1739 | u64 tsf; |
| 1740 | u8 rssi; |
| 1741 | u8 agc; |
| 1742 | u16 sig_avg; |
| 1743 | u16 noise_diff; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1744 | struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); |
| 1745 | struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); |
| 1746 | struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1747 | u8 *data = IWL_RX_DATA(pkt); |
| 1748 | |
| 1749 | /* MAC header */ |
| 1750 | fc = le16_to_cpu(header->frame_control); |
| 1751 | seq_ctl = le16_to_cpu(header->seq_ctrl); |
| 1752 | |
| 1753 | /* metadata */ |
| 1754 | channel = le16_to_cpu(rx_hdr->channel); |
| 1755 | phy_flags = le16_to_cpu(rx_hdr->phy_flags); |
| 1756 | rate_sym = rx_hdr->rate; |
| 1757 | length = le16_to_cpu(rx_hdr->len); |
| 1758 | |
| 1759 | /* end-of-frame status and timestamp */ |
| 1760 | status = le32_to_cpu(rx_end->status); |
| 1761 | bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp); |
| 1762 | tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff; |
| 1763 | tsf = le64_to_cpu(rx_end->timestamp); |
| 1764 | |
| 1765 | /* signal statistics */ |
| 1766 | rssi = rx_stats->rssi; |
| 1767 | agc = rx_stats->agc; |
| 1768 | sig_avg = le16_to_cpu(rx_stats->sig_avg); |
| 1769 | noise_diff = le16_to_cpu(rx_stats->noise_diff); |
| 1770 | |
| 1771 | to_us = !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1772 | |
| 1773 | /* if data frame is to us and all is good, |
| 1774 | * (optionally) print summary for only 1 out of every 100 */ |
| 1775 | if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) == |
| 1776 | (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) { |
| 1777 | dataframe = 1; |
| 1778 | if (!group100) |
| 1779 | print_summary = 1; /* print each frame */ |
| 1780 | else if (priv->framecnt_to_us < 100) { |
| 1781 | priv->framecnt_to_us++; |
| 1782 | print_summary = 0; |
| 1783 | } else { |
| 1784 | priv->framecnt_to_us = 0; |
| 1785 | print_summary = 1; |
| 1786 | hundred = 1; |
| 1787 | } |
| 1788 | } else { |
| 1789 | /* print summary for all other frames */ |
| 1790 | print_summary = 1; |
| 1791 | } |
| 1792 | |
| 1793 | if (print_summary) { |
| 1794 | char *title; |
| 1795 | u32 rate; |
| 1796 | |
| 1797 | if (hundred) |
| 1798 | title = "100Frames"; |
| 1799 | else if (fc & IEEE80211_FCTL_RETRY) |
| 1800 | title = "Retry"; |
| 1801 | else if (ieee80211_is_assoc_response(fc)) |
| 1802 | title = "AscRsp"; |
| 1803 | else if (ieee80211_is_reassoc_response(fc)) |
| 1804 | title = "RasRsp"; |
| 1805 | else if (ieee80211_is_probe_response(fc)) { |
| 1806 | title = "PrbRsp"; |
| 1807 | print_dump = 1; /* dump frame contents */ |
| 1808 | } else if (ieee80211_is_beacon(fc)) { |
| 1809 | title = "Beacon"; |
| 1810 | print_dump = 1; /* dump frame contents */ |
| 1811 | } else if (ieee80211_is_atim(fc)) |
| 1812 | title = "ATIM"; |
| 1813 | else if (ieee80211_is_auth(fc)) |
| 1814 | title = "Auth"; |
| 1815 | else if (ieee80211_is_deauth(fc)) |
| 1816 | title = "DeAuth"; |
| 1817 | else if (ieee80211_is_disassoc(fc)) |
| 1818 | title = "DisAssoc"; |
| 1819 | else |
| 1820 | title = "Frame"; |
| 1821 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1822 | rate = iwl4965_rate_index_from_plcp(rate_sym); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1823 | if (rate == -1) |
| 1824 | rate = 0; |
| 1825 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1826 | rate = iwl4965_rates[rate].ieee / 2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1827 | |
| 1828 | /* print frame summary. |
| 1829 | * MAC addresses show just the last byte (for brevity), |
| 1830 | * but you can hack it to show more, if you'd like to. */ |
| 1831 | if (dataframe) |
| 1832 | IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, " |
| 1833 | "len=%u, rssi=%d, chnl=%d, rate=%u, \n", |
| 1834 | title, fc, header->addr1[5], |
| 1835 | length, rssi, channel, rate); |
| 1836 | else { |
| 1837 | /* src/dst addresses assume managed mode */ |
| 1838 | IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, " |
| 1839 | "src=0x%02x, rssi=%u, tim=%lu usec, " |
| 1840 | "phy=0x%02x, chnl=%d\n", |
| 1841 | title, fc, header->addr1[5], |
| 1842 | header->addr3[5], rssi, |
| 1843 | tsf_low - priv->scan_start_tsf, |
| 1844 | phy_flags, channel); |
| 1845 | } |
| 1846 | } |
| 1847 | if (print_dump) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1848 | iwl4965_print_hex_dump(IWL_DL_RX, data, length); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1849 | } |
| 1850 | #endif |
| 1851 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1852 | static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1853 | { |
| 1854 | if (priv->hw_setting.shared_virt) |
| 1855 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1856 | sizeof(struct iwl4965_shared), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1857 | priv->hw_setting.shared_virt, |
| 1858 | priv->hw_setting.shared_phys); |
| 1859 | } |
| 1860 | |
| 1861 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1862 | * 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] | 1863 | * |
| 1864 | * return : set the bit for each supported rate insert in ie |
| 1865 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1866 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1867 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1868 | { |
| 1869 | u16 ret_rates = 0, bit; |
| 1870 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1871 | u8 *cnt = ie; |
| 1872 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1873 | |
| 1874 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1875 | if (bit & supported_rate) { |
| 1876 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1877 | rates[*cnt] = iwl4965_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1878 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1879 | (*cnt)++; |
| 1880 | (*left)--; |
| 1881 | if ((*left <= 0) || |
| 1882 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1883 | break; |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | return ret_rates; |
| 1888 | } |
| 1889 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1890 | #ifdef CONFIG_IWL4965_HT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1891 | void static iwl4965_set_ht_capab(struct ieee80211_hw *hw, |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1892 | struct ieee80211_ht_cap *ht_cap, |
| 1893 | u8 use_current_config); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1894 | #endif |
| 1895 | |
| 1896 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1897 | * 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] | 1898 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1899 | static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1900 | struct ieee80211_mgmt *frame, |
| 1901 | int left, int is_direct) |
| 1902 | { |
| 1903 | int len = 0; |
| 1904 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1905 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1906 | #ifdef CONFIG_IWL4965_HT |
| 1907 | struct ieee80211_hw_mode *mode; |
| 1908 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1909 | |
| 1910 | /* Make sure there is enough space for the probe request, |
| 1911 | * two mandatory IEs and the data */ |
| 1912 | left -= 24; |
| 1913 | if (left < 0) |
| 1914 | return 0; |
| 1915 | len += 24; |
| 1916 | |
| 1917 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1918 | memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1919 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1920 | memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1921 | frame->seq_ctrl = 0; |
| 1922 | |
| 1923 | /* fill in our indirect SSID IE */ |
| 1924 | /* ...next IE... */ |
| 1925 | |
| 1926 | left -= 2; |
| 1927 | if (left < 0) |
| 1928 | return 0; |
| 1929 | len += 2; |
| 1930 | pos = &(frame->u.probe_req.variable[0]); |
| 1931 | *pos++ = WLAN_EID_SSID; |
| 1932 | *pos++ = 0; |
| 1933 | |
| 1934 | /* fill in our direct SSID IE... */ |
| 1935 | if (is_direct) { |
| 1936 | /* ...next IE... */ |
| 1937 | left -= 2 + priv->essid_len; |
| 1938 | if (left < 0) |
| 1939 | return 0; |
| 1940 | /* ... fill it in... */ |
| 1941 | *pos++ = WLAN_EID_SSID; |
| 1942 | *pos++ = priv->essid_len; |
| 1943 | memcpy(pos, priv->essid, priv->essid_len); |
| 1944 | pos += priv->essid_len; |
| 1945 | len += 2 + priv->essid_len; |
| 1946 | } |
| 1947 | |
| 1948 | /* fill in supported rate */ |
| 1949 | /* ...next IE... */ |
| 1950 | left -= 2; |
| 1951 | if (left < 0) |
| 1952 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1953 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1954 | /* ... fill it in... */ |
| 1955 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1956 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1957 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1958 | /* exclude 60M rate */ |
| 1959 | active_rates = priv->rates_mask; |
| 1960 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1961 | |
| 1962 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1963 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1964 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1965 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1966 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1967 | active_rates &= ~ret_rates; |
| 1968 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1969 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1970 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1971 | active_rates &= ~ret_rates; |
| 1972 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1973 | len += 2 + *pos; |
| 1974 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1975 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1976 | goto fill_end; |
| 1977 | |
| 1978 | /* fill in supported extended rate */ |
| 1979 | /* ...next IE... */ |
| 1980 | left -= 2; |
| 1981 | if (left < 0) |
| 1982 | return 0; |
| 1983 | /* ... fill it in... */ |
| 1984 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1985 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1986 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1987 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1988 | if (*pos > 0) |
| 1989 | len += 2 + *pos; |
| 1990 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1991 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1992 | mode = priv->hw->conf.mode; |
| 1993 | if (mode->ht_info.ht_supported) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1994 | pos += (*pos) + 1; |
| 1995 | *pos++ = WLAN_EID_HT_CAPABILITY; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1996 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 1997 | iwl4965_set_ht_capab(priv->hw, |
| 1998 | (struct ieee80211_ht_cap *)pos, 0); |
| 1999 | len += 2 + sizeof(struct ieee80211_ht_cap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2000 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2001 | #endif /*CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2002 | |
| 2003 | fill_end: |
| 2004 | return (u16)len; |
| 2005 | } |
| 2006 | |
| 2007 | /* |
| 2008 | * QoS support |
| 2009 | */ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2010 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2011 | static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv, |
| 2012 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2013 | { |
| 2014 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2015 | return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
| 2016 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2019 | static void iwl4965_reset_qos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2020 | { |
| 2021 | u16 cw_min = 15; |
| 2022 | u16 cw_max = 1023; |
| 2023 | u8 aifs = 2; |
| 2024 | u8 is_legacy = 0; |
| 2025 | unsigned long flags; |
| 2026 | int i; |
| 2027 | |
| 2028 | spin_lock_irqsave(&priv->lock, flags); |
| 2029 | priv->qos_data.qos_active = 0; |
| 2030 | |
| 2031 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { |
| 2032 | if (priv->qos_data.qos_enable) |
| 2033 | priv->qos_data.qos_active = 1; |
| 2034 | if (!(priv->active_rate & 0xfff0)) { |
| 2035 | cw_min = 31; |
| 2036 | is_legacy = 1; |
| 2037 | } |
| 2038 | } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2039 | if (priv->qos_data.qos_enable) |
| 2040 | priv->qos_data.qos_active = 1; |
| 2041 | } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 2042 | cw_min = 31; |
| 2043 | is_legacy = 1; |
| 2044 | } |
| 2045 | |
| 2046 | if (priv->qos_data.qos_active) |
| 2047 | aifs = 3; |
| 2048 | |
| 2049 | priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); |
| 2050 | priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); |
| 2051 | priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; |
| 2052 | priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; |
| 2053 | priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; |
| 2054 | |
| 2055 | if (priv->qos_data.qos_active) { |
| 2056 | i = 1; |
| 2057 | priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); |
| 2058 | priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); |
| 2059 | priv->qos_data.def_qos_parm.ac[i].aifsn = 7; |
| 2060 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 2061 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2062 | |
| 2063 | i = 2; |
| 2064 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2065 | cpu_to_le16((cw_min + 1) / 2 - 1); |
| 2066 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2067 | cpu_to_le16(cw_max); |
| 2068 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 2069 | if (is_legacy) |
| 2070 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2071 | cpu_to_le16(6016); |
| 2072 | else |
| 2073 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2074 | cpu_to_le16(3008); |
| 2075 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2076 | |
| 2077 | i = 3; |
| 2078 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2079 | cpu_to_le16((cw_min + 1) / 4 - 1); |
| 2080 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2081 | cpu_to_le16((cw_max + 1) / 2 - 1); |
| 2082 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 2083 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2084 | if (is_legacy) |
| 2085 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2086 | cpu_to_le16(3264); |
| 2087 | else |
| 2088 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2089 | cpu_to_le16(1504); |
| 2090 | } else { |
| 2091 | for (i = 1; i < 4; i++) { |
| 2092 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2093 | cpu_to_le16(cw_min); |
| 2094 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2095 | cpu_to_le16(cw_max); |
| 2096 | priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; |
| 2097 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 2098 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2099 | } |
| 2100 | } |
| 2101 | IWL_DEBUG_QOS("set QoS to default \n"); |
| 2102 | |
| 2103 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2104 | } |
| 2105 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2106 | static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2107 | { |
| 2108 | unsigned long flags; |
| 2109 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2110 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2111 | return; |
| 2112 | |
| 2113 | if (!priv->qos_data.qos_enable) |
| 2114 | return; |
| 2115 | |
| 2116 | spin_lock_irqsave(&priv->lock, flags); |
| 2117 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 2118 | |
| 2119 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 2120 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 2121 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2122 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2123 | if (priv->qos_data.qos_active) |
| 2124 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2125 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 2126 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2127 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 2128 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2129 | 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] | 2130 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2131 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2132 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2133 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2134 | if (force || iwl4965_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2135 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 2136 | priv->qos_data.qos_active, |
| 2137 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2138 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2139 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2140 | &(priv->qos_data.def_qos_parm)); |
| 2141 | } |
| 2142 | } |
| 2143 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2144 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2145 | /* |
| 2146 | * Power management (not Tx power!) functions |
| 2147 | */ |
| 2148 | #define MSEC_TO_USEC 1024 |
| 2149 | |
| 2150 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 2151 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
| 2152 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 2153 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 2154 | __constant_cpu_to_le32(X1), \ |
| 2155 | __constant_cpu_to_le32(X2), \ |
| 2156 | __constant_cpu_to_le32(X3), \ |
| 2157 | __constant_cpu_to_le32(X4)} |
| 2158 | |
| 2159 | |
| 2160 | /* default power management (not Tx power) table values */ |
| 2161 | /* for tim 0-10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2162 | static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2163 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2164 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 2165 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 2166 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 2167 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 2168 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 2169 | }; |
| 2170 | |
| 2171 | /* for tim > 10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2172 | static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2173 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2174 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 2175 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 2176 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 2177 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 2178 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 2179 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 2180 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 2181 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 2182 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 2183 | }; |
| 2184 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2185 | int iwl4965_power_init_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2186 | { |
| 2187 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2188 | struct iwl4965_power_mgr *pow_data; |
| 2189 | int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2190 | u16 pci_pm; |
| 2191 | |
| 2192 | IWL_DEBUG_POWER("Initialize power \n"); |
| 2193 | |
| 2194 | pow_data = &(priv->power_data); |
| 2195 | |
| 2196 | memset(pow_data, 0, sizeof(*pow_data)); |
| 2197 | |
| 2198 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 2199 | pow_data->dtim_val = 0xffff; |
| 2200 | |
| 2201 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 2202 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 2203 | |
| 2204 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 2205 | if (rc != 0) |
| 2206 | return 0; |
| 2207 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2208 | struct iwl4965_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2209 | |
| 2210 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 2211 | |
| 2212 | for (i = 0; i < IWL_POWER_AC; i++) { |
| 2213 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 2214 | |
| 2215 | if (pci_pm & 0x1) |
| 2216 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 2217 | else |
| 2218 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 2219 | } |
| 2220 | } |
| 2221 | return rc; |
| 2222 | } |
| 2223 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2224 | static int iwl4965_update_power_cmd(struct iwl4965_priv *priv, |
| 2225 | struct iwl4965_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2226 | { |
| 2227 | int rc = 0, i; |
| 2228 | u8 skip; |
| 2229 | u32 max_sleep = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2230 | struct iwl4965_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2231 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2232 | struct iwl4965_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2233 | |
| 2234 | if (mode > IWL_POWER_INDEX_5) { |
| 2235 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 2236 | return -1; |
| 2237 | } |
| 2238 | pow_data = &(priv->power_data); |
| 2239 | |
| 2240 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 2241 | range = &pow_data->pwr_range_0[0]; |
| 2242 | else |
| 2243 | range = &pow_data->pwr_range_1[1]; |
| 2244 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2245 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2246 | |
| 2247 | #ifdef IWL_MAC80211_DISABLE |
| 2248 | if (priv->assoc_network != NULL) { |
| 2249 | unsigned long flags; |
| 2250 | |
| 2251 | period = priv->assoc_network->tim.tim_period; |
| 2252 | } |
| 2253 | #endif /*IWL_MAC80211_DISABLE */ |
| 2254 | skip = range[mode].no_dtim; |
| 2255 | |
| 2256 | if (period == 0) { |
| 2257 | period = 1; |
| 2258 | skip = 0; |
| 2259 | } |
| 2260 | |
| 2261 | if (skip == 0) { |
| 2262 | max_sleep = period; |
| 2263 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2264 | } else { |
| 2265 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 2266 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 2267 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2268 | } |
| 2269 | |
| 2270 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 2271 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 2272 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 2273 | } |
| 2274 | |
| 2275 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 2276 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 2277 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 2278 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 2279 | le32_to_cpu(cmd->sleep_interval[0]), |
| 2280 | le32_to_cpu(cmd->sleep_interval[1]), |
| 2281 | le32_to_cpu(cmd->sleep_interval[2]), |
| 2282 | le32_to_cpu(cmd->sleep_interval[3]), |
| 2283 | le32_to_cpu(cmd->sleep_interval[4])); |
| 2284 | |
| 2285 | return rc; |
| 2286 | } |
| 2287 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2288 | static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2289 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 2290 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2291 | int rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2292 | struct iwl4965_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2293 | |
| 2294 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2295 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2296 | * else user level */ |
| 2297 | switch (mode) { |
| 2298 | case IWL_POWER_BATTERY: |
| 2299 | final_mode = IWL_POWER_INDEX_3; |
| 2300 | break; |
| 2301 | case IWL_POWER_AC: |
| 2302 | final_mode = IWL_POWER_MODE_CAM; |
| 2303 | break; |
| 2304 | default: |
| 2305 | final_mode = mode; |
| 2306 | break; |
| 2307 | } |
| 2308 | |
| 2309 | cmd.keep_alive_beacons = 0; |
| 2310 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2311 | iwl4965_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2312 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2313 | rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2314 | |
| 2315 | if (final_mode == IWL_POWER_MODE_CAM) |
| 2316 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 2317 | else |
| 2318 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 2319 | |
| 2320 | return rc; |
| 2321 | } |
| 2322 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2323 | 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] | 2324 | { |
| 2325 | /* Filter incoming packets to determine if they are targeted toward |
| 2326 | * this network, discarding packets coming from ourselves */ |
| 2327 | switch (priv->iw_mode) { |
| 2328 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 2329 | /* packets from our adapter are dropped (echo) */ |
| 2330 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 2331 | return 0; |
| 2332 | /* {broad,multi}cast packets to our IBSS go through */ |
| 2333 | if (is_multicast_ether_addr(header->addr1)) |
| 2334 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 2335 | /* packets to our adapter go through */ |
| 2336 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2337 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 2338 | /* packets from our adapter are dropped (echo) */ |
| 2339 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 2340 | return 0; |
| 2341 | /* {broad,multi}cast packets to our BSS go through */ |
| 2342 | if (is_multicast_ether_addr(header->addr1)) |
| 2343 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 2344 | /* packets to our adapter go through */ |
| 2345 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2346 | } |
| 2347 | |
| 2348 | return 1; |
| 2349 | } |
| 2350 | |
| 2351 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2352 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2353 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2354 | { |
| 2355 | switch (status & TX_STATUS_MSK) { |
| 2356 | case TX_STATUS_SUCCESS: |
| 2357 | return "SUCCESS"; |
| 2358 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 2359 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 2360 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 2361 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 2362 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 2363 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 2364 | TX_STATUS_ENTRY(DEST_PS); |
| 2365 | TX_STATUS_ENTRY(ABORTED); |
| 2366 | TX_STATUS_ENTRY(BT_RETRY); |
| 2367 | TX_STATUS_ENTRY(STA_INVALID); |
| 2368 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 2369 | TX_STATUS_ENTRY(TID_DISABLE); |
| 2370 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 2371 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 2372 | TX_STATUS_ENTRY(TX_LOCKED); |
| 2373 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 2374 | } |
| 2375 | |
| 2376 | return "UNKNOWN"; |
| 2377 | } |
| 2378 | |
| 2379 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2380 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2381 | * |
| 2382 | * NOTE: priv->mutex is not required before calling this function |
| 2383 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2384 | static int iwl4965_scan_cancel(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2385 | { |
| 2386 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 2387 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2388 | return 0; |
| 2389 | } |
| 2390 | |
| 2391 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2392 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2393 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 2394 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2395 | queue_work(priv->workqueue, &priv->abort_scan); |
| 2396 | |
| 2397 | } else |
| 2398 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 2399 | |
| 2400 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2401 | } |
| 2402 | |
| 2403 | return 0; |
| 2404 | } |
| 2405 | |
| 2406 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2407 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2408 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 2409 | * |
| 2410 | * NOTE: priv->mutex must be held before calling this function |
| 2411 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2412 | 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] | 2413 | { |
| 2414 | unsigned long now = jiffies; |
| 2415 | int ret; |
| 2416 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2417 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2418 | if (ret && ms) { |
| 2419 | mutex_unlock(&priv->mutex); |
| 2420 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 2421 | test_bit(STATUS_SCANNING, &priv->status)) |
| 2422 | msleep(1); |
| 2423 | mutex_lock(&priv->mutex); |
| 2424 | |
| 2425 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2426 | } |
| 2427 | |
| 2428 | return ret; |
| 2429 | } |
| 2430 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2431 | static void iwl4965_sequence_reset(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2432 | { |
| 2433 | /* Reset ieee stats */ |
| 2434 | |
| 2435 | /* We don't reset the net_device_stats (ieee->stats) on |
| 2436 | * re-association */ |
| 2437 | |
| 2438 | priv->last_seq_num = -1; |
| 2439 | priv->last_frag_num = -1; |
| 2440 | priv->last_packet_time = 0; |
| 2441 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2442 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 2446 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 2447 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2448 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2449 | { |
| 2450 | u16 new_val = 0; |
| 2451 | u16 beacon_factor = 0; |
| 2452 | |
| 2453 | beacon_factor = |
| 2454 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 2455 | / MAX_UCODE_BEACON_INTERVAL; |
| 2456 | new_val = beacon_val / beacon_factor; |
| 2457 | |
| 2458 | return cpu_to_le16(new_val); |
| 2459 | } |
| 2460 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2461 | static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2462 | { |
| 2463 | u64 interval_tm_unit; |
| 2464 | u64 tsf, result; |
| 2465 | unsigned long flags; |
| 2466 | struct ieee80211_conf *conf = NULL; |
| 2467 | u16 beacon_int = 0; |
| 2468 | |
| 2469 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2470 | |
| 2471 | spin_lock_irqsave(&priv->lock, flags); |
| 2472 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1); |
| 2473 | priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0); |
| 2474 | |
| 2475 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 2476 | |
| 2477 | tsf = priv->timestamp1; |
| 2478 | tsf = ((tsf << 32) | priv->timestamp0); |
| 2479 | |
| 2480 | beacon_int = priv->beacon_int; |
| 2481 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2482 | |
| 2483 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 2484 | if (beacon_int == 0) { |
| 2485 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 2486 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 2487 | } else { |
| 2488 | priv->rxon_timing.beacon_interval = |
| 2489 | cpu_to_le16(beacon_int); |
| 2490 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2491 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2492 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2493 | } |
| 2494 | |
| 2495 | priv->rxon_timing.atim_window = 0; |
| 2496 | } else { |
| 2497 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2498 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2499 | /* TODO: we need to get atim_window from upper stack |
| 2500 | * for now we set to 0 */ |
| 2501 | priv->rxon_timing.atim_window = 0; |
| 2502 | } |
| 2503 | |
| 2504 | interval_tm_unit = |
| 2505 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 2506 | result = do_div(tsf, interval_tm_unit); |
| 2507 | priv->rxon_timing.beacon_init_val = |
| 2508 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 2509 | |
| 2510 | IWL_DEBUG_ASSOC |
| 2511 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 2512 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 2513 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 2514 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 2515 | } |
| 2516 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2517 | static int iwl4965_scan_initiate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2518 | { |
| 2519 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2520 | IWL_ERROR("APs don't scan.\n"); |
| 2521 | return 0; |
| 2522 | } |
| 2523 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2524 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2525 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 2526 | return -EIO; |
| 2527 | } |
| 2528 | |
| 2529 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2530 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 2531 | return -EAGAIN; |
| 2532 | } |
| 2533 | |
| 2534 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2535 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 2536 | "Queuing.\n"); |
| 2537 | return -EAGAIN; |
| 2538 | } |
| 2539 | |
| 2540 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 2541 | priv->scan_bands = 2; |
| 2542 | set_bit(STATUS_SCANNING, &priv->status); |
| 2543 | priv->scan_start = jiffies; |
| 2544 | priv->scan_pass_start = priv->scan_start; |
| 2545 | |
| 2546 | queue_work(priv->workqueue, &priv->request_scan); |
| 2547 | |
| 2548 | return 0; |
| 2549 | } |
| 2550 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2551 | 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] | 2552 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2553 | struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2554 | |
| 2555 | if (hw_decrypt) |
| 2556 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 2557 | else |
| 2558 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 2559 | |
| 2560 | return 0; |
| 2561 | } |
| 2562 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2563 | 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] | 2564 | { |
| 2565 | if (phymode == MODE_IEEE80211A) { |
| 2566 | priv->staging_rxon.flags &= |
| 2567 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 2568 | | RXON_FLG_CCK_MSK); |
| 2569 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2570 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2571 | /* Copied from iwl4965_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2572 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2573 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2574 | else |
| 2575 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2576 | |
| 2577 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2578 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2579 | |
| 2580 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 2581 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 2582 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2587 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2588 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2589 | static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2590 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2591 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2592 | |
| 2593 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 2594 | |
| 2595 | switch (priv->iw_mode) { |
| 2596 | case IEEE80211_IF_TYPE_AP: |
| 2597 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 2598 | break; |
| 2599 | |
| 2600 | case IEEE80211_IF_TYPE_STA: |
| 2601 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 2602 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 2603 | break; |
| 2604 | |
| 2605 | case IEEE80211_IF_TYPE_IBSS: |
| 2606 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 2607 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2608 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 2609 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2610 | break; |
| 2611 | |
| 2612 | case IEEE80211_IF_TYPE_MNTR: |
| 2613 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 2614 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 2615 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2616 | break; |
| 2617 | } |
| 2618 | |
| 2619 | #if 0 |
| 2620 | /* TODO: Figure out when short_preamble would be set and cache from |
| 2621 | * that */ |
| 2622 | if (!hw_to_local(priv->hw)->short_preamble) |
| 2623 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2624 | else |
| 2625 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2626 | #endif |
| 2627 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2628 | ch_info = iwl4965_get_channel_info(priv, priv->phymode, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2629 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2630 | |
| 2631 | if (!ch_info) |
| 2632 | ch_info = &priv->channel_info[0]; |
| 2633 | |
| 2634 | /* |
| 2635 | * in some case A channels are all non IBSS |
| 2636 | * in this case force B/G channel |
| 2637 | */ |
| 2638 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 2639 | !(is_channel_ibss(ch_info))) |
| 2640 | ch_info = &priv->channel_info[0]; |
| 2641 | |
| 2642 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
| 2643 | if (is_channel_a_band(ch_info)) |
| 2644 | priv->phymode = MODE_IEEE80211A; |
| 2645 | else |
| 2646 | priv->phymode = MODE_IEEE80211G; |
| 2647 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2648 | iwl4965_set_flags_for_phymode(priv, priv->phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2649 | |
| 2650 | priv->staging_rxon.ofdm_basic_rates = |
| 2651 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2652 | priv->staging_rxon.cck_basic_rates = |
| 2653 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2654 | |
| 2655 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 2656 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 2657 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2658 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 2659 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 2660 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 2661 | iwl4965_set_rxon_chain(priv); |
| 2662 | } |
| 2663 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2664 | static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2665 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2666 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2667 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2668 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2669 | ch_info = iwl4965_get_channel_info(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2670 | priv->phymode, |
| 2671 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2672 | |
| 2673 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 2674 | IWL_ERROR("channel %d not IBSS channel\n", |
| 2675 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2676 | return -EINVAL; |
| 2677 | } |
| 2678 | } |
| 2679 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2680 | priv->iw_mode = mode; |
| 2681 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2682 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2683 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2684 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2685 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2686 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2687 | /* dont commit rxon if rf-kill is on*/ |
| 2688 | if (!iwl4965_is_ready_rf(priv)) |
| 2689 | return -EAGAIN; |
| 2690 | |
| 2691 | cancel_delayed_work(&priv->scan_check); |
| 2692 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 2693 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 2694 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2695 | return -EAGAIN; |
| 2696 | } |
| 2697 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2698 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2699 | |
| 2700 | return 0; |
| 2701 | } |
| 2702 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2703 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2704 | struct ieee80211_tx_control *ctl, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2705 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2706 | struct sk_buff *skb_frag, |
| 2707 | int last_frag) |
| 2708 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2709 | struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2710 | |
| 2711 | switch (keyinfo->alg) { |
| 2712 | case ALG_CCMP: |
| 2713 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2714 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
| 2715 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 2716 | break; |
| 2717 | |
| 2718 | case ALG_TKIP: |
| 2719 | #if 0 |
| 2720 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2721 | |
| 2722 | if (last_frag) |
| 2723 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2724 | 8); |
| 2725 | else |
| 2726 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2727 | #endif |
| 2728 | break; |
| 2729 | |
| 2730 | case ALG_WEP: |
| 2731 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
| 2732 | (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
| 2733 | |
| 2734 | if (keyinfo->keylen == 13) |
| 2735 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2736 | |
| 2737 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2738 | |
| 2739 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
| 2740 | "with key %d\n", ctl->key_idx); |
| 2741 | break; |
| 2742 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2743 | default: |
| 2744 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 2745 | break; |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | /* |
| 2750 | * handle build REPLY_TX command notification. |
| 2751 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2752 | static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv, |
| 2753 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2754 | struct ieee80211_tx_control *ctrl, |
| 2755 | struct ieee80211_hdr *hdr, |
| 2756 | int is_unicast, u8 std_id) |
| 2757 | { |
| 2758 | __le16 *qc; |
| 2759 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2760 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 2761 | |
| 2762 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2763 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 2764 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 2765 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 2766 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2767 | if (ieee80211_is_probe_response(fc) && |
| 2768 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2769 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2770 | } else { |
| 2771 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2772 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2773 | } |
| 2774 | |
| 2775 | cmd->cmd.tx.sta_id = std_id; |
| 2776 | if (ieee80211_get_morefrag(hdr)) |
| 2777 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2778 | |
| 2779 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2780 | if (qc) { |
| 2781 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 2782 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 2783 | } else |
| 2784 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2785 | |
| 2786 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 2787 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2788 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 2789 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 2790 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2791 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2792 | } |
| 2793 | |
| 2794 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2795 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2796 | |
| 2797 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 2798 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 2799 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 2800 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2801 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2802 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2803 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2804 | } else |
| 2805 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
| 2806 | |
| 2807 | cmd->cmd.tx.driver_txop = 0; |
| 2808 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2809 | cmd->cmd.tx.next_frame_len = 0; |
| 2810 | } |
| 2811 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2812 | /** |
| 2813 | * iwl4965_get_sta_id - Find station's index within station table |
| 2814 | * |
| 2815 | * If new IBSS station, create new entry in station table |
| 2816 | */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2817 | static int iwl4965_get_sta_id(struct iwl4965_priv *priv, |
| 2818 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2819 | { |
| 2820 | int sta_id; |
| 2821 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2822 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2823 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2824 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2825 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2826 | is_multicast_ether_addr(hdr->addr1)) |
| 2827 | return priv->hw_setting.bcast_sta_id; |
| 2828 | |
| 2829 | switch (priv->iw_mode) { |
| 2830 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2831 | /* If we are a client station in a BSS network, use the special |
| 2832 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2833 | case IEEE80211_IF_TYPE_STA: |
| 2834 | return IWL_AP_ID; |
| 2835 | |
| 2836 | /* If we are an AP, then find the station, or use BCAST */ |
| 2837 | case IEEE80211_IF_TYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2838 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2839 | if (sta_id != IWL_INVALID_STATION) |
| 2840 | return sta_id; |
| 2841 | return priv->hw_setting.bcast_sta_id; |
| 2842 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2843 | /* If this frame is going out to an IBSS network, find the station, |
| 2844 | * or create a new station table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2845 | case IEEE80211_IF_TYPE_IBSS: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2846 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2847 | if (sta_id != IWL_INVALID_STATION) |
| 2848 | return sta_id; |
| 2849 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2850 | /* Create new station table entry */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame^] | 2851 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, |
| 2852 | 0, CMD_ASYNC, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2853 | |
| 2854 | if (sta_id != IWL_INVALID_STATION) |
| 2855 | return sta_id; |
| 2856 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2857 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2858 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2859 | print_mac(mac, hdr->addr1)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2860 | iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2861 | return priv->hw_setting.bcast_sta_id; |
| 2862 | |
| 2863 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2864 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2865 | return priv->hw_setting.bcast_sta_id; |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | /* |
| 2870 | * start REPLY_TX command process |
| 2871 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2872 | static int iwl4965_tx_skb(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2873 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 2874 | { |
| 2875 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2876 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2877 | u32 *control_flags; |
| 2878 | int txq_id = ctl->queue; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2879 | struct iwl4965_tx_queue *txq = NULL; |
| 2880 | struct iwl4965_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2881 | dma_addr_t phys_addr; |
| 2882 | dma_addr_t txcmd_phys; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2883 | struct iwl4965_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2884 | u16 len, idx, len_org; |
| 2885 | u8 id, hdr_len, unicast; |
| 2886 | u8 sta_id; |
| 2887 | u16 seq_number = 0; |
| 2888 | u16 fc; |
| 2889 | __le16 *qc; |
| 2890 | u8 wait_write_ptr = 0; |
| 2891 | unsigned long flags; |
| 2892 | int rc; |
| 2893 | |
| 2894 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2895 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2896 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2897 | goto drop_unlock; |
| 2898 | } |
| 2899 | |
| 2900 | if (!priv->interface_id) { |
| 2901 | IWL_DEBUG_DROP("Dropping - !priv->interface_id\n"); |
| 2902 | goto drop_unlock; |
| 2903 | } |
| 2904 | |
| 2905 | if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) { |
| 2906 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 2907 | goto drop_unlock; |
| 2908 | } |
| 2909 | |
| 2910 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2911 | id = 0; |
| 2912 | |
| 2913 | fc = le16_to_cpu(hdr->frame_control); |
| 2914 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2915 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2916 | if (ieee80211_is_auth(fc)) |
| 2917 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 2918 | else if (ieee80211_is_assoc_request(fc)) |
| 2919 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 2920 | else if (ieee80211_is_reassoc_request(fc)) |
| 2921 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2922 | #endif |
| 2923 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2924 | /* drop all data frame if we are not associated */ |
| 2925 | if (!iwl4965_is_associated(priv) && !priv->assoc_id && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2926 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2927 | IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2928 | goto drop_unlock; |
| 2929 | } |
| 2930 | |
| 2931 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2932 | |
| 2933 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2934 | |
| 2935 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2936 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2937 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2938 | DECLARE_MAC_BUF(mac); |
| 2939 | |
| 2940 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 2941 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2942 | goto drop; |
| 2943 | } |
| 2944 | |
| 2945 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2946 | |
| 2947 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2948 | if (qc) { |
| 2949 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2950 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 2951 | IEEE80211_SCTL_SEQ; |
| 2952 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2953 | (hdr->seq_ctrl & |
| 2954 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2955 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2956 | #ifdef CONFIG_IWL4965_HT |
| 2957 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2958 | /* aggregation is on for this <sta,tid> */ |
| 2959 | if (ctl->flags & IEEE80211_TXCTL_HT_MPDU_AGG) |
| 2960 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2961 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 2962 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2963 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2964 | |
| 2965 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2966 | txq = &priv->txq[txq_id]; |
| 2967 | q = &txq->q; |
| 2968 | |
| 2969 | spin_lock_irqsave(&priv->lock, flags); |
| 2970 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2971 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2972 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2973 | memset(tfd, 0, sizeof(*tfd)); |
| 2974 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2975 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2976 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2977 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2978 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2979 | txq->txb[q->write_ptr].skb[0] = skb; |
| 2980 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2981 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2982 | |
| 2983 | /* 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] | 2984 | out_cmd = &txq->cmd[idx]; |
| 2985 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2986 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2987 | |
| 2988 | /* |
| 2989 | * Set up the Tx-command (not MAC!) header. |
| 2990 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2991 | * after Tx, uCode's Tx response will return this value so driver can |
| 2992 | * locate the frame within the tx queue and do post-tx processing. |
| 2993 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2994 | out_cmd->hdr.cmd = REPLY_TX; |
| 2995 | 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] | 2996 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2997 | |
| 2998 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2999 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 3000 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3001 | /* |
| 3002 | * Use the first empty entry in this queue's command buffer array |
| 3003 | * to contain the Tx command and MAC header concatenated together |
| 3004 | * (payload data will be in another buffer). |
| 3005 | * Size of this varies, due to varying MAC header length. |
| 3006 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 3007 | * of the MAC header (device reads on dword boundaries). |
| 3008 | * We'll tell device about this padding later. |
| 3009 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | len = priv->hw_setting.tx_cmd_len + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3011 | sizeof(struct iwl4965_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3012 | |
| 3013 | len_org = len; |
| 3014 | len = (len + 3) & ~3; |
| 3015 | |
| 3016 | if (len_org != len) |
| 3017 | len_org = 1; |
| 3018 | else |
| 3019 | len_org = 0; |
| 3020 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3021 | /* Physical address of this Tx command's header (not MAC header!), |
| 3022 | * within command buffer array. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3023 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx + |
| 3024 | offsetof(struct iwl4965_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3025 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3026 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 3027 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3028 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3029 | |
| 3030 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3031 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3032 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3033 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 3034 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3035 | len = skb->len - hdr_len; |
| 3036 | if (len) { |
| 3037 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 3038 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3039 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3042 | /* Tell 4965 about any 2-byte padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3043 | if (len_org) |
| 3044 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 3045 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3046 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3047 | len = (u16)skb->len; |
| 3048 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 3049 | |
| 3050 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3051 | 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] | 3052 | |
| 3053 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3054 | 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] | 3055 | |
| 3056 | iwl4965_tx_cmd(priv, out_cmd, sta_id, txcmd_phys, |
| 3057 | hdr, hdr_len, ctl, NULL); |
| 3058 | |
| 3059 | if (!ieee80211_get_morefrag(hdr)) { |
| 3060 | txq->need_update = 1; |
| 3061 | if (qc) { |
| 3062 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 3063 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 3064 | } |
| 3065 | } else { |
| 3066 | wait_write_ptr = 1; |
| 3067 | txq->need_update = 0; |
| 3068 | } |
| 3069 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3070 | iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3071 | sizeof(out_cmd->cmd.tx)); |
| 3072 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3073 | 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] | 3074 | ieee80211_get_hdrlen(fc)); |
| 3075 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3076 | /* Set up entry for this TFD in Tx byte-count array */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3077 | iwl4965_tx_queue_update_wr_ptr(priv, txq, len); |
| 3078 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3079 | /* Tell device the write index *just past* this latest filled TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3080 | q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 3081 | rc = iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3082 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3083 | |
| 3084 | if (rc) |
| 3085 | return rc; |
| 3086 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3087 | if ((iwl4965_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3088 | && priv->mac80211_registered) { |
| 3089 | if (wait_write_ptr) { |
| 3090 | spin_lock_irqsave(&priv->lock, flags); |
| 3091 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3092 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3093 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3094 | } |
| 3095 | |
| 3096 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 3097 | } |
| 3098 | |
| 3099 | return 0; |
| 3100 | |
| 3101 | drop_unlock: |
| 3102 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3103 | drop: |
| 3104 | return -1; |
| 3105 | } |
| 3106 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3107 | static void iwl4965_set_rate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3108 | { |
| 3109 | const struct ieee80211_hw_mode *hw = NULL; |
| 3110 | struct ieee80211_rate *rate; |
| 3111 | int i; |
| 3112 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3113 | hw = iwl4965_get_hw_mode(priv, priv->phymode); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 3114 | if (!hw) { |
| 3115 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 3116 | return; |
| 3117 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3118 | |
| 3119 | priv->active_rate = 0; |
| 3120 | priv->active_rate_basic = 0; |
| 3121 | |
| 3122 | IWL_DEBUG_RATE("Setting rates for 802.11%c\n", |
| 3123 | hw->mode == MODE_IEEE80211A ? |
| 3124 | 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g')); |
| 3125 | |
| 3126 | for (i = 0; i < hw->num_rates; i++) { |
| 3127 | rate = &(hw->rates[i]); |
| 3128 | if ((rate->val < IWL_RATE_COUNT) && |
| 3129 | (rate->flags & IEEE80211_RATE_SUPPORTED)) { |
| 3130 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3131 | rate->val, iwl4965_rates[rate->val].plcp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3132 | (rate->flags & IEEE80211_RATE_BASIC) ? |
| 3133 | "*" : ""); |
| 3134 | priv->active_rate |= (1 << rate->val); |
| 3135 | if (rate->flags & IEEE80211_RATE_BASIC) |
| 3136 | priv->active_rate_basic |= (1 << rate->val); |
| 3137 | } else |
| 3138 | IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3139 | rate->val, iwl4965_rates[rate->val].plcp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 3143 | priv->active_rate, priv->active_rate_basic); |
| 3144 | |
| 3145 | /* |
| 3146 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 3147 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 3148 | * OFDM |
| 3149 | */ |
| 3150 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 3151 | priv->staging_rxon.cck_basic_rates = |
| 3152 | ((priv->active_rate_basic & |
| 3153 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3154 | else |
| 3155 | priv->staging_rxon.cck_basic_rates = |
| 3156 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3157 | |
| 3158 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 3159 | priv->staging_rxon.ofdm_basic_rates = |
| 3160 | ((priv->active_rate_basic & |
| 3161 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 3162 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3163 | else |
| 3164 | priv->staging_rxon.ofdm_basic_rates = |
| 3165 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3166 | } |
| 3167 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3168 | 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] | 3169 | { |
| 3170 | unsigned long flags; |
| 3171 | |
| 3172 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 3173 | return; |
| 3174 | |
| 3175 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 3176 | disable_radio ? "OFF" : "ON"); |
| 3177 | |
| 3178 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3179 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3180 | /* FIXME: This is a workaround for AP */ |
| 3181 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 3182 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3183 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3184 | CSR_UCODE_SW_BIT_RFKILL); |
| 3185 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3186 | iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3187 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3188 | } |
| 3189 | return; |
| 3190 | } |
| 3191 | |
| 3192 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3193 | 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] | 3194 | |
| 3195 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3196 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3197 | |
| 3198 | /* wake up ucode */ |
| 3199 | msleep(10); |
| 3200 | |
| 3201 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3202 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 3203 | if (!iwl4965_grab_nic_access(priv)) |
| 3204 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3205 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3206 | |
| 3207 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 3208 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3209 | "disabled by HW switch\n"); |
| 3210 | return; |
| 3211 | } |
| 3212 | |
| 3213 | queue_work(priv->workqueue, &priv->restart); |
| 3214 | return; |
| 3215 | } |
| 3216 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3217 | 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] | 3218 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 3219 | { |
| 3220 | u16 fc = |
| 3221 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 3222 | |
| 3223 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 3224 | return; |
| 3225 | |
| 3226 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 3227 | return; |
| 3228 | |
| 3229 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 3230 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 3231 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 3232 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3233 | RX_RES_STATUS_BAD_ICV_MIC) |
| 3234 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 3235 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 3236 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 3237 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3238 | RX_RES_STATUS_DECRYPT_OK) { |
| 3239 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 3240 | stats->flag |= RX_FLAG_DECRYPTED; |
| 3241 | } |
| 3242 | break; |
| 3243 | |
| 3244 | default: |
| 3245 | break; |
| 3246 | } |
| 3247 | } |
| 3248 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3249 | void iwl4965_handle_data_packet_monitor(struct iwl4965_priv *priv, |
| 3250 | struct iwl4965_rx_mem_buffer *rxb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3251 | void *data, short len, |
| 3252 | struct ieee80211_rx_status *stats, |
| 3253 | u16 phy_flags) |
| 3254 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3255 | struct iwl4965_rt_rx_hdr *iwl4965_rt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3256 | |
| 3257 | /* First cache any information we need before we overwrite |
| 3258 | * the information provided in the skb from the hardware */ |
| 3259 | s8 signal = stats->ssi; |
| 3260 | s8 noise = 0; |
| 3261 | int rate = stats->rate; |
| 3262 | u64 tsf = stats->mactime; |
| 3263 | __le16 phy_flags_hw = cpu_to_le16(phy_flags); |
| 3264 | |
| 3265 | /* We received data from the HW, so stop the watchdog */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3266 | if (len > IWL_RX_BUF_SIZE - sizeof(*iwl4965_rt)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3267 | IWL_DEBUG_DROP("Dropping too large packet in monitor\n"); |
| 3268 | return; |
| 3269 | } |
| 3270 | |
| 3271 | /* copy the frame data to write after where the radiotap header goes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3272 | iwl4965_rt = (void *)rxb->skb->data; |
| 3273 | memmove(iwl4965_rt->payload, data, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3274 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3275 | iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 3276 | iwl4965_rt->rt_hdr.it_pad = 0; /* always good to zero */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3277 | |
| 3278 | /* total header + data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3279 | iwl4965_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl4965_rt)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3280 | |
| 3281 | /* Set the size of the skb to the size of the frame */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3282 | skb_put(rxb->skb, sizeof(*iwl4965_rt) + len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3283 | |
| 3284 | /* Big bitfield of all the fields we provide in radiotap */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3285 | iwl4965_rt->rt_hdr.it_present = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3286 | cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) | |
| 3287 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
| 3288 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 3289 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 3290 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 3291 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 3292 | (1 << IEEE80211_RADIOTAP_ANTENNA)); |
| 3293 | |
| 3294 | /* Zero the flags, we'll add to them as we go */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3295 | iwl4965_rt->rt_flags = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3296 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3297 | iwl4965_rt->rt_tsf = cpu_to_le64(tsf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3298 | |
| 3299 | /* Convert to dBm */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3300 | iwl4965_rt->rt_dbmsignal = signal; |
| 3301 | iwl4965_rt->rt_dbmnoise = noise; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3302 | |
| 3303 | /* Convert the channel frequency and set the flags */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3304 | iwl4965_rt->rt_channelMHz = cpu_to_le16(stats->freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3305 | if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3306 | iwl4965_rt->rt_chbitmask = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3307 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); |
| 3308 | else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3309 | iwl4965_rt->rt_chbitmask = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3310 | cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); |
| 3311 | else /* 802.11g */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3312 | iwl4965_rt->rt_chbitmask = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3313 | cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ)); |
| 3314 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3315 | rate = iwl4965_rate_index_from_plcp(rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3316 | if (rate == -1) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3317 | iwl4965_rt->rt_rate = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3318 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3319 | iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3320 | |
| 3321 | /* antenna number */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3322 | iwl4965_rt->rt_antenna = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3323 | le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4; |
| 3324 | |
| 3325 | /* set the preamble flag if we have it */ |
| 3326 | if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3327 | iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3328 | |
| 3329 | IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); |
| 3330 | |
| 3331 | stats->flag |= RX_FLAG_RADIOTAP; |
| 3332 | ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); |
| 3333 | rxb->skb = NULL; |
| 3334 | } |
| 3335 | |
| 3336 | |
| 3337 | #define IWL_PACKET_RETRY_TIME HZ |
| 3338 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3339 | 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] | 3340 | { |
| 3341 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 3342 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 3343 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 3344 | u16 *last_seq, *last_frag; |
| 3345 | unsigned long *last_time; |
| 3346 | |
| 3347 | switch (priv->iw_mode) { |
| 3348 | case IEEE80211_IF_TYPE_IBSS:{ |
| 3349 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3350 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3351 | u8 *mac = header->addr2; |
| 3352 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 3353 | |
| 3354 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3355 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3356 | if (!compare_ether_addr(entry->mac, mac)) |
| 3357 | break; |
| 3358 | } |
| 3359 | if (p == &priv->ibss_mac_hash[index]) { |
| 3360 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 3361 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3362 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3363 | return 0; |
| 3364 | } |
| 3365 | memcpy(entry->mac, mac, ETH_ALEN); |
| 3366 | entry->seq_num = seq; |
| 3367 | entry->frag_num = frag; |
| 3368 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3369 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3370 | return 0; |
| 3371 | } |
| 3372 | last_seq = &entry->seq_num; |
| 3373 | last_frag = &entry->frag_num; |
| 3374 | last_time = &entry->packet_time; |
| 3375 | break; |
| 3376 | } |
| 3377 | case IEEE80211_IF_TYPE_STA: |
| 3378 | last_seq = &priv->last_seq_num; |
| 3379 | last_frag = &priv->last_frag_num; |
| 3380 | last_time = &priv->last_packet_time; |
| 3381 | break; |
| 3382 | default: |
| 3383 | return 0; |
| 3384 | } |
| 3385 | if ((*last_seq == seq) && |
| 3386 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 3387 | if (*last_frag == frag) |
| 3388 | goto drop; |
| 3389 | if (*last_frag + 1 != frag) |
| 3390 | /* out-of-order fragment */ |
| 3391 | goto drop; |
| 3392 | } else |
| 3393 | *last_seq = seq; |
| 3394 | |
| 3395 | *last_frag = frag; |
| 3396 | *last_time = jiffies; |
| 3397 | return 0; |
| 3398 | |
| 3399 | drop: |
| 3400 | return 1; |
| 3401 | } |
| 3402 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3403 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3404 | |
| 3405 | #include "iwl-spectrum.h" |
| 3406 | |
| 3407 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 3408 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 3409 | #define TIME_UNIT 1024 |
| 3410 | |
| 3411 | /* |
| 3412 | * extended beacon time format |
| 3413 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 3414 | * the high 1 byte is the beacon counts |
| 3415 | * the lower 3 bytes is the time in usec within one beacon interval |
| 3416 | */ |
| 3417 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3418 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3419 | { |
| 3420 | u32 quot; |
| 3421 | u32 rem; |
| 3422 | u32 interval = beacon_interval * 1024; |
| 3423 | |
| 3424 | if (!interval || !usec) |
| 3425 | return 0; |
| 3426 | |
| 3427 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 3428 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 3429 | |
| 3430 | return (quot << 24) + rem; |
| 3431 | } |
| 3432 | |
| 3433 | /* base is usually what we get from ucode with each received frame, |
| 3434 | * the same as HW timer counter counting down |
| 3435 | */ |
| 3436 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3437 | 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] | 3438 | { |
| 3439 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 3440 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 3441 | u32 interval = beacon_interval * TIME_UNIT; |
| 3442 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 3443 | (addon & BEACON_TIME_MASK_HIGH); |
| 3444 | |
| 3445 | if (base_low > addon_low) |
| 3446 | res += base_low - addon_low; |
| 3447 | else if (base_low < addon_low) { |
| 3448 | res += interval + base_low - addon_low; |
| 3449 | res += (1 << 24); |
| 3450 | } else |
| 3451 | res += (1 << 24); |
| 3452 | |
| 3453 | return cpu_to_le32(res); |
| 3454 | } |
| 3455 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3456 | static int iwl4965_get_measurement(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3457 | struct ieee80211_measurement_params *params, |
| 3458 | u8 type) |
| 3459 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3460 | struct iwl4965_spectrum_cmd spectrum; |
| 3461 | struct iwl4965_rx_packet *res; |
| 3462 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3463 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 3464 | .data = (void *)&spectrum, |
| 3465 | .meta.flags = CMD_WANT_SKB, |
| 3466 | }; |
| 3467 | u32 add_time = le64_to_cpu(params->start_time); |
| 3468 | int rc; |
| 3469 | int spectrum_resp_status; |
| 3470 | int duration = le16_to_cpu(params->duration); |
| 3471 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3472 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3473 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3474 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3475 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 3476 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3477 | |
| 3478 | memset(&spectrum, 0, sizeof(spectrum)); |
| 3479 | |
| 3480 | spectrum.channel_count = cpu_to_le16(1); |
| 3481 | spectrum.flags = |
| 3482 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 3483 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 3484 | cmd.len = sizeof(spectrum); |
| 3485 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 3486 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3487 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3488 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3489 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3490 | add_time, |
| 3491 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3492 | else |
| 3493 | spectrum.start_time = 0; |
| 3494 | |
| 3495 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 3496 | spectrum.channels[0].channel = params->channel; |
| 3497 | spectrum.channels[0].type = type; |
| 3498 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 3499 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 3500 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 3501 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3502 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3503 | if (rc) |
| 3504 | return rc; |
| 3505 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3506 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3507 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 3508 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 3509 | rc = -EIO; |
| 3510 | } |
| 3511 | |
| 3512 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 3513 | switch (spectrum_resp_status) { |
| 3514 | case 0: /* Command will be handled */ |
| 3515 | if (res->u.spectrum.id != 0xff) { |
| 3516 | IWL_DEBUG_INFO |
| 3517 | ("Replaced existing measurement: %d\n", |
| 3518 | res->u.spectrum.id); |
| 3519 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 3520 | } |
| 3521 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 3522 | rc = 0; |
| 3523 | break; |
| 3524 | |
| 3525 | case 1: /* Command will not be handled */ |
| 3526 | rc = -EAGAIN; |
| 3527 | break; |
| 3528 | } |
| 3529 | |
| 3530 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 3531 | |
| 3532 | return rc; |
| 3533 | } |
| 3534 | #endif |
| 3535 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3536 | static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv, |
| 3537 | struct iwl4965_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3538 | { |
| 3539 | |
| 3540 | tx_sta->status.ack_signal = 0; |
| 3541 | tx_sta->status.excessive_retries = 0; |
| 3542 | tx_sta->status.queue_length = 0; |
| 3543 | tx_sta->status.queue_number = 0; |
| 3544 | |
| 3545 | if (in_interrupt()) |
| 3546 | ieee80211_tx_status_irqsafe(priv->hw, |
| 3547 | tx_sta->skb[0], &(tx_sta->status)); |
| 3548 | else |
| 3549 | ieee80211_tx_status(priv->hw, |
| 3550 | tx_sta->skb[0], &(tx_sta->status)); |
| 3551 | |
| 3552 | tx_sta->skb[0] = NULL; |
| 3553 | } |
| 3554 | |
| 3555 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3556 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3557 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3558 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3559 | * need to be reclaimed. As result, some free space forms. If there is |
| 3560 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3561 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3562 | 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] | 3563 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3564 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
| 3565 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3566 | int nfreed = 0; |
| 3567 | |
| 3568 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 3569 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 3570 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3571 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3572 | return 0; |
| 3573 | } |
| 3574 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3575 | for (index = iwl4965_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3576 | q->read_ptr != index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3577 | 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] | 3578 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3579 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3580 | &(txq->txb[txq->q.read_ptr])); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3581 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3582 | } else if (nfreed > 1) { |
| 3583 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3584 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3585 | queue_work(priv->workqueue, &priv->restart); |
| 3586 | } |
| 3587 | nfreed++; |
| 3588 | } |
| 3589 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3590 | if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3591 | (txq_id != IWL_CMD_QUEUE_NUM) && |
| 3592 | priv->mac80211_registered) |
| 3593 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3594 | |
| 3595 | |
| 3596 | return nfreed; |
| 3597 | } |
| 3598 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3599 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3600 | { |
| 3601 | status &= TX_STATUS_MSK; |
| 3602 | return (status == TX_STATUS_SUCCESS) |
| 3603 | || (status == TX_STATUS_DIRECT_DONE); |
| 3604 | } |
| 3605 | |
| 3606 | /****************************************************************************** |
| 3607 | * |
| 3608 | * Generic RX handler implementations |
| 3609 | * |
| 3610 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3611 | #ifdef CONFIG_IWL4965_HT |
| 3612 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3613 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3614 | static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3615 | struct ieee80211_hdr *hdr) |
| 3616 | { |
| 3617 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 3618 | return IWL_AP_ID; |
| 3619 | else { |
| 3620 | u8 *da = ieee80211_get_DA(hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3621 | return iwl4965_hw_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3622 | } |
| 3623 | } |
| 3624 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3625 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
| 3626 | struct iwl4965_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3627 | { |
| 3628 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 3629 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 3630 | txb[idx].skb[0]->data; |
| 3631 | return NULL; |
| 3632 | } |
| 3633 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3634 | 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] | 3635 | { |
| 3636 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 3637 | tx_resp->frame_count); |
| 3638 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 3639 | |
| 3640 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3641 | |
| 3642 | /** |
| 3643 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 3644 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3645 | static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv, |
| 3646 | struct iwl4965_ht_agg *agg, |
| 3647 | struct iwl4965_tx_resp *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3648 | u16 start_idx) |
| 3649 | { |
| 3650 | u32 status; |
| 3651 | __le32 *frame_status = &tx_resp->status; |
| 3652 | struct ieee80211_tx_status *tx_status = NULL; |
| 3653 | struct ieee80211_hdr *hdr = NULL; |
| 3654 | int i, sh; |
| 3655 | int txq_id, idx; |
| 3656 | u16 seq; |
| 3657 | |
| 3658 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3659 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3660 | |
| 3661 | agg->frame_count = tx_resp->frame_count; |
| 3662 | agg->start_idx = start_idx; |
| 3663 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3664 | agg->bitmap0 = agg->bitmap1 = 0; |
| 3665 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3666 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3667 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3668 | /* Only one frame was attempted; no block-ack will arrive */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3669 | struct iwl4965_tx_queue *txq ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3670 | status = le32_to_cpu(frame_status[0]); |
| 3671 | |
| 3672 | txq_id = agg->txq_id; |
| 3673 | txq = &priv->txq[txq_id]; |
| 3674 | /* FIXME: code repetition */ |
| 3675 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d \n", |
| 3676 | agg->frame_count, agg->start_idx); |
| 3677 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3678 | tx_status = &(priv->txq[txq_id].txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3679 | tx_status->retry_count = tx_resp->failure_frame; |
| 3680 | tx_status->queue_number = status & 0xff; |
| 3681 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3682 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3683 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3684 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3685 | IEEE80211_TX_STATUS_ACK : 0; |
| 3686 | tx_status->control.tx_rate = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3687 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3688 | /* FIXME: code repetition end */ |
| 3689 | |
| 3690 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 3691 | status & 0xff, tx_resp->failure_frame); |
| 3692 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3693 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3694 | |
| 3695 | agg->wait_for_ba = 0; |
| 3696 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3697 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3698 | u64 bitmap = 0; |
| 3699 | int start = agg->start_idx; |
| 3700 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3701 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3702 | for (i = 0; i < agg->frame_count; i++) { |
| 3703 | u16 sc; |
| 3704 | status = le32_to_cpu(frame_status[i]); |
| 3705 | seq = status >> 16; |
| 3706 | idx = SEQ_TO_INDEX(seq); |
| 3707 | txq_id = SEQ_TO_QUEUE(seq); |
| 3708 | |
| 3709 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 3710 | AGG_TX_STATE_ABORT_MSK)) |
| 3711 | continue; |
| 3712 | |
| 3713 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 3714 | agg->frame_count, txq_id, idx); |
| 3715 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3716 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3717 | |
| 3718 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 3719 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 3720 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 3721 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 3722 | idx, SEQ_TO_SN(sc), |
| 3723 | hdr->seq_ctrl); |
| 3724 | return -1; |
| 3725 | } |
| 3726 | |
| 3727 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 3728 | i, idx, SEQ_TO_SN(sc)); |
| 3729 | |
| 3730 | sh = idx - start; |
| 3731 | if (sh > 64) { |
| 3732 | sh = (start - idx) + 0xff; |
| 3733 | bitmap = bitmap << sh; |
| 3734 | sh = 0; |
| 3735 | start = idx; |
| 3736 | } else if (sh < -64) |
| 3737 | sh = 0xff - (start - idx); |
| 3738 | else if (sh < 0) { |
| 3739 | sh = start - idx; |
| 3740 | start = idx; |
| 3741 | bitmap = bitmap << sh; |
| 3742 | sh = 0; |
| 3743 | } |
| 3744 | bitmap |= (1 << sh); |
| 3745 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 3746 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 3747 | } |
| 3748 | |
| 3749 | agg->bitmap0 = bitmap & 0xFFFFFFFF; |
| 3750 | agg->bitmap1 = bitmap >> 32; |
| 3751 | agg->start_idx = start; |
| 3752 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3753 | IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%x\n", |
| 3754 | agg->frame_count, agg->start_idx, |
| 3755 | agg->bitmap0); |
| 3756 | |
| 3757 | if (bitmap) |
| 3758 | agg->wait_for_ba = 1; |
| 3759 | } |
| 3760 | return 0; |
| 3761 | } |
| 3762 | #endif |
| 3763 | #endif |
| 3764 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3765 | /** |
| 3766 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 3767 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3768 | static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv, |
| 3769 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3770 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3771 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3772 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3773 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3774 | int index = SEQ_TO_INDEX(sequence); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3775 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3776 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3777 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3778 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3779 | #ifdef CONFIG_IWL4965_HT |
| 3780 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3781 | int tid, sta_id; |
| 3782 | #endif |
| 3783 | #endif |
| 3784 | |
| 3785 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 3786 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 3787 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3788 | index, txq->q.n_bd, txq->q.write_ptr, |
| 3789 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3790 | return; |
| 3791 | } |
| 3792 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3793 | #ifdef CONFIG_IWL4965_HT |
| 3794 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3795 | if (txq->sched_retry) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3796 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3797 | struct ieee80211_hdr *hdr = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3798 | iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 3799 | struct iwl4965_ht_agg *agg = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3800 | __le16 *qc = ieee80211_get_qos_ctrl(hdr); |
| 3801 | |
| 3802 | if (qc == NULL) { |
| 3803 | IWL_ERROR("BUG_ON qc is null!!!!\n"); |
| 3804 | return; |
| 3805 | } |
| 3806 | |
| 3807 | tid = le16_to_cpu(*qc) & 0xf; |
| 3808 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3809 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3810 | if (unlikely(sta_id == IWL_INVALID_STATION)) { |
| 3811 | IWL_ERROR("Station not known for\n"); |
| 3812 | return; |
| 3813 | } |
| 3814 | |
| 3815 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 3816 | |
| 3817 | iwl4965_tx_status_reply_tx(priv, agg, tx_resp, index); |
| 3818 | |
| 3819 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3820 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3821 | /* TODO: send BAR */ |
| 3822 | } |
| 3823 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3824 | if ((txq->q.read_ptr != (scd_ssn & 0xff))) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3825 | index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3826 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 3827 | "%d index %d\n", scd_ssn , index); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3828 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3829 | } |
| 3830 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3831 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 3832 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3833 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3834 | |
| 3835 | tx_status->retry_count = tx_resp->failure_frame; |
| 3836 | tx_status->queue_number = status; |
| 3837 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3838 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3839 | |
| 3840 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3841 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3842 | |
| 3843 | tx_status->control.tx_rate = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3844 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3845 | |
| 3846 | 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] | 3847 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3848 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 3849 | tx_resp->failure_frame); |
| 3850 | |
| 3851 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
| 3852 | if (index != -1) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3853 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3854 | #ifdef CONFIG_IWL4965_HT |
| 3855 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3856 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3857 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 3858 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3859 | |
| 3860 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 3861 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 3862 | } |
| 3863 | |
| 3864 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3865 | static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv, |
| 3866 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3867 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3868 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3869 | struct iwl4965_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3870 | struct delayed_work *pwork; |
| 3871 | |
| 3872 | palive = &pkt->u.alive_frame; |
| 3873 | |
| 3874 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 3875 | "0x%01X 0x%01X\n", |
| 3876 | palive->is_valid, palive->ver_type, |
| 3877 | palive->ver_subtype); |
| 3878 | |
| 3879 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 3880 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 3881 | memcpy(&priv->card_alive_init, |
| 3882 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3883 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3884 | pwork = &priv->init_alive_start; |
| 3885 | } else { |
| 3886 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3887 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3888 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3889 | pwork = &priv->alive_start; |
| 3890 | } |
| 3891 | |
| 3892 | /* We delay the ALIVE response by 5ms to |
| 3893 | * give the HW RF Kill time to activate... */ |
| 3894 | if (palive->is_valid == UCODE_VALID_OK) |
| 3895 | queue_delayed_work(priv->workqueue, pwork, |
| 3896 | msecs_to_jiffies(5)); |
| 3897 | else |
| 3898 | IWL_WARNING("uCode did not respond OK.\n"); |
| 3899 | } |
| 3900 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3901 | static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv, |
| 3902 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3903 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3904 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3905 | |
| 3906 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 3907 | return; |
| 3908 | } |
| 3909 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3910 | static void iwl4965_rx_reply_error(struct iwl4965_priv *priv, |
| 3911 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3912 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3913 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3914 | |
| 3915 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 3916 | "seq 0x%04X ser 0x%08X\n", |
| 3917 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 3918 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 3919 | pkt->u.err_resp.cmd_id, |
| 3920 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 3921 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 3922 | } |
| 3923 | |
| 3924 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 3925 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3926 | 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] | 3927 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3928 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3929 | struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 3930 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3931 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 3932 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 3933 | rxon->channel = csa->channel; |
| 3934 | priv->staging_rxon.channel = csa->channel; |
| 3935 | } |
| 3936 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3937 | static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv, |
| 3938 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3939 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3940 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3941 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3942 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3943 | |
| 3944 | if (!report->state) { |
| 3945 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 3946 | "Spectrum Measure Notification: Start\n"); |
| 3947 | return; |
| 3948 | } |
| 3949 | |
| 3950 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 3951 | priv->measurement_status |= MEASUREMENT_READY; |
| 3952 | #endif |
| 3953 | } |
| 3954 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3955 | static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv, |
| 3956 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3957 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3958 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3959 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3960 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3961 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 3962 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 3963 | #endif |
| 3964 | } |
| 3965 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3966 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv, |
| 3967 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3968 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3969 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3970 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 3971 | "notification for %s:\n", |
| 3972 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3973 | 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] | 3974 | } |
| 3975 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3976 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3977 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3978 | struct iwl4965_priv *priv = |
| 3979 | container_of(work, struct iwl4965_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3980 | struct sk_buff *beacon; |
| 3981 | |
| 3982 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ |
| 3983 | beacon = ieee80211_beacon_get(priv->hw, priv->interface_id, NULL); |
| 3984 | |
| 3985 | if (!beacon) { |
| 3986 | IWL_ERROR("update beacon failed\n"); |
| 3987 | return; |
| 3988 | } |
| 3989 | |
| 3990 | mutex_lock(&priv->mutex); |
| 3991 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 3992 | if (priv->ibss_beacon) |
| 3993 | dev_kfree_skb(priv->ibss_beacon); |
| 3994 | |
| 3995 | priv->ibss_beacon = beacon; |
| 3996 | mutex_unlock(&priv->mutex); |
| 3997 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3998 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4001 | static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv, |
| 4002 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4003 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4004 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4005 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 4006 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 4007 | 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] | 4008 | |
| 4009 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 4010 | "tsf %d %d rate %d\n", |
| 4011 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 4012 | beacon->beacon_notify_hdr.failure_frame, |
| 4013 | le32_to_cpu(beacon->ibss_mgr_status), |
| 4014 | le32_to_cpu(beacon->high_tsf), |
| 4015 | le32_to_cpu(beacon->low_tsf), rate); |
| 4016 | #endif |
| 4017 | |
| 4018 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 4019 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 4020 | queue_work(priv->workqueue, &priv->beacon_update); |
| 4021 | } |
| 4022 | |
| 4023 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4024 | static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv, |
| 4025 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4026 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4027 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4028 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 4029 | struct iwl4965_scanreq_notification *notif = |
| 4030 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4031 | |
| 4032 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 4033 | #endif |
| 4034 | } |
| 4035 | |
| 4036 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4037 | static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv, |
| 4038 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4039 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4040 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 4041 | struct iwl4965_scanstart_notification *notif = |
| 4042 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4043 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 4044 | IWL_DEBUG_SCAN("Scan start: " |
| 4045 | "%d [802.11%s] " |
| 4046 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 4047 | notif->channel, |
| 4048 | notif->band ? "bg" : "a", |
| 4049 | notif->tsf_high, |
| 4050 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 4051 | } |
| 4052 | |
| 4053 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4054 | static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv, |
| 4055 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4056 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4057 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 4058 | struct iwl4965_scanresults_notification *notif = |
| 4059 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4060 | |
| 4061 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 4062 | "%d [802.11%s] " |
| 4063 | "(TSF: 0x%08X:%08X) - %d " |
| 4064 | "elapsed=%lu usec (%dms since last)\n", |
| 4065 | notif->channel, |
| 4066 | notif->band ? "bg" : "a", |
| 4067 | le32_to_cpu(notif->tsf_high), |
| 4068 | le32_to_cpu(notif->tsf_low), |
| 4069 | le32_to_cpu(notif->statistics[0]), |
| 4070 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 4071 | jiffies_to_msecs(elapsed_jiffies |
| 4072 | (priv->last_scan_jiffies, jiffies))); |
| 4073 | |
| 4074 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4075 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4079 | static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv, |
| 4080 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4081 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4082 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 4083 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4084 | |
| 4085 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 4086 | scan_notif->scanned_channels, |
| 4087 | scan_notif->tsf_low, |
| 4088 | scan_notif->tsf_high, scan_notif->status); |
| 4089 | |
| 4090 | /* The HW is no longer scanning */ |
| 4091 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 4092 | |
| 4093 | /* The scan completion notification came in, so kill that timer... */ |
| 4094 | cancel_delayed_work(&priv->scan_check); |
| 4095 | |
| 4096 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 4097 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 4098 | jiffies_to_msecs(elapsed_jiffies |
| 4099 | (priv->scan_pass_start, jiffies))); |
| 4100 | |
| 4101 | /* Remove this scanned band from the list |
| 4102 | * of pending bands to scan */ |
| 4103 | priv->scan_bands--; |
| 4104 | |
| 4105 | /* If a request to abort was given, or the scan did not succeed |
| 4106 | * then we reset the scan state machine and terminate, |
| 4107 | * re-queuing another scan if one has been requested */ |
| 4108 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 4109 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 4110 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 4111 | } else { |
| 4112 | /* If there are more bands on this scan pass reschedule */ |
| 4113 | if (priv->scan_bands > 0) |
| 4114 | goto reschedule; |
| 4115 | } |
| 4116 | |
| 4117 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4118 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4119 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 4120 | |
| 4121 | clear_bit(STATUS_SCANNING, &priv->status); |
| 4122 | |
| 4123 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 4124 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 4125 | |
| 4126 | queue_work(priv->workqueue, &priv->scan_completed); |
| 4127 | |
| 4128 | return; |
| 4129 | |
| 4130 | reschedule: |
| 4131 | priv->scan_pass_start = jiffies; |
| 4132 | queue_work(priv->workqueue, &priv->request_scan); |
| 4133 | } |
| 4134 | |
| 4135 | /* Handle notification from uCode that card's power state is changing |
| 4136 | * due to software, hardware, or critical temperature RFKILL */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4137 | static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv, |
| 4138 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4139 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4140 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4141 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 4142 | unsigned long status = priv->status; |
| 4143 | |
| 4144 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 4145 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 4146 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 4147 | |
| 4148 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 4149 | RF_CARD_DISABLED)) { |
| 4150 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4151 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4152 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 4153 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4154 | if (!iwl4965_grab_nic_access(priv)) { |
| 4155 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4156 | priv, HBUS_TARG_MBX_C, |
| 4157 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4158 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4159 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | if (!(flags & RXON_CARD_DISABLED)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4163 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4164 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4165 | if (!iwl4965_grab_nic_access(priv)) { |
| 4166 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4167 | priv, HBUS_TARG_MBX_C, |
| 4168 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4169 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4170 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4171 | } |
| 4172 | } |
| 4173 | |
| 4174 | if (flags & RF_CARD_DISABLED) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4175 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4176 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4177 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 4178 | if (!iwl4965_grab_nic_access(priv)) |
| 4179 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | if (flags & HW_CARD_DISABLED) |
| 4184 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4185 | else |
| 4186 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4187 | |
| 4188 | |
| 4189 | if (flags & SW_CARD_DISABLED) |
| 4190 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4191 | else |
| 4192 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4193 | |
| 4194 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4195 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4196 | |
| 4197 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 4198 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 4199 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 4200 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 4201 | queue_work(priv->workqueue, &priv->rf_kill); |
| 4202 | else |
| 4203 | wake_up_interruptible(&priv->wait_command_queue); |
| 4204 | } |
| 4205 | |
| 4206 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4207 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4208 | * |
| 4209 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 4210 | * to the host. |
| 4211 | * |
| 4212 | * This function chains into the hardware specific files for them to setup |
| 4213 | * any hardware specific handlers as well. |
| 4214 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4215 | static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4216 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4217 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 4218 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 4219 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 4220 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4221 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4222 | iwl4965_rx_spectrum_measure_notif; |
| 4223 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4224 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4225 | iwl4965_rx_pm_debug_statistics_notif; |
| 4226 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4227 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4228 | /* |
| 4229 | * The same handler is used for both the REPLY to a discrete |
| 4230 | * statistics request from the host as well as for the periodic |
| 4231 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4232 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4233 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 4234 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4235 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4236 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 4237 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4238 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4239 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4240 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4241 | iwl4965_rx_scan_complete_notif; |
| 4242 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 4243 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4244 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4245 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4246 | iwl4965_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4250 | * 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] | 4251 | * @rxb: Rx buffer to reclaim |
| 4252 | * |
| 4253 | * If an Rx buffer has an async callback associated with it the callback |
| 4254 | * will be executed. The attached skb (if present) will only be freed |
| 4255 | * if the callback returns 1 |
| 4256 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4257 | static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv, |
| 4258 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4259 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4260 | struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4261 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 4262 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 4263 | int index = SEQ_TO_INDEX(sequence); |
| 4264 | int huge = sequence & SEQ_HUGE_FRAME; |
| 4265 | int cmd_index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4266 | struct iwl4965_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4267 | |
| 4268 | /* If a Tx command is being handled and it isn't in the actual |
| 4269 | * command queue then there a command routing bug has been introduced |
| 4270 | * in the queue management code. */ |
| 4271 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 4272 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 4273 | txq_id, pkt->hdr.cmd); |
| 4274 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 4275 | |
| 4276 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 4277 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 4278 | |
| 4279 | /* Input error checking is done when commands are added to queue. */ |
| 4280 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 4281 | cmd->meta.source->u.skb = rxb->skb; |
| 4282 | rxb->skb = NULL; |
| 4283 | } else if (cmd->meta.u.callback && |
| 4284 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 4285 | rxb->skb = NULL; |
| 4286 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4287 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4288 | |
| 4289 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 4290 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4291 | wake_up_interruptible(&priv->wait_command_queue); |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | /************************** RX-FUNCTIONS ****************************/ |
| 4296 | /* |
| 4297 | * Rx theory of operation |
| 4298 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4299 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), |
| 4300 | * each of which point to Receive Buffers to be filled by 4965. These get |
| 4301 | * used not only for Rx frames, but for any command response or notification |
| 4302 | * from the 4965. The driver and 4965 manage the Rx buffers by means |
| 4303 | * of indexes into the circular buffer. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4304 | * |
| 4305 | * Rx Queue Indexes |
| 4306 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4307 | * |
| 4308 | * The READ index maps to the first position that the firmware may be writing |
| 4309 | * to -- the driver can read up to (but not including) this position and get |
| 4310 | * good data. |
| 4311 | * The READ index is managed by the firmware once the card is enabled. |
| 4312 | * |
| 4313 | * The WRITE index maps to the last position the driver has read from -- the |
| 4314 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4315 | * |
| 4316 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 4317 | * WRITE = READ. |
| 4318 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4319 | * 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] | 4320 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4321 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4322 | * 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] | 4323 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4324 | * process as many packets as possible, moving the WRITE index forward as it |
| 4325 | * resets the Rx queue buffers with new memory. |
| 4326 | * |
| 4327 | * The management in the driver is as follows: |
| 4328 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 4329 | * 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] | 4330 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4331 | * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4332 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 4333 | * 'processed' and 'read' driver indexes as well) |
| 4334 | * + A received packet is processed and handed to the kernel network stack, |
| 4335 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 4336 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 4337 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 4338 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 4339 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4340 | * |
| 4341 | * |
| 4342 | * Driver sequence: |
| 4343 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4344 | * iwl4965_rx_queue_alloc() Allocates rx_free |
| 4345 | * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4346 | * iwl4965_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4347 | * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4348 | * queue, updates firmware pointers, and updates |
| 4349 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4350 | * are available, schedules iwl4965_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4351 | * |
| 4352 | * -- enable interrupts -- |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4353 | * 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] | 4354 | * READ INDEX, detaching the SKB from the pool. |
| 4355 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4356 | * Calls iwl4965_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4357 | * slots. |
| 4358 | * ... |
| 4359 | * |
| 4360 | */ |
| 4361 | |
| 4362 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4363 | * iwl4965_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4364 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4365 | static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4366 | { |
| 4367 | int s = q->read - q->write; |
| 4368 | if (s <= 0) |
| 4369 | s += RX_QUEUE_SIZE; |
| 4370 | /* keep some buffer to not confuse full and empty queue */ |
| 4371 | s -= 2; |
| 4372 | if (s < 0) |
| 4373 | s = 0; |
| 4374 | return s; |
| 4375 | } |
| 4376 | |
| 4377 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4378 | * 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] | 4379 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4380 | 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] | 4381 | { |
| 4382 | u32 reg = 0; |
| 4383 | int rc = 0; |
| 4384 | unsigned long flags; |
| 4385 | |
| 4386 | spin_lock_irqsave(&q->lock, flags); |
| 4387 | |
| 4388 | if (q->need_update == 0) |
| 4389 | goto exit_unlock; |
| 4390 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4391 | /* If power-saving is in use, make sure device is awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4392 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4393 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4394 | |
| 4395 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4396 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4397 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4398 | goto exit_unlock; |
| 4399 | } |
| 4400 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4401 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4402 | if (rc) |
| 4403 | goto exit_unlock; |
| 4404 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4405 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4406 | iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4407 | q->write & ~0x7); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4408 | iwl4965_release_nic_access(priv); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4409 | |
| 4410 | /* Else device is assumed to be awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4411 | } else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4412 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4413 | iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4414 | |
| 4415 | |
| 4416 | q->need_update = 0; |
| 4417 | |
| 4418 | exit_unlock: |
| 4419 | spin_unlock_irqrestore(&q->lock, flags); |
| 4420 | return rc; |
| 4421 | } |
| 4422 | |
| 4423 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4424 | * 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] | 4425 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4426 | static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4427 | dma_addr_t dma_addr) |
| 4428 | { |
| 4429 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 4430 | } |
| 4431 | |
| 4432 | |
| 4433 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4434 | * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4435 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4436 | * 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] | 4437 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4438 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4439 | * |
| 4440 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4441 | * also updates the memory address in the firmware to reference the new |
| 4442 | * target buffer. |
| 4443 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4444 | static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4445 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4446 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4447 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4448 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4449 | unsigned long flags; |
| 4450 | int write, rc; |
| 4451 | |
| 4452 | spin_lock_irqsave(&rxq->lock, flags); |
| 4453 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4454 | while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4455 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4456 | element = rxq->rx_free.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4457 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4458 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4459 | |
| 4460 | /* Point to Rx buffer via next RBD in circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4461 | rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4462 | rxq->queue[rxq->write] = rxb; |
| 4463 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 4464 | rxq->free_count--; |
| 4465 | } |
| 4466 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4467 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 4468 | * refill it */ |
| 4469 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4470 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4471 | |
| 4472 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4473 | /* If we've added more space for the firmware to place data, tell it. |
| 4474 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4475 | if ((write != (rxq->write & ~0x7)) |
| 4476 | || (abs(rxq->write - rxq->read) > 7)) { |
| 4477 | spin_lock_irqsave(&rxq->lock, flags); |
| 4478 | rxq->need_update = 1; |
| 4479 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4480 | rc = iwl4965_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4481 | if (rc) |
| 4482 | return rc; |
| 4483 | } |
| 4484 | |
| 4485 | return 0; |
| 4486 | } |
| 4487 | |
| 4488 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4489 | * 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] | 4490 | * |
| 4491 | * When moving to rx_free an SKB is allocated for the slot. |
| 4492 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4493 | * Also restock the Rx queue via iwl4965_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 4494 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4495 | */ |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4496 | static void iwl4965_rx_allocate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4497 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4498 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4499 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4500 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4501 | unsigned long flags; |
| 4502 | spin_lock_irqsave(&rxq->lock, flags); |
| 4503 | while (!list_empty(&rxq->rx_used)) { |
| 4504 | element = rxq->rx_used.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4505 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4506 | |
| 4507 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4508 | rxb->skb = |
| 4509 | alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC); |
| 4510 | if (!rxb->skb) { |
| 4511 | if (net_ratelimit()) |
| 4512 | printk(KERN_CRIT DRV_NAME |
| 4513 | ": Can not allocate SKB buffers\n"); |
| 4514 | /* We don't reschedule replenish work here -- we will |
| 4515 | * call the restock method and if it still needs |
| 4516 | * more buffers it will schedule replenish */ |
| 4517 | break; |
| 4518 | } |
| 4519 | priv->alloc_rxb_skb++; |
| 4520 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4521 | |
| 4522 | /* Get physical address of RB/SKB */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4523 | rxb->dma_addr = |
| 4524 | pci_map_single(priv->pci_dev, rxb->skb->data, |
| 4525 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4526 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4527 | rxq->free_count++; |
| 4528 | } |
| 4529 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | /* |
| 4533 | * this should be called while priv->lock is locked |
| 4534 | */ |
| 4535 | void __iwl4965_rx_replenish(void *data) |
| 4536 | { |
| 4537 | struct iwl4965_priv *priv = data; |
| 4538 | |
| 4539 | iwl4965_rx_allocate(priv); |
| 4540 | iwl4965_rx_queue_restock(priv); |
| 4541 | } |
| 4542 | |
| 4543 | |
| 4544 | void iwl4965_rx_replenish(void *data) |
| 4545 | { |
| 4546 | struct iwl4965_priv *priv = data; |
| 4547 | unsigned long flags; |
| 4548 | |
| 4549 | iwl4965_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4550 | |
| 4551 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4552 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4553 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4554 | } |
| 4555 | |
| 4556 | /* 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] | 4557 | * 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] | 4558 | * This free routine walks the list of POOL entries and if SKB is set to |
| 4559 | * non NULL it is unmapped and freed |
| 4560 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4561 | 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] | 4562 | { |
| 4563 | int i; |
| 4564 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4565 | if (rxq->pool[i].skb != NULL) { |
| 4566 | pci_unmap_single(priv->pci_dev, |
| 4567 | rxq->pool[i].dma_addr, |
| 4568 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4569 | dev_kfree_skb(rxq->pool[i].skb); |
| 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 4574 | rxq->dma_addr); |
| 4575 | rxq->bd = NULL; |
| 4576 | } |
| 4577 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4578 | int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4579 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4580 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4581 | struct pci_dev *dev = priv->pci_dev; |
| 4582 | int i; |
| 4583 | |
| 4584 | spin_lock_init(&rxq->lock); |
| 4585 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4586 | INIT_LIST_HEAD(&rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4587 | |
| 4588 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4589 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 4590 | if (!rxq->bd) |
| 4591 | return -ENOMEM; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4592 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4593 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4594 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 4595 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4596 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4597 | /* Set us so that we have processed and used all buffers, but have |
| 4598 | * not restocked the Rx queue with fresh buffers */ |
| 4599 | rxq->read = rxq->write = 0; |
| 4600 | rxq->free_count = 0; |
| 4601 | rxq->need_update = 0; |
| 4602 | return 0; |
| 4603 | } |
| 4604 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4605 | 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] | 4606 | { |
| 4607 | unsigned long flags; |
| 4608 | int i; |
| 4609 | spin_lock_irqsave(&rxq->lock, flags); |
| 4610 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4611 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4612 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4613 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 4614 | /* In the reset function, these buffers may have been allocated |
| 4615 | * to an SKB, so we need to unmap and free potential storage */ |
| 4616 | if (rxq->pool[i].skb != NULL) { |
| 4617 | pci_unmap_single(priv->pci_dev, |
| 4618 | rxq->pool[i].dma_addr, |
| 4619 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4620 | priv->alloc_rxb_skb--; |
| 4621 | dev_kfree_skb(rxq->pool[i].skb); |
| 4622 | rxq->pool[i].skb = NULL; |
| 4623 | } |
| 4624 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4625 | } |
| 4626 | |
| 4627 | /* Set us so that we have processed and used all buffers, but have |
| 4628 | * not restocked the Rx queue with fresh buffers */ |
| 4629 | rxq->read = rxq->write = 0; |
| 4630 | rxq->free_count = 0; |
| 4631 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4632 | } |
| 4633 | |
| 4634 | /* Convert linear signal-to-noise ratio into dB */ |
| 4635 | static u8 ratio2dB[100] = { |
| 4636 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 4637 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 4638 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 4639 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 4640 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 4641 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 4642 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 4643 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 4644 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 4645 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 4646 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 4647 | }; |
| 4648 | |
| 4649 | /* Calculates a relative dB value from a ratio of linear |
| 4650 | * (i.e. not dB) signal levels. |
| 4651 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4652 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4653 | { |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4654 | /* 1000:1 or higher just report as 60 dB */ |
| 4655 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4656 | return 60; |
| 4657 | |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4658 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4659 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4660 | if (sig_ratio >= 100) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4661 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 4662 | |
| 4663 | /* We shouldn't see this */ |
| 4664 | if (sig_ratio < 1) |
| 4665 | return 0; |
| 4666 | |
| 4667 | /* Use table for ratios 1:1 - 99:1 */ |
| 4668 | return (int)ratio2dB[sig_ratio]; |
| 4669 | } |
| 4670 | |
| 4671 | #define PERFECT_RSSI (-20) /* dBm */ |
| 4672 | #define WORST_RSSI (-95) /* dBm */ |
| 4673 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 4674 | |
| 4675 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 4676 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 4677 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4678 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4679 | { |
| 4680 | int sig_qual; |
| 4681 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 4682 | |
| 4683 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 4684 | * as indicator; formula is (signal dbm - noise dbm). |
| 4685 | * SNR at or above 40 is a great signal (100%). |
| 4686 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 4687 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 4688 | if (noise_dbm) { |
| 4689 | if (rssi_dbm - noise_dbm >= 40) |
| 4690 | return 100; |
| 4691 | else if (rssi_dbm < noise_dbm) |
| 4692 | return 0; |
| 4693 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 4694 | |
| 4695 | /* Else use just the signal level. |
| 4696 | * This formula is a least squares fit of data points collected and |
| 4697 | * compared with a reference system that had a percentage (%) display |
| 4698 | * for signal quality. */ |
| 4699 | } else |
| 4700 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 4701 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 4702 | (RSSI_RANGE * RSSI_RANGE); |
| 4703 | |
| 4704 | if (sig_qual > 100) |
| 4705 | sig_qual = 100; |
| 4706 | else if (sig_qual < 1) |
| 4707 | sig_qual = 0; |
| 4708 | |
| 4709 | return sig_qual; |
| 4710 | } |
| 4711 | |
| 4712 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4713 | * iwl4965_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4714 | * |
| 4715 | * Uses the priv->rx_handlers callback function array to invoke |
| 4716 | * the appropriate handlers, including command responses, |
| 4717 | * frame-received notifications, and other notifications. |
| 4718 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4719 | static void iwl4965_rx_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4720 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4721 | struct iwl4965_rx_mem_buffer *rxb; |
| 4722 | struct iwl4965_rx_packet *pkt; |
| 4723 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4724 | u32 r, i; |
| 4725 | int reclaim; |
| 4726 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4727 | u8 fill_rx = 0; |
| 4728 | u32 count = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4729 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4730 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 4731 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4732 | r = iwl4965_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4733 | i = rxq->read; |
| 4734 | |
| 4735 | /* Rx interrupt, but nothing sent from uCode */ |
| 4736 | if (i == r) |
| 4737 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 4738 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4739 | if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
| 4740 | fill_rx = 1; |
| 4741 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4742 | while (i != r) { |
| 4743 | rxb = rxq->queue[i]; |
| 4744 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4745 | /* 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] | 4746 | * then a bug has been introduced in the queue refilling |
| 4747 | * routines -- catch it here */ |
| 4748 | BUG_ON(rxb == NULL); |
| 4749 | |
| 4750 | rxq->queue[i] = NULL; |
| 4751 | |
| 4752 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
| 4753 | IWL_RX_BUF_SIZE, |
| 4754 | PCI_DMA_FROMDEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4755 | pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4756 | |
| 4757 | /* Reclaim a command buffer only if this packet is a response |
| 4758 | * to a (driver-originated) command. |
| 4759 | * If the packet (e.g. Rx frame) originated from uCode, |
| 4760 | * there is no command buffer to reclaim. |
| 4761 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 4762 | * but apparently a few don't get set; catch them here. */ |
| 4763 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 4764 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
| 4765 | (pkt->hdr.cmd != REPLY_4965_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 4766 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4767 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 4768 | (pkt->hdr.cmd != REPLY_TX); |
| 4769 | |
| 4770 | /* Based on type of command response or notification, |
| 4771 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4772 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4773 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 4774 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4775 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 4776 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 4777 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 4778 | } else { |
| 4779 | /* No handling needed */ |
| 4780 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4781 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 4782 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 4783 | pkt->hdr.cmd); |
| 4784 | } |
| 4785 | |
| 4786 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4787 | /* Invoke any callbacks, transfer the skb to caller, and |
| 4788 | * fire off the (possibly) blocking iwl4965_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4789 | * as we reclaim the driver command queue */ |
| 4790 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4791 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4792 | else |
| 4793 | IWL_WARNING("Claim null rxb?\n"); |
| 4794 | } |
| 4795 | |
| 4796 | /* For now we just don't re-use anything. We can tweak this |
| 4797 | * later to try and re-use notification packets and SKBs that |
| 4798 | * fail to Rx correctly */ |
| 4799 | if (rxb->skb != NULL) { |
| 4800 | priv->alloc_rxb_skb--; |
| 4801 | dev_kfree_skb_any(rxb->skb); |
| 4802 | rxb->skb = NULL; |
| 4803 | } |
| 4804 | |
| 4805 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
| 4806 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4807 | spin_lock_irqsave(&rxq->lock, flags); |
| 4808 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 4809 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4810 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4811 | /* If there are a lot of unused frames, |
| 4812 | * restock the Rx queue so ucode wont assert. */ |
| 4813 | if (fill_rx) { |
| 4814 | count++; |
| 4815 | if (count >= 8) { |
| 4816 | priv->rxq.read = i; |
| 4817 | __iwl4965_rx_replenish(priv); |
| 4818 | count = 0; |
| 4819 | } |
| 4820 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | /* Backtrack one entry */ |
| 4824 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4825 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4826 | } |
| 4827 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4828 | /** |
| 4829 | * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware |
| 4830 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4831 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 4832 | struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4833 | { |
| 4834 | u32 reg = 0; |
| 4835 | int rc = 0; |
| 4836 | int txq_id = txq->q.id; |
| 4837 | |
| 4838 | if (txq->need_update == 0) |
| 4839 | return rc; |
| 4840 | |
| 4841 | /* if we're trying to save power */ |
| 4842 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 4843 | /* wake up nic if it's powered down ... |
| 4844 | * uCode will wake up, and interrupt us again, so next |
| 4845 | * time we'll skip this part. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4846 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4847 | |
| 4848 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 4849 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4850 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4851 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4852 | return rc; |
| 4853 | } |
| 4854 | |
| 4855 | /* restore this queue's parameters in nic hardware. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4856 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4857 | if (rc) |
| 4858 | return rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4859 | iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4860 | txq->q.write_ptr | (txq_id << 8)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4861 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4862 | |
| 4863 | /* else not in power-save mode, uCode will never sleep when we're |
| 4864 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 4865 | } else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4866 | iwl4965_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4867 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4868 | |
| 4869 | txq->need_update = 0; |
| 4870 | |
| 4871 | return rc; |
| 4872 | } |
| 4873 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4874 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4875 | static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4876 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4877 | DECLARE_MAC_BUF(mac); |
| 4878 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4879 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4880 | iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4881 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 4882 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 4883 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 4884 | le32_to_cpu(rxon->filter_flags)); |
| 4885 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 4886 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 4887 | rxon->ofdm_basic_rates); |
| 4888 | 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] | 4889 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 4890 | print_mac(mac, rxon->node_addr)); |
| 4891 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 4892 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4893 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 4894 | } |
| 4895 | #endif |
| 4896 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4897 | static void iwl4965_enable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4898 | { |
| 4899 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 4900 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4901 | iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4902 | } |
| 4903 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4904 | static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4905 | { |
| 4906 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 4907 | |
| 4908 | /* disable interrupts from uCode/NIC to host */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4909 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4910 | |
| 4911 | /* acknowledge/clear/reset any interrupts still pending |
| 4912 | * from uCode or flow handler (Rx/Tx DMA) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4913 | iwl4965_write32(priv, CSR_INT, 0xffffffff); |
| 4914 | iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4915 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 4916 | } |
| 4917 | |
| 4918 | static const char *desc_lookup(int i) |
| 4919 | { |
| 4920 | switch (i) { |
| 4921 | case 1: |
| 4922 | return "FAIL"; |
| 4923 | case 2: |
| 4924 | return "BAD_PARAM"; |
| 4925 | case 3: |
| 4926 | return "BAD_CHECKSUM"; |
| 4927 | case 4: |
| 4928 | return "NMI_INTERRUPT"; |
| 4929 | case 5: |
| 4930 | return "SYSASSERT"; |
| 4931 | case 6: |
| 4932 | return "FATAL_ERROR"; |
| 4933 | } |
| 4934 | |
| 4935 | return "UNKNOWN"; |
| 4936 | } |
| 4937 | |
| 4938 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4939 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4940 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4941 | static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4942 | { |
| 4943 | u32 data2, line; |
| 4944 | u32 desc, time, count, base, data1; |
| 4945 | u32 blink1, blink2, ilink1, ilink2; |
| 4946 | int rc; |
| 4947 | |
| 4948 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 4949 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4950 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4951 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 4952 | return; |
| 4953 | } |
| 4954 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4955 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4956 | if (rc) { |
| 4957 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4958 | return; |
| 4959 | } |
| 4960 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4961 | count = iwl4965_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4962 | |
| 4963 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 4964 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
| 4965 | IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n", |
| 4966 | priv->status, priv->config, count); |
| 4967 | } |
| 4968 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4969 | desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 4970 | blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 4971 | blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 4972 | ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 4973 | ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 4974 | data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 4975 | data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 4976 | line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 4977 | time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4978 | |
| 4979 | IWL_ERROR("Desc Time " |
| 4980 | "data1 data2 line\n"); |
| 4981 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 4982 | desc_lookup(desc), desc, time, data1, data2, line); |
| 4983 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 4984 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 4985 | ilink1, ilink2); |
| 4986 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4987 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 4991 | |
| 4992 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4993 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4994 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4995 | * NOTE: Must be called with iwl4965_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4996 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4997 | 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] | 4998 | u32 num_events, u32 mode) |
| 4999 | { |
| 5000 | u32 i; |
| 5001 | u32 base; /* SRAM byte address of event log header */ |
| 5002 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 5003 | u32 ptr; /* SRAM byte address of log data */ |
| 5004 | u32 ev, time, data; /* event log data */ |
| 5005 | |
| 5006 | if (num_events == 0) |
| 5007 | return; |
| 5008 | |
| 5009 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 5010 | |
| 5011 | if (mode == 0) |
| 5012 | event_size = 2 * sizeof(u32); |
| 5013 | else |
| 5014 | event_size = 3 * sizeof(u32); |
| 5015 | |
| 5016 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 5017 | |
| 5018 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 5019 | * place event id # at far right for easier visual parsing. */ |
| 5020 | for (i = 0; i < num_events; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5021 | ev = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5022 | ptr += sizeof(u32); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5023 | time = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5024 | ptr += sizeof(u32); |
| 5025 | if (mode == 0) |
| 5026 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 5027 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5028 | data = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5029 | ptr += sizeof(u32); |
| 5030 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 5031 | } |
| 5032 | } |
| 5033 | } |
| 5034 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5035 | static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5036 | { |
| 5037 | int rc; |
| 5038 | u32 base; /* SRAM byte address of event log header */ |
| 5039 | u32 capacity; /* event log capacity in # entries */ |
| 5040 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 5041 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 5042 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 5043 | u32 size; /* # entries that we'll print */ |
| 5044 | |
| 5045 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5046 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5047 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 5048 | return; |
| 5049 | } |
| 5050 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5051 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5052 | if (rc) { |
| 5053 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 5054 | return; |
| 5055 | } |
| 5056 | |
| 5057 | /* event log header */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5058 | capacity = iwl4965_read_targ_mem(priv, base); |
| 5059 | mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 5060 | num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 5061 | next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5062 | |
| 5063 | size = num_wraps ? capacity : next_entry; |
| 5064 | |
| 5065 | /* bail out if nothing in log */ |
| 5066 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 5067 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5068 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5069 | return; |
| 5070 | } |
| 5071 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 5072 | 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] | 5073 | size, num_wraps); |
| 5074 | |
| 5075 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 5076 | * i.e the next one that uCode would fill. */ |
| 5077 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5078 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5079 | capacity - next_entry, mode); |
| 5080 | |
| 5081 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5082 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5083 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5084 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5088 | * 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] | 5089 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5090 | static void iwl4965_irq_handle_error(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5091 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5092 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5093 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 5094 | |
| 5095 | /* Cancel currently queued command. */ |
| 5096 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 5097 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5098 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5099 | if (iwl4965_debug_level & IWL_DL_FW_ERRORS) { |
| 5100 | iwl4965_dump_nic_error_log(priv); |
| 5101 | iwl4965_dump_nic_event_log(priv); |
| 5102 | iwl4965_print_rx_config_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5103 | } |
| 5104 | #endif |
| 5105 | |
| 5106 | wake_up_interruptible(&priv->wait_command_queue); |
| 5107 | |
| 5108 | /* Keep the restart process from trying to send host |
| 5109 | * commands by clearing the INIT status bit */ |
| 5110 | clear_bit(STATUS_READY, &priv->status); |
| 5111 | |
| 5112 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 5113 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 5114 | "Restarting adapter due to uCode error.\n"); |
| 5115 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5116 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5117 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 5118 | sizeof(priv->recovery_rxon)); |
| 5119 | priv->error_recovering = 1; |
| 5120 | } |
| 5121 | queue_work(priv->workqueue, &priv->restart); |
| 5122 | } |
| 5123 | } |
| 5124 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5125 | static void iwl4965_error_recovery(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5126 | { |
| 5127 | unsigned long flags; |
| 5128 | |
| 5129 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 5130 | sizeof(priv->staging_rxon)); |
| 5131 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5132 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5133 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5134 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5135 | |
| 5136 | spin_lock_irqsave(&priv->lock, flags); |
| 5137 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 5138 | priv->error_recovering = 0; |
| 5139 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5140 | } |
| 5141 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5142 | static void iwl4965_irq_tasklet(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5143 | { |
| 5144 | u32 inta, handled = 0; |
| 5145 | u32 inta_fh; |
| 5146 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5147 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5148 | u32 inta_mask; |
| 5149 | #endif |
| 5150 | |
| 5151 | spin_lock_irqsave(&priv->lock, flags); |
| 5152 | |
| 5153 | /* Ack/clear/reset pending uCode interrupts. |
| 5154 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 5155 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5156 | inta = iwl4965_read32(priv, CSR_INT); |
| 5157 | iwl4965_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5158 | |
| 5159 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 5160 | * Any new interrupts that happen after this, either while we're |
| 5161 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5162 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
| 5163 | iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5164 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5165 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5166 | if (iwl4965_debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5167 | /* just for debug */ |
| 5168 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5169 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5170 | inta, inta_mask, inta_fh); |
| 5171 | } |
| 5172 | #endif |
| 5173 | |
| 5174 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 5175 | * atomic, make sure that inta covers all the interrupts that |
| 5176 | * we've discovered, even if FH interrupt came in just after |
| 5177 | * reading CSR_INT. */ |
| 5178 | if (inta_fh & CSR_FH_INT_RX_MASK) |
| 5179 | inta |= CSR_INT_BIT_FH_RX; |
| 5180 | if (inta_fh & CSR_FH_INT_TX_MASK) |
| 5181 | inta |= CSR_INT_BIT_FH_TX; |
| 5182 | |
| 5183 | /* Now service all interrupt bits discovered above. */ |
| 5184 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 5185 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 5186 | |
| 5187 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5188 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5189 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5190 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5191 | |
| 5192 | handled |= CSR_INT_BIT_HW_ERR; |
| 5193 | |
| 5194 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5195 | |
| 5196 | return; |
| 5197 | } |
| 5198 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5199 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5200 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5201 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
| 5202 | if (inta & CSR_INT_BIT_MAC_CLK_ACTV) |
| 5203 | IWL_DEBUG_ISR("Microcode started or stopped.\n"); |
| 5204 | |
| 5205 | /* Alive notification via Rx interrupt will do the real work */ |
| 5206 | if (inta & CSR_INT_BIT_ALIVE) |
| 5207 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 5208 | } |
| 5209 | #endif |
| 5210 | /* Safely ignore these bits for debug checks below */ |
| 5211 | inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE); |
| 5212 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5213 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5214 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 5215 | int hw_rf_kill = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5216 | if (!(iwl4965_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5217 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 5218 | hw_rf_kill = 1; |
| 5219 | |
| 5220 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 5221 | "RF_KILL bit toggled to %s.\n", |
| 5222 | hw_rf_kill ? "disable radio":"enable radio"); |
| 5223 | |
| 5224 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 5225 | * when we loaded driver, and is now set to "enable". |
| 5226 | * After we're Alive, RF_KILL gets handled by |
| 5227 | * iwl_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 5228 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 5229 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5230 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 5231 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5232 | |
| 5233 | handled |= CSR_INT_BIT_RF_KILL; |
| 5234 | } |
| 5235 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5236 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5237 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 5238 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 5239 | handled |= CSR_INT_BIT_CT_KILL; |
| 5240 | } |
| 5241 | |
| 5242 | /* Error detected by uCode */ |
| 5243 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 5244 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 5245 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5246 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5247 | handled |= CSR_INT_BIT_SW_ERR; |
| 5248 | } |
| 5249 | |
| 5250 | /* uCode wakes up after power-down sleep */ |
| 5251 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 5252 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5253 | iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq); |
| 5254 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 5255 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 5256 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 5257 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 5258 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 5259 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5260 | |
| 5261 | handled |= CSR_INT_BIT_WAKEUP; |
| 5262 | } |
| 5263 | |
| 5264 | /* All uCode command responses, including Tx command responses, |
| 5265 | * Rx "responses" (frame-received notification), and other |
| 5266 | * notifications from uCode come through here*/ |
| 5267 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5268 | iwl4965_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5269 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 5270 | } |
| 5271 | |
| 5272 | if (inta & CSR_INT_BIT_FH_TX) { |
| 5273 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 5274 | handled |= CSR_INT_BIT_FH_TX; |
| 5275 | } |
| 5276 | |
| 5277 | if (inta & ~handled) |
| 5278 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 5279 | |
| 5280 | if (inta & ~CSR_INI_SET_MASK) { |
| 5281 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 5282 | inta & ~CSR_INI_SET_MASK); |
| 5283 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 5284 | } |
| 5285 | |
| 5286 | /* Re-enable all interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5287 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5288 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5289 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5290 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
| 5291 | inta = iwl4965_read32(priv, CSR_INT); |
| 5292 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
| 5293 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5294 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 5295 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 5296 | } |
| 5297 | #endif |
| 5298 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5299 | } |
| 5300 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5301 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5302 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5303 | struct iwl4965_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5304 | u32 inta, inta_mask; |
| 5305 | u32 inta_fh; |
| 5306 | if (!priv) |
| 5307 | return IRQ_NONE; |
| 5308 | |
| 5309 | spin_lock(&priv->lock); |
| 5310 | |
| 5311 | /* Disable (but don't clear!) interrupts here to avoid |
| 5312 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 5313 | * If we have something to service, the tasklet will re-enable ints. |
| 5314 | * 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] | 5315 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 5316 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5317 | |
| 5318 | /* Discover which interrupts are active/pending */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5319 | inta = iwl4965_read32(priv, CSR_INT); |
| 5320 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5321 | |
| 5322 | /* Ignore interrupt if there's nothing in NIC to service. |
| 5323 | * This may be due to IRQ shared with another device, |
| 5324 | * or due to sporadic interrupts thrown from our NIC. */ |
| 5325 | if (!inta && !inta_fh) { |
| 5326 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 5327 | goto none; |
| 5328 | } |
| 5329 | |
| 5330 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5331 | /* Hardware disappeared. It might have already raised |
| 5332 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5333 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5334 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5338 | inta, inta_mask, inta_fh); |
| 5339 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5340 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5341 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5342 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5343 | unplugged: |
| 5344 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5345 | return IRQ_HANDLED; |
| 5346 | |
| 5347 | none: |
| 5348 | /* re-enable interrupts here since we don't have anything to service. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5349 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5350 | spin_unlock(&priv->lock); |
| 5351 | return IRQ_NONE; |
| 5352 | } |
| 5353 | |
| 5354 | /************************** EEPROM BANDS **************************** |
| 5355 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5356 | * The iwl4965_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5357 | * EEPROM contents to the specific channel number supported for each |
| 5358 | * band. |
| 5359 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5360 | * 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] | 5361 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 5362 | * The specific geography and calibration information for that channel |
| 5363 | * is contained in the eeprom map itself. |
| 5364 | * |
| 5365 | * During init, we copy the eeprom information and channel map |
| 5366 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 5367 | * |
| 5368 | * channel_map_24/52 provides the index in the channel_info array for a |
| 5369 | * given channel. We have to have two separate maps as there is channel |
| 5370 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 5371 | * band_2 |
| 5372 | * |
| 5373 | * A value of 0xff stored in the channel_map indicates that the channel |
| 5374 | * is not supported by the hardware at all. |
| 5375 | * |
| 5376 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 5377 | * valid for Tx with the current hardware. This means that |
| 5378 | * while the system can tune and receive on a given channel, it may not |
| 5379 | * be able to associate or transmit any frames on that |
| 5380 | * channel. There is no corresponding channel information for that |
| 5381 | * entry. |
| 5382 | * |
| 5383 | *********************************************************************/ |
| 5384 | |
| 5385 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5386 | static const u8 iwl4965_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5387 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 5388 | }; |
| 5389 | |
| 5390 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5391 | static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5392 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 5393 | }; |
| 5394 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5395 | static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5396 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 5397 | }; |
| 5398 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5399 | static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5400 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 5401 | }; |
| 5402 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5403 | static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5404 | 145, 149, 153, 157, 161, 165 |
| 5405 | }; |
| 5406 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5407 | static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5408 | 1, 2, 3, 4, 5, 6, 7 |
| 5409 | }; |
| 5410 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5411 | static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5412 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 |
| 5413 | }; |
| 5414 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5415 | static void iwl4965_init_band_reference(const struct iwl4965_priv *priv, |
| 5416 | int band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5417 | int *eeprom_ch_count, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5418 | const struct iwl4965_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5419 | **eeprom_ch_info, |
| 5420 | const u8 **eeprom_ch_index) |
| 5421 | { |
| 5422 | switch (band) { |
| 5423 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5424 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5425 | *eeprom_ch_info = priv->eeprom.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5426 | *eeprom_ch_index = iwl4965_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5427 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5428 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5429 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5430 | *eeprom_ch_info = priv->eeprom.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5431 | *eeprom_ch_index = iwl4965_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5432 | break; |
| 5433 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5434 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5435 | *eeprom_ch_info = priv->eeprom.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5436 | *eeprom_ch_index = iwl4965_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5437 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5438 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5439 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5440 | *eeprom_ch_info = priv->eeprom.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5441 | *eeprom_ch_index = iwl4965_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5442 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5443 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5444 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5445 | *eeprom_ch_info = priv->eeprom.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5446 | *eeprom_ch_index = iwl4965_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5447 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5448 | case 6: /* 2.4GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5449 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5450 | *eeprom_ch_info = priv->eeprom.band_24_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5451 | *eeprom_ch_index = iwl4965_eeprom_band_6; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5452 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5453 | case 7: /* 5 GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5454 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5455 | *eeprom_ch_info = priv->eeprom.band_52_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5456 | *eeprom_ch_index = iwl4965_eeprom_band_7; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5457 | break; |
| 5458 | default: |
| 5459 | BUG(); |
| 5460 | return; |
| 5461 | } |
| 5462 | } |
| 5463 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5464 | /** |
| 5465 | * iwl4965_get_channel_info - Find driver's private channel info |
| 5466 | * |
| 5467 | * Based on band and channel number. |
| 5468 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5469 | 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] | 5470 | int phymode, u16 channel) |
| 5471 | { |
| 5472 | int i; |
| 5473 | |
| 5474 | switch (phymode) { |
| 5475 | case MODE_IEEE80211A: |
| 5476 | for (i = 14; i < priv->channel_count; i++) { |
| 5477 | if (priv->channel_info[i].channel == channel) |
| 5478 | return &priv->channel_info[i]; |
| 5479 | } |
| 5480 | break; |
| 5481 | |
| 5482 | case MODE_IEEE80211B: |
| 5483 | case MODE_IEEE80211G: |
| 5484 | if (channel >= 1 && channel <= 14) |
| 5485 | return &priv->channel_info[channel - 1]; |
| 5486 | break; |
| 5487 | |
| 5488 | } |
| 5489 | |
| 5490 | return NULL; |
| 5491 | } |
| 5492 | |
| 5493 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 5494 | ? # x " " : "") |
| 5495 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5496 | /** |
| 5497 | * iwl4965_init_channel_map - Set up driver's info for all possible channels |
| 5498 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5499 | static int iwl4965_init_channel_map(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5500 | { |
| 5501 | int eeprom_ch_count = 0; |
| 5502 | const u8 *eeprom_ch_index = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5503 | const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5504 | int band, ch; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5505 | struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5506 | |
| 5507 | if (priv->channel_count) { |
| 5508 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 5509 | return 0; |
| 5510 | } |
| 5511 | |
| 5512 | if (priv->eeprom.version < 0x2f) { |
| 5513 | IWL_WARNING("Unsupported EEPROM version: 0x%04X\n", |
| 5514 | priv->eeprom.version); |
| 5515 | return -EINVAL; |
| 5516 | } |
| 5517 | |
| 5518 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 5519 | |
| 5520 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5521 | ARRAY_SIZE(iwl4965_eeprom_band_1) + |
| 5522 | ARRAY_SIZE(iwl4965_eeprom_band_2) + |
| 5523 | ARRAY_SIZE(iwl4965_eeprom_band_3) + |
| 5524 | ARRAY_SIZE(iwl4965_eeprom_band_4) + |
| 5525 | ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5526 | |
| 5527 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 5528 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5529 | priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5530 | priv->channel_count, GFP_KERNEL); |
| 5531 | if (!priv->channel_info) { |
| 5532 | IWL_ERROR("Could not allocate channel_info\n"); |
| 5533 | priv->channel_count = 0; |
| 5534 | return -ENOMEM; |
| 5535 | } |
| 5536 | |
| 5537 | ch_info = priv->channel_info; |
| 5538 | |
| 5539 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 5540 | * channel map we maintain (that contains additional information than |
| 5541 | * what just in the EEPROM) */ |
| 5542 | for (band = 1; band <= 5; band++) { |
| 5543 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5544 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5545 | &eeprom_ch_info, &eeprom_ch_index); |
| 5546 | |
| 5547 | /* Loop through each band adding each of the channels */ |
| 5548 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5549 | ch_info->channel = eeprom_ch_index[ch]; |
| 5550 | ch_info->phymode = (band == 1) ? MODE_IEEE80211B : |
| 5551 | MODE_IEEE80211A; |
| 5552 | |
| 5553 | /* permanently store EEPROM's channel regulatory flags |
| 5554 | * and max power in channel info database. */ |
| 5555 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 5556 | |
| 5557 | /* Copy the run-time flags so they are there even on |
| 5558 | * invalid channels */ |
| 5559 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 5560 | |
| 5561 | if (!(is_channel_valid(ch_info))) { |
| 5562 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 5563 | "No traffic\n", |
| 5564 | ch_info->channel, |
| 5565 | ch_info->flags, |
| 5566 | is_channel_a_band(ch_info) ? |
| 5567 | "5.2" : "2.4"); |
| 5568 | ch_info++; |
| 5569 | continue; |
| 5570 | } |
| 5571 | |
| 5572 | /* Initialize regulatory-based run-time data */ |
| 5573 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 5574 | eeprom_ch_info[ch].max_power_avg; |
| 5575 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 5576 | ch_info->min_power = 0; |
| 5577 | |
| 5578 | IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x" |
| 5579 | " %ddBm): Ad-Hoc %ssupported\n", |
| 5580 | ch_info->channel, |
| 5581 | is_channel_a_band(ch_info) ? |
| 5582 | "5.2" : "2.4", |
| 5583 | CHECK_AND_PRINT(IBSS), |
| 5584 | CHECK_AND_PRINT(ACTIVE), |
| 5585 | CHECK_AND_PRINT(RADAR), |
| 5586 | CHECK_AND_PRINT(WIDE), |
| 5587 | CHECK_AND_PRINT(NARROW), |
| 5588 | CHECK_AND_PRINT(DFS), |
| 5589 | eeprom_ch_info[ch].flags, |
| 5590 | eeprom_ch_info[ch].max_power_avg, |
| 5591 | ((eeprom_ch_info[ch]. |
| 5592 | flags & EEPROM_CHANNEL_IBSS) |
| 5593 | && !(eeprom_ch_info[ch]. |
| 5594 | flags & EEPROM_CHANNEL_RADAR)) |
| 5595 | ? "" : "not "); |
| 5596 | |
| 5597 | /* Set the user_txpower_limit to the highest power |
| 5598 | * supported by any channel */ |
| 5599 | if (eeprom_ch_info[ch].max_power_avg > |
| 5600 | priv->user_txpower_limit) |
| 5601 | priv->user_txpower_limit = |
| 5602 | eeprom_ch_info[ch].max_power_avg; |
| 5603 | |
| 5604 | ch_info++; |
| 5605 | } |
| 5606 | } |
| 5607 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5608 | /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5609 | for (band = 6; band <= 7; band++) { |
| 5610 | int phymode; |
| 5611 | u8 fat_extension_chan; |
| 5612 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5613 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5614 | &eeprom_ch_info, &eeprom_ch_index); |
| 5615 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5616 | /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5617 | phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5618 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5619 | /* Loop through each band adding each of the channels */ |
| 5620 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5621 | |
| 5622 | if ((band == 6) && |
| 5623 | ((eeprom_ch_index[ch] == 5) || |
| 5624 | (eeprom_ch_index[ch] == 6) || |
| 5625 | (eeprom_ch_index[ch] == 7))) |
| 5626 | fat_extension_chan = HT_IE_EXT_CHANNEL_MAX; |
| 5627 | else |
| 5628 | fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; |
| 5629 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5630 | /* Set up driver's info for lower half */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5631 | iwl4965_set_fat_chan_info(priv, phymode, |
| 5632 | eeprom_ch_index[ch], |
| 5633 | &(eeprom_ch_info[ch]), |
| 5634 | fat_extension_chan); |
| 5635 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5636 | /* Set up driver's info for upper half */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5637 | iwl4965_set_fat_chan_info(priv, phymode, |
| 5638 | (eeprom_ch_index[ch] + 4), |
| 5639 | &(eeprom_ch_info[ch]), |
| 5640 | HT_IE_EXT_CHANNEL_BELOW); |
| 5641 | } |
| 5642 | } |
| 5643 | |
| 5644 | return 0; |
| 5645 | } |
| 5646 | |
| 5647 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 5648 | * sending probe req. This should be set long enough to hear probe responses |
| 5649 | * from more than one AP. */ |
| 5650 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5651 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 5652 | |
| 5653 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 5654 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 5655 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 5656 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 5657 | * no other traffic). |
| 5658 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 5659 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 5660 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 5661 | |
| 5662 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 5663 | * Must be set longer than active dwell time. |
| 5664 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 5665 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5666 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 5667 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 5668 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 5669 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5670 | 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] | 5671 | { |
| 5672 | if (phymode == MODE_IEEE80211A) |
| 5673 | return IWL_ACTIVE_DWELL_TIME_52; |
| 5674 | else |
| 5675 | return IWL_ACTIVE_DWELL_TIME_24; |
| 5676 | } |
| 5677 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5678 | 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] | 5679 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5680 | u16 active = iwl4965_get_active_dwell_time(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5681 | u16 passive = (phymode != MODE_IEEE80211A) ? |
| 5682 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 5683 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 5684 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5685 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5686 | /* If we're associated, we clamp the maximum passive |
| 5687 | * dwell time to be 98% of the beacon interval (minus |
| 5688 | * 2 * channel tune time) */ |
| 5689 | passive = priv->beacon_int; |
| 5690 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 5691 | passive = IWL_PASSIVE_DWELL_BASE; |
| 5692 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 5693 | } |
| 5694 | |
| 5695 | if (passive <= active) |
| 5696 | passive = active + 1; |
| 5697 | |
| 5698 | return passive; |
| 5699 | } |
| 5700 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5701 | 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] | 5702 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5703 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5704 | { |
| 5705 | const struct ieee80211_channel *channels = NULL; |
| 5706 | const struct ieee80211_hw_mode *hw_mode; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5707 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5708 | u16 passive_dwell = 0; |
| 5709 | u16 active_dwell = 0; |
| 5710 | int added, i; |
| 5711 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5712 | hw_mode = iwl4965_get_hw_mode(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5713 | if (!hw_mode) |
| 5714 | return 0; |
| 5715 | |
| 5716 | channels = hw_mode->channels; |
| 5717 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5718 | active_dwell = iwl4965_get_active_dwell_time(priv, phymode); |
| 5719 | passive_dwell = iwl4965_get_passive_dwell_time(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5720 | |
| 5721 | for (i = 0, added = 0; i < hw_mode->num_channels; i++) { |
| 5722 | if (channels[i].chan == |
| 5723 | le16_to_cpu(priv->active_rxon.channel)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5724 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5725 | IWL_DEBUG_SCAN |
| 5726 | ("Skipping current channel %d\n", |
| 5727 | le16_to_cpu(priv->active_rxon.channel)); |
| 5728 | continue; |
| 5729 | } |
| 5730 | } else if (priv->only_active_channel) |
| 5731 | continue; |
| 5732 | |
| 5733 | scan_ch->channel = channels[i].chan; |
| 5734 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5735 | ch_info = iwl4965_get_channel_info(priv, phymode, |
| 5736 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5737 | if (!is_channel_valid(ch_info)) { |
| 5738 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 5739 | scan_ch->channel); |
| 5740 | continue; |
| 5741 | } |
| 5742 | |
| 5743 | if (!is_active || is_channel_passive(ch_info) || |
| 5744 | !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN)) |
| 5745 | scan_ch->type = 0; /* passive */ |
| 5746 | else |
| 5747 | scan_ch->type = 1; /* active */ |
| 5748 | |
| 5749 | if (scan_ch->type & 1) |
| 5750 | scan_ch->type |= (direct_mask << 1); |
| 5751 | |
| 5752 | if (is_channel_narrow(ch_info)) |
| 5753 | scan_ch->type |= (1 << 7); |
| 5754 | |
| 5755 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 5756 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 5757 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5758 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5759 | scan_ch->tpc.dsp_atten = 110; |
| 5760 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 5761 | |
| 5762 | /*scan_pwr_info->tpc.tx_gain; */ |
| 5763 | if (phymode == MODE_IEEE80211A) |
| 5764 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 5765 | else { |
| 5766 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 5767 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5768 | * power level: |
| 5769 | * scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5770 | */ |
| 5771 | } |
| 5772 | |
| 5773 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 5774 | scan_ch->channel, |
| 5775 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 5776 | (scan_ch->type & 1) ? |
| 5777 | active_dwell : passive_dwell); |
| 5778 | |
| 5779 | scan_ch++; |
| 5780 | added++; |
| 5781 | } |
| 5782 | |
| 5783 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 5784 | return added; |
| 5785 | } |
| 5786 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5787 | static void iwl4965_reset_channel_flag(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5788 | { |
| 5789 | int i, j; |
| 5790 | for (i = 0; i < 3; i++) { |
| 5791 | struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i]; |
| 5792 | for (j = 0; j < hw_mode->num_channels; j++) |
| 5793 | hw_mode->channels[j].flag = hw_mode->channels[j].val; |
| 5794 | } |
| 5795 | } |
| 5796 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5797 | static void iwl4965_init_hw_rates(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5798 | struct ieee80211_rate *rates) |
| 5799 | { |
| 5800 | int i; |
| 5801 | |
| 5802 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5803 | rates[i].rate = iwl4965_rates[i].ieee * 5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5804 | rates[i].val = i; /* Rate scaling will work on indexes */ |
| 5805 | rates[i].val2 = i; |
| 5806 | rates[i].flags = IEEE80211_RATE_SUPPORTED; |
| 5807 | /* Only OFDM have the bits-per-symbol set */ |
| 5808 | if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE)) |
| 5809 | rates[i].flags |= IEEE80211_RATE_OFDM; |
| 5810 | else { |
| 5811 | /* |
| 5812 | * If CCK 1M then set rate flag to CCK else CCK_2 |
| 5813 | * which is CCK | PREAMBLE2 |
| 5814 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5815 | rates[i].flags |= (iwl4965_rates[i].plcp == 10) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5816 | IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2; |
| 5817 | } |
| 5818 | |
| 5819 | /* Set up which ones are basic rates... */ |
| 5820 | if (IWL_BASIC_RATES_MASK & (1 << i)) |
| 5821 | rates[i].flags |= IEEE80211_RATE_BASIC; |
| 5822 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5826 | * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5827 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5828 | static int iwl4965_init_geos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5829 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5830 | struct iwl4965_channel_info *ch; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5831 | struct ieee80211_hw_mode *modes; |
| 5832 | struct ieee80211_channel *channels; |
| 5833 | struct ieee80211_channel *geo_ch; |
| 5834 | struct ieee80211_rate *rates; |
| 5835 | int i = 0; |
| 5836 | enum { |
| 5837 | A = 0, |
| 5838 | B = 1, |
| 5839 | G = 2, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5840 | }; |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 5841 | int mode_count = 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5842 | |
| 5843 | if (priv->modes) { |
| 5844 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 5845 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5846 | return 0; |
| 5847 | } |
| 5848 | |
| 5849 | modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count, |
| 5850 | GFP_KERNEL); |
| 5851 | if (!modes) |
| 5852 | return -ENOMEM; |
| 5853 | |
| 5854 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 5855 | priv->channel_count, GFP_KERNEL); |
| 5856 | if (!channels) { |
| 5857 | kfree(modes); |
| 5858 | return -ENOMEM; |
| 5859 | } |
| 5860 | |
| 5861 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)), |
| 5862 | GFP_KERNEL); |
| 5863 | if (!rates) { |
| 5864 | kfree(modes); |
| 5865 | kfree(channels); |
| 5866 | return -ENOMEM; |
| 5867 | } |
| 5868 | |
| 5869 | /* 0 = 802.11a |
| 5870 | * 1 = 802.11b |
| 5871 | * 2 = 802.11g |
| 5872 | */ |
| 5873 | |
| 5874 | /* 5.2GHz channels start after the 2.4GHz channels */ |
| 5875 | modes[A].mode = MODE_IEEE80211A; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5876 | modes[A].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5877 | modes[A].rates = rates; |
| 5878 | modes[A].num_rates = 8; /* just OFDM */ |
| 5879 | modes[A].rates = &rates[4]; |
| 5880 | modes[A].num_channels = 0; |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 5881 | #ifdef CONFIG_IWL4965_HT |
| 5882 | iwl4965_init_ht_hw_capab(&modes[A].ht_info, MODE_IEEE80211A); |
| 5883 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5884 | |
| 5885 | modes[B].mode = MODE_IEEE80211B; |
| 5886 | modes[B].channels = channels; |
| 5887 | modes[B].rates = rates; |
| 5888 | modes[B].num_rates = 4; /* just CCK */ |
| 5889 | modes[B].num_channels = 0; |
| 5890 | |
| 5891 | modes[G].mode = MODE_IEEE80211G; |
| 5892 | modes[G].channels = channels; |
| 5893 | modes[G].rates = rates; |
| 5894 | modes[G].num_rates = 12; /* OFDM & CCK */ |
| 5895 | modes[G].num_channels = 0; |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 5896 | #ifdef CONFIG_IWL4965_HT |
| 5897 | iwl4965_init_ht_hw_capab(&modes[G].ht_info, MODE_IEEE80211G); |
| 5898 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5899 | |
| 5900 | priv->ieee_channels = channels; |
| 5901 | priv->ieee_rates = rates; |
| 5902 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5903 | iwl4965_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5904 | |
| 5905 | for (i = 0, geo_ch = channels; i < priv->channel_count; i++) { |
| 5906 | ch = &priv->channel_info[i]; |
| 5907 | |
| 5908 | if (!is_channel_valid(ch)) { |
| 5909 | IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- " |
| 5910 | "skipping.\n", |
| 5911 | ch->channel, is_channel_a_band(ch) ? |
| 5912 | "5.2" : "2.4"); |
| 5913 | continue; |
| 5914 | } |
| 5915 | |
| 5916 | if (is_channel_a_band(ch)) { |
| 5917 | geo_ch = &modes[A].channels[modes[A].num_channels++]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5918 | } else { |
| 5919 | geo_ch = &modes[B].channels[modes[B].num_channels++]; |
| 5920 | modes[G].num_channels++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | geo_ch->freq = ieee80211chan2mhz(ch->channel); |
| 5924 | geo_ch->chan = ch->channel; |
| 5925 | geo_ch->power_level = ch->max_power_avg; |
| 5926 | geo_ch->antenna_max = 0xff; |
| 5927 | |
| 5928 | if (is_channel_valid(ch)) { |
| 5929 | geo_ch->flag = IEEE80211_CHAN_W_SCAN; |
| 5930 | if (ch->flags & EEPROM_CHANNEL_IBSS) |
| 5931 | geo_ch->flag |= IEEE80211_CHAN_W_IBSS; |
| 5932 | |
| 5933 | if (ch->flags & EEPROM_CHANNEL_ACTIVE) |
| 5934 | geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN; |
| 5935 | |
| 5936 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
| 5937 | geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT; |
| 5938 | |
| 5939 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 5940 | priv->max_channel_txpower_limit = |
| 5941 | ch->max_power_avg; |
| 5942 | } |
| 5943 | |
| 5944 | geo_ch->val = geo_ch->flag; |
| 5945 | } |
| 5946 | |
| 5947 | if ((modes[A].num_channels == 0) && priv->is_abg) { |
| 5948 | printk(KERN_INFO DRV_NAME |
| 5949 | ": Incorrectly detected BG card as ABG. Please send " |
| 5950 | "your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 5951 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
| 5952 | priv->is_abg = 0; |
| 5953 | } |
| 5954 | |
| 5955 | printk(KERN_INFO DRV_NAME |
| 5956 | ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
| 5957 | modes[G].num_channels, modes[A].num_channels); |
| 5958 | |
| 5959 | /* |
| 5960 | * NOTE: We register these in preference of order -- the |
| 5961 | * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick |
| 5962 | * a phymode based on rates or AP capabilities but seems to |
| 5963 | * configure it purely on if the channel being configured |
| 5964 | * is supported by a mode -- and the first match is taken |
| 5965 | */ |
| 5966 | |
| 5967 | if (modes[G].num_channels) |
| 5968 | ieee80211_register_hwmode(priv->hw, &modes[G]); |
| 5969 | if (modes[B].num_channels) |
| 5970 | ieee80211_register_hwmode(priv->hw, &modes[B]); |
| 5971 | if (modes[A].num_channels) |
| 5972 | ieee80211_register_hwmode(priv->hw, &modes[A]); |
| 5973 | |
| 5974 | priv->modes = modes; |
| 5975 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5976 | |
| 5977 | return 0; |
| 5978 | } |
| 5979 | |
| 5980 | /****************************************************************************** |
| 5981 | * |
| 5982 | * uCode download functions |
| 5983 | * |
| 5984 | ******************************************************************************/ |
| 5985 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5986 | static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5987 | { |
| 5988 | if (priv->ucode_code.v_addr != NULL) { |
| 5989 | pci_free_consistent(priv->pci_dev, |
| 5990 | priv->ucode_code.len, |
| 5991 | priv->ucode_code.v_addr, |
| 5992 | priv->ucode_code.p_addr); |
| 5993 | priv->ucode_code.v_addr = NULL; |
| 5994 | } |
| 5995 | if (priv->ucode_data.v_addr != NULL) { |
| 5996 | pci_free_consistent(priv->pci_dev, |
| 5997 | priv->ucode_data.len, |
| 5998 | priv->ucode_data.v_addr, |
| 5999 | priv->ucode_data.p_addr); |
| 6000 | priv->ucode_data.v_addr = NULL; |
| 6001 | } |
| 6002 | if (priv->ucode_data_backup.v_addr != NULL) { |
| 6003 | pci_free_consistent(priv->pci_dev, |
| 6004 | priv->ucode_data_backup.len, |
| 6005 | priv->ucode_data_backup.v_addr, |
| 6006 | priv->ucode_data_backup.p_addr); |
| 6007 | priv->ucode_data_backup.v_addr = NULL; |
| 6008 | } |
| 6009 | if (priv->ucode_init.v_addr != NULL) { |
| 6010 | pci_free_consistent(priv->pci_dev, |
| 6011 | priv->ucode_init.len, |
| 6012 | priv->ucode_init.v_addr, |
| 6013 | priv->ucode_init.p_addr); |
| 6014 | priv->ucode_init.v_addr = NULL; |
| 6015 | } |
| 6016 | if (priv->ucode_init_data.v_addr != NULL) { |
| 6017 | pci_free_consistent(priv->pci_dev, |
| 6018 | priv->ucode_init_data.len, |
| 6019 | priv->ucode_init_data.v_addr, |
| 6020 | priv->ucode_init_data.p_addr); |
| 6021 | priv->ucode_init_data.v_addr = NULL; |
| 6022 | } |
| 6023 | if (priv->ucode_boot.v_addr != NULL) { |
| 6024 | pci_free_consistent(priv->pci_dev, |
| 6025 | priv->ucode_boot.len, |
| 6026 | priv->ucode_boot.v_addr, |
| 6027 | priv->ucode_boot.p_addr); |
| 6028 | priv->ucode_boot.v_addr = NULL; |
| 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6033 | * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6034 | * looking at all data. |
| 6035 | */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6036 | static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 * image, |
| 6037 | u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6038 | { |
| 6039 | u32 val; |
| 6040 | u32 save_len = len; |
| 6041 | int rc = 0; |
| 6042 | u32 errcnt; |
| 6043 | |
| 6044 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 6045 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6046 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6047 | if (rc) |
| 6048 | return rc; |
| 6049 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6050 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6051 | |
| 6052 | errcnt = 0; |
| 6053 | for (; len > 0; len -= sizeof(u32), image++) { |
| 6054 | /* read data comes through single port, auto-incr addr */ |
| 6055 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 6056 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6057 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6058 | if (val != le32_to_cpu(*image)) { |
| 6059 | IWL_ERROR("uCode INST section is invalid at " |
| 6060 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 6061 | save_len - len, val, le32_to_cpu(*image)); |
| 6062 | rc = -EIO; |
| 6063 | errcnt++; |
| 6064 | if (errcnt >= 20) |
| 6065 | break; |
| 6066 | } |
| 6067 | } |
| 6068 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6069 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6070 | |
| 6071 | if (!errcnt) |
| 6072 | IWL_DEBUG_INFO |
| 6073 | ("ucode image in INSTRUCTION memory is good\n"); |
| 6074 | |
| 6075 | return rc; |
| 6076 | } |
| 6077 | |
| 6078 | |
| 6079 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6080 | * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6081 | * using sample data 100 bytes apart. If these sample points are good, |
| 6082 | * it's a pretty good bet that everything between them is good, too. |
| 6083 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6084 | 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] | 6085 | { |
| 6086 | u32 val; |
| 6087 | int rc = 0; |
| 6088 | u32 errcnt = 0; |
| 6089 | u32 i; |
| 6090 | |
| 6091 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 6092 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6093 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6094 | if (rc) |
| 6095 | return rc; |
| 6096 | |
| 6097 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 6098 | /* read data comes through single port, auto-incr addr */ |
| 6099 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 6100 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6101 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6102 | i + RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6103 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6104 | if (val != le32_to_cpu(*image)) { |
| 6105 | #if 0 /* Enable this if you want to see details */ |
| 6106 | IWL_ERROR("uCode INST section is invalid at " |
| 6107 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 6108 | i, val, *image); |
| 6109 | #endif |
| 6110 | rc = -EIO; |
| 6111 | errcnt++; |
| 6112 | if (errcnt >= 3) |
| 6113 | break; |
| 6114 | } |
| 6115 | } |
| 6116 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6117 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6118 | |
| 6119 | return rc; |
| 6120 | } |
| 6121 | |
| 6122 | |
| 6123 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6124 | * iwl4965_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6125 | * and verify its contents |
| 6126 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6127 | static int iwl4965_verify_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6128 | { |
| 6129 | __le32 *image; |
| 6130 | u32 len; |
| 6131 | int rc = 0; |
| 6132 | |
| 6133 | /* Try bootstrap */ |
| 6134 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 6135 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6136 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6137 | if (rc == 0) { |
| 6138 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 6139 | return 0; |
| 6140 | } |
| 6141 | |
| 6142 | /* Try initialize */ |
| 6143 | image = (__le32 *)priv->ucode_init.v_addr; |
| 6144 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6145 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6146 | if (rc == 0) { |
| 6147 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 6148 | return 0; |
| 6149 | } |
| 6150 | |
| 6151 | /* Try runtime/protocol */ |
| 6152 | image = (__le32 *)priv->ucode_code.v_addr; |
| 6153 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6154 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6155 | if (rc == 0) { |
| 6156 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 6157 | return 0; |
| 6158 | } |
| 6159 | |
| 6160 | IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
| 6161 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6162 | /* Since nothing seems to match, show first several data entries in |
| 6163 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 6164 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6165 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 6166 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6167 | rc = iwl4965_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6168 | |
| 6169 | return rc; |
| 6170 | } |
| 6171 | |
| 6172 | |
| 6173 | /* check contents of special bootstrap uCode SRAM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6174 | static int iwl4965_verify_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6175 | { |
| 6176 | __le32 *image = priv->ucode_boot.v_addr; |
| 6177 | u32 len = priv->ucode_boot.len; |
| 6178 | u32 reg; |
| 6179 | u32 val; |
| 6180 | |
| 6181 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 6182 | |
| 6183 | /* verify BSM SRAM contents */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6184 | val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6185 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 6186 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 6187 | reg += sizeof(u32), image ++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6188 | val = iwl4965_read_prph(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6189 | if (val != le32_to_cpu(*image)) { |
| 6190 | IWL_ERROR("BSM uCode verification failed at " |
| 6191 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 6192 | BSM_SRAM_LOWER_BOUND, |
| 6193 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 6194 | val, le32_to_cpu(*image)); |
| 6195 | return -EIO; |
| 6196 | } |
| 6197 | } |
| 6198 | |
| 6199 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 6200 | |
| 6201 | return 0; |
| 6202 | } |
| 6203 | |
| 6204 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6205 | * iwl4965_load_bsm - Load bootstrap instructions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6206 | * |
| 6207 | * BSM operation: |
| 6208 | * |
| 6209 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 6210 | * in special SRAM that does not power down during RFKILL. When powering back |
| 6211 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 6212 | * the bootstrap program into the on-board processor, and starts it. |
| 6213 | * |
| 6214 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 6215 | * program from host DRAM locations indicated by the host driver in the |
| 6216 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 6217 | * automatically. |
| 6218 | * |
| 6219 | * When initializing the NIC, the host driver points the BSM to the |
| 6220 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 6221 | * notifies host via "initialize alive" that it is complete. |
| 6222 | * |
| 6223 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 6224 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 6225 | * (filled initially with starting data values for the on-board processor), |
| 6226 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 6227 | * which begins normal operation. |
| 6228 | * |
| 6229 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 6230 | * the backup data cache in DRAM before SRAM is powered down. |
| 6231 | * |
| 6232 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 6233 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 6234 | * and re-launches the runtime uCode from where it left off. |
| 6235 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6236 | static int iwl4965_load_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6237 | { |
| 6238 | __le32 *image = priv->ucode_boot.v_addr; |
| 6239 | u32 len = priv->ucode_boot.len; |
| 6240 | dma_addr_t pinst; |
| 6241 | dma_addr_t pdata; |
| 6242 | u32 inst_len; |
| 6243 | u32 data_len; |
| 6244 | int rc; |
| 6245 | int i; |
| 6246 | u32 done; |
| 6247 | u32 reg_offset; |
| 6248 | |
| 6249 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 6250 | |
| 6251 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 6252 | if (len > IWL_MAX_BSM_SIZE) |
| 6253 | return -EINVAL; |
| 6254 | |
| 6255 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6256 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6257 | * NOTE: iwl4965_initialize_alive_start() will replace these values, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6258 | * after the "initialize" uCode has run, to point to |
| 6259 | * runtime/protocol instructions and backup data cache. */ |
| 6260 | pinst = priv->ucode_init.p_addr >> 4; |
| 6261 | pdata = priv->ucode_init_data.p_addr >> 4; |
| 6262 | inst_len = priv->ucode_init.len; |
| 6263 | data_len = priv->ucode_init_data.len; |
| 6264 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6265 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6266 | if (rc) |
| 6267 | return rc; |
| 6268 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6269 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6270 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6271 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 6272 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6273 | |
| 6274 | /* Fill BSM memory with bootstrap instructions */ |
| 6275 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 6276 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 6277 | reg_offset += sizeof(u32), image++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6278 | _iwl4965_write_prph(priv, reg_offset, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6279 | le32_to_cpu(*image)); |
| 6280 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6281 | rc = iwl4965_verify_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6282 | if (rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6283 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6284 | return rc; |
| 6285 | } |
| 6286 | |
| 6287 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6288 | iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 6289 | iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6290 | RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6291 | iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6292 | |
| 6293 | /* Load bootstrap code into instruction SRAM now, |
| 6294 | * to prepare to load "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6295 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6296 | BSM_WR_CTRL_REG_BIT_START); |
| 6297 | |
| 6298 | /* Wait for load of bootstrap uCode to finish */ |
| 6299 | for (i = 0; i < 100; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6300 | done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6301 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 6302 | break; |
| 6303 | udelay(10); |
| 6304 | } |
| 6305 | if (i < 100) |
| 6306 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 6307 | else { |
| 6308 | IWL_ERROR("BSM write did not complete!\n"); |
| 6309 | return -EIO; |
| 6310 | } |
| 6311 | |
| 6312 | /* Enable future boot loads whenever power management unit triggers it |
| 6313 | * (e.g. when powering back up after power-save shutdown) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6314 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6315 | BSM_WR_CTRL_REG_BIT_START_EN); |
| 6316 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6317 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6318 | |
| 6319 | return 0; |
| 6320 | } |
| 6321 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6322 | static void iwl4965_nic_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6323 | { |
| 6324 | /* Remove all resets to allow NIC to operate */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6325 | iwl4965_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6326 | } |
| 6327 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6328 | static int iwl4965_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc) |
| 6329 | { |
| 6330 | desc->v_addr = pci_alloc_consistent(pci_dev, desc->len, &desc->p_addr); |
| 6331 | return (desc->v_addr != NULL) ? 0 : -ENOMEM; |
| 6332 | } |
| 6333 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6334 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6335 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6336 | * |
| 6337 | * Copy into buffers for card to fetch via bus-mastering |
| 6338 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6339 | static int iwl4965_read_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6340 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6341 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6342 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6343 | const struct firmware *ucode_raw; |
| 6344 | const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode"; |
| 6345 | u8 *src; |
| 6346 | size_t len; |
| 6347 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 6348 | |
| 6349 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 6350 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6351 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 6352 | if (ret < 0) { |
| 6353 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 6354 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6355 | goto error; |
| 6356 | } |
| 6357 | |
| 6358 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 6359 | name, ucode_raw->size); |
| 6360 | |
| 6361 | /* Make sure that we got at least our header! */ |
| 6362 | if (ucode_raw->size < sizeof(*ucode)) { |
| 6363 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6364 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6365 | goto err_release; |
| 6366 | } |
| 6367 | |
| 6368 | /* Data from ucode file: header followed by uCode images */ |
| 6369 | ucode = (void *)ucode_raw->data; |
| 6370 | |
| 6371 | ver = le32_to_cpu(ucode->ver); |
| 6372 | inst_size = le32_to_cpu(ucode->inst_size); |
| 6373 | data_size = le32_to_cpu(ucode->data_size); |
| 6374 | init_size = le32_to_cpu(ucode->init_size); |
| 6375 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 6376 | boot_size = le32_to_cpu(ucode->boot_size); |
| 6377 | |
| 6378 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 6379 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 6380 | inst_size); |
| 6381 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 6382 | data_size); |
| 6383 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 6384 | init_size); |
| 6385 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 6386 | init_data_size); |
| 6387 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 6388 | boot_size); |
| 6389 | |
| 6390 | /* Verify size of file vs. image size info in file's header */ |
| 6391 | if (ucode_raw->size < sizeof(*ucode) + |
| 6392 | inst_size + data_size + init_size + |
| 6393 | init_data_size + boot_size) { |
| 6394 | |
| 6395 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 6396 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6397 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6398 | goto err_release; |
| 6399 | } |
| 6400 | |
| 6401 | /* Verify that uCode images will fit in card's SRAM */ |
| 6402 | if (inst_size > IWL_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6403 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 6404 | inst_size); |
| 6405 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6406 | goto err_release; |
| 6407 | } |
| 6408 | |
| 6409 | if (data_size > IWL_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6410 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 6411 | data_size); |
| 6412 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6413 | goto err_release; |
| 6414 | } |
| 6415 | if (init_size > IWL_MAX_INST_SIZE) { |
| 6416 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6417 | ("uCode init instr len %d too large to fit in\n", |
| 6418 | init_size); |
| 6419 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6420 | goto err_release; |
| 6421 | } |
| 6422 | if (init_data_size > IWL_MAX_DATA_SIZE) { |
| 6423 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6424 | ("uCode init data len %d too large to fit in\n", |
| 6425 | init_data_size); |
| 6426 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6427 | goto err_release; |
| 6428 | } |
| 6429 | if (boot_size > IWL_MAX_BSM_SIZE) { |
| 6430 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6431 | ("uCode boot instr len %d too large to fit in\n", |
| 6432 | boot_size); |
| 6433 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6434 | goto err_release; |
| 6435 | } |
| 6436 | |
| 6437 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 6438 | |
| 6439 | /* Runtime instructions and 2 copies of data: |
| 6440 | * 1) unmodified from disk |
| 6441 | * 2) backup cache for save/restore during power-downs */ |
| 6442 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6443 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6444 | |
| 6445 | priv->ucode_data.len = data_size; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6446 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6447 | |
| 6448 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6449 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6450 | |
| 6451 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6452 | if (init_size && init_data_size) { |
| 6453 | priv->ucode_init.len = init_size; |
| 6454 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6455 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6456 | priv->ucode_init_data.len = init_data_size; |
| 6457 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 6458 | |
| 6459 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 6460 | goto err_pci_alloc; |
| 6461 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6462 | |
| 6463 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6464 | if (boot_size) { |
| 6465 | priv->ucode_boot.len = boot_size; |
| 6466 | iwl4965_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6467 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6468 | if (!priv->ucode_boot.v_addr) |
| 6469 | goto err_pci_alloc; |
| 6470 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6471 | |
| 6472 | /* Copy images into buffers for card's bus-master reads ... */ |
| 6473 | |
| 6474 | /* Runtime instructions (first block of data in file) */ |
| 6475 | src = &ucode->data[0]; |
| 6476 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6477 | 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] | 6478 | memcpy(priv->ucode_code.v_addr, src, len); |
| 6479 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 6480 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 6481 | |
| 6482 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6483 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6484 | src = &ucode->data[inst_size]; |
| 6485 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6486 | 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] | 6487 | memcpy(priv->ucode_data.v_addr, src, len); |
| 6488 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 6489 | |
| 6490 | /* Initialization instructions (3rd block) */ |
| 6491 | if (init_size) { |
| 6492 | src = &ucode->data[inst_size + data_size]; |
| 6493 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6494 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 6495 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6496 | memcpy(priv->ucode_init.v_addr, src, len); |
| 6497 | } |
| 6498 | |
| 6499 | /* Initialization data (4th block) */ |
| 6500 | if (init_data_size) { |
| 6501 | src = &ucode->data[inst_size + data_size + init_size]; |
| 6502 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6503 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 6504 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6505 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 6506 | } |
| 6507 | |
| 6508 | /* Bootstrap instructions (5th block) */ |
| 6509 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 6510 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6511 | 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] | 6512 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 6513 | |
| 6514 | /* We have our copies now, allow OS release its copies */ |
| 6515 | release_firmware(ucode_raw); |
| 6516 | return 0; |
| 6517 | |
| 6518 | err_pci_alloc: |
| 6519 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6520 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6521 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6522 | |
| 6523 | err_release: |
| 6524 | release_firmware(ucode_raw); |
| 6525 | |
| 6526 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6527 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6528 | } |
| 6529 | |
| 6530 | |
| 6531 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6532 | * iwl4965_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6533 | * |
| 6534 | * Tell initialization uCode where to find runtime uCode. |
| 6535 | * |
| 6536 | * BSM registers initially contain pointers to initialization uCode. |
| 6537 | * We need to replace them to load runtime uCode inst and data, |
| 6538 | * and to save runtime data when powering down. |
| 6539 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6540 | static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6541 | { |
| 6542 | dma_addr_t pinst; |
| 6543 | dma_addr_t pdata; |
| 6544 | int rc = 0; |
| 6545 | unsigned long flags; |
| 6546 | |
| 6547 | /* bits 35:4 for 4965 */ |
| 6548 | pinst = priv->ucode_code.p_addr >> 4; |
| 6549 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 6550 | |
| 6551 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6552 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6553 | if (rc) { |
| 6554 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6555 | return rc; |
| 6556 | } |
| 6557 | |
| 6558 | /* Tell bootstrap uCode where to find image to load */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6559 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6560 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6561 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6562 | priv->ucode_data.len); |
| 6563 | |
| 6564 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 6565 | * that all new ptr/size info is in place */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6566 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6567 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 6568 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6569 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6570 | |
| 6571 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6572 | |
| 6573 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 6574 | |
| 6575 | return rc; |
| 6576 | } |
| 6577 | |
| 6578 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6579 | * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6580 | * |
| 6581 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 6582 | * |
| 6583 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 6584 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 6585 | * (3945 does not contain this data). |
| 6586 | * |
| 6587 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 6588 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6589 | static void iwl4965_init_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6590 | { |
| 6591 | /* Check alive response for "valid" sign from uCode */ |
| 6592 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 6593 | /* We had an error bringing up the hardware, so take it |
| 6594 | * all the way back down so we can try again */ |
| 6595 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 6596 | goto restart; |
| 6597 | } |
| 6598 | |
| 6599 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 6600 | * This is a paranoid check, because we would not have gotten the |
| 6601 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6602 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6603 | /* Runtime instruction load was bad; |
| 6604 | * take it all the way back down so we can try again */ |
| 6605 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 6606 | goto restart; |
| 6607 | } |
| 6608 | |
| 6609 | /* Calculate temperature */ |
| 6610 | priv->temperature = iwl4965_get_temperature(priv); |
| 6611 | |
| 6612 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 6613 | * load and launch runtime uCode, which will send us another "Alive" |
| 6614 | * notification. */ |
| 6615 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6616 | if (iwl4965_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6617 | /* Runtime instruction load won't happen; |
| 6618 | * take it all the way back down so we can try again */ |
| 6619 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 6620 | goto restart; |
| 6621 | } |
| 6622 | return; |
| 6623 | |
| 6624 | restart: |
| 6625 | queue_work(priv->workqueue, &priv->restart); |
| 6626 | } |
| 6627 | |
| 6628 | |
| 6629 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6630 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6631 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6632 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6633 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6634 | static void iwl4965_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6635 | { |
| 6636 | int rc = 0; |
| 6637 | |
| 6638 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 6639 | |
| 6640 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 6641 | /* We had an error bringing up the hardware, so take it |
| 6642 | * all the way back down so we can try again */ |
| 6643 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 6644 | goto restart; |
| 6645 | } |
| 6646 | |
| 6647 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 6648 | * This is a paranoid check, because we would not have gotten the |
| 6649 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6650 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6651 | /* Runtime instruction load was bad; |
| 6652 | * take it all the way back down so we can try again */ |
| 6653 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 6654 | goto restart; |
| 6655 | } |
| 6656 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6657 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6658 | |
| 6659 | rc = iwl4965_alive_notify(priv); |
| 6660 | if (rc) { |
| 6661 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
| 6662 | rc); |
| 6663 | goto restart; |
| 6664 | } |
| 6665 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6666 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6667 | set_bit(STATUS_ALIVE, &priv->status); |
| 6668 | |
| 6669 | /* Clear out the uCode error bit if it is set */ |
| 6670 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 6671 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6672 | rc = iwl4965_init_channel_map(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6673 | if (rc) { |
| 6674 | IWL_ERROR("initializing regulatory failed: %d\n", rc); |
| 6675 | return; |
| 6676 | } |
| 6677 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6678 | iwl4965_init_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6679 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6680 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6681 | return; |
| 6682 | |
| 6683 | if (!priv->mac80211_registered) { |
| 6684 | /* Unlock so any user space entry points can call back into |
| 6685 | * the driver without a deadlock... */ |
| 6686 | mutex_unlock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6687 | iwl4965_rate_control_register(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6688 | rc = ieee80211_register_hw(priv->hw); |
| 6689 | priv->hw->conf.beacon_int = 100; |
| 6690 | mutex_lock(&priv->mutex); |
| 6691 | |
| 6692 | if (rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6693 | iwl4965_rate_control_unregister(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6694 | IWL_ERROR("Failed to register network " |
| 6695 | "device (error %d)\n", rc); |
| 6696 | return; |
| 6697 | } |
| 6698 | |
| 6699 | priv->mac80211_registered = 1; |
| 6700 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6701 | iwl4965_reset_channel_flag(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6702 | } else |
| 6703 | ieee80211_start_queues(priv->hw); |
| 6704 | |
| 6705 | priv->active_rate = priv->rates_mask; |
| 6706 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 6707 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6708 | iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6709 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6710 | if (iwl4965_is_associated(priv)) { |
| 6711 | struct iwl4965_rxon_cmd *active_rxon = |
| 6712 | (struct iwl4965_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6713 | |
| 6714 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 6715 | sizeof(priv->staging_rxon)); |
| 6716 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 6717 | } else { |
| 6718 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6719 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6720 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 6721 | } |
| 6722 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6723 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6724 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6725 | |
| 6726 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6727 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6728 | |
| 6729 | /* At this point, the NIC is initialized and operational */ |
| 6730 | priv->notif_missed_beacons = 0; |
| 6731 | set_bit(STATUS_READY, &priv->status); |
| 6732 | |
| 6733 | iwl4965_rf_kill_ct_config(priv); |
| 6734 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
| 6735 | |
| 6736 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6737 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6738 | |
| 6739 | return; |
| 6740 | |
| 6741 | restart: |
| 6742 | queue_work(priv->workqueue, &priv->restart); |
| 6743 | } |
| 6744 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6745 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6746 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6747 | static void __iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6748 | { |
| 6749 | unsigned long flags; |
| 6750 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6751 | struct ieee80211_conf *conf = NULL; |
| 6752 | |
| 6753 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 6754 | |
| 6755 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6756 | |
| 6757 | if (!exit_pending) |
| 6758 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6759 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6760 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6761 | |
| 6762 | /* Unblock any waiting calls */ |
| 6763 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 6764 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6765 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 6766 | * exiting the module */ |
| 6767 | if (!exit_pending) |
| 6768 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6769 | |
| 6770 | /* stop and reset the on-board processor */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6771 | iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6772 | |
| 6773 | /* tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6774 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6775 | |
| 6776 | if (priv->mac80211_registered) |
| 6777 | ieee80211_stop_queues(priv->hw); |
| 6778 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6779 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6780 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6781 | if (!iwl4965_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6782 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6783 | STATUS_RF_KILL_HW | |
| 6784 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6785 | STATUS_RF_KILL_SW | |
| 6786 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6787 | STATUS_IN_SUSPEND; |
| 6788 | goto exit; |
| 6789 | } |
| 6790 | |
| 6791 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 6792 | * SUSPEND bits and continue taking the NIC down. */ |
| 6793 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6794 | STATUS_RF_KILL_HW | |
| 6795 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6796 | STATUS_RF_KILL_SW | |
| 6797 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6798 | STATUS_IN_SUSPEND | |
| 6799 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 6800 | STATUS_FW_ERROR; |
| 6801 | |
| 6802 | spin_lock_irqsave(&priv->lock, flags); |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6803 | iwl4965_clear_bit(priv, CSR_GP_CNTRL, |
| 6804 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6805 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6806 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6807 | iwl4965_hw_txq_ctx_stop(priv); |
| 6808 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6809 | |
| 6810 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6811 | if (!iwl4965_grab_nic_access(priv)) { |
| 6812 | iwl4965_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6813 | APMG_CLK_VAL_DMA_CLK_RQT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6814 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6815 | } |
| 6816 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6817 | |
| 6818 | udelay(5); |
| 6819 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6820 | iwl4965_hw_nic_stop_master(priv); |
| 6821 | iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
| 6822 | iwl4965_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6823 | |
| 6824 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6825 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6826 | |
| 6827 | if (priv->ibss_beacon) |
| 6828 | dev_kfree_skb(priv->ibss_beacon); |
| 6829 | priv->ibss_beacon = NULL; |
| 6830 | |
| 6831 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6832 | iwl4965_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6833 | } |
| 6834 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6835 | static void iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6836 | { |
| 6837 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6838 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6839 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6840 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6841 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | #define MAX_HW_RESTARTS 5 |
| 6845 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6846 | static int __iwl4965_up(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6847 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6848 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6849 | int rc, i; |
| 6850 | u32 hw_rf_kill = 0; |
| 6851 | |
| 6852 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6853 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 6854 | return -EIO; |
| 6855 | } |
| 6856 | |
| 6857 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 6858 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 6859 | "parameter)\n"); |
| 6860 | return 0; |
| 6861 | } |
| 6862 | |
Reinette Chatre | a781cf9 | 2008-01-21 10:08:31 -0800 | [diff] [blame] | 6863 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 6864 | IWL_ERROR("ucode not available for device bringup\n"); |
| 6865 | return -EIO; |
| 6866 | } |
| 6867 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6868 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
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 | rc = iwl4965_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6871 | if (rc) { |
| 6872 | IWL_ERROR("Unable to int nic\n"); |
| 6873 | return rc; |
| 6874 | } |
| 6875 | |
| 6876 | /* make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6877 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6878 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6879 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 6880 | |
| 6881 | /* clear (again), then enable host interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6882 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 6883 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6884 | |
| 6885 | /* really make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6886 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6887 | 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] | 6888 | |
| 6889 | /* Copy original ucode data image from disk into backup cache. |
| 6890 | * This will be used to initialize the on-board processor's |
| 6891 | * data SRAM for a clean start when the runtime program first loads. */ |
| 6892 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
| 6893 | priv->ucode_data.len); |
| 6894 | |
| 6895 | /* If platform's RF_KILL switch is set to KILL, |
| 6896 | * wait for BIT_INT_RF_KILL interrupt before loading uCode |
| 6897 | * and getting things started */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6898 | if (!(iwl4965_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6899 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 6900 | hw_rf_kill = 1; |
| 6901 | |
| 6902 | if (test_bit(STATUS_RF_KILL_HW, &priv->status) || hw_rf_kill) { |
| 6903 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 6904 | return 0; |
| 6905 | } |
| 6906 | |
| 6907 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 6908 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6909 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6910 | |
| 6911 | /* load bootstrap state machine, |
| 6912 | * load bootstrap program into processor's memory, |
| 6913 | * prepare to load the "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6914 | rc = iwl4965_load_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6915 | |
| 6916 | if (rc) { |
| 6917 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); |
| 6918 | continue; |
| 6919 | } |
| 6920 | |
| 6921 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6922 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6923 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6924 | /* MAC Address location in EEPROM is same for 3945/4965 */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6925 | get_eeprom_mac(priv, priv->mac_addr); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6926 | IWL_DEBUG_INFO("MAC address: %s\n", |
| 6927 | print_mac(mac, priv->mac_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6928 | |
| 6929 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 6930 | |
| 6931 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 6932 | |
| 6933 | return 0; |
| 6934 | } |
| 6935 | |
| 6936 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6937 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6938 | |
| 6939 | /* tried to restart and config the device for as long as our |
| 6940 | * patience could withstand */ |
| 6941 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 6942 | return -EIO; |
| 6943 | } |
| 6944 | |
| 6945 | |
| 6946 | /***************************************************************************** |
| 6947 | * |
| 6948 | * Workqueue callbacks |
| 6949 | * |
| 6950 | *****************************************************************************/ |
| 6951 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6952 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6953 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6954 | struct iwl4965_priv *priv = |
| 6955 | container_of(data, struct iwl4965_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6956 | |
| 6957 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6958 | return; |
| 6959 | |
| 6960 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6961 | iwl4965_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6962 | mutex_unlock(&priv->mutex); |
| 6963 | } |
| 6964 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6965 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6966 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6967 | struct iwl4965_priv *priv = |
| 6968 | container_of(data, struct iwl4965_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6969 | |
| 6970 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6971 | return; |
| 6972 | |
| 6973 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6974 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6975 | mutex_unlock(&priv->mutex); |
| 6976 | } |
| 6977 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6978 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6979 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6980 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6981 | |
| 6982 | wake_up_interruptible(&priv->wait_command_queue); |
| 6983 | |
| 6984 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6985 | return; |
| 6986 | |
| 6987 | mutex_lock(&priv->mutex); |
| 6988 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6989 | if (!iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6990 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 6991 | "HW and/or SW RF Kill no longer active, restarting " |
| 6992 | "device\n"); |
| 6993 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6994 | queue_work(priv->workqueue, &priv->restart); |
| 6995 | } else { |
| 6996 | |
| 6997 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 6998 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 6999 | "disabled by SW switch\n"); |
| 7000 | else |
| 7001 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 7002 | "Kill switch must be turned off for " |
| 7003 | "wireless networking to work.\n"); |
| 7004 | } |
| 7005 | mutex_unlock(&priv->mutex); |
| 7006 | } |
| 7007 | |
| 7008 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 7009 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7010 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7011 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7012 | struct iwl4965_priv *priv = |
| 7013 | container_of(data, struct iwl4965_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7014 | |
| 7015 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7016 | return; |
| 7017 | |
| 7018 | mutex_lock(&priv->mutex); |
| 7019 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 7020 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 7021 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 7022 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 7023 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7024 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7025 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7026 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7027 | } |
| 7028 | mutex_unlock(&priv->mutex); |
| 7029 | } |
| 7030 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7031 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7032 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7033 | struct iwl4965_priv *priv = |
| 7034 | container_of(data, struct iwl4965_priv, request_scan); |
| 7035 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7036 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7037 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7038 | .meta.flags = CMD_SIZE_HUGE, |
| 7039 | }; |
| 7040 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7041 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7042 | struct ieee80211_conf *conf = NULL; |
| 7043 | u8 direct_mask; |
| 7044 | int phymode; |
| 7045 | |
| 7046 | conf = ieee80211_get_hw_conf(priv->hw); |
| 7047 | |
| 7048 | mutex_lock(&priv->mutex); |
| 7049 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7050 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7051 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 7052 | goto done; |
| 7053 | } |
| 7054 | |
| 7055 | /* Make sure the scan wasn't cancelled before this queued work |
| 7056 | * was given the chance to run... */ |
| 7057 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 7058 | goto done; |
| 7059 | |
| 7060 | /* This should never be called or scheduled if there is currently |
| 7061 | * a scan active in the hardware. */ |
| 7062 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 7063 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 7064 | "Ignoring second request.\n"); |
| 7065 | rc = -EIO; |
| 7066 | goto done; |
| 7067 | } |
| 7068 | |
| 7069 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 7070 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 7071 | goto done; |
| 7072 | } |
| 7073 | |
| 7074 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 7075 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 7076 | goto done; |
| 7077 | } |
| 7078 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7079 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7080 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 7081 | goto done; |
| 7082 | } |
| 7083 | |
| 7084 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 7085 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 7086 | goto done; |
| 7087 | } |
| 7088 | |
| 7089 | if (!priv->scan_bands) { |
| 7090 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 7091 | goto done; |
| 7092 | } |
| 7093 | |
| 7094 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7095 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7096 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 7097 | if (!priv->scan) { |
| 7098 | rc = -ENOMEM; |
| 7099 | goto done; |
| 7100 | } |
| 7101 | } |
| 7102 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7103 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7104 | |
| 7105 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 7106 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 7107 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7108 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7109 | u16 interval = 0; |
| 7110 | u32 extra; |
| 7111 | u32 suspend_time = 100; |
| 7112 | u32 scan_suspend_time = 100; |
| 7113 | unsigned long flags; |
| 7114 | |
| 7115 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 7116 | |
| 7117 | spin_lock_irqsave(&priv->lock, flags); |
| 7118 | interval = priv->beacon_int; |
| 7119 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7120 | |
| 7121 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7122 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7123 | if (!interval) |
| 7124 | interval = suspend_time; |
| 7125 | |
| 7126 | extra = (suspend_time / interval) << 22; |
| 7127 | scan_suspend_time = (extra | |
| 7128 | ((suspend_time % interval) * 1024)); |
| 7129 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 7130 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 7131 | scan_suspend_time, interval); |
| 7132 | } |
| 7133 | |
| 7134 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 7135 | if (priv->one_direct_scan) { |
| 7136 | IWL_DEBUG_SCAN |
| 7137 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7138 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7139 | priv->direct_ssid_len)); |
| 7140 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 7141 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 7142 | memcpy(scan->direct_scan[0].ssid, |
| 7143 | priv->direct_ssid, priv->direct_ssid_len); |
| 7144 | direct_mask = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7145 | } else if (!iwl4965_is_associated(priv) && priv->essid_len) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7146 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 7147 | scan->direct_scan[0].len = priv->essid_len; |
| 7148 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 7149 | direct_mask = 1; |
| 7150 | } else |
| 7151 | direct_mask = 0; |
| 7152 | |
| 7153 | /* We don't build a direct scan probe request; the uCode will do |
| 7154 | * that based on the direct_mask added to each channel entry */ |
| 7155 | scan->tx_cmd.len = cpu_to_le16( |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7156 | iwl4965_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7157 | IWL_MAX_SCAN_SIZE - sizeof(scan), 0)); |
| 7158 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 7159 | scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; |
| 7160 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 7161 | |
| 7162 | /* flags + rate selection */ |
| 7163 | |
| 7164 | scan->tx_cmd.tx_flags |= cpu_to_le32(0x200); |
| 7165 | |
| 7166 | switch (priv->scan_bands) { |
| 7167 | case 2: |
| 7168 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 7169 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7170 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7171 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 7172 | |
| 7173 | scan->good_CRC_th = 0; |
| 7174 | phymode = MODE_IEEE80211G; |
| 7175 | break; |
| 7176 | |
| 7177 | case 1: |
| 7178 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7179 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7180 | RATE_MCS_ANT_B_MSK); |
| 7181 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
| 7182 | phymode = MODE_IEEE80211A; |
| 7183 | break; |
| 7184 | |
| 7185 | default: |
| 7186 | IWL_WARNING("Invalid scan band count\n"); |
| 7187 | goto done; |
| 7188 | } |
| 7189 | |
| 7190 | /* select Rx chains */ |
| 7191 | |
| 7192 | /* Force use of chains B and C (0x6) for scan Rx. |
| 7193 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 7194 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 7195 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 7196 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 7197 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 7198 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 7199 | |
| 7200 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 7201 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 7202 | |
| 7203 | if (direct_mask) |
| 7204 | IWL_DEBUG_SCAN |
| 7205 | ("Initiating direct scan for %s.\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7206 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7207 | else |
| 7208 | IWL_DEBUG_SCAN("Initiating indirect scan.\n"); |
| 7209 | |
| 7210 | scan->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7211 | iwl4965_get_channels_for_scan( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7212 | priv, phymode, 1, /* active */ |
| 7213 | direct_mask, |
| 7214 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
| 7215 | |
| 7216 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7217 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7218 | cmd.data = scan; |
| 7219 | scan->len = cpu_to_le16(cmd.len); |
| 7220 | |
| 7221 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7222 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7223 | if (rc) |
| 7224 | goto done; |
| 7225 | |
| 7226 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 7227 | IWL_SCAN_CHECK_WATCHDOG); |
| 7228 | |
| 7229 | mutex_unlock(&priv->mutex); |
| 7230 | return; |
| 7231 | |
| 7232 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 7233 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7234 | queue_work(priv->workqueue, &priv->scan_completed); |
| 7235 | mutex_unlock(&priv->mutex); |
| 7236 | } |
| 7237 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7238 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7239 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7240 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7241 | |
| 7242 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7243 | return; |
| 7244 | |
| 7245 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7246 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7247 | mutex_unlock(&priv->mutex); |
| 7248 | } |
| 7249 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7250 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7251 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7252 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7253 | |
| 7254 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7255 | return; |
| 7256 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7257 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7258 | queue_work(priv->workqueue, &priv->up); |
| 7259 | } |
| 7260 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7261 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7262 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7263 | struct iwl4965_priv *priv = |
| 7264 | container_of(data, struct iwl4965_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7265 | |
| 7266 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7267 | return; |
| 7268 | |
| 7269 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7270 | iwl4965_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7271 | mutex_unlock(&priv->mutex); |
| 7272 | } |
| 7273 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7274 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 7275 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7276 | static void iwl4965_bg_post_associate(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7277 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7278 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7279 | post_associate.work); |
| 7280 | |
| 7281 | int rc = 0; |
| 7282 | struct ieee80211_conf *conf = NULL; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7283 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7284 | |
| 7285 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7286 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 7287 | return; |
| 7288 | } |
| 7289 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7290 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 7291 | priv->assoc_id, |
| 7292 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7293 | |
| 7294 | |
| 7295 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7296 | return; |
| 7297 | |
| 7298 | mutex_lock(&priv->mutex); |
| 7299 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7300 | if (!priv->interface_id || !priv->is_open) { |
| 7301 | mutex_unlock(&priv->mutex); |
| 7302 | return; |
| 7303 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7304 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7305 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7306 | conf = ieee80211_get_hw_conf(priv->hw); |
| 7307 | |
| 7308 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7309 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7310 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7311 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7312 | iwl4965_setup_rxon_timing(priv); |
| 7313 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7314 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7315 | if (rc) |
| 7316 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7317 | "Attempting to continue.\n"); |
| 7318 | |
| 7319 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 7320 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7321 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7322 | if (priv->current_ht_config.is_ht) |
| 7323 | iwl4965_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7324 | #endif /* CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7325 | iwl4965_set_rxon_chain(priv); |
| 7326 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7327 | |
| 7328 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 7329 | priv->assoc_id, priv->beacon_int); |
| 7330 | |
| 7331 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7332 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7333 | else |
| 7334 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7335 | |
| 7336 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7337 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7338 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 7339 | else |
| 7340 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7341 | |
| 7342 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7343 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7344 | |
| 7345 | } |
| 7346 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7347 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7348 | |
| 7349 | switch (priv->iw_mode) { |
| 7350 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7351 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7352 | break; |
| 7353 | |
| 7354 | case IEEE80211_IF_TYPE_IBSS: |
| 7355 | |
| 7356 | /* clear out the station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7357 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7358 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7359 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
| 7360 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 7361 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 7362 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7363 | |
| 7364 | break; |
| 7365 | |
| 7366 | default: |
| 7367 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 7368 | __FUNCTION__, priv->iw_mode); |
| 7369 | break; |
| 7370 | } |
| 7371 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7372 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7373 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7374 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7375 | /* Enable Rx differential gain and sensitivity calibrations */ |
| 7376 | iwl4965_chain_noise_reset(priv); |
| 7377 | priv->start_calib = 1; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7378 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7379 | |
| 7380 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7381 | priv->assoc_station_added = 1; |
| 7382 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7383 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7384 | iwl4965_activate_qos(priv, 0); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7385 | #endif /* CONFIG_IWL4965_QOS */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7386 | /* we have just associated, don't start scan too early */ |
| 7387 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7388 | mutex_unlock(&priv->mutex); |
| 7389 | } |
| 7390 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7391 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7392 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7393 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7394 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7395 | if (!iwl4965_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7396 | return; |
| 7397 | |
| 7398 | mutex_lock(&priv->mutex); |
| 7399 | |
| 7400 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7401 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7402 | |
| 7403 | mutex_unlock(&priv->mutex); |
| 7404 | } |
| 7405 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7406 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 7407 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7408 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7409 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7410 | struct iwl4965_priv *priv = |
| 7411 | container_of(work, struct iwl4965_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7412 | |
| 7413 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 7414 | |
| 7415 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7416 | return; |
| 7417 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7418 | if (priv->cache_conf) |
| 7419 | iwl4965_mac_config(priv->hw, priv->cache_conf); |
| 7420 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7421 | ieee80211_scan_completed(priv->hw); |
| 7422 | |
| 7423 | /* Since setting the TXPOWER may have been deferred while |
| 7424 | * performing the scan, fire one off */ |
| 7425 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7426 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7427 | mutex_unlock(&priv->mutex); |
| 7428 | } |
| 7429 | |
| 7430 | /***************************************************************************** |
| 7431 | * |
| 7432 | * mac80211 entry point functions |
| 7433 | * |
| 7434 | *****************************************************************************/ |
| 7435 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7436 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7437 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7438 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7439 | |
| 7440 | IWL_DEBUG_MAC80211("enter\n"); |
| 7441 | |
| 7442 | /* we should be verifying the device is ready to be opened */ |
| 7443 | mutex_lock(&priv->mutex); |
| 7444 | |
| 7445 | priv->is_open = 1; |
| 7446 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7447 | if (!iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7448 | ieee80211_start_queues(priv->hw); |
| 7449 | |
| 7450 | mutex_unlock(&priv->mutex); |
| 7451 | IWL_DEBUG_MAC80211("leave\n"); |
| 7452 | return 0; |
| 7453 | } |
| 7454 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7455 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7456 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7457 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7458 | |
| 7459 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7460 | |
| 7461 | |
| 7462 | mutex_lock(&priv->mutex); |
| 7463 | /* stop mac, cancel any scan request and clear |
| 7464 | * RXON_FILTER_ASSOC_MSK BIT |
| 7465 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7466 | priv->is_open = 0; |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7467 | if (!iwl4965_is_ready_rf(priv)) { |
| 7468 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7469 | mutex_unlock(&priv->mutex); |
| 7470 | return; |
| 7471 | } |
| 7472 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7473 | iwl4965_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7474 | cancel_delayed_work(&priv->post_associate); |
| 7475 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7476 | iwl4965_commit_rxon(priv); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7477 | mutex_unlock(&priv->mutex); |
| 7478 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7479 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7480 | } |
| 7481 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7482 | 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] | 7483 | struct ieee80211_tx_control *ctl) |
| 7484 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7485 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7486 | |
| 7487 | IWL_DEBUG_MAC80211("enter\n"); |
| 7488 | |
| 7489 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 7490 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 7491 | return -1; |
| 7492 | } |
| 7493 | |
| 7494 | IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
| 7495 | ctl->tx_rate); |
| 7496 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7497 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7498 | dev_kfree_skb_any(skb); |
| 7499 | |
| 7500 | IWL_DEBUG_MAC80211("leave\n"); |
| 7501 | return 0; |
| 7502 | } |
| 7503 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7504 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7505 | struct ieee80211_if_init_conf *conf) |
| 7506 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7507 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7508 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7509 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7510 | |
| 7511 | IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7512 | |
| 7513 | if (priv->interface_id) { |
| 7514 | IWL_DEBUG_MAC80211("leave - interface_id != 0\n"); |
| 7515 | return 0; |
| 7516 | } |
| 7517 | |
| 7518 | spin_lock_irqsave(&priv->lock, flags); |
| 7519 | priv->interface_id = conf->if_id; |
| 7520 | |
| 7521 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7522 | |
| 7523 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 7524 | |
| 7525 | if (conf->mac_addr) { |
| 7526 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 7527 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 7528 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7529 | iwl4965_set_mode(priv, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7530 | |
| 7531 | IWL_DEBUG_MAC80211("leave\n"); |
| 7532 | mutex_unlock(&priv->mutex); |
| 7533 | |
| 7534 | return 0; |
| 7535 | } |
| 7536 | |
| 7537 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7538 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7539 | * |
| 7540 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 7541 | * be set inappropriately and the driver currently sets the hardware up to |
| 7542 | * use it whenever needed. |
| 7543 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7544 | 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] | 7545 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7546 | struct iwl4965_priv *priv = hw->priv; |
| 7547 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7548 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7549 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7550 | |
| 7551 | mutex_lock(&priv->mutex); |
| 7552 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel); |
| 7553 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7554 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7555 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7556 | ret = -EIO; |
| 7557 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7558 | } |
| 7559 | |
| 7560 | /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 7561 | * what is exposed through include/ declarations */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7562 | if (unlikely(!iwl4965_param_disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7563 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7564 | |
| 7565 | if (unlikely(priv->cache_conf)) |
| 7566 | IWL_DEBUG_MAC80211("leave - still scanning\n"); |
| 7567 | else { |
| 7568 | /* Cache the configuration now so that we can |
| 7569 | * replay it after the hardware scan is finished. */ |
| 7570 | priv->cache_conf = kmalloc(sizeof(*conf), GFP_KERNEL); |
| 7571 | if (priv->cache_conf) { |
| 7572 | memcpy(priv->cache_conf, conf, sizeof(*conf)); |
| 7573 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7574 | } else { |
| 7575 | IWL_DEBUG_MAC80211("leave - no memory\n"); |
| 7576 | ret = -ENOMEM; |
| 7577 | } |
| 7578 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7579 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7580 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7581 | } |
| 7582 | |
| 7583 | spin_lock_irqsave(&priv->lock, flags); |
| 7584 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7585 | ch_info = iwl4965_get_channel_info(priv, conf->phymode, conf->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7586 | if (!is_channel_valid(ch_info)) { |
| 7587 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n", |
| 7588 | conf->channel, conf->phymode); |
| 7589 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 7590 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7591 | ret = -EINVAL; |
| 7592 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7593 | } |
| 7594 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7595 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7596 | /* if we are switching fron ht to 2.4 clear flags |
| 7597 | * from any ht related info since 2.4 does not |
| 7598 | * support ht */ |
| 7599 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel) |
| 7600 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7601 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 7602 | #endif |
| 7603 | ) |
| 7604 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7605 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7606 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7607 | iwl4965_set_rxon_channel(priv, conf->phymode, conf->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7608 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7609 | iwl4965_set_flags_for_phymode(priv, conf->phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7610 | |
| 7611 | /* The list of supported rates and rate mask can be different |
| 7612 | * for each phymode; since the phymode may have changed, reset |
| 7613 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7614 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7615 | |
| 7616 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7617 | |
| 7618 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7619 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7620 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7621 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7622 | } |
| 7623 | #endif |
| 7624 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7625 | iwl4965_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7626 | |
| 7627 | if (!conf->radio_enabled) { |
| 7628 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7629 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7630 | } |
| 7631 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7632 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7633 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7634 | ret = -EIO; |
| 7635 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7636 | } |
| 7637 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7638 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7639 | |
| 7640 | if (memcmp(&priv->active_rxon, |
| 7641 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7642 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7643 | else |
| 7644 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 7645 | |
| 7646 | IWL_DEBUG_MAC80211("leave\n"); |
| 7647 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7648 | out: |
| 7649 | if (priv->cache_conf) { |
| 7650 | kfree(priv->cache_conf); |
| 7651 | priv->cache_conf = NULL; |
| 7652 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7653 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7654 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7655 | } |
| 7656 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7657 | static void iwl4965_config_ap(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7658 | { |
| 7659 | int rc = 0; |
| 7660 | |
| 7661 | if (priv->status & STATUS_EXIT_PENDING) |
| 7662 | return; |
| 7663 | |
| 7664 | /* The following should be done only at AP bring up */ |
| 7665 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 7666 | |
| 7667 | /* RXON - unassoc (to set timing command) */ |
| 7668 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7669 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7670 | |
| 7671 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7672 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7673 | iwl4965_setup_rxon_timing(priv); |
| 7674 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7675 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7676 | if (rc) |
| 7677 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7678 | "Attempting to continue.\n"); |
| 7679 | |
| 7680 | iwl4965_set_rxon_chain(priv); |
| 7681 | |
| 7682 | /* FIXME: what should be the assoc_id for AP? */ |
| 7683 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7684 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7685 | priv->staging_rxon.flags |= |
| 7686 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7687 | else |
| 7688 | priv->staging_rxon.flags &= |
| 7689 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7690 | |
| 7691 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7692 | if (priv->assoc_capability & |
| 7693 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7694 | priv->staging_rxon.flags |= |
| 7695 | RXON_FLG_SHORT_SLOT_MSK; |
| 7696 | else |
| 7697 | priv->staging_rxon.flags &= |
| 7698 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7699 | |
| 7700 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7701 | priv->staging_rxon.flags &= |
| 7702 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7703 | } |
| 7704 | /* restore RXON assoc */ |
| 7705 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7706 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7707 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7708 | iwl4965_activate_qos(priv, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7709 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7710 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 7711 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7712 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7713 | |
| 7714 | /* FIXME - we need to add code here to detect a totally new |
| 7715 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 7716 | * clear sta table, add BCAST sta... */ |
| 7717 | } |
| 7718 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7719 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, int if_id, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7720 | struct ieee80211_if_conf *conf) |
| 7721 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7722 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7723 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7724 | unsigned long flags; |
| 7725 | int rc; |
| 7726 | |
| 7727 | if (conf == NULL) |
| 7728 | return -EIO; |
| 7729 | |
| 7730 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 7731 | (!conf->beacon || !conf->ssid_len)) { |
| 7732 | IWL_DEBUG_MAC80211 |
| 7733 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 7734 | return 0; |
| 7735 | } |
| 7736 | |
| 7737 | mutex_lock(&priv->mutex); |
| 7738 | |
| 7739 | IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id); |
| 7740 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7741 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 7742 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7743 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7744 | /* |
| 7745 | * very dubious code was here; the probe filtering flag is never set: |
| 7746 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7747 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 7748 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7749 | */ |
| 7750 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7751 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7752 | mutex_unlock(&priv->mutex); |
| 7753 | return 0; |
| 7754 | } |
| 7755 | |
| 7756 | if (priv->interface_id != if_id) { |
| 7757 | IWL_DEBUG_MAC80211("leave - interface_id != if_id\n"); |
| 7758 | mutex_unlock(&priv->mutex); |
| 7759 | return 0; |
| 7760 | } |
| 7761 | |
| 7762 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7763 | if (!conf->bssid) { |
| 7764 | conf->bssid = priv->mac_addr; |
| 7765 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7766 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 7767 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7768 | } |
| 7769 | if (priv->ibss_beacon) |
| 7770 | dev_kfree_skb(priv->ibss_beacon); |
| 7771 | |
| 7772 | priv->ibss_beacon = conf->beacon; |
| 7773 | } |
| 7774 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7775 | if (iwl4965_is_rfkill(priv)) |
| 7776 | goto done; |
| 7777 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7778 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 7779 | !is_multicast_ether_addr(conf->bssid)) { |
| 7780 | /* If there is currently a HW scan going on in the background |
| 7781 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7782 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7783 | IWL_WARNING("Aborted scan still in progress " |
| 7784 | "after 100ms\n"); |
| 7785 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 7786 | mutex_unlock(&priv->mutex); |
| 7787 | return -EAGAIN; |
| 7788 | } |
| 7789 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 7790 | |
| 7791 | /* TODO: Audit driver for usage of these members and see |
| 7792 | * if mac80211 deprecates them (priv->bssid looks like it |
| 7793 | * shouldn't be there, but I haven't scanned the IBSS code |
| 7794 | * to verify) - jpk */ |
| 7795 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 7796 | |
| 7797 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7798 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7799 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7800 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7801 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7802 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7803 | priv, priv->active_rxon.bssid_addr, 1); |
| 7804 | } |
| 7805 | |
| 7806 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7807 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7808 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7809 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7810 | } |
| 7811 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7812 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7813 | spin_lock_irqsave(&priv->lock, flags); |
| 7814 | if (!conf->ssid_len) |
| 7815 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7816 | else |
| 7817 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 7818 | |
| 7819 | priv->essid_len = conf->ssid_len; |
| 7820 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7821 | |
| 7822 | IWL_DEBUG_MAC80211("leave\n"); |
| 7823 | mutex_unlock(&priv->mutex); |
| 7824 | |
| 7825 | return 0; |
| 7826 | } |
| 7827 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7828 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7829 | unsigned int changed_flags, |
| 7830 | unsigned int *total_flags, |
| 7831 | int mc_count, struct dev_addr_list *mc_list) |
| 7832 | { |
| 7833 | /* |
| 7834 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7835 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7836 | */ |
| 7837 | *total_flags = 0; |
| 7838 | } |
| 7839 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7840 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7841 | struct ieee80211_if_init_conf *conf) |
| 7842 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7843 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7844 | |
| 7845 | IWL_DEBUG_MAC80211("enter\n"); |
| 7846 | |
| 7847 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7848 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7849 | if (iwl4965_is_ready_rf(priv)) { |
| 7850 | iwl4965_scan_cancel_timeout(priv, 100); |
| 7851 | cancel_delayed_work(&priv->post_associate); |
| 7852 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 7853 | iwl4965_commit_rxon(priv); |
| 7854 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7855 | if (priv->interface_id == conf->if_id) { |
| 7856 | priv->interface_id = 0; |
| 7857 | memset(priv->bssid, 0, ETH_ALEN); |
| 7858 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7859 | priv->essid_len = 0; |
| 7860 | } |
| 7861 | mutex_unlock(&priv->mutex); |
| 7862 | |
| 7863 | IWL_DEBUG_MAC80211("leave\n"); |
| 7864 | |
| 7865 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7866 | static void iwl4965_mac_erp_ie_changed(struct ieee80211_hw *hw, |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7867 | u8 changes, int cts_protection, int preamble) |
| 7868 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7869 | struct iwl4965_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7870 | |
| 7871 | if (changes & IEEE80211_ERP_CHANGE_PREAMBLE) { |
| 7872 | if (preamble == WLAN_ERP_PREAMBLE_SHORT) |
| 7873 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7874 | else |
| 7875 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7876 | } |
| 7877 | |
| 7878 | if (changes & IEEE80211_ERP_CHANGE_PROTECTION) { |
Zhu Yi | 797a54c | 2007-11-12 11:37:43 +0800 | [diff] [blame] | 7879 | if (cts_protection && (priv->phymode != MODE_IEEE80211A)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7880 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 7881 | else |
| 7882 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 7883 | } |
| 7884 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7885 | if (iwl4965_is_associated(priv)) |
| 7886 | iwl4965_send_rxon_assoc(priv); |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7887 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7888 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7889 | 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] | 7890 | { |
| 7891 | int rc = 0; |
| 7892 | unsigned long flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7893 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7894 | |
| 7895 | IWL_DEBUG_MAC80211("enter\n"); |
| 7896 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7897 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7898 | spin_lock_irqsave(&priv->lock, flags); |
| 7899 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7900 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7901 | rc = -EIO; |
| 7902 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 7903 | goto out_unlock; |
| 7904 | } |
| 7905 | |
| 7906 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 7907 | rc = -EIO; |
| 7908 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 7909 | goto out_unlock; |
| 7910 | } |
| 7911 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7912 | /* we don't schedule scan within next_scan_jiffies period */ |
| 7913 | if (priv->next_scan_jiffies && |
| 7914 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 7915 | rc = -EAGAIN; |
| 7916 | goto out_unlock; |
| 7917 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7918 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7919 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 7920 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7921 | rc = -EAGAIN; |
| 7922 | goto out_unlock; |
| 7923 | } |
| 7924 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7925 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7926 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7927 | |
| 7928 | priv->one_direct_scan = 1; |
| 7929 | priv->direct_ssid_len = (u8) |
| 7930 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 7931 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7932 | } else |
| 7933 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7934 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7935 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7936 | |
| 7937 | IWL_DEBUG_MAC80211("leave\n"); |
| 7938 | |
| 7939 | out_unlock: |
| 7940 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7941 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7942 | |
| 7943 | return rc; |
| 7944 | } |
| 7945 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7946 | 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] | 7947 | const u8 *local_addr, const u8 *addr, |
| 7948 | struct ieee80211_key_conf *key) |
| 7949 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7950 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7951 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7952 | int rc = 0; |
| 7953 | u8 sta_id; |
| 7954 | |
| 7955 | IWL_DEBUG_MAC80211("enter\n"); |
| 7956 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7957 | if (!iwl4965_param_hwcrypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7958 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 7959 | return -EOPNOTSUPP; |
| 7960 | } |
| 7961 | |
| 7962 | if (is_zero_ether_addr(addr)) |
| 7963 | /* only support pairwise keys */ |
| 7964 | return -EOPNOTSUPP; |
| 7965 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7966 | sta_id = iwl4965_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7967 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7968 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 7969 | print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7970 | return -EINVAL; |
| 7971 | } |
| 7972 | |
| 7973 | mutex_lock(&priv->mutex); |
| 7974 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7975 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7976 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7977 | switch (cmd) { |
| 7978 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7979 | rc = iwl4965_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7980 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7981 | iwl4965_set_rxon_hwcrypto(priv, 1); |
| 7982 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7983 | key->hw_key_idx = sta_id; |
| 7984 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 7985 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 7986 | } |
| 7987 | break; |
| 7988 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7989 | rc = iwl4965_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7990 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7991 | iwl4965_set_rxon_hwcrypto(priv, 0); |
| 7992 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7993 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 7994 | } |
| 7995 | break; |
| 7996 | default: |
| 7997 | rc = -EINVAL; |
| 7998 | } |
| 7999 | |
| 8000 | IWL_DEBUG_MAC80211("leave\n"); |
| 8001 | mutex_unlock(&priv->mutex); |
| 8002 | |
| 8003 | return rc; |
| 8004 | } |
| 8005 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8006 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8007 | const struct ieee80211_tx_queue_params *params) |
| 8008 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8009 | struct iwl4965_priv *priv = hw->priv; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8010 | #ifdef CONFIG_IWL4965_QOS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8011 | unsigned long flags; |
| 8012 | int q; |
Reinette Chatre | 0054b34 | 2007-11-29 11:09:42 +0800 | [diff] [blame] | 8013 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8014 | |
| 8015 | IWL_DEBUG_MAC80211("enter\n"); |
| 8016 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8017 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8018 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 8019 | return -EIO; |
| 8020 | } |
| 8021 | |
| 8022 | if (queue >= AC_NUM) { |
| 8023 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 8024 | return 0; |
| 8025 | } |
| 8026 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8027 | #ifdef CONFIG_IWL4965_QOS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8028 | if (!priv->qos_data.qos_enable) { |
| 8029 | priv->qos_data.qos_active = 0; |
| 8030 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 8031 | return 0; |
| 8032 | } |
| 8033 | q = AC_NUM - 1 - queue; |
| 8034 | |
| 8035 | spin_lock_irqsave(&priv->lock, flags); |
| 8036 | |
| 8037 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 8038 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 8039 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 8040 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
| 8041 | cpu_to_le16((params->burst_time * 100)); |
| 8042 | |
| 8043 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 8044 | priv->qos_data.qos_active = 1; |
| 8045 | |
| 8046 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8047 | |
| 8048 | mutex_lock(&priv->mutex); |
| 8049 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8050 | iwl4965_activate_qos(priv, 1); |
| 8051 | else if (priv->assoc_id && iwl4965_is_associated(priv)) |
| 8052 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8053 | |
| 8054 | mutex_unlock(&priv->mutex); |
| 8055 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8056 | #endif /*CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8057 | |
| 8058 | IWL_DEBUG_MAC80211("leave\n"); |
| 8059 | return 0; |
| 8060 | } |
| 8061 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8062 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8063 | struct ieee80211_tx_queue_stats *stats) |
| 8064 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8065 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8066 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8067 | struct iwl4965_tx_queue *txq; |
| 8068 | struct iwl4965_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8069 | unsigned long flags; |
| 8070 | |
| 8071 | IWL_DEBUG_MAC80211("enter\n"); |
| 8072 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8073 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8074 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 8075 | return -EIO; |
| 8076 | } |
| 8077 | |
| 8078 | spin_lock_irqsave(&priv->lock, flags); |
| 8079 | |
| 8080 | for (i = 0; i < AC_NUM; i++) { |
| 8081 | txq = &priv->txq[i]; |
| 8082 | q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8083 | avail = iwl4965_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8084 | |
| 8085 | stats->data[i].len = q->n_window - avail; |
| 8086 | stats->data[i].limit = q->n_window - q->high_mark; |
| 8087 | stats->data[i].count = q->n_window; |
| 8088 | |
| 8089 | } |
| 8090 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8091 | |
| 8092 | IWL_DEBUG_MAC80211("leave\n"); |
| 8093 | |
| 8094 | return 0; |
| 8095 | } |
| 8096 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8097 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8098 | struct ieee80211_low_level_stats *stats) |
| 8099 | { |
| 8100 | IWL_DEBUG_MAC80211("enter\n"); |
| 8101 | IWL_DEBUG_MAC80211("leave\n"); |
| 8102 | |
| 8103 | return 0; |
| 8104 | } |
| 8105 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8106 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8107 | { |
| 8108 | IWL_DEBUG_MAC80211("enter\n"); |
| 8109 | IWL_DEBUG_MAC80211("leave\n"); |
| 8110 | |
| 8111 | return 0; |
| 8112 | } |
| 8113 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8114 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8115 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8116 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8117 | unsigned long flags; |
| 8118 | |
| 8119 | mutex_lock(&priv->mutex); |
| 8120 | IWL_DEBUG_MAC80211("enter\n"); |
| 8121 | |
| 8122 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8123 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8124 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8125 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8126 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8127 | #ifdef CONFIG_IWL4965_HT_AGG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8128 | /* if (priv->lq_mngr.agg_ctrl.granted_ba) |
| 8129 | iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);*/ |
| 8130 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8131 | memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl4965_agg_control)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8132 | priv->lq_mngr.agg_ctrl.tid_traffic_load_threshold = 10; |
| 8133 | priv->lq_mngr.agg_ctrl.ba_timeout = 5000; |
| 8134 | priv->lq_mngr.agg_ctrl.auto_agg = 1; |
| 8135 | |
| 8136 | if (priv->lq_mngr.agg_ctrl.auto_agg) |
| 8137 | priv->lq_mngr.agg_ctrl.requested_ba = TID_ALL_ENABLED; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8138 | #endif /*CONFIG_IWL4965_HT_AGG */ |
| 8139 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8140 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8141 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8142 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8143 | #endif |
| 8144 | |
| 8145 | cancel_delayed_work(&priv->post_associate); |
| 8146 | |
| 8147 | spin_lock_irqsave(&priv->lock, flags); |
| 8148 | priv->assoc_id = 0; |
| 8149 | priv->assoc_capability = 0; |
| 8150 | priv->call_post_assoc_from_beacon = 0; |
| 8151 | priv->assoc_station_added = 0; |
| 8152 | |
| 8153 | /* new association get rid of ibss beacon skb */ |
| 8154 | if (priv->ibss_beacon) |
| 8155 | dev_kfree_skb(priv->ibss_beacon); |
| 8156 | |
| 8157 | priv->ibss_beacon = NULL; |
| 8158 | |
| 8159 | priv->beacon_int = priv->hw->conf.beacon_int; |
| 8160 | priv->timestamp1 = 0; |
| 8161 | priv->timestamp0 = 0; |
| 8162 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 8163 | priv->beacon_int = 0; |
| 8164 | |
| 8165 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8166 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 8167 | if (!iwl4965_is_ready_rf(priv)) { |
| 8168 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 8169 | mutex_unlock(&priv->mutex); |
| 8170 | return; |
| 8171 | } |
| 8172 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8173 | /* we are restarting association process |
| 8174 | * clear RXON_FILTER_ASSOC_MSK bit |
| 8175 | */ |
| 8176 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8177 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8178 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8179 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8180 | } |
| 8181 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8182 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 8183 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8184 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8185 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 8186 | mutex_unlock(&priv->mutex); |
| 8187 | return; |
| 8188 | } |
| 8189 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8190 | priv->only_active_channel = 0; |
| 8191 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8192 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8193 | |
| 8194 | mutex_unlock(&priv->mutex); |
| 8195 | |
| 8196 | IWL_DEBUG_MAC80211("leave\n"); |
| 8197 | |
| 8198 | } |
| 8199 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8200 | 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] | 8201 | struct ieee80211_tx_control *control) |
| 8202 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8203 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8204 | unsigned long flags; |
| 8205 | |
| 8206 | mutex_lock(&priv->mutex); |
| 8207 | IWL_DEBUG_MAC80211("enter\n"); |
| 8208 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8209 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8210 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 8211 | mutex_unlock(&priv->mutex); |
| 8212 | return -EIO; |
| 8213 | } |
| 8214 | |
| 8215 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 8216 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 8217 | mutex_unlock(&priv->mutex); |
| 8218 | return -EIO; |
| 8219 | } |
| 8220 | |
| 8221 | spin_lock_irqsave(&priv->lock, flags); |
| 8222 | |
| 8223 | if (priv->ibss_beacon) |
| 8224 | dev_kfree_skb(priv->ibss_beacon); |
| 8225 | |
| 8226 | priv->ibss_beacon = skb; |
| 8227 | |
| 8228 | priv->assoc_id = 0; |
| 8229 | |
| 8230 | IWL_DEBUG_MAC80211("leave\n"); |
| 8231 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8232 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8233 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8234 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8235 | #endif |
| 8236 | |
| 8237 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 8238 | |
| 8239 | mutex_unlock(&priv->mutex); |
| 8240 | |
| 8241 | return 0; |
| 8242 | } |
| 8243 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8244 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8245 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8246 | static void iwl4965_ht_info_fill(struct ieee80211_conf *conf, |
| 8247 | struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8248 | { |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8249 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 8250 | struct ieee80211_ht_info *ht_conf = &conf->ht_conf; |
| 8251 | struct ieee80211_ht_bss_info *ht_bss_conf = &conf->ht_bss_conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8252 | |
| 8253 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8254 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8255 | if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) { |
| 8256 | iwl_conf->is_ht = 0; |
| 8257 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8258 | } |
| 8259 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8260 | iwl_conf->is_ht = 1; |
| 8261 | 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] | 8262 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8263 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
| 8264 | iwl_conf->sgf |= 0x1; |
| 8265 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
| 8266 | iwl_conf->sgf |= 0x2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8267 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8268 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 8269 | iwl_conf->max_amsdu_size = |
| 8270 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 8271 | iwl_conf->supported_chan_width = |
| 8272 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 8273 | iwl_conf->tx_mimo_ps_mode = |
| 8274 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 8275 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8276 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8277 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 8278 | iwl_conf->extension_chan_offset = |
| 8279 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 8280 | iwl_conf->tx_chan_width = |
| 8281 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 8282 | iwl_conf->ht_protection = |
| 8283 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 8284 | iwl_conf->non_GF_STA_present = |
| 8285 | !!(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] | 8286 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8287 | IWL_DEBUG_MAC80211("control channel %d\n", |
| 8288 | iwl_conf->control_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8289 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8290 | } |
| 8291 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8292 | static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw, |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8293 | struct ieee80211_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8294 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8295 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8296 | |
| 8297 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8298 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8299 | iwl4965_ht_info_fill(conf, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8300 | iwl4965_set_rxon_chain(priv); |
| 8301 | |
| 8302 | if (priv && priv->assoc_id && |
| 8303 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
| 8304 | unsigned long flags; |
| 8305 | |
| 8306 | spin_lock_irqsave(&priv->lock, flags); |
| 8307 | if (priv->beacon_int) |
| 8308 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 8309 | else |
| 8310 | priv->call_post_assoc_from_beacon = 1; |
| 8311 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8312 | } |
| 8313 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8314 | IWL_DEBUG_MAC80211("leave:\n"); |
| 8315 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8316 | } |
| 8317 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8318 | static void iwl4965_set_ht_capab(struct ieee80211_hw *hw, |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 8319 | struct ieee80211_ht_cap *ht_cap, |
| 8320 | u8 use_current_config) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8321 | { |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 8322 | struct ieee80211_conf *conf = &hw->conf; |
| 8323 | struct ieee80211_hw_mode *mode = conf->mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8324 | |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 8325 | if (use_current_config) { |
| 8326 | ht_cap->cap_info = cpu_to_le16(conf->ht_conf.cap); |
| 8327 | memcpy(ht_cap->supp_mcs_set, |
| 8328 | conf->ht_conf.supp_mcs_set, 16); |
| 8329 | } else { |
| 8330 | ht_cap->cap_info = cpu_to_le16(mode->ht_info.cap); |
| 8331 | memcpy(ht_cap->supp_mcs_set, |
| 8332 | mode->ht_info.supp_mcs_set, 16); |
| 8333 | } |
| 8334 | ht_cap->ampdu_params_info = |
| 8335 | (mode->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 8336 | ((mode->ht_info.ampdu_density << 2) & |
| 8337 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8338 | } |
| 8339 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8340 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8341 | |
| 8342 | /***************************************************************************** |
| 8343 | * |
| 8344 | * sysfs attributes |
| 8345 | * |
| 8346 | *****************************************************************************/ |
| 8347 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8348 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8349 | |
| 8350 | /* |
| 8351 | * The following adds a new attribute to the sysfs representation |
| 8352 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 8353 | * used for controlling the debug level. |
| 8354 | * |
| 8355 | * See the level definitions in iwl for details. |
| 8356 | */ |
| 8357 | |
| 8358 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 8359 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8360 | return sprintf(buf, "0x%08X\n", iwl4965_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8361 | } |
| 8362 | static ssize_t store_debug_level(struct device_driver *d, |
| 8363 | const char *buf, size_t count) |
| 8364 | { |
| 8365 | char *p = (char *)buf; |
| 8366 | u32 val; |
| 8367 | |
| 8368 | val = simple_strtoul(p, &p, 0); |
| 8369 | if (p == buf) |
| 8370 | printk(KERN_INFO DRV_NAME |
| 8371 | ": %s is not in hex or decimal form.\n", buf); |
| 8372 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8373 | iwl4965_debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8374 | |
| 8375 | return strnlen(buf, count); |
| 8376 | } |
| 8377 | |
| 8378 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 8379 | show_debug_level, store_debug_level); |
| 8380 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8381 | #endif /* CONFIG_IWL4965_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8382 | |
| 8383 | static ssize_t show_rf_kill(struct device *d, |
| 8384 | struct device_attribute *attr, char *buf) |
| 8385 | { |
| 8386 | /* |
| 8387 | * 0 - RF kill not enabled |
| 8388 | * 1 - SW based RF kill active (sysfs) |
| 8389 | * 2 - HW based RF kill active |
| 8390 | * 3 - Both HW and SW based RF kill active |
| 8391 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8392 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8393 | int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | |
| 8394 | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); |
| 8395 | |
| 8396 | return sprintf(buf, "%i\n", val); |
| 8397 | } |
| 8398 | |
| 8399 | static ssize_t store_rf_kill(struct device *d, |
| 8400 | struct device_attribute *attr, |
| 8401 | const char *buf, size_t count) |
| 8402 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8403 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8404 | |
| 8405 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8406 | iwl4965_radio_kill_sw(priv, buf[0] == '1'); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8407 | mutex_unlock(&priv->mutex); |
| 8408 | |
| 8409 | return count; |
| 8410 | } |
| 8411 | |
| 8412 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); |
| 8413 | |
| 8414 | static ssize_t show_temperature(struct device *d, |
| 8415 | struct device_attribute *attr, char *buf) |
| 8416 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8417 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8418 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8419 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8420 | return -EAGAIN; |
| 8421 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8422 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8423 | } |
| 8424 | |
| 8425 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 8426 | |
| 8427 | static ssize_t show_rs_window(struct device *d, |
| 8428 | struct device_attribute *attr, |
| 8429 | char *buf) |
| 8430 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8431 | struct iwl4965_priv *priv = d->driver_data; |
| 8432 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8433 | } |
| 8434 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 8435 | |
| 8436 | static ssize_t show_tx_power(struct device *d, |
| 8437 | struct device_attribute *attr, char *buf) |
| 8438 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8439 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8440 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 8441 | } |
| 8442 | |
| 8443 | static ssize_t store_tx_power(struct device *d, |
| 8444 | struct device_attribute *attr, |
| 8445 | const char *buf, size_t count) |
| 8446 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8447 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8448 | char *p = (char *)buf; |
| 8449 | u32 val; |
| 8450 | |
| 8451 | val = simple_strtoul(p, &p, 10); |
| 8452 | if (p == buf) |
| 8453 | printk(KERN_INFO DRV_NAME |
| 8454 | ": %s is not in decimal form.\n", buf); |
| 8455 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8456 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8457 | |
| 8458 | return count; |
| 8459 | } |
| 8460 | |
| 8461 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 8462 | |
| 8463 | static ssize_t show_flags(struct device *d, |
| 8464 | struct device_attribute *attr, char *buf) |
| 8465 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8466 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8467 | |
| 8468 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 8469 | } |
| 8470 | |
| 8471 | static ssize_t store_flags(struct device *d, |
| 8472 | struct device_attribute *attr, |
| 8473 | const char *buf, size_t count) |
| 8474 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8475 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8476 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 8477 | |
| 8478 | mutex_lock(&priv->mutex); |
| 8479 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 8480 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8481 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8482 | IWL_WARNING("Could not cancel scan.\n"); |
| 8483 | else { |
| 8484 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 8485 | flags); |
| 8486 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8487 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8488 | } |
| 8489 | } |
| 8490 | mutex_unlock(&priv->mutex); |
| 8491 | |
| 8492 | return count; |
| 8493 | } |
| 8494 | |
| 8495 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 8496 | |
| 8497 | static ssize_t show_filter_flags(struct device *d, |
| 8498 | struct device_attribute *attr, char *buf) |
| 8499 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8500 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8501 | |
| 8502 | return sprintf(buf, "0x%04X\n", |
| 8503 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 8504 | } |
| 8505 | |
| 8506 | static ssize_t store_filter_flags(struct device *d, |
| 8507 | struct device_attribute *attr, |
| 8508 | const char *buf, size_t count) |
| 8509 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8510 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8511 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 8512 | |
| 8513 | mutex_lock(&priv->mutex); |
| 8514 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 8515 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8516 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8517 | IWL_WARNING("Could not cancel scan.\n"); |
| 8518 | else { |
| 8519 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 8520 | "0x%04X\n", filter_flags); |
| 8521 | priv->staging_rxon.filter_flags = |
| 8522 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8523 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8524 | } |
| 8525 | } |
| 8526 | mutex_unlock(&priv->mutex); |
| 8527 | |
| 8528 | return count; |
| 8529 | } |
| 8530 | |
| 8531 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 8532 | store_filter_flags); |
| 8533 | |
| 8534 | static ssize_t show_tune(struct device *d, |
| 8535 | struct device_attribute *attr, char *buf) |
| 8536 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8537 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8538 | |
| 8539 | return sprintf(buf, "0x%04X\n", |
| 8540 | (priv->phymode << 8) | |
| 8541 | le16_to_cpu(priv->active_rxon.channel)); |
| 8542 | } |
| 8543 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8544 | 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] | 8545 | |
| 8546 | static ssize_t store_tune(struct device *d, |
| 8547 | struct device_attribute *attr, |
| 8548 | const char *buf, size_t count) |
| 8549 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8550 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8551 | char *p = (char *)buf; |
| 8552 | u16 tune = simple_strtoul(p, &p, 0); |
| 8553 | u8 phymode = (tune >> 8) & 0xff; |
| 8554 | u16 channel = tune & 0xff; |
| 8555 | |
| 8556 | IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel); |
| 8557 | |
| 8558 | mutex_lock(&priv->mutex); |
| 8559 | if ((le16_to_cpu(priv->staging_rxon.channel) != channel) || |
| 8560 | (priv->phymode != phymode)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8561 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8562 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8563 | ch_info = iwl4965_get_channel_info(priv, phymode, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8564 | if (!ch_info) { |
| 8565 | IWL_WARNING("Requested invalid phymode/channel " |
| 8566 | "combination: %d %d\n", phymode, channel); |
| 8567 | mutex_unlock(&priv->mutex); |
| 8568 | return -EINVAL; |
| 8569 | } |
| 8570 | |
| 8571 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8572 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8573 | IWL_WARNING("Could not cancel scan.\n"); |
| 8574 | else { |
| 8575 | IWL_DEBUG_INFO("Committing phymode and " |
| 8576 | "rxon.channel = %d %d\n", |
| 8577 | phymode, channel); |
| 8578 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8579 | iwl4965_set_rxon_channel(priv, phymode, channel); |
| 8580 | iwl4965_set_flags_for_phymode(priv, phymode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8581 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8582 | iwl4965_set_rate(priv); |
| 8583 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8584 | } |
| 8585 | } |
| 8586 | mutex_unlock(&priv->mutex); |
| 8587 | |
| 8588 | return count; |
| 8589 | } |
| 8590 | |
| 8591 | static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune); |
| 8592 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8593 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8594 | |
| 8595 | static ssize_t show_measurement(struct device *d, |
| 8596 | struct device_attribute *attr, char *buf) |
| 8597 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8598 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8599 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8600 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 8601 | u8 *data = (u8 *) & measure_report; |
| 8602 | unsigned long flags; |
| 8603 | |
| 8604 | spin_lock_irqsave(&priv->lock, flags); |
| 8605 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 8606 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8607 | return 0; |
| 8608 | } |
| 8609 | memcpy(&measure_report, &priv->measure_report, size); |
| 8610 | priv->measurement_status = 0; |
| 8611 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8612 | |
| 8613 | while (size && (PAGE_SIZE - len)) { |
| 8614 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8615 | PAGE_SIZE - len, 1); |
| 8616 | len = strlen(buf); |
| 8617 | if (PAGE_SIZE - len) |
| 8618 | buf[len++] = '\n'; |
| 8619 | |
| 8620 | ofs += 16; |
| 8621 | size -= min(size, 16U); |
| 8622 | } |
| 8623 | |
| 8624 | return len; |
| 8625 | } |
| 8626 | |
| 8627 | static ssize_t store_measurement(struct device *d, |
| 8628 | struct device_attribute *attr, |
| 8629 | const char *buf, size_t count) |
| 8630 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8631 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8632 | struct ieee80211_measurement_params params = { |
| 8633 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 8634 | .start_time = cpu_to_le64(priv->last_tsf), |
| 8635 | .duration = cpu_to_le16(1), |
| 8636 | }; |
| 8637 | u8 type = IWL_MEASURE_BASIC; |
| 8638 | u8 buffer[32]; |
| 8639 | u8 channel; |
| 8640 | |
| 8641 | if (count) { |
| 8642 | char *p = buffer; |
| 8643 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 8644 | channel = simple_strtoul(p, NULL, 0); |
| 8645 | if (channel) |
| 8646 | params.channel = channel; |
| 8647 | |
| 8648 | p = buffer; |
| 8649 | while (*p && *p != ' ') |
| 8650 | p++; |
| 8651 | if (*p) |
| 8652 | type = simple_strtoul(p + 1, NULL, 0); |
| 8653 | } |
| 8654 | |
| 8655 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 8656 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8657 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8658 | |
| 8659 | return count; |
| 8660 | } |
| 8661 | |
| 8662 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 8663 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8664 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8665 | |
| 8666 | static ssize_t store_retry_rate(struct device *d, |
| 8667 | struct device_attribute *attr, |
| 8668 | const char *buf, size_t count) |
| 8669 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8670 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8671 | |
| 8672 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 8673 | if (priv->retry_rate <= 0) |
| 8674 | priv->retry_rate = 1; |
| 8675 | |
| 8676 | return count; |
| 8677 | } |
| 8678 | |
| 8679 | static ssize_t show_retry_rate(struct device *d, |
| 8680 | struct device_attribute *attr, char *buf) |
| 8681 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8682 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8683 | return sprintf(buf, "%d", priv->retry_rate); |
| 8684 | } |
| 8685 | |
| 8686 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 8687 | store_retry_rate); |
| 8688 | |
| 8689 | static ssize_t store_power_level(struct device *d, |
| 8690 | struct device_attribute *attr, |
| 8691 | const char *buf, size_t count) |
| 8692 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8693 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8694 | int rc; |
| 8695 | int mode; |
| 8696 | |
| 8697 | mode = simple_strtoul(buf, NULL, 0); |
| 8698 | mutex_lock(&priv->mutex); |
| 8699 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8700 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8701 | rc = -EAGAIN; |
| 8702 | goto out; |
| 8703 | } |
| 8704 | |
| 8705 | if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC)) |
| 8706 | mode = IWL_POWER_AC; |
| 8707 | else |
| 8708 | mode |= IWL_POWER_ENABLED; |
| 8709 | |
| 8710 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8711 | rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8712 | if (rc) { |
| 8713 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 8714 | goto out; |
| 8715 | } |
| 8716 | priv->power_mode = mode; |
| 8717 | } |
| 8718 | |
| 8719 | rc = count; |
| 8720 | |
| 8721 | out: |
| 8722 | mutex_unlock(&priv->mutex); |
| 8723 | return rc; |
| 8724 | } |
| 8725 | |
| 8726 | #define MAX_WX_STRING 80 |
| 8727 | |
| 8728 | /* Values are in microsecond */ |
| 8729 | static const s32 timeout_duration[] = { |
| 8730 | 350000, |
| 8731 | 250000, |
| 8732 | 75000, |
| 8733 | 37000, |
| 8734 | 25000, |
| 8735 | }; |
| 8736 | static const s32 period_duration[] = { |
| 8737 | 400000, |
| 8738 | 700000, |
| 8739 | 1000000, |
| 8740 | 1000000, |
| 8741 | 1000000 |
| 8742 | }; |
| 8743 | |
| 8744 | static ssize_t show_power_level(struct device *d, |
| 8745 | struct device_attribute *attr, char *buf) |
| 8746 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8747 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8748 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 8749 | char *p = buf; |
| 8750 | |
| 8751 | p += sprintf(p, "%d ", level); |
| 8752 | switch (level) { |
| 8753 | case IWL_POWER_MODE_CAM: |
| 8754 | case IWL_POWER_AC: |
| 8755 | p += sprintf(p, "(AC)"); |
| 8756 | break; |
| 8757 | case IWL_POWER_BATTERY: |
| 8758 | p += sprintf(p, "(BATTERY)"); |
| 8759 | break; |
| 8760 | default: |
| 8761 | p += sprintf(p, |
| 8762 | "(Timeout %dms, Period %dms)", |
| 8763 | timeout_duration[level - 1] / 1000, |
| 8764 | period_duration[level - 1] / 1000); |
| 8765 | } |
| 8766 | |
| 8767 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 8768 | p += sprintf(p, " OFF\n"); |
| 8769 | else |
| 8770 | p += sprintf(p, " \n"); |
| 8771 | |
| 8772 | return (p - buf + 1); |
| 8773 | |
| 8774 | } |
| 8775 | |
| 8776 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 8777 | store_power_level); |
| 8778 | |
| 8779 | static ssize_t show_channels(struct device *d, |
| 8780 | struct device_attribute *attr, char *buf) |
| 8781 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8782 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8783 | int len = 0, i; |
| 8784 | struct ieee80211_channel *channels = NULL; |
| 8785 | const struct ieee80211_hw_mode *hw_mode = NULL; |
| 8786 | int count = 0; |
| 8787 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8788 | if (!iwl4965_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8789 | return -EAGAIN; |
| 8790 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8791 | hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211G); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8792 | if (!hw_mode) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8793 | hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211B); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8794 | if (hw_mode) { |
| 8795 | channels = hw_mode->channels; |
| 8796 | count = hw_mode->num_channels; |
| 8797 | } |
| 8798 | |
| 8799 | len += |
| 8800 | sprintf(&buf[len], |
| 8801 | "Displaying %d channels in 2.4GHz band " |
| 8802 | "(802.11bg):\n", count); |
| 8803 | |
| 8804 | for (i = 0; i < count; i++) |
| 8805 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 8806 | channels[i].chan, |
| 8807 | channels[i].power_level, |
| 8808 | channels[i]. |
| 8809 | flag & IEEE80211_CHAN_W_RADAR_DETECT ? |
| 8810 | " (IEEE 802.11h required)" : "", |
| 8811 | (!(channels[i].flag & IEEE80211_CHAN_W_IBSS) |
| 8812 | || (channels[i]. |
| 8813 | flag & |
| 8814 | IEEE80211_CHAN_W_RADAR_DETECT)) ? "" : |
| 8815 | ", IBSS", |
| 8816 | channels[i]. |
| 8817 | flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? |
| 8818 | "active/passive" : "passive only"); |
| 8819 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8820 | hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211A); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8821 | if (hw_mode) { |
| 8822 | channels = hw_mode->channels; |
| 8823 | count = hw_mode->num_channels; |
| 8824 | } else { |
| 8825 | channels = NULL; |
| 8826 | count = 0; |
| 8827 | } |
| 8828 | |
| 8829 | len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band " |
| 8830 | "(802.11a):\n", count); |
| 8831 | |
| 8832 | for (i = 0; i < count; i++) |
| 8833 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 8834 | channels[i].chan, |
| 8835 | channels[i].power_level, |
| 8836 | channels[i]. |
| 8837 | flag & IEEE80211_CHAN_W_RADAR_DETECT ? |
| 8838 | " (IEEE 802.11h required)" : "", |
| 8839 | (!(channels[i].flag & IEEE80211_CHAN_W_IBSS) |
| 8840 | || (channels[i]. |
| 8841 | flag & |
| 8842 | IEEE80211_CHAN_W_RADAR_DETECT)) ? "" : |
| 8843 | ", IBSS", |
| 8844 | channels[i]. |
| 8845 | flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? |
| 8846 | "active/passive" : "passive only"); |
| 8847 | |
| 8848 | return len; |
| 8849 | } |
| 8850 | |
| 8851 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 8852 | |
| 8853 | static ssize_t show_statistics(struct device *d, |
| 8854 | struct device_attribute *attr, char *buf) |
| 8855 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8856 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8857 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8858 | u32 len = 0, ofs = 0; |
| 8859 | u8 *data = (u8 *) & priv->statistics; |
| 8860 | int rc = 0; |
| 8861 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8862 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8863 | return -EAGAIN; |
| 8864 | |
| 8865 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8866 | rc = iwl4965_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8867 | mutex_unlock(&priv->mutex); |
| 8868 | |
| 8869 | if (rc) { |
| 8870 | len = sprintf(buf, |
| 8871 | "Error sending statistics request: 0x%08X\n", rc); |
| 8872 | return len; |
| 8873 | } |
| 8874 | |
| 8875 | while (size && (PAGE_SIZE - len)) { |
| 8876 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8877 | PAGE_SIZE - len, 1); |
| 8878 | len = strlen(buf); |
| 8879 | if (PAGE_SIZE - len) |
| 8880 | buf[len++] = '\n'; |
| 8881 | |
| 8882 | ofs += 16; |
| 8883 | size -= min(size, 16U); |
| 8884 | } |
| 8885 | |
| 8886 | return len; |
| 8887 | } |
| 8888 | |
| 8889 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 8890 | |
| 8891 | static ssize_t show_antenna(struct device *d, |
| 8892 | struct device_attribute *attr, char *buf) |
| 8893 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8894 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8895 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8896 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8897 | return -EAGAIN; |
| 8898 | |
| 8899 | return sprintf(buf, "%d\n", priv->antenna); |
| 8900 | } |
| 8901 | |
| 8902 | static ssize_t store_antenna(struct device *d, |
| 8903 | struct device_attribute *attr, |
| 8904 | const char *buf, size_t count) |
| 8905 | { |
| 8906 | int ant; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8907 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8908 | |
| 8909 | if (count == 0) |
| 8910 | return 0; |
| 8911 | |
| 8912 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 8913 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 8914 | return count; |
| 8915 | } |
| 8916 | |
| 8917 | if ((ant >= 0) && (ant <= 2)) { |
| 8918 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8919 | priv->antenna = (enum iwl4965_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8920 | } else |
| 8921 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 8922 | |
| 8923 | |
| 8924 | return count; |
| 8925 | } |
| 8926 | |
| 8927 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 8928 | |
| 8929 | static ssize_t show_status(struct device *d, |
| 8930 | struct device_attribute *attr, char *buf) |
| 8931 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8932 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
| 8933 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8934 | return -EAGAIN; |
| 8935 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 8936 | } |
| 8937 | |
| 8938 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 8939 | |
| 8940 | static ssize_t dump_error_log(struct device *d, |
| 8941 | struct device_attribute *attr, |
| 8942 | const char *buf, size_t count) |
| 8943 | { |
| 8944 | char *p = (char *)buf; |
| 8945 | |
| 8946 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8947 | iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8948 | |
| 8949 | return strnlen(buf, count); |
| 8950 | } |
| 8951 | |
| 8952 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 8953 | |
| 8954 | static ssize_t dump_event_log(struct device *d, |
| 8955 | struct device_attribute *attr, |
| 8956 | const char *buf, size_t count) |
| 8957 | { |
| 8958 | char *p = (char *)buf; |
| 8959 | |
| 8960 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8961 | iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8962 | |
| 8963 | return strnlen(buf, count); |
| 8964 | } |
| 8965 | |
| 8966 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 8967 | |
| 8968 | /***************************************************************************** |
| 8969 | * |
| 8970 | * driver setup and teardown |
| 8971 | * |
| 8972 | *****************************************************************************/ |
| 8973 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8974 | static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8975 | { |
| 8976 | priv->workqueue = create_workqueue(DRV_NAME); |
| 8977 | |
| 8978 | init_waitqueue_head(&priv->wait_command_queue); |
| 8979 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8980 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 8981 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 8982 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 8983 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 8984 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 8985 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 8986 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 8987 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
| 8988 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 8989 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 8990 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 8991 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8992 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8993 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8994 | |
| 8995 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8996 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8997 | } |
| 8998 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8999 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9000 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9001 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9002 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 9003 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9004 | cancel_delayed_work(&priv->scan_check); |
| 9005 | cancel_delayed_work(&priv->alive_start); |
| 9006 | cancel_delayed_work(&priv->post_associate); |
| 9007 | cancel_work_sync(&priv->beacon_update); |
| 9008 | } |
| 9009 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9010 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9011 | &dev_attr_antenna.attr, |
| 9012 | &dev_attr_channels.attr, |
| 9013 | &dev_attr_dump_errors.attr, |
| 9014 | &dev_attr_dump_events.attr, |
| 9015 | &dev_attr_flags.attr, |
| 9016 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9017 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9018 | &dev_attr_measurement.attr, |
| 9019 | #endif |
| 9020 | &dev_attr_power_level.attr, |
| 9021 | &dev_attr_retry_rate.attr, |
| 9022 | &dev_attr_rf_kill.attr, |
| 9023 | &dev_attr_rs_window.attr, |
| 9024 | &dev_attr_statistics.attr, |
| 9025 | &dev_attr_status.attr, |
| 9026 | &dev_attr_temperature.attr, |
| 9027 | &dev_attr_tune.attr, |
| 9028 | &dev_attr_tx_power.attr, |
| 9029 | |
| 9030 | NULL |
| 9031 | }; |
| 9032 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9033 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9034 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9035 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9036 | }; |
| 9037 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9038 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 9039 | .tx = iwl4965_mac_tx, |
| 9040 | .start = iwl4965_mac_start, |
| 9041 | .stop = iwl4965_mac_stop, |
| 9042 | .add_interface = iwl4965_mac_add_interface, |
| 9043 | .remove_interface = iwl4965_mac_remove_interface, |
| 9044 | .config = iwl4965_mac_config, |
| 9045 | .config_interface = iwl4965_mac_config_interface, |
| 9046 | .configure_filter = iwl4965_configure_filter, |
| 9047 | .set_key = iwl4965_mac_set_key, |
| 9048 | .get_stats = iwl4965_mac_get_stats, |
| 9049 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 9050 | .conf_tx = iwl4965_mac_conf_tx, |
| 9051 | .get_tsf = iwl4965_mac_get_tsf, |
| 9052 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 9053 | .beacon_update = iwl4965_mac_beacon_update, |
| 9054 | .erp_ie_changed = iwl4965_mac_erp_ie_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9055 | #ifdef CONFIG_IWL4965_HT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9056 | .conf_ht = iwl4965_mac_conf_ht, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9057 | #ifdef CONFIG_IWL4965_HT_AGG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9058 | .ht_tx_agg_start = iwl4965_mac_ht_tx_agg_start, |
| 9059 | .ht_tx_agg_stop = iwl4965_mac_ht_tx_agg_stop, |
| 9060 | .ht_rx_agg_start = iwl4965_mac_ht_rx_agg_start, |
| 9061 | .ht_rx_agg_stop = iwl4965_mac_ht_rx_agg_stop, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9062 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 9063 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9064 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9065 | }; |
| 9066 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9067 | 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] | 9068 | { |
| 9069 | int err = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9070 | struct iwl4965_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9071 | struct ieee80211_hw *hw; |
| 9072 | int i; |
| 9073 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9074 | /* Disabling hardware scan means that mac80211 will perform scans |
| 9075 | * "the hard way", rather than using device's scan. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9076 | if (iwl4965_param_disable_hw_scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9077 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9078 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9079 | } |
| 9080 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9081 | if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) || |
| 9082 | (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9083 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
| 9084 | IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); |
| 9085 | err = -EINVAL; |
| 9086 | goto out; |
| 9087 | } |
| 9088 | |
| 9089 | /* mac80211 allocates memory for this device instance, including |
| 9090 | * space for this driver's private structure */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9091 | hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9092 | if (hw == NULL) { |
| 9093 | IWL_ERROR("Can not allocate network device\n"); |
| 9094 | err = -ENOMEM; |
| 9095 | goto out; |
| 9096 | } |
| 9097 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 9098 | |
Johannes Berg | f51359a | 2007-10-28 14:53:36 +0100 | [diff] [blame] | 9099 | hw->rate_control_algorithm = "iwl-4965-rs"; |
| 9100 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9101 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 9102 | priv = hw->priv; |
| 9103 | priv->hw = hw; |
| 9104 | |
| 9105 | priv->pci_dev = pdev; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9106 | priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9107 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9108 | iwl4965_debug_level = iwl4965_param_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9109 | atomic_set(&priv->restrict_refcnt, 0); |
| 9110 | #endif |
| 9111 | priv->retry_rate = 1; |
| 9112 | |
| 9113 | priv->ibss_beacon = NULL; |
| 9114 | |
| 9115 | /* Tell mac80211 and its clients (e.g. Wireless Extensions) |
| 9116 | * the range of signal quality values that we'll provide. |
| 9117 | * Negative values for level/noise indicate that we'll provide dBm. |
| 9118 | * For WE, at least, non-0 values here *enable* display of values |
| 9119 | * in app (iwconfig). */ |
| 9120 | hw->max_rssi = -20; /* signal level, negative indicates dBm */ |
| 9121 | hw->max_noise = -20; /* noise level, negative indicates dBm */ |
| 9122 | hw->max_signal = 100; /* link quality indication (%) */ |
| 9123 | |
| 9124 | /* Tell mac80211 our Tx characteristics */ |
| 9125 | hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; |
| 9126 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9127 | /* Default value; 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9128 | hw->queues = 4; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9129 | #ifdef CONFIG_IWL4965_HT |
| 9130 | #ifdef CONFIG_IWL4965_HT_AGG |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9131 | /* Enhanced value; more queues, to support 11n aggregation */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9132 | hw->queues = 16; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9133 | #endif /* CONFIG_IWL4965_HT_AGG */ |
| 9134 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9135 | |
| 9136 | spin_lock_init(&priv->lock); |
| 9137 | spin_lock_init(&priv->power_data.lock); |
| 9138 | spin_lock_init(&priv->sta_lock); |
| 9139 | spin_lock_init(&priv->hcmd_lock); |
| 9140 | spin_lock_init(&priv->lq_mngr.lock); |
| 9141 | |
| 9142 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) |
| 9143 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
| 9144 | |
| 9145 | INIT_LIST_HEAD(&priv->free_frames); |
| 9146 | |
| 9147 | mutex_init(&priv->mutex); |
| 9148 | if (pci_enable_device(pdev)) { |
| 9149 | err = -ENODEV; |
| 9150 | goto out_ieee80211_free_hw; |
| 9151 | } |
| 9152 | |
| 9153 | pci_set_master(pdev); |
| 9154 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9155 | /* Clear the driver's (not device's) station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9156 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9157 | |
| 9158 | priv->data_retry_limit = -1; |
| 9159 | priv->ieee_channels = NULL; |
| 9160 | priv->ieee_rates = NULL; |
| 9161 | priv->phymode = -1; |
| 9162 | |
| 9163 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 9164 | if (!err) |
| 9165 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 9166 | if (err) { |
| 9167 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 9168 | goto out_pci_disable_device; |
| 9169 | } |
| 9170 | |
| 9171 | pci_set_drvdata(pdev, priv); |
| 9172 | err = pci_request_regions(pdev, DRV_NAME); |
| 9173 | if (err) |
| 9174 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9175 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9176 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 9177 | * PCI Tx retries from interfering with C3 CPU state */ |
| 9178 | pci_write_config_byte(pdev, 0x41, 0x00); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9179 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9180 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 9181 | if (!priv->hw_base) { |
| 9182 | err = -ENODEV; |
| 9183 | goto out_pci_release_regions; |
| 9184 | } |
| 9185 | |
| 9186 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 9187 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 9188 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 9189 | |
| 9190 | /* Initialize module parameter values here */ |
| 9191 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9192 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9193 | if (iwl4965_param_disable) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9194 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 9195 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 9196 | } |
| 9197 | |
| 9198 | priv->iw_mode = IEEE80211_IF_TYPE_STA; |
| 9199 | |
| 9200 | priv->ps_mode = 0; |
| 9201 | priv->use_ant_b_for_management_frame = 1; /* start with ant B */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9202 | priv->valid_antenna = 0x7; /* assume all 3 connected */ |
| 9203 | priv->ps_mode = IWL_MIMO_PS_NONE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9204 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 9205 | /* Choose which receivers/antennas to use */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9206 | iwl4965_set_rxon_chain(priv); |
| 9207 | |
| 9208 | printk(KERN_INFO DRV_NAME |
| 9209 | ": Detected Intel Wireless WiFi Link 4965AGN\n"); |
| 9210 | |
| 9211 | /* Device-specific setup */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9212 | if (iwl4965_hw_set_hw_setting(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9213 | IWL_ERROR("failed to set hw settings\n"); |
| 9214 | mutex_unlock(&priv->mutex); |
| 9215 | goto out_iounmap; |
| 9216 | } |
| 9217 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9218 | #ifdef CONFIG_IWL4965_QOS |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9219 | if (iwl4965_param_qos_enable) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9220 | priv->qos_data.qos_enable = 1; |
| 9221 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9222 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9223 | |
| 9224 | priv->qos_data.qos_active = 0; |
| 9225 | priv->qos_data.qos_cap.val = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9226 | #endif /* CONFIG_IWL4965_QOS */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9227 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9228 | iwl4965_set_rxon_channel(priv, MODE_IEEE80211G, 6); |
| 9229 | iwl4965_setup_deferred_work(priv); |
| 9230 | iwl4965_setup_rx_handlers(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9231 | |
| 9232 | priv->rates_mask = IWL_RATES_MASK; |
| 9233 | /* If power management is turned on, default to AC mode */ |
| 9234 | priv->power_mode = IWL_POWER_AC; |
| 9235 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 9236 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9237 | iwl4965_disable_interrupts(priv); |
Jes Sorensen | 49df2b3 | 2007-10-26 16:10:39 +0200 | [diff] [blame] | 9238 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9239 | pci_enable_msi(pdev); |
| 9240 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9241 | err = request_irq(pdev->irq, iwl4965_isr, IRQF_SHARED, DRV_NAME, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9242 | if (err) { |
| 9243 | IWL_ERROR("Error allocating IRQ %d\n", pdev->irq); |
| 9244 | goto out_disable_msi; |
| 9245 | } |
| 9246 | |
| 9247 | mutex_lock(&priv->mutex); |
| 9248 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9249 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9250 | if (err) { |
| 9251 | IWL_ERROR("failed to create sysfs device attributes\n"); |
| 9252 | mutex_unlock(&priv->mutex); |
| 9253 | goto out_release_irq; |
| 9254 | } |
| 9255 | |
| 9256 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 9257 | * ucode filename and max sizes are card-specific. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9258 | err = iwl4965_read_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9259 | if (err) { |
| 9260 | IWL_ERROR("Could not read microcode: %d\n", err); |
| 9261 | mutex_unlock(&priv->mutex); |
| 9262 | goto out_pci_alloc; |
| 9263 | } |
| 9264 | |
| 9265 | mutex_unlock(&priv->mutex); |
| 9266 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 9267 | IWL_DEBUG_INFO("Queueing UP work.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9268 | |
| 9269 | queue_work(priv->workqueue, &priv->up); |
| 9270 | |
| 9271 | return 0; |
| 9272 | |
| 9273 | out_pci_alloc: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9274 | iwl4965_dealloc_ucode_pci(priv); |
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 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9277 | |
| 9278 | out_release_irq: |
| 9279 | free_irq(pdev->irq, priv); |
| 9280 | |
| 9281 | out_disable_msi: |
| 9282 | pci_disable_msi(pdev); |
| 9283 | destroy_workqueue(priv->workqueue); |
| 9284 | priv->workqueue = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9285 | iwl4965_unset_hw_setting(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9286 | |
| 9287 | out_iounmap: |
| 9288 | pci_iounmap(pdev, priv->hw_base); |
| 9289 | out_pci_release_regions: |
| 9290 | pci_release_regions(pdev); |
| 9291 | out_pci_disable_device: |
| 9292 | pci_disable_device(pdev); |
| 9293 | pci_set_drvdata(pdev, NULL); |
| 9294 | out_ieee80211_free_hw: |
| 9295 | ieee80211_free_hw(priv->hw); |
| 9296 | out: |
| 9297 | return err; |
| 9298 | } |
| 9299 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9300 | static void iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9301 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9302 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9303 | struct list_head *p, *q; |
| 9304 | int i; |
| 9305 | |
| 9306 | if (!priv) |
| 9307 | return; |
| 9308 | |
| 9309 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 9310 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9311 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 9312 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9313 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9314 | |
| 9315 | /* Free MAC hash list for ADHOC */ |
| 9316 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 9317 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 9318 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9319 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9320 | } |
| 9321 | } |
| 9322 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9323 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9324 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9325 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9326 | |
| 9327 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9328 | iwl4965_rx_queue_free(priv, &priv->rxq); |
| 9329 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9330 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9331 | iwl4965_unset_hw_setting(priv); |
| 9332 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9333 | |
| 9334 | if (priv->mac80211_registered) { |
| 9335 | ieee80211_unregister_hw(priv->hw); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9336 | iwl4965_rate_control_unregister(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9337 | } |
| 9338 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 9339 | /*netif_stop_queue(dev); */ |
| 9340 | flush_workqueue(priv->workqueue); |
| 9341 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9342 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9343 | * priv->workqueue... so we can't take down the workqueue |
| 9344 | * until now... */ |
| 9345 | destroy_workqueue(priv->workqueue); |
| 9346 | priv->workqueue = NULL; |
| 9347 | |
| 9348 | free_irq(pdev->irq, priv); |
| 9349 | pci_disable_msi(pdev); |
| 9350 | pci_iounmap(pdev, priv->hw_base); |
| 9351 | pci_release_regions(pdev); |
| 9352 | pci_disable_device(pdev); |
| 9353 | pci_set_drvdata(pdev, NULL); |
| 9354 | |
| 9355 | kfree(priv->channel_info); |
| 9356 | |
| 9357 | kfree(priv->ieee_channels); |
| 9358 | kfree(priv->ieee_rates); |
| 9359 | |
| 9360 | if (priv->ibss_beacon) |
| 9361 | dev_kfree_skb(priv->ibss_beacon); |
| 9362 | |
| 9363 | ieee80211_free_hw(priv->hw); |
| 9364 | } |
| 9365 | |
| 9366 | #ifdef CONFIG_PM |
| 9367 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9368 | 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] | 9369 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9370 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9371 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9372 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 9373 | |
| 9374 | /* Take down the device; powers it off, etc. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9375 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9376 | |
| 9377 | if (priv->mac80211_registered) |
| 9378 | ieee80211_stop_queues(priv->hw); |
| 9379 | |
| 9380 | pci_save_state(pdev); |
| 9381 | pci_disable_device(pdev); |
| 9382 | pci_set_power_state(pdev, PCI_D3hot); |
| 9383 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9384 | return 0; |
| 9385 | } |
| 9386 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9387 | static void iwl4965_resume(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9388 | { |
| 9389 | unsigned long flags; |
| 9390 | |
| 9391 | /* The following it a temporary work around due to the |
| 9392 | * suspend / resume not fully initializing the NIC correctly. |
| 9393 | * Without all of the following, resume will not attempt to take |
| 9394 | * down the NIC (it shouldn't really need to) and will just try |
| 9395 | * and bring the NIC back up. However that fails during the |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9396 | * ucode verification process. This then causes iwl4965_down to be |
| 9397 | * called *after* iwl4965_hw_nic_init() has succeeded -- which |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9398 | * then lets the next init sequence succeed. So, we've |
| 9399 | * replicated all of that NIC init code here... */ |
| 9400 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9401 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9402 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9403 | iwl4965_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9404 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9405 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 9406 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9407 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9408 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 9409 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 9410 | 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] | 9411 | |
| 9412 | /* tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9413 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9414 | |
| 9415 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9416 | iwl4965_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9417 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9418 | if (!iwl4965_grab_nic_access(priv)) { |
| 9419 | iwl4965_write_prph(priv, APMG_CLK_DIS_REG, |
Tomas Winkler | ac17a94 | 2007-10-25 17:15:37 +0800 | [diff] [blame] | 9420 | APMG_CLK_VAL_DMA_CLK_RQT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9421 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9422 | } |
| 9423 | spin_unlock_irqrestore(&priv->lock, flags); |
| 9424 | |
| 9425 | udelay(5); |
| 9426 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9427 | iwl4965_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9428 | |
| 9429 | /* Bring the device back up */ |
| 9430 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
| 9431 | queue_work(priv->workqueue, &priv->up); |
| 9432 | } |
| 9433 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9434 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9435 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9436 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9437 | int err; |
| 9438 | |
| 9439 | printk(KERN_INFO "Coming out of suspend...\n"); |
| 9440 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9441 | pci_set_power_state(pdev, PCI_D0); |
| 9442 | err = pci_enable_device(pdev); |
| 9443 | pci_restore_state(pdev); |
| 9444 | |
| 9445 | /* |
| 9446 | * Suspend/Resume resets the PCI configuration space, so we have to |
| 9447 | * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries |
| 9448 | * from interfering with C3 CPU state. pci_restore_state won't help |
| 9449 | * here since it only restores the first 64 bytes pci config header. |
| 9450 | */ |
| 9451 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 9452 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9453 | iwl4965_resume(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9454 | |
| 9455 | return 0; |
| 9456 | } |
| 9457 | |
| 9458 | #endif /* CONFIG_PM */ |
| 9459 | |
| 9460 | /***************************************************************************** |
| 9461 | * |
| 9462 | * driver and module entry point |
| 9463 | * |
| 9464 | *****************************************************************************/ |
| 9465 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9466 | static struct pci_driver iwl4965_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9467 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9468 | .id_table = iwl4965_hw_card_ids, |
| 9469 | .probe = iwl4965_pci_probe, |
| 9470 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9471 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9472 | .suspend = iwl4965_pci_suspend, |
| 9473 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9474 | #endif |
| 9475 | }; |
| 9476 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9477 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9478 | { |
| 9479 | |
| 9480 | int ret; |
| 9481 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 9482 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9483 | ret = pci_register_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9484 | if (ret) { |
| 9485 | IWL_ERROR("Unable to initialize PCI module\n"); |
| 9486 | return ret; |
| 9487 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9488 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9489 | ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9490 | if (ret) { |
| 9491 | IWL_ERROR("Unable to create driver sysfs file\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9492 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9493 | return ret; |
| 9494 | } |
| 9495 | #endif |
| 9496 | |
| 9497 | return ret; |
| 9498 | } |
| 9499 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9500 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9501 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9502 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9503 | driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9504 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9505 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9506 | } |
| 9507 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9508 | module_param_named(antenna, iwl4965_param_antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9509 | 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] | 9510 | module_param_named(disable, iwl4965_param_disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9511 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9512 | module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9513 | MODULE_PARM_DESC(hwcrypto, |
| 9514 | "using hardware crypto engine (default 0 [software])\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9515 | module_param_named(debug, iwl4965_param_debug, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9516 | MODULE_PARM_DESC(debug, "debug output mask"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9517 | 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] | 9518 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 9519 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9520 | module_param_named(queues_num, iwl4965_param_queues_num, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9521 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 9522 | |
| 9523 | /* QoS */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9524 | module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9525 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
| 9526 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9527 | module_exit(iwl4965_exit); |
| 9528 | module_init(iwl4965_init); |